diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-10-29 18:26:11 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-10-29 18:26:11 (GMT) |
commit | a992e11fe36b8461d3064a7cc37552a44c7dd022 (patch) | |
tree | 3dff17e9ede275989dfcb512e3763576f19715be /Modules/_decimal/_decimal.c | |
parent | 7165d8b9ba7df402fb167ff20dc6d1a35e7386ed (diff) | |
download | cpython-a992e11fe36b8461d3064a7cc37552a44c7dd022.zip cpython-a992e11fe36b8461d3064a7cc37552a44c7dd022.tar.gz cpython-a992e11fe36b8461d3064a7cc37552a44c7dd022.tar.bz2 |
Issue #19437: Fix convert_op_cmp() of decimal.Decimal rich comparator, handle
PyObject_IsInstance() failure
Diffstat (limited to 'Modules/_decimal/_decimal.c')
-rw-r--r-- | Modules/_decimal/_decimal.c | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c index d3e3940..628b2f7 100644 --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -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) { |