Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfixes #24

Merged
merged 5 commits into from
Nov 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion luabind/detail/call_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion luabind/detail/object_rep.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void*, int> get_instance(class_id target) const
{
Expand Down Expand Up @@ -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<class T>
Expand Down
2 changes: 0 additions & 2 deletions luabind/lua_proxy_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(), -1)<0) {
return error_policy.handle_error(interpreter, typeid(T));
}
#endif
return cv.to_cpp(interpreter, decorated_type<T>(), -1);
}

Expand Down
29 changes: 9 additions & 20 deletions src/object_rep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand All @@ -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<object_rep*>(lua_touserdata(L, 1));
Expand All @@ -90,7 +80,6 @@ namespace luabind { namespace detail
lua_call(L, 1, 0);
}

instance->release_dependency_refs(L);
instance->~object_rep();

lua_pushnil(L);
Expand Down
2 changes: 0 additions & 2 deletions src/open.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down