Skip to content

Commit 85b4f36

Browse files
dlechdpgeorge
authored andcommitted
py/modsys: Use MP_REGISTER_ROOT_POINTER().
This uses MP_REGISTER_ROOT_POINTER() to register cur_exception, sys_exitfunc, mp_sys_path_obj, mp_sys_argv_obj and sys_mutable instead of using a conditional inside of mp_state_vm_t. Signed-off-by: David Lechner <david@pybricks.com>
1 parent a98aa66 commit 85b4f36

2 files changed

Lines changed: 20 additions & 22 deletions

File tree

py/modsys.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,24 @@ const mp_obj_module_t mp_module_sys = {
286286

287287
MP_REGISTER_MODULE(MP_QSTR_usys, mp_module_sys);
288288

289+
// If MICROPY_PY_SYS_PATH_ARGV_DEFAULTS is not enabled then these two lists
290+
// must be initialised after the call to mp_init.
291+
MP_REGISTER_ROOT_POINTER(mp_obj_list_t mp_sys_path_obj);
292+
MP_REGISTER_ROOT_POINTER(mp_obj_list_t mp_sys_argv_obj);
293+
294+
#if MICROPY_PY_SYS_EXC_INFO
295+
// current exception being handled, for sys.exc_info()
296+
MP_REGISTER_ROOT_POINTER(mp_obj_base_t * cur_exception);
297+
#endif
298+
299+
#if MICROPY_PY_SYS_ATEXIT
300+
// exposed through sys.atexit function
301+
MP_REGISTER_ROOT_POINTER(mp_obj_t sys_exitfunc);
289302
#endif
303+
304+
#if MICROPY_PY_SYS_ATTR_DELEGATION
305+
// Contains mutable sys attributes.
306+
MP_REGISTER_ROOT_POINTER(mp_obj_t sys_mutable[MP_SYS_MUTABLE_NUM]);
307+
#endif
308+
309+
#endif // MICROPY_PY_SYS

py/mpstate.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -154,31 +154,9 @@ typedef struct _mp_state_vm_t {
154154
mp_sched_item_t sched_queue[MICROPY_SCHEDULER_DEPTH];
155155
#endif
156156

157-
// current exception being handled, for sys.exc_info()
158-
#if MICROPY_PY_SYS_EXC_INFO
159-
mp_obj_base_t *cur_exception;
160-
#endif
161-
162-
#if MICROPY_PY_SYS_ATEXIT
163-
// exposed through sys.atexit function
164-
mp_obj_t sys_exitfunc;
165-
#endif
166-
167157
// dictionary for the __main__ module
168158
mp_obj_dict_t dict_main;
169159

170-
#if MICROPY_PY_SYS
171-
// If MICROPY_PY_SYS_PATH_ARGV_DEFAULTS is not enabled then these two lists
172-
// must be initialised after the call to mp_init.
173-
mp_obj_list_t mp_sys_path_obj;
174-
mp_obj_list_t mp_sys_argv_obj;
175-
176-
#if MICROPY_PY_SYS_ATTR_DELEGATION
177-
// Contains mutable sys attributes.
178-
mp_obj_t sys_mutable[MP_SYS_MUTABLE_NUM];
179-
#endif
180-
#endif
181-
182160
// dictionary for overridden builtins
183161
#if MICROPY_CAN_OVERRIDE_BUILTINS
184162
mp_obj_dict_t *mp_module_builtins_override_dict;

0 commit comments

Comments
 (0)