]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-93937, C API: Move PyFrame_GetBack() to Python.h (#93938)
authorVictor Stinner <vstinner@python.org>
Sun, 19 Jun 2022 10:02:33 +0000 (12:02 +0200)
committerGitHub <noreply@github.com>
Sun, 19 Jun 2022 10:02:33 +0000 (12:02 +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.

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 8075a726f61f34c1febd7ad0441d9fb7e1a46044..256d5822e5196eef24effe179226d6ced54407b8 100644 (file)
@@ -1752,6 +1752,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
@@ -1888,7 +1903,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 a509e2c58056871a8bbbdff303b05b1f2bf67e2b..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 f9bc973ba778450b7681ab90d5c3e6ab5b1f491b..eaaab5e0118f198e69a57f10670719ade1bb860f 100644 (file)
@@ -1567,6 +1567,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 220b6120dac52aeecb19aeeff4f2653b78b734ae..2a668c0ca0cc97d5a290fdefa406fde242937b36 100644 (file)
@@ -10,7 +10,6 @@
 #endif
 
 #include "pycore_call.h"          // _PyObject_CallNoArgs()
-#include "frameobject.h"
 
 #include <stdbool.h>
 
index 54957db89663e0b382001e6d268b22e876739a5f..8bf4de758fe932bc1c692a90e022f2fb468f127a 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 eed9a8a1d85d5846da3d566675b716130c6b7608..f40601ad3a1a7204b15769485fa5edc7a8547be4 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 d33cd58333ec100291c95bdd4af3b9ec7ff3ce04..b36268782bda9ff4b2ab9122b32fef6d21bbc069 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 b8535dfe7115a13919f5bf52314f69c6c4cc9a18..678347331ef4dde54eef674c23b30d5ae3b192bd 100644 (file)
@@ -2,7 +2,6 @@
 #include <ctype.h>
 
 #include "structmember.h"         // PyMemberDef
-#include "frameobject.h"
 #include "expat.h"
 
 #include "pyexpat.h"
index 49b1cba89b1d6ff53bd95666925cc36e0a4a14cd..75aee909a3b4965414245badb44ae79ce92fa042 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 1236acdcd1930bef2b2ea26120211e44d1a52f90..40df69e8b8315c2c2eb37619b5dce3edca325c80 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 2e00fa9a7735c23713e38788930cb3fb31cb544d..4248fcd7c52dc9e159700e23371af4634218f1da 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 9c2920cf2bd5059ee8a9e3228e7211412c0cf33e..903444bfe2bbd29e6c2748b52e1d3e4d535056d0 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 085ca4506baaed79ce032b548934009543fd4422..601dae8fb465584767e69d2955720674d3eed611 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 44e4ffecb5e3c475d31c679d097547d8228446cd..77f80b90b93c9baa11db54dee984bca97195fdd7 100644 (file)
@@ -28,7 +28,6 @@
 
 #include "pycore_dict.h"
 #include "dictobject.h"
-#include "frameobject.h"
 #include "pycore_frame.h"
 #include "opcode.h"
 #include "pydtrace.h"
index 3573f54ad63e9ba155d283c10744725a005dee4c..9eaf41d09a894ce014a7bc221e33d068d52b18b2 100644 (file)
@@ -3,7 +3,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 b9cae15568d0f5214617c118c30f06f9085450ff..8a9a58479aeccb025567db41872d1f961a9d7f42 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 e76c9aa1a14c5e89d6c18d770feff42a4fbca317..439689b32aea8ab833f72e50eaba700482064ba1 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