From f1895fd9b91fc41d34e78c5c6a98e9d6d966f04e Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 17 Jun 2022 13:25:37 +0200 Subject: [PATCH] gh-93937, C API: Move PyFrame_GetBack() to Python.h Move the follow functions and type from frameobject.h to pyframe.h, so the standard 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. --- Doc/whatsnew/3.11.rst | 16 +++++++++++++++- Include/cpython/frameobject.h | 13 ------------- Include/cpython/pyframe.h | 17 +++++++++++++++++ Include/pyframe.h | 6 ++++++ Makefile.pre.in | 1 + ...022-06-17-13-41-38.gh-issue-93937.uKVTEh.rst | 14 ++++++++++++++ Modules/_ctypes/callbacks.c | 1 - Modules/_testcapimodule.c | 1 - Modules/_xxsubinterpretersmodule.c | 1 - Modules/faulthandler.c | 2 -- Modules/pyexpat.c | 1 - Objects/object.c | 1 - Objects/typeobject.c | 1 - PCbuild/pythoncore.vcxproj | 1 + PCbuild/pythoncore.vcxproj.filters | 3 +++ Python/_warnings.c | 1 - Python/ceval.c | 1 - Python/frame.c | 2 +- Python/suggestions.c | 1 - Python/sysmodule.c | 2 +- Python/traceback.c | 3 ++- 21 files changed, 61 insertions(+), 28 deletions(-) create mode 100644 Include/cpython/pyframe.h create mode 100644 Misc/NEWS.d/next/C API/2022-06-17-13-41-38.gh-issue-93937.uKVTEh.rst diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 8075a726f61f34..256d5822e5196e 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 ``, it's no longer needed to add + ``#include ``: + + * :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 a509e2c5805687..4e19535c656f2c 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 00000000000000..1dc634ccee9a27 --- /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 feac16f69de698..13d52312ea966e 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 f3c70b99c9e221..fadf61fdad2974 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -1564,6 +1564,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 00000000000000..c0a0745aa0dd25 --- /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 ``, it's no longer needed to add ``#include +``: + +* :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 220b6120dac52a..2a668c0ca0cc97 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 diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 54957db89663e0..8bf4de758fe932 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 eed9a8a1d85d58..f40601ad3a1a72 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 d33cd58333ec10..b36268782bda9f 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 #include #include diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c index b8535dfe7115a1..678347331ef4dd 100644 --- a/Modules/pyexpat.c +++ b/Modules/pyexpat.c @@ -2,7 +2,6 @@ #include #include "structmember.h" // PyMemberDef -#include "frameobject.h" #include "expat.h" #include "pyexpat.h" diff --git a/Objects/object.c b/Objects/object.c index 49b1cba89b1d6f..75aee909a3b496 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 db4682c69ed0e3..be57eb3bc4fb06 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 be76f1bc55859a..6ac926976ffc55 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -167,6 +167,7 @@ + diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters index 5573e0020491a6..78cd5d16009a3f 100644 --- a/PCbuild/pythoncore.vcxproj.filters +++ b/PCbuild/pythoncore.vcxproj.filters @@ -435,6 +435,9 @@ Include\cpython + + Include\cpython + Include\cpython diff --git a/Python/_warnings.c b/Python/_warnings.c index 085ca4506baaed..601dae8fb46558 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 ca3797c2160945..bfcd120b85bbdf 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 3573f54ad63e9b..9eaf41d09a894c 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 b84acaaed6b1fd..c336ec8ffffc9c 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 b9cae15568d0f5..8a9a58479aeccb 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 e76c9aa1a14c5e..439689b32aea8a 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