python2.7.3 SIGSEGV in visit_decref()

51 views
Skip to first unread message

Juan A. Rubio

unread,
Apr 29, 2013, 8:04:52 AM4/29/13
to ctyp...@googlegroups.com, ctypes...@lists.sourceforge.net
Hi there,

probably this is not the right forum for this question, so please let me know if that is the case.

I am developing a Python test tool whose goal is to wrap with ctypes a C library for testing purposes. This C library in turns loads at run-time a number of other libraries using dlopen.

My Python tool executes the tests seemingly correctly but the Python interpreter segfaults at the end of most (not all) of the runs. This is the backtrace:

 Program received signal SIGSEGV, Segmentation fault.
 0x0000000000568af8 in visit_decref ()
 (gdb) bt
 #0  0x0000000000568af8 in visit_decref ()
 #1  0x0000000000567376 in dict_traverse.18311 ()
 #2  0x0000000000543015 in collect.48496 ()
 #3  0x00000000004aedf0 in Py_Finalize ()
 #4  0x00000000004af358 in Py_Exit ()
 #5  0x00000000004af42a in handle_system_exit.42667 ()
 #6  0x00000000004a93fa in PyRun_SimpleFileExFlags ()
 #7  0x00000000004aa8bd in Py_Main ()
 #8  0x00007ffff68df76d in __libc_start_main (main=0x41b980 <main>, argc=4, ubp_av=0x7fffffffe278, init=<optimised out>, fini=<optimised out>, rtld_fini=<optimised out>, stack_end=0x7fffffffe268)
     at libc-start.c:226
 #9  0x000000000041b9b1 in _start ()

My environment is Ubuntu Linux 12.04 x86_64 and Python 2.7.3 (not sure what version of ctypesgen I used at the time but I could look it up).

I was wondering if this would sound like a familiar issue to people with ctypes experience?.

Any pointers would be very much appreciated.

Thanks,
Juan

Alan Robertson

unread,
Apr 29, 2013, 8:55:11 AM4/29/13
to ctyp...@googlegroups.com
It's probably cleaning up objects before exiting. If your objects have
__del__ methods (like all mine do), then it's probably running into some
kind of issue interacting with the free code in your C code.

In my experience, the stack tracebacks you get from python when you
crash with ctypes code loaded are rarely useful, and often deceptive.

I do something VERY similar with my C code -- most of my tests are in
python. It's nearly always painful when I get a crash. In the case of
my particular code, I verify that all the C objects that my code creates
are free at the end of every test.

I wish I knew how to make the pain go away - but the only cure I came
out with was having debugging I can turn on in the C code that helps me
localize the issue to some smallish amount of code.
> --
>
> ---
> You received this message because you are subscribed to the Google
> Groups "Ctypesgen Development List" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to ctypesgen+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Juan Rubio

unread,
Apr 29, 2013, 5:31:32 PM4/29/13
to ctyp...@googlegroups.com
Alan,

thanks for the "localization" hint.

I've managed to fix these issues. I needed to pass a buffer to a c function so that the function could copy a string in it, but I never allocated the actual buffer.  Never cared to touch the string received so maybe that's why Python only crashed at clean up time.

Regards,
Juan

Alan Robertson

unread,
Apr 29, 2013, 6:01:33 PM4/29/13
to ctyp...@googlegroups.com
On 04/29/2013 03:31 PM, Juan Rubio wrote:
> Alan,
>
> thanks for the "localization" hint.
>
> I've managed to fix these issues. I needed to pass a buffer to a c
> function so that the function could copy a string in it, but I never
> allocated the actual buffer. Never cared to touch the string received
> so maybe that's why Python only crashed at clean up time.

Yeah, I think I do that in one place... I'm not proud of how I did it,
but it works...

It was weird... Kind of like lighting candles, chanting, and swinging a
dead chicken over your head ;-)

--
Alan Robertson <al...@unix.sh> - @OSSAlanR

"Openness is the foundation and preservative of friendship... Let me claim from you at all times your undisguised opinions." - William Wilberforce

anatoly techtonik

unread,
Apr 30, 2013, 4:16:32 AM4/30/13
to ctyp...@googlegroups.com
On Tue, Apr 30, 2013 at 1:01 AM, Alan Robertson <al...@unix.sh> wrote:
On 04/29/2013 03:31 PM, Juan Rubio wrote:
> Alan,
>
> thanks for the "localization" hint.
>
> I've managed to fix these issues. I needed to pass a buffer to a c
> function so that the function could copy a string in it, but I never
> allocated the actual buffer.  Never cared to touch the string received
> so maybe that's why Python only crashed at clean up time.

Yeah, I think I do that in one place...  I'm not proud of how I did it,
but it works...

It was weird... Kind of like lighting candles, chanting, and swinging a
dead chicken over your head ;-)

If it takes too long, it helps to swing two dead chickens simultaneously in opposite directions. ;)
-- 
anatoly t.

Reply all
Reply to author
Forward
0 new messages