]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-43974: Move Py_BUILD_CORE_MODULE into module code (GH-29157)
authorChristian Heimes <christian@python.org>
Fri, 22 Oct 2021 13:36:28 +0000 (16:36 +0300)
committerGitHub <noreply@github.com>
Fri, 22 Oct 2021 13:36:28 +0000 (15:36 +0200)
setup.py no longer defines Py_BUILD_CORE_MODULE. Instead every
module defines the macro before #include "Python.h" unless
Py_BUILD_CORE_BUILTIN is already defined.

Py_BUILD_CORE_BUILTIN is defined for every module that is built by
Modules/Setup.

The PR also simplifies Modules/Setup. Makefile and makesetup
already define Py_BUILD_CORE_BUILTIN and include Modules/internal
for us.

Signed-off-by: Christian Heimes <christian@python.org>
40 files changed:
Misc/NEWS.d/next/Build/2021-10-22-14-00-44.bpo-43974.HHZtbx.rst [new file with mode: 0644]
Modules/Setup
Modules/_abc.c
Modules/_asynciomodule.c
Modules/_blake2/blake2b_impl.c
Modules/_blake2/blake2module.c
Modules/_blake2/blake2s_impl.c
Modules/_ctypes/_ctypes.c
Modules/_ctypes/callbacks.c
Modules/_ctypes/cfield.c
Modules/_ctypes/stgdict.c
Modules/_cursesmodule.c
Modules/_datetimemodule.c
Modules/_decimal/_decimal.c
Modules/_hashopenssl.c
Modules/_heapqmodule.c
Modules/_json.c
Modules/_lsprof.c
Modules/_math.c
Modules/_pickle.c
Modules/_posixsubprocess.c
Modules/_queuemodule.c
Modules/_randommodule.c
Modules/_sha3/sha3module.c
Modules/_struct.c
Modules/_testinternalcapi.c
Modules/_testmultiphase.c
Modules/_xxsubinterpretersmodule.c
Modules/_zoneinfo.c
Modules/arraymodule.c
Modules/binascii.c
Modules/cmathmodule.c
Modules/mathmodule.c
Modules/md5module.c
Modules/sha1module.c
Modules/sha256module.c
Modules/sha512module.c
Modules/unicodedata.c
PCbuild/pyproject.props
setup.py

diff --git a/Misc/NEWS.d/next/Build/2021-10-22-14-00-44.bpo-43974.HHZtbx.rst b/Misc/NEWS.d/next/Build/2021-10-22-14-00-44.bpo-43974.HHZtbx.rst
new file mode 100644 (file)
index 0000000..728a095
--- /dev/null
@@ -0,0 +1,2 @@
+``setup.py`` no longer defines ``Py_BUILD_CORE_MODULE``. Instead every
+module, that uses the internal API, defines the macro.
index a4440dfb6fc9dd4985d3a906a22c949ad5510769..a5b1a7b9c14afad982f4195d3e3e26fde9bfefe0 100644 (file)
@@ -99,26 +99,26 @@ PYTHONPATH=$(COREPYTHONPATH)
 # cannot be built as shared!
 
 _collections _collectionsmodule.c
-_abc -DPy_BUILD_CORE_BUILTIN _abc.c
+_abc _abc.c
 _codecs _codecsmodule.c
-_functools -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal _functoolsmodule.c
-_io -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal -I$(srcdir)/Modules/_io _io/_iomodule.c _io/iobase.c _io/fileio.c _io/bytesio.c _io/bufferedio.c _io/textio.c _io/stringio.c
-_locale -DPy_BUILD_CORE_BUILTIN _localemodule.c  # -lintl
-_operator -DPy_BUILD_CORE_BUILTIN _operator.c
-_signal -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal signalmodule.c
-_sre -DPy_BUILD_CORE_BUILTIN _sre.c
+_functools _functoolsmodule.c
+_io -I$(srcdir)/Modules/_io _io/_iomodule.c _io/iobase.c _io/fileio.c _io/bytesio.c _io/bufferedio.c _io/textio.c _io/stringio.c
+_locale _localemodule.c  # -lintl
+_operator _operator.c
+_signal signalmodule.c
+_sre _sre.c
 _stat _stat.c
 _symtable symtablemodule.c  # setup.py can't track the .h file that _symtable depends on.
