Re: Sharing a lua_State across DLL boundary

Peter Colberg <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
Hi Julien,

not sure if this applies to Windows and DLLs, too, but I had a similar
experience with GCC and shared modules on Linux: classes registered
with Luabind where only valid within that shared library, but caused
segmentation faults if used across shared library boundaries.

The solution was to patch the luabind::type_id class, and compare
using typeid(T).name() instead of typeid(T)::operator=. For GCC, the
reason why the typeid operator might not work across shared libraries
is explained here [1]. In this particular case, I loaded the shared
library with Lua's require(), which, unfortunately, does not pass
RTLD_GLOBAL to dlopen.

[1] http://gcc.gnu.org/faq.html#dso

The typeid equality problem has appeared in other C++ libraries, e.g.
in boost::any[2], with the same fix[3], typeid(T).name() comparison.

[2] https://svn.boost.org/trac/boost/ticket/754
[3] https://svn.boost.org/trac/boost/changeset/56168

Maybe the attached patch helps in the case of DLLs, too.

Peter

------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network 
management toolset available today.  Delivers lowest initial 
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd

_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user
luabind_type_id_across_shared_libraries.patch (text/x-diff, 786 B)
--- include.orig/luabind/typeid.hpp
+++ include/luabind/typeid.hpp
@@ -6,6 +6,7 @@
 # define LUABIND_TYPEID_081227_HPP
 
 # include <boost/operators.hpp>
+# include <cstring>
 # include <typeinfo>
 # include <luabind/detail/primitives.hpp>
 
@@ -33,17 +34,17 @@
 
     bool operator!=(type_id const& other) const
     {
-        return *id != *other.id;
+        return std::strcmp(id->name(), other.id->name()) != 0;
     }
 
     bool operator==(type_id const& other) const
     {
-        return *id == *other.id;
+        return std::strcmp(id->name(), other.id->name()) == 0;
     }
 
     bool operator<(type_id const& other) const
     {
-        return id->before(*other.id);
+        return std::strcmp(id->name(), other.id->name()) < 0;
     }
 
     char const* name() const
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.