-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 11/15/2012 11:47 AM, Jim Fulton wrote:
> On Sun, Aug 26, 2012 at 2:30 PM, Tres Seaver
> <cvs-ad...@zope.org> wrote:
>> Log message for revision 127583:
> 
> ...
> 
>> Modified: persistent/trunk/persistent/cPersistence.c 
>> ===================================================================
> 
> ...
> 
>> @@ -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 */ +          } +      }
> 
> This is wrong.  You're comparing a long long and a PyObject*.


Thanks.  The attached patch should fix it to compare the value of the
largest allowed size, rather than its pointer.  Does that look correct?


>> 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)
> 
> This test is meant to test that the code that prevents us from 
> overflowing the 30-bits reserved for storring estimated sizes.  Using 
> * 2 (rather than * 4) should be enough.

OK.  If we are truncating anyway, it shouldn't matter.

> We don't really need to support Python longs, do we?  We just need to 
> fix the test to not provoke a long.
> 
> If someone sets a size >2G on a 32-bit platform, they'll get a type 
> error.  I don't think this is a big problem.  If they're doing this, 
> they probably have other problems. :)

The C code raises ValueError in that case.  I don't care whether we
truncate or not:  if you think that an exception works, I'm fine with
changing the tests (and the Python implementation) to fit.

> I propose to revert this change and change 1024 to 2.



Tres.
- -- 
===================================================================
Tres Seaver          +1 540-429-0999          tsea...@palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iEYEARECAAYFAlClKGAACgkQ+gerLs4ltQ7xGwCggARtQgeOSrAES6QJplyer+/k
a44AoJQZoEMzyrGoTrAzCf256EkKSOsv
=ogkb
-----END PGP SIGNATURE-----
=== modified file 'persistent/cPersistence.c'
--- persistent/cPersistence.c	2012-08-26 18:58:51 +0000
+++ persistent/cPersistence.c	2012-11-15 17:33:30 +0000
@@ -24,7 +24,8 @@
 };
 
 /* These two objects are initialized when the module is loaded */
-static PyObject *TimeStamp, *py_simple_new, *sys_maxint;
+static PyObject *TimeStamp, *py_simple_new, *max_est_size;
+static int max_est_size_i = 1073741696;
 
 /* Strings initialized by init_strings() below. */
 static PyObject *py_keys, *py_setstate, *py___dict__, *py_timeTime;
@@ -1121,9 +1122,9 @@
       if (PyLong_Check(v))
       {
           long long llv = PyLong_AsLongLong(v);
-          if (llv > sys_maxint)
+          if (llv > max_est_size_i)
           {
-             v = sys_maxint;  /* borrow reference */
+             v = max_est_size;  /* borrow reference */
           }
       }
       if (PyInt_Check(v))
@@ -1434,14 +1435,10 @@
         return;
     }
 
-  if (!sys_maxint)
+  if (!max_est_size)
     {
-      m = PyImport_ImportModule("sys");
-      if (!m)
-        return;
-      sys_maxint = PyObject_GetAttrString(m, "maxint");
-      Py_DECREF(m);
-      if (!sys_maxint)
+      max_est_size = PyInt_FromInt(max_est_size_i);
+      if (!max_est_size)
         return;
     }
 }

_______________________________________________
For more information about ZODB, see http://zodb.org/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
https://mail.zope.org/mailman/listinfo/zodb-dev

Reply via email to