[Numpy-discussion] possibly ctypes related segfault

Martin Wiechert martin.wiechert at gmx.de
Mon Aug 27 08:57:28 EDT 2007

Hi list,

I'm suffering from a strange segfault and would appreciate your help.

I'm calling a small C function using ctypes / numpy.ctypeslib. The function 
works in the sense that it returns correct results. After calling the 
function however I can reliably evoke a segfault by using readline tab 

I'm not very experienced, but this smells like a memory management bug to me, 
which is strange, because I'm not doing any mallocing/freeing at all in the C 

I could not reproduce the bug in a debug build of python (--without-pymalloc) 
or on another machine. The crashing machine is an eight-way opteron.

Maybe I should mention that the C function calls two lapack fortran functions. 
Can this cause problems?

Anyway, I'm at a loss. Please help!

I've attached the files for reference.

Thanks Martin

P.S.: Here is what valgrind finds in the debug build:

-bash-3.1$ valgrind ~/local/debug/bin/python
==16266== Memcheck, a memory error detector.
==16266== Copyright (C) 2002-2006, and GNU GPL'd, by Julian Seward et al.
==16266== Using LibVEX rev 1658, a library for dynamic binary translation.
==16266== Copyright (C) 2004-2006, and GNU GPL'd, by OpenWorks LLP.
==16266== Using valgrind-3.2.1, a dynamic binary instrumentation framework.
==16266== Copyright (C) 2000-2006, and GNU GPL'd, by Julian Seward et al.
==16266== For more details, rerun with: -v
Python 2.5.1 (r251:54863, Aug 24 2007, 16:13:26)
[GCC 4.1.1 20070105 (Red Hat 4.1.1-51)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> execfile ('recttest.py')
--16266-- DWARF2 CFI reader: unhandled CFI instruction 0:10
--16266-- DWARF2 CFI reader: unhandled CFI instruction 0:10
78.6006829739 4
[92353 refs]
==16266== Conditional jump or move depends on uninitialised value(s)
==16266==    at 0x41361F: parsetok (parsetok.c:189)
==16266==    by 0x4131B6: PyParser_ParseFileFlags (parsetok.c:89)
==16266==    by 0x4E01D2: PyParser_ASTFromFile (pythonrun.c:1381)
==16266==    by 0x4DE15C: PyRun_InteractiveOneFlags (pythonrun.c:770)
==16266==    by 0x4DDF15: PyRun_InteractiveLoopFlags (pythonrun.c:721)
==16266==    by 0x4DDD70: PyRun_AnyFileExFlags (pythonrun.c:690)
==16266==    by 0x412E05: Py_Main (main.c:523)
==16266==    by 0x411D62: main (python.c:23)
[92353 refs]
[37870 refs]
==16266== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 98 from 1)
==16266== malloc/free: in use at exit: 2,791,249 bytes in 17,090 blocks.
==16266== malloc/free: 174,713 allocs, 157,623 frees, 376,495,377 bytes 
==16266== For counts of detected errors, rerun with: -v
==16266== searching for pointers to 17,090 not-freed blocks.
==16266== checked 5,156,624 bytes.
==16266== LEAK SUMMARY:
==16266==    definitely lost: 0 bytes in 0 blocks.
==16266==      possibly lost: 35,400 bytes in 103 blocks.
==16266==    still reachable: 2,755,849 bytes in 16,987 blocks.
==16266==         suppressed: 0 bytes in 0 blocks.
==16266== Reachable blocks (those to which a pointer was found) are not shown.
==16266== To see them, rerun with: --show-reachable=yes

-------------- next part --------------
A non-text attachment was scrubbed...
Name: solver.c
Type: text/x-csrc
Size: 4892 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20070827/dd147e91/attachment.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cMontecarlo.py
Type: application/x-python
Size: 2657 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20070827/dd147e91/attachment.bin>

More information about the NumPy-Discussion mailing list