-_thread -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal _threadmodule.c
+_thread _threadmodule.c
 _tracemalloc _tracemalloc.c  # See bpo-35053 as to why this is built in.
 _weakref _weakref.c
 atexit atexitmodule.c
 errno errnomodule.c
 faulthandler faulthandler.c
 itertools itertoolsmodule.c
-posix -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal posixmodule.c
+posix posixmodule.c
 pwd pwdmodule.c
-time -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal timemodule.c
+time timemodule.c
 
 
 # ---
@@ -139,7 +139,7 @@ time -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal timemodule.c
 
 #_asyncio _asynciomodule.c
 #_bisect _bisectmodule.c
-#_blake2 -DPy_BUILD_CORE_BUILTIN _blake2/blake2module.c _blake2/blake2b_impl.c _blake2/blake2s_impl.c
+#_blake2 _blake2/blake2module.c _blake2/blake2b_impl.c _blake2/blake2s_impl.c
 #_codecs_cn cjkcodecs/_codecs_cn.c
 #_codecs_hk cjkcodecs/_codecs_hk.c
 #_codecs_iso2022 cjkcodecs/_codecs_iso2022.c
@@ -150,31 +150,31 @@ time -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal timemodule.c
 #_csv _csv.c
 #_datetime _datetimemodule.c
 #_elementtree -DHAVE_EXPAT_CONFIG_H -DUSE_PYEXPAT_CAPI -I$(srcdir)/Modules/expat _elementtree.c
-#_heapq -DPy_BUILD_CORE_MODULE _heapqmodule.c
-#_json -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal _json.c
+#_heapq _heapqmodule.c
+#_json _json.c
 #_lsprof _lsprof.c rotatingtree.c
-#_md5 -DPy_BUILD_CORE_BUILTIN md5module.c
+#_md5 md5module.c
 #_multibytecodec cjkcodecs/multibytecodec.c
 #_opcode _opcode.c
-#_pickle -DPy_BUILD_CORE_MODULE _pickle.c
-#_posixsubprocess -DPy_BUILD_CORE_BUILTIN _posixsubprocess.c
-#_queue -DPy_BUILD_CORE_MODULE _queuemodule.c
-#_random -DPy_BUILD_CORE_MODULE _randommodule.c
-#_sha1 -DPy_BUILD_CORE_BUILTIN sha1module.c
-#_sha256 -DPy_BUILD_CORE_BUILTIN sha256module.c
-#_sha512 -DPy_BUILD_CORE_BUILTIN sha512module.c
-#_sha3 -DPy_BUILD_CORE_BUILTIN _sha3/sha3module.c
+#_pickle _pickle.c
+#_posixsubprocess _posixsubprocess.c
+#_queue _queuemodule.c
+#_random _randommodule.c
+#_sha1 sha1module.c
+#_sha256 sha256module.c
+#_sha512 sha512module.c
+#_sha3 _sha3/sha3module.c
 #_statistics _statisticsmodule.c
-#_struct -DPy_BUILD_CORE_MODULE _struct.c
+#_struct _struct.c
 #_typing _typingmodule.c
-#_zoneinfo -DPy_BUILD_CORE_MODULE _zoneinfo.c
-#array -DPy_BUILD_CORE_MODULE arraymodule.c
+#_zoneinfo _zoneinfo.c
+#array arraymodule.c
 #audioop audioop.c
-#binascii -DPy_BUILD_CORE_MODULE binascii.c
-#cmath -DPy_BUILD_CORE_MODULE cmathmodule.c _math.c  # -lm
-#math -DPy_BUILD_CORE_MODULE mathmodule.c _math.c  # -lm
+#binascii binascii.c
+#cmath cmathmodule.c _math.c  # -lm
+#math mathmodule.c _math.c  # -lm
 #pyexpat -DHAVE_EXPAT_CONFIG_H -DXML_POOR_ENTROPY -DUSE_PYEXPAT_CAPI -I$(srcdir)/Modules/expat  expat/xmlparse.c expat/xmlrole.c expat/xmltok.c pyexpat.c
