[Python-Dev] Problems with Python's default dlopen flags

Jack Jansen Jack.Jansen@oratrix.com
Mon, 6 May 2002 00:09:33 +0200

On zondag, mei 5, 2002, at 11:08 , David Abrahams wrote:

> From: "Jack Jansen" <Jack.Jansen@oratrix.com>
>> On zondag, mei 5, 2002, at 09:26 , Martin v. Loewis wrote:
>>>> And in fact, I expect to ask users to do something special, like
>>>> explicitly linking between extension modules
>>> Indeed, that should also work fine - if users explicitly link
>>> extension modules against each other, they should be able to share
>>> symbols.
>>  From experience I can say this is not a good idea. MacOS
>> extension modules used to do this until Python 1.5.2, and it can
>> have undesired side effects (similar to the C++ initializer
>> problems you noted). If you need to communicate symbols between
>> module A and B it's better to make a normal shared library
>> ABglue.so which contains the glue code, and link both A and B
>> against it. The only question is where to put the ABglue.so
>> file,
> That's hardly the only question:
> If A needs to throw an exception which is caught in B, what is 
> "the glue
> code" that you put in ABglue.so?
> If a class with inlined virtual functions is used by A with subclasses
> defined in B, what is the "glue code"?
> What about templates? ;-)  (vague, but relevant)

Well, you're now going into territory where I'm not really 
familiar, C++, and more precisely it's runtime system on various 
platforms (especially the stuff with zero-overhead runtimes and 
such tends to make my head explode), but I would guess that if 
you take the code from A that declares symbols used by B and 
vice versa and move that to a common ancestor you should be done.

If all else fails you could even take the whole A module except 
the init routine and stuff it in Acore.so, similarly for B, link 
Acore.so against Bcore.so and vice versa and have the A and B 
modules be skeletons with just the init routine. That way you 
know that your Acore and Bcore will be loaded via the normal 
shared library loading method, which probably handles 
initializers and cross-segment exceptions correctly,
- Jack Jansen        <Jack.Jansen@oratrix.com>        
http://www.cwi.nl/~jack -
- If I can't dance I don't want to be part of your revolution -- 
Emma Goldman -