logo       

Re: Using ctypes to access OS X frameworks: msg#00017

python.ctypes

Subject: Re: Using ctypes to access OS X frameworks


On Oct 15, 2004, at 1:20 PM, Thomas Heller wrote:

I have been asked in private email if ctypes can be used to access OS X
frameworks. I googled around a bit and found these pages:

http://developer.apple.com/samplecode/CallMachOFramework/ CallMachOFramework.html

http://developer.apple.com/samplecode/CallMachOFramework/listing2.html

Remember that I know nearly nothing about macs, but by reading these
pages I got the impression that the key functions here are
LoadFrameworkBundle() and CFBundleGetFunctionPointerForName(), which
seem to play roles similar to dl_open()/dl_sym() or
LoadLibrary()/GetProcAddress().

All of the function lookup code in OS X nomatter which API it's from boils down to dyld. libdl is implemented as a shim over top of dyld, so ctypes can already be used to load code from frameworks. All you have to do is point it at the code in the bundle, which is always Foo.framework/Versions/Current/Foo .. as opposed to libfoo.so on other platforms.

Apart from that, I really do not know if this is a niche covered by
PyObjC, or would ctypes have a place here?

PyObjC in SVN does wrap CFBundleGetFunctionPointer for name (objc.loadBundleFunctions, IIRC) and can do some, not all, of the things that ctypes does. It's primarily useful if you're calling into functions that are CoreFoundation based, or deal with very basic types (integers, floats, simple structures, etc.).

Here is an example that uses PyObjC to do something ctypes-like. Note that it's a lot less ugly if the functions are shoved into globals.. but I wanted to make sure all of the functions exist at runtime because CPS is undocumented private SPI and may disappear in the future.

http://svn.red-bean.com/pyobjc/trunk/pyobjc/Examples/wmEnable.py

I've been meaning to experiment with ctypes more on OS X, but I have simply been too busy :(

-bob


-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise