[IronPython] IronPython 2.6.1 & ctypes, C library, and debugging with VS2008
TP
wingusr at gmail.com
Sun Jul 18 18:44:36 CEST 2010
I'm using IronPython 2.6.1 for Net 2.0 and VS2008 on Windows XP SP3.
I have a python script that lets me access the Leptonica Image
Processing C library (http://leptonica.com/) using the ctypes module.
Everything seems to work fine with cpython 2.6. I can correctly load
leptonlib.dll, create leptonica PIX images, manipulate them, and even
display them using PyQT. I can use VS2008 to put breakpoints on
leptonica C functions and step through the C code in the VS2008
debugger.
I thought I'd give IronPython a try since it also has ctypes, but I
ran into a number of problems.
The leptonlib.dll must be loading since I am able to correctly get
back the library's version string. That is the following works:
_getLeptonlibVersion = _leptonlib.getLeptonlibVersion
_getLeptonlibVersion.restype = ctypes.c_void_p
addr = _getLeptonlibVersion()
version = ctypes.string_at(addr)
However the following code doesn't seem to work under IronPython 2.6.1:
pix = Pix(dimensions=(10,20,1))
where essentially the following is called:
_pix = ctypes.c_void_p()
_pix.value = _leptonlib.pixCreate(width, height, depth)
self._pix = _pix
and I want to treat _pix as an opaque ptr I just hand back to
leptonica whenever it needs it. For example:
def height(self):
"""Get height of pix in pixels."""
return _leptonlib.pixGetHeight(self._pix)
Which works with cpython but returns something other than 20 with IronPython.
By specifying "-X:Debug -X:FullFrames -X:Tracing leptonica.py" as the
arguments to C:\Program Files\IronPython 2.6\ipy.exe I can get
IronPython to correctly stop at places in my script where I put:
import pdb
pdb.set_trace()
when I debug leptonlibd.dll with VS2008. However, my breakpoints on
leptonica's C functions never seem to get hit. This works fine if I
instead use python26.exe as command to launch when debugging.
Ideally I like to have the VS Debugger stop in leptonlibd.dll's
pixCreate() C function just before it returns its value so I can
compare that to what I get back on the IronPython side.
So how's does one use VS2008 to step through C functions in DLLs that
are loaded by IronPython and the ctypes module?
Secondly, am I using ctypes wrong, and does my code only work by
happenstance for cpython.
More information about the Ironpython-users
mailing list