-#unicodedata  -DPy_BUILD_CORE_BUILTIN unicodedata.c
+#unicodedata  unicodedata.c
 
 # Modules with some UNIX dependencies -- on by default:
 # (If you have a really backward UNIX, select and socket may not be
@@ -286,7 +286,7 @@ time -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal timemodule.c
 # provided by the ncurses library.  e.g. on Linux, link with -lncurses
 # instead of -lcurses).
 
-#_curses -DPy_BUILD_CORE_MODULE -lcurses -ltermcap _cursesmodule.c
+#_curses -lcurses -ltermcap _cursesmodule.c
 
 # Wrapper for the panel library that's part of ncurses and SYSV curses.
 #_curses_panel -lpanel -lncurses _curses_panel.c
@@ -305,7 +305,7 @@ xxsubtype xxsubtype.c  # Required for the test suite to pass!
 #_testbuffer _testbuffer.c
 #_testcapi _testcapimodule.c  # CANNOT be statically compiled!
 #_testimportmultiple _testimportmultiple.c
-#_testinternalcapi -DPy_BUILD_CORE_MODULE -I$(srcdir)/Include/internal _testinternalcapi.c
+#_testinternalcapi _testinternalcapi.c
 #_testmultiphase _testmultiphase.c
 
 
index 8aa68359039e7dd3f2901294f4f8dbe237b8068d..b7465c379dddf42dd1c6003b3d6f92460d97568c 100644 (file)
@@ -1,4 +1,7 @@
 /* ABCMeta implementation */
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
 
 #include "Python.h"
 #include "pycore_moduleobject.h"  // _PyModule_GetState()
index adc5ff9f796cca986cb6d6d0ce2e4d468a23338d..8386a50d55826d34b707c4a3fd6cff05beef5558 100644 (file)
@@ -1,3 +1,7 @@
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "Python.h"
 #include "pycore_pyerrors.h"      // _PyErr_ClearExcState()
 #include "pycore_pystate.h"       // _PyThreadState_GET()
index b16324e8f7aeb8e1f48a88f76004548582693d6a..e1421dd8ff8b825000a70ebf1d44bee3881e22d6 100644 (file)
  * The blake2s_impl.c is autogenerated from blake2b_impl.c.
  */
 
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "Python.h"
 #include "pycore_strhex.h"       // _Py_strhex()
 
index 631de2cc0abc7404a5a80424fe6d6e6041defc4f..3b6bba277a3139969bebf2bd0a01deb86771479c 100644 (file)
@@ -8,6 +8,10 @@
  * any warranty. http://creativecommons.org/publicdomain/zero/1.0/
  */
 
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "Python.h"
 
 #include "impl/blake2.h"
index 6b31a363ea27b92eefe28d00824840626f2111d7..763c0178e6bcd518a839bcefe79092e134827dde 100644 (file)
  * The blake2s_impl.c is autogenerated from blake2s_impl.c.
  */
 
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "Python.h"
 #include "pycore_strhex.h"        // _Py_strhex()
 
index f8940fdbed2424140b9ba6b76cf85125448587b4..96078c7726d597a3d6e421d6d3ce2e9af125276d 100644 (file)
@@ -98,6 +98,9 @@ bytes(cdata)
  * PyCField_Type
  *
  */
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
 
 #define PY_SSIZE_T_CLEAN
 
index c24f04ce3a0f8e69e4b2058cf9d6faf3dd062b26..0f7789a973e8f2fee8c991fc678d64495125e74f 100644 (file)
@@ -1,3 +1,7 @@
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "Python.h"
 // windows.h must be included before pycore internal headers
 #ifdef MS_WIN32
index 2cfd657028aca06ae7f5568f043af69e689accdf..515b2801820986d4cea220af2cd398d4353e8e24 100644 (file)
@@ -1,3 +1,7 @@
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "Python.h"
 // windows.h must be included before pycore internal headers
 #ifdef MS_WIN32
index 43669d7152a7e92f02a69c7294a66271226a71f9..6c1917b18d45099fe1e58989885dcc93f8dcb840 100644 (file)
@@ -1,3 +1,7 @@
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "Python.h"
 // windows.h must be included before pycore internal headers
 #ifdef MS_WIN32
