thouis / numpy-trac-migration

numpy Trac to github issues migration
2 stars 3 forks source link

np.searchsorted segfaults when input is a recarray (Trac #2066) #5863

Open numpy-gitbot opened 11 years ago

numpy-gitbot commented 11 years ago

Original ticket http://projects.scipy.org/numpy/ticket/2066 on 2012-02-26 by trac user josh.ayers, assigned to unknown.

The following code segfaults. I'm running NumPy 1.6.1 on Windows 7.

import numpy as np
dtype = np.format_parser(['i4', 'i4'], [], [])
a = np.recarray((2, ), dtype)
np.searchsorted(a, 1)

The gdb output is below:

(gdb) run -c "import crash; crash.run()"

Starting program: c:\python27\python.exe -c "import crash; crash.run()"
[New Thread 3520.0x9cc]

Program received signal SIGSEGV, Segmentation fault.
0x673982ac in PyArray_SearchSorted ()
   from c:\python27\lib\site-packages\numpy\core\multiarray.pyd

(gdb) bt

#0  0x673982ac in PyArray_SearchSorted ()
   from c:\python27\lib\site-packages\numpy\core\multiarray.pyd
#1  0x673986e8 in array_searchsorted ()
   from c:\python27\lib\site-packages\numpy\core\multiarray.pyd
#2  0x1e0887c7 in python27!PyCFunction_Call () from c:\python27\python27.dll
#3  0x1e0bf781 in python27!PyEval_GetFuncDesc () from c:\python27\python27.dll
#4  0x0262abe8 in ?? ()
#5  0x1e1d57f8 in python27!PySuper_Type () from c:\python27\python27.dll
#6  0x00000002 in ?? ()
#7  0x01cedf30 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
(gdb)
numpy-gitbot commented 11 years ago

atmention:charris wrote on 2012-02-26

I suspect this is a problem with recarray. Things work better with array:

In [59]: a = np.array([(2,2),(2,2)], dtype)

In [60]: a
Out[60]: 
array([(2, 2), (2, 2)], 
      dtype=[('f0', '<i4'), ('f1', '<i4')])

In [61]: a.searchsorted(1)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/home/charris/<ipython-input-61-0a2b1f19a7e6> in <module>()
----> 1 a.searchsorted(1)

TypeError: invalid type promotion
numpy-gitbot commented 11 years ago

trac user josh.ayers wrote on 2012-02-27

That also segfaults for me on Windows, with the same gdb output.

I tried both cases - with a recarray and a standard structured array - on Ubuntu 11.10 in a virtual machine. It raises a !TypeError for both, so it seems like the problem is Windows-specific. However, the !NumPy version under Ubuntu was 1.5.1, versus 1.6.1 under Windows.

For further clarification, under Windows I'm using the !NumPy binaries that come with Python(x,y) 2.7.2.1.

numpy-gitbot commented 11 years ago

atmention:mwiebe wrote on 2012-03-12

NumPy should never segfault (except in the presence of funky ctypes code).

numpy-gitbot commented 11 years ago

Milestone changed to NumPy 1.7 by atmention:mwiebe on 2012-03-12

numpy-gitbot commented 11 years ago

trac user claumann wrote on 2012-04-11

Standard structured arrays segfault on Mac OSX with Enthought's python 2.7.2, but github numpy 2.0.0.dev-26aa3cf.

Using Fonnesbeck's current superpack (Apple Python 2.7.1 from Lion, numpy 1.7.0.dev-3503cf), the same code raises an type promotion error. Don't know if this is related to enthought or if the github master doesn't have the same type checking that 1.7.0.dev seems to have..

Python 2.7.2 |EPD 7.1-1 (64-bit)| (default, Jul 3 2011, 15:56:02) Type "copyright", "credits" or "license" for more information.

IPython 0.13.dev -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details.

Welcome to pylab, a matplotlib-based Python environment [backend: MacOSX]. For more information, type 'help(pylab)'.

In [1]: np.version Out[1]: '2.0.0.dev-26aa3cf'

In [2]: dtype = np.format_parser(['i4', 'i4'], [], [])

In [3]: a = np.array([(2,2),(2,2)], dtype)

In [4]: np.searchsorted(a, r_[1]) Segmentation fault: 11

numpy-gitbot commented 11 years ago

atmention:charris wrote on 2012-04-12

Raises TypeError in current master.

In [1]: dtype = np.format_parser(['i4', 'i4'], [], [])

In [2]: a = np.recarray((2, ), dtype)

In [3]: np.searchsorted(a, 1)
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (1615, 0))

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/home/charris/<ipython-input-3-c733016efef5> in <module>()
----> 1 np.searchsorted(a, 1)

/home/charris/.local/lib/python2.7/site-packages/numpy/core/fromnumeric.pyc in searchsorted(a, v, side, sorter)
    812     except AttributeError:
    813         return _wrapit(a, 'searchsorted', v, side, sorter)
--> 814     return searchsorted(v, side, sorter)
    815 
    816 

TypeError: invalid type promotion

In [4]: np.__version__
Out[4]: '1.7.0.dev-d50f961'

I think this is fixed I'm going to close the ticket unless someone can turn up a failure using the current devel version.