From 82554f581957a6d844b3210ddad8a155125205ab Mon Sep 17 00:00:00 2001 From: nitrocaster Date: Sun, 6 Dec 2015 12:53:51 +0300 Subject: [PATCH 1/4] Revert f1fe251, need better solution. This commit reverts f1fe251cee7bad18d42fb77e60638d5e7f900a2f. --- luabind/detail/object_rep.hpp | 2 +- src/object_rep.cpp | 29 +++++++++-------------------- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/luabind/detail/object_rep.hpp b/luabind/detail/object_rep.hpp index 63a15296..3fa585f5 100644 --- a/luabind/detail/object_rep.hpp +++ b/luabind/detail/object_rep.hpp @@ -52,7 +52,6 @@ namespace luabind { void set_instance(instance_holder* instance) { m_instance = instance; } void add_dependency(lua_State* L, int index); - void release_dependency_refs(lua_State* L); std::pair get_instance(class_id target) const { @@ -99,6 +98,7 @@ namespace luabind { std::aligned_storage<32>::type m_instance_buffer; class_rep* m_classrep; // the class information about this object's type std::size_t m_dependency_cnt; // counts dependencies + detail::lua_reference m_dependency_ref; // reference to lua table holding dependency references }; template diff --git a/src/object_rep.cpp b/src/object_rep.cpp index 86e99dde..d3a2bbe1 100644 --- a/src/object_rep.cpp +++ b/src/object_rep.cpp @@ -37,7 +37,7 @@ namespace luabind { namespace detail object_rep::object_rep(instance_holder* instance, class_rep* crep) : m_instance(instance) , m_classrep(crep) - , m_dependency_cnt(0) + , m_dependency_cnt(1) { } @@ -51,28 +51,18 @@ namespace luabind { namespace detail void object_rep::add_dependency(lua_State* L, int index) { - assert(m_dependency_cnt < sizeof(object_rep)); - - void* key = (char*)this + m_dependency_cnt; - - lua_pushlightuserdata(L, key); + if (!m_dependency_ref.is_valid()) + { + lua_newtable(L); + m_dependency_ref.set(L); + } + m_dependency_ref.get(L); lua_pushvalue(L, index); - lua_rawset(L, LUA_REGISTRYINDEX); - + lua_rawseti(L, -2, m_dependency_cnt); + lua_pop(L, 1); ++m_dependency_cnt; } - void object_rep::release_dependency_refs(lua_State* L) - { - for (std::size_t i = 0; i < m_dependency_cnt; ++i) - { - void* key = (char*)this + i; - lua_pushlightuserdata(L, key); - lua_pushnil(L); - lua_rawset(L, LUA_REGISTRYINDEX); - } - } - int destroy_instance(lua_State* L) { object_rep* instance = static_cast(lua_touserdata(L, 1)); @@ -90,7 +80,6 @@ namespace luabind { namespace detail lua_call(L, 1, 0); } - instance->release_dependency_refs(L); instance->~object_rep(); lua_pushnil(L); From b7b2bdb62368b66ed4973b262b9e7918b0fbdab7 Mon Sep 17 00:00:00 2001 From: nitrocaster Date: Fri, 11 Dec 2015 15:44:06 +0300 Subject: [PATCH 2/4] Remove function_introspection auto preload. --- src/open.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/open.cpp b/src/open.cpp index e0bee4cd..8ae8d07b 100644 --- a/src/open.cpp +++ b/src/open.cpp @@ -146,8 +146,6 @@ namespace luabind { lua_pushcclosure(L, &deprecated_super, 0); lua_setglobal(L, "super"); - - set_package_preload(L, "luabind.function_introspection", &bind_function_introspection); } } // namespace luabind From e2a94d33597c98b6e6bf066932cd00be6179d21b Mon Sep 17 00:00:00 2001 From: nitrocaster Date: Sun, 13 Dec 2015 20:11:13 +0300 Subject: [PATCH 3/4] Fix null pointer dereference when compiled with LUABIND_NO_ERROR_CHECKING. --- luabind/lua_proxy_interface.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/luabind/lua_proxy_interface.hpp b/luabind/lua_proxy_interface.hpp index 236f51f9..e5c38750 100644 --- a/luabind/lua_proxy_interface.hpp +++ b/luabind/lua_proxy_interface.hpp @@ -235,11 +235,9 @@ namespace luabind { detail::stack_pop pop(interpreter, 1); specialized_converter_policy_n<0, Policies, T, lua_to_cpp> cv; -#ifndef LUABIND_NO_ERROR_CHECKING if(cv.match(interpreter, decorated_type(), -1)<0) { return error_policy.handle_error(interpreter, typeid(T)); } -#endif return cv.to_cpp(interpreter, decorated_type(), -1); } From dfa8b8ac3cf057e88ec6297cd1d391ed76c46b60 Mon Sep 17 00:00:00 2001 From: Daniel Grondin Date: Tue, 15 Dec 2015 12:16:28 -0500 Subject: [PATCH 4/4] Fixed compilation warning when using -Wpedantic --- luabind/detail/call_function.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/luabind/detail/call_function.hpp b/luabind/detail/call_function.hpp index 53fd24aa..a9524faa 100644 --- a/luabind/detail/call_function.hpp +++ b/luabind/detail/call_function.hpp @@ -42,7 +42,7 @@ namespace luabind namespace detail { template< typename PolicyList, unsigned int pos > - void push_arguments(lua_State* /*L*/) {}; + void push_arguments(lua_State* /*L*/) {} template< typename PolicyList, unsigned int Pos, typename Arg0, typename... Args > void push_arguments(lua_State* L, Arg0&& arg0, Args&&... args)