]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-93937, C API: Move PyFrame_GetBack() to Python.h (#93938) (#94000)
authorVictor Stinner <vstinner@python.org>
Mon, 20 Jun 2022 13:47:41 +0000 (15:47 +0200)
committerGitHub <noreply@github.com>
Mon, 20 Jun 2022 13:47:41 +0000 (15:47 +0200)
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 27b989403356ccdd47545a93aeab8434e9c69f21)

21 files changed:
Doc/whatsnew/3.11.rst
Include/cpython/frameobject.h
Include/cpython/pyframe.h [new file with mode: 0644]
Include/pyframe.h
Makefile.pre.in
Misc/NEWS.d/next/C API/2022-06-17-13-41-38.gh-issue-93937.uKVTEh.rst [new file with mode: 0644]
Modules/_ctypes/callbacks.c
Modules/_testcapimodule.c
Modules/_xxsubinterpretersmodule.c
Modules/faulthandler.c
Modules/pyexpat.c
Objects/object.c
Objects/typeobject.c
PCbuild/pythoncore.vcxproj
PCbuild/pythoncore.vcxproj.filters
Python/_warnings.c
Python/ceval.c
Python/frame.c
Python/suggestions.c
Python/sysmodule.c
Python/traceback.c

index 33ea8bf794ed2404b19bf1a4b56818e9393ce4da..0275b44d38db104b98040482e702a9aaaafef9ef 100644 (file)
@@ -1757,6 +1757,21 @@ Porting to Python 3.11
   which are not available in the limited C API.
   (Contributed by Victor Stinner in :issue:`46007`.)
 
+* The following frame functions and type are now directly available with
+  ``#include <Python.h>``, it's no longer needed to add
+  ``#include <frameobject.h>``:
+
+  * :c:func:`PyFrame_Check`
+  * :c:func:`PyFrame_GetBack`
+  * :c:func:`PyFrame_GetBuiltins`
+  * :c:func:`PyFrame_GetGenerator`
+  * :c:func:`PyFrame_GetGlobals`
+  * :c:func:`PyFrame_GetLasti`
+  * :c:func:`PyFrame_GetLocals`
+  * :c:type:`PyFrame_Type`
+
+  (Contributed by Victor Stinner in :gh:`93937`.)
+
 .. _pyframeobject-3.11-hiding:
 
 * The :c:type:`PyFrameObject` structure members have been removed from the
@@ -1893,7 +1908,6 @@ Porting to Python 3.11
   paths and then modify them, finish initialization and use :c:func:`PySys_GetObject`
   to retrieve :data:`sys.path` as a Python list object and modify it directly.
 
-
 Deprecated
 ----------
 
index 9cd711e43559a608db34ed5757e8a2d77b37b81c..4e19535c656f2cbef34238143c61aa120d6c9c5e 100644 (file)
@@ -6,10 +6,6 @@
 
 /* Standard object interface */
 
-PyAPI_DATA(PyTypeObject) PyFrame_Type;
-
-#define PyFrame_Check(op) Py_IS_TYPE(op, &PyFrame_Type)
-
 PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *,
                                         PyObject *, PyObject *);
 
@@ -31,12 +27,3 @@ PyAPI_FUNC(int) _PyFrame_IsEntryFrame(PyFrameObject *frame);
 
 PyAPI_FUNC(int) PyFrame_FastToLocalsWithError(PyFrameObject *f);
 PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *);
-
-PyAPI_FUNC(PyFrameObject *) PyFrame_GetBack(PyFrameObject *frame);
-PyAPI_FUNC(PyObject *) PyFrame_GetLocals(PyFrameObject *frame);
-
-PyAPI_FUNC(PyObject *) PyFrame_GetGlobals(PyFrameObject *frame);
-PyAPI_FUNC(PyObject *) PyFrame_GetBuiltins(PyFrameObject *frame);
-
-PyAPI_FUNC(PyObject *) PyFrame_GetGenerator(PyFrameObject *frame);
-PyAPI_FUNC(int) PyFrame_GetLasti(PyFrameObject *frame);
diff --git a/Include/cpython/pyframe.h b/Include/cpython/pyframe.h
new file mode 100644 (file)
index 0000000..1dc634c
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef Py_CPYTHON_PYFRAME_H
+#  error "this header file must not be included directly"
+#endif
+
+PyAPI_DATA(PyTypeObject) PyFrame_Type;
+
+#define PyFrame_Check(op) Py_IS_TYPE((op), &PyFrame_Type)
+
+PyAPI_FUNC(PyFrameObject *) PyFrame_GetBack(PyFrameObject *frame);
+PyAPI_FUNC(PyObject *) PyFrame_GetLocals(PyFrameObject *frame);
+
+PyAPI_FUNC(PyObject *) PyFrame_GetGlobals(PyFrameObject *frame);
+PyAPI_FUNC(PyObject *) PyFrame_GetBuiltins(PyFrameObject *frame);
+
+PyAPI_FUNC(PyObject *) PyFrame_GetGenerator(PyFrameObject *frame);
+PyAPI_FUNC(int) PyFrame_GetLasti(PyFrameObject *frame);
+
index feac16f69de698c2b4a2053abe30c2874c3e9562..13d52312ea966e43322950405d06440e0c988fd9 100644 (file)
@@ -14,6 +14,12 @@ PyAPI_FUNC(int) PyFrame_GetLineNumber(PyFrameObject *);
 
 PyAPI_FUNC(PyCodeObject *) PyFrame_GetCode(PyFrameObject *frame);
 
