Причина Ошибки сегментирования
Помогите понять причину возникновения ошибки сегментирования.
$ cat libmatrix.c
void ones_matrix(
const int n,
const int m,
double* mtx)
{
for(int i=0; i<n; ++i)
for(int j=0; j<m; ++j)
*(mtx++)=(i+j)/2.;
}
$ cat matrix.py
#!/usr/bin/python
from os import path
from sys import platform
path = path.dirname(path.realpath(__file__))
if 'linux' in platform:
mod_matrix_maker=cdll.LoadLibrary("%s/libmatrix.so" % path)
def myones(n,m):
A=ndarray((n,m),dtype='d')
mod_matrix_maker.ones_matrix(n,m,A.reshape(-1,1).ctypes.data)
return A
$ cat test.py
#!/usr/bin/python
import ctypes
from sys import path
path.append('./../')
from module.matrix import *
A = myones(1000,200)
print A
$ ./test.py
Ошибка сегментирования
$ gdb --args python ./test.py
GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /usr/bin/python...(no debugging symbols found)...done.
(gdb) run
Starting program: /usr/bin/python ./test.py
[Thread debugging using libthread_db enabled]
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff347b5e2 in ones_matrix (n=1000, m=200, mtx=0xf32f4010) at libmatrix.c:11
11 *(mtx++)=(i+j)/2.;
(gdb) bt full
#0 0x00007ffff347b5e2 in ones_matrix (n=1000, m=200, mtx=0xf32f4010) at libmatrix.c:11
j = 0
i = 0
#1 0x00007ffff6377d54 in ffi_call_unix64 () from /usr/lib/python2.7/lib-dynload/_ctypes.so
No symbol table info available.
#2 0x00007ffff6377775 in ffi_call () from /usr/lib/python2.7/lib-dynload/_ctypes.so
No symbol table info available.
#3 0x00007ffff636fef7 in _ctypes_callproc () from /usr/lib/python2.7/lib-dynload/_ctypes.so
No symbol table info available.
#4 0x00007ffff63675f7 in ?? () from /usr/lib/python2.7/lib-dynload/_ctypes.so
No symbol table info available.
#5 0x000000000041ad2a in PyObject_Call ()
No symbol table info available.
#6 0x00000000004b6b9e in PyEval_EvalFrameEx ()
No symbol table info available.
#7 0x00000000004b6d77 in PyEval_EvalFrameEx ()
No symbol table info available.
#8 0x00000000004bcd2d in PyEval_EvalCodeEx ()
No symbol table info available.
#9 0x00000000004bd802 in PyEval_EvalCode ()
No symbol table info available.
#10 0x00000000004dcc22 in ?? ()
No symbol table info available.
#11 0x00000000004dd7e4 in PyRun_FileExFlags ()
No symbol table info available.
#12 0x00000000004de2ee in PyRun_SimpleFileExFlags ()
No symbol table info available.
#13 0x00000000004ee6dd in Py_Main ()
---Type <return> to continue, or q <return> to quit---
No symbol table info available.
#14 0x00007ffff699e30d in __libc_start_main () from /lib/x86_64-linux-gnu/libc.so.6
No symbol table info available.
#15 0x000000000041cb69 in _start ()
No symbol table info available.