Commit 067ae126 authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

objclosure: Fix printing of generator closures.

The code previously assumed that only functions can be closed over.
parent 9b0b373e
......@@ -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
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;
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++) {
if (o->closed[i] == MP_OBJ_NULL) {
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 j in i:
print(j)
# test that printing of closed-over generators doesn't lead to segfaults
def genc():
foo = 1
repr(lambda: (yield foo))
genc()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment