Commit dcfeeb41 authored by Jim Fulton's avatar Jim Fulton

- Fixed: In the C implimentation, an integer was compared with a

  pointer, with undefined results and a compiler warning.

- Fixed: the Python implementation of the _p_estimated_size propety
  didn't support deletion.

- Simplified implememnntation of the _p_estimated_size property to
  only accept integers.  A TypeError is raised if an incorrect type is
  provided.
parent edb25536
...@@ -4,8 +4,15 @@ ...@@ -4,8 +4,15 @@
4.0.3 (unreleased) 4.0.3 (unreleased)
------------------ ------------------
- TBD - Fixed: In the C implimentation, an integer was compared with a
pointer, with undefined results and a compiler warning.
- Fixed: the Python implementation of the _p_estimated_size propety
didn't support deletion.
- Simplified implememnntation of the _p_estimated_size property to
only accept integers. A TypeError is raised if an incorrect type is
provided.
4.0.2 (2012-08-27) 4.0.2 (2012-08-27)
------------------ ------------------
......
...@@ -24,7 +24,7 @@ struct ccobject_head_struct { ...@@ -24,7 +24,7 @@ struct ccobject_head_struct {
}; };
/* These two objects are initialized when the module is loaded */ /* These two objects are initialized when the module is loaded */
static PyObject *TimeStamp, *py_simple_new, *sys_maxint; static PyObject *TimeStamp, *py_simple_new;
/* Strings initialized by init_strings() below. */ /* Strings initialized by init_strings() below. */
static PyObject *py_keys, *py_setstate, *py___dict__, *py_timeTime; static PyObject *py_keys, *py_setstate, *py___dict__, *py_timeTime;
...@@ -1118,14 +1118,6 @@ Per_set_estimated_size(cPersistentObject *self, PyObject *v) ...@@ -1118,14 +1118,6 @@ Per_set_estimated_size(cPersistentObject *self, PyObject *v)
{ {
if (v) if (v)
{ {
if (PyLong_Check(v))
{
long long llv = PyLong_AsLongLong(v);
if (llv > sys_maxint)
{
v = sys_maxint; /* borrow reference */
}
}
if (PyInt_Check(v)) if (PyInt_Check(v))
{ {
long lv = PyInt_AS_LONG(v); long lv = PyInt_AS_LONG(v);
...@@ -1139,7 +1131,7 @@ Per_set_estimated_size(cPersistentObject *self, PyObject *v) ...@@ -1139,7 +1131,7 @@ Per_set_estimated_size(cPersistentObject *self, PyObject *v)
} }
else else
{ {
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_TypeError,
"_p_estimated_size must be an integer"); "_p_estimated_size must be an integer");
return -1; return -1;
} }
...@@ -1430,18 +1422,6 @@ initcPersistence(void) ...@@ -1430,18 +1422,6 @@ initcPersistence(void)
return; return;
TimeStamp = PyObject_GetAttrString(m, "TimeStamp"); TimeStamp = PyObject_GetAttrString(m, "TimeStamp");
Py_DECREF(m); Py_DECREF(m);
if (!TimeStamp) /* fall through to immediate return on error */
return;
}
if (!sys_maxint)
{
m = PyImport_ImportModule("sys");
if (!m)
return;
sys_maxint = PyObject_GetAttrString(m, "maxint");
Py_DECREF(m);
if (!sys_maxint)
return;
} }
} }
...@@ -166,12 +166,18 @@ class Persistent(object): ...@@ -166,12 +166,18 @@ class Persistent(object):
return self.__size * 64 return self.__size * 64
def _set_estimated_size(self, value): def _set_estimated_size(self, value):
value = int(value) if isinstance(value, int):
if value < 0: if value < 0:
raise ValueError('_p_estimated_size must not be negative') raise ValueError('_p_estimated_size must not be negative')
self.__size = _estimated_size_in_24_bits(value) self.__size = _estimated_size_in_24_bits(value)
else:
raise TypeError("_p_estimated_size must be an integer")
def _del_estimated_size(self):
self.__size = 0
_p_estimated_size = property(_get_estimated_size, _set_estimated_size) _p_estimated_size = property(
_get_estimated_size, _set_estimated_size, _del_estimated_size)
# The '_p_sticky' property is not (yet) part of the API: for now, # The '_p_sticky' property is not (yet) part of the API: for now,
# it exists to simplify debugging and testing assertions. # it exists to simplify debugging and testing assertions.
......
...@@ -486,6 +486,20 @@ class _Persistent_Base(object): ...@@ -486,6 +486,20 @@ class _Persistent_Base(object):
inst = self._makeOne() inst = self._makeOne()
self.assertEqual(inst._p_estimated_size, 0) self.assertEqual(inst._p_estimated_size, 0)
def test_query_p_estimated_size_del(self):
inst = self._makeOne()
inst._p_estimated_size = 123
self.assertEqual(inst._p_estimated_size, 128)
del inst._p_estimated_size
self.assertEqual(inst._p_estimated_size, 0)
def test_assign_p_estimated_size_wrong_type(self):
inst = self._makeOne()
self.assertRaises(TypeError,
lambda : setattr(inst, '_p_estimated_size', None))
self.assertRaises(TypeError,
lambda : setattr(inst, '_p_estimated_size', 1L))
def test_assign_p_estimated_size_negative(self): def test_assign_p_estimated_size_negative(self):
inst = self._makeOne() inst = self._makeOne()
def _test(): def _test():
...@@ -504,12 +518,7 @@ class _Persistent_Base(object): ...@@ -504,12 +518,7 @@ class _Persistent_Base(object):
def test_assign_p_estimated_size_bigger(self): def test_assign_p_estimated_size_bigger(self):
inst = self._makeOne() inst = self._makeOne()
inst._p_estimated_size = 1073741697 * 4 #still <= 32 bits inst._p_estimated_size = 1073741697 * 2
self.assertEqual(inst._p_estimated_size, 16777215 * 64)
def test_assign_p_estimated_size_bigger_than_sys_maxint(self):
inst = self._makeOne()
inst._p_estimated_size = 2**63 -1 #largest 'long long' in C
self.assertEqual(inst._p_estimated_size, 16777215 * 64) self.assertEqual(inst._p_estimated_size, 16777215 * 64)
def test___getattribute___p__names(self): 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