Skip to content

Commit

Permalink
Fix use of Luabind classes across shared library boundary.
Browse files Browse the repository at this point in the history
Classes registered with Luabind are only valid within that shared library,
but cause segmentation faults if used across shared library boundaries.

Compare types using typeid(T).name() instead of typeid(T)::operator=.

This fixes use of shared libraries with the GCC 3.0 C++ ABI and loaded
using Lua's require(), which does not pass RTLD_GLOBAL to dlopen.

http://gcc.gnu.org/faq.html#dso

The typeid problem has appeared in other C++ libraries, e.g. boost::any.

https://svn.boost.org/trac/boost/ticket/754
https://svn.boost.org/trac/boost/changeset/56168
  • Loading branch information
Peter Colberg authored and Oberon00 committed Jun 30, 2013
1 parent 950e1e3 commit a83af3c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions luabind/typeid.hpp
Expand Up @@ -6,6 +6,7 @@
# define LUABIND_TYPEID_081227_HPP

# include <boost/operators.hpp>
# include <cstring>
# include <typeinfo>
# include <luabind/detail/primitives.hpp>

Expand Down Expand Up @@ -33,17 +34,17 @@ class type_id

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
Expand Down

0 comments on commit a83af3c

Please sign in to comment.