Commit d305e3be authored by Victor Stinner's avatar Victor Stinner

Issue #19437: Fix convert_op_cmp() of decimal.Decimal rich comparator, handle

PyObject_IsInstance() failure
parent 16866e4e
...@@ -3009,18 +3009,25 @@ convert_op_cmp(PyObject **vcmp, PyObject **wcmp, PyObject *v, PyObject *w, ...@@ -3009,18 +3009,25 @@ convert_op_cmp(PyObject **vcmp, PyObject **wcmp, PyObject *v, PyObject *w,
*wcmp = Py_NotImplemented; *wcmp = Py_NotImplemented;
} }
} }
else if (PyObject_IsInstance(w, Rational)) { else {
*wcmp = numerator_as_decimal(w, context); int is_instance = PyObject_IsInstance(w, Rational);
if (*wcmp && !mpd_isspecial(MPD(v))) { if (is_instance < 0) {
*vcmp = multiply_by_denominator(v, w, context); *wcmp = NULL;
if (*vcmp == NULL) { return 0;
Py_CLEAR(*wcmp); }
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 {
else { Py_INCREF(Py_NotImplemented);
Py_INCREF(Py_NotImplemented); *wcmp = Py_NotImplemented;
*wcmp = Py_NotImplemented; }
} }
if (*wcmp == NULL || *wcmp == Py_NotImplemented) { if (*wcmp == NULL || *wcmp == Py_NotImplemented) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment