[pypy-issue] Issue #1872: `numpy.ndarray.swapaxes` random segfault. (pypy/pypy)

Yichao Yu issues-reply at bitbucket.org
Tue Sep 23 21:01:07 CEST 2014


New issue 1872: `numpy.ndarray.swapaxes` random segfault.
https://bitbucket.org/pypy/pypy/issue/1872/numpyndarrayswapaxes-random-segfault

Yichao Yu:

PyPy segfault randomly when running `numpy.array([]).swapaxes(0, 2)` and can be reproduce with the following script.

```
from numpy import *

for i in range(10000):
    array([]).swapaxes(0, 2)
```

The result of the function is also wrong

```
In [1]: from numpy import *     

In [2]: array([]).swapaxes(0, 2)
Out[2]: array([  6.90455688e-310])

In [3]: array([]).swapaxes(0, 3)
Out[3]: 
array([  6.90455688e-310,   6.90455688e-310,   6.90455688e-310,
         6.90455688e-310,   6.90455688e-310,   6.90455688e-310,
         6.90455688e-310,   6.90455688e-310])

In [4]: array([]).swapaxes(0, 4)
Out[4]: <repr(<numpy.ndarray at 0x7f1a04d302f0>) failed: MemoryError: >

In [5]: array([]).swapaxes(0, 5)
Out[5]: array([ 0.])

In [6]: array([]).swapaxes(0, 6)
Out[6]: array([], dtype=float64)

In [7]: array([]).swapaxes(0, 7)
Out[7]: array([], dtype=float64)

In [8]: array([]).swapaxes(0, 1)
[1]    21306 segmentation fault (core dumped)  ipypy
```

whereas all of them should return `array([], dtype=float64)`

BT of the segfault (not sure if it is useful but hopefully it shows the call path).

