Dynamic Cast failed over multiple modules

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Dynamic Cast failed over multiple modules

Holger Brandsmeier
Dear List,

when I use dynamic cast from two boost modules on a class with "vague
linkage", in my real use case a template in the simplified example I
show you a class which is declared inline, then the dynamic cast fails
in the second module.

So when I call the code from python from the first module (in which
the Vertex object has been created), then the dynamic cast succeeds:

"calling performTest(m) ...
I am a Vertex"

but when I do the same from the other module, then I get

"calling performTest2(m) ...
dynamic cast failed, I got the object:
I am a Vertex"

I attached a very simple example in the files:
  bugDynamicCastSimplified.h (declares the Classes VerboseObject,
Vertex and Mesh)
  bugDynamicCastPy.cpp (first boost module)
  bugDynamicCast2Py.cpp (second boost module)

The problem dissapears without the vague linkage, e.g. when you define
REMOVE_INLINE_DEFINITION in the code. This is not a very nice  option
for me, as in my real use case Vertex is a template, and this would
force me to initialize it for each type.

My gcc is:
> g++ --version
g++ (Gentoo 4.4.5 p1.2, pie-0.4.5) 4.4.5

And I am building the project with cmake (not boost). I read the FAQ
entry at http://gcc.gnu.org/faq.html#dso and added "-Wl,-E" to
CMAKE_SHARED_LINKER_FLAGS. About the RTLD_GLOBAL flag for dlopen, I
don't know how python handles this.

Do you have any ideas how to solve this? Or is this simply not
possible with python?

-Holger

_______________________________________________
Cplusplus-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/cplusplus-sig

bugDynamicCastSimplified.h (1K) Download Attachment
bugDynamicCastPy.cpp (344 bytes) Download Attachment
bugDynamicCast2Py.cpp (294 bytes) Download Attachment
bugDynamicCastSimplified.cpp (212 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic Cast failed over multiple modules

Mathieu Malaterre
On Thu, Sep 8, 2011 at 11:56 AM, Holger Brandsmeier <[hidden email]> wrote:
[...]
> CMAKE_SHARED_LINKER_FLAGS. About the RTLD_GLOBAL flag for dlopen, I
> don't know how python handles this.
>
> Do you have any ideas how to solve this? Or is this simply not
> possible with python?

Here is what I use:

if os.name == 'posix':
  orig_dlopen_flags = sys.getdlopenflags()
  try:
    import dl
  except ImportError:
    try:
      import DLFCN as dl
    except ImportError:
      dl = None
  if dl:
    sys.setdlopenflags(dl.RTLD_NOW|dl.RTLD_GLOBAL)
  # now load the module !
  from gdcmswig import *
  sys.setdlopenflags(orig_dlopen_flags)
  del dl
  del orig_dlopen_flags


ref:
http://gdcm.git.sourceforge.net/git/gitweb.cgi?p=gdcm/gdcm;a=blob;f=Wrapping/Python/gdcm.py;h=fd7ee0da80297d608c2939b8661ce0e81c33314a;hb=HEAD

--
Mathieu
_______________________________________________
Cplusplus-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/cplusplus-sig
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic Cast failed over multiple modules

Holger Brandsmeier
Mathieu,

thank you very much. This is exactly what I was still missing.

-Holger

On Thu, Sep 8, 2011 at 12:00, Mathieu Malaterre
<[hidden email]> wrote:

> On Thu, Sep 8, 2011 at 11:56 AM, Holger Brandsmeier <[hidden email]> wrote:
> [...]
>> CMAKE_SHARED_LINKER_FLAGS. About the RTLD_GLOBAL flag for dlopen, I
>> don't know how python handles this.
>>
>> Do you have any ideas how to solve this? Or is this simply not
>> possible with python?
>
> Here is what I use:
>
> if os.name == 'posix':
>  orig_dlopen_flags = sys.getdlopenflags()
>  try:
>    import dl
>  except ImportError:
>    try:
>      import DLFCN as dl
>    except ImportError:
>      dl = None
>  if dl:
>    sys.setdlopenflags(dl.RTLD_NOW|dl.RTLD_GLOBAL)
>  # now load the module !
>  from gdcmswig import *
>  sys.setdlopenflags(orig_dlopen_flags)
>  del dl
>  del orig_dlopen_flags
>
>
> ref:
> http://gdcm.git.sourceforge.net/git/gitweb.cgi?p=gdcm/gdcm;a=blob;f=Wrapping/Python/gdcm.py;h=fd7ee0da80297d608c2939b8661ce0e81c33314a;hb=HEAD
>
> --
> Mathieu
> _______________________________________________
> Cplusplus-sig mailing list
> [hidden email]
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>
_______________________________________________
Cplusplus-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/cplusplus-sig