[Zodb-checkins] CVS: Zope/lib/Components/ExtensionClass/src -
Missing.c:1.13.10.3
Jeremy Hylton
jeremy at zope.com
Fri May 9 17:59:36 EDT 2003
Update of /cvs-repository/Zope/lib/Components/ExtensionClass/src
In directory cvs.zope.org:/tmp/cvs-serv16571
Modified Files:
Tag: Zope-2_6-branch
Missing.c
Log Message:
Backport real fix for coercion bug.
=== Zope/lib/Components/ExtensionClass/src/Missing.c 1.13.10.2 => 1.13.10.3 ===
--- Zope/lib/Components/ExtensionClass/src/Missing.c:1.13.10.2 Fri May 9 16:03:02 2003
+++ Zope/lib/Components/ExtensionClass/src/Missing.c Fri May 9 16:59:35 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 = {
@@ -253,7 +264,7 @@
0L,0L,
"Represent totally unknown quantities\n"
"\n"
- "Missing values are used to represent numberic quantities that are\n"
+ "Missing values are used to represent numeric quantities that are\n"
"unknown. They support all mathematical operations except\n"
"conversions by returning themselves.\n",
METHOD_CHAIN(NULL)
@@ -295,65 +306,5 @@
PyDict_SetItemString(d, "Value", theValue);
PyDict_SetItemString(d, "V", theValue);
PyDict_SetItemString(d, "MV", theValue);
-
- /* Check for errors */
- if (PyErr_Occurred())
- Py_FatalError("can't initialize module Missing");
}
-
-/*****************************************************************************
-Revision Log:
-
- $Log$
- Revision 1.13.10.2 2003/05/09 20:03:02 jeremy
- Backport coercion bug fix.
-
- Revision 1.13.10.1 2002/11/13 16:40:01 jeremy
- Backport: Fix includes before Python.h.
-
- Revision 1.13 2002/06/10 22:48:46 jeremy
- Update ExtensionClass to ZPL 2.0.
-
- Revision 1.12 2002/01/25 15:34:06 gvanrossum
- Get rid of __version__, as Jim recommends. Use $ from docstring instead.
-
- Revision 1.11 2001/03/28 14:06:51 jeremy
- gcc -Wall cleanup
- - make function decls prototypes
- - remove unreferenced functions
-
- Revision 1.10 1999/08/25 20:15:29 jim
- Made getattr a bit pickler to prevent getting attributes like "%f5.3".
-
- Revision 1.9 1999/06/10 20:09:47 jim
- Updated to use new ExtensionClass destructor protocol.
-
- Revision 1.8 1998/11/17 19:54:33 jim
- new copyright.
-
- Revision 1.7 1997/10/03 14:43:27 jim
- Fixed comparison bug, again :-(
-
- Revision 1.6 1997/09/23 16:06:03 jim
- Added MV member.
-
- Revision 1.5 1997/09/23 15:17:12 jim
- Added cmp.
-
- Revision 1.4 1997/09/18 21:01:33 jim
- Added check to getattr to fail on methods that begin with underscore.
- Note that Missing really defeats testing from protocols by testing for
- attributes.
-
- Revision 1.3 1997/09/17 22:49:35 jim
- Fixed refcount bug.
- Added logic so: Missing.Value.spam() returns Missing.Value.
- Added logic to make Missing.Value picklable.
-
- Revision 1.2 1997/07/02 20:19:37 jim
- Got rid of unused macros and ErrorObject.
-
- Revision 1.1 1997/07/01 21:36:34 jim
-
-
-*****************************************************************************/
+
More information about the Zodb-checkins
mailing list