diff options
author | Victor Stinner <vstinner@python.org> | 2022-06-19 10:02:33 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-19 10:02:33 (GMT) |
commit | 27b989403356ccdd47545a93aeab8434e9c69f21 (patch) | |
tree | 731c6554ce03b81ed4fca91035ddad1efec632a6 | |
parent | 2664d9aacf25aa18e1753e57f80f345ed9bd31e0 (diff) | |
download | cpython-27b989403356ccdd47545a93aeab8434e9c69f21.zip cpython-27b989403356ccdd47545a93aeab8434e9c69f21.tar.gz cpython-27b989403356ccdd47545a93aeab8434e9c69f21.tar.bz2 |
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.
-rw-r--r-- | Doc/whatsnew/3.11.rst | 16 | ||||
-rw-r--r-- | Include/cpython/frameobject.h | 13 | ||||
-rw-r--r-- | Include/cpython/pyframe.h | 17 | ||||
-rw-r--r-- | Include/pyframe.h | 6 | ||||
-rw-r--r-- | Makefile.pre.in | 1 | ||||
-rw-r--r-- | Misc/NEWS.d/next/C API/2022-06-17-13-41-38.gh-issue-93937.uKVTEh.rst | 14 | ||||
-rw-r--r-- | Modules/_ctypes/callbacks.c | 1 | ||||
-rw-r--r-- | Modules/_testcapimodule.c | 1 | ||||
-rw-r--r-- | Modules/_xxsubinterpretersmodule.c | 1 | ||||
-rw-r--r-- | Modules/faulthandler.c | 2 | ||||
-rw-r--r-- | Modules/pyexpat.c | 1 | ||||
-rw-r--r-- | Objects/object.c | 1 | ||||
-rw-r--r-- | Objects/typeobject.c | 1 | ||||
-rw-r--r-- | PCbuild/pythoncore.vcxproj | 1 | ||||
-rw-r--r-- | PCbuild/pythoncore.vcxproj.filters | 3 | ||||
-rw-r--r-- | Python/_warnings.c | 1 | ||||
-rw-r--r-- | Python/ceval.c | 1 | ||||
-rw-r--r-- | Python/frame.c | 2 | ||||
-rw-r--r-- | Python/suggestions.c | 1 | ||||
-rw-r--r-- | Python/sysmodule.c | 2 | ||||
-rw-r--r-- | Python/traceback.c | 3 |
21 files changed, 61 insertions, 28 deletions
diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 8075a72..256d582 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -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 ---------- diff --git a/Include/cpython/frameobject.h b/Include/cpython/frameobject.h index a509e2c..4e19535 100644 --- a/Include/cpython/frameobject.h +++ b/Include/cpython/frameobject.h @@ -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 index 0000000..1dc634c --- /dev/null +++ b/Include/cpython/pyframe.h @@ -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); + diff --git a/Include/pyframe.h b/Include/pyframe.h index feac16f..13d5231 100644 --- a/Include/pyframe.h +++ b/Include/pyframe.h @@ -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 diff --git a/Makefile.pre.in b/Makefile.pre.in index f9bc973..eaaab5e 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -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 index 0000000..c0a0745 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2022-06-17-13-41-38.gh-issue-93937.uKVTEh.rst @@ -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. diff --git a/Modules/_ctypes/callbacks.c b/Modules/_ctypes/callbacks.c index 220b612..2a668c0 100644 --- a/Modules/_ctypes/callbacks.c +++ b/Modules/_ctypes/callbacks.c @@ -10,7 +10,6 @@ #endif #include "pycore_call.h" // _PyObject_CallNoArgs() -#include "frameobject.h" #include <stdbool.h> diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 54957db..8bf4de7 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -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 diff --git a/Modules/_xxsubinterpretersmodule.c b/Modules/_xxsubinterpretersmodule.c index eed9a8a..f40601a 100644 --- a/Modules/_xxsubinterpretersmodule.c +++ b/Modules/_xxsubinterpretersmodule.c @@ -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" diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c index d33cd58..b362687 100644 --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -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> diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c index b8535df..6783473 100644 --- a/Modules/pyexpat.c +++ b/Modules/pyexpat.c @@ -2,7 +2,6 @@ #include <ctype.h> #include "structmember.h" // PyMemberDef -#include "frameobject.h" #include "expat.h" #include "pyexpat.h" diff --git a/Objects/object.c b/Objects/object.c index 49b1cba..75aee90 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -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 diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 1236acd..40df69e 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -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 diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index 2e00fa9..4248fcd 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -167,6 +167,7 @@ <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" /> diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters index 9c2920c..903444b 100644 --- a/PCbuild/pythoncore.vcxproj.filters +++ b/PCbuild/pythoncore.vcxproj.filters @@ -435,6 +435,9 @@ <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> diff --git a/Python/_warnings.c b/Python/_warnings.c index 085ca45..601dae8 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -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" diff --git a/Python/ceval.c b/Python/ceval.c index 44e4ffe..77f80b9 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -28,7 +28,6 @@ #include "pycore_dict.h" #include "dictobject.h" -#include "frameobject.h" #include "pycore_frame.h" #include "opcode.h" #include "pydtrace.h" diff --git a/Python/frame.c b/Python/frame.c index 3573f54..9eaf41d 100644 --- a/Python/frame.c +++ b/Python/frame.c @@ -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" diff --git a/Python/suggestions.c b/Python/suggestions.c index b84acaa..c336ec8 100644 --- a/Python/suggestions.c +++ b/Python/suggestions.c @@ -1,5 +1,4 @@ #include "Python.h" -#include "frameobject.h" #include "pycore_frame.h" #include "pycore_pyerrors.h" diff --git a/Python/sysmodule.c b/Python/sysmodule.c index b9cae15..8a9a584 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -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 diff --git a/Python/traceback.c b/Python/traceback.c index e76c9aa..439689b 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -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 |