Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1ce3f84

Browse files
committed
Issue #19437: Fix convert_op_cmp() of decimal.Decimal rich comparator, handle
PyObject_IsInstance() failure
1 parent 6decccd commit 1ce3f84

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

Modules/_decimal/_decimal.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3009,18 +3009,25 @@ convert_op_cmp(PyObject **vcmp, PyObject **wcmp, PyObject *v, PyObject *w,
30093009
*wcmp = Py_NotImplemented;
30103010
}
30113011
}
3012-
else if (PyObject_IsInstance(w, Rational)) {
3013-
*wcmp = numerator_as_decimal(w, context);
3014-
if (*wcmp && !mpd_isspecial(MPD(v))) {
3015-
*vcmp = multiply_by_denominator(v, w, context);
3016-
if (*vcmp == NULL) {
3017-
Py_CLEAR(*wcmp);
3012+
else {
3013+
int is_instance = PyObject_IsInstance(w, Rational);
3014+
if (is_instance < 0) {
3015+
*wcmp = NULL;
3016+
return 0;
3017+
}
3018+
if (is_instance) {
3019+
*wcmp = numerator_as_decimal(w, context);
3020+
if (*wcmp && !mpd_isspecial(MPD(v))) {
3021+
*vcmp = multiply_by_denominator(v, w, context);
3022+
if (*vcmp == NULL) {
3023+
Py_CLEAR(*wcmp);
3024+
}
30183025
}
30193026
}
3020-
}
3021-
else {
3022-
Py_INCREF(Py_NotImplemented);
3023-
*wcmp = Py_NotImplemented;
3027+
else {
3028+
Py_INCREF(Py_NotImplemented);
3029+
*wcmp = Py_NotImplemented;
3030+
}
30243031
}
30253032

30263033
if (*wcmp == NULL || *wcmp == Py_NotImplemented) {

0 commit comments

Comments
 (0)