[Zope-Checkins] CVS: Zope3/lib/python/Persistence/BTrees - BTreeTemplate.c:1.1.2.20 BucketTemplate.c:1.1.2.19 Maintainer.txt:1.1.2.3 _fsBTree.c:1.1.2.3 intkeymacros.h:1.1.2.4 intvaluemacros.h:1.1.2.2 objectkeymacros.h:1.1.2.3 objectvaluemacros.h:1.1.2.2

Tim Peters tim.one@comcast.net
Thu, 6 Jun 2002 15:24:05 -0400


Update of /cvs-repository/Zope3/lib/python/Persistence/BTrees
In directory cvs.zope.org:/tmp/cvs-serv6405

Modified Files:
      Tag: Zope-3x-branch
	BTreeTemplate.c BucketTemplate.c Maintainer.txt _fsBTree.c 
	intkeymacros.h intvaluemacros.h objectkeymacros.h 
	objectvaluemacros.h 
Log Message:
Replaced funky KEY_IF_OBJECT and VALUE_IF_OBJECT macros with straight
defined/undefined KEY_TYPE_IS_PYOBJECT and VALUE_TYPE_IS_PYOBJECT macros.
This also allows to convert some runtime tests into compile-time decisions.


=== Zope3/lib/python/Persistence/BTrees/BTreeTemplate.c 1.1.2.19 => 1.1.2.20 ===
 
     len = self->len;
-    if (KEY_IF_OBJECT(self) != NULL) {
-        /* Keys are Python objects so need to be traversed.  Note that the
-         * key 0 slot is unused and should not be traversed.
-         */
-        for (i = 1; i < len; i++)
-	    VISIT(self->data[i].key);
-    }
+#ifdef KEY_TYPE_IS_PYOBJECT
+    /* Keys are Python objects so need to be traversed.  Note that the
+     * key 0 slot is unused and should not be traversed.
+     */
+    for (i = 1; i < len; i++)
+        VISIT(self->data[i].key);
+#endif
 
     /* Children are always pointers, and child 0 is legit. */
     for (i = 0; i < len; i++)


=== Zope3/lib/python/Persistence/BTrees/BucketTemplate.c 1.1.2.18 => 1.1.2.19 ===
 
     len = self->len;
-    if (KEY_IF_OBJECT(self) != NULL) {
-        /* Keys are Python objects so need to be traversed. */
-        for (i = 0; i < len; i++)
-            VISIT(self->keys[i]);
-    }
+    (void)i;    /* if neither keys nor values are PyObject*, "i" is otherwise
+                   unreferenced and we get a nuisance compiler wng */
+#ifdef KEY_TYPE_IS_PYOBJECT
+    /* Keys are Python objects so need to be traversed. */
+    for (i = 0; i < len; i++)
+        VISIT(self->keys[i]);
+#endif
 
-    if (self->values != NULL && VALUE_IF_OBJECT(self) != NULL) {
+#ifdef VALUE_TYPE_IS_PYOBJECT
+    if (self->values != NULL) {
         /* self->values exists (this is a mapping bucket, not a set bucket),
          * and are Python objects, so need to be traversed. */
         for (i = 0; i < len; i++)
             VISIT(self->values[i]);
     }
+#endif
 
     VISIT(self->next);
 


=== Zope3/lib/python/Persistence/BTrees/Maintainer.txt 1.1.2.2 => 1.1.2.3 ===
 The C type declaration for keys (e.g., int or PyObject*).
 
+KEY_TYPE_IS_PYOBJECT
+Define if KEY_TYPE is a PyObject*, else undef.
+
 KEY_CHECK(K)
 Tests whether the PyObject* K can be converted to the (C) key type
 (KEY_TYPE).  The macro should return a boolean (zero for false,
@@ -79,16 +82,15 @@
 done (for example, KEY_CHECK(ARG) returns false), set a Python error
 and set status to 0.  If there is no error, leave status alone.
 
-KEY_IF_OBJECT(K) K
-If KEY_TYPE is a PyObject*, return K (the argument), else expand to
-NULL.
-
 
 Macros for Values
 
 VALUE_TYPE
 The C type declaration for values (e.g., int or PyObject*).
 
+VALUE_TYPE_IS_PYOBJECT
+Define if VALUE_TYPE is a PyObject*, else undef.
+
 TEST_VALUE(X, Y)
 Like Python's cmp().  Compares X to Y, where X & Y are C values of
 type VALUE_TYPE.  The macro returns an int, with value
@@ -117,10 +119,6 @@
 Normalize the value, V, using the parameter MIN.  This is almost
 certainly a YAGNI.  It is a no op for most types. For integers, V is
 replaced by V/MIN only if MIN > 0.
-
-VALUE_IF_OBJECT(V)
-If VALUE_TYPE is a PyObject*, return V (the argument), else expand to
-NULL.
 
 
 Macros for Set Operations


=== Zope3/lib/python/Persistence/BTrees/_fsBTree.c 1.1.2.2 => 1.1.2.3 ===
 #define KEYMACROS_H "$Id$\n"
 #define KEY_TYPE char2
+#undef KEY_TYPE_IS_PYOBJECT
 #define KEY_CHECK(K) (PyString_Check(K) && PyString_GET_SIZE(K)==2)
 #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)
@@ -38,11 +39,11 @@
   if (KEY_CHECK(ARG)) memcpy(TARGET, PyString_AS_STRING(ARG), 2); else { \
       PyErr_SetString(PyExc_TypeError, "expected two-character string key"); \
       (STATUS)=0; } 
-#define KEY_IF_OBJECT(K) NULL
 
 /*#include "intvaluemacros.h"*/
 #define VALUEMACROS_H "$Id$\n"
 #define VALUE_TYPE char6
+#undef VALUE_TYPE_IS_PYOBJECT
 #define TEST_VALUE(K, T) strncmp(K,T,6)
 #define DECLARE_VALUE(NAME) VALUE_TYPE NAME
 #define DECREF_VALUE(k)
@@ -54,8 +55,6 @@
       memcpy(TARGET, PyString_AS_STRING(ARG), 6); else { \
       PyErr_SetString(PyExc_TypeError, "expected six-character string key"); \
       (STATUS)=0; } 
-#define KEY_IF_OBJECT(K) NULL
-#define VALUE_IF_OBJECT(V) NULL
   
 #define NORMALIZE_VALUE(V, MIN)
 #include "BTreeModuleTemplate.c"


=== Zope3/lib/python/Persistence/BTrees/intkeymacros.h 1.1.2.3 => 1.1.2.4 ===
 
 #define KEY_TYPE int
+#undef KEY_TYPE_IS_PYOBJECT
 #define KEY_CHECK PyInt_Check
 #define TEST_KEY_SET_OR(V, K, T) if ( ( (V) = (((K) < (T)) ? -1 : (((K) > (T)) ? 1: 0)) ) , 0 )
 #define DECREF_KEY(KEY)
@@ -16,5 +17,4 @@
 		     (ARG)->ob_type->tp_name); \
 	(STATUS) = 0; \
 	(TARGET) = 0; \
-    } 
-#define KEY_IF_OBJECT(K) NULL
+    }


