Skip to content

Commit

Permalink
py/objmodule: Add builtin deinit functionality.
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Leech <[email protected]>
  • Loading branch information
pi-anl committed Oct 23, 2024
1 parent 838f212 commit f66ea31
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions py/objmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,21 @@ static const mp_module_delegation_entry_t mp_builtin_module_delegation_table[] =
};
#endif

#if MICROPY_MODULE_BUILTIN_INIT
void mp_module_builtin_deinit() {
// Iterate through builtin modules. Run the __del__ function if defined.
for (size_t i = 0; i < mp_builtin_module_map.alloc; i++) {
if (mp_builtin_module_map.table[i].key != MP_OBJ_NULL) {
mp_obj_t dest[2];
mp_load_method_maybe(mp_builtin_module_map.table[i].value, MP_QSTR___del__, dest);
if (dest[0] != MP_OBJ_NULL) {
mp_call_method_n_kw(0, 0, dest);
}
}
}
}
#endif

// Attempts to find (and initialise) a built-in, otherwise returns
// MP_OBJ_NULL.
mp_obj_t mp_module_get_builtin(qstr module_name, bool extensible) {
Expand Down
1 change: 1 addition & 0 deletions py/objmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
extern const mp_map_t mp_builtin_module_map;
extern const mp_map_t mp_builtin_extensible_module_map;

void mp_module_builtin_deinit();
mp_obj_t mp_module_get_builtin(qstr module_name, bool extensible);

void mp_module_generic_attr(qstr attr, mp_obj_t *dest, const uint16_t *keys, mp_obj_t *values);
Expand Down

0 comments on commit f66ea31

Please sign in to comment.