Commit 54642b0b authored by Jim Fulton's avatar Jim Fulton

Added type checks to get better error messages.

parent 709f6b3c
......@@ -1001,6 +1001,12 @@ _BTree_setstate(BTree *self, PyObject *state, int noval)
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;
......
......@@ -1182,6 +1182,12 @@ _bucket_setstate(Bucket *self, PyObject *state)
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;
......
......@@ -108,6 +108,12 @@ _set_setstate(Bucket *self, PyObject *args)
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; )
......
......@@ -83,6 +83,13 @@ class Base(TestCase):
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__()
......
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