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.

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.

2 participants