constrain tp_compare() to return -1, 0, or 1
This commit is contained in:
parent
cd89c39c51
commit
0161aabf5d
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue