Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2b74ad8

Browse files
authored
Merge pull request adafruit#10622 from dhalbert/micropython-mpy-import
Better error when mistakenly importing MicroPython .mpy file
2 parents 77bd2db + 5d1bbca commit 2b74ad8

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

locale/circuitpython.pot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,6 +1394,10 @@ msgstr ""
13941394
msgid "Mapping must be a tuple"
13951395
msgstr ""
13961396

1397+
#: py/persistentcode.c
1398+
msgid "MicroPython .mpy file; use CircuitPython mpy-cross"
1399+
msgstr ""
1400+
13971401
#: ports/raspberrypi/bindings/rp2pio/StateMachine.c
13981402
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
13991403
msgid "Mismatched data size"

py/persistentcode.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,9 @@ void mp_raw_code_load(mp_reader_t *reader, mp_compiled_module_t *cm) {
471471
read_bytes(reader, header, sizeof(header));
472472
byte arch = MPY_FEATURE_DECODE_ARCH(header[2]);
473473
// CIRCUITPY-CHANGE: 'C', not 'M'
474+
if (header[0] == 'M') {
475+
mp_raise_ValueError(MP_ERROR_TEXT("MicroPython .mpy file; use CircuitPython mpy-cross"));
476+
}
474477
if (header[0] != 'C'
475478
|| header[1] != MPY_VERSION
476479
|| (arch != MP_NATIVE_ARCH_NONE && MPY_FEATURE_DECODE_SUB_VERSION(header[2]) != MPY_SUB_VERSION)

0 commit comments

Comments
 (0)