Skip to content

extmod/vfs_blockdev: Support bool return from Python read/write blocks. #16222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

dpgeorge
Copy link
Member

@dpgeorge dpgeorge commented Nov 13, 2024

Summary

Commit f4ab9d9 inadvertently broke some Python block devices, for example esp32 and stm32 SDCard classes. Those classes return a bool from their readblocks and writeblocks methods instead of an integer errno code. With that change, both False and True return values are now be interpreted as non-zero and hence the block device call fails.

The fix in this commit is to allow a bool and explicitly convert True to 0 and False to -MP_EIO.

Fixes issues #16171 and #16214.

Testing

Tested on PYBV11 using:

import pyb, vfs
sdcard = pyb.SDCard()
vfs.VfsFat(sdcard)

That would previously fail, but with this patch passes.

Tested also on ESP32 (a Lolin 32 Pro). Wit this patch mounting an SD card passes.

Trade-offs and Alternatives

This is a simple fix and a candidate for a patch release (1.24.1). An alternative is to make the Python blockdev functions return integers instead of bools, but that's an API change.

Edit: see #16223 for the alternative.

Commit f4ab9d9 inadvertently broke some
Python block devices, for example esp32 and stm32 SDCard classes.  Those
classes return a bool from their `readblocks` and `writeblocks` methods
instead of an integer errno code.  With that change, both `False` and
`True` return values are now be interpreted as non-zero and hence the block
device call fails.

The fix in this commit is to allow a bool and explicitly convert `True` to
0 and `False` to `-MP_EIO`.

Signed-off-by: Damien George <damien@micropython.org>
@dpgeorge dpgeorge added the extmod Relates to extmod/ directory in source label Nov 13, 2024
Copy link

codecov bot commented Nov 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.57%. Comparing base (611d8f9) to head (5dc9eda).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #16222   +/-   ##
=======================================
  Coverage   98.57%   98.57%           
=======================================
  Files         164      164           
  Lines       21345    21347    +2     
=======================================
+ Hits        21041    21043    +2     
  Misses        304      304           

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

Copy link

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:   +16 +0.002% standard
      stm32:   +16 +0.004% PYBV10
     mimxrt:   +16 +0.004% TEENSY40
        rp2:    +8 +0.001% RPI_PICO_W
       samd:   +16 +0.006% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

Copy link
Contributor

@projectgus projectgus left a comment

Choose a reason for hiding this comment

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

Thanks for following this up. This looks good to me as the stop-gap for a patch release.

@dpgeorge
Copy link
Member Author

I tested on ESP32 and this patch fixes the issue.

@dpgeorge dpgeorge merged commit 5dc9eda into micropython:master Nov 18, 2024
60 of 62 checks passed
@dpgeorge dpgeorge deleted the extmod-vfs-blockdev-support-bool-return branch November 18, 2024 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extmod Relates to extmod/ directory in source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy