From 414c9302bdff7bd7900246240acd05666e2692e0 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Tue, 1 Oct 2024 10:47:13 +0200 Subject: Build fixes for mingw/g++ --- src/_pch.h | 1 + src/debug.h | 4 ++-- src/keeper.cpp | 2 +- src/linda.cpp | 35 ++++++++++++++++++----------------- src/platform.h | 6 +++++- src/threading.cpp | 13 ++++++++++--- 6 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/_pch.h b/src/_pch.h index 29a8108..21d862e 100644 --- a/src/_pch.h +++ b/src/_pch.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #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 #else // HAVE_LUA_ASSERT() -#define LUA_ASSERT(L_, c) nullptr // nothing -#define LUA_ASSERT_CODE(code_) nullptr +#define LUA_ASSERT(L_, c) ((void) 0) // nothing +#define LUA_ASSERT_CODE(code_) ((void) 0) #define STACK_CHECK_START_REL(L_, offset_) #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_) int Keeper::PushLindaStorage(Linda& linda_, DestState const L_) { Keeper* const _keeper{ linda_.whichKeeper() }; - KeeperState const _K{ _keeper ? _keeper->K : nullptr }; + KeeperState const _K{ _keeper ? _keeper->K : KeeperState{ nullptr } }; if (_K == nullptr) { return 0; } 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 { { STACK_CHECK_START_REL(L_, 0); for (int const _i : std::ranges::iota_view{ start_, end_ + 1 }) { - switch (LuaType const _t{ luaG_type(L_, _i) }) { + LuaType const _t{ luaG_type(L_, _i) }; + switch (_t) { case LuaType::BOOLEAN: case LuaType::NUMBER: case LuaType::STRING: @@ -81,6 +82,19 @@ namespace { // ############################################################################################# + template + [[nodiscard]] static inline Linda* ToLinda(lua_State* const L_, int const idx_) + { + Linda* const _linda{ static_cast(LindaFactory::Instance.toDeep(L_, idx_)) }; + if constexpr (!OPT) { + luaL_argcheck(L_, _linda != nullptr, idx_, "expecting a linda object"); // doesn't return if linda is nullptr + LUA_ASSERT(L_, _linda->U == Universe::Get(L_)); + } + return _linda; + } + + // ############################################################################################# + /* * string = linda:__tostring( linda_ud) * @@ -108,19 +122,6 @@ namespace { return 0; } - // ############################################################################################# - - template - [[nodiscard]] static inline Linda* ToLinda(lua_State* const L_, int const idx_) - { - Linda* const _linda{ static_cast(LindaFactory::Instance.toDeep(L_, idx_)) }; - if constexpr (!OPT) { - luaL_argcheck(L_, _linda != nullptr, idx_, "expecting a linda object"); // doesn't return if linda is nullptr - LUA_ASSERT(L_, _linda->U == Universe::Get(L_)); - } - return _linda; - } - // ############################################################################################# // ############################################################################################# } // namespace @@ -195,7 +196,7 @@ int Linda::ProtectedCall(lua_State* const L_, lua_CFunction const f_) // acquire the keeper Keeper* const _keeper{ _linda->acquireKeeper() }; - KeeperState const _K{ _keeper ? _keeper->K : nullptr }; + KeeperState const _K{ _keeper ? _keeper->K : KeeperState{ nullptr } }; if (_K == nullptr) return 0; @@ -574,7 +575,7 @@ LUAG_FUNC(linda_receive) Lane* const _lane{ kLanePointerRegKey.readLightUserDataValue(L_) }; Keeper* const _keeper{ _linda->whichKeeper() }; - KeeperState const _K{ _keeper ? _keeper->K : nullptr }; + KeeperState const _K{ _keeper ? _keeper->K : KeeperState{ nullptr } }; if (_K == nullptr) return 0; @@ -713,7 +714,7 @@ LUAG_FUNC(linda_send) { Lane* const _lane{ kLanePointerRegKey.readLightUserDataValue(L_) }; Keeper* const _keeper{ _linda->whichKeeper() }; - KeeperState const _K{ _keeper ? _keeper->K : nullptr }; + KeeperState const _K{ _keeper ? _keeper->K : KeeperState{ nullptr } }; if (_K == nullptr) return 0; 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 @@ #pragma once -#ifdef _WIN32_WCE +#if (defined _WIN32_WCE) #define PLATFORM_POCKETPC #elif defined(_XBOX) #define PLATFORM_XBOX #elif (defined _WIN32) #define PLATFORM_WIN32 +#if !defined(NOMINMAX) #define NOMINMAX +#endif // NOMINMAX #elif (defined __linux__) #define PLATFORM_LINUX #elif (defined __APPLE__) && (defined __MACH__) @@ -17,6 +19,8 @@ #define PLATFORM_QNX #elif (defined __CYGWIN__) #define PLATFORM_CYGWIN +#elif (defined __MINGW32__) || (defined __MINGW64__) +#define PLATFORM_MINGW #else #error "Unknown platform!" #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_) void THREAD_SET_PRIORITY(std::thread& thread_, int prio_, [[maybe_unused]] bool sudo_) { // prio range [-3,+3] was checked by the caller - if (!SetThreadPriority(thread_.native_handle(), gs_prio_remap[prio_ + 3])) { + // for some reason when building for mingw, native_handle() is an unsigned long long, but HANDLE is a void* + // -> need a strong cast to make g++ happy + if (!SetThreadPriority((HANDLE)thread_.native_handle(), gs_prio_remap[prio_ + 3])) { FAIL("THREAD_SET_PRIORITY", GetLastError()); } } @@ -194,7 +196,7 @@ void THREAD_SETNAME(std::string_view const& name_) #include #include -#if (defined(__MINGW32__) || defined(__MINGW64__)) && defined pthread_attr_setschedpolicy +#if (defined PLATFORM_MINGW) && defined pthread_attr_setschedpolicy #if pthread_attr_setschedpolicy(A, S) == ENOTSUP // from the mingw-w64 team: // Well, we support pthread_setschedparam by which you can specify @@ -327,10 +329,15 @@ static int const gs_prio_remap[] = { #define _PRIO_0 15 #define _PRIO_LO 1 -#elif defined(PLATFORM_CYGWIN) +#elif defined(PLATFORM_CYGWIN) || defined(PLATFORM_MINGW) // // TBD: Find right values for Cygwin // +#define _PRIO_MODE SCHED_OTHER +#define _PRIO_SCOPE PTHREAD_SCOPE_PROCESS +#define _PRIO_HI 31 +#define _PRIO_0 15 +#define _PRIO_LO 1 #else #error "Unknown OS: not implemented!" #endif -- cgit v1.2.3-55-g6feb