-
Notifications
You must be signed in to change notification settings - Fork 132
Fix build on Python 3.14 + GCC 15 by isolating internal C headers #408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes Python 3.14 build compatibility by refactoring how internal Python headers are included. Python 3.14 introduced C++ templates in dynamic_annotations.h, which caused "template with C linkage" compilation errors when these headers were included inside extern "C" blocks.
Key changes:
- Moved internal Python header includes (
pycore_interp.h) and compatibility macros from the header file to the implementation file - Added
extern "C"guards to the header file for C++ compatibility - Changed Cython to correctly import from the header file instead of the implementation file
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
line_profiler/c_trace_callbacks.h |
Removed internal Python headers and compatibility macros; added extern "C" guards for C++ compatibility |
line_profiler/c_trace_callbacks.c |
Added internal Python headers and compatibility macros previously in the header file |
line_profiler/_line_profiler.pyx |
Changed Cython import from .c to .h file (correct best practice) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@Erotemic: I have no clue on why the wheel build is failing on windows, it's a simple code move with trivial c++ guard additions to comply with cpython API changes. No functional changes. Without a similar fix, line_profiler cannot be installed on recent distro including python 3.14 as default: fedora 43, ... |
|
Hmm, looks like the issue is real though. I'm not sure exactly what it is either. |
|
Hey folks! I'm currently trying to figure out what it would take for The CI failure appears to be related to symbol visibility of a couple of |
|
@lysnikolaou if you want to fork this and submit a PR with your modifications to test them on CI that would help. I have limited ability to look into the issues at the moment, but I'll review code if the dashboards are green. |
|
Sure, I can do that. I didn't want to step on any toes and open a PR before @jerome-benoit has signaled whether they're planning to move this forward. |
Python 3.14 introduces C++ templates in
dynamic_annotations.h(included viainternal/pycore_interp.h). This caused compilation errors ("template with C linkage") because these headers were included insideextern "C"blocks inc_trace_callbacks.h, which is required for Cython/C++ compatibility.This commit refactors the code to separate the interface from the implementation details:
_PyGC_FINALIZED,HAVE_STD_ATOMIC, etc.) fromc_trace_callbacks.htoc_trace_callbacks.c.c_trace_callbacks.cis now compiled asFix build on Python 3.14 by isolating internal C headersPython 3.14 introduces C++ templates in
dynamic_annotations.h(included viainternal/pycore_interp.h). This caused compilation errors ("template with C linkage") because these headers were included insideextern "C"blocks inc_trace_callbacks.h, which is required for Cython/C++ compatibility.This commit refactors the code to separate the interface from the implementation details:
_PyGC_FINALIZED,HAVE_STD_ATOMIC, etc.) fromc_trace_callbacks.htoc_trace_callbacks.c.c_trace_callbacks.cis now compiled as