BLD: define _USE_MATH_DEFINES in c_args - #870
Open
fjankovi wants to merge 1 commit into
Open
Conversation
Python.h includes <math.h> before cwt.template.c gets a chance to define _USE_MATH_DEFINES, so the define never takes effect and M_PI is left undeclared wherever math.h gates it on that macro. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
fjankovi
force-pushed
the
fix/use-math-defines-before-python-h
branch
from
September 3, 2026 15:45
3af0aa4 to
cdbb118
Compare
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
✳️ Assisted by Claude Opus 5
cwt.template.c:18defines_USE_MATH_DEFINESimmediately before#include "math.h", but<math.h>has already been included by that point, so the define has no effect:cwt.template.cis not a translation unit of its own — it is textually included fromcwt.c(lines 9 and 13), after that chain has already run. The include guard is set, so line 19 is a no-op andM_PIat line 65 is undeclared.Whether that matters is platform-dependent:
pyconfig.hdefines_XOPEN_SOURCE 700, and glibc exposesM_PIunder__USE_XOPENregardless of_USE_MATH_DEFINES.PC/pyconfig.hdefines none of_XOPEN_SOURCE,_POSIX_C_SOURCE,_GNU_SOURCEor_USE_MATH_DEFINES, and mingw-w64'smath.hgates theM_*block on#if !defined(__STRICT_ANSI__) || defined(_POSIX_C_SOURCE) || ... || defined(_USE_MATH_DEFINES).meson.buildsetsc_std=c17, which defines__STRICT_ANSI__— so every clause is false at the first include.Observed building 1.7.0 from source under Python 3.14 on Windows (that version has no cp314 wheel):
1.9.0 ships cp314 wheels, so the source build is rarely exercised right now — but the code is unchanged on
main, and this resurfaces in the window before wheels exist for each new CPython.Fixed by adding
-D_USE_MATH_DEFINEStoc_argsinpywt/_extensions/meson.build.Caveat: this was not compiled on Windows — the mechanism is derived from the mingw-w64 header rather than observed under MSVC, which is untested. Downstream context: ROCm/TheRock#7798.