Commit 8935d030 authored by Tim Peters's avatar Tim Peters

Collector #892: Misleading error msg when initializing an OIBTree

from a dict with a float value.

Mapping_update():  This squashed errors raised by PyObject_SetItem(),
changing them to a "not a 2-tuple" TypeError instead.  Unclear why, since
2-tupleness was checked earlier.  Fixed by backporting part of the
ZODB4 BTree construction code, which doesn't have this problem.  Bonus:
it's faster now too.
parent d680d201
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
****************************************************************************/ ****************************************************************************/
#define BUCKETTEMPLATE_C "$Id: BucketTemplate.c,v 1.53 2003/04/16 16:01:10 tim_one Exp $\n" #define BUCKETTEMPLATE_C "$Id: BucketTemplate.c,v 1.54 2003/05/12 00:36:17 tim_one Exp $\n"
/* Use BUCKET_SEARCH to find the index at which a key belongs. /* Use BUCKET_SEARCH to find the index at which a key belongs.
* INDEX An int lvalue to hold the index i such that KEY belongs at * INDEX An int lvalue to hold the index i such that KEY belongs at
...@@ -461,7 +461,7 @@ static PyObject * ...@@ -461,7 +461,7 @@ static PyObject *
Mapping_update(PyObject *self, PyObject *args) Mapping_update(PyObject *self, PyObject *args)
{ {
PyObject *seq=0, *o, *t, *v, *tb, *k, *items = NULL; PyObject *seq=0, *o, *t, *v, *tb, *k, *items = NULL;
int i, ind; int i;
UNLESS(PyArg_ParseTuple(args, "|O:update", &seq)) return NULL; UNLESS(PyArg_ParseTuple(args, "|O:update", &seq)) return NULL;
...@@ -497,16 +497,22 @@ Mapping_update(PyObject *self, PyObject *args) ...@@ -497,16 +497,22 @@ Mapping_update(PyObject *self, PyObject *args)
Py_XDECREF(tb); Py_XDECREF(tb);
break; break;
} }
ind = PyArg_ParseTuple(o, "OO;items must be 2-item tuples", &k, &v);
if (ind) if (!PyTuple_Check(o) || PyTuple_GET_SIZE(o) != 2)
ind = PyObject_SetItem(self, k, v); {
else Py_DECREF(o);
ind = -1; PyErr_SetString(PyExc_TypeError,
Py_DECREF(o); "Sequence must contain 2-item tuples");
if (ind < 0) { goto err;
PyErr_SetString(PyExc_TypeError,"Sequence must contain 2-item tuples"); }
goto err; k = PyTuple_GET_ITEM(o, 0);
v = PyTuple_GET_ITEM(o, 1);
if (PyObject_SetItem(self, k, v) < 0)
{
Py_DECREF(o);
goto err;
} }
Py_DECREF(o);
} }
Py_XDECREF(items); Py_XDECREF(items);
......
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