Skip to content

Commit c113d57

Browse files
committed
bpo-43974: Set Py_BUILD_CORE_MODULE for all core modules
1 parent 99f71ae commit c113d57

File tree

3 files changed

+49
-61
lines changed

3 files changed

+49
-61
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``setup.py`` now defines ``Py_BUILD_CORE_MODULE`` for all core modules
2+
automatically. ``Modules/Setup`` no longer defines ``Py_BUILD_CORE_BUILTIN``.
3+
The macro is automatically defined for builtins by ``Modules/makesetup``.

Modules/Setup

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -101,29 +101,29 @@ PYTHONPATH=$(COREPYTHONPATH)
101101
# This only contains the minimal set of modules required to run the
102102
# setup.py script in the root of the Python source tree.
103103

104-
posix -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal posixmodule.c # posix (UNIX) system calls
104+
posix -I$(srcdir)/Include/internal posixmodule.c # posix (UNIX) system calls
105105
errno errnomodule.c # posix (UNIX) errno values
106106
pwd pwdmodule.c # this is needed to find out the user's home dir
107107
# if $HOME is not set
108-
_sre -DPy_BUILD_CORE_BUILTIN _sre.c # Fredrik Lundh's new regular expressions
108+
_sre _sre.c # Fredrik Lundh's new regular expressions
109109
_codecs _codecsmodule.c # access to the builtin codecs and codec registry
110110
_weakref _weakref.c # weak references
111-
_functools -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal _functoolsmodule.c # Tools for working with functions and callable objects
112-
_operator -DPy_BUILD_CORE_BUILTIN _operator.c # operator.add() and similar goodies
111+
_functools -I$(srcdir)/Include/internal _functoolsmodule.c # Tools for working with functions and callable objects
112+
_operator _operator.c # operator.add() and similar goodies
113113
_collections _collectionsmodule.c # Container types
114-
_abc -DPy_BUILD_CORE_BUILTIN _abc.c # Abstract base classes
114+
_abc _abc.c # Abstract base classes
115115
itertools itertoolsmodule.c # Functions creating iterators for efficient looping
116116
atexit atexitmodule.c # Register functions to be run at interpreter-shutdown
117-
_signal -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal signalmodule.c
117+
_signal -I$(srcdir)/Include/internal signalmodule.c
118118
_stat _stat.c # stat.h interface
119-
time -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal timemodule.c # -lm # time operations and variables
120-
_thread -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal _threadmodule.c # low-level threading interface
119+
time -I$(srcdir)/Include/internal timemodule.c # -lm # time operations and variables
120+
_thread -I$(srcdir)/Include/internal _threadmodule.c # low-level threading interface
121121

122122
# access to ISO C locale support
123-
_locale -DPy_BUILD_CORE_BUILTIN _localemodule.c # -lintl
123+
_locale _localemodule.c # -lintl
124124

125125
# Standard I/O baseline
126-
_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
126+
_io -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
127127

128128
# faulthandler module
129129
faulthandler faulthandler.c
@@ -166,26 +166,26 @@ _symtable symtablemodule.c
166166

167167
# Modules that should always be present (non UNIX dependent):
168168

169-
#array -DPy_BUILD_CORE_MODULE arraymodule.c # array objects
170-
#cmath cmathmodule.c _math.c -DPy_BUILD_CORE_MODULE # -lm # complex math library functions
171-
#math mathmodule.c _math.c -DPy_BUILD_CORE_MODULE # -lm # math library functions, e.g. sin()
169+
array arraymodule.c # array objects
170+
#cmath cmathmodule.c _math.c # -lm # complex math library functions
171+
#math mathmodule.c _math.c # -lm # math library functions, e.g. sin()
172172
#_contextvars _contextvarsmodule.c # Context Variables
173-
#_struct -DPy_BUILD_CORE_MODULE _struct.c # binary structure packing/unpacking
173+
#_struct _struct.c # binary structure packing/unpacking
174174
#_weakref _weakref.c # basic weak reference support
175175
#_testcapi _testcapimodule.c # Python C API test module
176-
#_testinternalcapi _testinternalcapi.c -I$(srcdir)/Include/internal -DPy_BUILD_CORE_MODULE # Python internal C API test module
177-
#_random _randommodule.c -DPy_BUILD_CORE_MODULE # Random number generator
176+
#_testinternalcapi _testinternalcapi.c -I$(srcdir)/Include/internal # Python internal C API test module
177+
#_random _randommodule.c # Random number generator
178178
#_elementtree -I$(srcdir)/Modules/expat -DHAVE_EXPAT_CONFIG_H -DUSE_PYEXPAT_CAPI _elementtree.c # elementtree accelerator
179-
#_pickle -DPy_BUILD_CORE_MODULE _pickle.c # pickle accelerator
179+
#_pickle _pickle.c # pickle accelerator
180180
#_datetime _datetimemodule.c # datetime accelerator
181-
#_zoneinfo _zoneinfo.c -DPy_BUILD_CORE_MODULE # zoneinfo accelerator
181+
#_zoneinfo _zoneinfo.c # zoneinfo accelerator
182182
#_bisect _bisectmodule.c # Bisection algorithms
183-
#_heapq _heapqmodule.c -DPy_BUILD_CORE_MODULE # Heap queue algorithm
183+
#_heapq _heapqmodule.c # Heap queue algorithm
184184
#_asyncio _asynciomodule.c # Fast asyncio Future
185-
#_json -I$(srcdir)/Include/internal -DPy_BUILD_CORE_BUILTIN _json.c # _json speedups
185+
#_json -I$(srcdir)/Include/internal _json.c # _json speedups
186186
#_statistics _statisticsmodule.c # statistics accelerator
187187

