Skip to content

Commit 27b9894

Browse files
authored
gh-93937, C API: Move PyFrame_GetBack() to Python.h (#93938)
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.
1 parent 2664d9a commit 27b9894

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
@@ -1752,6 +1752,21 @@ Porting to Python 3.11
17521752
which are not available in the limited C API.
17531753
(Contributed by Victor Stinner in :issue:`46007`.)
17541754

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

17571772
* The :c:type:`PyFrameObject` structure members have been removed from the
@@ -1888,7 +1903,6 @@ Porting to Python 3.11
18881903
paths and then modify them, finish initialization and use :c:func:`PySys_GetObject`
18891904
to retrieve :data:`sys.path` as a Python list object and modify it directly.
18901905

1891-
18921906
Deprecated
18931907
----------
18941908

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
@@ -1567,6 +1567,7 @@ PYTHON_HEADERS= \
15671567
$(srcdir)/Include/cpython/pydebug.h \
15681568
$(srcdir)/Include/cpython/pyerrors.h \
15691569
$(srcdir)/Include/cpython/pyfpe.h \
1570+
$(srcdir)/Include/cpython/pyframe.h \
15701571
$(srcdir)/Include/cpython/pylifecycle.h \
15711572
$(srcdir)/Include/cpython/pymem.h \
15721573
$(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)