summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-06-22 17:39:32 +0200
committerGitHub <noreply@github.com>2020-06-22 17:39:32 +0200
commitc45dbe93b7094fe014442c198727ee38b25541c4 (patch)
tree9ee531ffa21bda6d8edfdcfdf046e75b98e597fa
parent384621c42f9102e31ba2c47feba144af09c989e5 (diff)
downloadcpython-git-c45dbe93b7094fe014442c198727ee38b25541c4.tar.gz
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.
-rw-r--r--Include/cpython/listobject.h1
-rw-r--r--Include/internal/pycore_list.h20
-rw-r--r--Makefile.pre.in1
-rw-r--r--Modules/Setup2
-rw-r--r--Modules/_heapqmodule.c2
-rw-r--r--PCbuild/pythoncore.vcxproj3
-rw-r--r--PCbuild/pythoncore.vcxproj.filters3
-rw-r--r--setup.py3
8 files changed, 31 insertions, 4 deletions
diff --git a/Include/cpython/listobject.h b/Include/cpython/listobject.h
index b1af5f6764..70b9d83d8a 100644
--- a/Include/cpython/listobject.h
+++ b/Include/cpython/listobject.h
@@ -32,4 +32,3 @@ PyAPI_FUNC(void) _PyList_DebugMallocStats(FILE *out);
#define PyList_GET_ITEM(op, i) (_PyList_CAST(op)->ob_item[i])
#define PyList_SET_ITEM(op, i, v) (_PyList_CAST(op)->ob_item[i] = (v))
#define PyList_GET_SIZE(op) Py_SIZE(_PyList_CAST(op))
-#define _PyList_ITEMS(op) (_PyList_CAST(op)->ob_item)
diff --git a/Include/internal/pycore_list.h b/Include/internal/pycore_list.h
new file mode 100644
index 0000000000..f18fb052c4
--- /dev/null
+++ b/Include/internal/pycore_list.h
@@ -0,0 +1,20 @@
+#ifndef Py_INTERNAL_LIST_H
+#define Py_INTERNAL_LIST_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef Py_BUILD_CORE
+# error "this header requires Py_BUILD_CORE define"
+#endif
+
+#include "listobject.h" // _PyList_CAST()
+
+
+#define _PyList_ITEMS(op) (_PyList_CAST(op)->ob_item)
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* !Py_INTERNAL_LIST_H */
diff --git a/Makefile.pre.in b/Makefile.pre.in
index a52a97f796..3428b9842a 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -1110,6 +1110,7 @@ PYTHON_HEADERS= \
$(srcdir)/Include/internal/pycore_import.h \
$(srcdir)/Include/internal/pycore_initconfig.h \
$(srcdir)/Include/internal/pycore_interp.h \
+ $(srcdir)/Include/internal/pycore_list.h \
$(srcdir)/Include/internal/pycore_object.h \
$(srcdir)/Include/internal/pycore_pathconfig.h \
$(srcdir)/Include/internal/pycore_pyerrors.h \
diff --git a/Modules/Setup b/Modules/Setup
index 5d428d5b8b..470bf6bc2e 100644
--- a/Modules/Setup
+++ b/Modules/Setup
@@ -180,7 +180,7 @@ _symtable symtablemodule.c
#_datetime _datetimemodule.c # datetime accelerator
#_zoneinfo _zoneinfo.c # zoneinfo accelerator
#_bisect _bisectmodule.c # Bisection algorithms
-#_heapq _heapqmodule.c # Heap queue algorithm
+#_heapq _heapqmodule.c -DPy_BUILD_CORE_MODULE # Heap queue algorithm
#_asyncio _asynciomodule.c # Fast asyncio Future
#_json -I$(srcdir)/Include/internal -DPy_BUILD_CORE_BUILTIN _json.c # _json speedups
#_statistics _statisticsmodule.c # statistics accelerator
diff --git a/Modules/_heapqmodule.c b/Modules/_heapqmodule.c
index 193478d79b..20468c28f2 100644
--- a/Modules/_heapqmodule.c
+++ b/Modules/_heapqmodule.c
@@ -7,9 +7,11 @@ annotated by François Pinard, and converted to C by Raymond Hettinger.
*/
#include "Python.h"
+#include "pycore_list.h" // _PyList_ITEMS()
#include "clinic/_heapqmodule.c.h"
+
/*[clinic input]
module _heapq
[clinic start generated code]*/
diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj
index 00714757f6..54e23c2c2b 100644
--- a/PCbuild/pythoncore.vcxproj
+++ b/PCbuild/pythoncore.vcxproj
@@ -165,8 +165,8 @@
<ClInclude Include="..\Include\internal\pycore_abstract.h" />
<ClInclude Include="..\Include\internal\pycore_accu.h" />
<ClInclude Include="..\Include\internal\pycore_atomic.h" />
- <ClInclude Include="..\Include\internal\pycore_bytes_methods.h" />
<ClInclude Include="..\Include\internal\pycore_bitutils.h" />
+ <ClInclude Include="..\Include\internal\pycore_bytes_methods.h" />
<ClInclude Include="..\Include\internal\pycore_call.h" />
<ClInclude Include="..\Include\internal\pycore_ceval.h" />
<ClInclude Include="..\Include\internal\pycore_code.h" />
@@ -181,6 +181,7 @@
<ClInclude Include="..\Include\internal\pycore_import.h" />
<ClInclude Include="..\Include\internal\pycore_initconfig.h" />
<ClInclude Include="..\Include\internal\pycore_interp.h" />
+ <ClInclude Include="..\Include\internal\pycore_list.h" />
<ClInclude Include="..\Include\internal\pycore_object.h" />
<ClInclude Include="..\Include\internal\pycore_pathconfig.h" />
<ClInclude Include="..\Include\internal\pycore_pyerrors.h" />
diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters
index ddcdaf4719..4ba0bc2ac3 100644
--- a/PCbuild/pythoncore.vcxproj.filters
+++ b/PCbuild/pythoncore.vcxproj.filters
@@ -240,6 +240,9 @@
<ClInclude Include="..\Include\internal\pycore_interp.h">
<Filter>Include</Filter>
</ClInclude>
+ <ClInclude Include="..\Include\internal\pycore_list.h">
+ <Filter>Include</Filter>
+ </ClInclude>
<ClInclude Include="..\Include\internal\pycore_object.h">
<Filter>Include</Filter>
</ClInclude>
diff --git a/setup.py b/setup.py
index 648e4e6a89..21a5a58981 100644
--- a/setup.py
+++ b/setup.py
@@ -863,7 +863,8 @@ class PyBuildExt(build_ext):
# bisect
self.add(Extension("_bisect", ["_bisectmodule.c"]))
# heapq
- self.add(Extension("_heapq", ["_heapqmodule.c"]))
+ self.add(Extension("_heapq", ["_heapqmodule.c"],
+ extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
# C-optimized pickle replacement
self.add(Extension("_pickle", ["_pickle.c"],
extra_compile_args=['-DPy_BUILD_CORE_MODULE']))