-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Record arrays with fields that contain multiple objects will segfault on array.resize #4857
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
Comments
is this even the expected result?
shouldn't it be all zero and not first zero rest none? the issue appears as the resize path only sets the first entry and the rest is not memset to 0 to get the |
fix would be something along the lines of this, assuming this behavior is indeed intended: --- a/numpy/core/src/multiarray/shape.c
+++ b/numpy/core/src/multiarray/shape.c
@@ -328,6 +328,8 @@ _putzero(char *optr, PyObject *zero, PyArray_Descr *dtype)
else {
Py_INCREF(zero);
NPY_COPY_PYOBJECT_PTR(optr, &zero);
+ npy_intp elsize = dtype->elsize;
+ memset(optr + sizeof(PyObject*), 0, elsize - sizeof(PyObject*));
}
return;
} |
juliantaylor
added a commit
to juliantaylor/numpy
that referenced
this issue
Jul 18, 2014
np.zeros(2, dtype=[('k', object, 2)]) did only initialize the first element to zero while the rest stayed None. In [1]: numpy.zeros(2, dtype=[('k', object, 2)]) Out[1]: array([([0, None],), ([0, None],)], dtype=[('k', 'O', (2,))]) This is a surprising and likely not intended behavior which is fixed here. The changed function PyArray_FillObjectArray is only used with None or zero inputs from numpy, though as its part of the API it could affect third parties but this is not very likely. Additionally the memory after the first element was not initialized when the object was resized. Closes numpygh-4857
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This short script will always segfault for me.
The text was updated successfully, but these errors were encountered: