There was a leak when running scripts and catching errors, where she didn't properly clean up the stack.

This commit is contained in:
ThePhD 2017-04-09 12:04:57 -04:00
parent 814562260d
commit 2df532f79b
4 changed files with 74 additions and 50 deletions

View File

@ -20,8 +20,8 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// This file was generated with a script. // This file was generated with a script.
// Generated 2017-04-08 12:25:20.970713 UTC // Generated 2017-04-09 16:04:17.392392 UTC
// This header was generated with sol v2.17.0 (revision 28fff10) // This header was generated with sol v2.17.0 (revision 8145622)
// https://github.com/ThePhD/sol2 // https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_INCLUDE_HPP #ifndef SOL_SINGLE_INCLUDE_HPP
@ -4023,6 +4023,36 @@ namespace sol {
namespace sol { namespace sol {
namespace stack { namespace stack {
inline void remove(lua_State* L, int index, int count) {
if (count < 1)
return;
int top = lua_gettop(L);
if (index == -count || top == index) {
// Slice them right off the top
lua_pop(L, static_cast<int>(count));
return;
}
// Remove each item one at a time using stack operations
// Probably slower, maybe, haven't benchmarked,
// but necessary
if (index < 0) {
index = lua_gettop(L) + (index + 1);
}
int last = index + count;
for (int i = index; i < last; ++i) {
lua_remove(L, index);
}
}
struct push_popper_at {
lua_State* L;
int index;
int count;
push_popper_at(lua_State* luastate, int index = -1, int count = 1) : L(luastate), index(index), count(count) { }
~push_popper_at() { remove(L, index, count); }
};
template <bool top_level> template <bool top_level>
struct push_popper_n { struct push_popper_n {
lua_State* L; lua_State* L;
@ -7193,28 +7223,6 @@ namespace sol {
return luaL_ref(L, tableindex); return luaL_ref(L, tableindex);
} }
inline void remove(lua_State* L, int index, int count) {
if (count < 1)
return;
int top = lua_gettop(L);
if (index == -count || top == index) {
// Slice them right off the top
lua_pop(L, static_cast<int>(count));
return;
}
// Remove each item one at a time using stack operations
// Probably slower, maybe, haven't benchmarked,
// but necessary
if (index < 0) {
index = lua_gettop(L) + (index + 1);
}
int last = index + count;
for (int i = index; i < last; ++i) {
lua_remove(L, index);
}
}
template <bool check_args = stack_detail::default_check_arguments, typename R, typename... Args, typename Fx, typename... FxArgs, typename = std::enable_if_t<!std::is_void<R>::value>> template <bool check_args = stack_detail::default_check_arguments, typename R, typename... Args, typename Fx, typename... FxArgs, typename = std::enable_if_t<!std::is_void<R>::value>>
inline decltype(auto) call(types<R> tr, types<Args...> ta, lua_State* L, int start, Fx&& fx, FxArgs&&... args) { inline decltype(auto) call(types<R> tr, types<Args...> ta, lua_State* L, int start, Fx&& fx, FxArgs&&... args) {
typedef std::make_index_sequence<sizeof...(Args)> args_indices; typedef std::make_index_sequence<sizeof...(Args)> args_indices;
@ -13085,6 +13093,7 @@ namespace sol {
if (x != load_status::ok) { if (x != load_status::ok) {
return protected_function_result(L, -1, 0, 1, static_cast<call_status>(x)); return protected_function_result(L, -1, 0, 1, static_cast<call_status>(x));
} }
stack::push_popper_at pp(L, lua_absindex(L, -1), 1);
protected_function pf(L, -1); protected_function pf(L, -1);
set_environment(env, pf); set_environment(env, pf);
return pf(); return pf();
@ -13096,7 +13105,8 @@ namespace sol {
if (x != load_status::ok) { if (x != load_status::ok) {
return protected_function_result(L, -1, 0, 1, static_cast<call_status>(x)); return protected_function_result(L, -1, 0, 1, static_cast<call_status>(x));
} }
protected_function pf(L, -1); stack::push_popper_at pp(L, lua_absindex(L, -1), 1);
stack_protected_function pf(L, -1);
set_environment(env, pf); set_environment(env, pf);
return pf(); return pf();
} }
@ -13106,7 +13116,8 @@ namespace sol {
if (x != load_status::ok) { if (x != load_status::ok) {
return protected_function_result(L, -1, 0, 1, static_cast<call_status>(x)); return protected_function_result(L, -1, 0, 1, static_cast<call_status>(x));
} }
protected_function pf(L, -1); stack::push_popper_at pp(L, lua_absindex(L, -1), 1);
stack_protected_function pf(L, -1);
return pf(); return pf();
} }
@ -13115,6 +13126,7 @@ namespace sol {
if (x != load_status::ok) { if (x != load_status::ok) {
return protected_function_result(L, -1, 0, 1, static_cast<call_status>(x)); return protected_function_result(L, -1, 0, 1, static_cast<call_status>(x));
} }
stack::push_popper_at pp(L, lua_absindex(L, -1), 1);
protected_function pf(L, -1); protected_function pf(L, -1);
return pf(); return pf();
} }

View File

@ -27,6 +27,36 @@
namespace sol { namespace sol {
namespace stack { namespace stack {
inline void remove(lua_State* L, int index, int count) {
if (count < 1)
return;
int top = lua_gettop(L);
if (index == -count || top == index) {
// Slice them right off the top
lua_pop(L, static_cast<int>(count));
return;
}
// Remove each item one at a time using stack operations
// Probably slower, maybe, haven't benchmarked,
// but necessary
if (index < 0) {
index = lua_gettop(L) + (index + 1);
}
int last = index + count;
for (int i = index; i < last; ++i) {
lua_remove(L, index);
}
}
struct push_popper_at {
lua_State* L;
int index;
int count;
push_popper_at(lua_State* luastate, int index = -1, int count = 1) : L(luastate), index(index), count(count) { }
~push_popper_at() { remove(L, index, count); }
};
template <bool top_level> template <bool top_level>
struct push_popper_n { struct push_popper_n {
lua_State* L; lua_State* L;

View File

@ -105,28 +105,6 @@ namespace sol {
return luaL_ref(L, tableindex); return luaL_ref(L, tableindex);
} }
inline void remove(lua_State* L, int index, int count) {
if (count < 1)
return;
int top = lua_gettop(L);
if (index == -count || top == index) {
// Slice them right off the top
lua_pop(L, static_cast<int>(count));
return;
}
// Remove each item one at a time using stack operations
// Probably slower, maybe, haven't benchmarked,
// but necessary
if (index < 0) {
index = lua_gettop(L) + (index + 1);
}
int last = index + count;
for (int i = index; i < last; ++i) {
lua_remove(L, index);
}
}
template <bool check_args = stack_detail::default_check_arguments, typename R, typename... Args, typename Fx, typename... FxArgs, typename = std::enable_if_t<!std::is_void<R>::value>> template <bool check_args = stack_detail::default_check_arguments, typename R, typename... Args, typename Fx, typename... FxArgs, typename = std::enable_if_t<!std::is_void<R>::value>>
inline decltype(auto) call(types<R> tr, types<Args...> ta, lua_State* L, int start, Fx&& fx, FxArgs&&... args) { inline decltype(auto) call(types<R> tr, types<Args...> ta, lua_State* L, int start, Fx&& fx, FxArgs&&... args) {
typedef std::make_index_sequence<sizeof...(Args)> args_indices; typedef std::make_index_sequence<sizeof...(Args)> args_indices;

View File

@ -263,6 +263,7 @@ namespace sol {
if (x != load_status::ok) { if (x != load_status::ok) {
return protected_function_result(L, -1, 0, 1, static_cast<call_status>(x)); return protected_function_result(L, -1, 0, 1, static_cast<call_status>(x));
} }
stack::push_popper_at pp(L, lua_absindex(L, -1), 1);
protected_function pf(L, -1); protected_function pf(L, -1);
set_environment(env, pf); set_environment(env, pf);
return pf(); return pf();
@ -274,7 +275,8 @@ namespace sol {
if (x != load_status::ok) { if (x != load_status::ok) {
return protected_function_result(L, -1, 0, 1, static_cast<call_status>(x)); return protected_function_result(L, -1, 0, 1, static_cast<call_status>(x));
} }
protected_function pf(L, -1); stack::push_popper_at pp(L, lua_absindex(L, -1), 1);
stack_protected_function pf(L, -1);
set_environment(env, pf); set_environment(env, pf);
return pf(); return pf();
} }
@ -284,7 +286,8 @@ namespace sol {
if (x != load_status::ok) { if (x != load_status::ok) {
return protected_function_result(L, -1, 0, 1, static_cast<call_status>(x)); return protected_function_result(L, -1, 0, 1, static_cast<call_status>(x));
} }
protected_function pf(L, -1); stack::push_popper_at pp(L, lua_absindex(L, -1), 1);
stack_protected_function pf(L, -1);
return pf(); return pf();
} }
@ -293,6 +296,7 @@ namespace sol {
if (x != load_status::ok) { if (x != load_status::ok) {
return protected_function_result(L, -1, 0, 1, static_cast<call_status>(x)); return protected_function_result(L, -1, 0, 1, static_cast<call_status>(x));
} }
stack::push_popper_at pp(L, lua_absindex(L, -1), 1);
protected_function pf(L, -1); protected_function pf(L, -1);
return pf(); return pf();
} }