Skip to content

Fix build on Python 3.14 by isolating internal C headers and removing inline specifiers#412

Merged
Erotemic merged 2 commits into
pyutils:mainfrom
lysnikolaou:build-314
Jan 21, 2026
Merged

Fix build on Python 3.14 by isolating internal C headers and removing inline specifiers#412
Erotemic merged 2 commits into
pyutils:mainfrom
lysnikolaou:build-314

Conversation

@lysnikolaou
Copy link
Copy Markdown
Contributor

Supersedes #408.

jerome-benoit and others added 2 commits November 24, 2025 18:06
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
Copy link
Copy Markdown

codecov Bot commented Jan 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.28%. Comparing base (60e928f) to head (cf36ee9).
⚠️ Report is 25 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

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

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 630abb0...cf36ee9. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lysnikolaou
Copy link
Copy Markdown
Contributor Author

Failure on 3.14 is unrelated. There's already an open issue tracking it on #411.

@jerome-benoit
Copy link
Copy Markdown
Contributor

@Erotemic: It would be great to have a release with that PR in. Currently line_profiler is not even an installable package with python 3.14.

@Erotemic
Copy link
Copy Markdown
Member

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.

@lysnikolaou
Copy link
Copy Markdown
Contributor Author

Can we maybe merge this nevertheless so that main is buildable without having to check out this PR?

@chatgpt-codex-connector
Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

1 similar comment
@chatgpt-codex-connector
Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

Copy link
Copy Markdown
Member

@Erotemic Erotemic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_callback to static is better to signal that it isn't used anywhere else.

  • Removing inline set_local_trace and monitoring_restart_version solves 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.

@Erotemic Erotemic merged commit 2df0060 into pyutils:main Jan 21, 2026
44 of 45 checks passed
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