index 511073f2ac13799a467949c3ab53a232c41e127c..3770a032e977dc2b1b40bcbe27acdc7d01173720 100644 (file)
@@ -100,6 +100,10 @@ static const char PyCursesVersion[] = "2.2";
 
 /* Includes */
 
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #define PY_SSIZE_T_CLEAN
 
 #include "Python.h"
index e54a01b44c5bad0c761c5a86c55ac3d4807ef8bc..67441eba28f7f65bd257e1238470c0e0ab5fbf80 100644 (file)
@@ -7,6 +7,10 @@
  * the capsule are defined below */
 #define _PY_DATETIME_IMPL
 
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "Python.h"
 #include "pycore_long.h"          // _PyLong_GetOne()
 #include "pycore_object.h"        // _PyObject_Init()
index 237edd5191fd948c16e2754fbd94466e2683f873..7fc7315603e7add91fb433e9a4d3f735d2175c81 100644 (file)
@@ -25,6 +25,9 @@
  * SUCH DAMAGE.
  */
 
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
 
 #include <Python.h>
 #include "pycore_pystate.h"       // _PyThreadState_GET()
index b4ba60baaac93d79ce7e0a3ba8152b4745e91ed0..12491917832b69e102f65d1c06a0724488b0f11b 100644 (file)
 #endif
 #define OPENSSL_NO_DEPRECATED 1
 
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #define PY_SSIZE_T_CLEAN
 
 #include "Python.h"
index 20468c28f24234ad7f5374408d60eaf2eee6e88b..3dbaaa0a0da1d63928ebc07515e06d6f05db2da9 100644 (file)
@@ -6,6 +6,10 @@ annotated by François Pinard, and converted to C by Raymond Hettinger.
 
 */
 
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "Python.h"
 #include "pycore_list.h"          // _PyList_ITEMS()
 
index 6f68c1f7f9b715d2894d4e187d8f418cd92bfde1..1c9c50665d466c117ff720e59b64ec5c3575c592 100644 (file)
@@ -4,8 +4,8 @@
  * and as an extension module (Py_BUILD_CORE_MODULE define) on other
  * platforms. */
 
-#if !defined(Py_BUILD_CORE_BUILTIN) && !defined(Py_BUILD_CORE_MODULE)
-#  error "Py_BUILD_CORE_BUILTIN or Py_BUILD_CORE_MODULE must be defined"
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
 #endif
 
 #include "Python.h"
index 2e27afcea1b799b63ab4e747e75039b666f2bc94..ff499aacbab374260b56c035642a7037e235fc4a 100644 (file)
@@ -1,3 +1,7 @@
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "Python.h"
 #include "pycore_call.h"          // _PyObject_CallNoArgs()
 #include "pycore_pystate.h"       // _PyThreadState_GET()
index 68e3a2346925de8d8ecc63d3ccaaf340cdbe24e9..c1936a1088a243a756a9d43ac48638f71030de28 100644 (file)
@@ -1,6 +1,10 @@
 /* Definitions of some C99 math library functions, for those platforms
    that don't implement these functions already. */
 
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "Python.h"
 #include <float.h>
 #include "_math.h"
index 53ab57111967ce22ab6b2bed4ada6cad0f54a6d2..0d9e57aa90d22fc9c7ea1a2a52a3b04ace23d14b 100644 (file)
@@ -4,8 +4,8 @@
  * and as an extension module (Py_BUILD_CORE_MODULE define) on other
  * platforms. */
 
-#if !defined(Py_BUILD_CORE_BUILTIN) && !defined(Py_BUILD_CORE_MODULE)
-#  error "Py_BUILD_CORE_BUILTIN or Py_BUILD_CORE_MODULE must be defined"
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
 #endif
 
 #include "Python.h"
index 63207de8b91371ffe9fab95fd023d43b6cfc703c..de599f8c970e38705cbb2b91c112e78301ccb137 100644 (file)
@@ -1,4 +1,8 @@
 /* Authors: Gregory P. Smith & Jeffrey Yasskin */
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "Python.h"
 #include "pycore_fileutils.h"
 #if defined(HAVE_PIPE2) && !defined(_GNU_SOURCE)
