[pypy-commit] pypy cpyext-test-A: Allow the initial refcount of () to be != 1 in test_tupleobject, for CPython-compatibility of the test.

devin.jeanpierre pypy.commits at gmail.com
Sun May 1 02:24:34 EDT 2016


Author: Devin Jeanpierre <jeanpierreda at gmail.com>
Branch: cpyext-test-A
Changeset: r84082:dbc56228353b
Date: 2016-04-30 23:22 -0700
http://bitbucket.org/pypy/pypy/changeset/dbc56228353b/

Log:	Allow the initial refcount of () to be != 1 in test_tupleobject, for
	CPython-compatibility of the test.

diff --git a/pypy/module/cpyext/test/test_tupleobject.py b/pypy/module/cpyext/test/test_tupleobject.py
--- a/pypy/module/cpyext/test/test_tupleobject.py
+++ b/pypy/module/cpyext/test/test_tupleobject.py
@@ -84,7 +84,14 @@
              """
                 PyObject *item = PyTuple_New(0);
                 PyObject *t = PyTuple_New(1);
-                if (t->ob_refcnt != 1 || item->ob_refcnt != 1) {
+#ifdef PYPY_VERSION
+                // PyPy starts even empty tuples with a refcount of 1.
+                const int initial_item_refcount = 1;
+#else
+                // CPython can cache ().
+                const int initial_item_refcount = item->ob_refcnt;
+#endif  // PYPY_VERSION
+                if (t->ob_refcnt != 1 || item->ob_refcnt != initial_item_refcount) {
                     PyErr_SetString(PyExc_SystemError, "bad initial refcnt");
                     return NULL;
                 }
@@ -94,8 +101,8 @@
                     PyErr_SetString(PyExc_SystemError, "SetItem: t refcnt != 1");
                     return NULL;
                 }
-                if (item->ob_refcnt != 1) {
-                    PyErr_SetString(PyExc_SystemError, "SetItem: item refcnt != 1");
+                if (item->ob_refcnt != initial_item_refcount) {
+                    PyErr_SetString(PyExc_SystemError, "GetItem: item refcnt != initial_item_refcount");
                     return NULL;
                 }
 
@@ -109,8 +116,8 @@
                     PyErr_SetString(PyExc_SystemError, "GetItem: t refcnt != 1");
                     return NULL;
                 }
-                if (item->ob_refcnt != 1) {
-                    PyErr_SetString(PyExc_SystemError, "GetItem: item refcnt != 1");
+                if (item->ob_refcnt != initial_item_refcount) {
+                    PyErr_SetString(PyExc_SystemError, "GetItem: item refcnt != initial_item_refcount");
                     return NULL;
                 }
                 return t;


More information about the pypy-commit mailing list