Skip to content

Commit 85addfb

Browse files
authored
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 <Python.h> header file. Python.h includes directly Include/cpython/code.h instead.
1 parent 5c4d1f6 commit 85addfb

File tree

14 files changed

+17
-33
lines changed

14 files changed

+17
-33
lines changed

Doc/whatsnew/3.11.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@ Porting to Python 3.11
12101210
explicitly include the header files after ``#include <Python.h>``.
12111211
(Contributed by Victor Stinner in :issue:`45434`.)
12121212

1213-
* The non-limited API files ``cellobject.h``, ``classobject.h``, ``context.h``,
1213+
* The non-limited API files ``cellobject.h``, ``classobject.h``, ``code.h``, ``context.h``,
12141214
``funcobject.h``, ``genobject.h`` and ``longintrepr.h`` have been moved to
12151215
the ``Include/cpython`` directory. Moreover, the ``eval.h`` header file was
12161216
removed. These files must not be included directly, as they are already

Include/Python.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
#include "cpython/classobject.h"
6969
#include "fileobject.h"
7070
#include "pycapsule.h"
71-
#include "code.h"
71+
#include "cpython/code.h"
7272
#include "pyframe.h"
7373
#include "traceback.h"
7474
#include "sliceobject.h"

Include/code.h

-18
This file was deleted.

Include/cpython/code.h

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
#ifndef Py_CPYTHON_CODE_H
2-
# error "this header file must not be included directly"
1+
/* Definitions for bytecode */
2+
3+
#ifndef Py_LIMITED_API
4+
#ifndef Py_CODE_H
5+
#define Py_CODE_H
6+
#ifdef __cplusplus
7+
extern "C" {
38
#endif
49

510
/* 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,
204209
void **extra);
205210
PyAPI_FUNC(int) _PyCode_SetExtra(PyObject *code, Py_ssize_t index,
206211
void *extra);
212+
213+
#ifdef __cplusplus
214+
}
215+
#endif
216+
#endif // !Py_CODE_H
217+
#endif // !Py_LIMITED_API

Makefile.pre.in

-1
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,6 @@ PYTHON_HEADERS= \
14501450
$(srcdir)/Include/bytearrayobject.h \
14511451
$(srcdir)/Include/bytesobject.h \
14521452
$(srcdir)/Include/ceval.h \
1453-
$(srcdir)/Include/code.h \
14541453
$(srcdir)/Include/codecs.h \
14551454
$(srcdir)/Include/compile.h \
14561455
$(srcdir)/Include/complexobject.h \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Remove the ``Include/code.h`` header file. C extensions should only include
2+
the main ``<Python.h>`` header file. Patch by Victor Stinner.

Objects/codeobject.c

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <stdbool.h>
22

33
#include "Python.h"
4-
#include "code.h"
54
#include "opcode.h"
65
#include "structmember.h" // PyMemberDef
76
#include "pycore_code.h" // _PyCodeConstructor

PCbuild/pythoncore.vcxproj

-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@
129129
<ClInclude Include="..\Include\bytearrayobject.h" />
130130
<ClInclude Include="..\Include\bytesobject.h" />
131131
<ClInclude Include="..\Include\ceval.h" />
132-
<ClInclude Include="..\Include\code.h" />
133132
<ClInclude Include="..\Include\codecs.h" />
134133
<ClInclude Include="..\Include\compile.h" />
135134
<ClInclude Include="..\Include\complexobject.h" />

PCbuild/pythoncore.vcxproj.filters

-3
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,6 @@
132132
<ClInclude Include="..\Include\objimpl.h">
133133
<Filter>Include</Filter>
134134
</ClInclude>
135-
<ClInclude Include="..\Include\opcode.h">
136-
<Filter>Include</Filter>
137-
</ClInclude>
138135
<ClInclude Include="..\Include\osdefs.h">
139136
<Filter>Include</Filter>
140137
</ClInclude>

Python/ceval.c

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "pycore_tuple.h" // _PyTuple_ITEMS()
2424
#include "pycore_emscripten_signal.h" // _Py_CHECK_EMSCRIPTEN_SIGNALS
2525

26-
#include "code.h"
2726
#include "pycore_dict.h"
2827
#include "dictobject.h"
2928
#include "frameobject.h"

Python/marshal.c

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "pycore_call.h" // _PyObject_CallNoArgs()
1313
#include "pycore_code.h" // _PyCode_New()
1414
#include "pycore_hashtable.h" // _Py_hashtable_t
15-
#include "code.h"
1615
#include "marshal.h" // Py_MARSHAL_VERSION
1716

1817
/*[clinic input]

Python/pythonrun.c

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
#include "token.h" // INDENT
2727
#include "errcode.h" // E_EOF
28-
#include "code.h" // PyCodeObject
2928
#include "marshal.h" // PyMarshal_ReadLongFromFile()
3029

3130
#ifdef MS_WINDOWS

Python/sysmodule.c

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Data members:
3131
#include "pycore_structseq.h" // _PyStructSequence_InitType()
3232
#include "pycore_tuple.h" // _PyTuple_FromArray()
3333

34-
#include "code.h"
3534
#include "frameobject.h" // PyFrame_GetBack()
3635
#include "pydtrace.h"
3736
#include "osdefs.h" // DELIM

Python/traceback.c

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#include "Python.h"
55

6-
#include "code.h" // PyCode_Addr2Line etc
76
#include "frameobject.h" // PyFrame_GetBack()
87
#include "pycore_ast.h" // asdl_seq_*
98
#include "pycore_call.h" // _PyObject_CallMethodFormat()

0 commit comments

Comments
 (0)