From 13c817e61cf2f00fc398e01840e5d8c20e575c8c Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Mon, 5 Jun 2023 15:52:57 +1000 Subject: 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 --- py/builtin.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'py/builtin.h') diff --git a/py/builtin.h b/py/builtin.h index 81d0789802..57f275fb31 100644 --- a/py/builtin.h +++ b/py/builtin.h @@ -132,6 +132,8 @@ extern const mp_obj_module_t mp_module___main__; extern const mp_obj_module_t mp_module_builtins; extern const mp_obj_module_t mp_module_sys; +void mp_module_sys_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest); + // Modules needed by the parser when MICROPY_COMP_MODULE_CONST is enabled. extern const mp_obj_module_t mp_module_errno; extern const mp_obj_module_t mp_module_uctypes; -- cgit v1.2.3