Skip to content

Commit e23518f

Browse files
authored
gh-136017: avoid decref in rich compare for bool objects (#136018)
1 parent 07183eb commit e23518f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Objects/object.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,11 +1131,14 @@ PyObject_RichCompareBool(PyObject *v, PyObject *w, int op)
11311131
res = PyObject_RichCompare(v, w, op);
11321132
if (res == NULL)
11331133
return -1;
1134-
if (PyBool_Check(res))
1134+
if (PyBool_Check(res)) {
11351135
ok = (res == Py_True);
1136-
else
1136+
assert(_Py_IsImmortal(res));
1137+
}
1138+
else {
11371139
ok = PyObject_IsTrue(res);
1138-
Py_DECREF(res);
1140+
Py_DECREF(res);
1141+
}
11391142
return ok;
11401143
}
11411144

0 commit comments

Comments
 (0)