diff --git a/sol/table_iterator.hpp b/sol/table_iterator.hpp index 9742aff1..0d47264b 100644 --- a/sol/table_iterator.hpp +++ b/sol/table_iterator.hpp @@ -50,7 +50,7 @@ private: public: - basic_table_iterator () : idx(-1), keyidx(-1) { + basic_table_iterator () : keyidx(-1), idx(-1) { } diff --git a/sol/usertype_metatable.hpp b/sol/usertype_metatable.hpp index 4681a347..039b62fe 100644 --- a/sol/usertype_metatable.hpp +++ b/sol/usertype_metatable.hpp @@ -146,7 +146,7 @@ namespace sol { } template - int make_regs(regs_t& l, int index, sol::call_construction&, F&, Args&&... args) { + int make_regs(regs_t& l, int index, sol::call_construction, F&&, Args&&... args) { callconstructfunc = call; secondarymeta = true; int endindex = make_regs(l, index + 1, std::forward(args)...); @@ -154,7 +154,7 @@ namespace sol { } template - int make_regs(regs_t& l, int index, base_classes_tag&, bases&, Args&&... args) { + int make_regs(regs_t& l, int index, base_classes_tag, bases, Args&&... args) { int endindex = make_regs(l, index + 1, std::forward(args)...); if (sizeof...(Bases) < 1) return endindex; @@ -174,7 +174,7 @@ namespace sol { #endif // No Runtime Type Information vs. Throw-Style Inheritance } - template + template , base_classes_tag, call_construction>::value>> int make_regs(regs_t& l, int index, N&& n, F&&, Args&&... args) { string_detail::string_shim shimname = usertype_detail::make_shim(n); // Returnable scope diff --git a/test_overflow.cpp b/test_overflow.cpp index 365ccb66..68c11811 100644 --- a/test_overflow.cpp +++ b/test_overflow.cpp @@ -28,3 +28,20 @@ TEST_CASE("issues/stack-overflow", "make sure various operations repeated don't } ); } + + +TEST_CASE("issues/stack-overflow-2", "make sure basic iterators clean up properly when they're not iterated through (e.g., with empty())") { + sol::state lua; + sol::table t = lua.create_table_with(1, "wut"); + int MAX = 50000; + auto fx = [&]() { + int a = 50; + for (int i = 0; i < MAX; ++i) { + if (t.empty()) { + a += 4; + } + a += 2; + } + }; + REQUIRE_NOTHROW(fx()); +} diff --git a/test_usertypes.cpp b/test_usertypes.cpp index 2e7f0bbb..0bafbc74 100644 --- a/test_usertypes.cpp +++ b/test_usertypes.cpp @@ -915,7 +915,9 @@ TEST_CASE("usertype/coverage", "try all the things") { lua.new_usertype("ext_getset", sol::call_constructor, sol::constructors, sol::types>(), sol::meta_function::garbage_collect, sol::destructor(des), - "x", sol::overload(&ext_getset::x, &ext_getset::x2, [](ext_getset& m, std::string x, int y) { return m.meow + 50 + y + x.length(); }), + "x", sol::overload(&ext_getset::x, &ext_getset::x2, [](ext_getset& m, std::string x, int y) { + return m.meow + 50 + y + x.length(); + }), "bark", &ext_getset::bark, "meow", &ext_getset::meow, "readonlybark", sol::readonly(&ext_getset::bark), @@ -935,7 +937,7 @@ print(w) )"); int w = lua["w"]; - REQUIRE(w == 27); + REQUIRE(w == (56 + 50 + 14 + 14)); lua.script(R"( e:set(500) @@ -977,8 +979,8 @@ print(d) int c = lua["c"]; int d = lua["d"]; - REQUIRE(a == 5001); - REQUIRE(b == 9700); + REQUIRE(c == 9700); + REQUIRE(d == 56); lua.script(R"( e.writeonlypropbark = 500