py/objarray: Update slice data only if necessary. - #19658
Open
agatti wants to merge 2 commits into
Open
Conversation
Contributor
Author
|
Ugh, |
This commit skips modifications to array slices length information if there is no change in the slice size. For simplicity reasons both the slice size and the slice free items count were always updated on every memory access. This could be a problem if the slice object is pre-built and located in ROM, as some microcontrollers may trigger a bus error or other exceptions in that case. These changes make the update conditional, occurring only if the slice size has been changed. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #19658 +/- ##
=======================================
Coverage 98.58% 98.58%
=======================================
Files 182 182
Lines 23322 23323 +1
Branches 5 5
=======================================
+ Hits 22993 22994 +1
Misses 328 328
Partials 1 1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
agatti
force-pushed
the
mem_backup_slice
branch
from
August 27, 2026 07:12
def88be to
3447123
Compare
|
Code size report: |
This commit expands the test for `machine.mem_backup` to also include read and write operations through a memoryview slice. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
agatti
force-pushed
the
mem_backup_slice
branch
from
August 28, 2026 03:48
3447123 to
c00fdf0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR skips modifications to array slices length information if there is no change in the slice size.
For simplicity reasons both the slice size and the slice free items count were always updated on every memory access. This could be a problem if the slice object is pre-built and located in ROM, as some microcontrollers may trigger a bus error or other exceptions in that case.
That is true at least in the ESP32 port, in which the memoryview object is located in ROM, causing issues like #19655 for example.
I've also added some slice read/write to the relevant test.
This closes #19655.
Testing
The
basicsandextmodtest suites pass on an ESP32S3.Octoprobe will hopefully test the rest of the ports :)
Trade-offs and Alternatives
Since the slice update is now conditional there may be a minor size increase.
Generative AI
I did not use generative AI tools when creating this PR.