Skip to content

Commit 96254a9

Browse files
authored
gh-93937, C API: Move PyFrame_GetBack() to Python.h (#93938) (#94000)
Move the follow functions and type from frameobject.h to pyframe.h, so the standard <Python.h> provide frame getter functions: * PyFrame_Check() * PyFrame_GetBack() * PyFrame_GetBuiltins() * PyFrame_GetGenerator() * PyFrame_GetGlobals() * PyFrame_GetLasti() * PyFrame_GetLocals() * PyFrame_Type Remove #include "frameobject.h" from many C files. It's no longer needed. (cherry picked from commit 27b9894)
1 parent 81686e7 commit 96254a9

21 files changed

+61
-28
lines changed

Doc/whatsnew/3.11.rst

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,21 @@ Porting to Python 3.11
17571757
which are not available in the limited C API.
17581758
(Contributed by Victor Stinner in :issue:`46007`.)
17591759

1760+
* The following frame functions and type are now directly available with
1761+
``#include <Python.h>``, it's no longer needed to add
1762+
``#include <frameobject.h>``:
1763+
1764+
* :c:func:`PyFrame_Check`
1765+
* :c:func:`PyFrame_GetBack`
1766+
* :c:func:`PyFrame_GetBuiltins`
1767+
* :c:func:`PyFrame_GetGenerator`
1768+
* :c:func:`PyFrame_GetGlobals`
1769+
* :c:func:`PyFrame_GetLasti`
1770+
* :c:func:`PyFrame_GetLocals`
1771+
* :c:type:`PyFrame_Type`
1772+
1773+
(Contributed by Victor Stinner in :gh:`93937`.)
1774+
17601775
.. _pyframeobject-3.11-hiding:
17611776

17621777
* The :c:type:`PyFrameObject` structure members have been removed from the
@@ -1893,7 +1908,6 @@ Porting to Python 3.11
18931908
paths and then modify them, finish initialization and use :c:func:`PySys_GetObject`
18941909
to retrieve :data:`sys.path` as a Python list object and modify it directly.
18951910

1896-
18971911
Deprecated
18981912
----------
18991913

Include/cpython/frameobject.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66

77
/* Standard object interface */
88

9-
PyAPI_DATA(PyTypeObject) PyFrame_Type;
10-
11-
#define PyFrame_Check(op) Py_IS_TYPE(op, &PyFrame_Type)
12-
139
PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *,
1410
PyObject *, PyObject *);
1511

@@ -31,12 +27,3 @@ PyAPI_FUNC(int) _PyFrame_IsEntryFrame(PyFrameObject *frame);
3127

3228
PyAPI_FUNC(int) PyFrame_FastToLocalsWithError(PyFrameObject *f);
3329
PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *);
34-
35-
PyAPI_FUNC(PyFrameObject *) PyFrame_GetBack(PyFrameObject *frame);
36-
PyAPI_FUNC(PyObject *) PyFrame_GetLocals(PyFrameObject *frame);
37-
38-
PyAPI_FUNC(PyObject *) PyFrame_GetGlobals(PyFrameObject *frame);
39-
PyAPI_FUNC(PyObject *) PyFrame_GetBuiltins(PyFrameObject *frame);
40-
41-
PyAPI_FUNC(PyObject *) PyFrame_GetGenerator(PyFrameObject *frame);
42-
PyAPI_FUNC(int) PyFrame_GetLasti(PyFrameObject *frame);

Include/cpython/pyframe.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef Py_CPYTHON_PYFRAME_H
2+
# error "this header file must not be included directly"
3+
#endif
4+
5+
PyAPI_DATA(PyTypeObject) PyFrame_Type;
6+
7+
#define PyFrame_Check(op) Py_IS_TYPE((op), &PyFrame_Type)
8+
9+
PyAPI_FUNC(PyFrameObject *) PyFrame_GetBack(PyFrameObject *frame);
10+
PyAPI_FUNC(PyObject *) PyFrame_GetLocals(PyFrameObject *frame);
11+
12+
PyAPI_FUNC(PyObject *) PyFrame_GetGlobals(PyFrameObject *frame);
13+
PyAPI_FUNC(PyObject *) PyFrame_GetBuiltins(PyFrameObject *frame);
14+
15+
PyAPI_FUNC(PyObject *) PyFrame_GetGenerator(PyFrameObject *frame);
16+
PyAPI_FUNC(int) PyFrame_GetLasti(PyFrameObject *frame);
17+

Include/pyframe.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ PyAPI_FUNC(int) PyFrame_GetLineNumber(PyFrameObject *);
1414

1515
PyAPI_FUNC(PyCodeObject *) PyFrame_GetCode(PyFrameObject *frame);
1616

17+
#ifndef Py_LIMITED_API
18+
# define Py_CPYTHON_PYFRAME_H
19+
# include "cpython/pyframe.h"
20+
# undef Py_CPYTHON_PYFRAME_H
21+
#endif
22+
1723
#ifdef __cplusplus
1824
}
1925
#endif

Makefile.pre.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,7 @@ PYTHON_HEADERS= \
15761576
$(srcdir)/Include/cpython/pydebug.h \
15771577
$(srcdir)/Include/cpython/pyerrors.h \
15781578
$(srcdir)/Include/cpython/pyfpe.h \
1579+
$(srcdir)/Include/cpython/pyframe.h \
15791580
$(srcdir)/Include/cpython/pylifecycle.h \
15801581
$(srcdir)/Include/cpython/pymem.h \
15811582
$(srcdir)/Include/cpython/pystate.h \
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
The following frame functions and type are now directly available with
2+
``#include <Python.h>``, it's no longer needed to add ``#include
3+
<frameobject.h>``:
4+
5+
* :c:func:`PyFrame_Check`
6+
* :c:func:`PyFrame_GetBack`
7+
* :c:func:`PyFrame_GetBuiltins`
8+
* :c:func:`PyFrame_GetGenerator`
9+
* :c:func:`PyFrame_GetGlobals`
10+
* :c:func:`PyFrame_GetLasti`
11+
* :c:func:`PyFrame_GetLocals`
12+
* :c:type:`PyFrame_Type`
13+
14+
Patch by Victor Stinner.

Modules/_ctypes/callbacks.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#endif
1111

1212
#include "pycore_call.h" // _PyObject_CallNoArgs()
13-
#include "frameobject.h"
1413

1514
#include <stdbool.h>
1615

Modules/_testcapimodule.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#define PY_SSIZE_T_CLEAN
2222

2323
#include "Python.h"
24-
#include "frameobject.h" // PyFrame_Check()
2524
#include "datetime.h" // PyDateTimeAPI
2625
#include "marshal.h" // PyMarshal_WriteLongToFile
2726
#include "structmember.h" // PyMemberDef

Modules/_xxsubinterpretersmodule.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#endif
77

88
#include "Python.h"
9-
#include "frameobject.h"
109
#include "pycore_frame.h"
1110
#include "pycore_pystate.h" // _PyThreadState_GET()
1211
#include "pycore_interpreteridobject.h"

Modules/faulthandler.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
#include "pycore_signal.h" // Py_NSIG
66
#include "pycore_traceback.h" // _Py_DumpTracebackThreads
77

8-
#include "frameobject.h"
9-
108
#include <object.h>
119
#include <signal.h>
1210
#include <signal.h>

0 commit comments

Comments
 (0)