segfault using ndarray[object] #1608

llllllllll opened this Issue Feb 17, 2017 · 0 comments


None yet

1 participant

llllllllll commented Feb 17, 2017 edited

minimal repro case:

In [1]: %load_ext Cython

In [2]: %%cython
   ...: cimport numpy as np
   ...: import numpy as np
   ...: cpdef np.ndarray[object] encode_as_object(np.ndarray[object] ndarray,
   ...:                                           str encoding='utf-8',
   ...:                                           str errors='strict'):
   ...:     cdef np.ndarray[object] out = np.empty_like(ndarray, dtype='object')
   ...:     cdef Py_ssize_t n
   ...:     for n in range(len(ndarray)):
   ...:         out[n] = ndarray[n].encode(encoding, errors)
   ...:     return out
In file included from /home/joe/.virtualenvs/fundamentals/lib/python3.6/site-packages/numpy/core/include/numpy/ndarraytypes.h:1788:0,
                 from /home/joe/.virtualenvs/fundamentals/lib/python3.6/site-packages/numpy/core/include/numpy/ndarrayobject.h:18,
                 from /home/joe/.virtualenvs/fundamentals/lib/python3.6/site-packages/numpy/core/include/numpy/arrayobject.h:4,
                 from /home/joe/.cache/ipython/cython/_cython_magic_feb79cc694e6859260d24b21c1ab7c0b.c:451:
/home/joe/.virtualenvs/fundamentals/lib/python3.6/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
 #warning "Using deprecated NumPy API, disable it by " \

In [3]: array = np.array(['a', 'b', 'c'], dtype=object)

In [4]: encode_as_object(array)
Segmentation fault (core dumped)

This code works if you remove the object dtype qualifier from the output array even if I leave the return type as np.ndarray[object]

My env looks like like: (tested with gcc and clang to be safe)
cython git commit 935b691
python --version: Python 3.6.0
gcc --version: gcc (GCC) 7.0.1 20170210
clang --version: 3.9.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment