Skip to content

Commit 63d096d

Browse files
committed
Issue #24421: Compile _math.c separately to avoid race condition
1 parent bc85e35 commit 63d096d

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

Makefile.pre.in

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,11 +586,15 @@ pybuilddir.txt: $(BUILDPYTHON)
586586
exit 1 ; \
587587
fi
588588

589+
# This is shared by the math and cmath modules
590+
Modules/_math.o: Modules/_math.c Modules/_math.h
591+
$(CC) -c $(CCSHARED) $(PY_CORE_CFLAGS) -o $@ $<
592+
589593
# Build the shared modules
590594
# Under GNU make, MAKEFLAGS are sorted and normalized; the 's' for
591595
# -s, --silent or --quiet is always the first char.
592596
# Under BSD make, MAKEFLAGS might be " -s -v x=y".
593-
sharedmods: $(BUILDPYTHON) pybuilddir.txt
597+
sharedmods: $(BUILDPYTHON) pybuilddir.txt Modules/_math.o
594598
@case "$$MAKEFLAGS" in \
595599
*\ -s*|s*) quiet="-q";; \
596600
*) quiet="";; \

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ Tests
261261
Build
262262
-----
263263

264+
- Issue #24421: Compile Modules/_math.c once, before building extensions.
265+
Previously it could fail to compile properly if the math and cmath builds
266+
were concurrent.
267+
264268
- Issue #25348: Added ``--pgo`` and ``--pgo-job`` arguments to
265269
``PCbuild\build.bat`` for building with Profile-Guided Optimization. The
266270
old ``PCbuild\build_pgo.bat`` script is now deprecated, and simply calls

setup.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -598,13 +598,17 @@ def detect_modules(self):
598598

599599
# array objects
600600
exts.append( Extension('array', ['arraymodule.c']) )
601+
602+
shared_math = 'Modules/_math.o'
601603
# complex math library functions
602-
exts.append( Extension('cmath', ['cmathmodule.c', '_math.c'],
603-
depends=['_math.h'],
604+
exts.append( Extension('cmath', ['cmathmodule.c'],
605+
extra_objects=[shared_math],
606+
depends=['_math.h', shared_math],
604607
libraries=math_libs) )
605608
# math library functions, e.g. sin()
606-
exts.append( Extension('math', ['mathmodule.c', '_math.c'],
607-
depends=['_math.h'],
609+
exts.append( Extension('math', ['mathmodule.c'],
610+
extra_objects=[shared_math],
611+
depends=['_math.h', shared_math],
608612
libraries=math_libs) )
609613

610614
# time libraries: librt may be needed for clock_gettime()

0 commit comments

Comments
 (0)