[Pythonmac-SIG] cyptes problem on MacOS X

Shane Holloway shane.holloway at ieee.org
Tue Jan 2 07:50:00 CET 2007


Russel,

Sorry I have been away from this list a while.  I have been using  
ctypes on Mac OSX with both PPC and Intel for about a year and a half  
now.  They work great, as I am regularly interfacing with Quicktime,  
CoreVideo, and CoreImage, as well as the OpenGL and OpenAL  
frameworks.  We have even been working with the Freetype2 libraries,  
and some various 3rd party vendor libraries.

I think the problem you are having is more about interfacing with C  
var-args in the printf function, and less a platform problem.  (None  
of the APIs I work with use varargs)  We are having great success  
interfacing with system libraries using ctypes.  Numpy makes a great  
ally when working with large quantities of data.

The hardest part of your work will be interfacing with C++ code,  
mainly because C++ name mangling for methods is not standardized.   
Your best bet is to look for their external facing API, which are  
usually exposed in non-name-mangled C.  The GCCXML (compiled from  
latest source) project does a pretty good job of finding mangled C++  
entry points for various compiler toolchains, but your milage may vary.

Hope that helps a bit,
-Shane Holloway

On Dec 11, 2006, at 1:20 PM, Russell E. Owen wrote:

> I've been trying out ctypes (from MacPython 2.5) on MacOS X on a  
> PPC Mac
> and have run into a problem. I hope I'm just doing something  
> stupid, but
> it seems to match the tutorial so I'm really puzzled:
>
> import ctypes
> libc = ctypes.CDLL("libc.dylib")
> libc.printf("int=%d float=%f double=%f\n", ctypes.c_int(1),
> ctypes.c_float(2.0), ctypes.c_double(3.0));
>
> results in:
> int=1 float=-1.996124 double=0.000000
>
> I realize the docs doesn't actually claim to handle dylib files, but
> I've seen at least some info on the web that claims it works. One site
> suggested the need for ctypes.RTLD_GLOBAL to CDLL but adding it  
> made no
> difference.
>
> On a related subject...assuming I can get this to work...does anyone
> have any idea how the speed of ctypes relates to programming a  
> python C
> extension or using SWIG? This is mostly for use with NumPy and
> interfacing python to C/C++-based heavy duty astronomical image
> processing code.
>
> Other suggestions are welcome. We'll mostly be interfacing to C++ so
> I've considered trying out Boost, but it hasn't had an update in years
> which worries me. Robustness, ease of use and speed are all major
> requirements. Linux and MacOS X are the main platforms.
>
> -- Russell
>
> _______________________________________________
> Pythonmac-SIG maillist  -  Pythonmac-SIG at python.org
> http://mail.python.org/mailman/listinfo/pythonmac-sig



More information about the Pythonmac-SIG mailing list