diff options
| author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-10-16 09:42:03 +0200 |
|---|---|---|
| committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-10-16 09:42:03 +0200 |
| commit | 54acd7514dc0a2e9d593dd6312eae90ae6c0d6b5 (patch) | |
| tree | 358653435a913392b8d8d028f0360c951b525307 | |
| parent | 7d94b18dcc41ccdcb5c8e9cff658b7c2a84b283f (diff) | |
| download | lanes-54acd7514dc0a2e9d593dd6312eae90ae6c0d6b5.tar.gz lanes-54acd7514dc0a2e9d593dd6312eae90ae6c0d6b5.tar.bz2 lanes-54acd7514dc0a2e9d593dd6312eae90ae6c0d6b5.zip | |
Fix/suppress MSVC /Wall warnings
| -rw-r--r-- | src/_pch.h | 28 | ||||
| -rw-r--r-- | src/intercopycontext.cpp | 6 | ||||
| -rw-r--r-- | src/keeper.cpp | 12 | ||||
| -rw-r--r-- | src/keeper.h | 4 | ||||
| -rw-r--r-- | src/lanes.cpp | 8 | ||||
| -rw-r--r-- | src/state.cpp | 4 | ||||
| -rw-r--r-- | src/threading.cpp | 8 | ||||
| -rw-r--r-- | src/uniquekey.h | 7 | ||||
| -rw-r--r-- | src/universe.cpp | 2 |
9 files changed, 56 insertions, 23 deletions
| @@ -26,6 +26,14 @@ | |||
| 26 | #include <utility> | 26 | #include <utility> |
| 27 | #include <variant> | 27 | #include <variant> |
| 28 | 28 | ||
| 29 | #ifdef _MSC_VER | ||
| 30 | |||
| 31 | // warning level /Wall triggers a bunch of warnings in Lua headers. we can't do anything about that, so suppress them | ||
| 32 | #pragma warning(push) | ||
| 33 | #pragma warning(disable : 4820) // 'n' bytes padding added after data member 'x' | ||
| 34 | |||
| 35 | #endif // _MSC_VER | ||
| 36 | |||
| 29 | #ifdef __cplusplus | 37 | #ifdef __cplusplus |
| 30 | extern "C" | 38 | extern "C" |
| 31 | { | 39 | { |
| @@ -36,3 +44,23 @@ extern "C" | |||
| 36 | #ifdef __cplusplus | 44 | #ifdef __cplusplus |
| 37 | } | 45 | } |
| 38 | #endif // __cplusplus | 46 | #endif // __cplusplus |
| 47 | |||
| 48 | #ifdef _MSC_VER | ||
| 49 | |||
| 50 | #pragma warning(pop) | ||
| 51 | |||
| 52 | #pragma warning(disable : 4061) // enumerator 'x' in switch of 'y' is not explicitly handled by a case label | ||
| 53 | #pragma warning(disable : 4514) // 'x': unreferenced inline function has been removed | ||
| 54 | #pragma warning(disable : 4623) // 'x': default constructor was implicitly defined as deleted | ||
| 55 | #pragma warning(disable : 4623) // 'x': default constructor was implicitly defined as deleted | ||
| 56 | #pragma warning(disable : 4625) // 'x': copy constructor was implicitly defined as deleted | ||
| 57 | #pragma warning(disable : 4626) // 'x': assignment operator was implicitly defined as deleted | ||
| 58 | #pragma warning(disable : 4820) // 'n' bytes padding added after data member 'x' | ||
| 59 | #pragma warning(disable : 5026) // 'x': move constructor was implicitly defined as deleted | ||
| 60 | #pragma warning(disable : 5027) // 'x': move assignment operator was implicitly defined as deleted | ||
| 61 | #pragma warning(disable : 5039) // 'x': pointer or reference to potentially throwing function passed to 'extern "C"' function under -EHc. Undefined behavior may occur if this function throws an exception. | ||
| 62 | #pragma warning(disable : 5045) // Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified | ||
| 63 | #pragma warning(disable : 5220) // 'x': a non-static data member with a volatile qualified type no longer implies that compiler generated copy/move constructors and copy/move assignment operators are not trivial | ||
| 64 | #pragma warning(disable : 5246) // 'x': the initialization of a subobject should be wrapped in braces | ||
| 65 | |||
| 66 | #endif // _MSC_VER | ||
diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp index d21995c..473ebfd 100644 --- a/src/intercopycontext.cpp +++ b/src/intercopycontext.cpp | |||
| @@ -864,13 +864,13 @@ LuaType InterCopyContext::processConversion() const | |||
| 864 | _source = lua_touserdata(L1, -1); | 864 | _source = lua_touserdata(L1, -1); |
| 865 | void* _clone{ nullptr }; | 865 | void* _clone{ nullptr }; |
| 866 | // get the number of bytes to allocate for the clone | 866 | // get the number of bytes to allocate for the clone |
| 867 | size_t const userdata_size{ lua_rawlen(L1, kIdxTop) }; | 867 | size_t const _userdata_size{ lua_rawlen(L1, kIdxTop) }; |
| 868 | { | 868 | { |
| 869 | // extract uservalues (don't transfer them yet) | 869 | // extract uservalues (don't transfer them yet) |
| 870 | int const _nuv{ luaG_getalluservalues(L1, source_i) }; // L1: ... u [uv]* | 870 | int const _nuv{ luaG_getalluservalues(L1, source_i) }; // L1: ... u [uv]* |
| 871 | STACK_CHECK(L1, _nuv + 1); | 871 | STACK_CHECK(L1, _nuv + 1); |
| 872 | // create the clone userdata with the required number of uservalue slots | 872 | // create the clone userdata with the required number of uservalue slots |
| 873 | _clone = lua_newuserdatauv(L2, userdata_size, _nuv); // L2: ... mt u | 873 | _clone = lua_newuserdatauv(L2, _userdata_size, _nuv); // L2: ... mt u |
| 874 | // add it in the cache | 874 | // add it in the cache |
| 875 | lua_pushlightuserdata(L2, _source); // L2: ... mt u source | 875 | lua_pushlightuserdata(L2, _source); // L2: ... mt u source |
| 876 | lua_pushvalue(L2, -2); // L2: ... mt u source u | 876 | lua_pushvalue(L2, -2); // L2: ... mt u source u |
| @@ -906,7 +906,7 @@ LuaType InterCopyContext::processConversion() const | |||
| 906 | lua_remove(L2, -2); // L2: ... u __lanesclone | 906 | lua_remove(L2, -2); // L2: ... u __lanesclone |
| 907 | lua_pushlightuserdata(L2, _clone); // L2: ... u __lanesclone clone | 907 | lua_pushlightuserdata(L2, _clone); // L2: ... u __lanesclone clone |
| 908 | lua_pushlightuserdata(L2, _source); // L2: ... u __lanesclone clone source | 908 | lua_pushlightuserdata(L2, _source); // L2: ... u __lanesclone clone source |
| 909 | lua_pushinteger(L2, userdata_size); // L2: ... u __lanesclone clone source size | 909 | lua_pushinteger(L2, static_cast<lua_Integer>(_userdata_size)); // L2: ... u __lanesclone clone source size |
| 910 | // clone:__lanesclone(dest, source, size) | 910 | // clone:__lanesclone(dest, source, size) |
| 911 | lua_call(L2, 3, 0); // L2: ... u | 911 | lua_call(L2, 3, 0); // L2: ... u |
| 912 | } else { // regular function | 912 | } else { // regular function |
diff --git a/src/keeper.cpp b/src/keeper.cpp index 46f580b..bea91a7 100644 --- a/src/keeper.cpp +++ b/src/keeper.cpp | |||
| @@ -790,7 +790,7 @@ int Keeper::PushLindaStorage(Linda& linda_, DestState const L_) | |||
| 790 | 790 | ||
| 791 | void Keepers::DeleteKV::operator()(Keeper* const k_) const | 791 | void Keepers::DeleteKV::operator()(Keeper* const k_) const |
| 792 | { | 792 | { |
| 793 | for (Keeper& _k : std::views::counted(k_, count)) { | 793 | for (auto& _k : std::span<Keeper>(k_, count)) { |
| 794 | _k.~Keeper(); | 794 | _k.~Keeper(); |
| 795 | } | 795 | } |
| 796 | U->internalAllocator.free(k_, count * sizeof(Keeper)); | 796 | U->internalAllocator.free(k_, count * sizeof(Keeper)); |
| @@ -826,7 +826,7 @@ void Keepers::close() | |||
| 826 | // when keeper N+1 is closed, object is GCed, linda operation is called, which attempts to acquire keeper N, whose Lua state no longer exists | 826 | // when keeper N+1 is closed, object is GCed, linda operation is called, which attempts to acquire keeper N, whose Lua state no longer exists |
| 827 | // in that case, the linda operation should do nothing. which means that these operations must check for keeper acquisition success | 827 | // in that case, the linda operation should do nothing. which means that these operations must check for keeper acquisition success |
| 828 | // which is early-outed with a keepers->nbKeepers null-check | 828 | // which is early-outed with a keepers->nbKeepers null-check |
| 829 | size_t const _nbKeepers{ std::exchange(_kv.nbKeepers, 0) }; | 829 | size_t const _nbKeepers{ std::exchange(_kv.nbKeepers, size_t{ 0 }) }; |
| 830 | for (size_t const _i : std::ranges::iota_view{ size_t{ 0 }, _nbKeepers }) { | 830 | for (size_t const _i : std::ranges::iota_view{ size_t{ 0 }, _nbKeepers }) { |
| 831 | if (!_closeOneKeeper(_kv.keepers[_i])) { | 831 | if (!_closeOneKeeper(_kv.keepers[_i])) { |
| 832 | // detected partial init: destroy only the mutexes that got initialized properly | 832 | // detected partial init: destroy only the mutexes that got initialized properly |
| @@ -889,7 +889,7 @@ void Keepers::close() | |||
| 889 | * settings table is expected at position 1 on the stack | 889 | * settings table is expected at position 1 on the stack |
| 890 | */ | 890 | */ |
| 891 | 891 | ||
| 892 | void Keepers::initialize(Universe& U_, lua_State* L_, int const nbKeepers_, int const gc_threshold_) | 892 | void Keepers::initialize(Universe& U_, lua_State* L_, size_t const nbKeepers_, int const gc_threshold_) |
| 893 | { | 893 | { |
| 894 | gc_threshold = gc_threshold_; | 894 | gc_threshold = gc_threshold_; |
| 895 | 895 | ||
| @@ -945,7 +945,7 @@ void Keepers::initialize(Universe& U_, lua_State* L_, int const nbKeepers_, int | |||
| 945 | U->callOnStateCreate(_K, L, LookupMode::ToKeeper); | 945 | U->callOnStateCreate(_K, L, LookupMode::ToKeeper); |
| 946 | 946 | ||
| 947 | // _R[kLindasRegKey] = {} | 947 | // _R[kLindasRegKey] = {} |
| 948 | kLindasRegKey.setValue(_K, [](lua_State* L_) { lua_newtable(L_); }); | 948 | kLindasRegKey.setValue(_K, [](lua_State* const L_) { lua_newtable(L_); }); |
| 949 | STACK_CHECK(_K, 0); | 949 | STACK_CHECK(_K, 0); |
| 950 | 950 | ||
| 951 | // configure GC last | 951 | // configure GC last |
| @@ -968,8 +968,8 @@ void Keepers::initialize(Universe& U_, lua_State* L_, int const nbKeepers_, int | |||
| 968 | std::unique_ptr<Keeper[], DeleteKV>{ new(&U_) Keeper[nbKeepers_], DeleteKV{ &U_, nbKeepers_ } }, | 968 | std::unique_ptr<Keeper[], DeleteKV>{ new(&U_) Keeper[nbKeepers_], DeleteKV{ &U_, nbKeepers_ } }, |
| 969 | nbKeepers_ | 969 | nbKeepers_ |
| 970 | ); | 970 | ); |
| 971 | for (int const _i : std::ranges::iota_view{ 0, nbKeepers_ }) { | 971 | for (size_t const _i : std::ranges::iota_view{ size_t{ 0 }, nbKeepers_ }) { |
| 972 | _initOneKeeper(_kv.keepers[_i], _i); | 972 | _initOneKeeper(_kv.keepers[_i], static_cast<int>(_i)); |
| 973 | } | 973 | } |
| 974 | } | 974 | } |
| 975 | } | 975 | } |
diff --git a/src/keeper.h b/src/keeper.h index e505361..74bdbf2 100644 --- a/src/keeper.h +++ b/src/keeper.h | |||
| @@ -42,7 +42,7 @@ struct Keepers | |||
| 42 | struct DeleteKV | 42 | struct DeleteKV |
| 43 | { | 43 | { |
| 44 | Universe* U{}; | 44 | Universe* U{}; |
| 45 | int count{}; | 45 | size_t count{}; |
| 46 | void operator()(Keeper* k_) const; | 46 | void operator()(Keeper* k_) const; |
| 47 | }; | 47 | }; |
| 48 | // can't use std::vector<Keeper> because Keeper contains a mutex, so we need a raw memory buffer | 48 | // can't use std::vector<Keeper> because Keeper contains a mutex, so we need a raw memory buffer |
| @@ -65,7 +65,7 @@ struct Keepers | |||
| 65 | void close(); | 65 | void close(); |
| 66 | [[nodiscard]] Keeper* getKeeper(KeeperIndex idx_); | 66 | [[nodiscard]] Keeper* getKeeper(KeeperIndex idx_); |
| 67 | [[nodiscard]] int getNbKeepers() const; | 67 | [[nodiscard]] int getNbKeepers() const; |
| 68 | void initialize(Universe& U_, lua_State* L_, int nbKeepers_, int gc_threshold_); | 68 | void initialize(Universe& U_, lua_State* L_, size_t nbKeepers_, int gc_threshold_); |
| 69 | }; | 69 | }; |
| 70 | 70 | ||
| 71 | // ################################################################################################# | 71 | // ################################################################################################# |
diff --git a/src/lanes.cpp b/src/lanes.cpp index 3aef572..4ebe20c 100644 --- a/src/lanes.cpp +++ b/src/lanes.cpp | |||
| @@ -805,14 +805,14 @@ static volatile int s_ecoc_go_ahead = 0; | |||
| 805 | static void EnableCrashingOnCrashes(void) | 805 | static void EnableCrashingOnCrashes(void) |
| 806 | { | 806 | { |
| 807 | if (InterlockedCompareExchange(&s_ecoc_initCount, 1, 0) == 0) { | 807 | if (InterlockedCompareExchange(&s_ecoc_initCount, 1, 0) == 0) { |
| 808 | typedef BOOL(WINAPI * tGetPolicy)(LPDWORD lpFlags); | 808 | using GetPolicy_t = BOOL(WINAPI *)(LPDWORD lpFlags); |
| 809 | typedef BOOL(WINAPI * tSetPolicy)(DWORD dwFlags); | 809 | using SetPolicy_t = BOOL(WINAPI *)(DWORD dwFlags); |
| 810 | const DWORD EXCEPTION_SWALLOWING = 0x1; | 810 | const DWORD EXCEPTION_SWALLOWING = 0x1; |
| 811 | 811 | ||
| 812 | HMODULE _kernel32 = LoadLibraryA("kernel32.dll"); | 812 | HMODULE _kernel32 = LoadLibraryA("kernel32.dll"); |
| 813 | if (_kernel32) { | 813 | if (_kernel32) { |
| 814 | tGetPolicy pGetPolicy = (tGetPolicy) GetProcAddress(_kernel32, "GetProcessUserModeExceptionPolicy"); | 814 | auto pGetPolicy{ (GetPolicy_t) (void*) GetProcAddress(_kernel32, "GetProcessUserModeExceptionPolicy") }; |
| 815 | tSetPolicy pSetPolicy = (tSetPolicy) GetProcAddress(_kernel32, "SetProcessUserModeExceptionPolicy"); | 815 | auto pSetPolicy{ (SetPolicy_t) (void*) GetProcAddress(_kernel32, "SetProcessUserModeExceptionPolicy") }; |
| 816 | if (pGetPolicy && pSetPolicy) { | 816 | if (pGetPolicy && pSetPolicy) { |
| 817 | DWORD _dwFlags; | 817 | DWORD _dwFlags; |
| 818 | if (pGetPolicy(&_dwFlags)) { | 818 | if (pGetPolicy(&_dwFlags)) { |
diff --git a/src/state.cpp b/src/state.cpp index 4664486..27e595c 100644 --- a/src/state.cpp +++ b/src/state.cpp | |||
| @@ -266,10 +266,10 @@ namespace state { | |||
| 266 | break; | 266 | break; |
| 267 | } | 267 | } |
| 268 | // open library | 268 | // open library |
| 269 | std::string_view const _libName{ _libs.substr(_prefixLen, _nameLen) }; | 269 | std::string_view const _libName{ _libs.substr(static_cast<size_t>(_prefixLen), static_cast<size_t>(_nameLen)) }; |
| 270 | Open1Lib(_L, _libName); | 270 | Open1Lib(_L, _libName); |
| 271 | // advance to next item (can't do this earlier as it invalidates iterators) | 271 | // advance to next item (can't do this earlier as it invalidates iterators) |
| 272 | _libs.remove_prefix(_prefixLen + _nameLen); | 272 | _libs.remove_prefix(static_cast<size_t>(_prefixLen + _nameLen)); |
| 273 | } | 273 | } |
| 274 | lua_gc(_L, LUA_GCRESTART, 0); | 274 | lua_gc(_L, LUA_GCRESTART, 0); |
| 275 | 275 | ||
diff --git a/src/threading.cpp b/src/threading.cpp index 8ef41f5..ad3d3e4 100644 --- a/src/threading.cpp +++ b/src/threading.cpp | |||
| @@ -87,14 +87,14 @@ THE SOFTWARE. | |||
| 87 | * error in _this_ code. | 87 | * error in _this_ code. |
| 88 | */ | 88 | */ |
| 89 | #if defined(PLATFORM_XBOX) || defined(PLATFORM_WIN32) || defined(PLATFORM_POCKETPC) | 89 | #if defined(PLATFORM_XBOX) || defined(PLATFORM_WIN32) || defined(PLATFORM_POCKETPC) |
| 90 | static void FAIL(char const* funcname, int rc) | 90 | static void FAIL(char const* funcname_, DWORD const rc_) |
| 91 | { | 91 | { |
| 92 | #if defined(PLATFORM_XBOX) | 92 | #if defined(PLATFORM_XBOX) |
| 93 | fprintf(stderr, "%s() failed! (%d)\n", funcname, rc); | 93 | fprintf(stderr, "%s() failed! (%d)\n", funcname_, rc_); |
| 94 | #else // PLATFORM_XBOX | 94 | #else // PLATFORM_XBOX |
| 95 | char buf[256]; | 95 | char buf[256]; |
| 96 | FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, rc, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, 256, nullptr); | 96 | FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, rc_, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, 256, nullptr); |
| 97 | fprintf(stderr, "%s() failed! [GetLastError() -> %d] '%s'", funcname, rc, buf); | 97 | fprintf(stderr, "%s() failed! [GetLastError() -> %lu] '%s'", funcname_, rc_, buf); |
| 98 | #endif // PLATFORM_XBOX | 98 | #endif // PLATFORM_XBOX |
| 99 | #ifdef _MSC_VER | 99 | #ifdef _MSC_VER |
| 100 | __debugbreak(); // give a chance to the debugger! | 100 | __debugbreak(); // give a chance to the debugger! |
diff --git a/src/uniquekey.h b/src/uniquekey.h index 14b6d84..c409048 100644 --- a/src/uniquekey.h +++ b/src/uniquekey.h | |||
| @@ -22,7 +22,12 @@ class UniqueKey | |||
| 22 | { | 22 | { |
| 23 | } | 23 | } |
| 24 | // --------------------------------------------------------------------------------------------- | 24 | // --------------------------------------------------------------------------------------------- |
| 25 | constexpr UniqueKey(UniqueKey const& rhs_) = default; | 25 | // rule of 5 |
| 26 | UniqueKey() = delete; | ||
| 27 | constexpr UniqueKey(UniqueKey const&) = default; | ||
| 28 | UniqueKey(UniqueKey&&) = delete; | ||
| 29 | UniqueKey& operator=(UniqueKey const&) = delete; | ||
| 30 | UniqueKey& operator=(UniqueKey&&) = delete; | ||
| 26 | // debugName is irrelevant in comparisons | 31 | // debugName is irrelevant in comparisons |
| 27 | inline constexpr std::weak_ordering operator<=>(UniqueKey const& rhs_) const { return storage <=> rhs_.storage; } | 32 | inline constexpr std::weak_ordering operator<=>(UniqueKey const& rhs_) const { return storage <=> rhs_.storage; } |
| 28 | inline constexpr auto operator==(UniqueKey const& rhs_) const { return storage == rhs_.storage; } | 33 | inline constexpr auto operator==(UniqueKey const& rhs_) const { return storage == rhs_.storage; } |
diff --git a/src/universe.cpp b/src/universe.cpp index c435dad..7630e9c 100644 --- a/src/universe.cpp +++ b/src/universe.cpp | |||
| @@ -170,7 +170,7 @@ void Universe::callOnStateCreate(lua_State* const L_, lua_State* const from_, Lo | |||
| 170 | _U->selfdestructFirst = SELFDESTRUCT_END; | 170 | _U->selfdestructFirst = SELFDESTRUCT_END; |
| 171 | _U->initializeAllocatorFunction(L_); | 171 | _U->initializeAllocatorFunction(L_); |
| 172 | _U->initializeOnStateCreate(L_); | 172 | _U->initializeOnStateCreate(L_); |
| 173 | _U->keepers.initialize(*_U, L_, _nbUserKeepers, _keepers_gc_threshold); | 173 | _U->keepers.initialize(*_U, L_, static_cast<size_t>(_nbUserKeepers), _keepers_gc_threshold); |
| 174 | STACK_CHECK(L_, 0); | 174 | STACK_CHECK(L_, 0); |
| 175 | 175 | ||
| 176 | // Initialize 'timerLinda'; a common Linda object shared by all states | 176 | // Initialize 'timerLinda'; a common Linda object shared by all states |
