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 12 commits into
Conversation
|
BenchmarksBenchmark execution time: 2026-08-30 18:56:06 Comparing candidate commit 72d7f7a in PR branch Found 0 performance improvements and 6 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
Monitoring inject_hook already works. The wrap raise tests are skipif below NEXT and would demand a raise after wrap lift; they do not pin this PR error-string change. (cherry picked from commit 08c8693)
The SSI max bump does not need a bandit/mypy skip of lib-injection/. (cherry picked from commit 0cf5c73)
(cherry picked from commit cbe119a)
Lint extra bytecode==0.18.1 on 3.15 is not the runtime dep bytecode>=0.19.0. Leave both; they are different extras. (cherry picked from commit 5bd7d37)
Lint extra bytecode==0.18.1 conflicts with runtime bytecode>=0.19.0 when uv resolves extras for requires-python that includes 3.15. (cherry picked from commit cac61ca)
pyo3-ffi hides PyGILState_Check under Py_LIMITED_API (3.15 ABI3 forward-compat). The symbol is not limited-API; declare it locally so the crashtracker path compiles.
…PI builds" This reverts commit 652f657.
PyGILState_Check is not in the limited/stable ABI. This is a signal-handler probe, so do not shim or Ensure; on Py_LIMITED_API skip Python C API use. Lands on the shared limited-API parent so unofficial and profiling both inherit.
Description
Delta vs #19861.
src/native/contextvar.rsdeclaresPyContextVar_New/_Get/_Setlocally and calls those instead ofpyo3::ffi. pyo3-ffi omits them from limited-API bindings.If this merges and nothing else new lands: limited-API contextvar builds compile. No publish, testrunner, riot, or
requires-pythonchange.Testing
Native module compiles with the local declarations.
Risks
None. Declarations do not change runtime behavior on 3.9–3.14.
Additional Notes
No release note: internal compile fix,
changelog/no-changelog.Base: #19861. Next: #19907.