Skip to content

Conversation

@jerome-benoit
Copy link

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

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]>
Copilot AI review requested due to automatic review settings November 24, 2025 17:09
Copy link

Copilot AI left a 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.

@jerome-benoit jerome-benoit changed the title Fix build on Python 3.14 by isolating internal C headers Fix build on Python 3.14 + GCC 15 by isolating internal C headers Nov 24, 2025
@jerome-benoit
Copy link
Author

@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, ...

@Erotemic
Copy link
Member

Erotemic commented Dec 1, 2025

Hmm, looks like the issue is real though. I'm not sure exactly what it is either.

@lysnikolaou
Copy link

Hey folks! I'm currently trying to figure out what it would take for line_profiler to support the free-threaded build of Python 3.14. This problem is blocking me. Could I help move this along?

The CI failure appears to be related to symbol visibility of a couple of inline functions. Moving these function from the .c file to the header file and defining them with static inline ought to fix the issue, I think.

@Erotemic
Copy link
Member

Erotemic commented Jan 7, 2026

@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.

@lysnikolaou
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants