py/persistentcode: Only emit sub-version if generated code has native.

In order for v1.19.1 to load a .mpy, the formerly-feature-flags which are
now used for the sub-version must be zero.

The sub-version is only used to indicate a native version change, so it
should be zero when emitting bytecode-only .mpy files.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
pull/9738/head
Jim Mussared 2022-10-20 13:14:25 +11:00 zatwierdzone przez Damien George
rodzic 5ee1cb2771
commit 1ba0e8ff96
2 zmienionych plików z 3 dodań i 6 usunięć

Wyświetl plik

@ -591,21 +591,18 @@ void mp_raw_code_save(mp_compiled_module_t *cm, mp_print_t *print) {
// header contains: // header contains:
// byte 'M' // byte 'M'
// byte version // byte version
// byte feature flags // byte native arch (and sub-version if native)
// byte number of bits in a small int // byte number of bits in a small int
byte header[4] = { byte header[4] = {
'M', 'M',
MPY_VERSION, MPY_VERSION,
MPY_FEATURE_ENCODE_SUB_VERSION(MPY_SUB_VERSION), cm->has_native ? MPY_FEATURE_ENCODE_SUB_VERSION(MPY_SUB_VERSION) | MPY_FEATURE_ENCODE_ARCH(MPY_FEATURE_ARCH_DYNAMIC) : 0,
#if MICROPY_DYNAMIC_COMPILER #if MICROPY_DYNAMIC_COMPILER
mp_dynamic_compiler.small_int_bits, mp_dynamic_compiler.small_int_bits,
#else #else
MP_SMALL_INT_BITS, MP_SMALL_INT_BITS,
#endif #endif
}; };
if (cm->has_native) {
header[2] |= MPY_FEATURE_ENCODE_ARCH(MPY_FEATURE_ARCH_DYNAMIC);
}
mp_print_bytes(print, header, sizeof(header)); mp_print_bytes(print, header, sizeof(header));
// Number of entries in constant table. // Number of entries in constant table.

Wyświetl plik

@ -1676,7 +1676,7 @@ def merge_mpy(compiled_modules, output_file):
header = bytearray(4) header = bytearray(4)
header[0] = ord("M") header[0] = ord("M")
header[1] = config.MPY_VERSION header[1] = config.MPY_VERSION
header[2] = config.native_arch << 2 | config.MPY_SUB_VERSION header[2] = config.native_arch << 2 | config.MPY_SUB_VERSION if config.native_arch else 0
header[3] = config.mp_small_int_bits header[3] = config.mp_small_int_bits
merged_mpy.extend(header) merged_mpy.extend(header)