```
#0  pypy_g_read_int_at_mem___ptr (l_gcref_2=0x0, l_ofs_5=16, l_v1665891=8, l_v1665897=1) at rpython_jit_backend_llsupport_llmodel.c:3407
#1  0x00007ffff5cf1c33 in pypy_g_do_getarrayitem_gc (l___75=<optimized out>, l_v1803105=l_v1803105 at entry=0x7ffff1b3e020, 
    l_indexbox_9=l_indexbox_9 at entry=0x7ffff1b43e48, l_arraydescr_74=l_arraydescr_74 at entry=0x7ffff6dd92a0 <pypy_g_rpython_jit_backend_llsupport_descr_ArrayDescr_1>)
    at rpython_jit_metainterp_executor.c:13796
#2  0x00007ffff5cf1fde in pypy_g_execute___88_star_2 (l_metainterp_7=<optimized out>, l_opnum_89=l_opnum_89 at entry=88, 
    l_descr_97=l_descr_97 at entry=0x7ffff6dd92a0 <pypy_g_rpython_jit_backend_llsupport_descr_ArrayDescr_1>, l_stararg0_1881=l_stararg0_1881 at entry=0x7ffff1b3e020, 
    l_stararg1_1429=l_stararg1_1429 at entry=0x7ffff1b43e48) at rpython_jit_metainterp_executor.c:3823
#3  0x00007ffff5db5a8f in pypy_g__do_getarrayitem_gc_any___88 (l_self_18000=<optimized out>, l_self_18000 at entry=0x7ffff1b28570, l_op_200=l_op_200 at entry=88, 
    l_arraybox_15=0x7ffff1b3e020, l_indexbox_28=0x7ffff1b43e48, l_descr_213=0x7ffff6dd92a0 <pypy_g_rpython_jit_backend_llsupport_descr_ArrayDescr_1>)
    at rpython_jit_metainterp_pyjitpl_1.c:57770
#4  0x00007ffff5d83157 in pypy_g_handler_getarrayitem_gc_i (l_self_17746=0x7ffff1b28570, l_position_62=<optimized out>) at rpython_jit_metainterp_pyjitpl.c:40294
#5  0x00007ffff5d6f815 in pypy_g_MIFrame_run_one_step (l_self_17677=0x7ffff1b28570) at rpython_jit_metainterp_pyjitpl.c:19737
#6  0x00007ffff5d718d5 in pypy_g_MetaInterp__interpret (l_self_17661=<optimized out>) at rpython_jit_metainterp_pyjitpl.c:12373
#7  0x00007ffff5d71949 in pypy_g_MetaInterp_interpret (l_self_5455=<optimized out>) at rpython_jit_metainterp_pyjitpl.c:7166
#8  0x00007ffff5d71e3b in pypy_g_MetaInterp__compile_and_run_once (l_self_17644=<optimized out>, l_original_boxes_488=<optimized out>)
    at rpython_jit_metainterp_pyjitpl.c:4306
#9  0x00007ffff5d7b3e4 in pypy_g_compile_and_run_once___rpython_jit_metainterp_ji_5 (l_self_17647=<optimized out>, l_v1902137=l_v1902137 at entry=23, 
    l_v1902135=l_v1902135 at entry=false, l_v1902132=<optimized out>, l_v1902132 at entry=0x7ffff023dd00, l_v1902136=<optimized out>, l_v1902136 at entry=0x7ffff17edf10, 
    l_v1902134=<optimized out>, l_v1902134 at entry=0x7ffff7f1e020) at rpython_jit_metainterp_pyjitpl.c:6283
#10 0x00007ffff5e830cd in pypy_g_bound_reached__star_5_1 (l_hash_870=18355145746922850185, l_cell_128=<optimized out>, l_v2101540=23, l_v2101539=<optimized out>, 
    l_v2101541=<optimized out>, l_v2101537=<optimized out>, l_v2101536=<optimized out>) at rpython_jit_metainterp_warmstate.c:13652
#11 0x00007ffff5e83742 in pypy_g_maybe_compile_and_run__star_5_1 (l_increment_threshold_97=6.9533439442741953e-310, l_v2099061=23, l_v2099063=false, 
    l_v2099060=0x7ffff023dd00, l_v2099059=0x7ffff7dc1140 <pypy_g_array_91+40384>, l_v2099058=0x7ffff661b340 <pypy_g_typeinfo>)
    at rpython_jit_metainterp_warmstate.c:6661
#12 0x00007ffff5a11fbe in pypy_g_jump_absolute__AccessDirect_None (l_self_3607=<optimized out>, l_jumpto_1=23, l_ec_33=<optimized out>)
    at pypy_module_pypyjit_interp_jit.c:80
#13 0x00007ffff55a9619 in pypy_g_handle_bytecode__AccessDirect_None (l_self_13862=l_self_13862 at entry=0x7ffff17edf10, l_co_code_2=<optimized out>, 
    l_next_instr_53=<optimized out>, l_ec_17=l_ec_17 at entry=0x7ffff7f1e020) at pypy_interpreter_pyopcode.c:3071
#14 0x00007ffff5a120f5 in pypy_g_portal_5 (l_next_instr_59=<optimized out>, l_v4855=l_v4855 at entry=false, l_pycode_12=0x7ffff023dd00, 
    l_pycode_12 at entry=0x7ffff1ac77e8, l_self_15384=0x7ffff17edf10, l_self_15384 at entry=0x7ffff1ac7b90, l_ec_34=l_ec_34 at entry=0x7ffff7f1e020)
    at pypy_module_pypyjit_interp_jit.c:258
#15 0x00007ffff5e37f31 in pypy_g_ll_portal_runner__Unsigned_Bool_pypy_interpreter (l_stararg0_3081=0, l_stararg1_2826=<optimized out>, 
    l_stararg2_1362=<optimized out>, l_stararg3_840=<optimized out>, l_stararg3_840 at entry=0x7ffff17edf10, l_stararg4_604=<optimized out>, 
    l_stararg4_604 at entry=0x7ffff7f1e020) at rpython_jit_metainterp_warmspot.c:1834
#16 0x00007ffff5a11f8e in pypy_g_PyFrame_dispatch (l_self_3195=l_self_3195 at entry=0x7ffff17edf10, l_pycode_0=<optimized out>, l_next_instr_0=<optimized out>, 
    l_ec_4=l_ec_4 at entry=0x7ffff7f1e020) at pypy_module_pypyjit_interp_jit.c:23
#17 0x00007ffff558fc0b in pypy_g_PyFrame_execute_frame (l_self_13826=<optimized out>, l_w_inputvalue_1=<optimized out>, l_operr_11=<optimized out>)
    at pypy_interpreter_pyframe.c:2722
#18 0x00007ffff55900c0 in pypy_g_PyFrame_run (l_self_13823=<optimized out>) at pypy_interpreter_pyframe.c:1229
#19 0x00007ffff559e051 in pypy_g_EXEC_STMT__AccessDirect_None (l_self_13873=0x7ffff1486020, l_oparg_8=16, l_oparg_8 at entry=0, l_next_instr_21=8, 
    l_next_instr_21 at entry=263) at pypy_interpreter_pyopcode.c:17291
#20 0x00007ffff55a6286 in pypy_g_dispatch_bytecode__AccessDirect_None (l_self_13863=<optimized out>, l_self_13863 at entry=0x7ffff1486020, l_co_code_3=<optimized out>, 
    l_next_instr_4=<optimized out>, l_ec_18=<optimized out>, l_ec_18 at entry=0x7ffff7f1e020) at pypy_interpreter_pyopcode.c:7528
#21 0x00007ffff55a9619 in pypy_g_handle_bytecode__AccessDirect_None (l_self_13862=l_self_13862 at entry=0x7ffff1486020, l_co_code_2=<optimized out>, 
    l_next_instr_53=<optimized out>, l_ec_17=l_ec_17 at entry=0x7ffff7f1e020) at pypy_interpreter_pyopcode.c:3071
#22 0x00007ffff5a120f5 in pypy_g_portal_5 (l_next_instr_59=<optimized out>, l_v4855=l_v4855 at entry=false, 
    l_pycode_12=l_pycode_12 at entry=0x7ffff6bc0540 <pypy_g_pypy_interpreter_pycode_PyCode_85>, l_self_15384=l_self_15384 at entry=0x7ffff1aba2e8, 
---Type <return> to continue, or q <return> to quit---
    l_ec_34=l_ec_34 at entry=0x7ffff7f1e020) at pypy_module_pypyjit_interp_jit.c:258
#23 0x00007ffff5e37f31 in pypy_g_ll_portal_runner__Unsigned_Bool_pypy_interpreter (l_stararg0_3081=0, l_stararg1_2826=<optimized out>, 
    l_stararg2_1362=<optimized out>, l_stararg3_840=<optimized out>, l_stararg3_840 at entry=0x7ffff1486020, l_stararg4_604=<optimized out>, 
    l_stararg4_604 at entry=0x7ffff7f1e020) at rpython_jit_metainterp_warmspot.c:1834
#24 0x00007ffff5a11f8e in pypy_g_PyFrame_dispatch (l_self_3195=l_self_3195 at entry=0x7ffff1486020, l_pycode_0=<optimized out>, l_next_instr_0=<optimized out>, 
    l_ec_4=l_ec_4 at entry=0x7ffff7f1e020) at pypy_module_pypyjit_interp_jit.c:23
#25 0x00007ffff558fc0b in pypy_g_PyFrame_execute_frame (l_self_13826=<optimized out>, l_w_inputvalue_1=<optimized out>, l_operr_11=<optimized out>)
    at pypy_interpreter_pyframe.c:2722
#26 0x00007ffff55900c0 in pypy_g_PyFrame_run (l_self_13823=<optimized out>) at pypy_interpreter_pyframe.c:1229
#27 0x00007ffff559cf93 in pypy_g_call_function__AccessDirect_None (l_self_13871=0x7ffff14860b0, l_oparg_6=140737247945264, l_w_star_1=0x7ffff1aba240, 
    l_w_starstar_1=0x7ffff7dcdc80 <pypy_g_ExcData>) at pypy_interpreter_pyopcode.c:14983
#28 0x00007ffff55a773d in pypy_g_dispatch_bytecode__AccessDirect_None (l_self_13863=<optimized out>, l_self_13863 at entry=0x7ffff14860b0, l_co_code_3=<optimized out>, 
    l_next_instr_4=<optimized out>, l_ec_18=<optimized out>, l_ec_18 at entry=0x7ffff7f1e020) at pypy_interpreter_pyopcode.c:6730
#29 0x00007ffff55a9619 in pypy_g_handle_bytecode__AccessDirect_None (l_self_13862=l_self_13862 at entry=0x7ffff14860b0, l_co_code_2=<optimized out>, 
    l_next_instr_53=<optimized out>, l_ec_17=l_ec_17 at entry=0x7ffff7f1e020) at pypy_interpreter_pyopcode.c:3071
#30 0x00007ffff5a120f5 in pypy_g_portal_5 (l_next_instr_59=<optimized out>, l_v4855=l_v4855 at entry=false, 
    l_pycode_12=l_pycode_12 at entry=0x7ffff6b8c800 <pypy_g_pypy_interpreter_pycode_PyCode_25>, l_self_15384=l_self_15384 at entry=0x7ffff1aba0b8, 
    l_ec_34=l_ec_34 at entry=0x7ffff7f1e020) at pypy_module_pypyjit_interp_jit.c:258
#31 0x00007ffff5e37f31 in pypy_g_ll_portal_runner__Unsigned_Bool_pypy_interpreter (l_stararg0_3081=0, l_stararg1_2826=<optimized out>, 
    l_stararg2_1362=<optimized out>, l_stararg3_840=<optimized out>, l_stararg3_840 at entry=0x7ffff14860b0, l_stararg4_604=<optimized out>, 
    l_stararg4_604 at entry=0x7ffff7f1e020) at rpython_jit_metainterp_warmspot.c:1834
#32 0x00007ffff5a11f8e in pypy_g_PyFrame_dispatch (l_self_3195=l_self_3195 at entry=0x7ffff14860b0, l_pycode_0=<optimized out>, l_next_instr_0=<optimized out>, 
    l_ec_4=l_ec_4 at entry=0x7ffff7f1e020) at pypy_module_pypyjit_interp_jit.c:23
#33 0x00007ffff558fc0b in pypy_g_PyFrame_execute_frame (l_self_13826=<optimized out>, l_w_inputvalue_1=<optimized out>, l_operr_11=<optimized out>)
    at pypy_interpreter_pyframe.c:2722
#34 0x00007ffff55900c0 in pypy_g_PyFrame_run (l_self_13823=<optimized out>) at pypy_interpreter_pyframe.c:1229
#35 0x00007ffff559cf93 in pypy_g_call_function__AccessDirect_None (l_self_13871=0x7ffff17ed7c0, l_oparg_6=140737247944784, l_w_star_1=0x7ffff1aba060, 
    l_w_starstar_1=0x7ffff7dcdc80 <pypy_g_ExcData>) at pypy_interpreter_pyopcode.c:14983
#36 0x00007ffff55a762a in pypy_g_dispatch_bytecode__AccessDirect_None (l_self_13863=<optimized out>, l_self_13863 at entry=0x7ffff17ed7c0, l_co_code_3=<optimized out>, 
    l_next_instr_4=<optimized out>, l_ec_18=<optimized out>, l_ec_18 at entry=0x7ffff7f1e020) at pypy_interpreter_pyopcode.c:6680
#37 0x00007ffff55a9619 in pypy_g_handle_bytecode__AccessDirect_None (l_self_13862=l_self_13862 at entry=0x7ffff17ed7c0, l_co_code_2=<optimized out>, 
    l_next_instr_53=<optimized out>, l_ec_17=l_ec_17 at entry=0x7ffff7f1e020) at pypy_interpreter_pyopcode.c:3071
#38 0x00007ffff5a120f5 in pypy_g_portal_5 (l_next_instr_59=<optimized out>, l_v4855=l_v4855 at entry=false, 
    l_pycode_12=l_pycode_12 at entry=0x7ffff6b8c680 <pypy_g_pypy_interpreter_pycode_PyCode_27>, l_self_15384=l_self_15384 at entry=0x7ffff1c8c158, 
    l_ec_34=l_ec_34 at entry=0x7ffff7f1e020) at pypy_module_pypyjit_interp_jit.c:258
#39 0x00007ffff5e37f31 in pypy_g_ll_portal_runner__Unsigned_Bool_pypy_interpreter (l_stararg0_3081=0, l_stararg1_2826=<optimized out>, 
    l_stararg2_1362=<optimized out>, l_stararg3_840=<optimized out>, l_stararg3_840 at entry=0x7ffff17ed7c0, l_stararg4_604=<optimized out>, 
    l_stararg4_604 at entry=0x7ffff7f1e020) at rpython_jit_metainterp_warmspot.c:1834
#40 0x00007ffff5a11f8e in pypy_g_PyFrame_dispatch (l_self_3195=l_self_3195 at entry=0x7ffff17ed7c0, l_pycode_0=<optimized out>, l_next_instr_0=<optimized out>, 
    l_ec_4=l_ec_4 at entry=0x7ffff7f1e020) at pypy_module_pypyjit_interp_jit.c:23
#41 0x00007ffff558fc0b in pypy_g_PyFrame_execute_frame (l_self_13826=<optimized out>, l_w_inputvalue_1=<optimized out>, l_operr_11=<optimized out>)
    at pypy_interpreter_pyframe.c:2722
#42 0x00007ffff55900c0 in pypy_g_PyFrame_run (l_self_13823=<optimized out>) at pypy_interpreter_pyframe.c:1229
#43 0x00007ffff559cf93 in pypy_g_call_function__AccessDirect_None (l_self_13871=0x7ffff7f2e0b0, l_oparg_6=140737249853304, l_w_star_1=0x7ffff1c8bf88, 
    l_w_starstar_1=0x7ffff7dcdc80 <pypy_g_ExcData>) at pypy_interpreter_pyopcode.c:14983
#44 0x00007ffff55a76ad in pypy_g_dispatch_bytecode__AccessDirect_None (l_self_13863=<optimized out>, l_self_13863 at entry=0x7ffff7f2e0b0, l_co_code_3=<optimized out>, 
    l_next_instr_4=<optimized out>, l_ec_18=<optimized out>, l_ec_18 at entry=0x7ffff7f1e020) at pypy_interpreter_pyopcode.c:6642
---Type <return> to continue, or q <return> to quit---
#45 0x00007ffff55a9619 in pypy_g_handle_bytecode__AccessDirect_None (l_self_13862=l_self_13862 at entry=0x7ffff7f2e0b0, l_co_code_2=<optimized out>, 
    l_next_instr_53=<optimized out>, l_ec_17=l_ec_17 at entry=0x7ffff7f1e020) at pypy_interpreter_pyopcode.c:3071
#46 0x00007ffff5a120f5 in pypy_g_portal_5 (l_next_instr_59=<optimized out>, l_v4855=l_v4855 at entry=false, 
    l_pycode_12=l_pycode_12 at entry=0x7ffff6a7ac80 <pypy_g_pypy_interpreter_pycode_PyCode>, l_self_15384=l_self_15384 at entry=0x7ffff1a30e30, 
    l_ec_34=l_ec_34 at entry=0x7ffff7f1e020) at pypy_module_pypyjit_interp_jit.c:258
#47 0x00007ffff5e37f31 in pypy_g_ll_portal_runner__Unsigned_Bool_pypy_interpreter (l_stararg0_3081=0, l_stararg1_2826=<optimized out>, 
    l_stararg2_1362=<optimized out>, l_stararg3_840=<optimized out>, l_stararg3_840 at entry=0x7ffff7f2e0b0, l_stararg4_604=<optimized out>, 
    l_stararg4_604 at entry=0x7ffff7f1e020) at rpython_jit_metainterp_warmspot.c:1834
#48 0x00007ffff5a11f8e in pypy_g_PyFrame_dispatch (l_self_3195=l_self_3195 at entry=0x7ffff7f2e0b0, l_pycode_0=<optimized out>, l_next_instr_0=<optimized out>, 
    l_ec_4=l_ec_4 at entry=0x7ffff7f1e020) at pypy_module_pypyjit_interp_jit.c:23
#49 0x00007ffff558fc0b in pypy_g_PyFrame_execute_frame (l_self_13826=<optimized out>, l_w_inputvalue_1=<optimized out>, l_operr_11=<optimized out>)
    at pypy_interpreter_pyframe.c:2722
#50 0x00007ffff55900c0 in pypy_g_PyFrame_run (l_self_13823=<optimized out>) at pypy_interpreter_pyframe.c:1229
#51 0x00007ffff5545c4e in pypy_g_call_function__star_2 (l_w_func_33=0x7ffff6a7c500 <pypy_g_pypy_interpreter_function_Function>, l_stararg0_489=0x7ffff1a30d80, 
    l_stararg1_223=0x7ffff1a30de8) at pypy_interpreter_baseobjspace.c:1182
#52 0x00007ffff54b6393 in pypy_g_entry_point (l_l1_45=<optimized out>, l_l1_45 at entry=0x7ffff1a10010) at pypy_goal_targetpypystandalone.c:1872
#53 0x00007ffff60e2804 in pypy_main_function (argc=<optimized out>, argv=0x7fffffffdb38) at entrypoint.c:61
#54 0x00007ffff39db040 in __libc_start_main () from /usr/lib/libc.so.6
#55 0x00000000004005fe in ?? ()
```




More information about the pypy-issue mailing list