[pypy-svn] pypy default: Add a passing test about borrowing the same object twice from the same container.

amauryfa commits-noreply at bitbucket.org
Tue Mar 15 19:20:51 CET 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r42676:d8724d17e24f
Date: 2011-03-15 19:18 +0100
http://bitbucket.org/pypy/pypy/changeset/d8724d17e24f/

Log:	Add a passing test about borrowing the same object twice from the
	same container.

diff --git a/pypy/module/cpyext/test/test_borrow.py b/pypy/module/cpyext/test/test_borrow.py
--- a/pypy/module/cpyext/test/test_borrow.py
+++ b/pypy/module/cpyext/test/test_borrow.py
@@ -58,3 +58,22 @@
              """),
             ])
         assert module.test_borrow_destroy() == 42
+
+    def test_double_borrow(self):
+        module = self.import_extension('foo', [
+            ("run", "METH_NOARGS",
+             """
+                PyObject *t = PyTuple_New(1);
+                PyObject *s = PyRun_String("set()", Py_eval_input,
+                                           Py_None, Py_None);
+                PyObject *w = PyWeakref_NewRef(s, Py_None);
+                PyTuple_SetItem(t, 0, s);
+                PyTuple_GetItem(t, 0);
+                PyTuple_GetItem(t, 0);
+                Py_DECREF(t);
+                return w;
+             """),
+            ])
+        wr = module.run()
+        # check that the set() object was deallocated
+        assert wr() is None


More information about the Pypy-commit mailing list