[Numpy-svn] r6351 - in trunk/numpy/core: src tests

numpy-svn@scip... numpy-svn@scip...
Mon Feb 9 14:18:37 CST 2009


Author: ptvirtan
Date: 2009-02-09 14:18:08 -0600 (Mon, 09 Feb 2009)
New Revision: 6351

Modified:
   trunk/numpy/core/src/scalarmathmodule.c.src
   trunk/numpy/core/tests/test_regression.py
Log:
Fix #955: fix errobj leak in scalarmath floating point error handling

Modified: trunk/numpy/core/src/scalarmathmodule.c.src
===================================================================
--- trunk/numpy/core/src/scalarmathmodule.c.src	2009-02-07 18:51:31 UTC (rev 6350)
+++ trunk/numpy/core/src/scalarmathmodule.c.src	2009-02-09 20:18:08 UTC (rev 6351)
@@ -636,8 +636,11 @@
                                 &errobj) < 0)
             return NULL;
         first = 1;
-        if (PyUFunc_handlefperr(errmask, errobj, retstatus, &first))
+        if (PyUFunc_handlefperr(errmask, errobj, retstatus, &first)) {
+            Py_XDECREF(errobj);
             return NULL;
+        }
+        Py_XDECREF(errobj);
     }
 #endif
 
@@ -736,8 +739,11 @@
                                 &errobj) < 0)
             return NULL;
         first = 1;
-        if (PyUFunc_handlefperr(errmask, errobj, retstatus, &first))
+        if (PyUFunc_handlefperr(errmask, errobj, retstatus, &first)) {
+            Py_XDECREF(errobj);
             return NULL;
+        }
+        Py_XDECREF(errobj);
     }
 
 #if @isint@

Modified: trunk/numpy/core/tests/test_regression.py
===================================================================
--- trunk/numpy/core/tests/test_regression.py	2009-02-07 18:51:31 UTC (rev 6350)
+++ trunk/numpy/core/tests/test_regression.py	2009-02-09 20:18:08 UTC (rev 6351)
@@ -1,7 +1,7 @@
-
 from StringIO import StringIO
 import pickle
 import sys
+import gc
 from os import path
 from numpy.testing import *
 import numpy as np
@@ -1208,5 +1208,17 @@
         a = np.array(1)
         self.failUnlessRaises(ValueError, lambda x: x.choose([]), a)
 
+    def test_errobj_reference_leak(self, level=rlevel):
+        """Ticket #955"""
+        z = int(0)
+        p = np.int32(-1)
+
+        gc.collect()
+        n_before = len(gc.get_objects())
+        z**p  # this shouldn't leak a reference to errobj
+        gc.collect()
+        n_after = len(gc.get_objects())
+        assert n_before >= n_after, (n_before, n_after)
+
 if __name__ == "__main__":
     run_module_suite()



More information about the Numpy-svn mailing list