diff --git a/py/emitnative.c b/py/emitnative.c index 072163618502359992db0d200e5617250b18db31..ad89fb845f34f6f398650e7bf56a88bd450cbc52 100644 --- a/py/emitnative.c +++ b/py/emitnative.c @@ -1824,7 +1824,14 @@ STATIC void emit_native_setup_finally(emit_t *emit, mp_uint_t label) { } STATIC void emit_native_end_finally(emit_t *emit) { - emit_pre_pop_discard(emit); + // logic: + // exc = pop_stack + // if exc == None: pass + // else: raise exc + // the check if exc is None is done in the MP_F_NATIVE_RAISE stub + vtype_kind_t vtype; + emit_pre_pop_reg(emit, &vtype, REG_ARG_1); + emit_call(emit, MP_F_NATIVE_RAISE); emit_post(emit); } diff --git a/py/nativeglue.c b/py/nativeglue.c index d52eeaeaa5f260e2a77cbc04e7956e560d088e8f..43e7d699ff517b8e9a2c2edd2663226c18de1c65 100644 --- a/py/nativeglue.c +++ b/py/nativeglue.c @@ -80,8 +80,11 @@ mp_obj_t mp_native_call_function_n_kw(mp_obj_t fun_in, mp_uint_t n_args_kw, cons } // wrapper that makes raise obj and raises it -NORETURN void mp_native_raise(mp_obj_t o) { - nlr_raise(mp_make_raise_obj(o)); +// END_FINALLY opcode requires that we don't raise if o==None +void mp_native_raise(mp_obj_t o) { + if (o != mp_const_none) { + nlr_raise(mp_make_raise_obj(o)); + } } // these must correspond to the respective enum in runtime0.h diff --git a/py/runtime.h b/py/runtime.h index ce87bf07bc7090afe5109fdb35569b32eda2511c..1216462b2547bbcbb468757fbb0f744ec391b19f 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -119,7 +119,7 @@ NORETURN void mp_not_implemented(const char *msg); mp_uint_t mp_convert_obj_to_native(mp_obj_t obj, mp_uint_t type); mp_obj_t mp_convert_native_to_obj(mp_uint_t val, mp_uint_t type); mp_obj_t mp_native_call_function_n_kw(mp_obj_t fun_in, mp_uint_t n_args_kw, const mp_obj_t *args); -NORETURN void mp_native_raise(mp_obj_t o); +void mp_native_raise(mp_obj_t o); extern struct _mp_obj_list_t mp_sys_path_obj; extern struct _mp_obj_list_t mp_sys_argv_obj; diff --git a/tests/run-tests b/tests/run-tests index a88ad4c2b19aa78526d9db8420bc1e66af1c05fd..722f154896e87a21da5560125dc865ab527a42a9 100755 --- a/tests/run-tests +++ b/tests/run-tests @@ -78,7 +78,7 @@ def run_tests(pyb, tests, args): # Some tests are known to fail with native emitter # Remove them from the below when they work if args.emit == 'native': - skip_tests.update({'basics/%s.py' % t for t in 'bytes_gen class_store_class class_super class_super_object closure1 closure2 closure_defargs del_deref del_local fun3 fun_calldblstar fun_callstar fun_callstardblstar fun_defargs fun_defargs2 fun_kwargs fun_kwonly fun_kwonlydef fun_kwvarargs fun_varargs gen_yield_from gen_yield_from_close gen_yield_from_ducktype gen_yield_from_exc gen_yield_from_iter gen_yield_from_send gen_yield_from_throw generator1 generator2 generator_args generator_close generator_closure generator_exc generator_return generator_send globals_del string_format string_join subclass_native2_list subclass_native2_tuple try2 try_finally1 try_finally_loops try_finally_return try_reraise try_reraise2 unboundlocal with1 with_break with_continue with_return'.split()}) + skip_tests.update({'basics/%s.py' % t for t in 'bytes_gen class_store_class class_super class_super_object closure1 closure2 closure_defargs del_deref del_local fun3 fun_calldblstar fun_callstar fun_callstardblstar fun_defargs fun_defargs2 fun_kwargs fun_kwonly fun_kwonlydef fun_kwvarargs fun_varargs gen_yield_from gen_yield_from_close gen_yield_from_ducktype gen_yield_from_exc gen_yield_from_iter gen_yield_from_send gen_yield_from_throw generator1 generator2 generator_args generator_close generator_closure generator_exc generator_return generator_send globals_del string_format string_join subclass_native2_list subclass_native2_tuple try_finally_loops try_finally_return try_reraise try_reraise2 unboundlocal with1 with_break with_continue with_return'.split()}) skip_tests.add('float/string_format.py') skip_tests.add('import/gen_context.py') skip_tests.add('io/file_with.py')