From 8e64f794f08cb3e4f930df5bb17c3a7061516cca Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Thu, 2 May 2024 09:05:36 +0200 Subject: Progressively applying the coding rules --- src/cancel.cpp | 12 +++++----- src/deep.cpp | 16 ++++++------- src/deep.h | 8 +++---- src/lanes.cpp | 66 ++++++++++++++++++++++++++--------------------------- src/lanes_private.h | 12 +++++----- src/linda.cpp | 28 +++++++++++------------ src/tools.cpp | 32 +++++++++++++------------- src/uniquekey.h | 14 ++++++------ 8 files changed, 94 insertions(+), 94 deletions(-) (limited to 'src') diff --git a/src/cancel.cpp b/src/cancel.cpp index 9887cba..ed450f0 100644 --- a/src/cancel.cpp +++ b/src/cancel.cpp @@ -112,8 +112,8 @@ LUAG_FUNC(cancel_test) lane_->cancel_request = CancelRequest::Soft; // it's now signaled to stop // negative timeout: we don't want to truly abort the lane, we just want it to react to cancel_test() on its own if (wakeLane_) { // wake the thread so that execution returns from any pending linda operation if desired - std::condition_variable* const waiting_on{ lane_->m_waiting_on }; - if (lane_->m_status == Lane::Waiting && waiting_on != nullptr) { + std::condition_variable* const waiting_on{ lane_->waiting_on }; + if (lane_->status == Lane::Waiting && waiting_on != nullptr) { waiting_on->notify_all(); } } @@ -126,10 +126,10 @@ LUAG_FUNC(cancel_test) [[nodiscard]] static CancelResult thread_cancel_hard(Lane* lane_, lua_Duration duration_, bool wakeLane_) { lane_->cancel_request = CancelRequest::Hard; // it's now signaled to stop - // lane_->m_thread.get_stop_source().request_stop(); + // lane_->thread.get_stop_source().request_stop(); if (wakeLane_) { // wake the thread so that execution returns from any pending linda operation if desired - std::condition_variable* waiting_on = lane_->m_waiting_on; - if (lane_->m_status == Lane::Waiting && waiting_on != nullptr) { + std::condition_variable* waiting_on = lane_->waiting_on; + if (lane_->status == Lane::Waiting && waiting_on != nullptr) { waiting_on->notify_all(); } } @@ -144,7 +144,7 @@ CancelResult thread_cancel(Lane* lane_, CancelOp op_, int hookCount_, lua_Durati { // remember that lanes are not transferable: only one thread can cancel a lane, so no multithreading issue here // We can read 'lane_->status' without locks, but not wait for it (if Posix no PTHREAD_TIMEDJOIN) - if (lane_->m_status >= Lane::Done) { + if (lane_->status >= Lane::Done) { // say "ok" by default, including when lane is already done return CancelResult::Cancelled; } diff --git a/src/deep.cpp b/src/deep.cpp index 6358745..a824f72 100644 --- a/src/deep.cpp +++ b/src/deep.cpp @@ -111,7 +111,7 @@ static void LookupDeep(lua_State* L_) if (mode_ == LookupMode::FromKeeper) { DeepPrelude* const proxy{ *lua_tofulluserdata(L_, index_) }; // we can (and must) cast and fetch the internally stored factory - return &proxy->m_factory; + return &proxy->factory; } else { // essentially we are making sure that the metatable of the object we want to copy is stored in our metatable/factory database // it is the only way to ensure that the userdata is indeed a deep userdata! @@ -138,7 +138,7 @@ static void LookupDeep(lua_State* L_) void DeepFactory::DeleteDeepObject(lua_State* L_, DeepPrelude* o_) { STACK_CHECK_START_REL(L_, 0); - o_->m_factory.deleteDeepObjectInternal(L_, o_); + o_->factory.deleteDeepObjectInternal(L_, o_); STACK_CHECK(L_, 0); } @@ -157,7 +157,7 @@ void DeepFactory::DeleteDeepObject(lua_State* L_, DeepPrelude* o_) // can work without a universe if creating a deep userdata from some external C module when Lanes isn't loaded // in that case, we are not multithreaded and locking isn't necessary anyway - bool const isLastRef{ p->m_refcount.fetch_sub(1, std::memory_order_relaxed) == 1 }; + bool const isLastRef{ p->refcount.fetch_sub(1, std::memory_order_relaxed) == 1 }; if (isLastRef) { // retrieve wrapped __gc @@ -205,10 +205,10 @@ char const* DeepFactory::PushDeepProxy(DestState L_, DeepPrelude* prelude_, int DeepPrelude** const proxy{ lua_newuserdatauv(L_, nuv_) }; // L_: DPC proxy LUA_ASSERT(L_, proxy); *proxy = prelude_; - prelude_->m_refcount.fetch_add(1, std::memory_order_relaxed); // one more proxy pointing to this deep data + prelude_->refcount.fetch_add(1, std::memory_order_relaxed); // one more proxy pointing to this deep data // Get/create metatable for 'factory' (in this state) - DeepFactory& factory = prelude_->m_factory; + DeepFactory& factory = prelude_->factory; lua_pushlightuserdata(L_, std::bit_cast(&factory)); // L_: DPC proxy factory LookupDeep(L_); // L_: DPC proxy metatable|nil @@ -323,14 +323,14 @@ int DeepFactory::pushDeepUserdata(DestState L_, int nuv_) const raise_luaL_error(L_, "DeepFactory::newDeepObjectInternal failed to create deep userdata (out of memory)"); } - if (prelude->m_magic != kDeepVersion) { + if (prelude->magic != kDeepVersion) { // just in case, don't leak the newly allocated deep userdata object deleteDeepObjectInternal(L_, prelude); raise_luaL_error(L_, "Bad Deep Factory: kDeepVersion is incorrect, rebuild your implementation with the latest deep implementation"); } - LUA_ASSERT(L_, prelude->m_refcount.load(std::memory_order_relaxed) == 0); // 'DeepFactory::PushDeepProxy' will lift it to 1 - LUA_ASSERT(L_, &prelude->m_factory == this); + LUA_ASSERT(L_, prelude->refcount.load(std::memory_order_relaxed) == 0); // 'DeepFactory::PushDeepProxy' will lift it to 1 + LUA_ASSERT(L_, &prelude->factory == this); if (lua_gettop(L_) - oldtop != 0) { // just in case, don't leak the newly allocated deep userdata object diff --git a/src/deep.h b/src/deep.h index 6f4e64d..784952c 100644 --- a/src/deep.h +++ b/src/deep.h @@ -38,14 +38,14 @@ static constexpr UniqueKey kDeepVersion{ 0x91171AEC6641E9DBull, "kDeepVersion" } // a deep userdata is a full userdata that stores a single pointer to the actual DeepPrelude-derived object struct DeepPrelude { - UniqueKey const m_magic{ kDeepVersion }; + UniqueKey const magic{ kDeepVersion }; // when stored in a keeper state, the full userdata doesn't have a metatable, so we need direct access to the factory - class DeepFactory& m_factory; + class DeepFactory& factory; // data is destroyed when refcount is 0 - std::atomic m_refcount{ 0 }; + std::atomic refcount{ 0 }; DeepPrelude(DeepFactory& factory_) - : m_factory{ factory_ } + : factory{ factory_ } { } }; diff --git a/src/lanes.cpp b/src/lanes.cpp index 91a2f8b..38fe2b9 100644 --- a/src/lanes.cpp +++ b/src/lanes.cpp @@ -176,10 +176,10 @@ bool Lane::waitForCompletion(lua_Duration duration_) until = std::chrono::steady_clock::now() + std::chrono::duration_cast(duration_); } - std::unique_lock lock{ m_done_mutex }; - // std::stop_token token{ m_thread.get_stop_token() }; - // return m_done_signal.wait_until(lock, token, secs_, [this](){ return m_status >= Lane::Done; }); - return m_done_signal.wait_until(lock, until, [this]() { return m_status >= Lane::Done; }); + std::unique_lock lock{ done_mutex }; + // std::stop_token token{ thread.get_stop_token() }; + // return done_signal.wait_until(lock, token, secs_, [this](){ return status >= Lane::Done; }); + return done_signal.wait_until(lock, until, [this]() { return status >= Lane::Done; }); } // ################################################################################################# @@ -187,9 +187,9 @@ bool Lane::waitForCompletion(lua_Duration duration_) static void lane_main(Lane* lane); void Lane::startThread(int priority_) { - m_thread = std::jthread([this]() { lane_main(this); }); + thread = std::jthread([this]() { lane_main(this); }); if (priority_ != kThreadPrioDefault) { - JTHREAD_SET_PRIORITY(m_thread, priority_, U->m_sudo); + JTHREAD_SET_PRIORITY(thread, priority_, U->m_sudo); } } @@ -441,7 +441,7 @@ static void selfdestruct_add(Lane* lane_) // cancel/kill). // if (lane_->selfdestruct_next != nullptr) { - Lane** ref = (Lane**) &lane_->U->selfdestruct_first; + Lane* volatile* ref = static_cast(&lane_->U->selfdestruct_first); while (*ref != SELFDESTRUCT_END) { if (*ref == lane_) { @@ -452,7 +452,7 @@ static void selfdestruct_add(Lane* lane_) found = true; break; } - ref = (Lane**) &((*ref)->selfdestruct_next); + ref = static_cast(&((*ref)->selfdestruct_next)); } assert(found); } @@ -479,7 +479,7 @@ static void selfdestruct_add(Lane* lane_) // attempt the requested cancel with a small timeout. // if waiting on a linda, they will raise a cancel_error. // if a cancellation hook is desired, it will be installed to try to raise an error - if (lane->m_thread.joinable()) { + if (lane->thread.joinable()) { std::ignore = thread_cancel(lane, op, 1, timeout, true); } lane = lane->selfdestruct_next; @@ -532,7 +532,7 @@ static void selfdestruct_add(Lane* lane_) // no need to mutex-protect this as all threads in the universe are gone at that point if (U->timer_deep != nullptr) { // test ins case some early internal error prevented Lanes from creating the deep timer - [[maybe_unused]] int const prev_ref_count{ U->timer_deep->m_refcount.fetch_sub(1, std::memory_order_relaxed) }; + [[maybe_unused]] int const prev_ref_count{ U->timer_deep->refcount.fetch_sub(1, std::memory_order_relaxed) }; LUA_ASSERT(L_, prev_ref_count == 1); // this should be the last reference DeepFactory::DeleteDeepObject(L_, U->timer_deep); U->timer_deep = nullptr; @@ -784,13 +784,13 @@ static void lane_main(Lane* lane_) { lua_State* const L{ lane_->L }; // wait until the launching thread has finished preparing L - lane_->m_ready.wait(); + lane_->ready.wait(); int rc{ LUA_ERRRUN }; - if (lane_->m_status == Lane::Pending) { // nothing wrong happened during preparation, we can work + if (lane_->status == Lane::Pending) { // nothing wrong happened during preparation, we can work // At this point, the lane function and arguments are on the stack int const nargs{ lua_gettop(L) - 1 }; DEBUGSPEW_CODE(Universe* U = universe_get(L)); - lane_->m_status = Lane::Running; // Pending -> Running + lane_->status = Lane::Running; // Pending -> Running // Tie "set_finalizer()" to the state lua_pushcfunction(L, LG_set_finalizer); @@ -838,7 +838,7 @@ static void lane_main(Lane* lane_) // the finalizer generated an error, and left its own error message [and stack trace] on the stack rc = rc2; // we're overruling the earlier script error or normal return } - lane_->m_waiting_on = nullptr; // just in case + lane_->waiting_on = nullptr; // just in case if (selfdestruct_remove(lane_)) { // check and remove (under lock!) // We're a free-running thread and no-one's there to clean us up. lua_close(lane_->L); @@ -849,7 +849,7 @@ static void lane_main(Lane* lane_) lane_->U->selfdestruct_cs.unlock(); // we destroy our jthread member from inside the thread body, so we have to detach so that we don't try to join, as this doesn't seem a good idea - lane_->m_thread.detach(); + lane_->thread.detach(); delete lane_; lane_ = nullptr; } @@ -860,10 +860,10 @@ static void lane_main(Lane* lane_) Lane::Status const st = (rc == LUA_OK) ? Lane::Done : kCancelError.equals(L, 1) ? Lane::Cancelled : Lane::Error; { - // 'm_done_mutex' protects the -> Done|Error|Cancelled state change - std::lock_guard lock{ lane_->m_done_mutex }; - lane_->m_status = st; - lane_->m_done_signal.notify_one(); // wake up master (while 'lane_->m_done_mutex' is on) + // 'done_mutex' protects the -> Done|Error|Cancelled state change + std::lock_guard lock{ lane_->done_mutex }; + lane_->status = st; + lane_->done_signal.notify_one(); // wake up master (while 'lane_->done_mutex' is on) } } } @@ -994,12 +994,12 @@ LUAG_FUNC(lane_new) lua_settop(m_lane->L, 0); kCancelError.pushKey(m_lane->L); { - std::lock_guard lock{ m_lane->m_done_mutex }; - m_lane->m_status = Lane::Cancelled; - m_lane->m_done_signal.notify_one(); // wake up master (while 'lane->m_done_mutex' is on) + std::lock_guard lock{ m_lane->done_mutex }; + m_lane->status = Lane::Cancelled; + m_lane->done_signal.notify_one(); // wake up master (while 'lane->done_mutex' is on) } // unblock the thread so that it can terminate gracefully - m_lane->m_ready.count_down(); + m_lane->ready.count_down(); } } @@ -1037,7 +1037,7 @@ LUAG_FUNC(lane_new) void success() { prepareUserData(); - m_lane->m_ready.count_down(); + m_lane->ready.count_down(); m_lane = nullptr; } } onExit{ L_, lane, gc_cb_idx DEBUGSPEW_COMMA_PARAM(U) }; @@ -1214,7 +1214,7 @@ LUAG_FUNC(lane_new) } // We can read 'lane->status' without locks, but not wait for it - if (lane->m_status < Lane::Done) { + if (lane->status < Lane::Done) { // still running: will have to be cleaned up later selfdestruct_add(lane); assert(lane->selfdestruct_next); @@ -1272,7 +1272,7 @@ LUAG_FUNC(lane_new) void Lane::pushThreadStatus(lua_State* L_) { - char const* const str{ thread_status_string(m_status) }; + char const* const str{ thread_status_string(status) }; LUA_ASSERT(L_, str); lua_pushstring(L_, str); @@ -1294,7 +1294,7 @@ LUAG_FUNC(thread_join) lua_Duration const duration{ luaL_optnumber(L_, 2, -1.0) }; lua_State* const L2{ lane->L }; - bool const done{ !lane->m_thread.joinable() || lane->waitForCompletion(duration) }; + bool const done{ !lane->thread.joinable() || lane->waitForCompletion(duration) }; if (!done || !L2) { STACK_GROW(L_, 2); lua_pushnil(L_); // L_: lane timeout? nil @@ -1310,7 +1310,7 @@ LUAG_FUNC(thread_join) // debug_name is a pointer to string possibly interned in the lane's state, that no longer exists when the state is closed // so store it in the userdata uservalue at a key that can't possibly collide securize_debug_threadname(L_, lane); - switch (lane->m_status) { + switch (lane->status) { case Lane::Done: { int const n{ lua_gettop(L2) }; // whole L2 stack @@ -1343,7 +1343,7 @@ LUAG_FUNC(thread_join) break; default: - DEBUGSPEW_CODE(fprintf(stderr, "Status: %d\n", lane->m_status)); + DEBUGSPEW_CODE(fprintf(stderr, "Status: %d\n", lane->status)); LUA_ASSERT(L_, false); ret = 0; } @@ -1399,12 +1399,12 @@ LUAG_FUNC(thread_index) lua_pushcfunction(L_, LG_thread_join); lua_pushvalue(L_, kSelf); lua_call(L_, 1, LUA_MULTRET); // all return values are on the stack, at slots 4+ - switch (lane->m_status) { + switch (lane->status) { default: // this is an internal error, we probably never get here lua_settop(L_, 0); lua_pushliteral(L_, "Unexpected status: "); - lua_pushstring(L_, thread_status_string(lane->m_status)); + lua_pushstring(L_, thread_status_string(lane->status)); lua_concat(L_, 2); raise_lua_error(L_); [[fallthrough]]; // fall through if we are killed, as we got nil, "killed" on the stack @@ -1666,7 +1666,7 @@ LUAG_FUNC(configure) U->tracking_first = lua_toboolean(L_, -1) ? TRACKING_END : nullptr; lua_pop(L_, 1); // L_: settings #endif // HAVE_LANE_TRACKING() - // Linked chains handling + // Linked chains handling U->selfdestruct_first = SELFDESTRUCT_END; initialize_allocator_function(U, L_); initialize_on_state_create(U, L_); @@ -1682,7 +1682,7 @@ LUAG_FUNC(configure) // Proxy userdata contents is only a 'DeepPrelude*' pointer U->timer_deep = *lua_tofulluserdata(L_, -1); // increment refcount so that this linda remains alive as long as the universe exists. - U->timer_deep->m_refcount.fetch_add(1, std::memory_order_relaxed); + U->timer_deep->refcount.fetch_add(1, std::memory_order_relaxed); lua_pop(L_, 1); // L_: settings } STACK_CHECK(L_, 1); diff --git a/src/lanes_private.h b/src/lanes_private.h index 083ac4e..1d476cf 100644 --- a/src/lanes_private.h +++ b/src/lanes_private.h @@ -33,12 +33,12 @@ class Lane using enum Status; // the thread - std::jthread m_thread; + std::jthread thread; // a latch to wait for the lua_State to be ready - std::latch m_ready{ 1 }; + std::latch ready{ 1 }; // to wait for stop requests through m_thread's stop_source - std::mutex m_done_mutex; - std::condition_variable m_done_signal; // use condition_variable_any if waiting for a stop_token + std::mutex done_mutex; + std::condition_variable done_signal; // use condition_variable_any if waiting for a stop_token // // M: sub-thread OS thread // S: not used @@ -51,12 +51,12 @@ class Lane // M: prepares the state, and reads results // S: while S is running, M must keep out of modifying the state - Status volatile m_status{ Pending }; + Status volatile status{ Pending }; // // M: sets to Pending (before launching) // S: updates -> Running/Waiting -> Done/Error/Cancelled - std::condition_variable* volatile m_waiting_on{ nullptr }; + std::condition_variable* volatile waiting_on{ nullptr }; // // When status is Waiting, points on the linda's signal the thread waits on, else nullptr diff --git a/src/linda.cpp b/src/linda.cpp index 82f5f98..cda3a63 100644 --- a/src/linda.cpp +++ b/src/linda.cpp @@ -133,7 +133,7 @@ static void check_key_types(lua_State* L_, int start_, int end_) static constexpr std::array, 3> kKeysToCheck{ kLindaBatched, kCancelError, kNilSentinel }; for (UniqueKey const& key : kKeysToCheck) { if (key.equals(L_, i)) { - raise_luaL_error(L_, "argument #%d: can't use %s as a key", i, key.m_debugName); + raise_luaL_error(L_, "argument #%d: can't use %s as a key", i, key.debugName); break; } } @@ -276,20 +276,20 @@ LUAG_FUNC(linda_send) Lane::Status prev_status{ Lane::Error }; // prevent 'might be used uninitialized' warnings if (lane != nullptr) { // change status of lane to "waiting" - prev_status = lane->m_status; // Running, most likely + prev_status = lane->status; // Running, most likely LUA_ASSERT(L_, prev_status == Lane::Running); // but check, just in case - lane->m_status = Lane::Waiting; - LUA_ASSERT(L_, lane->m_waiting_on == nullptr); - lane->m_waiting_on = &linda->m_read_happened; + lane->status = Lane::Waiting; + LUA_ASSERT(L_, lane->waiting_on == nullptr); + lane->waiting_on = &linda->m_read_happened; } // could not send because no room: wait until some data was read before trying again, or until timeout is reached std::unique_lock keeper_lock{ K->m_mutex, std::adopt_lock }; std::cv_status const status{ linda->m_read_happened.wait_until(keeper_lock, until) }; - keeper_lock.release(); // we don't want to release the lock! + keeper_lock.release(); // we don't want to release the lock! try_again = (status == std::cv_status::no_timeout); // detect spurious wakeups if (lane != nullptr) { - lane->m_waiting_on = nullptr; - lane->m_status = prev_status; + lane->waiting_on = nullptr; + lane->status = prev_status; } } } @@ -423,11 +423,11 @@ LUAG_FUNC(linda_receive) Lane::Status prev_status{ Lane::Error }; // prevent 'might be used uninitialized' warnings if (lane != nullptr) { // change status of lane to "waiting" - prev_status = lane->m_status; // Running, most likely + prev_status = lane->status; // Running, most likely LUA_ASSERT(L_, prev_status == Lane::Running); // but check, just in case - lane->m_status = Lane::Waiting; - LUA_ASSERT(L_, lane->m_waiting_on == nullptr); - lane->m_waiting_on = &linda->m_write_happened; + lane->status = Lane::Waiting; + LUA_ASSERT(L_, lane->waiting_on == nullptr); + lane->waiting_on = &linda->m_write_happened; } // not enough data to read: wakeup when data was sent, or when timeout is reached std::unique_lock keeper_lock{ K->m_mutex, std::adopt_lock }; @@ -435,8 +435,8 @@ LUAG_FUNC(linda_receive) keeper_lock.release(); // we don't want to release the lock! try_again = (status == std::cv_status::no_timeout); // detect spurious wakeups if (lane != nullptr) { - lane->m_waiting_on = nullptr; - lane->m_status = prev_status; + lane->waiting_on = nullptr; + lane->status = prev_status; } } } diff --git a/src/tools.cpp b/src/tools.cpp index f4fbf46..c4ce24f 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -648,14 +648,14 @@ static constexpr RegistryUniqueKey kMtIdRegKey{ 0xA8895DCF4EC3FE3Cull }; lua_getglobal(L2, "decoda_name"); // L1: ... t ... L2: {} t decoda_name to = lua_tostring(L2, -1); lua_pop(L2, 1); // L1: ... t ... L2: {} t - // when mode_ == LookupMode::FromKeeper, L is a keeper state and L2 is not, therefore L2 is the state where we want to raise the error + // when mode_ == LookupMode::FromKeeper, L1 is a keeper state and L2 is not, therefore L2 is the state where we want to raise the error raise_luaL_error( (mode == LookupMode::FromKeeper) ? L2 : L1, "INTERNAL ERROR IN %s: table '%s' not found in %s destination transfer database.", from ? from : "main", fqn, - to ? to : "main"); - return false; + to ? to : "main" + ); } lua_remove(L2, -2); // L1: ... t ... L2: t break; @@ -1025,7 +1025,7 @@ void InterCopyContext::copy_func() const // transfer the bytecode, then the upvalues, to create a similar closure { - char const* name = nullptr; + char const* fname = nullptr; #define LOG_FUNC_INFO 0 #if LOG_FUNC_INFO // "To get information about a function you push it onto the @@ -1034,9 +1034,9 @@ void InterCopyContext::copy_func() const { lua_Debug ar; lua_pushvalue(L1, L1_i); // L1: ... b f - // fills 'name' 'namewhat' and 'linedefined', pops function + // fills 'fname' 'namewhat' and 'linedefined', pops function lua_getinfo(L1, ">nS", &ar); // L1: ... b - name = ar.namewhat; + fname = ar.namewhat; DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "FNAME: %s @ %d" INDENT_END(U), ar.short_src, ar.linedefined)); // just gives nullptr } #endif // LOG_FUNC_INFO @@ -1046,17 +1046,17 @@ void InterCopyContext::copy_func() const LUA_ASSERT(L1, s && sz); STACK_GROW(L2, 2); // Note: Line numbers seem to be taken precisely from the - // original function. 'name' is not used since the chunk + // original function. 'fname' is not used since the chunk // is precompiled (it seems...). // // TBD: Can we get the function's original name through, as well? // - if (luaL_loadbuffer(L2, s, sz, name) != 0) { // L2: ... {cache} ... p function + if (luaL_loadbuffer(L2, s, sz, fname) != 0) { // L2: ... {cache} ... p function // chunk is precompiled so only LUA_ERRMEM can happen // "Otherwise, it pushes an error message" // STACK_GROW(L1, 1); - raise_luaL_error(L1, "%s: %s", name, lua_tostring(L2, -1)); + raise_luaL_error(L1, "%s: %s", fname, lua_tostring(L2, -1)); } // remove the dumped string lua_pop(L1, 1); // ... @@ -1285,8 +1285,8 @@ void InterCopyContext::inter_copy_keyvaluepair() const [[nodiscard]] bool InterCopyContext::tryCopyClonable() const { - SourceIndex const L1_i{ lua_absindex(L1, this->L1_i) }; - void* const source{ lua_touserdata(L1, L1_i) }; + SourceIndex const L1i{ lua_absindex(L1, L1_i) }; + void* const source{ lua_touserdata(L1, L1i) }; STACK_CHECK_START_REL(L1, 0); STACK_CHECK_START_REL(L2, 0); @@ -1303,7 +1303,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const STACK_CHECK(L2, 0); // no metatable? -> not clonable - if (!lua_getmetatable(L1, L1_i)) { // L1: ... mt? + if (!lua_getmetatable(L1, L1i)) { // L1: ... mt? STACK_CHECK(L1, 0); return false; } @@ -1319,10 +1319,10 @@ void InterCopyContext::inter_copy_keyvaluepair() const // we need to copy over the uservalues of the userdata as well { int const mt{ lua_absindex(L1, -2) }; // L1: ... mt __lanesclone - size_t const userdata_size{ lua_rawlen(L1, L1_i) }; + size_t const userdata_size{ lua_rawlen(L1, L1i) }; // extract all the uservalues, but don't transfer them yet int uvi = 0; - while (lua_getiuservalue(L1, L1_i, ++uvi) != LUA_TNONE) {} // L1: ... mt __lanesclone [uv]+ nil + while (lua_getiuservalue(L1, L1i, ++uvi) != LUA_TNONE) {} // L1: ... mt __lanesclone [uv]+ nil // when lua_getiuservalue() returned LUA_TNONE, it pushed a nil. pop it now lua_pop(L1, 1); // L1: ... mt __lanesclone [uv]+ --uvi; @@ -1811,7 +1811,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const DEBUGSPEW_CODE(DebugSpewIndentScope m_scope); public: - OnExit(Universe* U_, lua_State* L2_) + OnExit(DEBUGSPEW_PARAM_COMMA(Universe* U_) lua_State* L2_) : L2{ L2_ } , top_L2{ lua_gettop(L2) } DEBUGSPEW_COMMA_PARAM(m_scope{ U_ }) { @@ -1821,7 +1821,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const { lua_settop(L2, top_L2); } - } onExit{ U, L2 }; + } onExit{ DEBUGSPEW_PARAM_COMMA(U) L2 }; STACK_CHECK_START_REL(L1, 0); if (lua_type_as_enum(L1, L1_i) != LuaType::TABLE) { diff --git a/src/uniquekey.h b/src/uniquekey.h index 984ef50..da699b0 100644 --- a/src/uniquekey.h +++ b/src/uniquekey.h @@ -10,19 +10,19 @@ class UniqueKey { protected: - uintptr_t const m_storage{ 0 }; + uintptr_t const storage{ 0 }; public: - char const* m_debugName{ nullptr }; + char const* debugName{ nullptr }; // --------------------------------------------------------------------------------------------- constexpr explicit UniqueKey(uint64_t val_, char const* debugName_ = nullptr) #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{ static_cast(val_ & 0x7FFFFFFFFFFFull) } + : storage{ static_cast(val_ & 0x7FFFFFFFFFFFull) } #else // LUAJIT_FLAVOR() - : m_storage{ static_cast(val_) } + : storage{ static_cast(val_) } #endif // LUAJIT_FLAVOR() - , m_debugName{ debugName_ } + , debugName{ debugName_ } { } // --------------------------------------------------------------------------------------------- @@ -32,12 +32,12 @@ class UniqueKey // --------------------------------------------------------------------------------------------- bool equals(lua_State* const L_, int i_) const { - return lua_touserdata(L_, i_) == std::bit_cast(m_storage); + return lua_touserdata(L_, i_) == std::bit_cast(storage); } // --------------------------------------------------------------------------------------------- void pushKey(lua_State* const L_) const { - lua_pushlightuserdata(L_, std::bit_cast(m_storage)); + lua_pushlightuserdata(L_, std::bit_cast(storage)); } }; -- cgit v1.2.3-55-g6feb