Re: [ctypes-users] Casting, Pointers, and OOR
Brought to you by:
theller
From: Mark G. <mar...@sy...> - 2007-11-29 14:34:33
|
I went back to double check and it looks like I was keeping a reference to the CFUNCTYPE not the callback function. I added this and my errors appeared to go away. Thanks for the help and sorry for the easy mistake. --Mark On 11/28/07, Lenard Lindstrom <le...@te...> wrote: > You do keep the callback alive with a Python reference, right? > > Lenard > > Mark Guagenti wrote: > > I went ahead and built a debug version of python 2.5.1 and ran a non > > wxpython version of my script and got it to fail as well. The > > exception appears to be occurring at: > > _ctypes_d.pyd!ffi_closure_SYSV(ffi_closure * closure=0x0153ff00, int * > > argp=0x0098278c) Line 243 + 0x1b > > > > --Mark > > > > On 11/28/07, Mark Guagenti <mar...@sy...> wrote: > > > >> On 11/28/07, Lenard Lindstrom <le...@te...> wrote: > >> > >>> Also, calling d.onData does not return control to the main thread, if > >>> that is the intension. Execution leaves the callback thread only when > >>> the callback returns. So it could be a threading problem with wx. > >>> > >> I thought wx.CallAfter would ensure that processing the data would > >> occur in the main thread of the application which in my case is the wx > >> GUI thread? > >> > >> I added the check you suggest and it appears that I am not getting a > >> null pointer. Here is an updated cooked down example: > >> > >> #Functype for dllCallback passed to DLL > >> recvType = ctypes.CFUNCTYPE(None, ctypes.c_ubyte, ctypes.c_void_p) > >> > >> class DllWrap(object): > >> ... > >> def dllCallback(self, dev, msg): > >> if not msg: > >> print "ERROR no msg!" > >> return > >> > >> data = ctypes.cast(msg, ctypes.POINTER(ctypes.c_char)) > >> > >> if not data: > >> print "ERROR no data!" > >> return > >> > >> len = int(binascii.hexlify(data[4]), 16) > >> b.onData(data[:len]) > >> dll.Free(dev, msg) > >> > >> class B(wx.grid.Grid): > >> ... > >> def onData(self, data): > >> wx.CallAfter(self.processData, data) > >> > >> def processData(self, data): > >> ... #Add data to grid > >> > >> > > > > > > > ------------------------------------------------------------------------- > SF.Net email is sponsored by: The Future of Linux Business White Paper > from Novell. From the desktop to the data center, Linux is going > mainstream. Let it simplify your IT future. > http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4 > _______________________________________________ > ctypes-users mailing list > cty...@li... > https://lists.sourceforge.net/lists/listinfo/ctypes-users > |