Browse Source

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

David Rose 19 years ago
parent
commit
0161aabf5d
1 changed files with 9 additions and 1 deletions
  1. 9 1
      dtool/src/interrogatedb/py_panda.cxx

+ 9 - 1
dtool/src/interrogatedb/py_panda.cxx

@@ -490,7 +490,15 @@ int DTOOL_PyObject_Compare(PyObject *v1, PyObject *v2)
         {
         {
             int answer = PyInt_AsLong(res);
             int answer = PyInt_AsLong(res);
             Py_DECREF(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)
         if(res != NULL)
             Py_DECREF(res);
             Py_DECREF(res);