Skip to content

Honor stored ctypes byref addresses in cast and memory access - #9184

Open
1ndahous3 wants to merge 1 commit into
RustPython:mainfrom
1ndahous3:ctypes_byref_pointer
Open

1ndahous3 wants to merge 1 commit into
RustPython:mainfrom
1ndahous3:ctypes_byref_pointer

Conversation

@1ndahous3

@1ndahous3 1ndahous3 commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Found while importing icalendar 7.3.0 on Windows, where python-dateutil casts a byref argument during timezone lookup.

Summary

  • Accept pointer argument wrappers in ctypes.cast() and use their stored address, including the byref() offset, for memory access.
  • Preserve c_void_p.from_param() support and reject argument wrappers for non-pointer types.

AI assistance

Written with Codex (GPT-6), reviewed by a human before submission.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected pointer handling so references created with byref account for the requested byte offset when accessing memory.
    • Improved pointer conversions to use addresses from compatible pointer arguments, including when creating a pointer from an integer address.
    • Invalid byte-string inputs to pointer casting and zero-length memory reads are now rejected.

Assisted-by: Codex:GPT-6
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-18T08:59:31.919349Z 980cbe6 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: RustPython/RustPython/.coderabbit.yml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d5bb83da-0359-49ed-b345-d0eb19577ae2
📥 Commits

Reviewing files that changed from the base of the PR and between 9f6f771 and 980cbe6.

📒 Files selected for processing: 2
  • crates/vm/src/stdlib/_ctypes/function.rs
  • extra_tests/snippets/stdlib_ctypes.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

Pointer extraction and casting now use stored addresses from matching P-tagged argument wrappers. The added tests check byref offsets, pointer reads, and rejected c_char_p.from_param inputs.

Changes: ctypes Pointer Argument Handling

Layer / File(s) Summary
Pointer argument conversion and regression checks
crates/vm/src/stdlib/_ctypes/function.rs, extra_tests/snippets/stdlib_ctypes.py
extract_ptr_from_arg and cast_impl use addresses from matching P-tagged CArgObject wrappers. Tests check byref offsets, pointer reads, and errors for casting or reading zero bytes from c_char_p.from_param(b"x").

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: youknowone

Merge Risk: ⚪ Minimal · up to 980cb

No issue remains that needs resolution before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly summarizes the main change: using stored ctypes byref addresses during casting and memory access.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · 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.

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.

1 participant