This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Matt.Clarke
Recipients Matt.Clarke
Date 2013-02-27.15:51:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1361980274.18.0.791136497364.issue17310@psf.upfronthosting.co.za>
In-reply-to
Content
I have had an issue arise with ctypes callbacks with 64bit Python on Windows.
Note: everything works fine with 32bit Python on Windows and on 32bit and 64bit Linux.

I have created a simple example to illustrate the issue I have (see attachment), but the real-life issue occurs with using Python to interact with the EPICS control software (http://www.aps.anl.gov/epics/) used at many major scientific institutes.

Basically, if I have a C callback that takes a struct (by value) greater than 8 bytes then the callback returns nonsense. 8 bytes or less works fine.

Stepping through with the Windows debugger, if appears that something goes amiss between the callback being called in C and the closure_fcn(ffi_cif *cif, void *resp, void **args, void *userdata) function in ctypes's callback.c file. Unfortunately, the debugger won't let me step in between those two points.

Looking at the memory I can see the original data in memory at some memory address, X, and a copy of the data at X+40 bytes, but the args in the closure_fcn points at X-40 bytes (which is junk).

Using 32bit Python the data copy is at X-40 bytes and the args pointer in the closure_fcn also points at this.

EPICS has some 64bit C/C++ clients that work fine using callbacks on Windows. Likewise, doing the same sort of thing as ctypes does with EPICS from C# using PInvoke works fine.
 
Any help would be much appreciated.
History
Date User Action Args
2013-02-27 15:51:14Matt.Clarkesetrecipients: + Matt.Clarke
2013-02-27 15:51:14Matt.Clarkesetmessageid: <1361980274.18.0.791136497364.issue17310@psf.upfronthosting.co.za>
2013-02-27 15:51:14Matt.Clarkelinkissue17310 messages
2013-02-27 15:51:13Matt.Clarkecreate