From d4a65521910d0645116331d56d4e9bae909a3f5f Mon Sep 17 00:00:00 2001 From: Andrew Leech Date: Wed, 23 Oct 2024 18:36:12 +1100 Subject: [PATCH] gen_mpy: Add checks in mp_lv_deinit_gc(). --- gen/gen_mpy.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/gen/gen_mpy.py b/gen/gen_mpy.py index 72d68230f..4a707bfe0 100644 --- a/gen/gen_mpy.py +++ b/gen/gen_mpy.py @@ -1128,16 +1128,21 @@ def register_int_ptr_type(convertor, *types): void mp_lv_deinit_gc() { - - // mp_printf(&mp_plat_print, "[ DEINIT GC ]"); - mp_lv_roots = MP_STATE_VM(mp_lv_roots) = NULL; - mp_lv_user_data = MP_STATE_VM(mp_lv_user_data) = NULL; - mp_lv_roots_initialized = MP_STATE_VM(mp_lv_roots_initialized) = 0; - lvgl_mod_initialized = MP_STATE_VM(lvgl_mod_initialized) = 0; - + if (MP_STATE_VM(mp_lv_roots_initialized)) { + // mp_printf(&mp_plat_print, "[ DEINIT GC ]"); + mp_lv_roots = MP_STATE_VM(mp_lv_roots) = NULL; + mp_lv_user_data = MP_STATE_VM(mp_lv_user_data) = NULL; + mp_lv_roots_initialized = MP_STATE_VM(mp_lv_roots_initialized) = 0; + lvgl_mod_initialized = MP_STATE_VM(lvgl_mod_initialized) = 0; + } } -static mp_obj_t lvgl_mod___init__(void) { +#if !MICROPY_MODULE_BUILTIN_INIT +#error MICROPY_MODULE_BUILTIN_INIT required to be set in build. +#endif + +static mp_obj_t lvgl_mod___init__(void) +{ if (!MP_STATE_VM(lvgl_mod_initialized)) { // __init__ for builtins is called each time the module is imported, // so ensure that initialisation only happens once. @@ -1154,8 +1159,8 @@ def register_int_ptr_type(convertor, *types): } static MP_DEFINE_CONST_FUN_OBJ_0(lvgl_mod___init___obj, lvgl_mod___init__); - -static mp_obj_t lvgl_mod___del__(void) { +static mp_obj_t lvgl_mod___del__(void) +{ if (MP_STATE_VM(lvgl_mod_initialized)) { #ifdef LV_PORT_INDEV_DEINIT LV_PORT_INDEV_DEINIT();