objclosure: Fix printing of generator closures.
The code previously assumed that only functions can be closed over.
This commit is contained in:
parent
9b0b373e5e
commit
067ae1269d
|
@ -67,7 +67,9 @@ mp_obj_t closure_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const
|
||||||
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED
|
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED
|
||||||
STATIC void closure_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) {
|
STATIC void closure_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) {
|
||||||
mp_obj_closure_t *o = o_in;
|
mp_obj_closure_t *o = o_in;
|
||||||
print(env, "<closure %s at %p, n_closed=%u ", mp_obj_fun_get_name(o->fun), o, o->n_closed);
|
print(env, "<closure ");
|
||||||
|
mp_obj_print_helper(print, env, o->fun, PRINT_REPR);
|
||||||
|
print(env, " at %p, n_closed=%u ", o, o->n_closed);
|
||||||
for (mp_uint_t i = 0; i < o->n_closed; i++) {
|
for (mp_uint_t i = 0; i < o->n_closed; i++) {
|
||||||
if (o->closed[i] == MP_OBJ_NULL) {
|
if (o->closed[i] == MP_OBJ_NULL) {
|
||||||
print(env, "(nil)");
|
print(env, "(nil)");
|
||||||
|
|
|
@ -24,3 +24,9 @@ generator_of_generators = (((x, y) for x in range(2)) for y in range(3))
|
||||||
for i in generator_of_generators:
|
for i in generator_of_generators:
|
||||||
for j in i:
|
for j in i:
|
||||||
print(j)
|
print(j)
|
||||||
|
|
||||||
|
# test that printing of closed-over generators doesn't lead to segfaults
|
||||||
|
def genc():
|
||||||
|
foo = 1
|
||||||
|
repr(lambda: (yield foo))
|
||||||
|
genc()
|
||||||
|
|
Loading…
Reference in New Issue