index eb61349b76581d5c2ca64f023783a89a4af0adc8..413387fecc4cd56d7f05c32ab515529b2b6e9f44 100644 (file)
@@ -1,3 +1,7 @@
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "Python.h"
 #include "pycore_moduleobject.h"  // _PyModule_GetState()
 #include "structmember.h"         // PyMemberDef
index 65d41f4e8e80c7d02128251466ae433fcb64ba52..5243d5a05e290020b5b275696fa50f383a8b176e 100644 (file)
 
 /* ---------------------------------------------------------------*/
 
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "Python.h"
 #include "pycore_moduleobject.h"  // _PyModule_GetState()
 #ifdef HAVE_PROCESS_H
index a033c4e4525456a74bba1ef1d9ece60f08215fb3..bfa96616df0c99327acee7fee53ef072eeb6522c 100644 (file)
  *
  */
 
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "Python.h"
 #include "pycore_strhex.h"        // _Py_strhex()
 #include "../hashlib.h"
index a8003a90b2682c42acdd66e0e06d8db7580d3433..210dbdc752f4c1901a1bd62a826f9d7ac3e4d5d0 100644 (file)
@@ -3,6 +3,10 @@
 /* New version supporting byte order, alignment and size options,
    character strings, and unsigned numbers */
 
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #define PY_SSIZE_T_CLEAN
 
 #include "Python.h"
index 3ba939651a4173f28735c2551e6d48219ba4eabc..1ca06069e11199f22b75c718bacfb6acca5ef969 100644 (file)
@@ -2,8 +2,8 @@
  * C Extension module to test Python internal C APIs (Include/internal).
  */
 
-#if !defined(Py_BUILD_CORE_BUILTIN) && !defined(Py_BUILD_CORE_MODULE)
-#  error "Py_BUILD_CORE_BUILTIN or Py_BUILD_CORE_MODULE must be defined"
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
 #endif
 
 /* Always enable assertions */
index 2d25e16bd4d390832b30717b5b354cded37f8c68..ee69c42336170da998192221e2d77a8a089bffc1 100644 (file)
@@ -1,6 +1,9 @@
 
 /* Testing module for multi-phase initialization of extension modules (PEP 489)
  */
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
 
 #include "Python.h"
 #include "pycore_namespace.h"     // _PyNamespace_New()
index b5c0a632191146f680d10b6477ca291128ced218..3f683768fcc28d47be6aef53b112c68ed16ac391 100644 (file)
@@ -1,6 +1,9 @@
 
 /* interpreters module */
 /* low-level access to interpreter primitives */
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
 
 #include "Python.h"
 #include "frameobject.h"
index 04fa09422b2134c0ab425f2a4491062ccfe7b478..cac347071f91dbf4a73dbef5674183d002d1b25d 100644 (file)
@@ -1,3 +1,7 @@
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "Python.h"
 #include "pycore_long.h"          // _PyLong_GetOne()
 #include "structmember.h"
index 5e57fe116059de151aa7ec01eaa79902ec7a2573..030ede57351e92d8ef8342ec9673b13b593adfd1 100644 (file)
@@ -3,6 +3,10 @@
 /* An array is a uniform list -- all items have the same type.
    The item type is restricted to simple C types like int or float */
 
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #define PY_SSIZE_T_CLEAN
 #include "Python.h"
 #include "pycore_floatobject.h"   // _PyFloat_Unpack4()
index 7037d34dbe2dd588232a25eb253fa609aef4da2f..fec0d82a39cdd75cf4e4e1178d91b705be76a80c 100644 (file)
 ** Brandon Long, September 2001.
 */
 
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #define PY_SSIZE_T_CLEAN
 
 #include "Python.h"
index 0f22049a170848e6a02d4915af5e469983c07f08..0e0489c5fe2d7326c93f59a9007f76ee74405411 100644 (file)
@@ -2,6 +2,10 @@
 
 /* much code borrowed from mathmodule.c */
 
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "Python.h"
 #include "pycore_dtoa.h"
 #include "_math.h"
