summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
Diffstat (limited to 'py')
-rw-r--r--py/persistentcode.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/py/persistentcode.c b/py/persistentcode.c
index 07395b304b..5cb5117093 100644
--- a/py/persistentcode.c
+++ b/py/persistentcode.c
@@ -38,6 +38,9 @@
#include "py/smallint.h"
+// The current version of .mpy files
+#define MPY_VERSION (1)
+
// The feature flags byte encodes the compile-time config options that
// affect the generate bytecode.
#define MPY_FEATURE_FLAGS ( \
@@ -209,10 +212,10 @@ STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader) {
mp_raw_code_t *mp_raw_code_load(mp_reader_t *reader) {
byte header[4];
read_bytes(reader, header, sizeof(header));
- if (strncmp((char*)header, "M\x00", 2) != 0) {
- mp_raise_ValueError("invalid .mpy file");
- }
- if (header[2] != MPY_FEATURE_FLAGS || header[3] > mp_small_int_bits()) {
+ if (header[0] != 'M'
+ || header[1] != MPY_VERSION
+ || header[2] != MPY_FEATURE_FLAGS
+ || header[3] > mp_small_int_bits()) {
mp_raise_ValueError("incompatible .mpy file");
}
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) {
// byte version
// byte feature flags
// byte number of bits in a small int
- byte header[4] = {'M', 0, MPY_FEATURE_FLAGS_DYNAMIC,
+ byte header[4] = {'M', MPY_VERSION, MPY_FEATURE_FLAGS_DYNAMIC,
#if MICROPY_DYNAMIC_COMPILER
mp_dynamic_compiler.small_int_bits,
#else