8000 py/objfun: Support __name__ on native functions and generators. · micropython/micropython@0c7ccb8 · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 0c7ccb8

Browse files
committed
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>
1 parent 6d403eb commit 0c7ccb8

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

py/objfun.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,14 @@ STATIC qstr mp_obj_code_get_name(const mp_obj_fun_bc_t *fun, const byte *code_in
139139

140140
qstr mp_obj_fun_get_name(mp_const_obj_t fun_in) {
141141
const mp_obj_fun_bc_t *fun = MP_OBJ_TO_PTR(fun_in);
142+
const byte *bc = fun->bytecode;
143+
142144
#if MICROPY_EMIT_NATIVE
143145
if (fun->base.type == &mp_type_fun_native || fun->base.type == &mp_type_native_gen_wrap) {
144-
// TODO native functions don't have name stored
145-
return MP_QSTR_;
146+
bc = mp_obj_fun_native_get_prelude_ptr(fun);
146147
}
147148
#endif
148149

149-
const byte *bc = fun->bytecode;
150150
MP_BC_PRELUDE_SIG_DECODE(bc);
151151
return mp_obj_code_get_name(fun, bc);
152152
}

tests/run-tests.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -643,9 +643,7 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1):
643643
# Some tests are known to fail with native emitter
644644
# Remove them from the below when they work
645645
if args.emit == "native":
646-
skip_tests.update(
647-
{"basics/%s.py" % t for t in "gen_yield_from_close generator_name".split()}
648-
) # require raise_varargs, generator name
646+
skip_tests.add("basics/gen_yield_from_close.py") # require raise_varargs
649647
skip_tests.update(
650648
{"basics/async_%s.py" % t for t in "with with2 with_break with_return".split()}
651649
) # require async_with
@@ -656,7 +654,6 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1):
656654
skip_tests.add("basics/del_deref.py") # requires checking for unbound local
657655
skip_tests.add("basics/del_local.py") # requires checking for unbound local
658656
skip_tests.add("basics/exception_chain.py") # raise from is not supported
659-
skip_tests.add("basics/fun_name.py") # requires proper names for native functions
660657
skip_tests.add("basics/scope_implicit.py") # requires checking for unbound local
661658
skip_tests.add("basics/sys_tracebacklimit.py") # requires traceback info
662659
skip_tests.add("basics/try_finally_return2.py") # requires raise_varargs

0 commit comments

Comments
 (0)
0