[Zope-Checkins] CVS: Zope/lib/python/BTrees - BucketTemplate.c:1.47.10.4

Tim Peters tim.one@comcast.net
Mon, 12 May 2003 12:36:10 -0400


Update of /cvs-repository/Zope/lib/python/BTrees
In directory cvs.zope.org:/tmp/cvs-serv2912/lib/python/BTrees

Modified Files:
      Tag: Zope-2_6-branch
	BucketTemplate.c 
Log Message:
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.


=== Zope/lib/python/BTrees/BucketTemplate.c 1.47.10.3 => 1.47.10.4 ===
--- Zope/lib/python/BTrees/BucketTemplate.c:1.47.10.3	Fri Apr 18 14:03:18 2003
+++ Zope/lib/python/BTrees/BucketTemplate.c	Mon May 12 12:36:09 2003
@@ -454,7 +454,7 @@
 Mapping_update(PyObject *self, PyObject *args)
 {
   PyObject *seq=0, *o, *t, *v, *tb, *k, *items = NULL;
-  int i, ind;
+  int i;
 
   UNLESS(PyArg_ParseTuple(args, "|O:update", &seq)) return NULL;
 
@@ -490,16 +490,22 @@
 	  Py_XDECREF(tb);
 	  break;
 	}
-      ind = PyArg_ParseTuple(o, "OO;items must be 2-item tuples", &k, &v);
-      if (ind)
-	ind = PyObject_SetItem(self, k, v);
-      else
-	ind = -1;
-      Py_DECREF(o);
-      if (ind < 0) {
-        PyErr_SetString(PyExc_TypeError,"Sequence must contain 2-item tuples");
-        goto err;
+
+      if (!PyTuple_Check(o) || PyTuple_GET_SIZE(o) != 2)
+        {
+	  Py_DECREF(o);
+	  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);