+#ifndef Py_LIMITED_API
+#  define Py_CPYTHON_PYFRAME_H
+#  include "cpython/pyframe.h"
+#  undef Py_CPYTHON_PYFRAME_H
+#endif
+
 #ifdef __cplusplus
 }
 #endif
index 803b75bdb3171b8efe54875c270d6702b6af2303..3b5f39427094aa4cf179b1f1499675ff0cb4556f 100644 (file)
@@ -1576,6 +1576,7 @@ PYTHON_HEADERS= \
                $(srcdir)/Include/cpython/pydebug.h \
                $(srcdir)/Include/cpython/pyerrors.h \
                $(srcdir)/Include/cpython/pyfpe.h \
+               $(srcdir)/Include/cpython/pyframe.h \
                $(srcdir)/Include/cpython/pylifecycle.h \
                $(srcdir)/Include/cpython/pymem.h \
                $(srcdir)/Include/cpython/pystate.h \
diff --git a/Misc/NEWS.d/next/C API/2022-06-17-13-41-38.gh-issue-93937.uKVTEh.rst b/Misc/NEWS.d/next/C API/2022-06-17-13-41-38.gh-issue-93937.uKVTEh.rst
new file mode 100644 (file)
index 0000000..c0a0745
--- /dev/null
@@ -0,0 +1,14 @@
+The following frame functions and type are now directly available with
+``#include <Python.h>``, it's no longer needed to add ``#include
+<frameobject.h>``:
+
+* :c:func:`PyFrame_Check`
+* :c:func:`PyFrame_GetBack`
+* :c:func:`PyFrame_GetBuiltins`
+* :c:func:`PyFrame_GetGenerator`
+* :c:func:`PyFrame_GetGlobals`
+* :c:func:`PyFrame_GetLasti`
+* :c:func:`PyFrame_GetLocals`
+* :c:type:`PyFrame_Type`
+
+Patch by Victor Stinner.
index e1e0225f67b341555a015319b43bc2c7e6961517..95b0912aecd75c2f5be6bdbd3b3b7f343041e413 100644 (file)
@@ -10,7 +10,6 @@
 #endif
 
 #include "pycore_call.h"          // _PyObject_CallNoArgs()
-#include "frameobject.h"
 
 #include <stdbool.h>
 
index a2d9ac807400b90d6249148312f8b29d99d286f5..1d557fe4df6f9e7dc3c33d5861ebf108ed11afd1 100644 (file)
@@ -21,7 +21,6 @@
 #define PY_SSIZE_T_CLEAN
 
 #include "Python.h"
-#include "frameobject.h"          // PyFrame_Check()
 #include "datetime.h"             // PyDateTimeAPI
 #include "marshal.h"              // PyMarshal_WriteLongToFile
 #include "structmember.h"         // PyMemberDef
index d1df00111cf54102ed1d754ad62b81e1b297d4d5..e5b96be8f68da837fcb6626a40691bd6d0e8ad81 100644 (file)
@@ -6,7 +6,6 @@
 #endif
 
 #include "Python.h"
-#include "frameobject.h"
 #include "pycore_frame.h"
 #include "pycore_pystate.h"       // _PyThreadState_GET()
 #include "pycore_interpreteridobject.h"
index 08c40834c45f20b424d712c32a86902b05fc8f80..3026bb6a3432aaa4e983ca44eae6ccb748906e37 100644 (file)
@@ -5,8 +5,6 @@
 #include "pycore_signal.h"        // Py_NSIG
 #include "pycore_traceback.h"     // _Py_DumpTracebackThreads
 
-#include "frameobject.h"
-
 #include <object.h>
 #include <signal.h>
 #include <signal.h>
index ad8148adae98beb76fb20a731787cd50d89fbc5f..12319ee675045d6b64250c54be994650bedbe62c 100644 (file)
@@ -2,7 +2,6 @@
 #include <ctype.h>
 
 #include "structmember.h"         // PyMemberDef
-#include "frameobject.h"
 #include "expat.h"
 
 #include "pyexpat.h"
index 303a22b6bfd01c5f4ab80c163b2da86573fb6b93..d9fa779462a9168854e0df90be782dc1d508cf32 100644 (file)
@@ -16,7 +16,6 @@
 #include "pycore_symtable.h"      // PySTEntry_Type
 #include "pycore_typeobject.h"    // _PyTypes_InitSlotDefs()
 #include "pycore_unionobject.h"   // _PyUnion_Type
-#include "frameobject.h"          // PyFrame_Type
 #include "pycore_interpreteridobject.h"  // _PyInterpreterID_Type
 
 #ifdef Py_LIMITED_API
