aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2024-12-17 11:53:15 +0100
committerBenoit Germain <benoit.germain@ubisoft.com>2024-12-17 11:53:15 +0100
commit48c99e29ae38db79522fb2833f3144ae58c7a906 (patch)
tree4fbf42918fa22fad025e75733dbe3caf76325f9b /src
parentefd5318b2d9132996bf35a6af2e82706665890ff (diff)
downloadlanes-48c99e29ae38db79522fb2833f3144ae58c7a906.tar.gz
lanes-48c99e29ae38db79522fb2833f3144ae58c7a906.tar.bz2
lanes-48c99e29ae38db79522fb2833f3144ae58c7a906.zip
Some constitude tweaks
Diffstat (limited to 'src')
-rw-r--r--src/compat.hpp8
-rw-r--r--src/deep.hpp2
-rw-r--r--src/keeper.hpp2
-rw-r--r--src/lane.hpp4
-rw-r--r--src/linda.hpp4
-rw-r--r--src/lindafactory.hpp2
-rw-r--r--src/macros_and_utils.hpp2
-rw-r--r--src/uniquekey.hpp1
-rw-r--r--src/universe.cpp2
-rw-r--r--src/universe.hpp22
10 files changed, 25 insertions, 24 deletions
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_)
68{ 68{
69 return lua_objlen(L_, idx_); 69 return lua_objlen(L_, idx_);
70} 70}
71void luaL_requiref(lua_State* L_, const char* modname_, lua_CFunction openf_, int glb_); // implementation copied from Lua 5.2 sources 71void luaL_requiref(lua_State* L_, char const* modname_, lua_CFunction openf_, int glb_); // implementation copied from Lua 5.2 sources
72 72
73int luaL_getsubtable(lua_State* L_, StackIndex idx_, const char* fname_); 73int luaL_getsubtable(lua_State* L_, StackIndex idx_, char const* fname_);
74 74
75#endif // LUA_VERSION_NUM == 501 75#endif // LUA_VERSION_NUM == 501
76 76
@@ -292,7 +292,7 @@ ENUM luaG_optenum(lua_State* const L_, StackIndex const idx_, ENUM const def_)
292 292
293// ################################################################################################# 293// #################################################################################################
294 294
295inline void luaG_registerlibfuncs(lua_State* L_, luaL_Reg const* funcs_) 295inline void luaG_registerlibfuncs(lua_State* const L_, luaL_Reg const* funcs_)
296{ 296{
297 // fake externs to make clang happy... 297 // fake externs to make clang happy...
298 extern void luaL_register(lua_State*, char const*, luaL_Reg const*); // Lua 5.1 298 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_)
396 396
397// ################################################################################################# 397// #################################################################################################
398 398
399inline void luaG_setfield(lua_State* const L_, StackIndex const idx_, char const* k_) = delete; 399inline void luaG_setfield(lua_State* const L_, StackIndex const idx_, char const* const k_) = delete;
400inline void luaG_setfield(lua_State* const L_, StackIndex const idx_, std::string_view const& k_) 400inline void luaG_setfield(lua_State* const L_, StackIndex const idx_, std::string_view const& k_)
401{ 401{
402 lua_setfield(L_, idx_, k_.data()); 402 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
86 [[nodiscard]] 86 [[nodiscard]]
87 int getObjectCount() const { return deepObjectCount.load(std::memory_order_relaxed); } 87 int getObjectCount() const { return deepObjectCount.load(std::memory_order_relaxed); }
88 [[nodiscard]] 88 [[nodiscard]]
89 static bool IsDeepUserdata(lua_State* const L_, StackIndex const idx_); 89 static bool IsDeepUserdata(lua_State* L_, StackIndex idx_);
90 [[nodiscard]] 90 [[nodiscard]]
91 static DeepFactory* LookupFactory(lua_State* L_, StackIndex index_, LookupMode mode_); 91 static DeepFactory* LookupFactory(lua_State* L_, StackIndex index_, LookupMode mode_);
92 static void PushDeepProxy(DestState L_, DeepPrelude* o_, UserValueCount nuv_, LookupMode mode_, lua_State* errL_); 92 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
70 70
71 public: 71 public:
72 // can only be instanced as a data member 72 // can only be instanced as a data member
73 static void* operator new(size_t size_) = delete; 73 static void* operator new(size_t const size_) = delete;
74 74
75 Keepers() = default; 75 Keepers() = default;
76 void collectGarbage(); 76 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
166 CancelResult cancel(CancelOp op_, std::chrono::time_point<std::chrono::steady_clock> until_, WakeLane wakeLane_, int hookCount_); 166 CancelResult cancel(CancelOp op_, std::chrono::time_point<std::chrono::steady_clock> until_, WakeLane wakeLane_, int hookCount_);
167 void closeState() 167 void closeState()
168 { 168 {
169 lua_State* const _L{ S };
170 S = nullptr;
171 L = nullptr; 169 L = nullptr;
172 nresults = 0; 170 nresults = 0;
173 lua_close(_L); // this collects our coroutine thread at the same time 171 lua_close(std::exchange(S, nullptr)); // this collects our coroutine thread at the same time
174 } 172 }
175 [[nodiscard]] 173 [[nodiscard]]
176 std::string_view errorTraceLevelString() const; 174 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
92 [[nodiscard]] 92 [[nodiscard]]
93 Keeper* acquireKeeper() const; 93 Keeper* acquireKeeper() const;
94 [[nodiscard]] 94 [[nodiscard]]
95 static Linda* CreateTimerLinda(lua_State* const L_, Passkey<Universe>) { return CreateTimerLinda(L_); } 95 static Linda* CreateTimerLinda(lua_State* const L_, Passkey<Universe> const) { return CreateTimerLinda(L_); }
96 static void DeleteTimerLinda(lua_State* const L_, Linda* const linda_, Passkey<Universe>) { DeleteTimerLinda(L_, linda_); } 96 static void DeleteTimerLinda(lua_State* const L_, Linda* const linda_, Passkey<Universe> const) { DeleteTimerLinda(L_, linda_); }
97 [[nodiscard]] 97 [[nodiscard]]
98 std::string_view getName() const; 98 std::string_view getName() const;
99 [[nodiscard]] 99 [[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
8: public DeepFactory 8: public DeepFactory
9{ 9{
10 public: 10 public:
11 // I'm not totally happy with having a 'global' variable. Maybe it should be dynamically created and stored somewhere in the universe? 11 // TODO: I'm not totally happy with having a 'global' variable. Maybe it should be dynamically created and stored somewhere in the universe?
12 static LindaFactory Instance; 12 static LindaFactory Instance;
13 13
14 LindaFactory(luaL_Reg const lindaMT_[]) 14 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;
8 8
9// ################################################################################################# 9// #################################################################################################
10 10
11inline void STACK_GROW(lua_State* L_, int n_) 11inline void STACK_GROW(lua_State* const L_, int const n_)
12{ 12{
13 if (!lua_checkstack(L_, n_)) { 13 if (!lua_checkstack(L_, n_)) {
14 raise_luaL_error(L_, "Cannot grow stack!"); 14 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
64 } 64 }
65 // --------------------------------------------------------------------------------------------- 65 // ---------------------------------------------------------------------------------------------
66 template <typename OP> 66 template <typename OP>
67 // TODO: add a requirement clause here for operation_ to be callable on L_
67 void setValue(lua_State* const L_, OP operation_) const 68 void setValue(lua_State* const L_, OP operation_) const
68 { 69 {
69 // Note we can't check stack consistency because operation is not always a push (could be insert, replace, whatever) 70 // 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_)
186 186
187// same as PUC-Lua l_alloc 187// same as PUC-Lua l_alloc
188[[nodiscard]] 188[[nodiscard]]
189static void* libc_lua_Alloc([[maybe_unused]] void* ud_, [[maybe_unused]] void* ptr_, [[maybe_unused]] size_t osize_, size_t nsize_) 189static void* libc_lua_Alloc([[maybe_unused]] void* const ud_, [[maybe_unused]] void* const ptr_, [[maybe_unused]] size_t const osize_, size_t const nsize_)
190{ 190{
191 if (nsize_ == 0) { 191 if (nsize_ == 0) {
192 free(ptr_); 192 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
26 std::mutex mutex; 26 std::mutex mutex;
27 27
28 [[nodiscard]] 28 [[nodiscard]]
29 static void* protected_lua_Alloc(void* ud_, void* ptr_, size_t osize_, size_t nsize_) 29 static void* protected_lua_Alloc(void* const ud_, void* const ptr_, size_t const osize_, size_t const nsize_)
30 { 30 {
31 ProtectedAllocator* const allocator{ static_cast<ProtectedAllocator*>(ud_) }; 31 ProtectedAllocator* const allocator{ static_cast<ProtectedAllocator*>(ud_) };
32 std::lock_guard<std::mutex> guard{ allocator->mutex }; 32 std::lock_guard<std::mutex> guard{ allocator->mutex };
@@ -36,8 +36,8 @@ class ProtectedAllocator
36 public: 36 public:
37 // 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) 37 // 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)
38 [[nodiscard]] 38 [[nodiscard]]
39 static void* operator new(size_t size_, lua_State* L_) noexcept = delete; 39 static void* operator new(size_t const size_, lua_State* const L_) noexcept = delete;
40 static void operator delete(void* p_, lua_State* L_) = delete; 40 static void operator delete(void* const p_, lua_State* const L_) = delete;
41 41
42 AllocatorDefinition makeDefinition() 42 AllocatorDefinition makeDefinition()
43 { 43 {
@@ -58,6 +58,7 @@ class ProtectedAllocator
58}; 58};
59 59
60// ################################################################################################# 60// #################################################################################################
61// #################################################################################################
61 62
62// xxh64 of string "kUniverseLightRegKey" generated at https://www.pelock.com/products/hash-calculator 63// xxh64 of string "kUniverseLightRegKey" generated at https://www.pelock.com/products/hash-calculator
63static constexpr RegistryUniqueKey kUniverseLightRegKey{ 0x48BBE9CEAB0BA04Full }; 64static constexpr RegistryUniqueKey kUniverseLightRegKey{ 0x48BBE9CEAB0BA04Full };
@@ -127,9 +128,9 @@ class Universe
127 128
128 public: 129 public:
129 [[nodiscard]] 130 [[nodiscard]]
130 static void* operator new([[maybe_unused]] size_t size_, lua_State* L_) noexcept { return luaG_newuserdatauv<Universe>(L_, UserValueCount{ 0 }); }; 131 static void* operator new([[maybe_unused]] size_t const size_, lua_State* const L_) noexcept { return luaG_newuserdatauv<Universe>(L_, UserValueCount{ 0 }); };
131 // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception 132 // can't actually delete the operator because the compiler generates stack unwinding code that could call it in case of exception
132 static void operator delete([[maybe_unused]] void* p_, [[maybe_unused]] lua_State* L_) {} // nothing to do, as nothing is allocated independently 133 static void operator delete([[maybe_unused]] void* const p_, [[maybe_unused]] lua_State* const L_) {} // nothing to do, as nothing is allocated independently
133 134
134 Universe(); 135 Universe();
135 ~Universe() = default; 136 ~Universe() = default;
@@ -139,15 +140,16 @@ class Universe
139 Universe& operator=(Universe const&) = delete; 140 Universe& operator=(Universe const&) = delete;
140 Universe& operator=(Universe&&) = delete; 141 Universe& operator=(Universe&&) = delete;
141 142
142 void callOnStateCreate(lua_State* const L_, lua_State* const from_, LookupMode const mode_); 143 void callOnStateCreate(lua_State* L_, lua_State* from_, LookupMode mode_);
143 [[nodiscard]] 144 [[nodiscard]]
144 static Universe* Create(lua_State* L_); 145 static Universe* Create(lua_State* L_);
145 [[nodiscard]] 146 [[nodiscard]]
146 static inline Universe* Get(lua_State* L_); 147 static inline Universe* Get(lua_State* L_);
147 void initializeAllocatorFunction(lua_State* L_); 148 void initializeAllocatorFunction(lua_State* L_);
148 static int InitializeFinalizer(lua_State* L_); 149 static int InitializeFinalizer(lua_State* L_);
149 void initializeOnStateCreate(lua_State* const L_); 150 void initializeOnStateCreate(lua_State* L_);
150 lanes::AllocatorDefinition resolveAllocator(lua_State* const L_, std::string_view const& hint_) const; 151 [[nodiscard]]
152 lanes::AllocatorDefinition resolveAllocator(lua_State* L_, std::string_view const& hint_) const;
151 static inline void Store(lua_State* L_, Universe* U_); 153 static inline void Store(lua_State* L_, Universe* U_);
152 [[nodiscard]] 154 [[nodiscard]]
153 bool terminateFreeRunningLanes(lua_Duration shutdownTimeout_, CancelOp op_); 155 bool terminateFreeRunningLanes(lua_Duration shutdownTimeout_, CancelOp op_);
@@ -156,7 +158,7 @@ class Universe
156// ################################################################################################# 158// #################################################################################################
157 159
158[[nodiscard]] 160[[nodiscard]]
159inline Universe* Universe::Get(lua_State* L_) 161inline Universe* Universe::Get(lua_State* const L_)
160{ 162{
161 STACK_CHECK_START_REL(L_, 0); 163 STACK_CHECK_START_REL(L_, 0);
162 Universe* const _universe{ kUniverseLightRegKey.readLightUserDataValue<Universe>(L_) }; 164 Universe* const _universe{ kUniverseLightRegKey.readLightUserDataValue<Universe>(L_) };
@@ -166,7 +168,7 @@ inline Universe* Universe::Get(lua_State* L_)
166 168
167// ################################################################################################# 169// #################################################################################################
168 170
169inline void Universe::Store(lua_State* L_, Universe* U_) 171inline void Universe::Store(lua_State* const L_, Universe* const U_)
170{ 172{
171 // TODO: check if we actually ever call Store with a null universe 173 // TODO: check if we actually ever call Store with a null universe
172 LUA_ASSERT(L_, !U_ || Universe::Get(L_) == nullptr); 174 LUA_ASSERT(L_, !U_ || Universe::Get(L_) == nullptr);