Skip to content

Use sequence repetition for ctypes array types - #9185

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

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

Conversation

@1ndahous3

@1ndahous3 1ndahous3 commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Found while importing Scapy 2.8.0 on Windows, where an array type is declared as 8 * ctypes.c_char.

Summary

  • Support both multiplication orders for all ctypes type families, including unions and function pointers.
  • Use the shared sequence-repeat slot to accept integer-like lengths and preserve reflected-operator dispatch.

AI assistance

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

Summary by CodeRabbit

  • New Features
    • ctypes types now support sequence repetition in either operand order, including scalar, array, pointer, structure, union, and function-pointer types.
    • Repetition accepts integer-like values and reports ValueError, TypeError, or OverflowError for invalid or out-of-range lengths.

@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:15.780051Z 6afdb23 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: 47ae5785-df77-45b5-a13e-74378064a23f
📥 Commits

Reviewing files that changed from the base of the PR and between 9f6f771 and 6afdb23.

📒 Files selected for processing: 7
  • crates/vm/src/stdlib/_ctypes/array.rs
  • crates/vm/src/stdlib/_ctypes/function.rs
  • crates/vm/src/stdlib/_ctypes/pointer.rs
  • crates/vm/src/stdlib/_ctypes/simple.rs
  • crates/vm/src/stdlib/_ctypes/structure.rs
  • crates/vm/src/stdlib/_ctypes/union.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; 8 remain after this review.

📝 Walkthrough

ctypes metaclasses now use sequence protocols for type repetition. Array-type creation uses a shared helper that validates lengths and operands. Tests cover repetition across ctypes types, index-based lengths, and reflected multiplication.

Changes: ctypes Sequence Repetition

Layer / File(s) Summary
Shared array repetition
crates/vm/src/stdlib/_ctypes/array.rs
Array types use sequence methods for repetition. The shared helper rejects negative lengths, non-type operands, and lengths above the isize-based limit with the corresponding errors, then calls the cached array-type factory.
Sequence protocol across ctypes metaclasses
crates/vm/src/stdlib/_ctypes/function.rs, crates/vm/src/stdlib/_ctypes/pointer.rs, crates/vm/src/stdlib/_ctypes/simple.rs, crates/vm/src/stdlib/_ctypes/structure.rs, crates/vm/src/stdlib/_ctypes/union.rs, extra_tests/snippets/stdlib_ctypes.py
Function-pointer, pointer, simple, structure, and union metaclasses expose the shared sequence methods instead of numeric multiplication methods. Simple-type repetition delegates to the shared array helper. Tests cover both operand orders, index-based lengths, and reflected multiplication.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: youknowone

Merge Risk: ⚪ Minimal · up to 6afdb

This change makes 8 * ctypes.c_char and ctypes.c_char * 8 both work for ctypes array types, which fixes the Scapy import failure on Windows. No concrete merge-blocking risk was identified, and tests cover both operand orders and reflected multiplication.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 53.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 30 functions across 7 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 and concisely describes the main change: replacing numeric multiplication with sequence repetition for ctypes array types. It matches the pull request objectives and changeset.
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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6afdb235cd

ℹ️ 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".

Comment thread extra_tests/snippets/stdlib_ctypes.py
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