From ae0b81dc946243c0a0f6ccc66232cc7fc7e23926 Mon Sep 17 00:00:00 2001 From: Daniel Wallin Date: Thu, 29 Jul 2010 09:48:58 +0200 Subject: [PATCH] Fix wrapper_base back reference being initialized with wrong value. --- luabind/detail/constructor.hpp | 2 +- luabind/handle.hpp | 9 +++++++++ luabind/shared_ptr_converter.hpp | 2 +- luabind/weak_ref.hpp | 2 +- src/weak_ref.cpp | 8 ++++---- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/luabind/detail/constructor.hpp b/luabind/detail/constructor.hpp index f8b6f3f..1cbceb7 100644 --- a/luabind/detail/constructor.hpp +++ b/luabind/detail/constructor.hpp @@ -25,7 +25,7 @@ inline void inject_backref(lua_State*, void*, void*) template void inject_backref(lua_State* L, T* p, wrap_base*) { - weak_ref(get_main_thread(L), 1).swap(wrap_access::ref(*p)); + weak_ref(get_main_thread(L), L, 1).swap(wrap_access::ref(*p)); } template diff --git a/luabind/handle.hpp b/luabind/handle.hpp index 3883e26..14adacb 100755 --- a/luabind/handle.hpp +++ b/luabind/handle.hpp @@ -35,6 +35,7 @@ class handle public: handle(); handle(lua_State* interpreter, int stack_index); + handle(lua_State* main, lua_State* interpreter, int stack_index); handle(handle const& other); ~handle(); @@ -74,6 +75,14 @@ inline handle::handle(lua_State* interpreter, int stack_index) m_index = luaL_ref(interpreter, LUA_REGISTRYINDEX); } +inline handle::handle(lua_State* main, lua_State* interpreter, int stack_index) + : m_interpreter(main) + , m_index(LUA_NOREF) +{ + lua_pushvalue(interpreter, stack_index); + m_index = luaL_ref(interpreter, LUA_REGISTRYINDEX); +} + inline handle::~handle() { if (m_interpreter && m_index != LUA_NOREF) diff --git a/luabind/shared_ptr_converter.hpp b/luabind/shared_ptr_converter.hpp index afdc841..2f61b5c 100644 --- a/luabind/shared_ptr_converter.hpp +++ b/luabind/shared_ptr_converter.hpp @@ -18,7 +18,7 @@ namespace detail struct shared_ptr_deleter { shared_ptr_deleter(lua_State* L, int index) - : life_support(get_main_thread(L), index) + : life_support(get_main_thread(L), L, index) {} void operator()(void const*) diff --git a/luabind/weak_ref.hpp b/luabind/weak_ref.hpp index 9eb7e24..e08e250 100755 --- a/luabind/weak_ref.hpp +++ b/luabind/weak_ref.hpp @@ -33,7 +33,7 @@ namespace luabind { { public: weak_ref(); - weak_ref(lua_State*, int); + weak_ref(lua_State* main, lua_State* L, int index); weak_ref(weak_ref const&); ~weak_ref(); diff --git a/src/weak_ref.cpp b/src/weak_ref.cpp index 56ddcef..245b26c 100755 --- a/src/weak_ref.cpp +++ b/src/weak_ref.cpp @@ -69,9 +69,9 @@ namespace luabind struct weak_ref::impl { - impl(lua_State* s, int index) + impl(lua_State* main, lua_State* s, int index) : count(0) - , state(s) + , state(main) , ref(0) { get_weak_table(s); @@ -97,8 +97,8 @@ namespace luabind { } - weak_ref::weak_ref(lua_State* L, int index) - : m_impl(new impl(L, index)) + weak_ref::weak_ref(lua_State* main, lua_State* L, int index) + : m_impl(new impl(main, L, index)) { m_impl->count = 1; } -- 2.11.4.GIT