[Checkins] SVN: persistent/branches/jim-fix-estimates-size/ - Fixed: In the C implimentation, an integer was compared with a
jim
cvs-admin at zope.org
Fri Nov 16 12:29:24 UTC 2012
Log message for revision 128312:
- 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.
Changed:
U persistent/branches/jim-fix-estimates-size/CHANGES.txt
U persistent/branches/jim-fix-estimates-size/persistent/cPersistence.c
U persistent/branches/jim-fix-estimates-size/persistent/persistence.py
U persistent/branches/jim-fix-estimates-size/persistent/tests/test_persistence.py
-=-
Modified: persistent/branches/jim-fix-estimates-size/CHANGES.txt
===================================================================
--- persistent/branches/jim-fix-estimates-size/CHANGES.txt 2012-11-16 12:19:52 UTC (rev 128311)
+++ persistent/branches/jim-fix-estimates-size/CHANGES.txt 2012-11-16 12:29:23 UTC (rev 128312)
@@ -4,9 +4,16 @@
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)
------------------
Modified: persistent/branches/jim-fix-estimates-size/persistent/cPersistence.c
===================================================================
--- persistent/branches/jim-fix-estimates-size/persistent/cPersistence.c 2012-11-16 12:19:52 UTC (rev 128311)
+++ persistent/branches/jim-fix-estimates-size/persistent/cPersistence.c 2012-11-16 12:29:23 UTC (rev 128312)
@@ -24,7 +24,7 @@
};
/* 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. */
static PyObject *py_keys, *py_setstate, *py___dict__, *py_timeTime;
@@ -1118,14 +1118,6 @@
{
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))
{
long lv = PyInt_AS_LONG(v);
@@ -1139,7 +1131,7 @@
}
else
{
- PyErr_SetString(PyExc_ValueError,
+ PyErr_SetString(PyExc_TypeError,
"_p_estimated_size must be an integer");
return -1;
}
@@ -1430,18 +1422,6 @@
return;
TimeStamp = PyObject_GetAttrString(m, "TimeStamp");
Py_DECREF(m);
- if (!TimeStamp)
- return;
+ /* fall through to immediate return on error */
}
-
- 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/branches/jim-fix-estimates-size/persistent/persistence.py
===================================================================
--- persistent/branches/jim-fix-estimates-size/persistent/persistence.py 2012-11-16 12:19:52 UTC (rev 128311)
+++ persistent/branches/jim-fix-estimates-size/persistent/persistence.py 2012-11-16 12:29:23 UTC (rev 128312)
@@ -166,13 +166,19 @@
return self.__size * 64
def _set_estimated_size(self, value):
- value = int(value)
- if value < 0:
- raise ValueError('_p_estimated_size must not be negative')
- self.__size = _estimated_size_in_24_bits(value)
+ if isinstance(value, int):
+ if value < 0:
+ raise ValueError('_p_estimated_size must not be negative')
+ self.__size = _estimated_size_in_24_bits(value)
+ else:
+ raise TypeError("_p_estimated_size must be an integer")
- _p_estimated_size = property(_get_estimated_size, _set_estimated_size)
+ def _del_estimated_size(self):
+ self.__size = 0
+ _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,
# it exists to simplify debugging and testing assertions.
def _get_sticky(self):
Modified: persistent/branches/jim-fix-estimates-size/persistent/tests/test_persistence.py
===================================================================
--- persistent/branches/jim-fix-estimates-size/persistent/tests/test_persistence.py 2012-11-16 12:19:52 UTC (rev 128311)
+++ persistent/branches/jim-fix-estimates-size/persistent/tests/test_persistence.py 2012-11-16 12:29:23 UTC (rev 128312)
@@ -486,6 +486,20 @@
inst = self._makeOne()
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):
inst = self._makeOne()
def _test():
@@ -504,14 +518,9 @@
def test_assign_p_estimated_size_bigger(self):
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)
-
def test___getattribute___p__names(self):
NAMES = ['_p_jar',
'_p_oid',
More information about the checkins
mailing list