Re: Illegal instruction on layers of callback wrappers
Thomas Stover <[email protected]> Fri, 13 May 2011 12:29:51 -0500
| Newsgroups | gmane.comp.python.ctypes |
|---|---|
| Message-ID | <[email protected]> |
On Thu, 12 May 2011 18:01:09 -0500, Thomas Stover <[email protected]> wrote: For the searchers and list miners, I figured it out. > > def __init__(self, callback_variable): ... > callback = CALLBACK_TYPE(self.CallbackWrapper) > self.use_callback(self.callback) It's hard to mix C and Python and not think like C. Anyway, here the variable "callback" is not like a C pointer, it is an object that provides the shim, context, etc. Sense the variable is local to the __init__() function, it is dereferenced and freed. Changing that to self.callback will hold the reference and everything works fine. It makes sense that there would be no way ctypes would know to increase that reference count just by handing C a callback, because that would leak in most cases without an explicit "not needed anymore" notation. Darn high-level language interpretation! I like it too, but sometimes on stuff like this, the lines saved from C's verbosity, are just moved onto all the things you have to keep track of in your mind. :) -- www.thomasstover.com FLYNN LIVES! ------------------------------------------------------------------------------ Achieve unprecedented app performance and reliability What every C/C++ and Fortran developer should know. Learn how Intel has extended the reach of its next-generation tools to help boost performance applications - inlcuding clusters. http://p.sf.net/sfu/intel-dev2devmay