[Checkins] SVN: persistent/trunk/ Worked around test failure due to overflow to long on 32-bit systems.

Tres Seaver cvs-admin at zope.org
Sun Aug 26 18:30:25 UTC 2012


Log message for revision 127583:
  Worked around test failure due to overflow to long on 32-bit systems.
  

Changed:
  _U  persistent/trunk/
  U   persistent/trunk/CHANGES.txt
  U   persistent/trunk/persistent/cPersistence.c
  U   persistent/trunk/persistent/tests/test_persistence.py

-=-
Modified: persistent/trunk/CHANGES.txt
===================================================================
--- persistent/trunk/CHANGES.txt	2012-08-26 16:19:07 UTC (rev 127582)
+++ persistent/trunk/CHANGES.txt	2012-08-26 18:30:20 UTC (rev 127583)
@@ -4,6 +4,8 @@
 4.0.1 (unreleased)
 ------------------
 
+- Worked around test failure due to overflow to long on 32-bit systems.
+
 - Renamed ``TimeStamp`` extension module to avoid clash with pure-Python
   ``timestamp`` module on case-insensitive filesystems.
 

Modified: persistent/trunk/persistent/cPersistence.c
===================================================================
--- persistent/trunk/persistent/cPersistence.c	2012-08-26 16:19:07 UTC (rev 127582)
+++ persistent/trunk/persistent/cPersistence.c	2012-08-26 18:30:20 UTC (rev 127583)
@@ -24,7 +24,7 @@
 };
 
 /* These two objects are initialized when the module is loaded */
-static PyObject *TimeStamp, *py_simple_new;
+static PyObject *TimeStamp, *py_simple_new, *sys_maxint;
 
 /* Strings initialized by init_strings() below. */
 static PyObject *py_keys, *py_setstate, *py___dict__, *py_timeTime;
@@ -1118,6 +1118,14 @@
 {
   if (v)
     {
+      if (PyLong_Check(v))
+      {
+          long long llv = PyInt_AsLongLong(v);
+          if (llv > sys_maxint)
+          {
+             v = sys_maxint;  /* borrow reference */
+          }
+      }
       if (PyInt_Check(v))
         {
           long lv = PyInt_AS_LONG(v);
@@ -1422,6 +1430,18 @@
         return;
       TimeStamp = PyObject_GetAttrString(m, "TimeStamp");
       Py_DECREF(m);
-      /* fall through to immediate return on error */
+      if (!TimeStamp)
+        return;
     }
+
+  if (!sys_maxint)
+    {
+      m = PyImport_ImportModule("sys");
+      if (!m)
+        return;
+      sys_maxint = PyObject_GetAttrString(m, "maxint");
+      Py_DECREF(m);
+      if (!sys_maxint)
+        return;
+    }
 }

Modified: persistent/trunk/persistent/tests/test_persistence.py
===================================================================
--- persistent/trunk/persistent/tests/test_persistence.py	2012-08-26 16:19:07 UTC (rev 127582)
+++ persistent/trunk/persistent/tests/test_persistence.py	2012-08-26 18:30:20 UTC (rev 127583)
@@ -504,9 +504,18 @@
 
     def test_assign_p_estimated_size_bigger(self):
         inst = self._makeOne()
-        inst._p_estimated_size = 1073741697 * 1024
+        inst._p_estimated_size = 1073741697 * 4 #still <= 32 bits
         self.assertEqual(inst._p_estimated_size, 16777215 * 64)
 
+    def test_assign_p_estimated_size_bigger_than_sys_maxint(self):
+        try:
+            from sys import maxint
+        except ImportError: #pragma NO COVER PYTHON3
+            maxint = 2**32 - 1
+        inst = self._makeOne()
+        inst._p_estimated_size = maxint + 1
+        self.assertEqual(inst._p_estimated_size, 16777215 * 64)
+
     def test___getattribute___p__names(self):
         NAMES = ['_p_jar',
                  '_p_oid',



More information about the checkins mailing list