[pypy-commit] pypy cpyext-avoid-roundtrip: (antocuni, arigo): we can no longer call decref on w_obj now, because make_ref returns an unliked PyObject for integers. Fix the test

antocuni pypy.commits at gmail.com
Tue Oct 10 04:33:37 EDT 2017


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: cpyext-avoid-roundtrip
Changeset: r92697:a6058690cb67
Date: 2017-10-10 10:32 +0200
http://bitbucket.org/pypy/pypy/changeset/a6058690cb67/

Log:	(antocuni, arigo): we can no longer call decref on w_obj now,
	because make_ref returns an unliked PyObject for integers. Fix the
	test

diff --git a/pypy/module/cpyext/test/test_number.py b/pypy/module/cpyext/test/test_number.py
--- a/pypy/module/cpyext/test/test_number.py
+++ b/pypy/module/cpyext/test/test_number.py
@@ -54,19 +54,23 @@
     def test_coerce(self, space):
         w_obj1 = space.wrap(123)
         w_obj2 = space.wrap(456.789)
+        p1 = make_ref(space, w_obj1)
+        p2 = make_ref(space, w_obj2)
         pp1 = lltype.malloc(PyObjectP.TO, 1, flavor='raw')
-        pp1[0] = make_ref(space, w_obj1)
+        pp1[0] = p1
         pp2 = lltype.malloc(PyObjectP.TO, 1, flavor='raw')
-        pp2[0] = make_ref(space, w_obj2)
+        pp2[0] = p2
         assert PyNumber_Coerce(space, pp1, pp2) == 0
         assert space.str_w(space.repr(from_ref(space, pp1[0]))) == '123.0'
         assert space.str_w(space.repr(from_ref(space, pp2[0]))) == '456.789'
+        #
+        # We need to decref twice because PyNumber_Coerce does an incref and
+        # possibly changes the content of pp1 and pp2
+        Py_DecRef(space, p1)
         Py_DecRef(space, pp1[0])
+        Py_DecRef(space, p2)
         Py_DecRef(space, pp2[0])
         lltype.free(pp1, flavor='raw')
-        # Yes, decrement twice since we decoupled between w_obj* and pp*[0].
-        Py_DecRef(space, w_obj1)
-        Py_DecRef(space, w_obj2)
         lltype.free(pp2, flavor='raw')
 
     def test_number_coerce_ex(self, space):


More information about the pypy-commit mailing list