index d95b850699ed8e1ff2f8d9870989d1a2202fe44a..1fcc045d3a2998ad6b144edefdca7184f7106f40 100644 (file)
@@ -11,7 +11,6 @@
 #include "pycore_pystate.h"       // _PyThreadState_GET()
 #include "pycore_typeobject.h"    // struct type_cache
 #include "pycore_unionobject.h"   // _Py_union_type_or
-#include "frameobject.h"          // PyFrameObject
 #include "pycore_frame.h"         // _PyInterpreterFrame
 #include "opcode.h"               // MAKE_CELL
 #include "structmember.h"         // PyMemberDef
index 3ce116d2babb08e003304da75e20c33433e7325a..a38040159e1fc8dde389a09bc66207258d54f6fe 100644 (file)
     <ClInclude Include="..\Include\cpython\pydebug.h" />
     <ClInclude Include="..\Include\cpython\pyerrors.h" />
     <ClInclude Include="..\Include\cpython\pyfpe.h" />
+    <ClInclude Include="..\Include\cpython\pyframe.h" />
     <ClInclude Include="..\Include\cpython\pylifecycle.h" />
     <ClInclude Include="..\Include\cpython\pymem.h" />
     <ClInclude Include="..\Include\cpython\pystate.h" />
index 542d551045686dbfaeb7081430a12201c0b87035..e3fe9271dd852faee53864e65fbce1afb35247a5 100644 (file)
     <ClInclude Include="..\Include\cpython\pymem.h">
       <Filter>Include\cpython</Filter>
     </ClInclude>
+    <ClInclude Include="..\Include\cpython\pyframe.h">
+      <Filter>Include\cpython</Filter>
+    </ClInclude>
     <ClInclude Include="..\Include\cpython\pylifecycle.h">
       <Filter>Include\cpython</Filter>
     </ClInclude>
index 942308b357e338188d6a475907a656b44cbb3322..4e2240006f6ed62d3b95e09f53333f5890f9069d 100644 (file)
@@ -4,7 +4,6 @@
 #include "pycore_long.h"          // _PyLong_GetZero()
 #include "pycore_pyerrors.h"
 #include "pycore_pystate.h"       // _PyThreadState_GET()
-#include "frameobject.h"          // PyFrame_GetBack()
 #include "pycore_frame.h"
 #include "clinic/_warnings.c.h"
 
index b8b27a815fb25c2be59d364d0a12511460d32069..03c7489e24cef79a295f20ff3076f058eff2ec07 100644 (file)
@@ -26,7 +26,6 @@
 
 #include "pycore_dict.h"
 #include "dictobject.h"
-#include "frameobject.h"
 #include "pycore_frame.h"
 #include "opcode.h"
 #include "pydtrace.h"
index c2da123a2bbc159bacc806db3dc876d82daea808..b6674edfd1e081446218f215f9fddbd13396735c 100644 (file)
@@ -1,7 +1,7 @@
 
 #include "Python.h"
 #include "frameobject.h"
-#include "pycore_code.h"           // stats
+#include "pycore_code.h"          // stats
 #include "pycore_frame.h"
 #include "pycore_object.h"        // _PyObject_GC_UNTRACK()
 #include "opcode.h"
index b84acaaed6b1fdb53b8e1fed9fb00ec854a3b030..c336ec8ffffc9c4151ed34c21774594d55b2a678 100644 (file)
@@ -1,5 +1,4 @@
 #include "Python.h"
-#include "frameobject.h"
 #include "pycore_frame.h"
 
 #include "pycore_pyerrors.h"
index 4f8b4cc17f2c1a6dc6726f37f02273c42e42ed2f..769864196036e86d551538d3d9f444e8d7a7946c 100644 (file)
@@ -31,7 +31,7 @@ Data members:
 #include "pycore_structseq.h"     // _PyStructSequence_InitType()
 #include "pycore_tuple.h"         // _PyTuple_FromArray()
 
-#include "frameobject.h"          // PyFrame_GetBack()
+#include "frameobject.h"          // PyFrame_FastToLocalsWithError()
 #include "pydtrace.h"
 #include "osdefs.h"               // DELIM
 #include "stdlib_module_names.h"  // _Py_stdlib_module_names
index 3ec0618af99f28c7789464886467c1ffc84b5aab..0c49a8c20a7f5418801ee3868588d5341ff69116 100644 (file)
@@ -3,7 +3,6 @@
 
 #include "Python.h"
 
-#include "frameobject.h"          // PyFrame_GetBack()
 #include "pycore_ast.h"           // asdl_seq_*
 #include "pycore_call.h"          // _PyObject_CallMethodFormat()
 #include "pycore_compile.h"       // _PyAST_Optimize
@@ -15,7 +14,9 @@
 #include "pycore_pyerrors.h"      // _PyErr_Fetch()
 #include "pycore_pystate.h"       // _PyThreadState_GET()
 #include "pycore_traceback.h"     // EXCEPTION_TB_HEADER
+
 #include "../Parser/pegen.h"      // _PyPegen_byte_offset_to_character_offset()
+#include "frameobject.h"          // PyFrame_New()
 #include "structmember.h"         // PyMemberDef
 #include "osdefs.h"               // SEP
 #ifdef HAVE_FCNTL_H