[Zodb-checkins] SVN: ZODB/trunk/src/BTrees/ Added type checks to get better error messages.
Jim Fulton
jim at zope.com
Sat Aug 22 13:46:16 EDT 2009
Log message for revision 103090:
Added type checks to get better error messages.
Changed:
U ZODB/trunk/src/BTrees/BTreeTemplate.c
U ZODB/trunk/src/BTrees/BucketTemplate.c
U ZODB/trunk/src/BTrees/SetTemplate.c
U ZODB/trunk/src/BTrees/tests/testBTrees.py
-=-
Modified: ZODB/trunk/src/BTrees/BTreeTemplate.c
===================================================================
--- ZODB/trunk/src/BTrees/BTreeTemplate.c 2009-08-22 17:46:13 UTC (rev 103089)
+++ ZODB/trunk/src/BTrees/BTreeTemplate.c 2009-08-22 17:46:16 UTC (rev 103090)
@@ -1001,6 +1001,12 @@
if (!PyArg_ParseTuple(state, "O|O:__setstate__", &items, &firstbucket))
return -1;
+ if (!PyTuple_Check(items)) {
+ PyErr_SetString(PyExc_TypeError,
+ "tuple required for first state element");
+ return -1;
+ }
+
len = PyTuple_Size(items);
if (len < 0)
return -1;
Modified: ZODB/trunk/src/BTrees/BucketTemplate.c
===================================================================
--- ZODB/trunk/src/BTrees/BucketTemplate.c 2009-08-22 17:46:13 UTC (rev 103089)
+++ ZODB/trunk/src/BTrees/BucketTemplate.c 2009-08-22 17:46:16 UTC (rev 103090)
@@ -1182,6 +1182,12 @@
if (!PyArg_ParseTuple(state, "O|O:__setstate__", &items, &next))
return -1;
+ if (!PyTuple_Check(items)) {
+ PyErr_SetString(PyExc_TypeError,
+ "tuple required for first state element");
+ return -1;
+ }
+
len = PyTuple_Size(items);
if (len < 0)
return -1;
Modified: ZODB/trunk/src/BTrees/SetTemplate.c
===================================================================
--- ZODB/trunk/src/BTrees/SetTemplate.c 2009-08-22 17:46:13 UTC (rev 103089)
+++ ZODB/trunk/src/BTrees/SetTemplate.c 2009-08-22 17:46:16 UTC (rev 103090)
@@ -108,6 +108,12 @@
UNLESS (PyArg_ParseTuple(args, "O|O", &items, &next))
return -1;
+ if (!PyTuple_Check(items)) {
+ PyErr_SetString(PyExc_TypeError,
+ "tuple required for first state element");
+ return -1;
+ }
+
if ((l=PyTuple_Size(items)) < 0) return -1;
for (i=self->len; --i >= 0; )
Modified: ZODB/trunk/src/BTrees/tests/testBTrees.py
===================================================================
--- ZODB/trunk/src/BTrees/tests/testBTrees.py 2009-08-22 17:46:13 UTC (rev 103089)
+++ ZODB/trunk/src/BTrees/tests/testBTrees.py 2009-08-22 17:46:16 UTC (rev 103090)
@@ -83,6 +83,13 @@
self._closeRoot(root)
self._closeRoot(root2)
+ def testSetstateArgumentChecking(self):
+ try: self.t.__class__().__setstate__(('',))
+ except TypeError, v:
+ self.assertEqual(str(v), 'tuple required for first state element')
+ else:
+ raise AssertionError("Expected exception")
+
def testGhostUnghost(self):
for i in 0, 10, 1000:
t = self.t.__class__()
More information about the Zodb-checkins
mailing list