Visitar URL original
Fix ctypes function pointer casts on Python 3.14 by youknowdot · Pull Request #8965 · RustPython/RustPython · GitHub
Skip to content

Fix ctypes function pointer casts on Python 3.14 - #8965

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:python314-ctypes-casts
Oct 5, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:python314-ctypes-casts

Conversation

@youknowdot

Copy link
Copy Markdown
Contributor

Casting a ctypes function pointer currently reads its storage address, and cast() rejects a function-pointer destination type. Load the stored callable address and recognize PyCFuncPtrType destinations. A callback can then roundtrip through c_void_p and remain callable after its original variables are dropped, using the existing ownership dictionary.

This two-file change is extracted from #8954 onto main f39b054b9c8cbbf884f53123eef028131789990c, retaining the Python 3.14 target. Its implementation remains in the mega upgrade until merged independently. The behavior matches CPython 3.14 cast validation.

One unique regression extends the existing ctypes snippet. Canonical cast tests cover data/string pointers; structure-field callback retention and integer/native-return function construction do not cover this callable-address roundtrip. No existing assertions or markers change.

Fresh standalone validation on e8bd96dc6c32c259c53a43ddbf4ba2c13ff65c64, Linux x86-64:

  • Rust workspace: 1,345 passed /18 ignored; separate C-API: 116 passed /4 ignored
  • Release startup confirms Python 3.14; the new callable-address/ownership regression passes natively and on exact CPython 3.14.7
  • Full test_ctypes: 322 run, 56 skipped, 5 retained expected failures; no unraisable exception or environment change. Fixture-dependent callback modules still skip because _ctypes_test is unavailable in the native build
  • Full snippets: 468 passed /12 environment failures. Native 234/4, exact CPython 3.14.7 reference 234/4, host harness 0/4. The same multiprocessing AF_UNIX and UID/GID-map restrictions occur on both interpreters; no new source skips hide them
  • Both Clippy gates and normal configured commit hooks pass without warnings

The broader callback argument/py_object transport work remains separate; this PR is scoped to cast().

AI assistance: prepared, reviewed and tested with Codex at the user's direction. Exact model metadata is unavailable; the commit records Assisted-by: Codex:model-version-unavailable.

Read the stored executable address when casting a function pointer and accept function pointer types as cast destinations. The existing ownership dictionary retains the original callback through a cast roundtrip.

Extracted independently on the unchanged Python 3.14 target, without typed callback argument or broader py_object transport changes. One unique callback-address/ownership regression extends the existing ctypes snippet; canonical coverage was checked for duplicates.

Assisted-by: Codex:model-version-unavailable
@coderabbitai

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Repository: RustPython/RustPython/.coderabbit.yml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 25d3d0a7-ba9a-4728-8384-aa3423635dd8
📥 Commits

Reviewing files that changed from the base of the PR and between 7536730 and e8bd96d.

📒 Files selected for processing (2)
  • crates/vm/src/stdlib/_ctypes/function.rs
  • extra_tests/snippets/stdlib_ctypes.py
 ______________________________________
< I read stack traces like tea leaves. >
 --------------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@youknowone
youknowone merged commit f46ba48 into RustPython:main Oct 5, 2026
30 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.

2 participants