[Pyrex] Pyrex exception handling bug

Robert Bradshaw robertwb at math.washington.edu
Wed Oct 24 10:11:49 CEST 2007


There is a bug in the except clause code that can lead to a double- 
decref (and mysterious, seemingly-unrelated errors down the road).  
Here's a patch.


# HG changeset patch
# User Robert Bradshaw <robertwb at math.washington.edu>
# Date 1193210066 25200
# Node ID 15af95b253bd4617566f32366f6b030e52214653
# Parent  03a1ed4db54209f4fbae58761dff15e912c5900e
Decref error in except clause

Temporary variables must be set to zero or they might be XDECREF'ed  
later, generating very hard to track bugs.

diff -r 03a1ed4db542 -r 15af95b253bd Compiler/Nodes.py
--- a/Compiler/Nodes.py Sun Oct 21 14:20:59 2007 +0200
+++ b/Compiler/Nodes.py Wed Oct 24 00:14:26 2007 -0700
@@ -2589,7 +2589,7 @@ class ExceptClauseNode(Node):
          self.body.generate_execution_code(code)
          code.exc_vars = old_exc_vars
          for var in self.exc_vars:
-            code.putln("Py_DECREF(%s);" % var)
+            code.putln("Py_DECREF(%s); %s = 0;" % (var, var))
          code.put_goto(end_label)
          code.putln(
              "}")




More information about the Pyrex mailing list