Skip to content

Commit c45dbe9

Browse files
authored
bpo-41078: Add pycore_list.h internal header file (GH-21057)
* Move _PyList_ITEMS() to pycore_list.h. * The C extension "_heapq" is now built with Py_BUILD_CORE_MODULE macro defined to access the internal C API.
1 parent 384621c commit c45dbe9

File tree

8 files changed

+31
-4
lines changed

8 files changed

+31
-4
lines changed

Include/cpython/listobject.h

-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,3 @@ PyAPI_FUNC(void) _PyList_DebugMallocStats(FILE *out);
3232
#define PyList_GET_ITEM(op, i) (_PyList_CAST(op)->ob_item[i])
3333
#define PyList_SET_ITEM(op, i, v) (_PyList_CAST(op)->ob_item[i] = (v))
3434
#define PyList_GET_SIZE(op) Py_SIZE(_PyList_CAST(op))
35-
#define _PyList_ITEMS(op) (_PyList_CAST(op)->ob_item)

Include/internal/pycore_list.h

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef Py_INTERNAL_LIST_H
2+
#define Py_INTERNAL_LIST_H
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
#ifndef Py_BUILD_CORE
8+
# error "this header requires Py_BUILD_CORE define"
9+
#endif
10+
11+
#include "listobject.h" // _PyList_CAST()
12+
13+
14+
#define _PyList_ITEMS(op) (_PyList_CAST(op)->ob_item)
15+
16+
17+
#ifdef __cplusplus
18+
}
19+
#endif
20+
#endif /* !Py_INTERNAL_LIST_H */

Makefile.pre.in

+1
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,7 @@ PYTHON_HEADERS= \
11101110
$(srcdir)/Include/internal/pycore_import.h \
11111111
$(srcdir)/Include/internal/pycore_initconfig.h \
11121112
$(srcdir)/Include/internal/pycore_interp.h \
1113+
$(srcdir)/Include/internal/pycore_list.h \
11131114
$(srcdir)/Include/internal/pycore_object.h \
11141115
$(srcdir)/Include/internal/pycore_pathconfig.h \
11151116
$(srcdir)/Include/internal/pycore_pyerrors.h \

Modules/Setup

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ _symtable symtablemodule.c
180180
#_datetime _datetimemodule.c # datetime accelerator
181181
#_zoneinfo _zoneinfo.c # zoneinfo accelerator
182182
#_bisect _bisectmodule.c # Bisection algorithms
183-
#_heapq _heapqmodule.c # Heap queue algorithm
183+
#_heapq _heapqmodule.c -DPy_BUILD_CORE_MODULE # Heap queue algorithm
184184
#_asyncio _asynciomodule.c # Fast asyncio Future
185185
#_json -I$(srcdir)/Include/internal -DPy_BUILD_CORE_BUILTIN _json.c # _json speedups
186186
#_statistics _statisticsmodule.c # statistics accelerator

Modules/_heapqmodule.c

+2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ annotated by François Pinard, and converted to C by Raymond Hettinger.
77
*/
88

99
#include "Python.h"
10+
#include "pycore_list.h" // _PyList_ITEMS()
1011

1112
#include "clinic/_heapqmodule.c.h"
1213

14+
1315
/*[clinic input]
1416
module _heapq
1517
[clinic start generated code]*/

PCbuild/pythoncore.vcxproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@
165165
<ClInclude Include="..\Include\internal\pycore_abstract.h" />
166166
<ClInclude Include="..\Include\internal\pycore_accu.h" />
167167
<ClInclude Include="..\Include\internal\pycore_atomic.h" />
168-
<ClInclude Include="..\Include\internal\pycore_bytes_methods.h" />
169168
<ClInclude Include="..\Include\internal\pycore_bitutils.h" />
169+
<ClInclude Include="..\Include\internal\pycore_bytes_methods.h" />
170170
<ClInclude Include="..\Include\internal\pycore_call.h" />
171171
<ClInclude Include="..\Include\internal\pycore_ceval.h" />
172172
<ClInclude Include="..\Include\internal\pycore_code.h" />
@@ -181,6 +181,7 @@
181181
<ClInclude Include="..\Include\internal\pycore_import.h" />
182182
<ClInclude Include="..\Include\internal\pycore_initconfig.h" />
183183
<ClInclude Include="..\Include\internal\pycore_interp.h" />
184+
<ClInclude Include="..\Include\internal\pycore_list.h" />
184185
<ClInclude Include="..\Include\internal\pycore_object.h" />
185186
<ClInclude Include="..\Include\internal\pycore_pathconfig.h" />
186187
<ClInclude Include="..\Include\internal\pycore_pyerrors.h" />

PCbuild/pythoncore.vcxproj.filters

+3
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@
240240
<ClInclude Include="..\Include\internal\pycore_interp.h">
241241
<Filter>Include</Filter>
242242
</ClInclude>
243+
<ClInclude Include="..\Include\internal\pycore_list.h">
244+
<Filter>Include</Filter>
245+
</ClInclude>
243246
<ClInclude Include="..\Include\internal\pycore_object.h">
244247
<Filter>Include</Filter>
245248
</ClInclude>

setup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,8 @@ def detect_simple_extensions(self):
863863
# bisect
864864
self.add(Extension("_bisect", ["_bisectmodule.c"]))
865865
# heapq
866-
self.add(Extension("_heapq", ["_heapqmodule.c"]))
866+
self.add(Extension("_heapq", ["_heapqmodule.c"],
867+
extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
867868
# C-optimized pickle replacement
868869
self.add(Extension("_pickle", ["_pickle.c"],
869870
extra_compile_args=['-DPy_BUILD_CORE_MODULE']))

0 commit comments

Comments
 (0)