From lgautier at gmail.com Fri Jun 6 12:31:09 2008 From: lgautier at gmail.com (Laurent Gautier) Date: Fri, 6 Jun 2008 12:31:09 +0200 Subject: [capi-sig] Segfault when using own C-written module and exiting python Message-ID: <27d1e6020806060331l56474a33i10262000a72c0df@mail.gmail.com> Dear List, I am having trouble with some of the use-cases for a C-written module of my own (if curious, I am working on Python-R interface... this is open source so I can provide the whole source if needed). Everything is working just fine and as expected... until the python process exits. When running my test script through gdb and with the '-v' flag for Python, it ends with --- # cleanup __main__ Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0xb7dde8c0 (LWP 19670)] 0x080f3d08 in PyObject_GC_UnTrack () --- I have looked for information on the internet... but have not found much. Would this kind of error be familiar to anyone ? Thanks, Laurent From mal at egenix.com Fri Jun 6 13:04:40 2008 From: mal at egenix.com (M.-A. Lemburg) Date: Fri, 06 Jun 2008 13:04:40 +0200 Subject: [capi-sig] Segfault when using own C-written module and exiting python In-Reply-To: <27d1e6020806060331l56474a33i10262000a72c0df@mail.gmail.com> References: <27d1e6020806060331l56474a33i10262000a72c0df@mail.gmail.com> Message-ID: <484919C8.8000604@egenix.com> On 2008-06-06 12:31, Laurent Gautier wrote: > Dear List, > > I am having trouble with some of the use-cases for a C-written module of my own > (if curious, I am working on Python-R interface... this is open source so I can > provide the whole source if needed). > > Everything is working just fine and as expected... until the python > process exits. > > When running my test script through gdb and with the '-v' flag for > Python, it ends with > --- > # cleanup __main__ > > Program received signal SIGSEGV, Segmentation fault. > [Switching to Thread 0xb7dde8c0 (LWP 19670)] > 0x080f3d08 in PyObject_GC_UnTrack () > > --- > > I have looked for information on the internet... but have not found > much. Would this kind > of error be familiar to anyone ? I've never seen this particular error before, but it's likely that you have a ref count bug somewhere in your code. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jun 06 2008) >>> Python/Zope Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ 2008-07-07: EuroPython 2008, Vilnius, Lithuania 30 days to go :::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! :::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 From python_capi at behnel.de Fri Jun 6 14:35:20 2008 From: python_capi at behnel.de (Stefan Behnel) Date: Fri, 06 Jun 2008 14:35:20 +0200 Subject: [capi-sig] Segfault when using own C-written module and exiting python In-Reply-To: <484919C8.8000604@egenix.com> References: <27d1e6020806060331l56474a33i10262000a72c0df@mail.gmail.com> <484919C8.8000604@egenix.com> Message-ID: <48492F08.1030500@behnel.de> Hi, M.-A. Lemburg wrote: > On 2008-06-06 12:31, Laurent Gautier wrote: >> I am having trouble with some of the use-cases for a C-written module >> of my own >> (if curious, I am working on Python-R interface... this is open source >> so I can provide the whole source if needed). > > I've never seen this particular error before, but it's likely that you > have a ref count bug somewhere in your code. If the existing code base isn't too large yet, consider switching to Cython instead of C. http://cython.org/ Stefan From lgautier at gmail.com Fri Jun 6 21:40:49 2008 From: lgautier at gmail.com (Laurent Gautier) Date: Fri, 6 Jun 2008 21:40:49 +0200 Subject: [capi-sig] Segfault when using own C-written module and exiting python In-Reply-To: <27d1e6020806060331l56474a33i10262000a72c0df@mail.gmail.com> References: <27d1e6020806060331l56474a33i10262000a72c0df@mail.gmail.com> Message-ID: <27d1e6020806061240h11661005we0a9ca6a41bd1511@mail.gmail.com> I have probably found the problem. I report it here in case someone has the same issue later. In my tp_new I had: PyObject_New(MyType, type); (and it was working just fine until I started with subclasses) while it seems that it should have been: type->tp_alloc(type, 0); L. 2008/6/6 Laurent Gautier : > Dear List, > > I am having trouble with some of the use-cases for a C-written module of my own > (if curious, I am working on Python-R interface... this is open source so I can > provide the whole source if needed). > > Everything is working just fine and as expected... until the python > process exits. > > When running my test script through gdb and with the '-v' flag for > Python, it ends with > --- > # cleanup __main__ > > Program received signal SIGSEGV, Segmentation fault. > [Switching to Thread 0xb7dde8c0 (LWP 19670)] > 0x080f3d08 in PyObject_GC_UnTrack () > > --- > > I have looked for information on the internet... but have not found > much. Would this kind > of error be familiar to anyone ? > > Thanks, > > > Laurent > From rhamph at gmail.com Sat Jun 7 04:14:40 2008 From: rhamph at gmail.com (Adam Olsen) Date: Fri, 6 Jun 2008 20:14:40 -0600 Subject: [capi-sig] Segfault when using own C-written module and exiting python In-Reply-To: <27d1e6020806061240h11661005we0a9ca6a41bd1511@mail.gmail.com> References: <27d1e6020806060331l56474a33i10262000a72c0df@mail.gmail.com> <27d1e6020806061240h11661005we0a9ca6a41bd1511@mail.gmail.com> Message-ID: On Fri, Jun 6, 2008 at 1:40 PM, Laurent Gautier wrote: > I have probably found the problem. I report it here in case someone > has the same issue later. > > In my tp_new I had: > > PyObject_New(MyType, type); > > (and it was working just fine until I started with subclasses) > > while it seems that it should have been: > > type->tp_alloc(type, 0); Do you have Py_TPFLAGS_HAVE_GC set? That'd require you to use PyObject_GC_New, which'd allocate extra space for the tracking flag, and the absence of which would explain the crash. -- Adam Olsen, aka Rhamphoryncus From python_capi at behnel.de Sat Jun 7 15:12:42 2008 From: python_capi at behnel.de (Stefan Behnel) Date: Sat, 07 Jun 2008 15:12:42 +0200 Subject: [capi-sig] Segfault when using own C-written module and exiting python In-Reply-To: <1212754381.9654.8.camel@hot-spring> References: <27d1e6020806060331l56474a33i10262000a72c0df@mail.gmail.com> <484919C8.8000604@egenix.com> <48491E39.90209@behnel.de> <1212754381.9654.8.camel@hot-spring> Message-ID: <484A894A.3010803@behnel.de> Hi, laurent wrote: > On Fri, 2008-06-06 at 13:23 +0200, Stefan Behnel wrote: >> If the existing code base isn't too large yet, consider switching to Cython >> instead of C. > > The C part is only a little more than 2000 lines of source so far > (and with no plan to go much beyond that, it's about feature-complete > for a first release). This might be a good read then: http://permalink.gmane.org/gmane.comp.python.cython.devel/1965 > The CPython project looks very nice. Cython. CPython is the name commonly used for the standard Python implementation. > However, there are potentially dark corners I have to work around (and > so far I am not completely successful at it, as my post suggests Then you should really consider letting Cython give you a hand with the ugly things (like garbage collection or class definition), so that you can concentrate on the more interesting stuff. Stefan From lgautier at gmail.com Sun Jun 8 12:23:40 2008 From: lgautier at gmail.com (Laurent Gautier) Date: Sun, 8 Jun 2008 12:23:40 +0200 Subject: [capi-sig] Segfault when using own C-written module and exiting python In-Reply-To: References: <27d1e6020806060331l56474a33i10262000a72c0df@mail.gmail.com> <27d1e6020806061240h11661005we0a9ca6a41bd1511@mail.gmail.com> Message-ID: <27d1e6020806080323l789451e8qc5291cc799369c68@mail.gmail.com> I stumbled upon some documentation about that (it had to do with circular references, AFAIR)... and I don't think that I have that flag set. I only have: Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE 2008/6/7 Adam Olsen : > On Fri, Jun 6, 2008 at 1:40 PM, Laurent Gautier wrote: >> I have probably found the problem. I report it here in case someone >> has the same issue later. >> >> In my tp_new I had: >> >> PyObject_New(MyType, type); >> >> (and it was working just fine until I started with subclasses) >> >> while it seems that it should have been: >> >> type->tp_alloc(type, 0); > > Do you have Py_TPFLAGS_HAVE_GC set? That'd require you to use > PyObject_GC_New, which'd allocate extra space for the tracking flag, > and the absence of which would explain the crash. > > > -- > Adam Olsen, aka Rhamphoryncus > From lgautier at gmail.com Sun Jun 8 12:34:10 2008 From: lgautier at gmail.com (Laurent Gautier) Date: Sun, 8 Jun 2008 12:34:10 +0200 Subject: [capi-sig] Segfault when using own C-written module and exiting python In-Reply-To: <484A87F5.1090600@behnel.de> References: <27d1e6020806060331l56474a33i10262000a72c0df@mail.gmail.com> <484919C8.8000604@egenix.com> <48491E39.90209@behnel.de> <1212754381.9654.8.camel@hot-spring> <484A87F5.1090600@behnel.de> Message-ID: <27d1e6020806080334m6194f05axf9284461585a08bd@mail.gmail.com> 2008/6/7 Stefan Behnel : > Hi, > > laurent wrote: >> On Fri, 2008-06-06 at 13:23 +0200, Stefan Behnel wrote: >>> If the existing code base isn't too large yet, consider switching to Cython >>> instead of C. >> >> The C part is only a little more than 2000 lines of source so far >> (and with no plan to go much beyond that, it's about feature-complete >> for a first release). > > This might be a good read then: > > http://permalink.gmane.org/gmane.comp.python.cython.devel/1965 > > >> The CPython project looks very nice. > > Cython. CPython is the name commonly used for the standard Python implementation. > Yes. It was just a freudian slip, I suppose. >> However, there are potentially dark corners I have to work around (and >> so far I am not completely successful at it, as my post suggests > > Then you should really consider letting Cython give you a hand with the ugly > things (like garbage collection or class definition), so that you can > concentrate on the more interesting stuff. Yes, I have read the mailing reference in the beginning of your mail... and I'll stick to C given the nature of what I have to do (especially since this is now working ;-) ). > Stefan > >