From 8f76537b0225b7349b68d5a39d45fd96818494ed Mon Sep 17 00:00:00 2001 From: oldlaptop Date: Wed, 12 Apr 2017 22:28:28 -0400 Subject: [PATCH 1/2] s/_L/L_State The iterator known as _L, besides having an absurdly poor name, clashes with standard headers on OpenBSD -current at the time of writing. This commit is the minimum needed to build on OpenBSD with an updated C++ standard library. --- code/scripting/lua/LuaTable.cpp | 18 +++++++++--------- code/scripting/lua/LuaTable.h | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/code/scripting/lua/LuaTable.cpp b/code/scripting/lua/LuaTable.cpp index 246d8eaa9b3..a81aef9fa15 100644 --- a/code/scripting/lua/LuaTable.cpp +++ b/code/scripting/lua/LuaTable.cpp @@ -97,39 +97,39 @@ LuaTable::iterator LuaTable::end() { return iterator(); // Empty iterator } -LuaTableIterator::LuaTableIterator(const LuaTable& t) : _L(t.getLuaState()) { - _stackTop = lua_gettop(_L); +LuaTableIterator::LuaTableIterator(const LuaTable& t) : _luaState(t.getLuaState()) { + _stackTop = lua_gettop(_luaState); t.pushValue(); - lua_pushnil(_L); + lua_pushnil(_luaState); toNextElement(); } LuaTableIterator::~LuaTableIterator() { - lua_settop(_L, _stackTop); + lua_settop(_luaState, _stackTop); } bool LuaTableIterator::hasElement() { return _hasElement; } void LuaTableIterator::toNextElement() { - auto ret = lua_next(_L, -2); + auto ret = lua_next(_luaState, -2); _hasElement = ret != 0; if (_hasElement) { LuaValue key; - key.setReference(UniqueLuaReference::create(_L, -2)); + key.setReference(UniqueLuaReference::create(_luaState, -2)); LuaValue value; - value.setReference(UniqueLuaReference::create(_L, -1)); + value.setReference(UniqueLuaReference::create(_luaState, -1)); _currentVal = std::make_pair(key, value); // Remove value from stack - lua_pop(_L, 1); + lua_pop(_luaState, 1); } } std::pair LuaTableIterator::getElement() { return _currentVal; } -} \ No newline at end of file +} diff --git a/code/scripting/lua/LuaTable.h b/code/scripting/lua/LuaTable.h index b95137d9638..7819c47fb06 100644 --- a/code/scripting/lua/LuaTable.h +++ b/code/scripting/lua/LuaTable.h @@ -19,7 +19,7 @@ class LuaTable; * be in the exact same state when you call the next method of this class. */ class LuaTableIterator { - lua_State* _L = nullptr; + lua_State* _luaState = nullptr; int _stackTop = 0; From 4b36e3c3798f23229ed380cd06e8b6a3a0456640 Mon Sep 17 00:00:00 2001 From: oldlaptop Date: Thu, 13 Apr 2017 23:06:07 -0400 Subject: [PATCH 2/2] add platform check for std::is_trivially_copyable Yes, the template instantiation appears necessary for cmake to detect the type. If there's a better type for it than int, I'm open to suggestions. --- cmake/platformChecks.cmake | 10 ++++++++++ cmake/platformChecks.h.in | 2 ++ code/scripting/ade.h | 4 +++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cmake/platformChecks.cmake b/cmake/platformChecks.cmake index 957aea6c74a..840842a36e1 100644 --- a/cmake/platformChecks.cmake +++ b/cmake/platformChecks.cmake @@ -7,6 +7,7 @@ include(CheckLibraryExists) include(CheckPrototypeDefinition) include(CheckStructHasMember) include(CheckSymbolExists) +include(CheckCXXSymbolExists) include(CheckTypeSize) CHECK_INCLUDE_FILE("execinfo.h" HAVE_EXECINFO_H) @@ -14,10 +15,19 @@ CHECK_INCLUDE_FILE_CXX("cxxabi.h" HAVE_CXXAPI_H) CHECK_TYPE_SIZE("max_align_t" MAX_ALIGN_T) +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set(CMAKE_REQUIRED_FLAGS "-std=c++11") # required for g++ <= 5 +endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set(CMAKE_EXTRA_INCLUDE_FILES "cstddef") CHECK_TYPE_SIZE("std::max_align_t" STD_MAX_ALIGN_T LANGUAGE CXX) +set(CMAKE_EXTRA_INCLUDE_FILES "type_traits") +CHECK_TYPE_SIZE("std::is_trivially_copyable" STD_IS_TRIVIALLY_COPYABLE LANGUAGE CXX) set(CMAKE_EXTRA_INCLUDE_FILES) +set(CMAKE_REQUIRED_FLAGS) + + CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP) CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP) diff --git a/cmake/platformChecks.h.in b/cmake/platformChecks.h.in index 06fb629aa20..246ea8f6866 100644 --- a/cmake/platformChecks.h.in +++ b/cmake/platformChecks.h.in @@ -8,6 +8,8 @@ #cmakedefine HAVE_MAX_ALIGN_T #cmakedefine HAVE_STD_MAX_ALIGN_T +#cmakedefine HAVE_STD_IS_TRIVIALLY_COPYABLE + #cmakedefine01 IS_64BIT #cmakedefine01 HAVE_STRCASECMP diff --git a/code/scripting/ade.h b/code/scripting/ade.h index 8478ea3ea55..0b4c9e6257c 100644 --- a/code/scripting/ade.h +++ b/code/scripting/ade.h @@ -5,6 +5,7 @@ #define FS2_OPEN_ADE_H #include "globalincs/pstypes.h" +#include "platformChecks.h" extern "C" { #include @@ -226,8 +227,9 @@ template class ade_obj: public ade_lib_handle { public: // Make sure that the stored type is compatible with our requirements +#ifdef HAVE_STD_IS_TRIVIALLY_COPYABLE static_assert(std::is_trivially_copyable::value, "ADE object types must be trivially copyable!"); - +#endif ade_obj(const char* in_name, const char* in_desc, const ade_lib_handle* in_deriv = NULL) { ade_table_entry ate;