From 887fc613dd943d1221d5a2a3b96cee37c0d81248 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Wed, 5 Feb 2025 16:24:35 +0100 Subject: All enums are [[nodiscard]] --- src/allocator.hpp | 6 +++--- src/cancel.hpp | 6 +++--- src/compat.hpp | 6 +++--- src/deep.hpp | 2 +- src/intercopycontext.cpp | 2 +- src/intercopycontext.hpp | 4 ++-- src/keeper.hpp | 4 ++-- src/lane.cpp | 1 + src/lane.hpp | 7 ++++--- src/linda.hpp | 2 +- src/tools.cpp | 2 ++ src/tools.hpp | 3 ++- 12 files changed, 25 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/allocator.hpp b/src/allocator.hpp index 16db1e6..c073391 100644 --- a/src/allocator.hpp +++ b/src/allocator.hpp @@ -68,18 +68,18 @@ namespace lanes { } [[nodiscard]] - void* alloc(size_t const nsize_) + void* alloc(size_t const nsize_) const { return allocF(allocUD, nullptr, 0, nsize_); } [[nodiscard]] - void* alloc(void* const ptr_, size_t const osize_, size_t const nsize_) + void* alloc(void* const ptr_, size_t const osize_, size_t const nsize_) const { return allocF(allocUD, ptr_, osize_, nsize_); } - void free(void* const ptr_, size_t const osize_) + void free(void* const ptr_, size_t const osize_) const { std::ignore = allocF(allocUD, ptr_, osize_, 0); } diff --git a/src/cancel.hpp b/src/cancel.hpp index 65ccf8d..0d59c52 100644 --- a/src/cancel.hpp +++ b/src/cancel.hpp @@ -6,20 +6,20 @@ // ################################################################################################# // Lane cancellation request modes -enum class CancelRequest : uint8_t +enum class [[nodiscard]] CancelRequest : uint8_t { None, // no pending cancel request Soft, // user wants the lane to cancel itself manually on cancel_test() Hard // user wants the lane to be interrupted (meaning code won't return from those functions) from inside linda:send/receive calls }; -struct CancelOp +struct [[nodiscard]] CancelOp { CancelRequest mode; LuaHookMask hookMask; }; -enum class CancelResult : uint8_t +enum class [[nodiscard]] CancelResult : uint8_t { Timeout, Cancelled diff --git a/src/compat.hpp b/src/compat.hpp index 0c7c5bb..d864ae9 100644 --- a/src/compat.hpp +++ b/src/compat.hpp @@ -34,7 +34,7 @@ // ################################################################################################# // a strong-typed wrapper over lua types to see them easier in a debugger -enum class LuaType +enum class [[nodiscard]] LuaType { NONE = LUA_TNONE, NIL = LUA_TNIL, @@ -49,7 +49,7 @@ enum class LuaType CDATA = 10 // LuaJIT CDATA }; -enum class LuaHookMask +enum class [[nodiscard]] LuaHookMask { None = 0, Call = LUA_MASKCALL, @@ -113,7 +113,7 @@ inline int luaL_optint(lua_State* L_, StackIndex n_, lua_Integer d_) // ################################################################################################# // a strong-typed wrapper over lua error codes to see them easier in a debugger -enum class LuaError +enum class [[nodiscard]] LuaError { OK = LUA_OK, YIELD = LUA_YIELD, diff --git a/src/deep.hpp b/src/deep.hpp index f8cfa0d..7d61f42 100644 --- a/src/deep.hpp +++ b/src/deep.hpp @@ -9,7 +9,7 @@ #include "uniquekey.hpp" // forwards -enum class LookupMode; +enum class [[nodiscard]] LookupMode; class DeepFactory; class Universe; diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp index 6b3d282..da4340e 100644 --- a/src/intercopycontext.cpp +++ b/src/intercopycontext.cpp @@ -156,7 +156,7 @@ static constexpr RegistryUniqueKey kMtIdRegKey{ 0xA8895DCF4EC3FE3Cull }; // get a unique ID for metatable at [i]. [[nodiscard]] -static lua_Integer get_mt_id(Universe* U_, lua_State* L_, StackIndex const idx_) +static lua_Integer get_mt_id(Universe* const U_, lua_State* const L_, StackIndex const idx_) { StackIndex const _absidx{ luaG_absindex(L_, idx_) }; diff --git a/src/intercopycontext.hpp b/src/intercopycontext.hpp index cc84017..ece4674 100644 --- a/src/intercopycontext.hpp +++ b/src/intercopycontext.hpp @@ -7,14 +7,14 @@ class Universe; // ################################################################################################# -enum class VT +enum class [[nodiscard]] VT { NORMAL, // keep this one first so that it's the value we get when we default-construct KEY, METATABLE }; -enum class InterCopyResult +enum class [[nodiscard]] InterCopyResult { Success, NotEnoughValues, diff --git a/src/keeper.hpp b/src/keeper.hpp index 4b16c2b..17b56de 100644 --- a/src/keeper.hpp +++ b/src/keeper.hpp @@ -4,7 +4,7 @@ // forwards class Linda; -enum class LookupMode; +enum class [[nodiscard]] LookupMode; class Universe; DECLARE_UNIQUE_TYPE(KeeperState,lua_State*); @@ -13,7 +13,7 @@ DECLARE_UNIQUE_TYPE(KeeperIndex, int); // ################################################################################################# -enum class LindaRestrict +enum class [[nodiscard]] LindaRestrict { None, SetGet, diff --git a/src/lane.cpp b/src/lane.cpp index c3f2996..5b05b4e 100644 --- a/src/lane.cpp +++ b/src/lane.cpp @@ -923,6 +923,7 @@ void Lane::applyDebugName() const // ################################################################################################# +[[nodiscard]] CancelResult Lane::cancel(CancelOp const op_, std::chrono::time_point const until_, WakeLane const wakeLane_, int const hookCount_) { // this is a hook installed with lua_sethook: can't capture anything to be convertible to lua_Hook diff --git a/src/lane.hpp b/src/lane.hpp index 4b0acab..4b5188c 100644 --- a/src/lane.hpp +++ b/src/lane.hpp @@ -44,7 +44,7 @@ static constexpr std::string_view kLaneMetatableName{ "Lane" }; #define kLanesCoreLibName kLanesLibName ".core" // for cancel() argument -enum class WakeLane +enum class [[nodiscard]] WakeLane { No, Yes @@ -60,7 +60,7 @@ class Lane final Running, Suspended, Waiting: Thread is inside the Lua VM. Done, Error, Cancelled: Thread execution is outside the Lua VM. It can be lua_close()d. */ - enum class Status + enum class [[nodiscard]] Status { Pending, Running, @@ -73,7 +73,7 @@ class Lane final }; using enum Status; - enum class ErrorTraceLevel + enum class [[nodiscard]] ErrorTraceLevel { Minimal, // no error handler function when running the lane body Basic, // lane body errors caught by a error handler @@ -163,6 +163,7 @@ class Lane final public: void applyDebugName() const; + [[nodiscard]] CancelResult cancel(CancelOp op_, std::chrono::time_point until_, WakeLane wakeLane_, int hookCount_); void closeState() { diff --git a/src/linda.hpp b/src/linda.hpp index 33fc504..01ca7e1 100644 --- a/src/linda.hpp +++ b/src/linda.hpp @@ -40,7 +40,7 @@ class Linda final } }; - enum class Status + enum class [[nodiscard]] Status { Active, Cancelled diff --git a/src/tools.cpp b/src/tools.cpp index f3be85c..ee6d720 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -67,6 +67,7 @@ static int dummy_writer([[maybe_unused]] lua_State* const L_, [[maybe_unused]] v * +-----------------+-------------------+------------+----------+ */ +[[nodiscard]] FuncSubType luaG_getfuncsubtype(lua_State* const L_, StackIndex const i_) { if (lua_tocfunction(L_, i_)) { // nullptr for LuaJIT-fast && bytecode functions @@ -93,6 +94,7 @@ FuncSubType luaG_getfuncsubtype(lua_State* const L_, StackIndex const i_) namespace tools { // inspired from tconcat() in ltablib.c + [[nodiscard]] std::string_view PushFQN(lua_State* const L_, StackIndex const t_, TableIndex const last_) { STACK_CHECK_START_REL(L_, 0); diff --git a/src/tools.hpp b/src/tools.hpp index 9a62cda..2b8c5b5 100644 --- a/src/tools.hpp +++ b/src/tools.hpp @@ -4,7 +4,7 @@ class Universe; -enum class LookupMode +enum class [[nodiscard]] LookupMode { LaneBody, // send the lane body directly from the source to the destination lane. keep this one first so that it's the value we get when we default-construct ToKeeper, // send a function from a lane to a keeper state @@ -20,6 +20,7 @@ enum class [[nodiscard]] FuncSubType FastJIT }; +[[nodiscard]] FuncSubType luaG_getfuncsubtype(lua_State* L_, StackIndex i_); // ################################################################################################# -- cgit v1.2.3-55-g6feb