Skip to content

py/objarray: Update slice data only if necessary. - #19658

Open
agatti wants to merge 2 commits into
micropython:masterfrom
agatti:mem_backup_slice
Open

py/objarray: Update slice data only if necessary.#19658
agatti wants to merge 2 commits into
micropython:masterfrom
agatti:mem_backup_slice

Conversation

@agatti

@agatti agatti commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

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 basics and extmod test 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.

@agatti

agatti commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

Ugh, minimal doesn't have slices? :| Fair enough, I'll create a new test then...

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

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.58%. Comparing base (4d80ff0) to head (c00fdf0).
⚠️ Report is 2 commits behind head on master.

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           
Flag Coverage Δ
unix-coverage-32bit 98.59% <100.00%> (+<0.01%) ⬆️
unix-coverage-64bit 98.52% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown

Code size report:

Reference:  esp32: Make esp32.LDO objects static, release on soft reset. [f668077]
Comparison: tests/extmod/machine_mem_backup: Add slice read/write test. [merge of c00fdf0]
  mpy-cross:    +0 +0.000% 
   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:   +16 +0.002% standard
      stm32:    +8 +0.002% PYBV10
      esp32:    -4 -0.000% ESP32_GENERIC
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +8 +0.001% RPI_PICO_W
       samd:    +8 +0.003% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +4 +0.001% VIRT_RV32

@agatti agatti added the py-core Relates to py/ directory in source label Aug 27, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

py-core Relates to py/ directory in source

Projects

None yet

Development

Successfully merging this pull request may close these issues.

esp32: slice assignment into machine.mem_backup() memoryview resets the chip (ESP32-S3, v1.29.0)

1 participant