py/nlrthumb.c: restore r1,r2,r3 clobbers to nlr_push(); fixes many Thonny issues#10805
Merged
tannewt merged 1 commit intoadafruit:mainfrom Feb 6, 2026
Merged
py/nlrthumb.c: restore r1,r2,r3 clobbers to nlr_push(); fixes many Thonny issues#10805tannewt merged 1 commit intoadafruit:mainfrom
tannewt merged 1 commit intoadafruit:mainfrom
Conversation
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.
Many issues were reported when using Thonny. If the code that Thonny sent to the REPL, while in raw paste mode, raised an exception, then there could be a hard crash causing safe mode, and causing the Thonny connection to fail. This problem was exercised inside
parse_compile_execute()inpyexec.cwhen in raw paste mode, whenexec_flagsincludedEXEC_FLAG_SOURCE_IS_READER. Thereaderstruct would get smashed, causingreader->close()to be0x0.A long time ago, in #506,
"r1", "r2", "r3"were added to the "clobbers" list innlr_push(), inpy/nlrthumb.c. That change was lost during a MicroPython merge. #7368 tried to fix that in a different way, usingreturns_twice, as suggested in micropython#3889. But that change was not merged into MicroPython: instead, thenlrroutines were compiled with-fno-ltoinstead.However, #7368 did not really fix the register clobbering problem. It was introduced between 8.0.0-beta.5 and 8.0.0-beta.6. 8.0.0-beta.6 is when the Thonny problems started.
So this PR restores the original #506 fix, and discards the
returns_twice. I tested with a Metro M0 (SAMD21), a Metro M4 (SAMD51), a PCA10059 (nRF52840), and a Micro:bit V2, all with Thonny.It's possible this bug caused other problems, but I don't see as clear a lineage as with all these similar Thonny problems.
This PR also includes adafruit/samd-peripherals#48, which was needed when testing some debug builds.