Fix importing CoreFoundation on OSX 10.4 (Tiger) when using a newer SDK.
PyObjC binaries fail to load on 10.4 if they were built against the 10.5 SDK,
even if -mmacosx-version-min=10.4 was set, because they're still linked to
symbols from CFFileDescriptor, which was introduced in OS X v10.5.
The error happens when the CoreFoundation module is imported, and the backtrace
looks something like this:
File "CoreFoundation/_CoreFoundation.pyc", line 11, in __load
portError: dlopen([...]/lib-dynload/CoreFoundation/_CoreFoundation.so, 2): Symbol not found: _CFFileDescriptorCreate
Referenced from: [...]/lib-dynload/CoreFoundation/_CoreFoundation.so
Expected in: /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
To fix this, we weakly link against the missing APIs using "#pragma weak" and
then remove the corresponding Python wrappers at runtime when we detect that
the underlying C functions aren't available. It's a bit gross, but it's
probably worse to try to mimic Py_InitModule*, which is "a bit of a hack"
according to its source code.
This way, users can write code like this:
from CoreFouncation import CFFileDescriptorCreate
CFFileDescriptor_avail = True
CFFileDescriptor_avail = False
CFFileDescriptor_avail = hasattr(CoreFoundation, "CFFileDescriptorCreate")
In the above examples, CFFileDescriptor_avail will be True on OSX 10.5+ and