[pypy-commit] pypy cpyext-leakchecking: Be more careful with refcounts in array.c

rlamy pypy.commits at gmail.com
Tue Jul 25 08:10:01 EDT 2017


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: cpyext-leakchecking
Changeset: r91965:438c0c9af393
Date: 2017-07-25 14:09 +0200
http://bitbucket.org/pypy/pypy/changeset/438c0c9af393/

Log:	Be more careful with refcounts in array.c

diff --git a/pypy/module/cpyext/sequence.py b/pypy/module/cpyext/sequence.py
--- a/pypy/module/cpyext/sequence.py
+++ b/pypy/module/cpyext/sequence.py
@@ -48,7 +48,7 @@
     m as the message text. If the conversion otherwise, fails, reraise the
     original exception"""
     if isinstance(w_obj, W_ListObject):
-        # make sure we can return a borrowed obj from PySequence_Fast_GET_ITEM    
+        # make sure we can return a borrowed obj from PySequence_Fast_GET_ITEM
         w_obj.convert_to_cpy_strategy(space)
         return w_obj
     try:
@@ -313,7 +313,7 @@
                                                          self)
         w_clone.switch_to_object_strategy()
         return w_clone
-        
+
     def copy_into(self, w_list, w_other):
         w_list.switch_to_object_strategy()
         w_list.strategy.copy_into(w_list, w_other)
@@ -378,7 +378,7 @@
 
     def is_empty_strategy(self):
         return False
-        
+
 
 PyObjectList = lltype.Ptr(lltype.Array(PyObject, hints={'nolength': True}))
 
diff --git a/pypy/module/cpyext/test/array.c b/pypy/module/cpyext/test/array.c
--- a/pypy/module/cpyext/test/array.c
+++ b/pypy/module/cpyext/test/array.c
@@ -1867,6 +1867,7 @@
         int n = PyList_Size(obj1);
         PyObject *v = getarrayitem(obj2, 0);
         int i = ((PyIntObject*)v)->ob_ival;
+        Py_DECREF(v);
         PyObject * ret = PyList_New(n*i);
         for (ii = 0; ii < i; ii++)
             for (nn = 0; nn < n; nn++)
@@ -1883,6 +1884,7 @@
         int n = PyList_Size(obj2);
         PyObject *v = getarrayitem(obj1, 0);
         int i = ((PyIntObject*)v)->ob_ival;
+        Py_DECREF(v);
         PyObject * ret = PyList_New(n*i);
         for (ii = 0; ii < i; ii++)
             for (nn = 0; nn < n; nn++)
@@ -1919,6 +1921,7 @@
         int n = PyList_Size(obj1);
         PyObject *v = getarrayitem(obj2, 0);
         int i = ((PyIntObject*)v)->ob_ival;
+        Py_DECREF(v);
         PyObject * ret = PyList_New(n);
         for (nn = 0; nn < n; nn++)
         {
@@ -1926,7 +1929,10 @@
             if (PyInt_Check(v))
                 PyList_SetItem(ret, nn, PyLong_FromLong(i * ((PyIntObject*)v)->ob_ival));
             else
+            {
+                Py_INCREF(v);
                 PyList_SetItem(ret, nn, v);
+            }
         }
         return ret;
     }
@@ -1936,6 +1942,7 @@
         int n = PyList_Size(obj2);
         PyObject *v = getarrayitem(obj1, 0);
         int i = ((PyIntObject*)v)->ob_ival;
+        Py_DECREF(v);
         PyObject * ret = PyList_New(n);
         for (nn = 0; nn < n; nn++)
         {
@@ -1943,7 +1950,10 @@
             if (PyInt_Check(v))
                 PyList_SetItem(ret, nn, PyLong_FromLong(i * ((PyIntObject*)v)->ob_ival));
             else
+            {
+                Py_INCREF(v);
                 PyList_SetItem(ret, nn, v);
+            }
         }
         return ret;
     }


More information about the pypy-commit mailing list