From: Stefan Behnel Date: Mon, 12 Oct 2009 11:48:15 +0000 (+0200) Subject: small refactoring and cleanup in try-except code generation X-Git-Tag: 0.13.beta0~2^2~121^2~70 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=08fb6d105797c93614c40b2e8a882fbeb503174c;p=cython.git small refactoring and cleanup in try-except code generation --- diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 7a6e1a2e..25912168 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -3479,15 +3479,11 @@ class RaiseStatNode(StatNode): tb_code = self.exc_tb.py_result() else: tb_code = "0" - if self.exc_type or self.exc_value or self.exc_tb: - code.putln( - "__Pyx_Raise(%s, %s, %s);" % ( - type_code, - value_code, - tb_code)) - else: - code.putln( - "__Pyx_ReRaise();") + code.putln( + "__Pyx_Raise(%s, %s, %s);" % ( + type_code, + value_code, + tb_code)) for obj in (self.exc_type, self.exc_value, self.exc_tb): if obj: obj.generate_disposal_code(code) @@ -4144,27 +4140,17 @@ class TryExceptStatNode(StatNode): for var in Naming.exc_save_vars: code.put_xdecref(var, py_object_type) code.put_goto(old_error_label) - - if code.label_used(try_break_label): - code.put_label(try_break_label) - for var in Naming.exc_save_vars: code.put_xgiveref(var) - code.putln("__Pyx_ExceptionReset(%s);" % - ', '.join(Naming.exc_save_vars)) - code.put_goto(old_break_label) - - if code.label_used(try_continue_label): - code.put_label(try_continue_label) - for var in Naming.exc_save_vars: code.put_xgiveref(var) - code.putln("__Pyx_ExceptionReset(%s);" % - ', '.join(Naming.exc_save_vars)) - code.put_goto(old_continue_label) - if code.label_used(except_return_label): - code.put_label(except_return_label) - for var in Naming.exc_save_vars: code.put_xgiveref(var) - code.putln("__Pyx_ExceptionReset(%s);" % - ', '.join(Naming.exc_save_vars)) - code.put_goto(old_return_label) + for exit_label, old_label in zip( + [try_break_label, try_continue_label, except_return_label], + [old_break_label, old_continue_label, old_return_label]): + + if code.label_used(exit_label): + code.put_label(exit_label) + for var in Naming.exc_save_vars: code.put_xgiveref(var) + code.putln("__Pyx_ExceptionReset(%s);" % + ', '.join(Naming.exc_save_vars)) + code.put_goto(old_label) if code.label_used(except_end_label): code.put_label(except_end_label) @@ -5006,30 +4992,6 @@ raise_error: #------------------------------------------------------------------------------------ -reraise_utility_code = UtilityCode( -proto = """ -static void __Pyx_ReRaise(void); /*proto*/ -""", -impl = """ -static void __Pyx_ReRaise(void) { - PyThreadState *tstate = PyThreadState_GET(); - PyObject* tmp_type = tstate->curexc_type; - PyObject* tmp_value = tstate->curexc_value; - PyObject* tmp_tb = tstate->curexc_traceback; - tstate->curexc_type = tstate->exc_type; - tstate->curexc_value = tstate->exc_value; - tstate->curexc_traceback = tstate->exc_traceback; - tstate->exc_type = 0; - tstate->exc_value = 0; - tstate->exc_traceback = 0; - Py_XDECREF(tmp_type); - Py_XDECREF(tmp_value); - Py_XDECREF(tmp_tb); -} -""") - -#------------------------------------------------------------------------------------ - arg_type_test_utility_code = UtilityCode( proto = """ static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,