1 #define SOL_CHECK_ARGUMENTS 2 3 #include <catch.hpp> 4 #include <sol.hpp> 5 6 7 TEST_CASE("issues/stack-overflow", "make sure various operations repeated don't trigger stack overflow") { 8 sol::state lua; 9 lua.script("t = {};t[0]=20"); 10 lua.script("lua_function=function(i)return i;end"); 11 12 sol::function f = lua["lua_function"]; 13 std::string teststring = "testtext"; 14 REQUIRE_NOTHROW( 15 for (int i = 0; i < 1000000; ++i) { 16 std::string result = f(teststring); 17 if (result != teststring) throw std::logic_error("RIP"); 18 } 19 ); 20 sol::table t = lua["t"]; 21 int expected = 20; 22 REQUIRE_NOTHROW( 23 for (int i = 0; i < 1000000; ++i) { 24 int result = t[0]; 25 t.size(); 26 if (result != expected) 27 throw std::logic_error("RIP"); 28 } 29 ); 30 } 31 32 33 TEST_CASE("issues/stack-overflow-2", "make sure basic iterators clean up properly when they're not iterated through (e.g., with empty())") { 34 sol::state lua; 35 sol::table t = lua.create_table_with(1, "wut"); 36 int MAX = 50000; __anon62f660650102() 37 auto fx = [&]() { 38 int a = 50; 39 for (int i = 0; i < MAX; ++i) { 40 if (t.empty()) { 41 a += 4; 42 } 43 a += 2; 44 } 45 }; 46 REQUIRE_NOTHROW(fx()); 47 } 48