@@ -103,12 +103,12 @@ const mp_obj_type_t mp_type_fun_builtin = {
103103/******************************************************************************/
104104/* byte code functions */
105105
106- const char * mp_obj_code_get_name (const byte * code_info ) {
106+ qstr mp_obj_code_get_name (const byte * code_info ) {
107107 mp_decode_uint (& code_info ); // skip code_info_size entry
108- return qstr_str ( mp_decode_uint (& code_info ) );
108+ return mp_decode_uint (& code_info );
109109}
110110
111- const char * mp_obj_fun_get_name (mp_const_obj_t fun_in ) {
111+ qstr mp_obj_fun_get_name (mp_const_obj_t fun_in ) {
112112 const mp_obj_fun_bc_t * fun = fun_in ;
113113 const byte * code_info = fun -> bytecode ;
114114 return mp_obj_code_get_name (code_info );
@@ -118,7 +118,7 @@ const char *mp_obj_fun_get_name(mp_const_obj_t fun_in) {
118118STATIC void fun_bc_print (void (* print )(void * env , const char * fmt , ...), void * env , mp_obj_t o_in , mp_print_kind_t kind ) {
119119 (void )kind ;
120120 mp_obj_fun_bc_t * o = o_in ;
121- print (env , "<function %s at 0x%x>" , mp_obj_fun_get_name (o ), o );
121+ print (env , "<function %s at 0x%x>" , qstr_str ( mp_obj_fun_get_name (o ) ), o );
122122}
123123#endif
124124
@@ -246,13 +246,24 @@ STATIC mp_obj_t fun_bc_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw,
246246 }
247247}
248248
249+ #if MICROPY_PY_FUNCTION_ATTRS
250+ STATIC void fun_bc_load_attr (mp_obj_t self_in , qstr attr , mp_obj_t * dest ) {
251+ if (attr == MP_QSTR___name__ ) {
252+ dest [0 ] = MP_OBJ_NEW_QSTR (mp_obj_fun_get_name (self_in ));
253+ }
254+ }
255+ #endif
256+
249257const mp_obj_type_t mp_type_fun_bc = {
250258 { & mp_type_type },
251259 .name = MP_QSTR_function ,
252260#if MICROPY_CPYTHON_COMPAT
253261 .print = fun_bc_print ,
254262#endif
255263 .call = fun_bc_call ,
264+ #if MICROPY_PY_FUNCTION_ATTRS
265+ .load_attr = fun_bc_load_attr ,
266+ #endif
256267};
257268
258269mp_obj_t mp_obj_new_fun_bc (mp_uint_t scope_flags , mp_uint_t n_pos_args , mp_uint_t n_kwonly_args , mp_obj_t def_args_in , mp_obj_t def_kw_args , const byte * code ) {
0 commit comments