Skip to content

Commit b09c4cf

Browse files
committed
Fix cell_richcompare in the case of NULLs.
Avoid the type error and return results as before.
1 parent 10dba24 commit b09c4cf

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

Objects/cellobject.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ cell_dealloc(PyObject *self)
8282
PyObject_GC_Del(op);
8383
}
8484

85+
static PyObject *
86+
cell_compare_impl(PyObject *a, PyObject *b, int op)
87+
{
88+
if (a != NULL && b != NULL) {
89+
return PyObject_RichCompare(a, b, op);
90+
}
91+
else {
92+
Py_RETURN_RICHCOMPARE(b == NULL, a == NULL, op);
93+
}
94+
}
95+
8596
static PyObject *
8697
cell_richcompare(PyObject *a, PyObject *b, int op)
8798
{
@@ -96,15 +107,10 @@ cell_richcompare(PyObject *a, PyObject *b, int op)
96107
PyObject *b_ref = PyCell_GetRef((PyCellObject *)b);
97108

98109
/* compare cells by contents; empty cells come before anything else */
99-
if (a_ref == NULL) {
100-
a_ref = Py_None;
101-
}
102-
if (b_ref == NULL) {
103-
b_ref = Py_None;
104-
}
105-
PyObject *res = PyObject_RichCompare(a_ref, b_ref, op);
106-
Py_DECREF(a_ref);
107-
Py_DECREF(b_ref);
110+
PyObject *res = cell_compare_impl(a_ref, b_ref, op);
111+
112+
Py_XDECREF(a_ref);
113+
Py_XDECREF(b_ref);
108114
return res;
109115
}
110116

0 commit comments

Comments
 (0)