Fix build on Python 3.14 by isolating internal C headers and removing inline specifiers#412
Conversation
Python 3.14 introduces C++ templates in `dynamic_annotations.h` (included via `internal/pycore_interp.h`). This caused compilation errors ("template with C linkage") because these headers were included inside `extern "C"` blocks in `c_trace_callbacks.h`, which is required for Cython/C++ compatibility.
This commit refactors the code to separate the interface from the implementation details:
- Moved internal Python header includes and compatibility macros (for `_PyGC_FINALIZED`, `HAVE_STD_ATOMIC`, etc.) from `c_trace_callbacks.h` to `c_trace_callbacks.c`.
- `c_trace_callbacks.c` is now compiled asFix build on Python 3.14 by isolating internal C headers
Python 3.14 introduces C++ templates in `dynamic_annotations.h` (included via `internal/pycore_interp.h`). This caused compilation errors ("template with C linkage") because these headers were included inside `extern "C"` blocks in `c_trace_callbacks.h`, which is required for Cython/C++ compatibility.
This commit refactors the code to separate the interface from the implementation details:
- Moved internal Python header includes and compatibility macros (for `_PyGC_FINALIZED`, `HAVE_STD_ATOMIC`, etc.) from `c_trace_callbacks.h` to `c_trace_callbacks.c`.
- `c_trace_callbacks.c` is now compiled as
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #412 +/- ##
==========================================
+ Coverage 87.56% 90.28% +2.71%
==========================================
Files 18 20 +2
Lines 1641 2080 +439
Branches 348 447 +99
==========================================
+ Hits 1437 1878 +441
- Misses 149 151 +2
+ Partials 55 51 -4 see 4 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
|
Failure on 3.14 is unrelated. There's already an open issue tracking it on #411. |
|
@Erotemic: It would be great to have a release with that PR in. Currently |
|
The failing test on main is blocking any release. I'm limited on time, if someone can propose of plan of merges that gets to a passing main brain, I'll make time to review it and push out a release. Otherwise, I'll have to build that plan, and I can't make promises on my schedule there. |
|
Can we maybe merge this nevertheless so that |
|
To use Codex here, create a Codex account and connect to github. |
1 similar comment
|
To use Codex here, create a Codex account and connect to github. |
Erotemic
left a comment
There was a problem hiding this comment.
So, not sure what's going on with codex, it should have been able to connect and contribute a review, but I think I've gone through this well enough where I understand what's going on and am comfortable merging.
My understanding is:
- Due to changes in 3.14 the "internal/pycore_interp.h" now contains C++ templates, and then we included it in an extern C block, including a C++ template in an extern C block causes an error.
So we moved the offending code from an h file to a c file. Then in our pyx file, we switch the cdef extern to point at the h file, which no longer contains the included C++ template. Then back in our h file we check if we are compiling with C++ and wrap TraceCallback in an extern C block to ensure we have the same C-style linker names, which the rest of the program expects.
These were the changes from #412. In addition to #408 this
-
changing
is_null_callbackto static is better to signal that it isn't used anywhere else. -
Removing inline
set_local_traceandmonitoring_restart_versionsolves portability issue due to subtle inline issues that was causing the linker issues in windows. In this case in C, it is correct to make these plain functions because they are used across different translation units and need a global symbol defined for the linker, and the inline prevented that.
Supersedes #408.