Skip to content

Release array and list locks around fromlist conversions - #9030

Merged
youknowone merged 1 commit into
RustPython:mainfrom
1ndahous3:array_fromlist_reentry
Oct 10, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
1ndahous3:array_fromlist_reentry

Conversation

@1ndahous3

@1ndahous3 1ndahous3 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Prevent array.fromlist from deadlocking when __index__ or __float__ accesses the destination array or modifies the source list.
  • Preserve CPython's preliminary resize, live list contents, size-change errors, and rollback behavior, including buffer exports created during conversion.
  • Keep bulk conversion for exact builtin values. Empty input succeeds when the array has exported buffers.
  • Complete the fromlist follow-up to Fix array search equality and reentrant callbacks #8870.

AI assistance

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

Summary by CodeRabbit

  • Bug Fixes
    • Improved array.fromlist handling for bulk conversions and values that require individual conversion. Conversion failures no longer leave partially appended values when rollback is possible.
    • Changes to the source list during conversion are detected, and existing error behavior is covered for index and memoryview export cases.
  • Tests
    • Added coverage for conversion callback order, source-list and array mutations, conversion failures, and memoryview exports.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 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-09T17:44:17.242339Z af30f73 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 9, 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: f2d9ce9d-08aa-41bb-b1c4-e4c6c9b997bf

📥 Commits

Reviewing files that changed from the base of the PR and between f5b6526 and af30f73.


📒 Files selected for processing (2)
  • crates/stdlib/src/array.rs
  • extra_tests/snippets/stdlib_array.py

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



📝 Walkthrough

Walkthrough

array.fromlist now uses bulk conversion for lists of exact built-in values and per-item conversion for other values. It checks for source-list changes during callbacks and attempts to restore the array length after errors.

Changes

Array fromlist behavior

Layer / File(s) Summary
Array conversion and resize helpers
crates/stdlib/src/array.rs
Bulk extension converts all items before appending. The new resize helper fills added entries with element defaults and returns MemoryError if capacity reservation fails. WideChar and Ucs4Char now derive Default.
fromlist conversion and callback handling
crates/stdlib/src/array.rs, extra_tests/snippets/stdlib_array.py
fromlist returns for an empty list, bulk-converts lists of exact int, float, bool, or str values, and otherwise converts items individually. It detects source-list size changes and attempts to restore the original array length after errors. Tests cover callbacks, list mutation, rollback, and memoryview exports.

Priority: ➖ Normal

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

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Fromlist as PyArray.fromlist
  participant Source as Source list
  participant Callback as Conversion callback
  participant Storage as Array storage
  Fromlist->>Source: Read list length and items
  Fromlist->>Storage: Resize with default elements
  loop For each item
    Fromlist->>Callback: Convert item
    Callback->>Source: May change list
    Callback->>Storage: May change array
    Fromlist->>Storage: Assign converted item
  end
  Fromlist->>Source: Check list length
  Fromlist->>Storage: Attempt length rollback after error
Loading

Suggested reviewers: youknowone


Merge Risk: ⚪ Minimal · up to af30f

This change makes array.fromlist avoid lock-related deadlocks when conversion callbacks touch the array or the source list, while preserving rollback and error behavior. No concrete merge-blocking risk was identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 8.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 accurately identifies the main change: releasing array and list locks during fromlist conversions to prevent deadlocks and support callbacks that access or modify these objects.
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.

@youknowone youknowone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@youknowone
youknowone merged commit 11a8de1 into RustPython:main Oct 10, 2026
30 checks passed
@1ndahous3
1ndahous3 deleted the array_fromlist_reentry branch October 13, 2026 08:22
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