From 403fe34aa5ca0a9e512755b7d403cd9965a8d830 Mon Sep 17 00:00:00 2001 From: Vitja Makarov Date: Fri, 10 Dec 2010 23:42:46 +0300 Subject: [PATCH] TryExceptStatNode: save previous exception state in temps --- Cython/Compiler/Naming.py | 4 ---- Cython/Compiler/Nodes.py | 29 ++++++++++++++++------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/Cython/Compiler/Naming.py b/Cython/Compiler/Naming.py index 052c1e34..20dbea3b 100644 --- a/Cython/Compiler/Naming.py +++ b/Cython/Compiler/Naming.py @@ -109,10 +109,6 @@ exc_lineno_name = pyrex_prefix + "exc_lineno" exc_vars = (exc_type_name, exc_value_name, exc_tb_name) -exc_save_vars = (pyrex_prefix + 'save_exc_type', - pyrex_prefix + 'save_exc_value', - pyrex_prefix + 'save_exc_tb') - api_name = pyrex_prefix + "capi__" h_guard_prefix = "__PYX_HAVE__" diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 364083f9..ef4a7829 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -4746,12 +4746,12 @@ class TryExceptStatNode(StatNode): try_continue_label = code.new_label('try_continue') try_end_label = code.new_label('try_end') + exc_save_vars = [code.funcstate.allocate_temp(py_object_type, False) + for i in xrange(3)] code.putln("{") - code.putln("PyObject %s;" % - ', '.join(['*%s' % var for var in Naming.exc_save_vars])) code.putln("__Pyx_ExceptionSave(%s);" % - ', '.join(['&%s' % var for var in Naming.exc_save_vars])) - for var in Naming.exc_save_vars: + ', '.join(['&%s' % var for var in exc_save_vars])) + for var in exc_save_vars: code.put_xgotref(var) code.putln( "/*try:*/ {") @@ -4770,14 +4770,14 @@ class TryExceptStatNode(StatNode): self.else_clause.generate_execution_code(code) code.putln( "}") - for var in Naming.exc_save_vars: + for var in exc_save_vars: code.put_xdecref_clear(var, py_object_type) code.put_goto(try_end_label) if code.label_used(try_return_label): code.put_label(try_return_label) - for var in Naming.exc_save_vars: code.put_xgiveref(var) + for var in exc_save_vars: code.put_xgiveref(var) code.putln("__Pyx_ExceptionReset(%s);" % - ', '.join(Naming.exc_save_vars)) + ', '.join(exc_save_vars)) code.put_goto(old_return_label) code.put_label(our_error_label) for temp_name, type in temps_to_clean_up: @@ -4789,9 +4789,9 @@ class TryExceptStatNode(StatNode): if error_label_used or not self.has_default_clause: if error_label_used: code.put_label(except_error_label) - for var in Naming.exc_save_vars: code.put_xgiveref(var) + for var in exc_save_vars: code.put_xgiveref(var) code.putln("__Pyx_ExceptionReset(%s);" % - ', '.join(Naming.exc_save_vars)) + ', '.join(exc_save_vars)) code.put_goto(old_error_label) for exit_label, old_label in zip( @@ -4800,19 +4800,22 @@ class TryExceptStatNode(StatNode): if code.label_used(exit_label): code.put_label(exit_label) - for var in Naming.exc_save_vars: code.put_xgiveref(var) + for var in exc_save_vars: code.put_xgiveref(var) code.putln("__Pyx_ExceptionReset(%s);" % - ', '.join(Naming.exc_save_vars)) + ', '.join(exc_save_vars)) code.put_goto(old_label) if code.label_used(except_end_label): code.put_label(except_end_label) - for var in Naming.exc_save_vars: code.put_xgiveref(var) + for var in exc_save_vars: code.put_xgiveref(var) code.putln("__Pyx_ExceptionReset(%s);" % - ', '.join(Naming.exc_save_vars)) + ', '.join(exc_save_vars)) code.put_label(try_end_label) code.putln("}") + for cname in exc_save_vars: + code.funcstate.release_temp(cname) + code.return_label = old_return_label code.break_label = old_break_label code.continue_label = old_continue_label -- 2.26.2