Intbitset __init__ calls SIGSEGV

The following code causes an increase in segmentation error. I'm not quite sure why ...

import numpy as np
from intbitset import intbitset

arr = np.array([1,2,3,4,5])

# This works
intbitset(arr.tolist())
=> intbitset([1, 2, 3, 4, 5])

# This throws SIGSEGV
intbitset([x for x in arr])

[x for x in arr] works fine and returns a list as expected.

Does anyone have an explanation? Is not understanding the list before the list before entering intbitsetctr taken into account ?

I tested both Python 3.6.3 and 2.7.13 (need to change zipto itertools.izip). Accidents on both. intbitsetversion 2.3.0

+4
source share
1 answer

Here's something interesting:

$ gdb python 
...
(gdb) run crash.py
...
Thread 1 "python" received signal SIGSEGV, Segmentation fault.
0x00007ffff745338b in ?? () from /usr/lib/libpython3.6m.so.1.0
(gdb) bt
#0  0x00007ffff745338b in ?? ()
   from /usr/lib/libpython3.6m.so.1.0
#1  0x00007ffff74a245f in ?? ()
   from /usr/lib/libpython3.6m.so.1.0
#2  0x00007ffff73f0565 in PyList_Append ()
   from /usr/lib/libpython3.6m.so.1.0
#3  0x00007ffff73a2580 in ?? ()
   from /usr/lib/libpython3.6m.so.1.0
#4  0x00007ffff7404b55 in _PyCFunction_FastCallDict ()
   from /usr/lib/libpython3.6m.so.1.0
#5  0x00007ffff740e10f in _PyObject_FastCallDict ()
   from /usr/lib/libpython3.6m.so.1.0
#6  0x00007ffff73fc9d0 in PyFile_WriteObject ()
   from /usr/lib/libpython3.6m.so.1.0
#7  0x00007ffff74a3d6a in PyFile_WriteString ()
   from /usr/lib/libpython3.6m.so.1.0
#8  0x00007ffff74b2f9d in PyTraceBack_Print ()
   from /usr/lib/libpython3.6m.so.1.0
#9  0x00007ffff7491154 in ?? ()
   from /usr/lib/libpython3.6m.so.1.0
#10 0x00007ffff7327d14 in ?? ()
   from /usr/lib/libpython3.6m.so.1.0
#11 0x00007ffff749136e in PyErr_Display ()
   from /usr/lib/libpython3.6m.so.1.0
#12 0x00007ffff74c890a in ?? ()
   from /usr/lib/libpython3.6m.so.1.0
#13 0x00007ffff7404ad0 in _PyCFunction_FastCallDict ()
   from /usr/lib/libpython3.6m.so.1.0
#14 0x00007ffff740e10f in _PyObject_FastCallDict ()
   from /usr/lib/libpython3.6m.so.1.0
#15 0x00007ffff7492c5b in PyErr_PrintEx ()
  3.6m.so.1.0
#16 0x00007ffff74939d1 in PyRun_SimpleFileExFlags ()
   from /usr/lib/libpython3.6m.so.1.0
#17 0x00007ffff748970b in Py_Main ()
   from /usr/lib/libpython3.6m.so.1.0
#18 0x0000555555554c39 in main ()

Watch the challenges PyErr_Displayand PyTraceBack_Print. It looks like Python was trying to show the error, but crashed in the process. Indeed, this is not a failure:

try:
    intbitset([x for x in arr])
except Exception as ex:
    print(repr(ex))

Rather, it outputs the following:

ValueError('retrieving integers from rhs is impossible: invalid index to scalar variable.')

, intbitset.__cinit__. , __cinit__ Cython.

, gen_arrtype_subscript C. :

>>> import numpy as np
>>> arr = np.array([1,2,3,4,5])
>>> arr[0][0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: invalid index to scalar variable.

, intbitset , :

  tuple_of_tuples = rhs and hasattr(rhs, '__getitem__') and hasattr(rhs[0], '__getitem__')

, (numpy.int64 ) __getitem__, , . , intbitset , , __getitem__.

, , , intbitset(x for x in arr): __getitem__, intbitset . intbitset(arr), tuple_of_tuples arr bool:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

numpy ( , bool), , .

, invalid index to scalar segfault, truth value of an array ? , raise ValueError() , , , Undefined , , .

, intbitset - , __cinit__. Cython, , .

0

Source: https://habr.com/ru/post/1694238/


All Articles