[luabind-cvs] luabind/luabind/luabind/detail policy.hpp,1.53,1.54
Brought to you by:
arvidn,
daniel_wallin
From: Arvid N. <ar...@us...> - 2005-12-21 23:09:56
|
Update of /cvsroot/luabind/luabind/luabind/luabind/detail In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32481/luabind/luabind/detail Modified Files: policy.hpp Log Message: fixed problem with returning const-references to abstract classes. The const_reference_policy was copying the objects. Also added a test to verify that the fix actually works Index: policy.hpp =================================================================== RCS file: /cvsroot/luabind/luabind/luabind/luabind/detail/policy.hpp,v retrieving revision 1.53 retrieving revision 1.54 diff -u -d -r1.53 -r1.54 --- policy.hpp 10 Dec 2005 16:52:54 -0000 1.53 +++ policy.hpp 21 Dec 2005 23:09:47 -0000 1.54 @@ -853,7 +853,7 @@ typedef const_ref_converter type; template<class T> - void apply(lua_State* L, const T& ref) + void apply(lua_State* L, T const& ref) { if (luabind::get_back_reference(L, ref)) return; @@ -864,32 +864,12 @@ // trying to use an unregistered type assert(crep && "you are trying to use an unregistered type"); + T const* ptr = &ref; - void* obj_rep; - void* held; - - boost::tie(obj_rep,held) = crep->allocate(L); - - void* object_ptr; - void(*destructor)(void*); - destructor = crep->destructor(); - int flags = 0; - if (crep->has_holder()) - { - flags = object_rep::owner; - new(held) T(ref); - object_ptr = held; - if (LUABIND_TYPE_INFO_EQUAL(LUABIND_TYPEID(T), crep->const_holder_type())) - { - flags |= object_rep::constant; - destructor = crep->const_holder_destructor(); - } - } - else - { - object_ptr = new T(ref); - } - new(obj_rep) object_rep(object_ptr, crep, flags, destructor); + // create the struct to hold the object + void* obj = lua_newuserdata(L, sizeof(object_rep)); + assert(obj && "internal error, please report"); + new(obj) object_rep(const_cast<T*>(ptr), crep, object_rep::constant, 0); // set the meta table detail::getref(L, crep->metatable_ref()); |