10000 BUG: Attempt to fix sparc segfault (gh-2668) by mwiebe · Pull Request #2794 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: Attempt to fix sparc segfault (gh-2668) #2794

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 2 commits into from
Dec 14, 2012
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions numpy/core/src/multiarray/dtype_transfer.c
Original file line number Diff line number Diff line change
Expand Up @@ -3582,6 +3582,13 @@ PyArray_GetDTypeTransferFunction(int aligned,
PyArray_ISNBO(dst_dtype->byteorder)) {

if (PyArray_EquivTypenums(src_type_num, dst_type_num)) {
/*
* For complex numbers, the alignment is smaller than the
* type size, so we turn off the aligned flag then.
*/
if (src_dtype->kind == 'c' || dst_dtype->kind == 'c') {
aligned = 0;
}
*out_stransfer = PyArray_GetStridedCopyFn(aligned,
src_stride, dst_stride,
src_itemsize);
Expand Down Expand Up @@ -3678,6 +3685,13 @@ PyArray_GetDTypeTransferFunction(int aligned,
/* This is a straight copy */
if (src_itemsize == 1 || PyArray_ISNBO(src_dtype->byteorder) ==
PyArray_ISNBO(dst_dtype->byteorder)) {
/*
* For complex numbers, the alignment is smaller than the
* type size, so we turn off the aligned flag then.
*/
if (src_dtype->kind == 'c' || dst_dtype->kind == 'c') {
aligned = 0;
}
*out_stransfer = PyArray_GetStridedCopyFn(aligned,
src_stride, dst_stride,
src_itemsize);
Expand Down
17 changes: 17 additions & 0 deletions numpy/core/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -1812,5 +1812,22 @@ def test_searchsorted_wrong_dtype(self):
a = np.recarray((2, ), dtype)
assert_raises(TypeError, np.searchsorted, a, 1)

def test_complex64_alignment(self):
# Issue gh-2668 (trac 2076), segfault on sparc due to misalignment
dtt = np.complex64
arr = np.arange(10, dtype=dtt)
# 2D array
arr2 = np.reshape(arr, (2, 5))
# Fortran write followed by (C or F) read caused bus error
data_str = arr2.tostring('F')
data_back = np.ndarray(arr2.shape,
arr2.dtype,
buffer=data_str,
order='F')
assert_array_equal(arr2, data_back)




if __name__ == "__main__":
run_module_suite()
0