Skip to content

Commit

Permalink
bpo-35134: Remove the Include/code.h header file (GH-32385)
Browse files Browse the repository at this point in the history
Remove the Include/code.h header file. C extensions should only
include the main <Python.h> header file.

Python.h includes directly Include/cpython/code.h instead.
  • Loading branch information
vstinner authored Apr 7, 2022
1 parent 5c4d1f6 commit 85addfb
Show file tree
Hide file tree
Showing 14 changed files with 17 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Doc/whatsnew/3.11.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ Porting to Python 3.11
explicitly include the header files after ``#include <Python.h>``.
(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
Expand Down
2 changes: 1 addition & 1 deletion Include/Python.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 0 additions & 18 deletions Include/code.h

This file was deleted.

15 changes: 13 additions & 2 deletions Include/cpython/code.h
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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
1 change: 0 additions & 1 deletion Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Remove the ``Include/code.h`` header file. C extensions should only include
the main ``<Python.h>`` header file. Patch by Victor Stinner.
1 change: 0 additions & 1 deletion Objects/codeobject.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <stdbool.h>

#include "Python.h"
#include "code.h"
#include "opcode.h"
#include "structmember.h" // PyMemberDef
#include "pycore_code.h" // _PyCodeConstructor
Expand Down
1 change: 0 additions & 1 deletion PCbuild/pythoncore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@
<ClInclude Include="..\Include\bytearrayobject.h" />
<ClInclude Include="..\Include\bytesobject.h" />
<ClInclude Include="..\Include\ceval.h" />
<ClInclude Include="..\Include\code.h" />
<ClInclude Include="..\Include\codecs.h" />
<ClInclude Include="..\Include\compile.h" />
<ClInclude Include="..\Include\complexobject.h" />
Expand Down
3 changes: 0 additions & 3 deletions PCbuild/pythoncore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@
<ClInclude Include="..\Include\objimpl.h">
<Filter>Include</Filter>
</ClInclude>
<ClInclude Include="..\Include\opcode.h">
<Filter>Include</Filter>
</ClInclude>
<ClInclude Include="..\Include\osdefs.h">
<Filter>Include</Filter>
</ClInclude>
Expand Down
1 change: 0 additions & 1 deletion Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion Python/marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 0 additions & 1 deletion Python/pythonrun.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 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 "code.h" // PyCode_Addr2Line etc
#include "frameobject.h" // PyFrame_GetBack()
#include "pycore_ast.h" // asdl_seq_*
#include "pycore_call.h" // _PyObject_CallMethodFormat()
Expand Down

0 comments on commit 85addfb

Please sign in to comment.