mirror of
https://github.com/micropython/micropython.git
synced 2025-12-16 09:50:15 +01:00
py/objmodule: Add a table of built-in modules with delegation.
This replaces the previous QSTR_null entry in the globals dict which could leak out to Python (e.g. via iteration of mod.__dict__) and could lead to crashes. It results in smaller code size at the expense of turning a lookup into a loop, but the list it is looping over likely only contains one or two elements. To allow a module to register its custom attr function it can use the new `MP_REGISTER_MODULE_DELEGATION` macro. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
4
py/obj.h
4
py/obj.h
@@ -437,6 +437,10 @@ typedef struct _mp_rom_obj_t { mp_const_obj_t o; } mp_rom_obj_t;
|
||||
// As above, but allow this module to be extended from the filesystem.
|
||||
#define MP_REGISTER_EXTENSIBLE_MODULE(module_name, obj_module)
|
||||
|
||||
// Add a custom handler for a builtin module that will be called to delegate
|
||||
// failed attribute lookups.
|
||||
#define MP_REGISTER_MODULE_DELEGATION(obj_module, fun_name)
|
||||
|
||||
// Declare a root pointer (to avoid garbage collection of a global static variable).
|
||||
// param variable_declaration: a valid C variable declaration
|
||||
#define MP_REGISTER_ROOT_POINTER(variable_declaration)
|
||||
|
||||
Reference in New Issue
Block a user