diff options
| author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-10-01 10:47:13 +0200 |
|---|---|---|
| committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-10-01 10:47:13 +0200 |
| commit | 414c9302bdff7bd7900246240acd05666e2692e0 (patch) | |
| tree | ac86f43363082708fc46146dec318467cd020f81 /src | |
| parent | b489dea8f3af63fcb2228bbdcfe402dde482cdec (diff) | |
| download | lanes-414c9302bdff7bd7900246240acd05666e2692e0.tar.gz lanes-414c9302bdff7bd7900246240acd05666e2692e0.tar.bz2 lanes-414c9302bdff7bd7900246240acd05666e2692e0.zip | |
Build fixes for mingw/g++
Diffstat (limited to 'src')
| -rw-r--r-- | src/_pch.h | 1 | ||||
| -rw-r--r-- | src/debug.h | 4 | ||||
| -rw-r--r-- | src/keeper.cpp | 2 | ||||
| -rw-r--r-- | src/linda.cpp | 35 | ||||
| -rw-r--r-- | src/platform.h | 6 | ||||
| -rw-r--r-- | src/threading.cpp | 13 |
6 files changed, 37 insertions, 24 deletions
| @@ -23,6 +23,7 @@ | |||
| 23 | #include <thread> | 23 | #include <thread> |
| 24 | #include <tuple> | 24 | #include <tuple> |
| 25 | #include <type_traits> | 25 | #include <type_traits> |
| 26 | #include <utility> | ||
| 26 | #include <variant> | 27 | #include <variant> |
| 27 | 28 | ||
| 28 | #ifdef __cplusplus | 29 | #ifdef __cplusplus |
diff --git a/src/debug.h b/src/debug.h index e199c3e..e96632d 100644 --- a/src/debug.h +++ b/src/debug.h | |||
| @@ -113,8 +113,8 @@ class StackChecker | |||
| 113 | 113 | ||
| 114 | #else // HAVE_LUA_ASSERT() | 114 | #else // HAVE_LUA_ASSERT() |
| 115 | 115 | ||
| 116 | #define LUA_ASSERT(L_, c) nullptr // nothing | 116 | #define LUA_ASSERT(L_, c) ((void) 0) // nothing |
| 117 | #define LUA_ASSERT_CODE(code_) nullptr | 117 | #define LUA_ASSERT_CODE(code_) ((void) 0) |
| 118 | 118 | ||
| 119 | #define STACK_CHECK_START_REL(L_, offset_) | 119 | #define STACK_CHECK_START_REL(L_, offset_) |
| 120 | #define STACK_CHECK_START_ABS(L_, offset_) | 120 | #define STACK_CHECK_START_ABS(L_, offset_) |
diff --git a/src/keeper.cpp b/src/keeper.cpp index cfeebbb..e2df380 100644 --- a/src/keeper.cpp +++ b/src/keeper.cpp | |||
| @@ -721,7 +721,7 @@ void Keeper::operator delete[](void* p_, Universe* U_) | |||
| 721 | int Keeper::PushLindaStorage(Linda& linda_, DestState const L_) | 721 | int Keeper::PushLindaStorage(Linda& linda_, DestState const L_) |
| 722 | { | 722 | { |
| 723 | Keeper* const _keeper{ linda_.whichKeeper() }; | 723 | Keeper* const _keeper{ linda_.whichKeeper() }; |
| 724 | KeeperState const _K{ _keeper ? _keeper->K : nullptr }; | 724 | KeeperState const _K{ _keeper ? _keeper->K : KeeperState{ nullptr } }; |
| 725 | if (_K == nullptr) { | 725 | if (_K == nullptr) { |
| 726 | return 0; | 726 | return 0; |
| 727 | } | 727 | } |
diff --git a/src/linda.cpp b/src/linda.cpp index 43fcd20..eb39c0f 100644 --- a/src/linda.cpp +++ b/src/linda.cpp | |||
| @@ -48,7 +48,8 @@ namespace { | |||
| 48 | { | 48 | { |
| 49 | STACK_CHECK_START_REL(L_, 0); | 49 | STACK_CHECK_START_REL(L_, 0); |
| 50 | for (int const _i : std::ranges::iota_view{ start_, end_ + 1 }) { | 50 | for (int const _i : std::ranges::iota_view{ start_, end_ + 1 }) { |
| 51 | switch (LuaType const _t{ luaG_type(L_, _i) }) { | 51 | LuaType const _t{ luaG_type(L_, _i) }; |
| 52 | switch (_t) { | ||
| 52 | case LuaType::BOOLEAN: | 53 | case LuaType::BOOLEAN: |
| 53 | case LuaType::NUMBER: | 54 | case LuaType::NUMBER: |
| 54 | case LuaType::STRING: | 55 | case LuaType::STRING: |
| @@ -81,6 +82,19 @@ namespace { | |||
| 81 | 82 | ||
| 82 | // ############################################################################################# | 83 | // ############################################################################################# |
| 83 | 84 | ||
| 85 | template <bool OPT> | ||
| 86 | [[nodiscard]] static inline Linda* ToLinda(lua_State* const L_, int const idx_) | ||
| 87 | { | ||
| 88 | Linda* const _linda{ static_cast<Linda*>(LindaFactory::Instance.toDeep(L_, idx_)) }; | ||
| 89 | if constexpr (!OPT) { | ||
| 90 | luaL_argcheck(L_, _linda != nullptr, idx_, "expecting a linda object"); // doesn't return if linda is nullptr | ||
| 91 | LUA_ASSERT(L_, _linda->U == Universe::Get(L_)); | ||
| 92 | } | ||
| 93 | return _linda; | ||
| 94 | } | ||
| 95 | |||
| 96 | // ############################################################################################# | ||
| 97 | |||
| 84 | /* | 98 | /* |
| 85 | * string = linda:__tostring( linda_ud) | 99 | * string = linda:__tostring( linda_ud) |
| 86 | * | 100 | * |
| @@ -109,19 +123,6 @@ namespace { | |||
| 109 | } | 123 | } |
| 110 | 124 | ||
| 111 | // ############################################################################################# | 125 | // ############################################################################################# |
| 112 | |||
| 113 | template <bool OPT> | ||
| 114 | [[nodiscard]] static inline Linda* ToLinda(lua_State* const L_, int const idx_) | ||
| 115 | { | ||
| 116 | Linda* const _linda{ static_cast<Linda*>(LindaFactory::Instance.toDeep(L_, idx_)) }; | ||
| 117 | if constexpr (!OPT) { | ||
| 118 | luaL_argcheck(L_, _linda != nullptr, idx_, "expecting a linda object"); // doesn't return if linda is nullptr | ||
| 119 | LUA_ASSERT(L_, _linda->U == Universe::Get(L_)); | ||
| 120 | } | ||
| 121 | return _linda; | ||
| 122 | } | ||
| 123 | |||
| 124 | // ############################################################################################# | ||
| 125 | // ############################################################################################# | 126 | // ############################################################################################# |
| 126 | } // namespace | 127 | } // namespace |
| 127 | // ################################################################################################# | 128 | // ################################################################################################# |
| @@ -195,7 +196,7 @@ int Linda::ProtectedCall(lua_State* const L_, lua_CFunction const f_) | |||
| 195 | 196 | ||
| 196 | // acquire the keeper | 197 | // acquire the keeper |
| 197 | Keeper* const _keeper{ _linda->acquireKeeper() }; | 198 | Keeper* const _keeper{ _linda->acquireKeeper() }; |
| 198 | KeeperState const _K{ _keeper ? _keeper->K : nullptr }; | 199 | KeeperState const _K{ _keeper ? _keeper->K : KeeperState{ nullptr } }; |
| 199 | if (_K == nullptr) | 200 | if (_K == nullptr) |
| 200 | return 0; | 201 | return 0; |
| 201 | 202 | ||
| @@ -574,7 +575,7 @@ LUAG_FUNC(linda_receive) | |||
| 574 | 575 | ||
| 575 | Lane* const _lane{ kLanePointerRegKey.readLightUserDataValue<Lane>(L_) }; | 576 | Lane* const _lane{ kLanePointerRegKey.readLightUserDataValue<Lane>(L_) }; |
| 576 | Keeper* const _keeper{ _linda->whichKeeper() }; | 577 | Keeper* const _keeper{ _linda->whichKeeper() }; |
| 577 | KeeperState const _K{ _keeper ? _keeper->K : nullptr }; | 578 | KeeperState const _K{ _keeper ? _keeper->K : KeeperState{ nullptr } }; |
| 578 | if (_K == nullptr) | 579 | if (_K == nullptr) |
| 579 | return 0; | 580 | return 0; |
| 580 | 581 | ||
| @@ -713,7 +714,7 @@ LUAG_FUNC(linda_send) | |||
| 713 | { | 714 | { |
| 714 | Lane* const _lane{ kLanePointerRegKey.readLightUserDataValue<Lane>(L_) }; | 715 | Lane* const _lane{ kLanePointerRegKey.readLightUserDataValue<Lane>(L_) }; |
| 715 | Keeper* const _keeper{ _linda->whichKeeper() }; | 716 | Keeper* const _keeper{ _linda->whichKeeper() }; |
| 716 | KeeperState const _K{ _keeper ? _keeper->K : nullptr }; | 717 | KeeperState const _K{ _keeper ? _keeper->K : KeeperState{ nullptr } }; |
| 717 | if (_K == nullptr) | 718 | if (_K == nullptr) |
| 718 | return 0; | 719 | return 0; |
| 719 | 720 | ||
diff --git a/src/platform.h b/src/platform.h index 5a740e5..b92f7e0 100644 --- a/src/platform.h +++ b/src/platform.h | |||
| @@ -1,12 +1,14 @@ | |||
| 1 | #pragma once | 1 | #pragma once |
| 2 | 2 | ||
| 3 | #ifdef _WIN32_WCE | 3 | #if (defined _WIN32_WCE) |
| 4 | #define PLATFORM_POCKETPC | 4 | #define PLATFORM_POCKETPC |
| 5 | #elif defined(_XBOX) | 5 | #elif defined(_XBOX) |
| 6 | #define PLATFORM_XBOX | 6 | #define PLATFORM_XBOX |
| 7 | #elif (defined _WIN32) | 7 | #elif (defined _WIN32) |
| 8 | #define PLATFORM_WIN32 | 8 | #define PLATFORM_WIN32 |
| 9 | #if !defined(NOMINMAX) | ||
| 9 | #define NOMINMAX | 10 | #define NOMINMAX |
| 11 | #endif // NOMINMAX | ||
| 10 | #elif (defined __linux__) | 12 | #elif (defined __linux__) |
| 11 | #define PLATFORM_LINUX | 13 | #define PLATFORM_LINUX |
| 12 | #elif (defined __APPLE__) && (defined __MACH__) | 14 | #elif (defined __APPLE__) && (defined __MACH__) |
| @@ -17,6 +19,8 @@ | |||
| 17 | #define PLATFORM_QNX | 19 | #define PLATFORM_QNX |
| 18 | #elif (defined __CYGWIN__) | 20 | #elif (defined __CYGWIN__) |
| 19 | #define PLATFORM_CYGWIN | 21 | #define PLATFORM_CYGWIN |
| 22 | #elif (defined __MINGW32__) || (defined __MINGW64__) | ||
| 23 | #define PLATFORM_MINGW | ||
| 20 | #else | 24 | #else |
| 21 | #error "Unknown platform!" | 25 | #error "Unknown platform!" |
| 22 | #endif | 26 | #endif |
diff --git a/src/threading.cpp b/src/threading.cpp index af2142b..8ef41f5 100644 --- a/src/threading.cpp +++ b/src/threading.cpp | |||
| @@ -134,7 +134,9 @@ void THREAD_SET_PRIORITY(int prio_, [[maybe_unused]] bool sudo_) | |||
| 134 | void THREAD_SET_PRIORITY(std::thread& thread_, int prio_, [[maybe_unused]] bool sudo_) | 134 | void THREAD_SET_PRIORITY(std::thread& thread_, int prio_, [[maybe_unused]] bool sudo_) |
| 135 | { | 135 | { |
| 136 | // prio range [-3,+3] was checked by the caller | 136 | // prio range [-3,+3] was checked by the caller |
| 137 | if (!SetThreadPriority(thread_.native_handle(), gs_prio_remap[prio_ + 3])) { | 137 | // for some reason when building for mingw, native_handle() is an unsigned long long, but HANDLE is a void* |
| 138 | // -> need a strong cast to make g++ happy | ||
| 139 | if (!SetThreadPriority((HANDLE)thread_.native_handle(), gs_prio_remap[prio_ + 3])) { | ||
| 138 | FAIL("THREAD_SET_PRIORITY", GetLastError()); | 140 | FAIL("THREAD_SET_PRIORITY", GetLastError()); |
| 139 | } | 141 | } |
| 140 | } | 142 | } |
| @@ -194,7 +196,7 @@ void THREAD_SETNAME(std::string_view const& name_) | |||
| 194 | #include <errno.h> | 196 | #include <errno.h> |
| 195 | #include <sched.h> | 197 | #include <sched.h> |
| 196 | 198 | ||
| 197 | #if (defined(__MINGW32__) || defined(__MINGW64__)) && defined pthread_attr_setschedpolicy | 199 | #if (defined PLATFORM_MINGW) && defined pthread_attr_setschedpolicy |
| 198 | #if pthread_attr_setschedpolicy(A, S) == ENOTSUP | 200 | #if pthread_attr_setschedpolicy(A, S) == ENOTSUP |
| 199 | // from the mingw-w64 team: | 201 | // from the mingw-w64 team: |
| 200 | // Well, we support pthread_setschedparam by which you can specify | 202 | // Well, we support pthread_setschedparam by which you can specify |
| @@ -327,10 +329,15 @@ static int const gs_prio_remap[] = { | |||
| 327 | #define _PRIO_0 15 | 329 | #define _PRIO_0 15 |
| 328 | #define _PRIO_LO 1 | 330 | #define _PRIO_LO 1 |
| 329 | 331 | ||
| 330 | #elif defined(PLATFORM_CYGWIN) | 332 | #elif defined(PLATFORM_CYGWIN) || defined(PLATFORM_MINGW) |
| 331 | // | 333 | // |
| 332 | // TBD: Find right values for Cygwin | 334 | // TBD: Find right values for Cygwin |
| 333 | // | 335 | // |
| 336 | #define _PRIO_MODE SCHED_OTHER | ||
| 337 | #define _PRIO_SCOPE PTHREAD_SCOPE_PROCESS | ||
| 338 | #define _PRIO_HI 31 | ||
| 339 | #define _PRIO_0 15 | ||
| 340 | #define _PRIO_LO 1 | ||
| 334 | #else | 341 | #else |
| 335 | #error "Unknown OS: not implemented!" | 342 | #error "Unknown OS: not implemented!" |
| 336 | #endif | 343 | #endif |
