From bf3d84195fc74d2834bd87f31d3681ce2a50edf6 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 29 Sep 2023 14:51:13 -0700 Subject: [PATCH] Fix decompressing using qstrs after running the VM The qstr state still pointed to qstr pools in the released MP heap. --- main.c | 4 ++++ py/qstr.c | 6 +++++- py/qstr.h | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 2607217e1b..3d4d665beb 100644 --- a/main.c +++ b/main.c @@ -219,6 +219,10 @@ STATIC void stop_mp(void) { usb_background(); #endif + // Set the qstr pool back to the const pools. The heap allocated ones will + // be overwritten. + qstr_reset(); + gc_deinit(); } diff --git a/py/qstr.c b/py/qstr.c index 5ff8b3bd54..6b7aead5c8 100644 --- a/py/qstr.c +++ b/py/qstr.c @@ -122,9 +122,13 @@ extern const qstr_pool_t MICROPY_QSTR_EXTRA_POOL; #define CONST_POOL mp_qstr_const_pool #endif -void qstr_init(void) { +void qstr_reset(void) { MP_STATE_VM(last_pool) = (qstr_pool_t *)&CONST_POOL; // we won't modify the const_pool since it has no allocated room left MP_STATE_VM(qstr_last_chunk) = NULL; +} + +void qstr_init(void) { + qstr_reset(); #if MICROPY_PY_THREAD && !MICROPY_PY_THREAD_GIL mp_thread_mutex_init(&MP_STATE_VM(qstr_mutex)); diff --git a/py/qstr.h b/py/qstr.h index c6c9768d05..24e0e756a3 100644 --- a/py/qstr.h +++ b/py/qstr.h @@ -78,6 +78,7 @@ typedef struct _qstr_pool_t { #define QSTR_TOTAL() (MP_STATE_VM(last_pool)->total_prev_len + MP_STATE_VM(last_pool)->len) +void qstr_reset(void); void qstr_init(void); mp_uint_t qstr_compute_hash(const byte *data, size_t len);