8000 BUG: Fixed crash in do_richcompare_on_scalars | Added complex check o… · numpy/numpy@e9a69eb · GitHub
[go: up one dir, main page]

Skip to content

Commit e9a69eb

Browse files
committed
BUG: Fixed crash in do_richcompare_on_scalars | Added complex check on fastpath
1 parent dc18734 commit e9a69eb

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

numpy/core/src/umath/scalarmath.c.src

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -637,16 +637,26 @@ do_richcompare_on_scalars(PyObject *self, PyObject *other, int cmp_op) {
637637
descr_from_basic_scalar(self, &self_descr);
638638
pyscalar_other = descr_from_basic_scalar(other, &other_descr);
639639

640-
if (NPY_LIKELY(pyscalar_other > 0)) {
641-
data_self = scalar_value(self, NULL);
642-
item_self = self_descr->f->getitem(data_self, NULL);
643-
644-
ret = PyObject_RichCompare(item_self, other, cmp_op);
645-
Py_DECREF(item_self);
640+
/* If either of the operands are complex AND the operator is not equality,
641+
* python's built-in richcompare cannot be used as it is not supported */
642+
if ((self_descr->type_num < NPY_CFLOAT &&
643+
(other_descr != NULL && other_descr->type_num < NPY_CFLOAT))
644+
|| (cmp_op == Py_EQ || cmp_op == Py_NE)) {
645+
if (NPY_LIKELY(pyscalar_other > 0)) {
646+
data_self = scalar_value(self, NULL);
647+
item_self = self_descr->f->getitem(data_self, NULL);
648+
649+
ret = PyObject_RichCompare(item_self, other, cmp_op);
650+
Py_DECREF(item_self);
646651

652+
}
653+
}
654+
if (NPY_LIKELY(self_descr != NULL)) {
655+
Py_DECREF(self_descr);
656+
}
657+
if (other_descr != NULL) {
658+
Py_DECREF(other_descr);
647659
}
648-
Py_DECREF(self_descr);
649-
Py_DECREF(other_descr);
650660

651661
return ret;
652662
}

0 commit comments

Comments
 (0)
0