From 011898fab90103ff638c5e6608956b9817e7da13 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Sun, 31 Mar 2024 17:44:38 +0200 Subject: C++ migration: fix some warnings in 32 bits builds --- src/keeper.cpp | 4 ++-- src/lanes.cpp | 20 +++++++------------- src/tools.cpp | 6 +++--- src/uniquekey.h | 6 +++--- src/universe.h | 2 +- 5 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/keeper.cpp b/src/keeper.cpp index 8f762e5..244cb6a 100644 --- a/src/keeper.cpp +++ b/src/keeper.cpp @@ -61,10 +61,10 @@ class keeper_fifo int limit{ -1 }; // a fifo full userdata has one uservalue, the table that holds the actual fifo contents - static void* operator new(size_t size_, lua_State* L) noexcept { return lua_newuserdatauv(L, 1); } + static void* operator new([[maybe_unused]] size_t size_, lua_State* L) noexcept { return lua_newuserdatauv(L, 1); } // always embedded somewhere else or "in-place constructed" as a full userdata // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception - static void operator delete(void* p_, lua_State* L) { ASSERT_L(!"should never be called") }; + static void operator delete([[maybe_unused]] void* p_, lua_State* L) { ASSERT_L(!"should never be called") }; static keeper_fifo* getPtr(lua_State* L, int idx_) { diff --git a/src/lanes.cpp b/src/lanes.cpp index 472b501..47ca79a 100644 --- a/src/lanes.cpp +++ b/src/lanes.cpp @@ -655,22 +655,16 @@ static constexpr UniqueKey EXTENDED_STACKTRACE_REGKEY{ 0x2357c69a7c92c936ull }; LUAG_FUNC( set_error_reporting) { luaL_checktype(L, 1, LUA_TSTRING); + char const* mode{ lua_tostring(L, 1) }; lua_pushliteral(L, "extended"); - int equal = lua_rawequal(L, -1, 1); - lua_pop(L, 1); - if (equal) + bool const extended{ strcmp(mode, "extended") == 0 }; + bool const basic{ strcmp(mode, "basic") == 0 }; + if (!extended && !basic) { - goto done; + return luaL_error(L, "unsupported error reporting model %s", mode); } - lua_pushliteral(L, "basic"); - equal = !lua_rawequal(L, -1, 1); - lua_pop(L, 1); - if (equal) - { - return luaL_error(L, "unsupported error reporting model"); - } -done: - EXTENDED_STACKTRACE_REGKEY.setValue(L, [equal](lua_State* L) { lua_pushboolean(L, equal); }); + + EXTENDED_STACKTRACE_REGKEY.setValue(L, [extended](lua_State* L) { lua_pushboolean(L, extended ? 1 : 0); }); return 0; } diff --git a/src/tools.cpp b/src/tools.cpp index 103122e..df7602e 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -156,7 +156,7 @@ void luaG_dump( lua_State* L) // ################################################################################################ // same as PUC-Lua l_alloc -extern "C" static void* libc_lua_Alloc([[maybe_unused]] void* ud, [[maybe_unused]] void* ptr_, size_t osize_, size_t nsize_) +extern "C" static void* libc_lua_Alloc([[maybe_unused]] void* ud, [[maybe_unused]] void* ptr_, [[maybe_unused]] size_t osize_, size_t nsize_) { if (nsize_ == 0) { @@ -175,7 +175,7 @@ static int luaG_provide_protected_allocator(lua_State* L) { Universe* const U{ universe_get(L) }; // push a new full userdata on the stack, giving access to the universe's protected allocator - AllocatorDefinition* const def{ new (L) AllocatorDefinition{ U->protected_allocator.makeDefinition() } }; + [[maybe_unused]] AllocatorDefinition* const def{ new (L) AllocatorDefinition{ U->protected_allocator.makeDefinition() } }; return 1; } @@ -229,7 +229,7 @@ void initialize_allocator_function(Universe* U, lua_State* L) { U->internal_allocator = AllocatorDefinition{ libc_lua_Alloc, nullptr }; } - else if (U->provide_allocator = luaG_provide_protected_allocator) + else if (U->provide_allocator == luaG_provide_protected_allocator) { // user wants mutex protection on the state's allocator. Use protection for our own allocations too, just in case. U->internal_allocator = U->protected_allocator.makeDefinition(); diff --git a/src/uniquekey.h b/src/uniquekey.h index bd3b61f..e592f0a 100644 --- a/src/uniquekey.h +++ b/src/uniquekey.h @@ -13,11 +13,11 @@ class UniqueKey public: - constexpr UniqueKey(uintptr_t val_) + constexpr UniqueKey(uint64_t val_) #if LUAJIT_FLAVOR() == 64 // building against LuaJIT headers for 64 bits, light userdata is restricted to 47 significant bits, because LuaJIT uses the other bits for internal optimizations - : m_storage{ val_ & 0x7fffffffffffull } + : m_storage{ static_cast(val_ & 0x7fffffffffffull) } #else // LUAJIT_FLAVOR() - : m_storage{ val_ } + : m_storage{ static_cast(val_) } #endif // LUAJIT_FLAVOR() { } diff --git a/src/universe.h b/src/universe.h index 3ee0868..6a65888 100644 --- a/src/universe.h +++ b/src/universe.h @@ -38,7 +38,7 @@ class AllocatorDefinition static void* operator new(size_t size_, lua_State* L) noexcept { return lua_newuserdatauv(L, size_, 0); } // always embedded somewhere else or "in-place constructed" as a full userdata // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception - static void operator delete(void* p_, lua_State* L) { ASSERT_L(!"should never be called") }; + static void operator delete([[maybe_unused]] void* p_, lua_State* L) { ASSERT_L(!"should never be called") }; AllocatorDefinition(lua_Alloc allocF_, void* allocUD_) noexcept : m_allocF{ allocF_ } -- cgit v1.2.3-55-g6feb