188-
#unicodedata unicodedata.c -DPy_BUILD_CORE_BUILTIN # static Unicode character database
188+
#unicodedata unicodedata.c # static Unicode character database
189189

190190

191191
# Modules with some UNIX dependencies -- on by default:
@@ -238,7 +238,7 @@ _symtable symtablemodule.c
238238
#termios termios.c # Steen Lumholt's termios module
239239
#resource resource.c # Jeremy Hylton's rlimit interface
240240

241-
#_posixsubprocess -DPy_BUILD_CORE_BUILTIN _posixsubprocess.c # POSIX subprocess module helper
241+
#_posixsubprocess _posixsubprocess.c # POSIX subprocess module helper
242242

243243
# Multimedia modules -- off by default.
244244
# These don't work for 64-bit platforms!!!
@@ -260,8 +260,8 @@ _symtable symtablemodule.c
260260
# The _sha module implements the SHA checksum algorithms.
261261
# (NIST's Secure Hash Algorithms.)
262262
#_sha1 sha1module.c
263-
#_sha256 sha256module.c -DPy_BUILD_CORE_BUILTIN
264-
#_sha512 sha512module.c -DPy_BUILD_CORE_BUILTIN
263+
#_sha256 sha256module.c
264+
#_sha512 sha512module.c
265265
#_sha3 _sha3/sha3module.c
266266

267267
# _blake module
@@ -318,7 +318,7 @@ _symtable symtablemodule.c
318318
# provided by the ncurses library. e.g. on Linux, link with -lncurses
319319
# instead of -lcurses).
320320

321-
#_curses _cursesmodule.c -lcurses -ltermcap -DPy_BUILD_CORE_MODULE
321+
#_curses _cursesmodule.c -lcurses -ltermcap
322322
# Wrapper for the panel library that's part of ncurses and SYSV curses.
323323
#_curses_panel _curses_panel.c -lpanel -lncurses
324324

setup.py

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ def __init__(self, dist):
372372
self.parallel = True
373373

374374
def add(self, ext):
375+
ext.define_macros.append(("Py_BUILD_CORE_MODULE", None))
375376
self.extensions.append(ext)
376377

377378
def set_srcdir(self):
@@ -877,8 +878,7 @@ def detect_simple_extensions(self):
877878
#
878879

