]> granicus.if.org Git - python/commitdiff
Issue #19437: Fix convert_op_cmp() of decimal.Decimal rich comparator, handle
authorVictor Stinner <victor.stinner@gmail.com>
Tue, 29 Oct 2013 18:26:11 +0000 (19:26 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Tue, 29 Oct 2013 18:26:11 +0000 (19:26 +0100)
PyObject_IsInstance() failure

Modules/_decimal/_decimal.c

index d3e394041f642e3b4c415484683b8419094a4e42..628b2f784f91b9f4bc35ddf4f0eca82a49c3f75b 100644 (file)
@@ -3009,18 +3009,25 @@ convert_op_cmp(PyObject **vcmp, PyObject **wcmp, PyObject *v, PyObject *w,
             *wcmp = Py_NotImplemented;
         }
     }
-    else if (PyObject_IsInstance(w, Rational)) {
-        *wcmp = numerator_as_decimal(w, context);
-        if (*wcmp && !mpd_isspecial(MPD(v))) {
-            *vcmp = multiply_by_denominator(v, w, context);
-            if (*vcmp == NULL) {
-                Py_CLEAR(*wcmp);
+    else {
+        int is_instance = PyObject_IsInstance(w, Rational);
+        if (is_instance < 0) {
+            *wcmp = NULL;
+            return 0;
+        }
+        if (is_instance) {
+            *wcmp = numerator_as_decimal(w, context);
+            if (*wcmp && !mpd_isspecial(MPD(v))) {
+                *vcmp = multiply_by_denominator(v, w, context);
+                if (*vcmp == NULL) {
+                    Py_CLEAR(*wcmp);
+                }
             }
         }
-    }
-    else {
-        Py_INCREF(Py_NotImplemented);
-        *wcmp = Py_NotImplemented;
+        else {
+            Py_INCREF(Py_NotImplemented);
+            *wcmp = Py_NotImplemented;
+        }
     }
 
     if (*wcmp == NULL || *wcmp == Py_NotImplemented) {