From 426999c6f0b121f8e9d6adbf2f9fd8a2fc7cbd94 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Thu, 27 Nov 2008 09:10:12 +0100 Subject: [PATCH] fix temp handling in 'with' transform --- Cython/Compiler/ParseTreeTransforms.py | 16 +++++++++------- Cython/Compiler/Tests/TestParseTreeTransforms.py | 2 ++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py index f4b02fde..94689d6c 100644 --- a/Cython/Compiler/ParseTreeTransforms.py +++ b/Cython/Compiler/ParseTreeTransforms.py @@ -457,6 +457,7 @@ class WithTransform(CythonTransform): EXIT = MGR.__exit__ MGR.__enter__() EXC = True + EXCINFO = None try: try: BODY @@ -475,6 +476,7 @@ class WithTransform(CythonTransform): EXIT = MGR.__exit__ VALUE = MGR.__enter__() EXC = True + EXCINFO = None try: try: TARGET = VALUE @@ -490,7 +492,9 @@ class WithTransform(CythonTransform): pipeline=[NormalizeTree(None)]) def visit_WithStatNode(self, node): - excinfo_temp = TempHandle(PyrexTypes.py_object_type) + # FIXME: excinfo_temp should be more local to the except + # clause that uses it, to avoid the presetting to None + excinfo_temp = TempHandle(Builtin.tuple_type) if node.target is not None: result = self.template_with_target.substitute({ u'EXPR' : node.manager, @@ -498,18 +502,16 @@ class WithTransform(CythonTransform): u'TARGET' : node.target, u'EXCINFO' : excinfo_temp.ref(node.pos) }, pos=node.pos) - # Set except excinfo target to EXCINFO - result.body.stats[4].body.stats[0].except_clauses[0].excinfo_target = ( - excinfo_temp.ref(node.pos)) else: result = self.template_without_target.substitute({ u'EXPR' : node.manager, u'BODY' : node.body, u'EXCINFO' : excinfo_temp.ref(node.pos) }, pos=node.pos) - # Set except excinfo target to EXCINFO - result.body.stats[4].body.stats[0].except_clauses[0].excinfo_target = ( - excinfo_temp.ref(node.pos)) + + # Set except excinfo target to EXCINFO + result.body.stats[5].body.stats[0].except_clauses[0].excinfo_target = ( + excinfo_temp.ref(node.pos)) return TempsBlockNode(node.pos, temps=[excinfo_temp], body=result) diff --git a/Cython/Compiler/Tests/TestParseTreeTransforms.py b/Cython/Compiler/Tests/TestParseTreeTransforms.py index 93e3d452..e79b1d6b 100644 --- a/Cython/Compiler/Tests/TestParseTreeTransforms.py +++ b/Cython/Compiler/Tests/TestParseTreeTransforms.py @@ -99,6 +99,7 @@ class TestWithTransform(TransformTest): $1_2 = $1_0.__exit__ $1_0.__enter__() $1_1 = True + $0_0 = None try: try: y = z ** 3 @@ -123,6 +124,7 @@ class TestWithTransform(TransformTest): $1_2 = $1_0.__exit__ $1_3 = $1_0.__enter__() $1_1 = True + $0_0 = None try: try: y = $1_3 -- 2.26.2