diff options
author | Damien George <damien@micropython.org> | 2024-02-16 16:55:39 +1100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2024-02-20 10:56:24 +1100 |
commit | 0c7ccb8807581f3654f70ee9ea86d3ca017f7ea2 (patch) | |
tree | 4d03320a76e91b7d9bae0757fa6a72bca5bd44ad /py/objfun.c | |
parent | 6d403eb6972b7f6137838d89dba1ae3f76846c8b (diff) |
py/objfun: Support __name__ on native functions and generators.
This is now easy to support, since the first machine-word of a native
function tells how to find the prelude, from which the function name can be
extracted in the same way as for bytecode.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'py/objfun.c')
-rw-r--r-- | py/objfun.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/py/objfun.c b/py/objfun.c index 31f4a1f83..992c8c784 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -139,14 +139,14 @@ STATIC qstr mp_obj_code_get_name(const mp_obj_fun_bc_t *fun, const byte *code_in qstr mp_obj_fun_get_name(mp_const_obj_t fun_in) { const mp_obj_fun_bc_t *fun = MP_OBJ_TO_PTR(fun_in); + const byte *bc = fun->bytecode; + #if MICROPY_EMIT_NATIVE if (fun->base.type == &mp_type_fun_native || fun->base.type == &mp_type_native_gen_wrap) { - // TODO native functions don't have name stored - return MP_QSTR_; + bc = mp_obj_fun_native_get_prelude_ptr(fun); } #endif - const byte *bc = fun->bytecode; MP_BC_PRELUDE_SIG_DECODE(bc); return mp_obj_code_get_name(fun, bc); } |