From 42978a9ed4984b9bdec902259827c326f8d4381c Mon Sep 17 00:00:00 2001 From: ThePhD Date: Sat, 31 May 2014 14:29:14 -0400 Subject: [PATCH] Fixed segfault on GCC. It was picking the wrong overload: by forward-declaring the std::function overload in `stack`, it is able to find the right function to use. All tests are passing the ninja file has been tweaked to make it easier to invoke a g++ build on windows --- build.ninja | 21 +++++++++++++++++++++ sol/function.hpp | 2 +- sol/stack.hpp | 4 ++++ tests.cpp | 9 ++++++--- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/build.ninja b/build.ninja index 747bcc33..984b2897 100644 --- a/build.ninja +++ b/build.ninja @@ -4,9 +4,11 @@ ninja_required_version = 1.3 builddir = bin objdir = obj cxx = g++ +cxxflagsd = -std=c++11 -pedantic -pedantic-errors -g -Wextra -Wall -O0 -DEBUG cxxflags = -std=c++11 -pedantic -pedantic-errors -Wextra -Wall -O2 -DNDEBUG incflags = -I"." -I"./include" -I"." -I"/usr/include/lua5.2" -I"./lua-5.2.2/src/" -I"./Catch/include/" linkflags = -static -L"./lib" -llua5.2 -ldl +linkflags_win = -static -L"./lib" -llua5.2 rule compile command = $cxx -MMD -MF $out.d $cxxflags -c $in -o $out $incflags @@ -14,14 +16,33 @@ rule compile depfile = $out.d description = Compiling $in +rule compiled + command = $cxx -MMD -MF $out.d $cxxflagsd -c $in -o $out $incflags + deps = gcc + depfile = $out.d + description = Compiling $in + rule link command = $cxx $in -o $out $linkflags description = Creating $out +rule link_win + command = $cxx $in -o $out $linkflags_win + description = Creating $out + build $objdir/tests.o: compile tests.cpp +build $objdir/debug/tests.o: compiled tests.cpp +build $objdir/win/tests.o: compile tests.cpp +build $objdir/win/debug/tests.o: compiled tests.cpp build $builddir/tests: link $objdir/tests.o +build $builddir/debug/tests: link $objdir/debug/tests.o +build $builddir/win/tests: link_win $objdir/win/tests.o +build $builddir/win/debug/tests: link_win $objdir/win/debug/tests.o build install: phony $builddir/tests +build install_debug: phony $builddir/debug/tests +build install_win: phony $builddir/win/tests +build install_win_debug: phony $builddir/win/debug/tests default install diff --git a/sol/function.hpp b/sol/function.hpp index 228f7734..a3affe0a 100644 --- a/sol/function.hpp +++ b/sol/function.hpp @@ -108,7 +108,7 @@ inline std::function get_std_func(types t, types<>, lua_St } template -inline std::function get(types>, lua_State* L, int index = -1) { +inline std::function get(types>, lua_State* L, int index) { typedef function_traits fx_t; typedef typename fx_t::args_type args_t; typedef typename tuple_types::type ret_t; diff --git a/sol/stack.hpp b/sol/stack.hpp index 4d004e00..b6d14f3f 100644 --- a/sol/stack.hpp +++ b/sol/stack.hpp @@ -29,6 +29,7 @@ #include #include #include +#include namespace sol { namespace stack { @@ -78,6 +79,9 @@ inline auto get(types t, lua_State* L, int index = -1) -> decltype(get_sol_ty return get_sol_type(std::is_base_of(), t, L, index); } +template +inline std::function get(types>, lua_State* L, int index = -1); + template inline T get_unsigned(std::true_type, lua_State* L, int index = -1) { return lua_tounsigned(L, index); diff --git a/tests.cpp b/tests.cpp index f415721e..11bc1af1 100644 --- a/tests.cpp +++ b/tests.cpp @@ -8,7 +8,8 @@ void test_free_func(std::function f) { void test_free_func2(std::function f, int arg1) { int val = f(arg1); - assert(arg1 == val); + if(val != arg1) + throw sol::error("failed function call!"); } std::string free_function() { @@ -30,8 +31,10 @@ struct self_test { void f(const self_test& t) { std::cout << "got test" << '\n'; - assert(t.bark == bark); - assert(&t == this); + if (t.bark != bark) + throw sol::error("bark values are not the same for self_test f function"); + if (&t != this) + throw sol::error("call does not reference self for self_test f function"); } };