879880
# array objects
880-
self.add(Extension('array', ['arraymodule.c'],
881-
extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
881+
self.add(Extension('array', ['arraymodule.c']))
882882

883883
# Context Variables
884884
self.add(Extension('_contextvars', ['_contextvarsmodule.c']))
@@ -887,14 +887,12 @@ def detect_simple_extensions(self):
887887

888888
# math library functions, e.g. sin()
889889
self.add(Extension('math', ['mathmodule.c'],
890-
extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
891890
extra_objects=[shared_math],
892891
depends=['_math.h', shared_math],
893892
libraries=['m']))
894893

895894
# complex math library functions
896895
self.add(Extension('cmath', ['cmathmodule.c'],
897-
extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
898896
extra_objects=[shared_math],
899897
depends=['_math.h', shared_math],
900898
libraries=['m']))
@@ -911,43 +909,33 @@ def detect_simple_extensions(self):
911909
# libm is needed by delta_new() that uses round() and by accum() that
912910
# uses modf().
913911
self.add(Extension('_datetime', ['_datetimemodule.c'],
914-
libraries=['m'],
915-
extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
912+
libraries=['m']))
916913
# zoneinfo module
917-
self.add(Extension('_zoneinfo', ['_zoneinfo.c'],
918-
extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
914+
self.add(Extension('_zoneinfo', ['_zoneinfo.c']))
919915
# random number generator implemented in C
920-
self.add(Extension("_random", ["_randommodule.c"],
921-
extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
916+
self.add(Extension("_random", ["_randommodule.c"]))
922917
# bisect
923918
self.add(Extension("_bisect", ["_bisectmodule.c"]))
924919
# heapq
925-
self.add(Extension("_heapq", ["_heapqmodule.c"],
926-
extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
920+
self.add(Extension("_heapq", ["_heapqmodule.c"]))
927921
# C-optimized pickle replacement
928-
self.add(Extension("_pickle", ["_pickle.c"],
929-
extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
922+
self.add(Extension("_pickle", ["_pickle.c"]))
930923
# _json speedups
931-
self.add(Extension("_json", ["_json.c"],
932-
extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
924+
self.add(Extension("_json", ["_json.c"]))
933925

934926
# profiler (_lsprof is for cProfile.py)
935927
self.add(Extension('_lsprof', ['_lsprof.c', 'rotatingtree.c']))
936928
# static Unicode character database
937929
self.add(Extension('unicodedata', ['unicodedata.c'],
938-
depends=['unicodedata_db.h', 'unicodename_db.h'],
939-
extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
930+
depends=['unicodedata_db.h', 'unicodename_db.h']))
940931
# _opcode module
941932
self.add(Extension('_opcode', ['_opcode.c']))
942933
# asyncio speedups
943-
self.add(Extension("_asyncio", ["_asynciomodule.c"],
944-
extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
934+
self.add(Extension("_asyncio", ["_asynciomodule.c"]))
945935
# _abc speedups
946-
self.add(Extension("_abc", ["_abc.c"],
947-
extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
936+
self.add(Extension("_abc", ["_abc.c"]))
948937
# _queue module
949-
self.add(Extension("_queue", ["_queuemodule.c"],
950-
extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
938+
self.add(Extension("_queue", ["_queuemodule.c"]))
951939
# _statistics module
952940
self.add(Extension("_statistics", ["_statisticsmodule.c"]))
953941

@@ -1010,17 +998,15 @@ def detect_simple_extensions(self):
1010998
self.add(Extension('_csv', ['_csv.c']))
1011999

10121000
# POSIX subprocess module helper.
1013-
self.add(Extension('_posixsubprocess', ['_posixsubprocess.c'],
1014-
extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
1001+
self.add(Extension('_posixsubprocess', ['_posixsubprocess.c']))
10151002

10161003
def detect_test_extensions(self):
10171004
# Python C API test module
10181005
self.add(Extension('_testcapi', ['_testcapimodule.c'],
10191006
depends=['testcapi_long.h']))
10201007

10211008
# Python Internal C API test module
1022-
self.add(Extension('_testinternalcapi', ['_testinternalcapi.c'],
1023-
extra_compile_args=['-DPy_BUILD_CORE_MODULE']))
1009+
self.add(Extension('_testinternalcapi', ['_testinternalcapi.c']))
10241010

10251011
# Python PEP-3118 (buffer protocol) test module
10261012
self.add(Extension('_testbuffer', ['_testbuffer.c']))
@@ -1160,7 +1146,6 @@ def detect_readline_curses(self):
11601146
if curses_library.startswith('ncurses'):
11611147
curses_libs = [curses_library]
11621148
self.add(Extension('_curses', ['_cursesmodule.c'],
1163-
extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
11641149
include_dirs=curses_includes,
11651150
define_macros=curses_defines,
11661151
libraries=curses_libs))
@@ -1175,7 +1160,6 @@ def detect_readline_curses(self):
11751160
curses_libs = ['curses']
11761161

11771162
self.add(Extension('_curses', ['_cursesmodule.c'],
1178-
extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
11791163
define_macros=curses_defines,
11801164
libraries=curses_libs))
11811165
else:
@@ -2199,7 +2183,7 @@ def detect_ctypes(self):
21992183
self.use_system_libffi = '--with-system-ffi' in sysconfig.get_config_var("CONFIG_ARGS")
22002184

22012185
include_dirs = []
2202-
extra_compile_args = ['-DPy_BUILD_CORE_MODULE']
2186+
extra_compile_args = []
22032187
extra_link_args = []
22042188
sources = ['_ctypes/_ctypes.c',
22052189
'_ctypes/callbacks.c',
@@ -2512,14 +2496,12 @@ def detect_hash_builtins(self):
25122496
if "sha256" in configured:
25132497
self.add(Extension(
25142498
'_sha256', ['sha256module.c'],
2515-
extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
25162499
depends=['hashlib.h']
25172500
))
25182501

25192502
if "sha512" in configured:
25202503
self.add(Extension(
25212504
'_sha512', ['sha512module.c'],
2522-
extra_compile_args=['-DPy_BUILD_CORE_MODULE'],
25232505
depends=['hashlib.h']
25242506
))
25252507

@@ -2714,9 +2696,12 @@ class DummyProcess:
27142696
'install_lib': PyBuildInstallLib},
27152697
# The struct module is defined here, because build_ext won't be
27162698
# called unless there's at least one extension module defined.
2717-
ext_modules=[Extension('_struct', ['_struct.c'],
2718-
extra_compile_args=['-DPy_BUILD_CORE_MODULE'])],
2719-
2699+
ext_modules=[
2700+
Extension(
2701+
'_struct', ['_struct.c'],
2702+
define_macros=[('Py_BUILD_CORE_MODULE', None)]
2703+
)
2704+
],
27202705
# If you change the scripts installed here, you also need to
27212706
# check the PyBuildScripts command above, and change the links
27222707
# created by the bininstall target in Makefile.pre.in

0 commit comments

Comments
 (0)