Skip to content

Commit a6a9a9a

Browse files
authored
Merge pull request numpy#24178 from ngoldbaum/setflags-error-handling
BUG: PyObject_IsTrue and PyObject_Not error handling in setflags
2 parents cd0bd07 + 185915b commit a6a9a9a

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

numpy/core/src/multiarray/methods.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2737,7 +2737,11 @@ array_setflags(PyArrayObject *self, PyObject *args, PyObject *kwds)
27372737
return NULL;
27382738

27392739
if (align_flag != Py_None) {
2740-
if (PyObject_Not(align_flag)) {
2740+
int isnot = PyObject_Not(align_flag);
2741+
if (isnot == -1) {
2742+
return NULL;
2743+
}
2744+
if (isnot) {
27412745
PyArray_CLEARFLAGS(self, NPY_ARRAY_ALIGNED);
27422746
}
27432747
else if (IsAligned(self)) {
@@ -2752,7 +2756,11 @@ array_setflags(PyArrayObject *self, PyObject *args, PyObject *kwds)
27522756
}
27532757

27542758
if (uic != Py_None) {
2755-
if (PyObject_IsTrue(uic)) {
2759+
int istrue = PyObject_IsTrue(uic);
2760+
if (istrue == -1) {
2761+
return NULL;
2762+
}
2763+
if (istrue) {
27562764
fa->flags = flagback;
27572765
PyErr_SetString(PyExc_ValueError,
27582766
"cannot set WRITEBACKIFCOPY "
@@ -2767,7 +2775,11 @@ array_setflags(PyArrayObject *self, PyObject *args, PyObject *kwds)
27672775
}
27682776

27692777
if (write_flag != Py_None) {
2770-
if (PyObject_IsTrue(write_flag)) {
2778+
int istrue = PyObject_IsTrue(write_flag);
2779+
if (istrue == -1) {
2780+
return NULL;
2781+
}
2782+
else if (istrue == 1) {
27712783
if (_IsWriteable(self)) {
27722784
/*
27732785
* _IsWritable (and PyArray_UpdateFlags) allows flipping this,

0 commit comments

Comments
 (0)