python: double free or corruption when using SWIG

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

python: double free or corruption when using SWIG

Damian Kaliszan
Hi,

I've recently dived into the following problem.
>From   python  I'm  calling  C  function  with  several  input  arrays
of doubles (ndarrays    in  python)  as  input  parameters and returning array of
doubles as well. I checked 2 possible solutions (1. output array as C function
variable  2.  separate  typemap  to  let C function to return array of
doubles (a pointer to array of doubles to be precise)

In first case , the piece of interface file looks as follows:

%apply (double* IN_ARRAY1, int DIM1) {( double* val, int n3),( double* bptr, int n4)};
%apply (int* IN_ARRAY1, int DIM1) {(int* row_offsets, int n1),(int* col, int n2)};

%typemap(out) double* my_function {
  int i;
  $result = PyList_New(templen);
  for (i = 0; i < templen; i++) {
    PyObject *o = PyFloat_FromDouble((double)$1[i]);
    PyList_SetItem($result,i,o);
  }
}

In second case:

%apply (int DIM1, double* ARGOUT_ARRAY1) {(int n5, double* xptr)};
%apply (double* IN_ARRAY1, int DIM1) {( double* val, int n3),( double* bptr, int n4)};
%apply (int* IN_ARRAY1, int DIM1) {(int* row_offsets, int n1),(int* col, int n2)};

Both   cases   compile  well,   I  can call the C function from python
correctly. I can print ouput array in both python and C correctly.

Suddently  when  trying to reshape the output array in python I get the
following error.


*** glibc detected *** python: double free or corruption (!prev): 0x0000000003027080 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x75f3e)[0x2b497e49df3e]
/lib64/libc.so.6(+0x78dd0)[0x2b497e4a0dd0]
/opt/exp_soft/local/opteron/python/3.5.1/lib/python3.5/site-packages/numpy/core/multiarray.cpython-35m-x86_64-linux-gnu.so(+0x1d28f)[0x2b4984e8d28f]
/opt/exp_soft/local/opteron/python/3.5.1/lib/python3.5/site-packages/numpy/core/multiarray.cpython-35m-x86_64-linux-gnu.so(+0x20191)[0x2b4984e90191]
/opt/exp_soft/local/opteron/python/3.5.1/lib/python3.5/site-packages/numpy/core/multiarray.cpython-35m-x86_64-linux-gnu.so(+0x201d7)[0x2b4984e901d7]
python[0x473f64]
python[0x491add]
python[0x47390f]
python[0x473979]
python[0x54e1f2]
python(_PyGC_CollectNoFail+0x31)[0x54ee11]
python(PyImport_Cleanup+0x2f4)[0x518e94]
python[0x52c519]
python(Py_Main+0x5d3)[0x420063]
python(main+0x152)[0x41c0a2]
/lib64/libc.so.6(__libc_start_main+0xfd)[0x2b497e446d1d]
python[0x41c149]
======= Memory map: ========
00400000-0065a000 r-xp 00000000 00:16 70148186                           /opt/exp_soft/local/generic/python/3.5.1/bin/python3.5
0085a000-008bd000 rw-p 0025a000 00:16 70148186                           /opt/exp_soft/local/generic/python/3.5.1/bin/python3.5
008bd000-008ee000 rw-p 00000000 00:00 0
0239d000-03153000 rw-p 00000000 00:00 0                                  [heap]
2b497d738000-2b497d758000 r-xp 00000000 00:12 176139275                  /lib64/ld-2.12.so
2b497d758000-2b497d759000 rw-p 00000000 00:00 0
2b497d957000-2b497d959000 r--p 0001f000 00:12 176139275                  /lib64/ld-2.12.so
2b497d959000-2b497d95a000 rw-p 00021000 00:12 176139275                  /lib64/ld-2.12.so
2b497d95a000-2b497d95b000 rw-p 00000000 00:00 0
2b497d960000-2b497d977000 r-xp 00000000 00:12 174034634                  /lib64/libpthread-2.12.so
2b497d977000-2b497db77000 ---p 00017000 00:12 174034634                  /lib64/libpthread-2.12.so
2b497db77000-2b497db78000 r--p 00017000 00:12 174034634                  /lib64/libpthread-2.12.so
2b497db78000-2b497db79000 rw-p 00018000 00:12 174034634                  /lib64/libpthread-2.12.so
2b497db79000-2b497db7e000 rw-p 00000000 00:00 0
2b497db80000-2b497db82000 r-xp 00000000 00:12 177718896                  /lib64/libdl-2.12.so
2b497db82000-2b497dd82000 ---p 00002000 00:12 177718896                  /lib64/libdl-2.12.so
2b497dd82000-2b497dd83000 r--p 00002000 00:12 177718896                  /lib64/libdl-2.12.so
2b497dd83000-2b497dd84000 rw-p 00003000 00:12 177718896                  /lib64/libdl-2.12.so
2b497dd88000-2b497dd8a000 r-xp 00000000 00:12 177718948                  /lib64/libutil-2.12.so
2b497dd8a000-2b497df89000 ---p 00002000 00:12 177718948                  /lib64/libutil-2.12.so
2b497df89000-2b497df8a000 r--p 00001000 00:12 177718948                  /lib64/libutil-2.12.so
2b497df8a000-2b497df8b000 rw-p 00002000 00:12 177718948                  /lib64/libutil-2.12.so
2b497df90000-2b497df97000 r-xp 00000000 00:12 175613094                  /lib64/librt-2.12.so
2b497df97000-2b497e196000 ---p 00007000 00:12 175613094                  /lib64/librt-2.12.so
2b497e196000-2b497e197000 r--p 00006000 00:12 175613094                  /lib64/librt-2.12.so
2b497e197000-2b497e198000 rw-p 00007000 00:12 175613094                  /lib64/librt-2.12.so
2b497e198000-2b497e199000 rw-p 00000000 00:00 0
2b497e1a0000-2b497e223000 r-xp 00000000 00:12 177718904                  /lib64/libm-2.12.so
2b497e223000-2b497e422000 ---p 00083000 00:12 177718904                  /lib64/libm-2.12.so
2b497e422000-2b497e423000 r--p 00082000 00:12 177718904                  /lib64/libm-2.12.so
2b497e423000-2b497e424000 rw-p 00083000 00:12 177718904                  /lib64/libm-2.12.so
2b497e428000-2b497e5b2000 r-xp 00000000 00:12 177718872                  /lib64/libc-2.12.so
2b497e5b2000-2b497e7b2000 ---p 0018a000 00:12 177718872                  /lib64/libc-2.12.so
2b497e7b2000-2b497e7b6000 r--p 0018a000 00:12 177718872                  /lib64/libc-2.12.so
2b497e7b6000-2b497e7b8000 rw-p 0018e000 00:12 177718872                  /lib64/libc-2.12.so
2b497e7b8000-2b497e7be000 rw-p 00000000 00:00 0
2b497e7c0000-2b4984652000 r--p 00000000 00:12 175613224                  /usr/lib/locale/locale-archive
2b4984658000-2b498465f000 r--s 00000000 00:12 176139062                  /usr/lib64/gconv/gconv-modules.cache
2b498465f000-2b49847df000 rw-p 00000000 00:00 0
2b4984911000-2b4984951000 rw-p 00000000 00:00 0
2b4984958000-2b498495a000 r-xp 00000000 00:16 80149839                   /opt/exp_soft/local/generic/python/3.5.1/lib/python3.5/lib-dynload/_heapq.cpython-35m-x86_64-linux-gnu.so
2b498495a000-2b4984b5a000 ---p 00002000 00:16 80149839                   /opt/exp_soft/local/generic/python/3.5.1/lib/python3.5/lib-dynload/_heapq.cpython-35m-x86_64-linux-gnu.so
2b4984b5a000-2b4984b5c000 rw-p 00002000 00:16 80149839                   /opt/exp_soft/local/generic/python/3.5.1/lib/python3.5/lib-dynload/_heapq.cpython-35m-x86_64-linux-gnu.so
2b4984b5c000-2b4984b9c000 rw-p 00000000 00:00 0
2b4984c1c000-2b4984c5c000 rw-p 00000000 00:00 0
2b4984c60000-2b4984c6c000 r-xp 00000000 00:16 80149868                   /opt/exp_soft/local/generic/python/3.5.1/lib/python3.5/lib-dynload/math.cpython-35m-x86_64-linux-gnu.so
2b4984c6c000-2b4984e6c000 ---p 0000c000 00:16 80149868                   /opt/exp_soft/local/generic/python/3.5.1/lib/python3.5/lib-dynload/math.cpython-35m-x86_64-linux-gnu.so
2b4984e6c000-2b4984e6e000 rw-p 0000c000 00:16 80149868                   /opt/exp_soft/local/generic/python/3.5.1/lib/python3.5/lib-dynload/math.cpython-35m-x86_64-linux-gnu.so
2b4984e70000-2b498503c000 r-xp 00000000 00:16 214021996                  /opt/exp_soft/local/generic/python/3.5.1/lib/python3.5/site-packages/numpy/core/multiarray.cpython-35m-x86_64-linux-gnu.so
2b498503c000-2b498523b000 ---p 001cc000 00:16 214021996                  /opt/exp_soft/local/generic/python/3.5.1/lib/python3.5/site-packages/numpy/core/multiarray.cpython-35m-x86_64-linux-gnu.so
2b498523b000-2b498524a000 rw-p 001cb000 00:16 214021996                  /opt/exp_soft/local/generic/python/3.5.1/lib/python3.5/site-packages/numpy/core/multiarray.cpython-35m-x86_64-linux-gnu.so
2b498524a000-2b498525c000 rw-p 00000000 00:00 0
2b498525c000-2b4985262000 rw-p 00970000 00:16 214021996                  /opt/exp_soft/local/generic/python/3.5.1/lib/python3.5/site-packages/numpy/core/multiarray.cpython-35m-x86_64-linux-gnu.so
2b4985268000-2b498757c000 r-xp 00000000 00:16 214546554                  /opt/exp_soft/local/generic/python/3.5.1/lib/python3.5/site-packages/numpy/.libs/libopenblasp-r0-39a31c03.2.18.so
2b498757c000-2b498777b000 ---p 02314000 00:16 214546554                  /opt/exp_soft/local/generic/python/3.5.1/lib/python3.5/site-packages/numpy/.libs/libopenblasp-r0-39a31c03.2.18.so
2b498777b000-2b498779a000 rw-p 02313000 00:16 214546554                  /opt/exp_soft/local/generic/python/3.5.1/lib/python3.5/site-packages/numpy/.libs/libopenblasp-r0-39a31c03.2.18.soAborted


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user