mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Fix crashing of simple usertypes from a previous herpderp.
This commit is contained in:
parent
431c629e42
commit
89107d3b90
|
@ -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 2016-09-18 02:39:04.820718 UTC
|
// Generated 2016-09-19 04:36:16.270592 UTC
|
||||||
// This header was generated with sol v2.14.0 (revision 1dfeb1d)
|
// This header was generated with sol v2.14.2 (revision 431c629)
|
||||||
// https://github.com/ThePhD/sol2
|
// https://github.com/ThePhD/sol2
|
||||||
|
|
||||||
#ifndef SOL_SINGLE_INCLUDE_HPP
|
#ifndef SOL_SINGLE_INCLUDE_HPP
|
||||||
|
@ -8448,8 +8448,8 @@ namespace sol {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct pusher<detail::tagged<T, destructor_wrapper<void>>> {
|
struct pusher<detail::tagged<T, destructor_wrapper<void>>> {
|
||||||
static int push(lua_State* L, detail::tagged<T, destructor_wrapper<void>>) {
|
static int push(lua_State* L, destructor_wrapper<void>) {
|
||||||
lua_CFunction cf = detail::user_alloc_destroy<T>;
|
lua_CFunction cf = detail::usertype_alloc_destroy<T>;
|
||||||
return stack::push(L, cf);
|
return stack::push(L, cf);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -321,8 +321,8 @@ namespace sol {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct pusher<detail::tagged<T, destructor_wrapper<void>>> {
|
struct pusher<detail::tagged<T, destructor_wrapper<void>>> {
|
||||||
static int push(lua_State* L, detail::tagged<T, destructor_wrapper<void>>) {
|
static int push(lua_State* L, destructor_wrapper<void>) {
|
||||||
lua_CFunction cf = detail::user_alloc_destroy<T>;
|
lua_CFunction cf = detail::usertype_alloc_destroy<T>;
|
||||||
return stack::push(L, cf);
|
return stack::push(L, cf);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -406,3 +406,34 @@ TEST_CASE("usertype/simple-runtime-append", "allow extra functions to be appende
|
||||||
REQUIRE(z == 100);
|
REQUIRE(z == 100);
|
||||||
REQUIRE(w == 100);
|
REQUIRE(w == 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("usertype/simple-destruction-test", "make sure usertypes are properly destructed and don't double-delete memory or segfault") {
|
||||||
|
sol::state lua;
|
||||||
|
|
||||||
|
class CrashClass {
|
||||||
|
public:
|
||||||
|
CrashClass() {
|
||||||
|
}
|
||||||
|
|
||||||
|
~CrashClass() {
|
||||||
|
a = 10; // This will cause a crash.
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
int a;
|
||||||
|
};
|
||||||
|
|
||||||
|
lua.new_simple_usertype<CrashClass>("CrashClass",
|
||||||
|
sol::call_constructor, sol::constructors<sol::types<>>()
|
||||||
|
);
|
||||||
|
|
||||||
|
lua.script(R"(
|
||||||
|
function testCrash()
|
||||||
|
local x = CrashClass()
|
||||||
|
end
|
||||||
|
)");
|
||||||
|
|
||||||
|
for (int i = 0; i < 1000; ++i) {
|
||||||
|
lua["testCrash"]();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1393,3 +1393,34 @@ TEST_CASE("usertype/as_function", "Ensure that variables can be turned into func
|
||||||
REQUIRE(x == 24);
|
REQUIRE(x == 24);
|
||||||
REQUIRE(y == 24);
|
REQUIRE(y == 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("usertype/destruction-test", "make sure usertypes are properly destructed and don't double-delete memory or segfault") {
|
||||||
|
sol::state lua;
|
||||||
|
|
||||||
|
class CrashClass {
|
||||||
|
public:
|
||||||
|
CrashClass() {
|
||||||
|
}
|
||||||
|
|
||||||
|
~CrashClass() {
|
||||||
|
a = 10; // This will cause a crash.
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
int a;
|
||||||
|
};
|
||||||
|
|
||||||
|
lua.new_usertype<CrashClass>("CrashClass",
|
||||||
|
sol::call_constructor, sol::constructors<sol::types<>>()
|
||||||
|
);
|
||||||
|
|
||||||
|
lua.script(R"(
|
||||||
|
function testCrash()
|
||||||
|
local x = CrashClass()
|
||||||
|
end
|
||||||
|
)");
|
||||||
|
|
||||||
|
for (int i = 0; i < 1000; ++i) {
|
||||||
|
lua["testCrash"]();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user