[Zodb-checkins] CVS: ZODB3/ExtensionClass/src - Missing.c:1.19

Jeremy Hylton jeremy at zope.com
Fri May 9 17:57:11 EDT 2003


Update of /cvs-repository/ZODB3/ExtensionClass/src
In directory cvs.zope.org:/tmp/cvs-serv16104

Modified Files:
	Missing.c 
Log Message:
Real fix for the coercion problem.


=== ZODB3/ExtensionClass/src/Missing.c 1.18 => 1.19 ===
--- ZODB3/ExtensionClass/src/Missing.c:1.18	Fri May  9 15:59:31 2003
+++ ZODB3/ExtensionClass/src/Missing.c	Fri May  9 16:57:10 2003
@@ -78,14 +78,19 @@
   return 0;
 }
 
-/* XXX Why does this type offer to corece at all? */
+/* coerce should return two values of the same type.
+
+   We violate that contract in a controlled way, by always coercing
+   the other object to Py_None.  We are guaranteed that our tp_compare
+   will be called because Py_None does not define a tp_compare.
+*/
+
 static int
 Missing_coerce(PyObject **pv, PyObject **pw)
 {
-    if (!(*pw)->ob_type->tp_as_number)
-	return 1;
     Py_INCREF(*pv);
-    Py_INCREF(*pw);
+    Py_INCREF(Py_None);
+    *pw = Py_None;
     return 0;
 }
 
@@ -221,10 +226,16 @@
   return self;
 }
 
+/* All Missing objects are equal to each other, but we have
+   specially arranged for Py_None to be passed as m2 via
+   Missing_coerce().  So be prepared for Py_None where
+   a Missing is expected.
+*/
+
 static int
 Missing_cmp(Missing *m1, Missing *m2)
 {
-  return m1->ob_type != m2->ob_type ;
+    return Py_None == (PyObject *)m2;
 }
 
 static PyExtensionClass MissingType = {
@@ -296,3 +307,4 @@
   PyDict_SetItemString(d, "V", theValue); 
   PyDict_SetItemString(d, "MV", theValue); 
 }
+ 




More information about the Zodb-checkins mailing list