Skip to content

Commit

Permalink
gh-93937, C API: Move PyFrame_GetBack() to Python.h (#93938)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vstinner committed Jun 19, 2022
1 parent 2664d9a commit 27b9894
Show file tree
Hide file tree
Showing 21 changed files with 61 additions and 28 deletions.
16 changes: 15 additions & 1 deletion Doc/whatsnew/3.11.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
----------

Expand Down
13 changes: 0 additions & 13 deletions Include/cpython/frameobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);

Expand All @@ -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);
17 changes: 17 additions & 0 deletions Include/cpython/pyframe.h
Original file line number Diff line number Diff line change
@@ -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);

6 changes: 6 additions & 0 deletions Include/pyframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
1 change: 0 additions & 1 deletion Modules/_ctypes/callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#endif

#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "frameobject.h"

#include <stdbool.h>

Expand Down
1 change: 0 additions & 1 deletion Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion Modules/_xxsubinterpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions Modules/faulthandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 0 additions & 1 deletion Modules/pyexpat.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <ctype.h>

#include "structmember.h" // PyMemberDef
#include "frameobject.h"
#include "expat.h"

#include "pyexpat.h"
Expand Down
1 change: 0 additions & 1 deletion Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions PCbuild/pythoncore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
3 changes: 3 additions & 0 deletions PCbuild/pythoncore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 0 additions & 1 deletion Python/_warnings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
1 change: 0 additions & 1 deletion Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

#include "pycore_dict.h"
#include "dictobject.h"
#include "frameobject.h"
#include "pycore_frame.h"
#include "opcode.h"
#include "pydtrace.h"
Expand Down
2 changes: 1 addition & 1 deletion Python/frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion Python/suggestions.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "Python.h"
#include "frameobject.h"
#include "pycore_frame.h"

#include "pycore_pyerrors.h"
Expand Down
2 changes: 1 addition & 1 deletion Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Python/traceback.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 27b9894

Please sign in to comment.