-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
ports/rp2: Replace pico-sdk assertion faults with python exceptions. #16991
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
base: master
Are you sure you want to change the base?
Conversation
|
Code size report: |
d8fdbc1 to
185f42f
Compare
|
Woof, is the 4k size gain because you've forced all assertions to be enabled here? This would probably be extremely useful for debugging user C modules, of which we (Pimoroni) have way, way too many, but should definitely be optional. Only a developer should ever see/care about these asserts, and if MicroPython is hitting a condition where an end user can trigger one then I'd argue that's a bug in MicroPython. But otherwise 👍 knowing how to hook this up might have saved us some real headaches. |
Come to think of it, maybe
Are there some debug assertion defines that already exist that could be used to gate this? |
Not as far as I'm aware, there's some debug stuff here but I've... surprisingly little experience with it 😬 Lines 501 to 544 in f1018ee
The ESP8266 port has an interesting (read: uncomplicated) take on this: micropython/ports/esp8266/esp_mphal.c Lines 131 to 134 in f1018ee
There doesn't really seem to be a consensus on dealing with SDK assertions in MicroPython itself, presumably because the various SDKs all have their own way of doing things. |
66ee83e to
bd6ec3d
Compare
|
It took me way too long messing around with trying to convert the assert flag's name into a qstr instead of just a raw char* (which didn't work), but yes: all of that size increase did indeed come down to that On the plus side, it looks like with that set to 0 now, the the compiler even ends up even fully eliding the text for |
Signed-off-by: Anson Mansfield <[email protected]>
Signed-off-by: Anson Mansfield <[email protected]>
bd6ec3d to
97a3ab4
Compare
Summary
This change replaces the default pico-sdk assertion fault handlers with new handlers that raise micropython exceptions.
Testing
I've verified that this works on real rp2040 hardware, using a custom module to trigger the pico-sdk assertion mechanism:
Which leads to:
Tradeoffs and Alternatives
It's not entirely clear what the best choice of exception and exception message is, and I invite comments on this topic.
At present I'm using variadic exceptions with a parameter derived from the name of the associated assertion enable gate.
invalid_params_ifandvalid_params_ifboth map toValueError("invalid params in pico-sdk %s"), andhard_assert_iffailures map toAssertionError("assertion failure in pico-sdk %s"). Should the latter perhaps be aRuntimeErrorrather than anAssertionError, though?