Skip to content

Commit 8e5de40

Browse files
authored
bpo-35134: Move classobject.h to Include/cpython/ (GH-28968)
Move classobject.h, context.h, genobject.h and longintrepr.h header files from Include/ to Include/cpython/. Remove redundant "#ifndef Py_LIMITED_API" in context.h. Remove explicit #include "longintrepr.h" in C files. It's not needed, Python.h already includes it.
1 parent 9ce9cfe commit 8e5de40

File tree

15 files changed

+39
-45
lines changed

15 files changed

+39
-45
lines changed

Doc/whatsnew/3.11.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,8 @@ Porting to Python 3.11
572572
header provides functions like ``printf()`` and ``fopen()``.
573573
(Contributed by Victor Stinner in :issue:`45434`.)
574574

575-
* The non-limited API files ``cellobject.h`` and ``funcobject.h`` have been
575+
* The non-limited API files ``cellobject.h``, ``classobject.h``, ``context.h``,
576+
``funcobject.h``, ``genobject.h`` and ``longintrepr.h`` have been
576577
moved to the ``Include/cpython`` directory. These files must not be included
577578
directly, as they are already included in ``Python.h``: :ref:`Include Files
578579
<api-includes>`. If they have been included directly, consider including

Include/Python.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
#include "bytesobject.h"
4747
#include "unicodeobject.h"
4848
#include "longobject.h"
49-
#include "longintrepr.h"
49+
#include "cpython/longintrepr.h"
5050
#include "boolobject.h"
5151
#include "floatobject.h"
5252
#include "complexobject.h"
@@ -61,7 +61,7 @@
6161
#include "methodobject.h"
6262
#include "moduleobject.h"
6363
#include "cpython/funcobject.h"
64-
#include "classobject.h"
64+
#include "cpython/classobject.h"
6565
#include "fileobject.h"
6666
#include "pycapsule.h"
6767
#include "code.h"
@@ -70,7 +70,8 @@
7070
#include "sliceobject.h"
7171
#include "cpython/cellobject.h"
7272
#include "iterobject.h"
73-
#include "genobject.h"
73+
#include "pystate.h"
74+
#include "cpython/genobject.h"
7475
#include "descrobject.h"
7576
#include "genericaliasobject.h"
7677
#include "warnings.h"
@@ -83,8 +84,7 @@
8384
#include "pyerrors.h"
8485
#include "cpython/initconfig.h"
8586
#include "pythread.h"
86-
#include "pystate.h"
87-
#include "context.h"
87+
#include "cpython/context.h"
8888
#include "modsupport.h"
8989
#include "compile.h"
9090
#include "pythonrun.h"

Include/classobject.h renamed to Include/cpython/classobject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,5 @@ PyAPI_FUNC(PyObject *) PyInstanceMethod_Function(PyObject *);
5353
#ifdef __cplusplus
5454
}
5555
#endif
56-
#endif /* !Py_CLASSOBJECT_H */
57-
#endif /* Py_LIMITED_API */
56+
#endif // !Py_CLASSOBJECT_H
57+
#endif // !Py_LIMITED_API

Include/context.h renamed to Include/cpython/context.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1+
#ifndef Py_LIMITED_API
12
#ifndef Py_CONTEXT_H
23
#define Py_CONTEXT_H
34
#ifdef __cplusplus
45
extern "C" {
56
#endif
67

7-
#ifndef Py_LIMITED_API
8-
9-
108
PyAPI_DATA(PyTypeObject) PyContext_Type;
119
typedef struct _pycontextobject PyContext;
1210

@@ -73,9 +71,8 @@ PyAPI_FUNC(int) PyContextVar_Reset(PyObject *var, PyObject *token);
7371
PyAPI_FUNC(PyObject *) _PyContext_NewHamtForTests(void);
7472

7573

76-
#endif /* !Py_LIMITED_API */
77-
7874
#ifdef __cplusplus
7975
}
8076
#endif
8177
#endif /* !Py_CONTEXT_H */
78+
#endif /* !Py_LIMITED_API */

Include/genobject.h renamed to Include/cpython/genobject.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/* Generator object interface */
32

43
#ifndef Py_LIMITED_API
@@ -8,8 +7,7 @@
87
extern "C" {
98
#endif
109

11-
#include "pystate.h" /* _PyErr_StackItem */
12-
#include "abstract.h" /* PySendResult */
10+
/* --- Generators --------------------------------------------------------- */
1311

1412
/* _PyGenObject_HEAD defines the initial segment of generator
1513
and coroutine objects. */
@@ -45,7 +43,9 @@ PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **);
4543
PyObject *_PyGen_yf(PyGenObject *);
4644
PyAPI_FUNC(void) _PyGen_Finalize(PyObject *self);
4745

48-
#ifndef Py_LIMITED_API
46+
47+
/* --- PyCoroObject ------------------------------------------------------- */
48+
4949
typedef struct {
5050
_PyGenObject_HEAD(cr)
5151
PyObject *cr_origin;
@@ -59,7 +59,8 @@ PyObject *_PyCoro_GetAwaitableIter(PyObject *o);
5959
PyAPI_FUNC(PyObject *) PyCoro_New(PyFrameObject *,
6060
PyObject *name, PyObject *qualname);
6161

62-
/* Asynchronous Generators */
62+
63+
/* --- Asynchronous Generators -------------------------------------------- */
6364

6465
typedef struct {
6566
_PyGenObject_HEAD(ag)
@@ -89,7 +90,6 @@ PyAPI_FUNC(PyObject *) PyAsyncGen_New(PyFrameObject *,
8990

9091
PyObject *_PyAsyncGenValueWrapperNew(PyObject *);
9192

92-
#endif
9393

9494
#undef _PyGenObject_HEAD
9595

File renamed without changes.

Makefile.pre.in

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,12 +1128,10 @@ PYTHON_HEADERS= \
11281128
$(srcdir)/Include/bytearrayobject.h \
11291129
$(srcdir)/Include/bytesobject.h \
11301130
$(srcdir)/Include/ceval.h \
1131-
$(srcdir)/Include/classobject.h \
11321131
$(srcdir)/Include/code.h \
11331132
$(srcdir)/Include/codecs.h \
11341133
$(srcdir)/Include/compile.h \
11351134
$(srcdir)/Include/complexobject.h \
1136-
$(srcdir)/Include/context.h \
11371135
$(srcdir)/Include/descrobject.h \
11381136
$(srcdir)/Include/dictobject.h \
11391137
$(srcdir)/Include/dynamic_annotations.h \
@@ -1144,13 +1142,11 @@ PYTHON_HEADERS= \
11441142
$(srcdir)/Include/fileutils.h \
11451143
$(srcdir)/Include/floatobject.h \
11461144
$(srcdir)/Include/frameobject.h \
1147-
$(srcdir)/Include/genobject.h \
11481145
$(srcdir)/Include/import.h \
11491146
$(srcdir)/Include/interpreteridobject.h \
11501147
$(srcdir)/Include/intrcheck.h \
11511148
$(srcdir)/Include/iterobject.h \
11521149
$(srcdir)/Include/listobject.h \
1153-
$(srcdir)/Include/longintrepr.h \
11541150
$(srcdir)/Include/longobject.h \
11551151
$(srcdir)/Include/marshal.h \
11561152
$(srcdir)/Include/memoryobject.h \
@@ -1202,18 +1198,22 @@ PYTHON_HEADERS= \
12021198
$(srcdir)/Include/cpython/bytesobject.h \
12031199
$(srcdir)/Include/cpython/cellobject.h \
12041200
$(srcdir)/Include/cpython/ceval.h \
1201+
$(srcdir)/Include/cpython/classobject.h \
12051202
$(srcdir)/Include/cpython/code.h \
12061203
$(srcdir)/Include/cpython/compile.h \
1204+
$(srcdir)/Include/cpython/context.h \
12071205
$(srcdir)/Include/cpython/dictobject.h \
12081206
$(srcdir)/Include/cpython/fileobject.h \
12091207
$(srcdir)/Include/cpython/fileutils.h \
12101208
$(srcdir)/Include/cpython/floatobject.h \
12111209
$(srcdir)/Include/cpython/frameobject.h \
12121210
$(srcdir)/Include/cpython/funcobject.h \
1211+
$(srcdir)/Include/cpython/genobject.h \
12131212
$(srcdir)/Include/cpython/import.h \
12141213
$(srcdir)/Include/cpython/initconfig.h \
12151214
$(srcdir)/Include/cpython/interpreteridobject.h \
12161215
$(srcdir)/Include/cpython/listobject.h \
1216+
$(srcdir)/Include/cpython/longintrepr.h \
12171217
$(srcdir)/Include/cpython/methodobject.h \
12181218
$(srcdir)/Include/cpython/object.h \
12191219
$(srcdir)/Include/cpython/objimpl.h \
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
Move ``cellobject.h`` and ``funcobject.h`` header files from ``Include/`` to
1+
Move ``cellobject.h``, ``classobject.h``, ``context.h``, ``funcobject.h``,
2+
``genobject.h`` and ``longintrepr.h`` header files from ``Include/`` to
23
``Include/cpython/``. C extensions should only include the main ``<Python.h>``
34
header. Patch by Victor Stinner.

Modules/_decimal/_decimal.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
#include <Python.h>
3030
#include "pycore_pystate.h" // _PyThreadState_GET()
31-
#include "longintrepr.h"
3231
#include "complexobject.h"
3332
#include "mpdecimal.h"
3433

Objects/abstract.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "pycore_unionobject.h" // _PyUnion_Check()
1111
#include <ctype.h>
1212
#include <stddef.h> // offsetof()
13-
#include "longintrepr.h"
1413

1514

1615

Objects/boolobject.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include "Python.h"
44
#include "pycore_pyerrors.h" // _Py_FatalRefcountError()
5-
#include "longintrepr.h"
65

76
/* We define bool_repr to return "False" or "True" */
87

Objects/longobject.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "pycore_long.h" // __PyLong_GetSmallInt_internal()
99
#include "pycore_object.h" // _PyObject_InitVar()
1010
#include "pycore_pystate.h" // _Py_IsMainInterpreter()
11-
#include "longintrepr.h"
1211

1312
#include <ctype.h>
1413
#include <float.h>

PCbuild/pythoncore.vcxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,29 +116,31 @@
116116
<ClInclude Include="..\Include\bytearrayobject.h" />
117117
<ClInclude Include="..\Include\bytesobject.h" />
118118
<ClInclude Include="..\Include\ceval.h" />
119-
<ClInclude Include="..\Include\classobject.h" />
120119
<ClInclude Include="..\Include\code.h" />
121120
<ClInclude Include="..\Include\codecs.h" />
122121
<ClInclude Include="..\Include\compile.h" />
123122
<ClInclude Include="..\Include\complexobject.h" />
124-
<ClInclude Include="..\Include\context.h" />
125123
<ClInclude Include="..\Include\cpython\abstract.h" />
126124
<ClInclude Include="..\Include\cpython\bytearrayobject.h" />
127125
<ClInclude Include="..\Include\cpython\bytesobject.h" />
128126
<ClInclude Include="..\Include\cpython\cellobject.h" />
129127
<ClInclude Include="..\Include\cpython\ceval.h" />
128+
<ClInclude Include="..\Include\cpython\classobject.h" />
130129
<ClInclude Include="..\Include\cpython\code.h" />
131130
<ClInclude Include="..\Include\cpython\compile.h" />
131+
<ClInclude Include="..\Include\cpython\context.h" />
132132
<ClInclude Include="..\Include\cpython\dictobject.h" />
133133
<ClInclude Include="..\Include\cpython\fileobject.h" />
134134
<ClInclude Include="..\Include\cpython\fileutils.h" />
135135
<ClInclude Include="..\Include\cpython\floatobject.h" />
136136
<ClInclude Include="..\Include\cpython\frameobject.h" />
137137
<ClInclude Include="..\Include\cpython\funcobject.h" />
138+
<ClInclude Include="..\Include\cpython\genobject.h" />
138139
<ClInclude Include="..\Include\cpython\import.h" />
139140
<ClInclude Include="..\Include\cpython\initconfig.h" />
140141
<ClInclude Include="..\Include\cpython\interpreteridobject.h" />
141142
<ClInclude Include="..\Include\cpython\listobject.h" />
143+
<ClInclude Include="..\Include\cpython\longintrepr.h" />
142144
<ClInclude Include="..\Include\cpython\methodobject.h" />
143145
<ClInclude Include="..\Include\cpython\object.h" />
144146
<ClInclude Include="..\Include\cpython\objimpl.h" />
@@ -170,7 +172,6 @@
170172
<ClInclude Include="..\Include\fileutils.h" />
171173
<ClInclude Include="..\Include\floatobject.h" />
172174
<ClInclude Include="..\Include\frameobject.h" />
173-
<ClInclude Include="..\Include\genobject.h" />
174175
<ClInclude Include="..\Include\import.h" />
175176
<ClInclude Include="..\Include\internal\pycore_abstract.h" />
176177
<ClInclude Include="..\Include\internal\pycore_accu.h" />
@@ -224,7 +225,6 @@
224225
<ClInclude Include="..\Include\intrcheck.h" />
225226
<ClInclude Include="..\Include\iterobject.h" />
226227
<ClInclude Include="..\Include\listobject.h" />
227-
<ClInclude Include="..\Include\longintrepr.h" />
228228
<ClInclude Include="..\Include\longobject.h" />
229229
<ClInclude Include="..\Include\marshal.h" />
230230
<ClInclude Include="..\Include\memoryobject.h" />

PCbuild/pythoncore.vcxproj.filters

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@
5454
<ClInclude Include="..\Include\ceval.h">
5555
<Filter>Include</Filter>
5656
</ClInclude>
57-
<ClInclude Include="..\Include\classobject.h">
58-
<Filter>Include</Filter>
59-
</ClInclude>
6057
<ClInclude Include="..\Include\code.h">
6158
<Filter>Include</Filter>
6259
</ClInclude>
@@ -69,9 +66,6 @@
6966
<ClInclude Include="..\Include\complexobject.h">
7067
<Filter>Include</Filter>
7168
</ClInclude>
72-
<ClInclude Include="..\Include\context.h">
73-
<Filter>Include</Filter>
74-
</ClInclude>
7569
<ClInclude Include="..\Include\datetime.h">
7670
<Filter>Include</Filter>
7771
</ClInclude>
@@ -105,9 +99,6 @@
10599
<ClInclude Include="..\Include\frameobject.h">
106100
<Filter>Include</Filter>
107101
</ClInclude>
108-
<ClInclude Include="..\Include\genobject.h">
109-
<Filter>Include</Filter>
110-
</ClInclude>
111102
<ClInclude Include="..\Include\import.h">
112103
<Filter>Include</Filter>
113104
</ClInclude>
@@ -120,9 +111,6 @@
120111
<ClInclude Include="..\Include\listobject.h">
121112
<Filter>Include</Filter>
122113
</ClInclude>
123-
<ClInclude Include="..\Include\longintrepr.h">
124-
<Filter>Include</Filter>
125-
</ClInclude>
126114
<ClInclude Include="..\Include\longobject.h">
127115
<Filter>Include</Filter>
128116
</ClInclude>
@@ -375,12 +363,18 @@
375363
<ClInclude Include="..\Include\cpython\ceval.h">
376364
<Filter>Include\cpython</Filter>
377365
</ClInclude>
366+
<ClInclude Include="..\Include\cpython\classobject.h">
367+
<Filter>Include\cpython</Filter>
368+
</ClInclude>
378369
<ClInclude Include="..\Include\cpython\code.h">
379370
<Filter>Include\cpython</Filter>
380371
</ClInclude>
381372
<ClInclude Include="..\Include\cpython\compile.h">
382373
<Filter>Include</Filter>
383374
</ClInclude>
375+
<ClInclude Include="..\Include\cpython\context.h">
376+
<Filter>Include\cpython</Filter>
377+
</ClInclude>
384378
<ClInclude Include="..\Include\cpython\dictobject.h">
385379
<Filter>Include\cpython</Filter>
386380
</ClInclude>
@@ -399,6 +393,9 @@
399393
<ClInclude Include="..\Include\cpython\listobject.h">
400394
<Filter>Include\cpython</Filter>
401395
</ClInclude>
396+
<ClInclude Include="..\Include\cpython\longintrepr.h">
397+
<Filter>Include</Filter>
398+
</ClInclude>
402399
<ClInclude Include="..\Include\cpython\odictobject.h">
403400
<Filter>Include</Filter>
404401
</ClInclude>
@@ -456,6 +453,9 @@
456453
<ClInclude Include="..\Include\cpython\funcobject.h">
457454
<Filter>Include\cpython</Filter>
458455
</ClInclude>
456+
<ClInclude Include="..\Include\cpython\genobject.h">
457+
<Filter>Include</Filter>
458+
</ClInclude>
459459
<ClInclude Include="..\Include\cpython\interpreteridobject.h">
460460
<Filter>Include\cpython</Filter>
461461
</ClInclude>

Python/marshal.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "pycore_code.h" // _PyCode_New()
1414
#include "pycore_floatobject.h" // _PyFloat_Pack8()
1515
#include "pycore_hashtable.h" // _Py_hashtable_t
16-
#include "longintrepr.h"
1716
#include "code.h"
1817
#include "marshal.h" // Py_MARSHAL_VERSION
1918

0 commit comments

Comments
 (0)