From 6b5c7b6ce61fc16f62bc539414e21842d0ab02dd Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Fri, 22 Sep 2023 10:45:49 -0500 Subject: [PATCH] fix const vs static generatorexit again --- py/obj.h | 2 ++ py/objexcept.c | 2 +- py/objgenerator.c | 4 ++-- py/vm.c | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/py/obj.h b/py/obj.h index 030641f066..000903c105 100644 --- a/py/obj.h +++ b/py/obj.h @@ -926,7 +926,9 @@ extern const struct _mp_obj_dict_t mp_const_empty_dict_obj; extern const struct _mp_obj_singleton_t mp_const_ellipsis_obj; extern const struct _mp_obj_traceback_t mp_const_empty_traceback_obj; extern const struct _mp_obj_singleton_t mp_const_notimplemented_obj; +#if MICROPY_CONST_GENERATOREXIT_OBJ extern const struct _mp_obj_exception_t mp_const_GeneratorExit_obj; +#endif // Fixed empty map. Useful when calling keyword-receiving functions // without any keywords from C, etc. diff --git a/py/objexcept.c b/py/objexcept.c index 1d7b57ee88..cceaa13e2f 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -285,7 +285,7 @@ void mp_obj_exception_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { if (dest[0] != MP_OBJ_NULL) { // store/delete attribute #if MICROPY_CONST_GENERATOREXIT_OBJ - if (self == &mp_static_GeneratorExit_obj) { + if (self == &mp_const_GeneratorExit_obj) { mp_raise_AttributeError(MP_ERROR_TEXT("can't set attribute")); } #endif diff --git a/py/objgenerator.c b/py/objgenerator.c index 328a7ef447..25cc8be569 100644 --- a/py/objgenerator.c +++ b/py/objgenerator.c @@ -39,7 +39,7 @@ // CIRCUITPY: https://github.com/adafruit/circuitpython/pull/7069 fix #if MICROPY_CONST_GENERATOREXIT_OBJ const -mp_obj_exception_t mp_static_GeneratorExit_obj = {{&mp_type_GeneratorExit}, (mp_obj_tuple_t *)&mp_const_empty_tuple_obj, (mp_obj_traceback_t *)&mp_const_empty_traceback_obj}; +mp_obj_exception_t mp_const_GeneratorExit_obj = {{&mp_type_GeneratorExit}, (mp_obj_tuple_t *)&mp_const_empty_tuple_obj, (mp_obj_traceback_t *)&mp_const_empty_traceback_obj}; #else static mp_obj_exception_t mp_static_GeneratorExit_obj; @@ -397,7 +397,7 @@ static mp_obj_t generatorexit(void) { MP_STATIC_ASSERT(!MICROPY_CONST_GENERATOREXIT_OBJ); mp_obj_exception_initialize0(&mp_static_GeneratorExit_obj, &mp_type_GeneratorExit); #endif - return MP_OBJ_FROM_PTR(&mp_static_GeneratorExit_obj); + return MP_OBJ_FROM_PTR(&mp_const_GeneratorExit_obj); } STATIC mp_obj_t gen_instance_close(mp_obj_t self_in) { diff --git a/py/vm.c b/py/vm.c index e09bc00421..42134f5a4a 100644 --- a/py/vm.c +++ b/py/vm.c @@ -1441,7 +1441,7 @@ unwind_loop: if ( true // CIRCUITPY #if MICROPY_CONST_GENERATOREXIT_OBJ - && nlr.ret_val != &mp_static_GeneratorExit_obj + && nlr.ret_val != &mp_const_GeneratorExit_obj #endif && *code_state->ip != MP_BC_END_FINALLY && *code_state->ip != MP_BC_RAISE_LAST) {