More refnanny fixes
authorDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Thu, 29 Jan 2009 20:00:15 +0000 (21:00 +0100)
committerDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Thu, 29 Jan 2009 20:00:15 +0000 (21:00 +0100)
Cython/Compiler/Code.py
Cython/Compiler/ModuleNode.py
Cython/Compiler/Nodes.py

index 3ebb184c03da5b91a33d2907fb79d433c33c6b8d..b380a59f68b11d6f56923afff81c68bda6dc8e98 100644 (file)
@@ -749,6 +749,9 @@ class CCodeWriter(object):
     def put_xgiveref(self, cname):
         self.putln("__Pyx_XGIVEREF(%s);" % cname)
 
+    def put_xgotref(self, cname):
+        self.putln("__Pyx_XGOTREF(%s);" % cname)
+
     def put_incref(self, cname, type, nanny=True):
         if nanny:
             self.putln("__Pyx_INCREF(%s);" % self.as_pyobject(cname, type))
index 1982775024658b922aff7719f2e53ba6b533cbdc..c4aaf1a0ce98a747cfed406d1a8ff26ede30c3fe 100644 (file)
@@ -2348,4 +2348,5 @@ int __Pyx_Refnanny_FinishContext(void*);
 #define __Pyx_FinishRefcountContext() 0
 #endif /* CYTHON_REFNANNY */
 #define __Pyx_XGIVEREF(r) (r ? __Pyx_GIVEREF(r) : 0)
+#define __Pyx_XGOTREF(r) (r ? __Pyx_GOTREF(r) : 0)
 """)
index 46c11dca03e6e9073f81f9663bdf9a520531e69b..0d6556200aa70bcbd1e57eeea53bf3ce9c347ccc 100644 (file)
@@ -2145,6 +2145,7 @@ class DefNode(FuncDefNode):
                     self.starstar_arg.entry.cname,
                     self.starstar_arg.entry.cname,
                     self.error_value()))
+            code.put_gotref(self.starstar_arg.entry.cname)
         if self.star_arg:
             self.star_arg.entry.xdecref_cleanup = 0
             code.putln('if (PyTuple_GET_SIZE(%s) > %d) {' % (
@@ -2153,6 +2154,7 @@ class DefNode(FuncDefNode):
             code.put('%s = PyTuple_GetSlice(%s, %d, PyTuple_GET_SIZE(%s)); ' % (
                     self.star_arg.entry.cname, Naming.args_cname,
                     max_positional_args, Naming.args_cname))
+            code.put_gotref(self.star_arg.entry.cname)
             if self.starstar_arg:
                 code.putln("")
                 code.putln("if (unlikely(!%s)) {" % self.star_arg.entry.cname)
@@ -4026,6 +4028,8 @@ class TryExceptStatNode(StatNode):
                    ', '.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:
+            code.put_xgotref(var)
         code.putln(
             "/*try:*/ {")
         code.return_label = try_return_label
@@ -4066,12 +4070,14 @@ class TryExceptStatNode(StatNode):
 
         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)
 
         if code.label_used(except_end_label):
             code.put_label(except_end_label)
+            for var in Naming.exc_save_vars: code.put_xgiveref(var)
             code.putln("__Pyx_ExceptionReset(%s);" %
                        ', '.join(Naming.exc_save_vars))
         code.put_label(try_end_label)