=== Zope3/lib/python/Persistence/BTrees/intvaluemacros.h 1.1.2.1 => 1.1.2.2 ===
 
 #define VALUE_TYPE int
-#define TEST_VALUE(K, T) (((K) < (T)) ? -1 : (((K) > (T)) ? 1: 0)) 
+#undef VALUE_TYPE_IS_PYOBJECT
+
+#define TEST_VALUE(K, T) (((K) < (T)) ? -1 : (((K) > (T)) ? 1: 0))
 #define VALUE_SAME(VALUE, TARGET) ( (VALUE) == (TARGET) )
 #define DECLARE_VALUE(NAME) VALUE_TYPE NAME
 #define VALUE_PARSE "i"
 #define DECREF_VALUE(k)
 #define INCREF_VALUE(k)
 #define COPY_VALUE(V, E) (V=(E))
-#define COPY_VALUE_TO_OBJECT(O, K) O=PyInt_FromLong(K) 
+#define COPY_VALUE_TO_OBJECT(O, K) O=PyInt_FromLong(K)
 #define COPY_VALUE_FROM_ARG(TARGET, ARG, STATUS) \
   if (PyInt_Check(ARG)) TARGET=PyInt_AsLong(ARG); else { \
       PyErr_SetString(PyExc_TypeError, "expected integer value"); \
-      (STATUS)=0; (TARGET)=0; } 
-  
+      (STATUS)=0; (TARGET)=0; }
+
 #define NORMALIZE_VALUE(V, MIN) ((MIN) > 0) ? ((V)/=(MIN)) : 0
 
 #define MERGE_DEFAULT 1
 #define MERGE(O1, w1, O2, w2) ((O1)*(w1)+(O2)*(w2))
 #define MERGE_WEIGHT(O, w) ((O)*(w))
-
-#define VALUE_IF_OBJECT(V) NULL


=== Zope3/lib/python/Persistence/BTrees/objectkeymacros.h 1.1.2.2 => 1.1.2.3 ===
 #define KEY_TYPE PyObject *
+#define KEY_TYPE_IS_PYOBJECT
 #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)
 #define COPY_KEY_TO_OBJECT(O, K) O=(K); Py_INCREF(O)
 #define COPY_KEY_FROM_ARG(TARGET, ARG, S) TARGET=(ARG)
-#define KEY_IF_OBJECT(K) K


=== Zope3/lib/python/Persistence/BTrees/objectvaluemacros.h 1.1.2.1 => 1.1.2.2 ===
 
 #define VALUE_TYPE PyObject *
+#define VALUE_TYPE_IS_PYOBJECT
 #define TEST_VALUE(VALUE, TARGET) PyObject_Compare((VALUE),(TARGET))
 #define DECLARE_VALUE(NAME) VALUE_TYPE NAME
 #define INCREF_VALUE(k) Py_INCREF(k)
@@ -10,4 +11,3 @@
 #define COPY_VALUE_TO_OBJECT(O, K) O=(K); Py_INCREF(O)
 #define COPY_VALUE_FROM_ARG(TARGET, ARG, S) TARGET=(ARG)
 #define NORMALIZE_VALUE(V, MIN) Py_INCREF(V)
-#define VALUE_IF_OBJECT(V) V