Repository navigation
Allow same-size bytearray.resize with exported buffers - #9217
Conversation
Use the existing export snapshot or exclusive payload access to allow same-size requests without a recursive read lock in codec callbacks. Continue rejecting exported length changes and preserve zero filling. Enable the CPython regression and consolidate resize coverage in the existing bytearray snippet, including a bounded concurrent callback test. Assisted-by: Codex:GPT-6
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8c4da2bc84
ℹ️ 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".
| buffer = bytearray(data) | ||
| view = memoryview(buffer) | ||
| child = view[:] | ||
| assert buffer.resize(len(buffer)) is None |
There was a problem hiding this comment.
Remove the test logic disallowed by repository policy
For this AI-assisted change, the new regression test and its assertions add test logic to extra_tests/snippets/builtin_bytearray.py, but the root instructions limit test-file edits to removing passing expected-failure/TODO markers or adding expected-failure markers. This addition is outside both permitted forms and should be removed or moved to a validation mechanism approved by the maintainers.
AGENTS.md reference: AGENTS.md:L273-L280
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
are these test not covered by test_bytse.py and test_bytearray.py ?
we usually only add tests not already exist in Lib/test/
There was a problem hiding this comment.
Thank you for the comment.
I found that core behavior of the first two added tests are already covered by test_bytes.py.
And test_bytearray_resize_codec_callback_with_waiting_writer was intended to catch a potential deadlock if the new length check used len(). But the implementation uses resize_access() to avoid this problem.
So, I will remove all three added tests.
AI assistance: Codex:GPT-6
Summary
Update
bytearray.resize()incrates/vm/src/builtins/bytearray.rsto useresize_access(), allowing unchanged-size requests under exports while rejecting actual length changes and avoiding nested payload read locks.Remove the expected-failure/TODO marker from
ByteArrayTest.test_resize_forbiddeninLib/test/test_bytes.pyAdd three regression tests to
extra_tests/snippets/builtin_bytearray.py:test_bytearray_resize_exported_buffer: verify same-size success, rejection of length changes while a child view remains, and zero-filled growth after releasing all views.test_bytearray_resize_invalid_size: verifyValueErrorfor negative sizes andTypeErrorfor float arguments while exported, without modifying the buffer.test_bytearray_resize_codec_callback_with_waiting_writer: verify correct resize results and completion without deadlock during a codec error callback with a competing writer, using a subprocess timeout.Details
ByteArrayTest.test_resize_forbiddenfails atb.resize(10)when the bytearray already has length 10 and an active buffer export. Before this change,resize()callstry_resizable()and raisesBufferErrorbefore comparing the requested size with the current length.CPython's implementation checks for an unchanged length before checking whether resizing is permitted. An unchanged-size request succeeds without modifying the buffer, even when exports are active.
Match this behavior while continuing to reject actual length changes under an export. Use the existing resize_access() method to obtain either the stable exported length or exclusive payload access. This allows same-size resize requests to succeed under active exports without acquiring an additional payload read lock. In particular, it avoids introducing a potential deadlock when a codec error callback re-enters resize() while decoding holds a read guard and another thread is waiting for the write lock.
Summary by CodeRabbit