From 85addfb9c6496eb3d26082348cf5aca848c877ef Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 7 Apr 2022 02:29:52 +0200 Subject: [PATCH] bpo-35134: Remove the Include/code.h header file (GH-32385) Remove the Include/code.h header file. C extensions should only include the main header file. Python.h includes directly Include/cpython/code.h instead. --- Doc/whatsnew/3.11.rst | 2 +- Include/Python.h | 2 +- Include/code.h | 18 ------------------ Include/cpython/code.h | 15 +++++++++++++-- Makefile.pre.in | 1 - .../2022-04-07-00-53-51.bpo-35134.zSjIzk.rst | 2 ++ Objects/codeobject.c | 1 - PCbuild/pythoncore.vcxproj | 1 - PCbuild/pythoncore.vcxproj.filters | 3 --- Python/ceval.c | 1 - Python/marshal.c | 1 - Python/pythonrun.c | 1 - Python/sysmodule.c | 1 - Python/traceback.c | 1 - 14 files changed, 17 insertions(+), 33 deletions(-) delete mode 100644 Include/code.h create mode 100644 Misc/NEWS.d/next/C API/2022-04-07-00-53-51.bpo-35134.zSjIzk.rst diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 4c9b32d9a94..31cdf10f666 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1210,7 +1210,7 @@ Porting to Python 3.11 explicitly include the header files after ``#include ``. (Contributed by Victor Stinner in :issue:`45434`.) -* The non-limited API files ``cellobject.h``, ``classobject.h``, ``context.h``, +* The non-limited API files ``cellobject.h``, ``classobject.h``, ``code.h``, ``context.h``, ``funcobject.h``, ``genobject.h`` and ``longintrepr.h`` have been moved to the ``Include/cpython`` directory. Moreover, the ``eval.h`` header file was removed. These files must not be included directly, as they are already diff --git a/Include/Python.h b/Include/Python.h index 4dc2edb4dbb..52a7aac6ba6 100644 --- a/Include/Python.h +++ b/Include/Python.h @@ -68,7 +68,7 @@ #include "cpython/classobject.h" #include "fileobject.h" #include "pycapsule.h" -#include "code.h" +#include "cpython/code.h" #include "pyframe.h" #include "traceback.h" #include "sliceobject.h" diff --git a/Include/code.h b/Include/code.h deleted file mode 100644 index 0245c32bc25..00000000000 --- a/Include/code.h +++ /dev/null @@ -1,18 +0,0 @@ -/* Definitions for bytecode */ - -#ifndef Py_CODE_H -#define Py_CODE_H -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef Py_LIMITED_API -# define Py_CPYTHON_CODE_H -# include "cpython/code.h" -# undef Py_CPYTHON_CODE_H -#endif - -#ifdef __cplusplus -} -#endif -#endif /* !Py_CODE_H */ diff --git a/Include/cpython/code.h b/Include/cpython/code.h index 15767831793..6dc2290ffeb 100644 --- a/Include/cpython/code.h +++ b/Include/cpython/code.h @@ -1,5 +1,10 @@ -#ifndef Py_CPYTHON_CODE_H -# error "this header file must not be included directly" +/* Definitions for bytecode */ + +#ifndef Py_LIMITED_API +#ifndef Py_CODE_H +#define Py_CODE_H +#ifdef __cplusplus +extern "C" { #endif /* Each instruction in a code object is a fixed-width value, @@ -204,3 +209,9 @@ PyAPI_FUNC(int) _PyCode_GetExtra(PyObject *code, Py_ssize_t index, void **extra); PyAPI_FUNC(int) _PyCode_SetExtra(PyObject *code, Py_ssize_t index, void *extra); + +#ifdef __cplusplus +} +#endif +#endif // !Py_CODE_H +#endif // !Py_LIMITED_API diff --git a/Makefile.pre.in b/Makefile.pre.in index 2f61259e69b..cb6e962045a 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -1450,7 +1450,6 @@ PYTHON_HEADERS= \ $(srcdir)/Include/bytearrayobject.h \ $(srcdir)/Include/bytesobject.h \ $(srcdir)/Include/ceval.h \ - $(srcdir)/Include/code.h \ $(srcdir)/Include/codecs.h \ $(srcdir)/Include/compile.h \ $(srcdir)/Include/complexobject.h \ diff --git a/Misc/NEWS.d/next/C API/2022-04-07-00-53-51.bpo-35134.zSjIzk.rst b/Misc/NEWS.d/next/C API/2022-04-07-00-53-51.bpo-35134.zSjIzk.rst new file mode 100644 index 00000000000..93e6e321604 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2022-04-07-00-53-51.bpo-35134.zSjIzk.rst @@ -0,0 +1,2 @@ +Remove the ``Include/code.h`` header file. C extensions should only include +the main ```` header file. Patch by Victor Stinner. diff --git a/Objects/codeobject.c b/Objects/codeobject.c index 7d50b40ec45..e872b398e08 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -1,7 +1,6 @@ #include #include "Python.h" -#include "code.h" #include "opcode.h" #include "structmember.h" // PyMemberDef #include "pycore_code.h" // _PyCodeConstructor diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index 6e51e17194d..cbd39368601 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -129,7 +129,6 @@ - diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters index 5fe6a9de21c..70af3052221 100644 --- a/PCbuild/pythoncore.vcxproj.filters +++ b/PCbuild/pythoncore.vcxproj.filters @@ -132,9 +132,6 @@ Include - - Include - Include diff --git a/Python/ceval.c b/Python/ceval.c index 487e09bc664..5384aac5d6e 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -23,7 +23,6 @@ #include "pycore_tuple.h" // _PyTuple_ITEMS() #include "pycore_emscripten_signal.h" // _Py_CHECK_EMSCRIPTEN_SIGNALS -#include "code.h" #include "pycore_dict.h" #include "dictobject.h" #include "frameobject.h" diff --git a/Python/marshal.c b/Python/marshal.c index e7cf6553bd1..19abcc8ffe4 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -12,7 +12,6 @@ #include "pycore_call.h" // _PyObject_CallNoArgs() #include "pycore_code.h" // _PyCode_New() #include "pycore_hashtable.h" // _Py_hashtable_t -#include "code.h" #include "marshal.h" // Py_MARSHAL_VERSION /*[clinic input] diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 38ca952838a..d117b790dfd 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -25,7 +25,6 @@ #include "token.h" // INDENT #include "errcode.h" // E_EOF -#include "code.h" // PyCodeObject #include "marshal.h" // PyMarshal_ReadLongFromFile() #ifdef MS_WINDOWS diff --git a/Python/sysmodule.c b/Python/sysmodule.c index de4e10a7e11..ac44b803b23 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -31,7 +31,6 @@ Data members: #include "pycore_structseq.h" // _PyStructSequence_InitType() #include "pycore_tuple.h" // _PyTuple_FromArray() -#include "code.h" #include "frameobject.h" // PyFrame_GetBack() #include "pydtrace.h" #include "osdefs.h" // DELIM diff --git a/Python/traceback.c b/Python/traceback.c index 0d0eb954c23..488c1b17cf5 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -3,7 +3,6 @@ #include "Python.h" -#include "code.h" // PyCode_Addr2Line etc #include "frameobject.h" // PyFrame_GetBack() #include "pycore_ast.h" // asdl_seq_* #include "pycore_call.h" // _PyObject_CallMethodFormat()