index 4fac0cc29e4e984e0f49854f6d51f319b781d3fc..6c12a4e70ddf2008770b2f3cb5e19caa3e6def61 100644 (file)
@@ -52,6 +52,10 @@ raised for division by zero and mod by zero.
    returned.
  */
 
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #include "Python.h"
 #include "pycore_bitutils.h"      // _Py_bit_length()
 #include "pycore_call.h"          // _PyObject_CallNoArgs()
index 4d03f6b844b33206740ba264227e8a091cfee7e0..48b11e0779f8752a181f422854b6ad7c25eec568 100644 (file)
@@ -15,6 +15,9 @@
 */
 
 /* MD5 objects */
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
 
 #include "Python.h"
 #include "hashlib.h"
index 153bc12a8bd743ef4e6f78aeb810f99037027239..9153557fbde7406209cbb7ca0533747fd75dfb0f 100644 (file)
@@ -15,6 +15,9 @@
 */
 
 /* SHA1 objects */
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
 
 #include "Python.h"
 #include "hashlib.h"
index 5858071db4e13334e2beb8c855f353624da08eae..17ee86683b7a89b0486b7c57d1c4d9528e507c50 100644 (file)
@@ -15,6 +15,9 @@
 */
 
 /* SHA objects */
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
 
 #include "Python.h"
 #include "pycore_bitutils.h"      // _Py_bswap32()
index e50b69be4617d9b11f1dde6b32ea8e2eed239df8..bf4408b455f2c486e58e91eb660e70ce5655b953 100644 (file)
@@ -15,6 +15,9 @@
 */
 
 /* SHA objects */
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
 
 #include "Python.h"
 #include "pycore_bitutils.h"      // _Py_bswap64()
index e863e53bfa9f17c156e54c99fffce5365a405648..bdbddcf10b778fb0be8d5c15507b0eda1566bb81 100644 (file)
 
    ------------------------------------------------------------------------ */
 
+#ifndef Py_BUILD_CORE_BUILTIN
+#  define Py_BUILD_CORE_MODULE 1
+#endif
+
 #define PY_SSIZE_T_CLEAN
 
 #include "Python.h"
index d492b71dfbaa3d275235aac92fb76b1ea2a69043..bbcabb5cdb4058eb2369786cc32904efa3f1d5b1 100644 (file)
@@ -25,7 +25,6 @@
     <_DebugPreprocessorDefinition Condition="$(Configuration) == 'Debug'">_DEBUG;</_DebugPreprocessorDefinition>
     <_PlatformPreprocessorDefinition>_WIN32;</_PlatformPreprocessorDefinition>
     <_PlatformPreprocessorDefinition Condition="$(Platform) == 'x64'">_WIN64;_M_X64;</_PlatformPreprocessorDefinition>
-    <_PydPreprocessorDefinition Condition="$(TargetExt) == '.pyd'">Py_BUILD_CORE_MODULE;</_PydPreprocessorDefinition>
     <_Py3NamePreprocessorDefinition>PY3_DLLNAME=L"$(Py3DllName)";</_Py3NamePreprocessorDefinition>
   </PropertyGroup>
   <ItemDefinitionGroup>
index 5428cbde1cc9b0902dc5ab62d97202cd64b7168e..03dce63984ef3013f22e19b3a3d1e0c1db7d0aaa 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -899,8 +899,7 @@ class PyBuildExt(build_ext):
         #
 
         # array objects
