Skip to content

Use sequence repetition for ctypes array types - #9185

Open
1ndahous3 wants to merge 3 commits into
RustPython:mainfrom
1ndahous3:ctypes_array_reflected
Open

1ndahous3 wants to merge 3 commits 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, including objects that provide an integer index. A right-hand operand can also customize the operation through its reverse multiplication behavior.
    • Invalid and out-of-range lengths raise ValueError, TypeError, or OverflowError, as appropriate.

@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-18T13:50:37.609603Z e1dbdce New commits
ℹ️ 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: 903857e8-fff2-4280-bc31-a876b6382341
📥 Commits

Reviewing files that changed from the base of the PR and between 9d9740e and e1dbdce.

📒 Files selected for processing: 1
  • 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 operands and lengths. 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 e1dbd

This change enables sequence repetition across ctypes type families while preserving index-like lengths and reflected multiplication. The inspected paths show no concrete merge-blocking regression; it is mergeable subject to normal checks.

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: using 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
@youknowone
youknowone enabled auto-merge (squash) October 18, 2026 13:36

@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: e1dbdce5da

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

Comment thread crates/vm/src/stdlib/_ctypes/union.rs
@codspeed

codspeed Bot commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by 15.86%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 61 untouched benchmarks
⏩ 4 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ rustpython[frozenset.py] 414.1 µs 357.5 µs +15.86%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing 1ndahous3:ctypes_array_reflected (e1dbdce) with main (6e064e5)2

Open in CodSpeed

Footnotes

  1. 4 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (e411f91) during the generation of this report, so 6e064e5 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

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