chore(native): declare PyContextVar_* locally for limited-API builds (PROF-15850) - #19903
chore(native): declare PyContextVar_* locally for limited-API builds (PROF-15850)#19903vlad-scherbich wants to merge 3 commits into
Conversation
|
BenchmarksBenchmark execution time: 2026-08-28 16:32:50 Comparing candidate commit bb9aaf9 in PR branch Found 0 performance improvements and 7 performance regressions! Performance is the same for 575 metrics, 10 unstable metrics, 2 known flaky benchmarks, 16 flaky benchmarks without significant changes.
|
|
Part of #19908 |
There was a problem hiding this comment.
Pull request overview
This PR fixes Rust native extension builds under Py_LIMITED_API (e.g., CPython 3.15 builds using PYO3_USE_ABI3_FORWARD_COMPATIBILITY) by locally declaring the PyContextVar_New, PyContextVar_Get, and PyContextVar_Set C-API entry points that are not exposed by pyo3-ffi in that configuration.
Changes:
- Add local
extern "C"declarations forPyContextVar_*functions insrc/native/contextvar.rs. - Switch call sites from
ffi::PyContextVar_*to the locally declared symbols so the module compiles with and withoutPy_LIMITED_API.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
5e2e905 to
9c1783d
Compare
Codeowners resolved asResolved from the full PR diff against |
Circular import analysis
|
Dependency direction analysis
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5e2e90539b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
f668305 to
def36ad
Compare
f9ee924 to
12acbff
Compare
12acbff to
59047aa
Compare
59047aa to
bb9aaf9
Compare
4362679 to
c493409
Compare
pyo3-ffi gates its entire `context` module behind `not(Py_LIMITED_API)` (pyo3-ffi 0.28.3 `src/lib.rs` lines 436 and 503), so `ffi::PyContextVar_New`, `ffi::PyContextVar_Get` and `ffi::PyContextVar_Set` disappear whenever the extension is built against the stable ABI. On CPython 3.15 that happens via `PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1`, since pyo3-build-config 0.28.3 caps `ABI3_MAX_MINOR` at 14. The build then fails with three E0425 "cannot find function ... in module `ffi`" errors on this file. Declare the three stable C API entry points locally so the module compiles in both configurations. Context variables date to Python 3.7, so the symbols are present on every interpreter ddtrace supports; verified to compile clean on 3.9, 3.13 and 3.15 with and without the stable-ABI path. Same class of fix as #18429, which closed the sibling `PyFrame_GetBack` gap for the crashtracker. Extracted from fc09033 on #19833, which bundled it with three unrelated formatting fixes. The code is unchanged from that commit; only the explanatory comment above the declarations was reworded. Co-authored-by: Vlad Scherbich <vlad.scherbich@datadoghq.com>
bb9aaf9 to
c2e9f4f
Compare
Description
pyo3-ffi hides
PyContextVar_New/_Get/_Setundernot(Py_LIMITED_API). CPython3.15 builds take
PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1(pyo3-build-config 0.28.3 capsABI3_MAX_MINORat 14), so those symbols vanish and the native module fails with E0425.This PR declares the three stable C API entry points locally in
src/native/contextvar.rs.Context variables exist since 3.7, so the symbols are on every interpreter we support.
If this merges and nothing else new lands: limited-API contextvar builds compile. No publish,
testrunner, riot, or
requires-pythonchange.Testing
Compiled clean on 3.9, 3.13, and 3.15, with and without the stable-ABI path.
Risks
None. Declarations match the stable C API; they do not change runtime behavior on 3.9–3.14.
Additional Notes
Extracted from #19833 (cc @wconti27). Closes #19908. Same class of fix as #18429.
No release note: internal compile fix,
changelog/no-changelog.Base: #19861. Next: #19905 (testrunner pyenv bump).