From af779f0bed47f625ca90cd9d1e26594d55a0d2f4 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Wed, 12 Aug 2020 19:07:32 -0400 Subject: [PATCH] Improve the testing macros to work across platforms. Add a note to the documentation about SOL_NO_LUA_HPP being less preferred over the C++ defines, to Fix #1013. Add regression tests (not yet fixed) so I can get to the bottom of VC++ being ass. --- docs/source/safety.rst | 1 + include/sol/version.hpp | 12 ++-- single/include/sol/config.hpp | 4 +- single/include/sol/forward.hpp | 16 +++-- single/include/sol/sol.hpp | 30 ++++---- tests/CMakeLists.txt | 1 + tests/regression_tests/CMakeLists.txt | 99 ++++++++++++++++++++++++++ tests/regression_tests/source/1008.cpp | 14 ++++ tests/regression_tests/source/main.cpp | 15 ++++ 9 files changed, 168 insertions(+), 24 deletions(-) create mode 100644 tests/regression_tests/CMakeLists.txt create mode 100644 tests/regression_tests/source/1008.cpp create mode 100644 tests/regression_tests/source/main.cpp diff --git a/docs/source/safety.rst b/docs/source/safety.rst index 338e2807..78993365 100644 --- a/docs/source/safety.rst +++ b/docs/source/safety.rst @@ -134,6 +134,7 @@ Linker Config ``SOL_USING_CXX_LUA`` triggers the following changes: * Lua includes are no longer wrapped in ``extern "C" {}`` blocks + * ``SOL_NO_LUA_HPP`` takes less precedence if this is explicitly turned on * Turns on ``SOL_EXCEPTIONS_SAFE_PROPAGATION`` automatically for you * Only use this if you know you've built your LuaJIT with the C++-specific invocations of your compiler (Lua by default builds as C code and is not distributed as a C++ library, but a C one with C symbols) diff --git a/include/sol/version.hpp b/include/sol/version.hpp index 6158892f..69e735a2 100644 --- a/include/sol/version.hpp +++ b/include/sol/version.hpp @@ -38,11 +38,13 @@ #define SOL_IS_ON(OP_SYMBOL) ((3 OP_SYMBOL 3) != 0) #define SOL_IS_OFF(OP_SYMBOL) ((3 OP_SYMBOL 3) == 0) -#define SOL_IS_DEFAULT_ON(OP_SYMBOL) ((3 OP_SYMBOL 3) == 1) +#define SOL_IS_DEFAULT_ON(OP_SYMBOL) ((3 OP_SYMBOL 3) > 3) +#define SOL_IS_DEFAULT_OFF(OP_SYMBOL) ((3 OP_SYMBOL 3 OP_SYMBOL 3) < 0) -#define SOL_ON + -#define SOL_OFF - -#define SOL_DEFAULT_ON / +#define SOL_ON | +#define SOL_OFF ^ +#define SOL_DEFAULT_ON + +#define SOL_DEFAULT_OFF - #if defined(_MSC_VER) #define SOL_COMPILER_CLANG_I_ SOL_OFF @@ -473,6 +475,8 @@ #else #define SOL_USE_LUA_HPP_I_ SOL_ON #endif +#elif defined(SOL_USING_CXX_LUA) + #define SOL_USE_LUA_HPP_I_ SOL_OFF #elif defined(__has_include) #if __has_include() #define SOL_USE_LUA_HPP_I_ SOL_ON diff --git a/single/include/sol/config.hpp b/single/include/sol/config.hpp index 76b96c5c..64833d53 100644 --- a/single/include/sol/config.hpp +++ b/single/include/sol/config.hpp @@ -20,8 +20,8 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // This file was generated with a script. -// Generated 2020-08-02 22:15:17.519015 UTC -// This header was generated with sol v3.2.1 (revision 7be51eb) +// Generated 2020-08-12 23:04:25.864654 UTC +// This header was generated with sol v3.2.1 (revision 5bbc095) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_CONFIG_HPP diff --git a/single/include/sol/forward.hpp b/single/include/sol/forward.hpp index 301bb7ed..5e76b26d 100644 --- a/single/include/sol/forward.hpp +++ b/single/include/sol/forward.hpp @@ -20,8 +20,8 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // This file was generated with a script. -// Generated 2020-08-02 22:15:17.497014 UTC -// This header was generated with sol v3.2.1 (revision 7be51eb) +// Generated 2020-08-12 23:04:25.839654 UTC +// This header was generated with sol v3.2.1 (revision 5bbc095) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP @@ -46,11 +46,13 @@ #define SOL_IS_ON(OP_SYMBOL) ((3 OP_SYMBOL 3) != 0) #define SOL_IS_OFF(OP_SYMBOL) ((3 OP_SYMBOL 3) == 0) -#define SOL_IS_DEFAULT_ON(OP_SYMBOL) ((3 OP_SYMBOL 3) == 1) +#define SOL_IS_DEFAULT_ON(OP_SYMBOL) ((3 OP_SYMBOL 3) > 3) +#define SOL_IS_DEFAULT_OFF(OP_SYMBOL) ((3 OP_SYMBOL 3 OP_SYMBOL 3) < 0) -#define SOL_ON + -#define SOL_OFF - -#define SOL_DEFAULT_ON / +#define SOL_ON | +#define SOL_OFF ^ +#define SOL_DEFAULT_ON + +#define SOL_DEFAULT_OFF - #if defined(_MSC_VER) #define SOL_COMPILER_CLANG_I_ SOL_OFF @@ -479,6 +481,8 @@ #else #define SOL_USE_LUA_HPP_I_ SOL_ON #endif +#elif defined(SOL_USING_CXX_LUA) + #define SOL_USE_LUA_HPP_I_ SOL_OFF #elif defined(__has_include) #if __has_include() #define SOL_USE_LUA_HPP_I_ SOL_ON diff --git a/single/include/sol/sol.hpp b/single/include/sol/sol.hpp index 75fe258d..df4deddd 100644 --- a/single/include/sol/sol.hpp +++ b/single/include/sol/sol.hpp @@ -20,8 +20,8 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // This file was generated with a script. -// Generated 2020-08-02 22:15:16.995707 UTC -// This header was generated with sol v3.2.1 (revision 7be51eb) +// Generated 2020-08-12 23:04:25.317593 UTC +// This header was generated with sol v3.2.1 (revision 5bbc095) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -72,11 +72,13 @@ #define SOL_IS_ON(OP_SYMBOL) ((3 OP_SYMBOL 3) != 0) #define SOL_IS_OFF(OP_SYMBOL) ((3 OP_SYMBOL 3) == 0) -#define SOL_IS_DEFAULT_ON(OP_SYMBOL) ((3 OP_SYMBOL 3) == 1) +#define SOL_IS_DEFAULT_ON(OP_SYMBOL) ((3 OP_SYMBOL 3) > 3) +#define SOL_IS_DEFAULT_OFF(OP_SYMBOL) ((3 OP_SYMBOL 3 OP_SYMBOL 3) < 0) -#define SOL_ON + -#define SOL_OFF - -#define SOL_DEFAULT_ON / +#define SOL_ON | +#define SOL_OFF ^ +#define SOL_DEFAULT_ON + +#define SOL_DEFAULT_OFF - #if defined(_MSC_VER) #define SOL_COMPILER_CLANG_I_ SOL_OFF @@ -505,6 +507,8 @@ #else #define SOL_USE_LUA_HPP_I_ SOL_ON #endif +#elif defined(SOL_USING_CXX_LUA) + #define SOL_USE_LUA_HPP_I_ SOL_OFF #elif defined(__has_include) #if __has_include() #define SOL_USE_LUA_HPP_I_ SOL_ON @@ -1242,7 +1246,7 @@ namespace sol { namespace meta { #endif // noexcept is part of a function's type -#if defined(_MSC_VER) && defined(_M_IX86) +#if SOL_IS_ON(SOL_COMPILER_VCXX_I_) && SOL_IS_ON(SOL_PLATFORM_X86_I_) template struct fx_traits : basic_traits { typedef R(__stdcall* function_pointer_type)(Args...); @@ -1426,10 +1430,12 @@ namespace sol { namespace meta { #endif // __stdcall x86 VC++ bug template - struct fx_traits : fx_traits::function_type, false> {}; + struct fx_traits + : public fx_traits::function_type, false> {}; template ::value> - struct callable_traits : fx_traits> {}; + struct callable_traits + : public fx_traits> {}; template struct callable_traits { @@ -16914,8 +16920,8 @@ namespace sol { else { using traits_type = lua_bind_traits; using return_type = typename traits_type::return_type; - constexpr bool is_const = std::is_const_v>; - if constexpr (is_const) { + constexpr bool ret_is_const = std::is_const_v>; + if constexpr (ret_is_const) { (void)fx; (void)detail::swallow{ 0, (static_cast(args), 0)... }; return luaL_error(L, "sol: cannot write to a readonly (const) variable"); @@ -18445,7 +18451,7 @@ namespace sol { template struct unqualified_pusher> { - static int push(lua_State* L, no_construction) { + static int push(lua_State* L, detail::tagged) { lua_CFunction cf = &function_detail::no_construction_error; return stack::push(L, cf); } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2e7ee370..1e3801b5 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -24,3 +24,4 @@ add_subdirectory(runtime_tests) add_subdirectory(compile_tests) +add_subdirectory(regression_tests) diff --git a/tests/regression_tests/CMakeLists.txt b/tests/regression_tests/CMakeLists.txt new file mode 100644 index 00000000..504dd091 --- /dev/null +++ b/tests/regression_tests/CMakeLists.txt @@ -0,0 +1,99 @@ +# # # # sol3 +# The MIT License (MIT) +# +# Copyright (c) 2013-2019 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. + +# # # # sol3 tests - runtime tests + +file(GLOB SOL2_RUNTIME_TEST_SOURCES source/*.cpp) +source_group(test_sources FILES ${SOL2_RUNTIME_TEST_SOURCES}) + +function(CREATE_TEST test_target_name test_name target_sol) + add_executable(${test_target_name} ${SOL2_RUNTIME_TEST_SOURCES}) + set_target_properties(${test_target_name} + PROPERTIES + OUTPUT_NAME ${test_name} + EXPORT_NAME sol2::${test_name}) + target_link_libraries(${test_target_name} + PUBLIC Threads::Threads ${LUA_LIBRARIES} ${target_sol}) + + if (MSVC) + if (NOT CMAKE_COMPILER_ID MATCHES "Clang") + target_compile_options(${test_target_name} + PRIVATE /bigobj /W4) + endif() + else() + target_compile_options(${test_target_name} + PRIVATE -std=c++1z -pthread + -Wno-unknown-warning -Wno-unknown-warning-option + -Wall -Wpedantic -Werror -pedantic -pedantic-errors + -Wno-noexcept-type) + + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + # For another day, when C++ is not so crap + # and we have time to audit the entire lib + # for all uses of `detail::swallow`... + #target_compile_options(${test_target_name} + # PRIVATE -Wcomma) + endif() + + if (IS_X86) + if(MINGW) + set_target_properties(${test_target_name} + PROPERTIES + LINK_FLAGS -static-libstdc++) + endif() + endif() + endif() + if (MSVC) + target_compile_options(${test_target_name} + PRIVATE /EHsc /std:c++latest) + target_compile_definitions(${test_target_name} + PRIVATE UNICODE _UNICODE + _CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_DEPRECATE) + else() + target_compile_options(${test_target_name} + PRIVATE -std=c++1z -Wno-unknown-warning -Wno-unknown-warning-option + -Wall -Wextra -Wpedantic -pedantic -pedantic-errors) + endif() + + if (SOL2_CI) + target_compile_definitions(${test_target_name} + PRIVATE SOL2_CI) + endif() + + if (CMAKE_DL_LIBS) + target_link_libraries(${test_target_name} + PRIVATE ${CMAKE_DL_LIBS}) + endif() + + add_test(NAME ${test_name} COMMAND ${test_target_name}) + install(TARGETS ${test_target_name} RUNTIME DESTINATION bin) +endfunction(CREATE_TEST) + +if (SOL2_TESTS) + CREATE_TEST(regression_tests "regression_tests" sol2::sol2) +endif() +if (SOL2_TESTS_SINGLE) + CREATE_TEST(regression_tests_single "regression_tests.single" sol2::sol2_single) +endif() +if (SOL2_TESTS_SINGLE_GENERATED) + CREATE_TEST(regression_tests_generated_single "regression_tests.single.generated" sol2::sol2_single_generated) +endif() diff --git a/tests/regression_tests/source/1008.cpp b/tests/regression_tests/source/1008.cpp new file mode 100644 index 00000000..c3ede2d3 --- /dev/null +++ b/tests/regression_tests/source/1008.cpp @@ -0,0 +1,14 @@ +#define SOL_ALL_SAFETIES_ON 1 + +#include + +int regression_1008() { + + sol::state lua; + lua.create_named_table("t"); + + sol::table t = lua["t"]; + t["f"] = sol::as_function([]() {}); + + return 0; +} \ No newline at end of file diff --git a/tests/regression_tests/source/main.cpp b/tests/regression_tests/source/main.cpp new file mode 100644 index 00000000..2f2027cb --- /dev/null +++ b/tests/regression_tests/source/main.cpp @@ -0,0 +1,15 @@ +#include + +extern int regression_1008(); + +int main(int, char*[]) { + using f_ptr = int (*)(); + const f_ptr regressions[] = { ®ression_1008 }; + const int sizeof_regressions = sizeof(regressions) / sizeof(regressions[0]); + int r = 0; + for (std::size_t i = 0; i < sizeof_regressions; ++i) { + f_ptr f = regressions[0]; + r += static_cast(f() != 0); + } + return r; +} \ No newline at end of file