[PyKDE] New PyKDE Release (alpha6) and Killing PyKDE 3.8

David Boddie david at boddie.org.uk
Tue Apr 27 13:39:00 BST 2004


On Tuesday 27 April 2004 08:22, Simon Edwards wrote:

> Anyway, answer lies on the dlopen() man page:
>
>     Optionally, RTLD_GLOBAL may be or'ed with flag,  in  which  case
>     the  external  symbols defined in the library will be made available to
>     subsequently loaded libraries.

I'm ahead of you here. ;-) The custom version of libpythonize I was using
with PyKDE 3.8 did this to allow me to do things like embedding a console in
Konqueror. I thought I sent you and Jim my changes...

> When kcontrol loads a module, it uses dlopen() load in the our python stub.
> The stub loads and libpython gets pulled in too. Then later the python
> interpreter uses dlopen() too to load time.so (or some other module). Then
> it fails. The reason being that kcontrol does _not_ use RTLD_GLOBAL when
> opening our module stub, so libpython gets loaded but its symbols are _not_
> made available to the next dlopen() call (the one for the module import).
> That is why an imported module can't resolve symbols from libpython.

Strangely, this strategy actually worked before. Unfortunately, upgrading to
the latest sip, PyQt and PyKDE has broken it. I'm wondering what I've
changed, or failed to change in the build system. I may install PyKDE 3.8
with a separate Python interpreter to check its old behaviour.

> Now, why does David's workaround actually work? When you link the kcontrol
> module stub against the time.so python module, the linker specifies in the
> generated module stub that time.so should also be loaded when loading the
> stub (along with libpython). So when kcontrol loads the stub, libpython
> gets pulled in and also time.so _at the same time_. And everything resolves
> correctly. Later python uses dlopen() to load time.so. dlopen() sees that
> time.so is already loaded and just happily goes on its merry way and life
> is good...

Thanks for the explanation. It's interesting to hear how it works;
particularly the parts describing when things are actually loaded.

> For bonus points: Is it possible to make a kcontrol module stub that loads
> libpythonize and libpython using dlopen(), but with the RTLD_GLOBAL flag
> set so that dlopen() in the python interpreter will work as expected? I
> guess I'll have to try that out... :-)

You just link in libpythonize at compile time, don't you?

> (BTW, linking with -export-dynamic -Wl,-E doesn't seem to have much effect)

I'll tidy up what I have and send it to you. Maybe I'll get around to hacking
on it again this weekend.

Have fun,

David




More information about the PyQt mailing list