Skip to content

Commit c3103b5

Browse files
committed
objgenerator: .print(): Output real underlying function name.
1 parent 1f85d62 commit c3103b5

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

py/obj.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ typedef struct _mp_obj_fun_native_t { // need this so we can define const object
508508

509509
bool mp_obj_fun_prepare_simple_args(mp_obj_t self_in, uint n_args, uint n_kw, const mp_obj_t *args,
510510
uint *out_args1_len, const mp_obj_t **out_args1, uint *out_args2_len, const mp_obj_t **out_args2);
511+
const char *mp_obj_code_get_name(const byte *code_info);
511512

512513
mp_obj_t mp_identity(mp_obj_t self);
513514
MP_DECLARE_CONST_FUN_OBJ(mp_identity_obj);

py/objfun.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,16 @@ mp_obj_t mp_make_function_var_between(int n_args_min, int n_args_max, mp_fun_var
126126
/******************************************************************************/
127127
/* byte code functions */
128128

129-
const char *mp_obj_fun_get_name(mp_obj_fun_bc_t *o) {
130-
const byte *code_info = o->bytecode;
129+
const char *mp_obj_code_get_name(const byte *code_info) {
131130
qstr block_name = code_info[8] | (code_info[9] << 8) | (code_info[10] << 16) | (code_info[11] << 24);
132131
return qstr_str(block_name);
133132
}
134133

134+
const char *mp_obj_fun_get_name(mp_obj_fun_bc_t *o) {
135+
const byte *code_info = o->bytecode;
136+
return mp_obj_code_get_name(code_info);
137+
}
138+
135139
#if MICROPY_CPYTHON_COMPAT
136140
STATIC void fun_bc_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) {
137141
mp_obj_fun_bc_t *o = o_in;

py/objgenerator.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ typedef struct _mp_obj_gen_instance_t {
6868
} mp_obj_gen_instance_t;
6969

7070
void gen_instance_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
71-
print(env, "<generator object 'fun-name' at %p>", self_in);
71+
mp_obj_gen_instance_t *self = self_in;
72+
print(env, "<generator object '%s' at %p>", mp_obj_code_get_name(self->code_info), self_in);
7273
}
7374

7475
mp_obj_t gen_instance_getiter(mp_obj_t self_in) {

0 commit comments

Comments
 (0)