Boost logo

Boost Users :

Subject: Re: [Boost-users] [Boost.serialization] unexpected bad_cast exception while deserializing some arbitrary instances (e.g.: ar & data) ...
From: troy d. straszheim (troy_at_[hidden])
Date: 2009-05-28 07:53:49


François Mauger wrote:
> Hi Troy,
>
>> You could try adding this to the top of your script:
>>
>> import dl
>> import sys
>> flags = sys.getdlopenflags()
>> sys.setdlopenflags(flags | dl.RTLD_GLOBAL)
>>
>
> Great! It works (at least no problem appeared after several trial)!
> Thank you very much. I was so desesperate!
> It seems also that I should use this 'trick' within my former
> work: it has probably worked for monthes only by chance!

We (IceCube) use this combination of serialization and python bindings
on a large
scale on linux/osx/fbsd with good results. I wouldn't be too afraid.

> Now I got a solution, may I dare ask you an explanation
> about this issue?
> I'm rather unskilled with this 'dl' stuff. What I don't understand
> is why my code was working in some case and not in another one, despite
> the fact that imported wrapper modules were the same.
> Does it have to do with some unpredictable dynamic loading
> of symbols depending of the Python running context? Do you think this
> issue would appear also under Darwin (the other target OS for my libs)?

You can look at the what the flags RTLD_GLOBAL and RTLD_LOCAL do in a
call to dlopen() (manpage). It is worth writing some test cases and
really learning what is happening. By default a python 'import' uses
RTLD_LOCAL (use strace and see for yourself); the voodoo above sets the
default to RTLD_GLOBAL, as you can probably guess. There is also a
paper called "how to write shared libraries" by Ulrich Drepper with lots
of good background information in it.

Another thing to play with: force an RTLD_GLOBAL load of the wrapped
shared library by calling dlopen("libwrappedlib.so", RTLD_NOW |
RTLD_GLOBAL) inside the BOOST_PYTHON_MODULE(wrappedlib) { ... } function.

-t


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net