constrain tp_compare() to return -1, 0, or 1

This commit is contained in:
David Rose 2006-10-13 21:14:15 +00:00
parent cd89c39c51
commit 0161aabf5d
1 changed files with 9 additions and 1 deletions

View File

@ -490,7 +490,15 @@ int DTOOL_PyObject_Compare(PyObject *v1, PyObject *v2)
{
int answer = PyInt_AsLong(res);
Py_DECREF(res);
return answer;
// Python really wants us to return strictly -1, 0, or 1.
if (answer < 0) {
return -1;
} else if (answer > 0) {
return 1;
} else {
return 0;
}
}
if(res != NULL)
Py_DECREF(res);