[Pythonmac-SIG] dlopenflags and sharing symbols across python extension modules
Zachary Pincus
zpincus at stanford.edu
Sun Mar 5 08:46:51 CET 2006
Hi folks,
I have a tricky issue with some python extension modules that need to
share symbols between themselves.
The setup: I am creating python modules to wrap a large template-
based C++ image processing library. The fundamental class that each
of these modules needs to be able to create, pass around, and
dynamic_cast from and to, is a templated image type.
This requires that at module load time, the C++ typeinfo objects
describing the template instantiations of that class be loaded into
the global symbol table and shared between all of the modules.
Otherwise, each module will have its own typeinfo object for the
class, causing dynamic_cast and other comparisons of object identity
to fail (because GCC uses the address of the typeinfo object to make
such comparisons).
I compiled the modules so that all the symbols are visible (nm -m
tells me that the tyepinfo symbols are all declared as 'weak
external', which is what they should be for sharing between modules).
Before I load the modules in Python, I call sys.setdlopenflags(0xA),
which is RTDL_NOW|RTDL_GLOBAL, as these constants are defined in
dlfcn.h on OS X.
This is what I have been told is necessary and sufficient for this to
work, yet somehow it is not working for me. When a collaborator
compiles this all on Linux with GCC, things work for him (note that
his dlopenflags are 0x102, which corresponds to RTDL_NOW|RTDL_GLOBAL
on his system).
Has anyone else wrestled with these issues? Does python not respect
sys.setdlopenflags() on OS X in some cases? Is there anything else I
should try to do?
I'm on OS X 10.4.5, using python 2.4.1 compiled as a framework (built
with GCC4, as are all of the modules I'm working on).
Any help or suggestions or thoughts would be greatly appreciated,
Zach Pincus
Program in Biomedical Informatics and Department of Biochemistry
Stanford University School of Medicine
More information about the Pythonmac-SIG
mailing list