diff --git a/py/obj.h b/py/obj.h index 35c98d371..ea4534bb2 100644 --- a/py/obj.h +++ b/py/obj.h @@ -508,6 +508,7 @@ typedef struct _mp_obj_fun_native_t { // need this so we can define const object bool mp_obj_fun_prepare_simple_args(mp_obj_t self_in, uint n_args, uint n_kw, const mp_obj_t *args, uint *out_args1_len, const mp_obj_t **out_args1, uint *out_args2_len, const mp_obj_t **out_args2); +const char *mp_obj_code_get_name(const byte *code_info); mp_obj_t mp_identity(mp_obj_t self); MP_DECLARE_CONST_FUN_OBJ(mp_identity_obj); diff --git a/py/objfun.c b/py/objfun.c index 94f6d26d7..f4d9dfb95 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -126,12 +126,16 @@ mp_obj_t mp_make_function_var_between(int n_args_min, int n_args_max, mp_fun_var /******************************************************************************/ /* byte code functions */ -const char *mp_obj_fun_get_name(mp_obj_fun_bc_t *o) { - const byte *code_info = o->bytecode; +const char *mp_obj_code_get_name(const byte *code_info) { qstr block_name = code_info[8] | (code_info[9] << 8) | (code_info[10] << 16) | (code_info[11] << 24); return qstr_str(block_name); } +const char *mp_obj_fun_get_name(mp_obj_fun_bc_t *o) { + const byte *code_info = o->bytecode; + return mp_obj_code_get_name(code_info); +} + #if MICROPY_CPYTHON_COMPAT STATIC void fun_bc_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) { mp_obj_fun_bc_t *o = o_in; diff --git a/py/objgenerator.c b/py/objgenerator.c index 895c03cc2..d02f838af 100644 --- a/py/objgenerator.c +++ b/py/objgenerator.c @@ -68,7 +68,8 @@ typedef struct _mp_obj_gen_instance_t { } mp_obj_gen_instance_t; void gen_instance_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { - print(env, "", self_in); + mp_obj_gen_instance_t *self = self_in; + print(env, "", mp_obj_code_get_name(self->code_info), self_in); } mp_obj_t gen_instance_getiter(mp_obj_t self_in) {