[pypy-svn] pypy pyarg-parsebuffer-new: Add a test for PyBuffer_Release decrefing the owned object and make it pass

exarkun commits-noreply at bitbucket.org
Wed Apr 20 23:20:13 CEST 2011


Author: Jean-Paul Calderone <exarkun at twistedmatrix.com>
Branch: pyarg-parsebuffer-new
Changeset: r43498:d4569f9560ed
Date: 2011-04-20 17:15 -0400
http://bitbucket.org/pypy/pypy/changeset/d4569f9560ed/

Log:	Add a test for PyBuffer_Release decrefing the owned object and make
	it pass

diff --git a/pypy/module/cpyext/test/test_object.py b/pypy/module/cpyext/test/test_object.py
--- a/pypy/module/cpyext/test/test_object.py
+++ b/pypy/module/cpyext/test/test_object.py
@@ -335,3 +335,31 @@
                  """)])
         result = module.fillinfo()
         assert "hello, world." == result
+
+
+class AppTestPyBuffer_Release(AppTestCpythonExtensionBase):
+    """
+    PyBuffer_Release releases the resources held by a Py_buffer.
+    """
+    def test_decrefObject(self):
+        """
+        The PyObject referenced by Py_buffer.obj has its reference count
+        decremented by PyBuffer_Release.
+        """
+        module = self.import_extension('foo', [
+                ("release", "METH_VARARGS",
+                 """
+    Py_buffer buf;
+    buf.obj = PyString_FromString("release me!");
+    buf.buf = PyString_AsString(buf.obj);
+    buf.len = PyString_Size(buf.obj);
+
+    /* The Py_buffer owns the only reference to that string.  Release the
+     * Py_buffer and the string should be released as well.
+     */
+    PyBuffer_Release(&buf);
+
+    Py_RETURN_NONE;
+                 """)])
+        assert module.release() is None
+

diff --git a/pypy/module/cpyext/object.py b/pypy/module/cpyext/object.py
--- a/pypy/module/cpyext/object.py
+++ b/pypy/module/cpyext/object.py
@@ -442,4 +442,4 @@
 
 @cpython_api([lltype.Ptr(Py_buffer)], lltype.Void, error=CANNOT_FAIL)
 def PyBuffer_Release(space, view):
-    pass
+    Py_DecRef(space, view.c_obj)


More information about the Pypy-commit mailing list