summaryrefslogtreecommitdiffstats
path: root/Objects/classobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-05-23 00:06:51 (GMT)
committerGuido van Rossum <guido@python.org>1997-05-23 00:06:51 (GMT)
commitc8b6df90045a3f419e6fab272d93ad4159e54ccc (patch)
tree20cb4b6f0ba2718577079198780d5fc3852e4a70 /Objects/classobject.c
parent5b2121b25fc6a50fe229fe25ef6be8a2f883d1f4 (diff)
downloadcpython-c8b6df90045a3f419e6fab272d93ad4159e54ccc.zip
cpython-c8b6df90045a3f419e6fab272d93ad4159e54ccc.tar.gz
cpython-c8b6df90045a3f419e6fab272d93ad4159e54ccc.tar.bz2
PyObject_Compare can raise an exception now.
Diffstat (limited to 'Objects/classobject.c')
-rw-r--r--Objects/classobject.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/Objects/classobject.c b/Objects/classobject.c
index 4ff34be..749a06a0 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -349,7 +349,6 @@ instance_dealloc(inst)
PyObject *f, *t, *v, *tb;
PyErr_Fetch(&t, &v, &tb);
f = PySys_GetObject("stderr");
- PyErr_Clear();
if (f != NULL) {
PyFile_WriteString("Exception ", f);
if (t) {
@@ -565,9 +564,13 @@ instance_compare(inst, other)
PyObject *result;
long outcome;
result = instance_compare1(inst, other);
- if (result == NULL || !PyInt_Check(result)) {
- PyErr_Clear();
- return (inst < other) ? -1 : 1;
+ if (result == NULL)
+ return -1;
+ if (!PyInt_Check(result)) {
+ Py_DECREF(result);
+ PyErr_SetString(PyExc_TypeError,
+ "comparison did not return an int");
+ return -1;
}
outcome = PyInt_AsLong(result);
Py_DECREF(result);
@@ -899,6 +902,11 @@ PyInstance_DoBinOp(v, w, opname, ropname, thisfunc)
return result;
if (halfbinop(w, v, ropname, &result, thisfunc, 1) <= 0)
return result;
+ /* Sigh -- special case for comnparisons */
+ if (strcmp(opname, "__cmp__") == 0) {
+ long c = (v < w) ? -1 : (v > w) ? 1 : 0;
+ return PyInt_FromLong(c);
+ }
sprintf(buf, "%s nor %s defined for these operands", opname, ropname);
PyErr_SetString(PyExc_TypeError, buf);
return NULL;