|
38 | 38 |
|
39 | 39 | #include "py/smallint.h" |
40 | 40 |
|
| 41 | +// The current version of .mpy files |
| 42 | +#define MPY_VERSION (1) |
| 43 | + |
41 | 44 | // The feature flags byte encodes the compile-time config options that |
42 | 45 | // affect the generate bytecode. |
43 | 46 | #define MPY_FEATURE_FLAGS ( \ |
@@ -209,10 +212,10 @@ STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader) { |
209 | 212 | mp_raw_code_t *mp_raw_code_load(mp_reader_t *reader) { |
210 | 213 | byte header[4]; |
211 | 214 | read_bytes(reader, header, sizeof(header)); |
212 | | - if (strncmp((char*)header, "M\x00", 2) != 0) { |
213 | | - mp_raise_ValueError("invalid .mpy file"); |
214 | | - } |
215 | | - if (header[2] != MPY_FEATURE_FLAGS || header[3] > mp_small_int_bits()) { |
| 215 | + if (header[0] != 'M' |
| 216 | + || header[1] != MPY_VERSION |
| 217 | + || header[2] != MPY_FEATURE_FLAGS |
| 218 | + || header[3] > mp_small_int_bits()) { |
216 | 219 | mp_raise_ValueError("incompatible .mpy file"); |
217 | 220 | } |
218 | 221 | mp_raw_code_t *rc = load_raw_code(reader); |
@@ -359,7 +362,7 @@ void mp_raw_code_save(mp_raw_code_t *rc, mp_print_t *print) { |
359 | 362 | // byte version |
360 | 363 | // byte feature flags |
361 | 364 | // byte number of bits in a small int |
362 | | - byte header[4] = {'M', 0, MPY_FEATURE_FLAGS_DYNAMIC, |
| 365 | + byte header[4] = {'M', MPY_VERSION, MPY_FEATURE_FLAGS_DYNAMIC, |
363 | 366 | #if MICROPY_DYNAMIC_COMPILER |
364 | 367 | mp_dynamic_compiler.small_int_bits, |
365 | 368 | #else |
|
0 commit comments