[Zope-Checkins] CVS: Zope2 - Acquisition.c:1.46.2.3

Jim Fulton jim@digicool.com
Wed, 21 Mar 2001 15:49:16 -0500 (EST)


Update of /cvs-repository/Zope2/lib/Components/ExtensionClass
In directory korak:/tmp/cvs-serv2721

Modified Files:
      Tag: zope-2_3-branch
	Acquisition.c 
Log Message:
Applied patch from Collector 2063 from randy@spoke.net that provides
acquisition wrappers with a sane __nonzero__.




--- Updated File Acquisition.c in package Zope2 --
--- Acquisition.c	2001/03/14 18:52:29	1.46.2.2
+++ Acquisition.c	2001/03/21 20:49:16	1.46.2.3
@@ -705,32 +705,7 @@
   long l;
   PyObject *r;
 
-  UNLESS(r=PyObject_GetAttr(OBJECT(self), py__len__))
-    {
-      /* Hm. Maybe we are being checked to see if we are true.
-	 
-	 Check to see if we have a __getitem__.  If we don't, then
-	 answer that we are true, otherwise raise an error.
-	 */
-      PyErr_Clear();
-      if ((r=PyObject_GetAttr(OBJECT(self), py__getitem__)))
-	{
-	  /* Hm, we have getitem, must be error */
-	  Py_DECREF(r);
-	  PyErr_SetObject(PyExc_AttributeError, py__len__);
-	  return -1;
-	}
-      PyErr_Clear();
-
-      /* Try nonzero */
-      UNLESS(r=PyObject_GetAttr(OBJECT(self), py__nonzero__))
-	{
-	  /* No nonzero, it's true :-) */
-	  PyErr_Clear();
-	  return 1;
-	}
-    }
-  
+  UNLESS(r=PyObject_GetAttr(OBJECT(self), py__len__)) return -1;
   UNLESS_ASSIGN(r,PyObject_CallObject(r,NULL)) return -1;
   l=PyInt_AsLong(r);
   Py_DECREF(r);
@@ -990,6 +965,31 @@
   return CallMethodO(OBJECT(self), py__hex__, NULL, NULL);
 }
 
+static int
+Wrapper_nonzero(Wrapper *self)
+{
+  long l;
+  PyObject *r;
+
+  UNLESS(r=PyObject_GetAttr(OBJECT(self), py__nonzero__))
+    {
+      PyErr_Clear();
+
+      /* Try len */
+      UNLESS(r=PyObject_GetAttr(OBJECT(self), py__len__))
+      {
+        /* No len, it's true :-) */
+        PyErr_Clear();
+        return 1;
+      }
+    }
+
+  UNLESS_ASSIGN(r,PyObject_CallObject(r,NULL)) return -1;
+  l=PyInt_AsLong(r);
+  Py_DECREF(r);
+  return l;
+}
+
 static PyNumberMethods Wrapper_as_number = {
 	(binaryfunc)Wrapper_add,	/*nb_add*/
 	(binaryfunc)Wrapper_sub,	/*nb_subtract*/
@@ -998,22 +998,22 @@
 	(binaryfunc)Wrapper_mod,	/*nb_remainder*/
 	(binaryfunc)Wrapper_divmod,	/*nb_divmod*/
 	(ternaryfunc)Wrapper_pow,	/*nb_power*/
-	(unaryfunc)Wrapper_neg,	/*nb_negative*/
-	(unaryfunc)Wrapper_pos,	/*nb_positive*/
-	(unaryfunc)Wrapper_abs,	/*nb_absolute*/
-	(inquiry)Wrapper_length,	/*nb_nonzero*/
+	(unaryfunc)Wrapper_neg,		/*nb_negative*/
+	(unaryfunc)Wrapper_pos,		/*nb_positive*/
+	(unaryfunc)Wrapper_abs,		/*nb_absolute*/
+	(inquiry)Wrapper_nonzero,	/*nb_nonzero*/
 	(unaryfunc)Wrapper_invert,	/*nb_invert*/
 	(binaryfunc)Wrapper_lshift,	/*nb_lshift*/
 	(binaryfunc)Wrapper_rshift,	/*nb_rshift*/
 	(binaryfunc)Wrapper_and,	/*nb_and*/
 	(binaryfunc)Wrapper_xor,	/*nb_xor*/
-	(binaryfunc)Wrapper_or,	/*nb_or*/
+	(binaryfunc)Wrapper_or,		/*nb_or*/
 	(coercion)Wrapper_coerce,	/*nb_coerce*/
-	(unaryfunc)Wrapper_int,	/*nb_int*/
+	(unaryfunc)Wrapper_int,		/*nb_int*/
 	(unaryfunc)Wrapper_long,	/*nb_long*/
 	(unaryfunc)Wrapper_float,	/*nb_float*/
-	(unaryfunc)Wrapper_oct,	/*nb_oct*/
-	(unaryfunc)Wrapper_hex,	/*nb_hex*/
+	(unaryfunc)Wrapper_oct,		/*nb_oct*/
+	(unaryfunc)Wrapper_hex,		/*nb_hex*/
 };