[Pythonmac-SIG] cyptes problem on MacOS X

Russell E. Owen rowen at cesmail.net
Mon Dec 11 21:20:23 CET 2006

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 

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

More information about the Pythonmac-SIG mailing list