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

+15-1
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

-13
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

+17
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

+6
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

+1
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 \
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

-1
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

-1
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

-1
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

-2
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>

Modules/pyexpat.c

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include <ctype.h>
33

44
#include "structmember.h" // PyMemberDef
5-
#include "frameobject.h"
65
#include "expat.h"
76

87
#include "pyexpat.h"

Objects/object.c

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "pycore_symtable.h" // PySTEntry_Type
1717
#include "pycore_typeobject.h" // _PyTypes_InitSlotDefs()
1818
#include "pycore_unionobject.h" // _PyUnion_Type
19-
#include "frameobject.h" // PyFrame_Type
2019
#include "pycore_interpreteridobject.h" // _PyInterpreterID_Type
2120

2221
#ifdef Py_LIMITED_API

Objects/typeobject.c

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "pycore_pystate.h" // _PyThreadState_GET()
1212
#include "pycore_typeobject.h" // struct type_cache
1313
#include "pycore_unionobject.h" // _Py_union_type_or
14-
#include "frameobject.h" // PyFrameObject
1514
#include "pycore_frame.h" // _PyInterpreterFrame
1615
#include "opcode.h" // MAKE_CELL
1716
#include "structmember.h" // PyMemberDef

PCbuild/pythoncore.vcxproj

+1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@
167167
<ClInclude Include="..\Include\cpython\pydebug.h" />
168168
<ClInclude Include="..\Include\cpython\pyerrors.h" />
169169
<ClInclude Include="..\Include\cpython\pyfpe.h" />
170+
<ClInclude Include="..\Include\cpython\pyframe.h" />
170171
<ClInclude Include="..\Include\cpython\pylifecycle.h" />
171172
<ClInclude Include="..\Include\cpython\pymem.h" />
172173
<ClInclude Include="..\Include\cpython\pystate.h" />

PCbuild/pythoncore.vcxproj.filters

+3
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,9 @@
435435
<ClInclude Include="..\Include\cpython\pymem.h">
436436
<Filter>Include\cpython</Filter>
437437
</ClInclude>
438+
<ClInclude Include="..\Include\cpython\pyframe.h">
439+
<Filter>Include\cpython</Filter>
440+
</ClInclude>
438441
<ClInclude Include="..\Include\cpython\pylifecycle.h">
439442
<Filter>Include\cpython</Filter>
440443
</ClInclude>

Python/_warnings.c

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "pycore_long.h" // _PyLong_GetZero()
55
#include "pycore_pyerrors.h"
66
#include "pycore_pystate.h" // _PyThreadState_GET()
7-
#include "frameobject.h" // PyFrame_GetBack()
87
#include "pycore_frame.h"
98
#include "clinic/_warnings.c.h"
109

Python/ceval.c

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
#include "pycore_dict.h"
3030
#include "dictobject.h"
31-
#include "frameobject.h"
3231
#include "pycore_frame.h"
3332
#include "opcode.h"
3433
#include "pydtrace.h"

Python/frame.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "Python.h"
55
#include "frameobject.h"
6-
#include "pycore_code.h" // stats
6+
#include "pycore_code.h" // stats
77
#include "pycore_frame.h"
88
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
99
#include "opcode.h"

Python/suggestions.c

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "Python.h"
2-
#include "frameobject.h"
32
#include "pycore_frame.h"
43

54
#include "pycore_pyerrors.h"

Python/sysmodule.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Data members:
3131
#include "pycore_structseq.h" // _PyStructSequence_InitType()
3232
#include "pycore_tuple.h" // _PyTuple_FromArray()
3333

34-
#include "frameobject.h" // PyFrame_GetBack()
34+
#include "frameobject.h" // PyFrame_FastToLocalsWithError()
3535
#include "pydtrace.h"
3636
#include "osdefs.h" // DELIM
3737
#include "stdlib_module_names.h" // _Py_stdlib_module_names

Python/traceback.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#include "Python.h"
55

6-
#include "frameobject.h" // PyFrame_GetBack()
76
#include "pycore_ast.h" // asdl_seq_*
87
#include "pycore_call.h" // _PyObject_CallMethodFormat()
98
#include "pycore_compile.h" // _PyAST_Optimize
@@ -15,7 +14,9 @@
1514
#include "pycore_pyerrors.h" // _PyErr_Fetch()
1615
#include "pycore_pystate.h" // _PyThreadState_GET()
1716
#include "pycore_traceback.h" // EXCEPTION_TB_HEADER
17+
1818
#include "../Parser/pegen.h" // _PyPegen_byte_offset_to_character_offset()
19+
#include "frameobject.h" // PyFrame_New()
1920
#include "structmember.h" // PyMemberDef
2021
#include "osdefs.h" // SEP
2122
#ifdef HAVE_FCNTL_H

0 commit comments

Comments
 (0)