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

Tim Peters tim.one@comcast.net
Sun, 11 May 2003 20:36:17 -0400


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

Modified Files:
	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.53 => 1.54 ===
--- Zope/lib/python/BTrees/BucketTemplate.c:1.53	Wed Apr 16 12:01:10 2003
+++ Zope/lib/python/BTrees/BucketTemplate.c	Sun May 11 20:36:17 2003
@@ -461,7 +461,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;
 
@@ -497,16 +497,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);