lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Hi All,
 Sorry for the annoyance, but had anybody tested this? I would like
to know if this results are reproducible, I'm really concerned about
Lua and C++ (+RTTI) integration.

BTW I've been told to give a reason to use RTLD_GLOBAL (and here it
is, basically this can lead to invalid C++ library behaviors when
loaded into lua, *only in linux* not in windows) but I can not
understand why it shouldn't be used, reading the documentation about
RTLD_GLOBAL flag I can not see anything dangerous.

I swear not talk about this topic again :)

  Jose L.

*only in linux* == in fact is a GCC > 3.0 "problem"

2007/3/30, Jose Luis Hidalgo <>:
> Not now, because this is not a bug. Also, I'm still not convinced that
> using RTLD_GLOBAL is a good thing, on the contrary, and others seemed
> to agree. Your application has quite specific needs.

Well, from the mail:

Let's remember that gcc since 3.0 version uses address comparisons to
determine type equality, so a very big part of the C++ RTTI mechanism
( typeid, dynamic_casts, ...) relies on this. I've made a test, you
can download here:

Basically there is a type "Common<class T>", and as a template it is
implemented in the header of  "common.hpp", two fictitious libraries
"m1" and "m2" use the "common" library and instances the template with
a float. Actually, Common<float> should be the SAME type in both
dll... but it is not because how libraries where loaded.

This will not be a very big deal, but in Windows lua has the correct
behavior, (in windows the type check is not done based on the typeid
pointers). So, for me, different non portable behaviors between
platforms is some kind of bug...

This is the Example (lua code) :

require("m1") -- loads m1
require("m2") -- loads m2
print( -- info about common<float> type (at m1)
print( -- info about common<float> type (at m2)

obj1 = m1.get() -- get the typeid(common<float>) from m1
obj2 = m2.get() -- get the typeid(common<float>) from m2
m2.check(obj1) -- check if typeid are the same (at m2 lib), should be
"1" for correct RTTI
m1.check(obj2) -- check if tyepid are the same (at m1 lib)

This is the output :

On Windows ( VS8/lua/lua5.1.exe )
Lua 5.1.1  Copyright (C) 1994-2006, PUC-Rio
> dofile("../../test.lua")
Creating an object...
Creating an object...
m1:typeid = 003AC04C typename = class Common<float> * Base = 003AC06C
m2:typeid = 0043C04C typename = class Common<float> * Base = 0043C06C
Check = 1
Check = 1
On Linux standard lua
Creating an object...
Creating an object...
m1:typeid = 0xb7eeb79c typename = P6CommonIfE Base = 0xb7eeb794
m2:typeid = 0xb7cef79c typename = P6CommonIfE Base = 0xb7cef794
Check = 0
Check = 0
On Linux modified lua (RTLD_GLOBAL)
Creating an object...
Creating an object...
m1:typeid = 0xb7fa879c typename = P6CommonIfE Base = 0xb7fa8794
m1:typeid = 0xb7fa879c typename = P6CommonIfE Base = 0xb7fa8794
Check = 1
Check = 1

The "Checks" are comparisons between the same types from -> and from -> ... "0" means they are not the same
type, "1" means they are.  As you can see, the vanilla lua interpreter
in windows has not the same behavior as Linux, but adding the
RTLD_GLOBAL everything is correct at both platforms.

 Jose L. Hidalgo Valiño (PpluX)
 ---- ----