Commit cb59607c authored by Tres Seaver's avatar Tres Seaver

Worked around test failure due to overflow to long on 32-bit systems.

parent b64c388b
......@@ -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.
......
......@@ -24,7 +24,7 @@ struct ccobject_head_struct {
};
/* 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 @@ Per_set_estimated_size(cPersistentObject *self, PyObject *v)
{
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 @@ initcPersistence(void)
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;
}
}
......@@ -504,7 +504,16 @@ class _Persistent_Base(object):
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):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment