From 48c99e29ae38db79522fb2833f3144ae58c7a906 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Tue, 17 Dec 2024 11:53:15 +0100 Subject: Some constitude tweaks --- src/compat.hpp | 8 ++++---- src/deep.hpp | 2 +- src/keeper.hpp | 2 +- src/lane.hpp | 4 +--- src/linda.hpp | 4 ++-- src/lindafactory.hpp | 2 +- src/macros_and_utils.hpp | 2 +- src/uniquekey.hpp | 1 + src/universe.cpp | 2 +- src/universe.hpp | 22 ++++++++++++---------- 10 files changed, 25 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/compat.hpp b/src/compat.hpp index 80bc391..0c7c5bb 100644 --- a/src/compat.hpp +++ b/src/compat.hpp @@ -68,9 +68,9 @@ inline size_t lua_rawlen(lua_State* L_, StackIndex idx_) { return lua_objlen(L_, idx_); } -void luaL_requiref(lua_State* L_, const char* modname_, lua_CFunction openf_, int glb_); // implementation copied from Lua 5.2 sources +void luaL_requiref(lua_State* L_, char const* modname_, lua_CFunction openf_, int glb_); // implementation copied from Lua 5.2 sources -int luaL_getsubtable(lua_State* L_, StackIndex idx_, const char* fname_); +int luaL_getsubtable(lua_State* L_, StackIndex idx_, char const* fname_); #endif // LUA_VERSION_NUM == 501 @@ -292,7 +292,7 @@ ENUM luaG_optenum(lua_State* const L_, StackIndex const idx_, ENUM const def_) // ################################################################################################# -inline void luaG_registerlibfuncs(lua_State* L_, luaL_Reg const* funcs_) +inline void luaG_registerlibfuncs(lua_State* const L_, luaL_Reg const* funcs_) { // fake externs to make clang happy... extern void luaL_register(lua_State*, char const*, luaL_Reg const*); // Lua 5.1 @@ -396,7 +396,7 @@ inline void luaG_pushglobaltable(lua_State* const L_) // ################################################################################################# -inline void luaG_setfield(lua_State* const L_, StackIndex const idx_, char const* k_) = delete; +inline void luaG_setfield(lua_State* const L_, StackIndex const idx_, char const* const k_) = delete; inline void luaG_setfield(lua_State* const L_, StackIndex const idx_, std::string_view const& k_) { lua_setfield(L_, idx_, k_.data()); diff --git a/src/deep.hpp b/src/deep.hpp index 8196e66..f8cfa0d 100644 --- a/src/deep.hpp +++ b/src/deep.hpp @@ -86,7 +86,7 @@ class DeepFactory [[nodiscard]] int getObjectCount() const { return deepObjectCount.load(std::memory_order_relaxed); } [[nodiscard]] - static bool IsDeepUserdata(lua_State* const L_, StackIndex const idx_); + static bool IsDeepUserdata(lua_State* L_, StackIndex idx_); [[nodiscard]] static DeepFactory* LookupFactory(lua_State* L_, StackIndex index_, LookupMode mode_); static void PushDeepProxy(DestState L_, DeepPrelude* o_, UserValueCount nuv_, LookupMode mode_, lua_State* errL_); diff --git a/src/keeper.hpp b/src/keeper.hpp index c0a8dc5..4b16c2b 100644 --- a/src/keeper.hpp +++ b/src/keeper.hpp @@ -70,7 +70,7 @@ struct Keepers public: // can only be instanced as a data member - static void* operator new(size_t size_) = delete; + static void* operator new(size_t const size_) = delete; Keepers() = default; void collectGarbage(); diff --git a/src/lane.hpp b/src/lane.hpp index 183c8bf..595bf4d 100644 --- a/src/lane.hpp +++ b/src/lane.hpp @@ -166,11 +166,9 @@ class Lane CancelResult cancel(CancelOp op_, std::chrono::time_point until_, WakeLane wakeLane_, int hookCount_); void closeState() { - lua_State* const _L{ S }; - S = nullptr; L = nullptr; nresults = 0; - lua_close(_L); // this collects our coroutine thread at the same time + lua_close(std::exchange(S, nullptr)); // this collects our coroutine thread at the same time } [[nodiscard]] std::string_view errorTraceLevelString() const; diff --git a/src/linda.hpp b/src/linda.hpp index 920db1b..65bca9f 100644 --- a/src/linda.hpp +++ b/src/linda.hpp @@ -92,8 +92,8 @@ class Linda [[nodiscard]] Keeper* acquireKeeper() const; [[nodiscard]] - static Linda* CreateTimerLinda(lua_State* const L_, Passkey) { return CreateTimerLinda(L_); } - static void DeleteTimerLinda(lua_State* const L_, Linda* const linda_, Passkey) { DeleteTimerLinda(L_, linda_); } + static Linda* CreateTimerLinda(lua_State* const L_, Passkey const) { return CreateTimerLinda(L_); } + static void DeleteTimerLinda(lua_State* const L_, Linda* const linda_, Passkey const) { DeleteTimerLinda(L_, linda_); } [[nodiscard]] std::string_view getName() const; [[nodiscard]] diff --git a/src/lindafactory.hpp b/src/lindafactory.hpp index 1512e9a..0921c8f 100644 --- a/src/lindafactory.hpp +++ b/src/lindafactory.hpp @@ -8,7 +8,7 @@ class LindaFactory : public DeepFactory { public: - // I'm not totally happy with having a 'global' variable. Maybe it should be dynamically created and stored somewhere in the universe? + // TODO: I'm not totally happy with having a 'global' variable. Maybe it should be dynamically created and stored somewhere in the universe? static LindaFactory Instance; LindaFactory(luaL_Reg const lindaMT_[]) diff --git a/src/macros_and_utils.hpp b/src/macros_and_utils.hpp index 0897367..26d47a9 100644 --- a/src/macros_and_utils.hpp +++ b/src/macros_and_utils.hpp @@ -8,7 +8,7 @@ using namespace std::chrono_literals; // ################################################################################################# -inline void STACK_GROW(lua_State* L_, int n_) +inline void STACK_GROW(lua_State* const L_, int const n_) { if (!lua_checkstack(L_, n_)) { raise_luaL_error(L_, "Cannot grow stack!"); diff --git a/src/uniquekey.hpp b/src/uniquekey.hpp index a8386a2..3006b3d 100644 --- a/src/uniquekey.hpp +++ b/src/uniquekey.hpp @@ -64,6 +64,7 @@ class RegistryUniqueKey } // --------------------------------------------------------------------------------------------- template + // TODO: add a requirement clause here for operation_ to be callable on L_ void setValue(lua_State* const L_, OP operation_) const { // Note we can't check stack consistency because operation is not always a push (could be insert, replace, whatever) diff --git a/src/universe.cpp b/src/universe.cpp index b7d11d8..bc309a2 100644 --- a/src/universe.cpp +++ b/src/universe.cpp @@ -186,7 +186,7 @@ Universe* Universe::Create(lua_State* const L_) // same as PUC-Lua l_alloc [[nodiscard]] -static void* libc_lua_Alloc([[maybe_unused]] void* ud_, [[maybe_unused]] void* ptr_, [[maybe_unused]] size_t osize_, size_t nsize_) +static void* libc_lua_Alloc([[maybe_unused]] void* const ud_, [[maybe_unused]] void* const ptr_, [[maybe_unused]] size_t const osize_, size_t const nsize_) { if (nsize_ == 0) { free(ptr_); diff --git a/src/universe.hpp b/src/universe.hpp index dbf0ece..d35172d 100644 --- a/src/universe.hpp +++ b/src/universe.hpp @@ -26,7 +26,7 @@ class ProtectedAllocator std::mutex mutex; [[nodiscard]] - static void* protected_lua_Alloc(void* ud_, void* ptr_, size_t osize_, size_t nsize_) + static void* protected_lua_Alloc(void* const ud_, void* const ptr_, size_t const osize_, size_t const nsize_) { ProtectedAllocator* const allocator{ static_cast(ud_) }; std::lock_guard guard{ allocator->mutex }; @@ -36,8 +36,8 @@ class ProtectedAllocator public: // we are not like our base class: we can't be created inside a full userdata (or we would have to install a metatable and __gc handler to destroy ourselves properly) [[nodiscard]] - static void* operator new(size_t size_, lua_State* L_) noexcept = delete; - static void operator delete(void* p_, lua_State* L_) = delete; + static void* operator new(size_t const size_, lua_State* const L_) noexcept = delete; + static void operator delete(void* const p_, lua_State* const L_) = delete; AllocatorDefinition makeDefinition() { @@ -57,6 +57,7 @@ class ProtectedAllocator } }; +// ################################################################################################# // ################################################################################################# // xxh64 of string "kUniverseLightRegKey" generated at https://www.pelock.com/products/hash-calculator @@ -127,9 +128,9 @@ class Universe public: [[nodiscard]] - static void* operator new([[maybe_unused]] size_t size_, lua_State* L_) noexcept { return luaG_newuserdatauv(L_, UserValueCount{ 0 }); }; + static void* operator new([[maybe_unused]] size_t const size_, lua_State* const L_) noexcept { return luaG_newuserdatauv(L_, UserValueCount{ 0 }); }; // 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([[maybe_unused]] void* p_, [[maybe_unused]] lua_State* L_) {} // nothing to do, as nothing is allocated independently + static void operator delete([[maybe_unused]] void* const p_, [[maybe_unused]] lua_State* const L_) {} // nothing to do, as nothing is allocated independently Universe(); ~Universe() = default; @@ -139,15 +140,16 @@ class Universe Universe& operator=(Universe const&) = delete; Universe& operator=(Universe&&) = delete; - void callOnStateCreate(lua_State* const L_, lua_State* const from_, LookupMode const mode_); + void callOnStateCreate(lua_State* L_, lua_State* from_, LookupMode mode_); [[nodiscard]] static Universe* Create(lua_State* L_); [[nodiscard]] static inline Universe* Get(lua_State* L_); void initializeAllocatorFunction(lua_State* L_); static int InitializeFinalizer(lua_State* L_); - void initializeOnStateCreate(lua_State* const L_); - lanes::AllocatorDefinition resolveAllocator(lua_State* const L_, std::string_view const& hint_) const; + void initializeOnStateCreate(lua_State* L_); + [[nodiscard]] + lanes::AllocatorDefinition resolveAllocator(lua_State* L_, std::string_view const& hint_) const; static inline void Store(lua_State* L_, Universe* U_); [[nodiscard]] bool terminateFreeRunningLanes(lua_Duration shutdownTimeout_, CancelOp op_); @@ -156,7 +158,7 @@ class Universe // ################################################################################################# [[nodiscard]] -inline Universe* Universe::Get(lua_State* L_) +inline Universe* Universe::Get(lua_State* const L_) { STACK_CHECK_START_REL(L_, 0); Universe* const _universe{ kUniverseLightRegKey.readLightUserDataValue(L_) }; @@ -166,7 +168,7 @@ inline Universe* Universe::Get(lua_State* L_) // ################################################################################################# -inline void Universe::Store(lua_State* L_, Universe* U_) +inline void Universe::Store(lua_State* const L_, Universe* const U_) { // TODO: check if we actually ever call Store with a null universe LUA_ASSERT(L_, !U_ || Universe::Get(L_) == nullptr); -- cgit v1.2.3-55-g6feb