From c4d589e2bb228e2b4a0942f3bd76479ec18acf84 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Fri, 28 Mar 2014 02:37:28 +0200 Subject: objgenerator: close(): Throw instance of GeneratorExit (not type). To comply with Python semantics and allow use of mp_obj_is_subclass_fast() for exception matching. --- py/objexcept.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'py/objexcept.c') diff --git a/py/objexcept.c b/py/objexcept.c index 71874751b..d4c4b1249 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -21,6 +21,12 @@ typedef struct mp_obj_exception_t { mp_obj_tuple_t args; } mp_obj_exception_t; +// Instance of GeneratorExit exception - needed by generator.close() +// This would belong to objgenerator.c, but to keep mp_obj_exception_t +// definition module-private so far, have it here. +STATIC mp_obj_exception_t GeneratorExit_obj = {{&mp_type_GeneratorExit}, MP_OBJ_NULL, NULL, {{&tuple_type}, 0}}; +const mp_obj_t mp_const_GeneratorExit = (mp_obj_t)&GeneratorExit_obj; + STATIC void mp_obj_exception_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) { mp_obj_exception_t *o = o_in; if (o->msg != NULL) { -- cgit v1.2.3