[Python-checkins] cpython (3.3): Issue #19437: Fix convert_op_cmp() of decimal.Decimal rich comparator, handle

stefan.krah python-checkins at python.org
Fri Nov 8 21:14:18 CET 2013


http://hg.python.org/cpython/rev/08c81db35959
changeset:   87015:08c81db35959
branch:      3.3
parent:      86989:9b9d188ed549
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Tue Oct 29 19:26:11 2013 +0100
summary:
  Issue #19437: Fix convert_op_cmp() of decimal.Decimal rich comparator, handle
PyObject_IsInstance() failure

files:
  Modules/_decimal/_decimal.c |  27 +++++++++++++++---------
  1 files changed, 17 insertions(+), 10 deletions(-)


diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c
--- a/Modules/_decimal/_decimal.c
+++ b/Modules/_decimal/_decimal.c
@@ -3009,18 +3009,25 @@
             *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) {

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list