Skip to content

BUG: duplicate message print if warning raises an exception #10257

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

Merged
merged 1 commit into from
Dec 25, 2017
Merged
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
16 changes: 2 additions & 14 deletions numpy/core/src/multiarray/arrayobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,22 +475,10 @@ array_dealloc(PyArrayObject *self)
"called.";
/* 2017-Nov-10 1.14 */
if (DEPRECATE(msg) < 0) {
/* dealloc must not raise an error, best effort try to write
/* dealloc cannot raise an error, best effort try to write
to stderr and clear the error
Copy link
Member

@eric-wieser eric-wieser Dec 22, 2017

Choose a reason for hiding this comment

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

I think you might need to actually clear the error before calling PyArray_ResolveWritebackIfCopy, in case the array is an object dtype, and PyArray_ResolveWritebackIfCopy causes refcounts to drop to zero which can run arbitrary python code

Copy link
Member

Choose a reason for hiding this comment

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

Although I suppose that's an unrelated fix

Copy link
Member Author

Choose a reason for hiding this comment

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

In the implementation of PyErr_WriteUnraisable it calls PyErr_Fetch which clears the error state

*/
PyObject * s;
#if PY_MAJOR_VERSION < 3
s = PyString_FromString(msg);
#else
s = PyUnicode_FromString(msg);
#endif
if (s) {
PyErr_WriteUnraisable(s);
Py_DECREF(s);
}
else {
PyErr_WriteUnraisable(Py_None);
}
PyErr_WriteUnraisable((PyObject *)&PyArray_Type);
}
retval = PyArray_ResolveWritebackIfCopy(self);
if (retval < 0)
Expand Down