Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyErr_NoMemory when PyArray_Zeros fails to initialize #5492

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion numpy/fft/fftpack_litemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ fftpack_rfftf(PyObject *NPY_UNUSED(self), PyObject *args)
PyObject *op1, *op2;
PyArrayObject *data, *ret;
PyArray_Descr *descr;
double *wsave, *dptr, *rptr;
double *wsave = NULL, *dptr, *rptr;
npy_intp nsave;
int npts, nrepeats, i, rstep;

Expand All @@ -166,6 +166,10 @@ fftpack_rfftf(PyObject *NPY_UNUSED(self), PyObject *args)
PyArray_DIMS(data)[PyArray_NDIM(data) - 1] = npts/2 + 1;
ret = (PyArrayObject *)PyArray_Zeros(PyArray_NDIM(data),
PyArray_DIMS(data), PyArray_DescrFromType(NPY_CDOUBLE), 0);
if (ret == NULL) {
PyErr_NoMemory();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have wrongly advised you here, the exception is already raised by PyArray_Zeros so this is not necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so if I remove PyErr_NoMemory it will still be flagged as an out-of-memory condition?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes PyArray_Zeros is a PyObject returning function, convention is that when these return NULL an exception is already set and just needs to be bubbled up to python, in this case it is raised all the way down in PyArray_NewFromDescr_int which does the main array creation and memory allocation

goto fail;
}
PyArray_DIMS(data)[PyArray_NDIM(data) - 1] = npts;
rstep = PyArray_DIM(ret, PyArray_NDIM(ret) - 1)*2;

Expand Down