From 740868af3fbff4da93cc3ad4de903883f4d8eb26 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Sat, 19 Jul 2025 12:15:45 +0100 Subject: [PATCH] Update sol2 and lua Also renames lua/lua.hpp to lua/lua_global.hpp. The previous name broke version auto-detection in sol2, which involves calling `__has_include()`. --- .github/workflows/vita.yml | 3 +- 3rdParty/Lua/CMakeLists.txt | 7 +- 3rdParty/sol2/CMakeLists.txt | 28 ++- ...educe-cmake_minimum_required-to-3.22.patch | 56 +++++ ...dex-out-of-bounds-in-stack_field.hpp.patch | 35 +++ ...end-to-sen-in-usertype_container.hpp.patch | 25 +++ ...Lua-Lua-target-when-using-system-Lua.patch | 27 +++ ...E_LINK_LIBRARIES-property-for-lualib.patch | 25 +++ ...ss_reference_equals-and-stateless_re.patch | 51 +++++ ...-Add-Nerixyz-s-test-and-fix-for-C-17.patch | 200 ++++++++++++++++++ ...Faster-track-for-lightuserdata_value.patch | 65 ++++++ .../sol2/patches/0009-Work-around-1581.patch | 47 ++++ Source/CMakeLists.txt | 2 +- Source/diablo.cpp | 2 +- Source/discord/discord.cpp | 2 +- Source/engine/render/scrollrt.cpp | 2 +- Source/lua/autocomplete.cpp | 2 +- Source/lua/{lua.cpp => lua_global.cpp} | 3 +- Source/lua/{lua.hpp => lua_global.hpp} | 0 Source/lua/repl.cpp | 2 +- test/timedemo_test.cpp | 2 +- uwp-project/devilutionx.vcxproj | 4 +- 22 files changed, 574 insertions(+), 16 deletions(-) create mode 100644 3rdParty/sol2/patches/0001-Reduce-cmake_minimum_required-to-3.22.patch create mode 100644 3rdParty/sol2/patches/0002-Fix-array-index-out-of-bounds-in-stack_field.hpp.patch create mode 100644 3rdParty/sol2/patches/0003-Change-end-to-sen-in-usertype_container.hpp.patch create mode 100644 3rdParty/sol2/patches/0004-Fix-missing-Lua-Lua-target-when-using-system-Lua.patch create mode 100644 3rdParty/sol2/patches/0005-fix-INTERFACE_LINK_LIBRARIES-property-for-lualib.patch create mode 100644 3rdParty/sol2/patches/0006-Overload-stateless_reference_equals-and-stateless_re.patch create mode 100644 3rdParty/sol2/patches/0007-Add-Nerixyz-s-test-and-fix-for-C-17.patch create mode 100644 3rdParty/sol2/patches/0008-Faster-track-for-lightuserdata_value.patch create mode 100644 3rdParty/sol2/patches/0009-Work-around-1581.patch rename Source/lua/{lua.cpp => lua_global.cpp} (96%) rename Source/lua/{lua.hpp => lua_global.hpp} (100%) diff --git a/.github/workflows/vita.yml b/.github/workflows/vita.yml index 33d0e9a43..6308a86bb 100644 --- a/.github/workflows/vita.yml +++ b/.github/workflows/vita.yml @@ -36,7 +36,8 @@ jobs: apk add \ gettext \ git \ - samurai + samurai \ + patch - name: Configure CMake run: | diff --git a/3rdParty/Lua/CMakeLists.txt b/3rdParty/Lua/CMakeLists.txt index bc9c6f428..fffed7ca8 100644 --- a/3rdParty/Lua/CMakeLists.txt +++ b/3rdParty/Lua/CMakeLists.txt @@ -13,11 +13,14 @@ endif() include(FetchContent) FetchContent_Declare_ExcludeFromAll(Lua - URL https://github.com/walterschell/Lua/archive/88246d621abf7b6fba9332f49229d507f020e450.tar.gz - URL_HASH MD5=03b76927cb5341ffc53bea12c37ddcca + URL https://github.com/walterschell/Lua/archive/3ed55a56eaa05c9221f40b3c07d0e908eb1067b0.tar.gz + URL_HASH MD5=77907b8209f77c65cb681a5012f2d804 ) FetchContent_MakeAvailable_ExcludeFromAll(Lua) +# Needed for sol2 +set(LUA_VERSION_STRING "5.4.7" PARENT_SCOPE) + if(CMAKE_SYSTEM_NAME MATCHES "Darwin" AND DARWIN_MAJOR_VERSION VERSION_EQUAL 8) # We need legacy-support from MacPorts for: # localtime_r gmtime_r diff --git a/3rdParty/sol2/CMakeLists.txt b/3rdParty/sol2/CMakeLists.txt index c2b1a0c8d..3b1d42591 100644 --- a/3rdParty/sol2/CMakeLists.txt +++ b/3rdParty/sol2/CMakeLists.txt @@ -1,11 +1,33 @@ include(functions/FetchContent_ExcludeFromAll_backport) +include(FetchContent) + +find_package(Patch REQUIRED) set(SOL2_ENABLE_INSTALL OFF) +set(SOL2_BUILD_LUA OFF) +set(SOL2_LUA_VERSION "${LUA_VERSION_STRING}") -include(FetchContent) FetchContent_Declare_ExcludeFromAll(sol2 - URL https://github.com/ThePhD/sol2/archive/2b0d2fe8ba0074e16b499940c4f3126b9c7d3471.tar.gz - URL_HASH MD5=869937e96e7c739b89920d12256fef4f + URL https://github.com/ThePhD/sol2/archive/c1f95a773c6f8f4fde8ca3efe872e7286afe4444.tar.gz + URL_HASH MD5=845ce869733636632d857d8517ac3eb5 + # https://github.com/ThePhD/sol2/pull/1712 + PATCH_COMMAND "${Patch_EXECUTABLE}" -p0 -N < ${CMAKE_CURRENT_LIST_DIR}/patches/0001-Reduce-cmake_minimum_required-to-3.22.patch || true + # https://github.com/ThePhD/sol2/pull/1722 + COMMAND "${Patch_EXECUTABLE}" -p0 -N < ${CMAKE_CURRENT_LIST_DIR}/patches/0002-Fix-array-index-out-of-bounds-in-stack_field.hpp.patch || true + # https://github.com/ThePhD/sol2/pull/1676 + COMMAND "${Patch_EXECUTABLE}" -p0 -N < ${CMAKE_CURRENT_LIST_DIR}/patches/0003-Change-end-to-sen-in-usertype_container.hpp.patch || true + # https://github.com/ThePhD/sol2/pull/1704 + COMMAND "${Patch_EXECUTABLE}" -p0 -N < ${CMAKE_CURRENT_LIST_DIR}/patches/0004-Fix-missing-Lua-Lua-target-when-using-system-Lua.patch || true + # https://github.com/ThePhD/sol2/pull/1705 + COMMAND "${Patch_EXECUTABLE}" -p0 -N < ${CMAKE_CURRENT_LIST_DIR}/patches/0005-fix-INTERFACE_LINK_LIBRARIES-property-for-lualib.patch || true + # https://github.com/ThePhD/sol2/pull/1716 + COMMAND "${Patch_EXECUTABLE}" -p0 -N < ${CMAKE_CURRENT_LIST_DIR}/patches/0006-Overload-stateless_reference_equals-and-stateless_re.patch || true + # https://github.com/ThePhD/sol2/pull/1716 + COMMAND "${Patch_EXECUTABLE}" -p0 -N < ${CMAKE_CURRENT_LIST_DIR}/patches/0007-Add-Nerixyz-s-test-and-fix-for-C-17.patch || true + # https://github.com/ThePhD/sol2/pull/1674 + COMMAND "${Patch_EXECUTABLE}" -p0 -N < ${CMAKE_CURRENT_LIST_DIR}/patches/0008-Faster-track-for-lightuserdata_value.patch || true + # https://github.com/ThePhD/sol2/pull/1722 + COMMAND "${Patch_EXECUTABLE}" -p0 -N < ${CMAKE_CURRENT_LIST_DIR}/patches/0009-Work-around-1581.patch || true ) FetchContent_MakeAvailable_ExcludeFromAll(sol2) diff --git a/3rdParty/sol2/patches/0001-Reduce-cmake_minimum_required-to-3.22.patch b/3rdParty/sol2/patches/0001-Reduce-cmake_minimum_required-to-3.22.patch new file mode 100644 index 000000000..8c93fd166 --- /dev/null +++ b/3rdParty/sol2/patches/0001-Reduce-cmake_minimum_required-to-3.22.patch @@ -0,0 +1,56 @@ +From d81d82dbea310f8491ec7a6e2cbcb78516c52b8d Mon Sep 17 00:00:00 2001 +From: Gleb Mazovetskiy +Date: Fri, 4 Jul 2025 18:44:27 +0100 +Subject: [PATCH 1/9] Reduce `cmake_minimum_required` to 3.22 + +Ubuntu 22.04 CMake is 3.22. +Debian stable CMake is 3.25. +Debian oldstable (EOL in 2026) has CMake 3.25 in bullseye-backports. +--- + CMakeLists.txt | 2 +- + documentation/CMakeLists.txt | 2 +- + single/CMakeLists.txt | 2 +- + 3 files changed, 3 insertions(+), 3 deletions(-) + +diff --git CMakeLists.txt CMakeLists.txt +index b54f71a3..507d9be5 100644 +--- CMakeLists.txt ++++ CMakeLists.txt +@@ -22,7 +22,7 @@ + + # # # # sol2 + # # # Required minimum version statement +-cmake_minimum_required(VERSION 3.26.0) ++cmake_minimum_required(VERSION 3.22) + # # # Project Include - file that is included after project declaration is finished + set(CMAKE_PROJECT_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Includes/Project.cmake") + +diff --git documentation/CMakeLists.txt documentation/CMakeLists.txt +index 1c7b6758..ba780c0f 100644 +--- documentation/CMakeLists.txt ++++ documentation/CMakeLists.txt +@@ -22,7 +22,7 @@ + + # # # # sol2, documentation generation + # # # Required minimum version statement +-cmake_minimum_required(VERSION 3.26.0) ++cmake_minimum_required(VERSION 3.22) + + find_package(Doxygen REQUIRED) + find_package(Python3 REQUIRED) +diff --git single/CMakeLists.txt single/CMakeLists.txt +index 2d55fe32..a16926de 100644 +--- single/CMakeLists.txt ++++ single/CMakeLists.txt +@@ -22,7 +22,7 @@ + + # # # # sol3, single + # # # Required minimum version statement +-cmake_minimum_required(VERSION 3.26.0) ++cmake_minimum_required(VERSION 3.22) + + find_package(Python3 REQUIRED) + +-- +2.48.1 + diff --git a/3rdParty/sol2/patches/0002-Fix-array-index-out-of-bounds-in-stack_field.hpp.patch b/3rdParty/sol2/patches/0002-Fix-array-index-out-of-bounds-in-stack_field.hpp.patch new file mode 100644 index 000000000..e79cdafd7 --- /dev/null +++ b/3rdParty/sol2/patches/0002-Fix-array-index-out-of-bounds-in-stack_field.hpp.patch @@ -0,0 +1,35 @@ +From 24241c564783a8dc9bca24aac69e0fb9cee76949 Mon Sep 17 00:00:00 2001 +From: martin nylin +Date: Tue, 11 Mar 2025 21:28:44 +0100 +Subject: [PATCH 2/9] Fix array index out of bounds in stack_field.hpp + +--- + include/sol/stack_field.hpp | 12 +++++++++++- + 1 file changed, 11 insertions(+), 1 deletion(-) + +diff --git include/sol/stack_field.hpp include/sol/stack_field.hpp +index 9dd66e2e..3b815225 100644 +--- include/sol/stack_field.hpp ++++ include/sol/stack_field.hpp +@@ -113,7 +113,17 @@ namespace sol { namespace stack { + lua_getglobal(L, &key[0]); + } + else { +- lua_getfield(L, tableindex, &key[0]); ++ if constexpr (std::is_same_v, const char*>) { ++ // Handle const char* case ++ if (key != nullptr) { ++ lua_getfield(L, tableindex, key); ++ } else { ++ push(L, lua_nil); ++ } ++ } else { ++ // Handle std::string case ++ lua_getfield(L, tableindex, key.c_str()); ++ } + } + } + else if constexpr (std::is_same_v) { +-- +2.48.1 + diff --git a/3rdParty/sol2/patches/0003-Change-end-to-sen-in-usertype_container.hpp.patch b/3rdParty/sol2/patches/0003-Change-end-to-sen-in-usertype_container.hpp.patch new file mode 100644 index 000000000..79b6884f2 --- /dev/null +++ b/3rdParty/sol2/patches/0003-Change-end-to-sen-in-usertype_container.hpp.patch @@ -0,0 +1,25 @@ +From 12a596d1b592acccd0ddee7df3b4e33f25550ff8 Mon Sep 17 00:00:00 2001 +From: martin nylin +Date: Tue, 11 Mar 2025 20:58:43 +0100 +Subject: [PATCH 3/9] Change end() to sen() in usertype_container.hpp + +--- + include/sol/usertype_container.hpp | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git include/sol/usertype_container.hpp include/sol/usertype_container.hpp +index 6d25d2a8..3ff81724 100644 +--- include/sol/usertype_container.hpp ++++ include/sol/usertype_container.hpp +@@ -1189,7 +1189,7 @@ namespace sol { + static int next_associative(std::true_type, lua_State* L_) { + iter& i = stack::unqualified_get>(L_, 1); + auto& it = i.it(); +- auto& end = i.end(); ++ auto& end = i.sen(); + if (it == end) { + return stack::push(L_, lua_nil); + } +-- +2.48.1 + diff --git a/3rdParty/sol2/patches/0004-Fix-missing-Lua-Lua-target-when-using-system-Lua.patch b/3rdParty/sol2/patches/0004-Fix-missing-Lua-Lua-target-when-using-system-Lua.patch new file mode 100644 index 000000000..a43079b5a --- /dev/null +++ b/3rdParty/sol2/patches/0004-Fix-missing-Lua-Lua-target-when-using-system-Lua.patch @@ -0,0 +1,27 @@ +From c5496869eab66dbf2ee1cb6d7f10536da809ace0 Mon Sep 17 00:00:00 2001 +From: syzygial <67280346+syzygial@users.noreply.github.com> +Date: Sat, 31 May 2025 22:38:52 -0400 +Subject: [PATCH 4/9] Fix missing Lua::Lua target when using system Lua + +--- + CMakeLists.txt | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git CMakeLists.txt CMakeLists.txt +index 507d9be5..ed1a6b59 100644 +--- CMakeLists.txt ++++ CMakeLists.txt +@@ -276,6 +276,10 @@ if (sol2-is-top-level-project) + set(LUA_LIBRARIES ${lualib}) + endif() + ++ if(NOT TARGET Lua::Lua) ++ add_library(Lua::Lua ALIAS ${lualib}) ++ endif() ++ + if (NOT LUA_FOUND AND NOT LUABUILD_FOUND) + message(FATAL_ERROR "sol2 Lua \"${SOL2_LUA_VERSION}\" not found and could not be targeted for building") + endif() +-- +2.48.1 + diff --git a/3rdParty/sol2/patches/0005-fix-INTERFACE_LINK_LIBRARIES-property-for-lualib.patch b/3rdParty/sol2/patches/0005-fix-INTERFACE_LINK_LIBRARIES-property-for-lualib.patch new file mode 100644 index 000000000..4412a66f2 --- /dev/null +++ b/3rdParty/sol2/patches/0005-fix-INTERFACE_LINK_LIBRARIES-property-for-lualib.patch @@ -0,0 +1,25 @@ +From f433abdad78bf7601563674f292ac4c96b042220 Mon Sep 17 00:00:00 2001 +From: syzygial <67280346+syzygial@users.noreply.github.com> +Date: Sat, 31 May 2025 12:04:26 -0400 +Subject: [PATCH 5/9] fix INTERFACE_LINK_LIBRARIES property for lualib + +--- + CMakeLists.txt | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git CMakeLists.txt CMakeLists.txt +index ed1a6b59..1e2edf9a 100644 +--- CMakeLists.txt ++++ CMakeLists.txt +@@ -270,7 +270,7 @@ if (sol2-is-top-level-project) + set_target_properties(${lualib} + PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${LUA_INCLUDE_DIR} +- INTERFACE_LINK_LIBRARIES "${LUA_SEARCH_DEPENDENCY_LIBS} ${CMAKE_DL_LIBS}" ++ INTERFACE_LINK_LIBRARIES "${LUA_SEARCH_DEPENDENCY_LIBS};${CMAKE_DL_LIBS}" + IMPORTED_LINK_INTERFACE_LANGUAGES C + IMPORTED_LOCATION ${lualiblocation}) + set(LUA_LIBRARIES ${lualib}) +-- +2.48.1 + diff --git a/3rdParty/sol2/patches/0006-Overload-stateless_reference_equals-and-stateless_re.patch b/3rdParty/sol2/patches/0006-Overload-stateless_reference_equals-and-stateless_re.patch new file mode 100644 index 000000000..f1542feff --- /dev/null +++ b/3rdParty/sol2/patches/0006-Overload-stateless_reference_equals-and-stateless_re.patch @@ -0,0 +1,51 @@ +From ee5af5e0564d1dad7d37e9849404b5be0849142f Mon Sep 17 00:00:00 2001 +From: Evil Eye +Date: Thu, 10 Jul 2025 17:53:18 +0200 +Subject: [PATCH 6/9] Overload stateless_reference_equals and + stateless_reference_hash to prevent implicit conversion of stack_reference to + stateless_reference + +--- + include/sol/reference.hpp | 12 ++++++++++++ + 1 file changed, 12 insertions(+) + +diff --git include/sol/reference.hpp include/sol/reference.hpp +index c7781552..e7be661a 100644 +--- include/sol/reference.hpp ++++ include/sol/reference.hpp +@@ -828,6 +828,8 @@ namespace sol { + stateless_reference_equals(lua_State* L_) noexcept : stateless_stack_reference_equals(L_) { + } + ++ using stateless_stack_reference_equals::operator(); ++ + bool operator()(const lua_nil_t& lhs, const stateless_reference& rhs) const noexcept { + return rhs.equals(lua_state(), lhs); + } +@@ -839,6 +841,14 @@ namespace sol { + bool operator()(const stateless_reference& lhs, const stateless_reference& rhs) const noexcept { + return lhs.equals(lua_state(), rhs); + } ++ ++ bool operator()(const stateless_stack_reference& lhs, const stateless_reference& rhs) const noexcept { ++ return rhs.equals(lua_state(), lhs); ++ } ++ ++ bool operator()(const stateless_reference& lhs, const stateless_stack_reference& rhs) const noexcept { ++ return lhs.equals(lua_state(), rhs); ++ } + }; + + struct reference_equals : public stack_reference_equals { +@@ -878,6 +888,8 @@ namespace sol { + stateless_reference_hash(lua_State* L_) noexcept : stateless_stack_reference_hash(L_) { + } + ++ using stateless_stack_reference_hash::operator(); ++ + result_type operator()(const stateless_reference& lhs) const noexcept { + std::hash h; + return h(lhs.pointer(lua_state())); +-- +2.48.1 + diff --git a/3rdParty/sol2/patches/0007-Add-Nerixyz-s-test-and-fix-for-C-17.patch b/3rdParty/sol2/patches/0007-Add-Nerixyz-s-test-and-fix-for-C-17.patch new file mode 100644 index 000000000..69d232a9a --- /dev/null +++ b/3rdParty/sol2/patches/0007-Add-Nerixyz-s-test-and-fix-for-C-17.patch @@ -0,0 +1,200 @@ +From 6ec30440f64de88a2ac1e909532c99ae0c3ee61f Mon Sep 17 00:00:00 2001 +From: Evil Eye +Date: Sat, 12 Jul 2025 15:33:54 +0200 +Subject: [PATCH 7/9] Add Nerixyz's test and fix for C++17 + +--- + include/sol/usertype_storage.hpp | 4 ++ + tests/regression_tests/1716/CMakeLists.txt | 45 ++++++++++++++ + .../source/1716 - registry indexing leak.cpp | 61 +++++++++++++++++++ + tests/regression_tests/1716/source/main.cpp | 31 ++++++++++ + tests/regression_tests/CMakeLists.txt | 1 + + 5 files changed, 142 insertions(+) + create mode 100644 tests/regression_tests/1716/CMakeLists.txt + create mode 100644 tests/regression_tests/1716/source/1716 - registry indexing leak.cpp + create mode 100644 tests/regression_tests/1716/source/main.cpp + +diff --git include/sol/usertype_storage.hpp include/sol/usertype_storage.hpp +index bdca6146..691a025b 100644 +--- include/sol/usertype_storage.hpp ++++ include/sol/usertype_storage.hpp +@@ -502,7 +502,11 @@ namespace sol { namespace u_detail { + stateless_reference* target = nullptr; + { + stack_reference k = stack::get(L, 2); ++#if __cpp_lib_generic_unordered_lookup >= 201811L + auto it = self.auxiliary_keys.find(k); ++#else ++ auto it = self.auxiliary_keys.find(basic_reference(k)); ++#endif + if (it != self.auxiliary_keys.cend()) { + target = &it->second; + } +diff --git tests/regression_tests/1716/CMakeLists.txt tests/regression_tests/1716/CMakeLists.txt +new file mode 100644 +index 00000000..33ca975c +--- /dev/null ++++ tests/regression_tests/1716/CMakeLists.txt +@@ -0,0 +1,45 @@ ++# # # # sol2 ++# The MIT License (MIT) ++# ++# Copyright (c) 2013-2022 Rapptz, ThePhD, and contributors ++# ++# Permission is hereby granted, free of charge, to any person obtaining a copy of ++# this software and associated documentation files (the "Software"), to deal in ++# the Software without restriction, including without limitation the rights to ++# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of ++# the Software, and to permit persons to whom the Software is furnished to do so, ++# subject to the following conditions: ++# ++# The above copyright notice and this permission notice shall be included in all ++# copies or substantial portions of the Software. ++# ++# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ++# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS ++# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR ++# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER ++# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ++# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ++ ++# # # # sol2 tests - simple regression tests ++ ++file(GLOB_RECURSE sources ++ LIST_DIRECTORIES FALSE ++ CONFIG_DEPENDS source/*.cpp) ++ ++sol2_create_basic_test(sol2.tests.regression_1716 sol2::sol2 ${sources}) ++sol2_create_basic_test(sol2.tests.regression_1716.SOL_ALL_SAFETIES_ON sol2::sol2 ${sources}) ++target_compile_options(sol2.tests.regression_1716 ++ PRIVATE ++ ${--allow-unreachable-code}) ++target_compile_definitions(sol2.tests.regression_1716.SOL_ALL_SAFETIES_ON ++ PRIVATE ++ SOL_ALL_SAFETIES_ON=1) ++target_compile_options(sol2.tests.regression_1716.SOL_ALL_SAFETIES_ON ++ PRIVATE ++ ${--allow-unreachable-code}) ++if (SOL2_TESTS_SINGLE) ++ sol2_create_basic_test(sol2.single.tests.regression_1716 sol2::sol2::single ${sources}) ++ target_compile_options(sol2.single.tests.regression_1716 ++ PRIVATE ++ ${--allow-unreachable-code}) ++endif() +diff --git tests/regression_tests/1716/source/1716 - registry indexing leak.cpp tests/regression_tests/1716/source/1716 - registry indexing leak.cpp +new file mode 100644 +index 00000000..9bc263f6 +--- /dev/null ++++ tests/regression_tests/1716/source/1716 - registry indexing leak.cpp +@@ -0,0 +1,61 @@ ++// sol2 ++ ++// The MIT License (MIT) ++ ++// Copyright (c) 2013-2022 Rapptz, ThePhD and contributors ++ ++// Permission is hereby granted, free of charge, to any person obtaining a copy of ++// this software and associated documentation files (the "Software"), to deal in ++// the Software without restriction, including without limitation the rights to ++// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of ++// the Software, and to permit persons to whom the Software is furnished to do so, ++// subject to the following conditions: ++ ++// The above copyright notice and this permission notice shall be included in all ++// copies or substantial portions of the Software. ++ ++// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ++// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS ++// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR ++// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER ++// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ++// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ++ ++#include ++ ++#include ++ ++TEST_CASE("#1716 - index and newindex should not leak values into the registry", "[sol2][regression][issue1716]") { ++ class vector { ++ public: ++ vector() = default; ++ ++ static int my_index(vector&, int) { ++ return 0; ++ } ++ ++ static void my_new_index(vector&, int, int) { ++ return; ++ } ++ }; ++ ++ sol::state lua; ++ lua.open_libraries(sol::lib::base); ++ lua.new_usertype("vector", ++ sol::constructors>(), // ++ sol::meta_function::index, ++ &vector::my_index, // ++ sol::meta_function::new_index, ++ &vector::my_new_index); ++ auto begin = lua.registry().size(); ++ lua.script(R"( ++ local v = vector.new() ++ local unused = 0 ++ for i=1,100 do ++ unused = v[1] ++ v[1] = 1 ++ end ++ )"); ++ ++ REQUIRE(lua.registry().size() <= begin + 1); ++} +diff --git tests/regression_tests/1716/source/main.cpp tests/regression_tests/1716/source/main.cpp +new file mode 100644 +index 00000000..43e1e320 +--- /dev/null ++++ tests/regression_tests/1716/source/main.cpp +@@ -0,0 +1,31 @@ ++// sol2 ++ ++// The MIT License (MIT) ++ ++// Copyright (c) 2013-2022 Rapptz, ThePhD and contributors ++ ++// Permission is hereby granted, free of charge, to any person obtaining a copy of ++// this software and associated documentation files (the "Software"), to deal in ++// the Software without restriction, including without limitation the rights to ++// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of ++// the Software, and to permit persons to whom the Software is furnished to do so, ++// subject to the following conditions: ++ ++// The above copyright notice and this permission notice shall be included in all ++// copies or substantial portions of the Software. ++ ++// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ++// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS ++// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR ++// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER ++// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ++// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ++ ++#define CATCH_CONFIG_RUNNER ++ ++#include ++ ++int main(int argc, char* argv[]) { ++ int result = Catch::Session().run(argc, argv); ++ return result; ++} +diff --git tests/regression_tests/CMakeLists.txt tests/regression_tests/CMakeLists.txt +index 7af8ed61..31400503 100644 +--- tests/regression_tests/CMakeLists.txt ++++ tests/regression_tests/CMakeLists.txt +@@ -23,4 +23,5 @@ + # # # # sol2 tests + + add_subdirectory(1011) ++add_subdirectory(1716) + add_subdirectory(simple) +-- +2.48.1 + diff --git a/3rdParty/sol2/patches/0008-Faster-track-for-lightuserdata_value.patch b/3rdParty/sol2/patches/0008-Faster-track-for-lightuserdata_value.patch new file mode 100644 index 000000000..4c5bc339c --- /dev/null +++ b/3rdParty/sol2/patches/0008-Faster-track-for-lightuserdata_value.patch @@ -0,0 +1,65 @@ +From f0d0ef4007c64a5a91146d834375a1684d27241c Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Pawe=C5=82=20Per=C5=82akowski?= +Date: Tue, 25 Feb 2025 17:39:39 +0100 +Subject: [PATCH 8/9] Faster track for lightuserdata_value + +--- + include/sol/stack_check_qualified.hpp | 2 +- + include/sol/stack_check_unqualified.hpp | 4 +--- + include/sol/stack_core.hpp | 5 ++--- + 3 files changed, 4 insertions(+), 7 deletions(-) + +diff --git include/sol/stack_check_qualified.hpp include/sol/stack_check_qualified.hpp +index cc2394af..3ce5b642 100644 +--- include/sol/stack_check_qualified.hpp ++++ include/sol/stack_check_qualified.hpp +@@ -28,7 +28,7 @@ + + namespace sol { namespace stack { + +- template ++ template + struct qualified_checker { + template + static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { +diff --git include/sol/stack_check_unqualified.hpp include/sol/stack_check_unqualified.hpp +index d75557c4..18974987 100644 +--- include/sol/stack_check_unqualified.hpp ++++ include/sol/stack_check_unqualified.hpp +@@ -389,9 +389,7 @@ namespace sol { namespace stack { + return success; + } + else if constexpr (meta::is_specialization_of_v) { +- unqualified_checker c; +- (void)c; +- return c.check(L_, index, std::forward(handler), tracking); ++ return stack::unqualified_check>(L_, index, std::forward(handler), tracking); + } + else { + if constexpr (std::is_pointer_v) { +diff --git include/sol/stack_core.hpp include/sol/stack_core.hpp +index c4f5e203..2ce3ca2b 100644 +--- include/sol/stack_core.hpp ++++ include/sol/stack_core.hpp +@@ -571,7 +571,7 @@ namespace sol { + + template + struct unqualified_checker; +- template ++ template + struct qualified_checker; + + template +@@ -1002,8 +1002,7 @@ namespace sol { + return sol_lua_check(types(), L, index, std::forward(handler), tracking); + } + else { +- using Tu = meta::unqualified_t; +- qualified_checker> c{}; ++ qualified_checker c{}; + return c.check(L, index, std::forward(handler), tracking); + } + } +-- +2.48.1 + diff --git a/3rdParty/sol2/patches/0009-Work-around-1581.patch b/3rdParty/sol2/patches/0009-Work-around-1581.patch new file mode 100644 index 000000000..328535588 --- /dev/null +++ b/3rdParty/sol2/patches/0009-Work-around-1581.patch @@ -0,0 +1,47 @@ +From 56cef1c15fb6f5b78e5debcb62d8ac914a0f007c Mon Sep 17 00:00:00 2001 +From: Gleb Mazovetskiy +Date: Sun, 20 Jul 2025 09:03:08 +0100 +Subject: [PATCH 9/9] Work around #1581 + +See https://github.com/ThePhD/sol2/issues/1581#issuecomment-2103463524 +--- + include/sol/function_types_stateless.hpp | 16 ++++++++++++++-- + 1 file changed, 14 insertions(+), 2 deletions(-) + +diff --git include/sol/function_types_stateless.hpp include/sol/function_types_stateless.hpp +index a2f66ba0..fe0f3f0b 100644 +--- include/sol/function_types_stateless.hpp ++++ include/sol/function_types_stateless.hpp +@@ -320,7 +320,13 @@ namespace sol { namespace function_detail { + } + + template +- static int call(lua_State* L) noexcept(std::is_nothrow_copy_assignable_v) { ++ static int call(lua_State* L) ++#if SOL_IS_ON(SOL_COMPILER_CLANG) ++ // apparent regression in clang 18 - llvm/llvm-project#91362 ++#else ++ noexcept(std::is_nothrow_copy_assignable_v) ++#endif ++ { + int nr; + if constexpr (no_trampoline) { + nr = real_call(L); +@@ -360,7 +366,13 @@ namespace sol { namespace function_detail { + } + + template +- static int call(lua_State* L) noexcept(std::is_nothrow_copy_assignable_v) { ++ static int call(lua_State* L) ++#if SOL_IS_ON(SOL_COMPILER_CLANG) ++ // apparent regression in clang 18 - llvm/llvm-project#91362 ++#else ++ noexcept(std::is_nothrow_copy_assignable_v) ++#endif ++ { + int nr; + if constexpr (no_trampoline) { + nr = real_call(L); +-- +2.48.1 + diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 99747fcff..cf6bf7930 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -97,7 +97,7 @@ set(libdevilutionx_SRCS levels/trigs.cpp lua/autocomplete.cpp - lua/lua.cpp + lua/lua_global.cpp lua/modules/audio.cpp lua/modules/hellfire.cpp lua/modules/dev.cpp diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 4658c216b..2c989e530 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -60,7 +60,7 @@ #include "levels/trigs.h" #include "lighting.h" #include "loadsave.h" -#include "lua/lua.hpp" +#include "lua/lua_global.hpp" #include "menu.h" #include "minitext.h" #include "missiles.h" diff --git a/Source/discord/discord.cpp b/Source/discord/discord.cpp index c4d3f5467..52f227a78 100644 --- a/Source/discord/discord.cpp +++ b/Source/discord/discord.cpp @@ -19,7 +19,7 @@ #include "config.h" #include "levels/gendung.h" #include "levels/setmaps.h" -#include "lua/lua.hpp" +#include "lua/lua_global.hpp" #include "multi.h" #include "panels/charpanel.hpp" #include "player.h" diff --git a/Source/engine/render/scrollrt.cpp b/Source/engine/render/scrollrt.cpp index 31c36a164..3f77eb882 100644 --- a/Source/engine/render/scrollrt.cpp +++ b/Source/engine/render/scrollrt.cpp @@ -40,7 +40,7 @@ #include "levels/gendung.h" #include "levels/tile_properties.hpp" #include "lighting.h" -#include "lua/lua.hpp" +#include "lua/lua_global.hpp" #include "minitext.h" #include "missiles.h" #include "nthread.h" diff --git a/Source/lua/autocomplete.cpp b/Source/lua/autocomplete.cpp index 61279aaac..c369b244e 100644 --- a/Source/lua/autocomplete.cpp +++ b/Source/lua/autocomplete.cpp @@ -13,7 +13,7 @@ #include "appfat.h" #include "engine/assets.hpp" -#include "lua/lua.hpp" +#include "lua/lua_global.hpp" #include "lua/metadoc.hpp" #include "utils/algorithm/container.hpp" #include "utils/str_cat.hpp" diff --git a/Source/lua/lua.cpp b/Source/lua/lua_global.cpp similarity index 96% rename from Source/lua/lua.cpp rename to Source/lua/lua_global.cpp index 33acf5e49..767147836 100644 --- a/Source/lua/lua.cpp +++ b/Source/lua/lua_global.cpp @@ -1,9 +1,10 @@ -#include "lua/lua.hpp" +#include "lua/lua_global.hpp" #include #include #include +#include #include #include diff --git a/Source/lua/lua.hpp b/Source/lua/lua_global.hpp similarity index 100% rename from Source/lua/lua.hpp rename to Source/lua/lua_global.hpp diff --git a/Source/lua/repl.cpp b/Source/lua/repl.cpp index 3d60a8198..425fb311f 100644 --- a/Source/lua/repl.cpp +++ b/Source/lua/repl.cpp @@ -10,7 +10,7 @@ #include #include -#include "lua/lua.hpp" +#include "lua/lua_global.hpp" #include "panels/console.hpp" #include "utils/str_cat.hpp" diff --git a/test/timedemo_test.cpp b/test/timedemo_test.cpp index 07e5c87f7..ad8010ece 100644 --- a/test/timedemo_test.cpp +++ b/test/timedemo_test.cpp @@ -7,7 +7,7 @@ #include "game_mode.hpp" #include "headless_mode.hpp" #include "init.hpp" -#include "lua/lua.hpp" +#include "lua/lua_global.hpp" #include "monstdat.h" #include "options.h" #include "pfile.h" diff --git a/uwp-project/devilutionx.vcxproj b/uwp-project/devilutionx.vcxproj index f2ddbeec1..06ac0352a 100644 --- a/uwp-project/devilutionx.vcxproj +++ b/uwp-project/devilutionx.vcxproj @@ -74,7 +74,7 @@ sdl_image.lib;libpng16_staticd.lib;pkware.lib;fmtd.lib;zlibstatic.lib;bzip2.lib;libsmackerdec.lib;libmpq.lib;libdevilutionx.lib;lua_static.lib;sdl2.lib;sdl_audiolib.lib;asio.lib;sodium.lib;zt.lib;lwip_pic.lib;miniupnpc_pic.lib;natpmp_pic.lib;zt_pic.lib;zto_pic.lib;shlwapi.lib;shell32.lib;%(AdditionalDependencies) - ..\build\SDL\VisualC-WinRT\x64\Debug\SDL-UWP;..\build\3rdParty\SDL_image\Debug;..\build\_deps\zlib-build\Debug;..\build\3rdParty\PKWare\Debug;..\build\3rdParty\bzip2\Debug;..\build\3rdParty\libsmackerdec\Debug;..\build\3rdParty\libmpq\Debug;..\build\_deps\lua-build\lua-5.4.6\Debug;..\build\_deps\sdl_audiolib-build\Debug;..\build\3rdParty\asio\Debug;..\build\_deps\libsodium-build\Debug;..\build\_deps\libzt-build\lib\Debug;..\build\_deps\libfmt-build\Debug;..\build\_deps\libpng-build\Debug;..\build\Source\libdevilutionx.dir\Debug;%(AdditionalLibraryDirectories) + ..\build\SDL\VisualC-WinRT\x64\Debug\SDL-UWP;..\build\3rdParty\SDL_image\Debug;..\build\_deps\zlib-build\Debug;..\build\3rdParty\PKWare\Debug;..\build\3rdParty\bzip2\Debug;..\build\3rdParty\libsmackerdec\Debug;..\build\3rdParty\libmpq\Debug;..\build\_deps\lua-build\lua-5.4.7\Debug;..\build\_deps\sdl_audiolib-build\Debug;..\build\3rdParty\asio\Debug;..\build\_deps\libsodium-build\Debug;..\build\_deps\libzt-build\lib\Debug;..\build\_deps\libfmt-build\Debug;..\build\_deps\libpng-build\Debug;..\build\Source\libdevilutionx.dir\Debug;%(AdditionalLibraryDirectories) pch.h @@ -93,7 +93,7 @@ sdl_image.lib;libpng16_static.lib;pkware.lib;fmt.lib;zlibstatic.lib;bzip2.lib;libsmackerdec.lib;libmpq.lib;libdevilutionx.lib;lua_static.lib;sdl2.lib;sdl_audiolib.lib;sheenbidi.lib;asio.lib;sodium.lib;zt.lib;lwip_pic.lib;miniupnpc_pic.lib;natpmp_pic.lib;zt_pic.lib;zto_pic.lib;shlwapi.lib;shell32.lib;%(AdditionalDependencies) - ..\build\SDL\VisualC-WinRT\x64\Release\SDL-UWP;..\build\3rdParty\SDL_image\Release;..\build\_deps\zlib-build\Release;..\build\3rdParty\PKWare\Release;..\build\3rdParty\bzip2\Release;..\build\3rdParty\libsmackerdec\Release;..\build\3rdParty\libmpq\Release;..\build\_deps\lua-build\lua-5.4.6\Release;..\build\_deps\sdl_audiolib-build\Release;..\build\3rdParty\asio\Release;..\build\_deps\libsodium-build\Release;..\build\_deps\libzt-build\lib\Release;..\build\_deps\libfmt-build\Release;..\build\_deps\libpng-build\Release;..\build\_deps\sheenbidi-build\Release;..\build\Source\libdevilutionx.dir\Release;%(AdditionalLibraryDirectories) + ..\build\SDL\VisualC-WinRT\x64\Release\SDL-UWP;..\build\3rdParty\SDL_image\Release;..\build\_deps\zlib-build\Release;..\build\3rdParty\PKWare\Release;..\build\3rdParty\bzip2\Release;..\build\3rdParty\libsmackerdec\Release;..\build\3rdParty\libmpq\Release;..\build\_deps\lua-build\lua-5.4.7\Release;..\build\_deps\sdl_audiolib-build\Release;..\build\3rdParty\asio\Release;..\build\_deps\libsodium-build\Release;..\build\_deps\libzt-build\lib\Release;..\build\_deps\libfmt-build\Release;..\build\_deps\libpng-build\Release;..\build\_deps\sheenbidi-build\Release;..\build\Source\libdevilutionx.dir\Release;%(AdditionalLibraryDirectories) pch.h