-        self.add(Extension('array', ['arraymodule.c'],
-                           extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
+        self.add(Extension('array', ['arraymodule.c']))
 
         # Context Variables
         self.add(Extension('_contextvars', ['_contextvarsmodule.c']))
@@ -909,14 +908,12 @@ class PyBuildExt(build_ext):
 
         # math library functions, e.g. sin()
         self.add(Extension('math',  ['mathmodule.c'],
-                           extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
                            extra_objects=[shared_math],
                            depends=['_math.h', shared_math],
                            libraries=['m']))
 
         # complex math library functions
         self.add(Extension('cmath', ['cmathmodule.c'],
-                           extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
                            extra_objects=[shared_math],
                            depends=['_math.h', shared_math],
                            libraries=['m']))
@@ -933,44 +930,33 @@ class PyBuildExt(build_ext):
         # libm is needed by delta_new() that uses round() and by accum() that
         # uses modf().
         self.add(Extension('_datetime', ['_datetimemodule.c'],
-                           libraries=['m'],
-                           extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
+                           libraries=['m']))
         # zoneinfo module
-        self.add(Extension('_zoneinfo', ['_zoneinfo.c'],
-                           extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
+        self.add(Extension('_zoneinfo', ['_zoneinfo.c']))
         # random number generator implemented in C
-        self.add(Extension("_random", ["_randommodule.c"],
-                           extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
+        self.add(Extension("_random", ["_randommodule.c"]))
         # bisect
         self.add(Extension("_bisect", ["_bisectmodule.c"]))
         # heapq
-        self.add(Extension("_heapq", ["_heapqmodule.c"],
-                           extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
+        self.add(Extension("_heapq", ["_heapqmodule.c"]))
         # C-optimized pickle replacement
-        self.add(Extension("_pickle", ["_pickle.c"],
-                           extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
+        self.add(Extension("_pickle", ["_pickle.c"]))
         # _json speedups
-        self.add(Extension("_json", ["_json.c"],
-                           extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
+        self.add(Extension("_json", ["_json.c"]))
 
         # profiler (_lsprof is for cProfile.py)
-        self.add(Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c'],
-                           extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
+        self.add(Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']))
         # static Unicode character database
         self.add(Extension('unicodedata', ['unicodedata.c'],
-                           depends=['unicodedata_db.h', 'unicodename_db.h'],
-                           extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
+                           depends=['unicodedata_db.h', 'unicodename_db.h']))
         # _opcode module
         self.add(Extension('_opcode', ['_opcode.c']))
         # asyncio speedups
-        self.add(Extension("_asyncio", ["_asynciomodule.c"],
-                           extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
+        self.add(Extension("_asyncio", ["_asynciomodule.c"]))
         # _abc speedups
-        self.add(Extension("_abc", ["_abc.c"],
-                           extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
+        self.add(Extension("_abc", ["_abc.c"]))
         # _queue module
-        self.add(Extension("_queue", ["_queuemodule.c"],
-                           extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
+        self.add(Extension("_queue", ["_queuemodule.c"]))
         # _statistics module
         self.add(Extension("_statistics", ["_statisticsmodule.c"]))
         # _typing module
@@ -1012,8 +998,7 @@ class PyBuildExt(build_ext):
         self.add(Extension('syslog', ['syslogmodule.c']))
 
         # Python interface to subinterpreter C-API.
-        self.add(Extension('_xxsubinterpreters', ['_xxsubinterpretersmodule.c'],
-                           extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
+        self.add(Extension('_xxsubinterpreters', ['_xxsubinterpretersmodule.c']))
 
         #
         # Here ends the simple stuff.  From here on, modules need certain
@@ -1036,8 +1021,7 @@ class PyBuildExt(build_ext):
         self.add(Extension('_csv', ['_csv.c']))
 
         # POSIX subprocess module helper.
-        self.add(Extension('_posixsubprocess', ['_posixsubprocess.c'],
-                           extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
+        self.add(Extension('_posixsubprocess', ['_posixsubprocess.c']))
 
     def detect_test_extensions(self):
         # Python C API test module
@@ -1045,8 +1029,7 @@ class PyBuildExt(build_ext):
                            depends=['testcapi_long.h']))
 
         # Python Internal C API test module
-        self.add(Extension('_testinternalcapi', ['_testinternalcapi.c'],
-                           extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
+        self.add(Extension('_testinternalcapi', ['_testinternalcapi.c']))
 
         # Python PEP-3118 (buffer protocol) test module
         self.add(Extension('_testbuffer', ['_testbuffer.c']))
@@ -1055,8 +1038,7 @@ class PyBuildExt(build_ext):
         self.add(Extension('_testimportmultiple', ['_testimportmultiple.c']))
 
         # Test multi-phase extension module init (PEP 489)
-        self.add(Extension('_testmultiphase', ['_testmultiphase.c'],
-                           extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
+        self.add(Extension('_testmultiphase', ['_testmultiphase.c']))
 
         # Fuzz tests.
         self.add(Extension('_xxtestfuzz',
@@ -1187,7 +1169,6 @@ class PyBuildExt(build_ext):
         if curses_library.startswith('ncurses'):
             curses_libs = [curses_library]
             self.add(Extension('_curses', ['_cursesmodule.c'],
-                               extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
                                include_dirs=curses_includes,
                                define_macros=curses_defines,
                                libraries=curses_libs))
@@ -1202,7 +1183,6 @@ class PyBuildExt(build_ext):
                 curses_libs = ['curses']
 
             self.add(Extension('_curses', ['_cursesmodule.c'],
-                               extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
                                define_macros=curses_defines,
                                libraries=curses_libs))
         else:
@@ -1722,7 +1702,7 @@ class PyBuildExt(build_ext):
 
         # Helper module for various ascii-encoders.  Uses zlib for an optimized
         # crc32 if we have it.  Otherwise binascii uses its own.
-        extra_compile_args = ['-DPy_BUILD_CORE_MODULE']
+        extra_compile_args = []
         if have_zlib:
             extra_compile_args.append('-DUSE_ZLIB_CRC32')
             libraries = ['z']
@@ -2230,7 +2210,7 @@ class PyBuildExt(build_ext):
             self.use_system_libffi = '--with-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS")
 
         include_dirs = []
-        extra_compile_args = ['-DPy_BUILD_CORE_MODULE']
+        extra_compile_args = []
         extra_link_args = []
         sources = ['_ctypes/_ctypes.c',
                    '_ctypes/callbacks.c',
@@ -2324,7 +2304,7 @@ class PyBuildExt(build_ext):
 
     def detect_decimal(self):
         # Stefan Krah's _decimal module
-        extra_compile_args = ['-DPy_BUILD_CORE_MODULE']
+        extra_compile_args = []
         undef_macros = []
         if '--with-system-libmpdec' in sysconfig.get_config_var("CONFIG_ARGS"):
             include_dirs = []
@@ -2482,7 +2462,6 @@ class PyBuildExt(build_ext):
             library_dirs=openssl_libdirs,
             libraries=openssl_libs,
             runtime_library_dirs=runtime_library_dirs,
-            extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
         )
 
         # This static linking is NOT OFFICIALLY SUPPORTED.
@@ -2545,28 +2524,24 @@ class PyBuildExt(build_ext):
             self.add(Extension(
                 '_sha256', ['sha256module.c'],
                 depends=['hashlib.h'],
-                extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
             ))
 
         if "sha512" in configured:
             self.add(Extension(
                 '_sha512', ['sha512module.c'],
                 depends=['hashlib.h'],
-                extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
             ))
 
         if "md5" in configured:
             self.add(Extension(
                 '_md5', ['md5module.c'],
                 depends=['hashlib.h'],
-                extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
             ))
 
         if "sha1" in configured:
             self.add(Extension(
                 '_sha1', ['sha1module.c'],
                 depends=['hashlib.h'],
-                extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
             ))
 
         if "blake2" in configured:
@@ -2582,7 +2557,6 @@ class PyBuildExt(build_ext):
                     '_blake2/blake2s_impl.c'
                 ],
                 depends=blake2_deps,
-                extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
             ))
 
         if "sha3" in configured:
@@ -2594,7 +2568,6 @@ class PyBuildExt(build_ext):
                 '_sha3',
                 ['_sha3/sha3module.c'],
                 depends=sha3_deps,
-                extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
             ))
 
     def detect_nis(self):
@@ -2750,8 +2723,7 @@ def main():
                       'install_lib': PyBuildInstallLib},
           # The struct module is defined here, because build_ext won't be
           # called unless there's at least one extension module defined.
-          ext_modules=[Extension('_struct', ['_struct.c'],
-                                 extra_compile_args=['-DPy_BUILD_CORE_MODULE'])],
+          ext_modules=[Extension('_struct', ['_struct.c'])],
 
           # If you change the scripts installed here, you also need to
           # check the PyBuildScripts command above, and change the links