Repository navigation
Align ctypes call ownership and C error state with Python 3.15 - #9218
Conversation
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
⛔ Files ignored due to path filters: 15
📒 Files selected for processing: 11
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [ ] lib: cpython/Lib/ctypes dependencies:
dependent tests: (37 tests)
Legend:
|
Merging this PR will degrade performance by 13.4%
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
Keep native raised errors separate from handled exceptions and preserve them across teardown callbacks. Import the related canonical ctypes call and type contracts. Assisted-by: OpenAI Codex: model version unavailable
Copy loader-owned names before Python filesystem decoding and update the related canonical ctypes utility and discovery tests from CPython 3.15. Preserve existing platform paths and dllist test markers. Assisted-by: OpenAI Codex: model version unavailable
Regenerate the pinned test through update_lib patches with reviewed marker data. Preserve other platform conditions and the unavailable extension-fixture guard. Assisted-by: OpenAI Codex: model version unavailable
Use the existing Python float formatter for float and double C argument representations. Keep long-double arguments on the canonical generic-address representation path. Preserve the unchanged canonical parameter repr assertions. Assisted-by: OpenAI Codex: model version unavailable
607e121 to
841a1bb
Compare
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 841a1bbc9c
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let msg = format!("Exception ignored while calling ctypes callback function {repr}"); | ||
| vm.run_unraisable(exc.clone(), Some(msg), vm.ctx.none()); | ||
| } | ||
| vm.attach_for_callback(|| { |
There was a problem hiding this comment.
Save callback errno before reattaching the VM
When a use_errno=True callback is invoked from a normal detached CDLL call, this transition runs before with_callback_errno_preserved snapshots the real C errno. attach_for_callback can wait for stop-the-world or reacquire a critical-section lock, so an interrupted synchronization can overwrite errno and the helper then restores that value to the native caller instead of the callback-entry value; bracket the attach/detach transition with errno preservation or save errno before attaching.
Useful? React with 👍 / 👎.
| import_helper.import_module('ctypes') | ||
|
|
||
|
|
||
| class TestModule(unittest.TestCase): |
There was a problem hiding this comment.
Keep the canonical test bodies unchanged
This adds a new test class and assertions under Lib/test, but the repository policy permits test-file changes only for adding an expected-failure marker or removing one with its TODO after a pass. The canonical ctypes refresh also adds or rewrites other test bodies, so those changes need to be excluded rather than landed as test logic.
AGENTS.md reference: AGENTS.md:L280-L282
Useful? React with 👍 / 👎.
Summary
Extract the Python3.15 ctypes call-contract closure from #8954, with its required CAPI error-state dependency:
_ctypes.__getattr__behavior.The utility/dllist dependency is included: synchronous native enumeration on Linux and Android copies loader-owned names before Python decoding. Existing macOS/Windows paths are preserved; unsupported outer targets are not newly supported. Android uses the repository API24 baseline, above the loader API21 requirement. Contributor-owned sequence-repetition changes are not duplicated.
Validation
Current integrated checkpoint 841a1bb
Replayed the original three commits onto main
43368209c505c8807f5efdf3a39729bb30866722, preserving their authors and messages, followed by a separate C argument representation compatibility fix. The final complete source tree matches the locally validated candidate. This incorporates the already-landed benchmark harness correction without duplicating its changes in the PR-only diff.The unchanged canonical parameter-representation test exposed two pre-existing issues also present on the pinned main: Rust numeric Display expanded
1e300rather than using Python float repr, and long-double taggincorrectly took the numeric representation path. The fix uses the existing Python float formatter forf/dand the existing generic-address representation forg, without changing FFI conversion, storage, or test assertions. Both sequential failures and the original candidate were retained before validating the final correction.Final scoped validation:
_ctypes_testimport were not executed. No foreign callback invocation or broad ctypes suite is claimed.Limits: the pinned CPython installation used for this validation lacks its standard-library
_ctypesextension, so the control attempt stopped at import and no new cross-runtime success is claimed. No full suite, benchmark, crash/stress tests, or new ABI coverage was run in this integration pass.The historical frozenset CodSpeed regression (358.4 to 413.8 microseconds on old head
607e121) has not yet been remeasured or explained by this repr fix. New exact-head CI is pending after publication. The current benchmark environment guard can skip measurement while the workflow succeeds; only actual benchmark execution/upload and comparison evidence will count as a remeasurement.Historical combined checkpoint 607e121
The initial hosted Linux run at 8e78504 failed with
test_ctypesENV CHANGED: the old Python/libffi dllist callback raised an unraisableValueError: PyObject is NULL, then the test skipped its missing extension fixture. Its automatic rerun reproduced the same environmental failure. The native dllist dependency removes that obsolete callback path.ListSharedLibrariesunder canonical unraisable/environment checking: system test passes, genuine missing_ctypes_testfixture skips,environment_altered=false. The fixture guard is retained.Historical constituent evidence
Standalone dllist on main eb2ffc6: fresh release, 1,401 workspace tests passed/18 ignored, 123 CAPI tests passed/4 ignored, both strict Clippy gates passed. Historical main58b54 fails the unchanged system-enumeration body with
Unsupported argument type; native candidate and oracle pass. Local Android runtime and OpenGL-loader coverage are not claimed.Original ctypes checkpoint 8e78504 (fresh sqlite+capi release):
_ctypes_testguard._ctypes.__getattr__(None/42/tuple)produced TypeError on sealed mega baseline and now matches the oracle's exact AttributeError/messages.Important provenance: mega already had the separate raised slot. The initial narrowed extraction omitted that dependency; it was restored before candidate runtime. The same PYFUNCTYPE inside-except probe passed on both mega and oracle, so this PR does not claim a newly reproduced mega conflation bug.
The native guard test checks storage nesting and Rust unwind. The Python teardown selections exercise real boundaries, but do not establish every nonempty-native-error reentrancy combination. No all-platform ABI or comprehensive callback/GC parity claim. Existing foreign-thread callback entry, callback conversion-error reporting, errcheck locking and incomplete callback metadata traversal remain separate limitations.
OpenAI Codex assisted with implementation, source review, canonical regeneration, automated validation and this PR description. The stated local checks were automated; this does not claim manual human testing. Prepared for the user's maintainer-directed Python3.15 upgrade work.