Skip to content

Commit 03a4f85

Browse files
authored
Merge pull request #4713 from jepler/mpy-magic-number
Change the first byte of CircuitPython 'mpy' files to "C"
2 parents 22feda1 + ef3ec93 commit 03a4f85

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

mpy-cross/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ MP_NOINLINE int main_(int argc, char **argv) {
210210
if (strcmp(argv[a], "-X") == 0) {
211211
a += 1;
212212
} else if (strcmp(argv[a], "--version") == 0) {
213-
printf("MicroPython " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE
214-
"; mpy-cross emitting mpy v" MP_STRINGIFY(MPY_VERSION) "\n");
213+
printf("CircuitPython " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE
214+
"; mpy-cross emitting mpy v" MP_STRINGIFY(MPY_VERSION) "-CircuitPython\n");
215215
return 0;
216216
} else if (strcmp(argv[a], "-v") == 0) {
217217
mp_verbose_flag++;

py/persistentcode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader, qstr_window_t *qw) {
564564
mp_raw_code_t *mp_raw_code_load(mp_reader_t *reader) {
565565
byte header[4];
566566
read_bytes(reader, header, sizeof(header));
567-
if (header[0] != 'M'
567+
if (header[0] != 'C'
568568
|| header[1] != MPY_VERSION
569569
|| MPY_FEATURE_DECODE_FLAGS(header[2]) != MPY_FEATURE_FLAGS
570570
|| header[3] > mp_small_int_bits()
@@ -819,7 +819,7 @@ void mp_raw_code_save(mp_raw_code_t *rc, mp_print_t *print) {
819819
// byte number of bits in a small int
820820
// uint size of qstr window
821821
byte header[4] = {
822-
'M',
822+
'C',
823823
MPY_VERSION,
824824
MPY_FEATURE_ENCODE_FLAGS(MPY_FEATURE_FLAGS_DYNAMIC),
825825
#if MICROPY_DYNAMIC_COMPILER

tests/import/mpy_native.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ def open(self, path, mode):
5858
# these are the test .mpy files
5959
user_files = {
6060
# bad architecture
61-
"/mod0.mpy": b"M\x05\xff\x00\x10",
61+
"/mod0.mpy": b"C\x05\xff\x00\x10",
6262
# test loading of viper and asm
6363
"/mod1.mpy": (
64-
b"M\x05\x0b\x1f\x20" # header
64+
b"C\x05\x0b\x1f\x20" # header
6565
b"\x20" # n bytes, bytecode
6666
b"\x00\x08\x02m\x02m" # prelude
6767
b"\x51" # LOAD_CONST_NONE
@@ -78,7 +78,7 @@ def open(self, path, mode):
7878
),
7979
# test loading viper with truncated data
8080
"/mod2.mpy": (
81-
b"M\x05\x0b\x1f\x20" # header
81+
b"C\x05\x0b\x1f\x20" # header
8282
b"\x20" # n bytes, bytecode
8383
b"\x00\x08\x02m\x02m" # prelude
8484
b"\x51" # LOAD_CONST_NONE
@@ -88,7 +88,7 @@ def open(self, path, mode):
8888
),
8989
# test loading viper with additional scope flags and relocation
9090
"/mod3.mpy": (
91-
b"M\x05\x0b\x1f\x20" # header
91+
b"C\x05\x0b\x1f\x20" # header
9292
b"\x20" # n bytes, bytecode
9393
b"\x00\x08\x02m\x02m" # prelude
9494
b"\x51" # LOAD_CONST_NONE

tools/mpy-tool.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,8 +767,8 @@ def read_raw_code(f, qstr_win):
767767
def read_mpy(filename):
768768
with open(filename, "rb") as f:
769769
header = bytes_cons(f.read(4))
770-
if header[0] != ord("M"):
771-
raise Exception("not a valid .mpy file")
770+
if header[0] != ord("C"):
771+
raise Exception("not a valid CircuitPython .mpy file")
772772
if header[1] != config.MPY_VERSION:
773773
raise Exception("incompatible .mpy version")
774774
feature_byte = header[2]

tools/mpy_ld.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ def build_mpy(env, entry_offset, fmpy, native_qstr_vals, native_qstr_objs):
909909
out.write_bytes(
910910
bytearray(
911911
[
912-
ord("M"),
912+
ord("C"),
913913
MPY_VERSION,
914914
env.arch.mpy_feature,
915915
MP_SMALL_INT_BITS,

0 commit comments

Comments
 (0)