[New-bugs-announce] [issue17310] Ctypes callbacks shows problem on Windows Python (64bit)

Matt Clarke report at bugs.python.org
Wed Feb 27 16:51:14 CET 2013

New submission from Matt Clarke:

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.

components: ctypes
files: code.txt
messages: 183156
nosy: Matt.Clarke
priority: normal
severity: normal
status: open
title: Ctypes callbacks shows problem on Windows Python (64bit)
type: behavior
versions: Python 2.7
Added file: http://bugs.python.org/file29265/code.txt

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list