Skip to content

Change the first byte of CircuitPython 'mpy' files to "C" #4713

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
merged 1 commit into from
May 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mpy-cross/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ MP_NOINLINE int main_(int argc, char **argv) {
if (strcmp(argv[a], "-X") == 0) {
a += 1;
} else if (strcmp(argv[a], "--version") == 0) {
printf("MicroPython " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE
"; mpy-cross emitting mpy v" MP_STRINGIFY(MPY_VERSION) "\n");
printf("CircuitPython " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE
"; mpy-cross emitting mpy v" MP_STRINGIFY(MPY_VERSION) "-CircuitPython\n");
return 0;
} else if (strcmp(argv[a], "-v") == 0) {
mp_verbose_flag++;
Expand Down
4 changes: 2 additions & 2 deletions py/persistentcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader, qstr_window_t *qw) {
mp_raw_code_t *mp_raw_code_load(mp_reader_t *reader) {
byte header[4];
read_bytes(reader, header, sizeof(header));
if (header[0] != 'M'
if (header[0] != 'C'
|| header[1] != MPY_VERSION
|| MPY_FEATURE_DECODE_FLAGS(header[2]) != MPY_FEATURE_FLAGS
|| header[3] > mp_small_int_bits()
Expand Down Expand Up @@ -819,7 +819,7 @@ void mp_raw_code_save(mp_raw_code_t *rc, mp_print_t *print) {
// byte number of bits in a small int
// uint size of qstr window
byte header[4] = {
'M',
'C',
MPY_VERSION,
MPY_FEATURE_ENCODE_FLAGS(MPY_FEATURE_FLAGS_DYNAMIC),
#if MICROPY_DYNAMIC_COMPILER
Expand Down
8 changes: 4 additions & 4 deletions tests/import/mpy_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ def open(self, path, mode):
# these are the test .mpy files
user_files = {
# bad architecture
"/mod0.mpy": b"M\x05\xff\x00\x10",
"/mod0.mpy": b"C\x05\xff\x00\x10",
# test loading of viper and asm
"/mod1.mpy": (
b"M\x05\x0b\x1f\x20" # header
b"C\x05\x0b\x1f\x20" # header
b"\x20" # n bytes, bytecode
b"\x00\x08\x02m\x02m" # prelude
b"\x51" # LOAD_CONST_NONE
Expand All @@ -78,7 +78,7 @@ def open(self, path, mode):
),
# test loading viper with truncated data
"/mod2.mpy": (
b"M\x05\x0b\x1f\x20" # header
b"C\x05\x0b\x1f\x20" # header
b"\x20" # n bytes, bytecode
b"\x00\x08\x02m\x02m" # prelude
b"\x51" # LOAD_CONST_NONE
Expand All @@ -88,7 +88,7 @@ def open(self, path, mode):
),
# test loading viper with additional scope flags and relocation
"/mod3.mpy": (
b"M\x05\x0b\x1f\x20" # header
b"C\x05\x0b\x1f\x20" # header
b"\x20" # n bytes, bytecode
b"\x00\x08\x02m\x02m" # prelude
b"\x51" # LOAD_CONST_NONE
Expand Down
4 changes: 2 additions & 2 deletions tools/mpy-tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,8 +767,8 @@ def read_raw_code(f, qstr_win):
def read_mpy(filename):
with open(filename, "rb") as f:
header = bytes_cons(f.read(4))
if header[0] != ord("M"):
raise Exception("not a valid .mpy file")
if header[0] != ord("C"):
raise Exception("not a valid CircuitPython .mpy file")
if header[1] != config.MPY_VERSION:
raise Exception("incompatible .mpy version")
feature_byte = header[2]
Expand Down
2 changes: 1 addition & 1 deletion tools/mpy_ld.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ def build_mpy(env, entry_offset, fmpy, native_qstr_vals, native_qstr_objs):
out.write_bytes(
bytearray(
[
ord("M"),
ord("C"),
MPY_VERSION,
env.arch.mpy_feature,
MP_SMALL_INT_BITS,
Expand Down