[Zodb-checkins] CVS: Zope/lib/python/BTrees - BTreeTemplate.c:1.30 BucketTemplate.c:1.30 Maintainer.txt:1.3 MergeTemplate.c:1.10 SetOpTemplate.c:1.14 _fsBTree.c:1.3 intkeymacros.h:1.8 objectkeymacros.h:1.3

Toby Dickenson tdickenson@geminidataloggers.com
Fri, 31 May 2002 05:41:10 -0400


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

Modified Files:
	BTreeTemplate.c BucketTemplate.c Maintainer.txt 
	MergeTemplate.c SetOpTemplate.c _fsBTree.c intkeymacros.h 
	objectkeymacros.h 
Log Message:
long overdue merge of toby-cmp-error-branch. btrees no longer ignore exceptions raised by the key comparison function

=== Zope/lib/python/BTrees/BTreeTemplate.c 1.29 => 1.30 ===
       for (min=0, max=self->len, i=max/2; max-min > 1; i=(min+max)/2)
         {
-          cmp=TEST_KEY(self->data[i].key, key);
+          TEST_KEY_SET_OR(cmp, self->data[i].key, key) return NULL;
           if (cmp < 0) min=i;
           else if (cmp == 0)
             {
@@ -360,7 +360,7 @@
   for (min=0, max=self->len, i=max/2; max-min > 1; i=(max+min)/2)
     {
       d=self->data+i;
-      cmp=TEST_KEY(d->key, key);
+      TEST_KEY_SET_OR(cmp, d->key, key) return -1;
       if (cmp < 0) min=i;
       else if (cmp==0)
 	{
@@ -838,7 +838,7 @@
   
   for (min=0, max=self->len, i=max/2; max-min > 1; i=(min+max)/2)
     {
-      cmp=TEST_KEY(self->data[i].key, key);
+      TEST_KEY_SET_OR(cmp, self->data[i].key, key) return -1;
       if (cmp < 0) min=i;
       else if (cmp == 0)
 	{


=== Zope/lib/python/BTrees/BucketTemplate.c 1.29 => 1.30 ===
   for (min=0, max=self->len, i=max/2, l=max; i != l; l=i, i=(min+max)/2)
     {
-      cmp=TEST_KEY(self->keys[i], key);
+      TEST_KEY_SET_OR(cmp, self->keys[i], key) return NULL;
       if (PyErr_Occurred()) goto err;
 
       if (cmp < 0) min=i;
@@ -137,7 +137,8 @@
 
   for (min=0, max=l=self->len, i=max/2; i != l; l=i, i=(min+max)/2)
     {
-      if ((cmp=TEST_KEY(self->keys[i], key)) < 0) min=i;
+      TEST_KEY_SET_OR(cmp, self->keys[i], key) return -1;
+      if (cmp < 0) min=i;
       else if (cmp==0)
 	{
 	  if (v)			/* Assign value to key */
@@ -441,7 +442,7 @@
 
   for (min=0, max=self->len, i=max/2, l=max; i != l; l=i, i=(min+max)/2) 
     {
-      cmp=TEST_KEY(self->keys[i], key);
+      TEST_KEY_SET_OR(cmp, self->keys[i], key) return -1;
       if (cmp < 0)
 	min=i;
       else if (cmp == 0)


=== Zope/lib/python/BTrees/Maintainer.txt 1.2 => 1.3 ===
 btree node.  Someday this will be tunable on BTree instances.
 
-
 Macros for Keys
 
 KEY_TYPE
@@ -42,12 +41,17 @@
 non-zero for true).  When it returns false, its caller should probably
 set a TypeError exception.
 
-TEST_KEY(K, T)
+TEST_KEY_SET_OR(V, K, T) 
 Like Python's cmp().  Compares K(ey) to T(arget), where K & T are C
-data values of type KEY_TYPE).  Return an int
+data values of type KEY_TYPE).
    < 0 if K < T
   == 0 if K == T
    > 0 if K > T
+The value is assigned to V. This macro acts like an 'if',
+where the following statement is executed only if a Python exception
+has been raised because the values could not be compared.
+
+
 
 DECREF_KEY(K)
 K is a value of KEY_TYPE.  If KEY_TYPE is a flavor of PyObject*, write
@@ -130,4 +134,4 @@
 The value doesn't matter.  If defined, SetOpTemplate.c compiles
 code for a multiunion() function (compute a union of many input sets
 at high speed).  This currently makes sense only for II sets, so
-only _IIBTree.c defines it.
\ No newline at end of file
+only _IIBTree.c defines it.


=== Zope/lib/python/BTrees/MergeTemplate.c 1.9 => 1.10 ===
   while (i1.position >= 0 && i2.position >= 0 && i3.position >= 0)
     {
-      cmp12=TEST_KEY(i1.key, i2.key);
-      cmp13=TEST_KEY(i1.key, i3.key);
+      TEST_KEY_SET_OR(cmp12, i1.key, i2.key) goto err;
+      TEST_KEY_SET_OR(cmp13, i1.key, i3.key) goto err;
       if (cmp12==0)
         {
           if (cmp13==0)
@@ -142,7 +142,7 @@
         }
       else
         {                       /* Both keys changed */
-          cmp23=TEST_KEY(i2.key, i3.key);
+          TEST_KEY_SET_OR(cmp23, i2.key, i3.key) goto err;
           if (cmp23==0)
             {                   /* dualing inserts or deletes */
               merge_error(i1.position, i2.position, i3.position, 4);
@@ -176,7 +176,7 @@
 
   while (i2.position >= 0 && i3.position >= 0)
     {                           /* New inserts */
-      cmp23=TEST_KEY(i2.key, i3.key);
+      TEST_KEY_SET_OR(cmp23, i2.key, i3.key) goto err;
       if (cmp23==0)
         {                       /* dualing inserts */
           merge_error(i1.position, i2.position, i3.position, 6);
@@ -196,7 +196,7 @@
 
   while (i1.position >= 0 && i2.position >= 0)
     {                           /* deleting i3 */
-      cmp12=TEST_KEY(i1.key, i2.key);
+      TEST_KEY_SET_OR(cmp12, i1.key, i2.key) goto err;
       if (cmp12 > 0)
         {                       /* insert i2 */
           if (merge_output(r, &i2, mapping) < 0) goto err;
@@ -216,7 +216,7 @@
 
   while (i1.position >= 0 && i3.position >= 0)
     {                           /* deleting i2 */
-      cmp13=TEST_KEY(i1.key, i3.key);
+      TEST_KEY_SET_OR(cmp13, i1.key, i3.key) goto err;
       if (cmp13 > 0)
         {                       /* insert i3 */
           if (merge_output(r, &i3, mapping) < 0) goto err;


=== Zope/lib/python/BTrees/SetOpTemplate.c 1.13 => 1.14 ===
   while (i1.position >= 0 && i2.position >= 0)
     {
-      cmp=TEST_KEY(i1.key, i2.key);
+      TEST_KEY_SET_OR(cmp, i1.key, i2.key) return NULL;
       if(cmp < 0)
 	{
 	  if(c1)


=== Zope/lib/python/BTrees/_fsBTree.c 1.2 => 1.3 ===
 #define KEY_TYPE char2
 #define KEY_CHECK(K) (PyString_Check(K) && PyString_GET_SIZE(K)==2)
-#define TEST_KEY(K, T) ((*(K) < *(T) || (*(K) == *(T) && (K)[1] < (T)[1])) ? -1 : ((*(K) == *(T) && (K)[1] == (T)[1]) ? 0 : 1))
+#define TEST_KEY_SET_OR(V, K, T) if ( ( (V) = ((*(K) < *(T) || (*(K) == *(T) && (K)[1] < (T)[1])) ? -1 : ((*(K) == *(T) && (K)[1] == (T)[1]) ? 0 : 1)) ), 0 )
 #define DECREF_KEY(KEY)
 #define INCREF_KEY(k)
 #define COPY_KEY(KEY, E) (*(KEY)=*(E), (KEY)[1]=(E)[1])


=== Zope/lib/python/BTrees/intkeymacros.h 1.7 => 1.8 ===
 #define KEY_TYPE int
 #define KEY_CHECK PyInt_Check
-#define TEST_KEY(K, T) (((K) < (T)) ? -1 : (((K) > (T)) ? 1: 0)) 
+#define TEST_KEY_SET_OR(V, K, T) if ( ( (V) = (((K) < (T)) ? -1 : (((K) > (T)) ? 1: 0)) ) , 0 )
 #define DECREF_KEY(KEY)
 #define INCREF_KEY(k)
 #define COPY_KEY(KEY, E) (KEY=(E))


=== Zope/lib/python/BTrees/objectkeymacros.h 1.2 => 1.3 ===
 #define KEY_TYPE PyObject *
-#define TEST_KEY(KEY, TARGET) PyObject_Compare((KEY),(TARGET))
+#define TEST_KEY_SET_OR(V, KEY, TARGET) if ( ( (V) = PyObject_Compare((KEY),(TARGET)) ), PyErr_Occurred() )
 #define INCREF_KEY(k) Py_INCREF(k)
 #define DECREF_KEY(KEY) Py_DECREF(KEY)
 #define COPY_KEY(KEY, E) KEY=(E)