From ac8caa415b36c875578c2ad0490965b80be2f37e Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Mon, 20 May 2024 15:57:03 +0200 Subject: More string_view --- src/cancel.cpp | 16 ++++----- src/cancel.h | 4 ++- src/compat.h | 11 ++++++ src/intercopycontext.cpp | 87 +++++++++++++++++++++++------------------------- src/lanes.cpp | 9 +++-- src/lindafactory.cpp | 9 +++-- src/tools.cpp | 31 ++++++++--------- src/universe.cpp | 6 ++-- 8 files changed, 88 insertions(+), 85 deletions(-) (limited to 'src') diff --git a/src/cancel.cpp b/src/cancel.cpp index ff7af1e..f093905 100644 --- a/src/cancel.cpp +++ b/src/cancel.cpp @@ -162,20 +162,20 @@ CancelResult thread_cancel(Lane* lane_, CancelOp op_, int hookCount_, std::chron // ################################################################################################# // ################################################################################################# -CancelOp which_cancel_op(char const* opString_) +CancelOp which_cancel_op(std::string_view const& opString_) { CancelOp _op{ CancelOp::Invalid }; - if (strcmp(opString_, "hard") == 0) { + if (opString_ == "hard") { _op = CancelOp::Hard; - } else if (strcmp(opString_, "soft") == 0) { + } else if (opString_ == "soft") { _op = CancelOp::Soft; - } else if (strcmp(opString_, "call") == 0) { + } else if (opString_== "call") { _op = CancelOp::MaskCall; - } else if (strcmp(opString_, "ret") == 0) { + } else if (opString_ == "ret") { _op = CancelOp::MaskRet; - } else if (strcmp(opString_, "line") == 0) { + } else if (opString_ == "line") { _op = CancelOp::MaskLine; - } else if (strcmp(opString_, "count") == 0) { + } else if (opString_ == "count") { _op = CancelOp::MaskCount; } return _op; @@ -186,7 +186,7 @@ CancelOp which_cancel_op(char const* opString_) [[nodiscard]] static CancelOp which_cancel_op(lua_State* L_, int idx_) { if (lua_type(L_, idx_) == LUA_TSTRING) { - char const* const _str{ lua_tostring(L_, idx_) }; + std::string_view const _str{ lua_tostringview(L_, idx_) }; CancelOp _op{ which_cancel_op(_str) }; lua_remove(L_, idx_); // argument is processed, remove it if (_op == CancelOp::Invalid) { diff --git a/src/cancel.h b/src/cancel.h index 1918df3..bac8b05 100644 --- a/src/cancel.h +++ b/src/cancel.h @@ -14,6 +14,8 @@ extern "C" #include "macros_and_utils.h" #include "uniquekey.h" +#include + // ################################################################################################# class Lane; // forward @@ -48,7 +50,7 @@ enum class CancelOp // xxh64 of string "kCancelError" generated at https://www.pelock.com/products/hash-calculator static constexpr UniqueKey kCancelError{ 0x0630345FEF912746ull, "lanes.cancel_error" }; // 'raise_cancel_error' sentinel -[[nodiscard]] CancelOp which_cancel_op(char const* opString_); +[[nodiscard]] CancelOp which_cancel_op(std::string_view const& opString_); [[nodiscard]] CancelResult thread_cancel(Lane* lane_, CancelOp op_, int hookCount_, std::chrono::time_point until_, bool wakeLane_); [[noreturn]] static inline void raise_cancel_error(lua_State* L_) diff --git a/src/compat.h b/src/compat.h index 0e95cde..3fb4e2d 100644 --- a/src/compat.h +++ b/src/compat.h @@ -25,6 +25,7 @@ extern "C" #endif // LUA_JITLIBNAME #include +#include // code is now preferring Lua 5.4 API @@ -249,3 +250,13 @@ inline constexpr LuaError ToLuaError(int rc_) // ################################################################################################# LuaType luaG_getmodule(lua_State* L_, char const* name_); + +// ################################################################################################# + +// a replacement of lua_tolstring +inline std::string_view lua_tostringview(lua_State* L_, int idx_) +{ + size_t _len{ 0 }; + char const* _str{ lua_tolstring(L_, idx_, &_len) }; + return std::string_view{ _str, _len }; +} diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp index 2f83400..1487afd 100644 --- a/src/intercopycontext.cpp +++ b/src/intercopycontext.cpp @@ -96,38 +96,37 @@ THE SOFTWARE. lua_pushvalue(L1, L1_i); // L1: ... v ... {} v lua_rawget(L1, -2); // L1: ... v ... {} "f.q.n" } - size_t _len{ 0 }; - char const* _fqn{ lua_tolstring(L1, -1, &_len) }; + std::string_view _fqn{ lua_tostringview(L1, -1) }; DEBUGSPEW_CODE(Universe* const _U = universe_get(L1)); - DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "function [C] %s \n" INDENT_END(_U), _fqn)); + DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "function [C] %s \n" INDENT_END(_U), _fqn.data())); // popping doesn't invalidate the pointer since this is an interned string gotten from the lookup database lua_pop(L1, (mode == LookupMode::FromKeeper) ? 1 : 2); // L1: ... v ... STACK_CHECK(L1, 0); - if (nullptr == _fqn && !lua_istable(L1, L1_i)) { // raise an error if we try to send an unknown function (but not for tables) - _len = 0; // just in case + if (_fqn.empty() && !lua_istable(L1, L1_i)) { // raise an error if we try to send an unknown function (but not for tables) + _fqn = std::string_view{}; // just in case // try to discover the name of the function we want to send lua_getglobal(L1, "decoda_name"); // L1: ... v ... decoda_name - char const* from{ lua_tostring(L1, -1) }; + char const* _from{ lua_tostring(L1, -1) }; lua_pushcfunction(L1, luaG_nameof); // L1: ... v ... decoda_name luaG_nameof lua_pushvalue(L1, L1_i); // L1: ... v ... decoda_name luaG_nameof t lua_call(L1, 1, 2); // L1: ... v ... decoda_name "type" "name"|nil - char const* typewhat{ (lua_type(L1, -2) == LUA_TSTRING) ? lua_tostring(L1, -2) : luaL_typename(L1, -2) }; + char const* _typewhat{ (lua_type(L1, -2) == LUA_TSTRING) ? lua_tostring(L1, -2) : luaL_typename(L1, -2) }; // second return value can be nil if the table was not found // probable reason: the function was removed from the source Lua state before Lanes was required. - char const *what, *gotchaA, *gotchaB; + char const *_what, *_gotchaA, *_gotchaB; if (lua_isnil(L1, -1)) { - gotchaA = " referenced by"; - gotchaB = "\n(did you remove it from the source Lua state before requiring Lanes?)"; - what = name; + _gotchaA = " referenced by"; + _gotchaB = "\n(did you remove it from the source Lua state before requiring Lanes?)"; + _what = name; } else { - gotchaA = ""; - gotchaB = ""; - what = (lua_type(L1, -1) == LUA_TSTRING) ? lua_tostring(L1, -1) : luaL_typename(L1, -1); + _gotchaA = ""; + _gotchaB = ""; + _what = (lua_type(L1, -1) == LUA_TSTRING) ? lua_tostring(L1, -1) : luaL_typename(L1, -1); } - raise_luaL_error(L1, "%s%s '%s' not found in %s origin transfer database.%s", typewhat, gotchaA, what, from ? from : "main", gotchaB); + raise_luaL_error(L1, "%s%s '%s' not found in %s origin transfer database.%s", _typewhat, _gotchaA, _what, _from ? _from : "main", _gotchaB); } STACK_CHECK(L1, 0); - return std::string_view{ _fqn, _len }; + return _fqn; } // ################################################################################################# @@ -208,7 +207,7 @@ void InterCopyContext::copy_func() const // transfer the bytecode, then the upvalues, to create a similar closure { - char const* fname = nullptr; + char const* _fname{}; #define LOG_FUNC_INFO 0 #if LOG_FUNC_INFO // "To get information about a function you push it onto the @@ -219,14 +218,13 @@ void InterCopyContext::copy_func() const lua_pushvalue(L1, L1_i); // L1: ... b f // fills 'fname' 'namewhat' and 'linedefined', pops function lua_getinfo(L1, ">nS", &_ar); // L1: ... b - fname = _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 { - size_t _sz; - char const* _s{ lua_tolstring(L1, -1, &_sz) }; // L1: ... b - LUA_ASSERT(L1, _s && _sz); + std::string_view const _bytecode{ lua_tostringview(L1, -1) }; // L1: ... b + LUA_ASSERT(L1, !_bytecode.empty()); STACK_GROW(L2, 2); // Note: Line numbers seem to be taken precisely from the // original function. 'fname' is not used since the chunk @@ -234,12 +232,12 @@ void InterCopyContext::copy_func() const // // TBD: Can we get the function's original name through, as well? // - if (luaL_loadbuffer(L2, _s, _sz, fname) != 0) { // L2: ... {cache} ... p function + if (luaL_loadbuffer(L2, _bytecode.data(), _bytecode.size(), _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(getErrL(), "%s: %s", fname, lua_tostring(L2, -1)); + raise_luaL_error(getErrL(), "%s: %s", _fname, lua_tostring(L2, -1)); } // remove the dumped string lua_pop(L1, 1); // ... @@ -268,7 +266,7 @@ void InterCopyContext::copy_func() const lua_pushglobaltable(L1); // L1: ... _G #endif // LUA_VERSION_NUM for (_n = 0; (_c.name = lua_getupvalue(L1, L1_i, 1 + _n)) != nullptr; ++_n) { // L1: ... _G up[n] - DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "UPNAME[%d]: %s -> " INDENT_END(U), n, _c.name)); + DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "UPNAME[%d]: %s -> " INDENT_END(U), _n, _c.name)); #if LUA_VERSION_NUM >= 502 if (lua_rawequal(L1, -1, -2)) { // is the upvalue equal to the global table? DEBUGSPEW_CODE(fprintf(stderr, "pushing destination global scope\n")); @@ -350,7 +348,7 @@ void InterCopyContext::lookup_native_func() const "%s%s: function '%s' not found in %s destination transfer database.", lua_isnil(L2, -1) ? "" : "INTERNAL ERROR IN ", _from ? _from : "main", - _fqn, + _fqn.data(), _to ? _to : "main"); return; } @@ -499,47 +497,45 @@ void InterCopyContext::inter_copy_keyvaluepair() const // maybe offer this possibility as a global configuration option, or a linda setting, or as a parameter of the call causing the transfer? } - char* valPath{ nullptr }; + char* _valPath{ nullptr }; if (U->verboseErrors) { // for debug purposes, let's try to build a useful name if (lua_type(L1, _key_i) == LUA_TSTRING) { - char const* key{ lua_tostring(L1, _key_i) }; - size_t const keyRawLen = lua_rawlen(L1, _key_i); - size_t const bufLen = strlen(name) + keyRawLen + 2; - valPath = (char*) alloca(bufLen); - sprintf(valPath, "%s.%*s", name, (int) keyRawLen, key); - key = nullptr; + std::string_view const _key{ lua_tostringview(L1, _key_i) }; + size_t const _bufLen{ strlen(name) + _key.size() + 2 }; // +2 for separator dot and terminating 0 + _valPath = static_cast(alloca(_bufLen)); + sprintf(_valPath, "%s.%*s", name, static_cast(_key.size()), _key.data()); } #if defined LUA_LNUM || LUA_VERSION_NUM >= 503 else if (lua_isinteger(L1, _key_i)) { lua_Integer const key{ lua_tointeger(L1, _key_i) }; - valPath = (char*) alloca(strlen(name) + 32 + 3); - sprintf(valPath, "%s[" LUA_INTEGER_FMT "]", name, key); + _valPath = (char*) alloca(strlen(name) + 32 + 3); // +3 for [] and terminating 0 + sprintf(_valPath, "%s[" LUA_INTEGER_FMT "]", name, key); } #endif // defined LUA_LNUM || LUA_VERSION_NUM >= 503 else if (lua_type(L1, _key_i) == LUA_TNUMBER) { lua_Number const key{ lua_tonumber(L1, _key_i) }; - valPath = (char*) alloca(strlen(name) + 32 + 3); - sprintf(valPath, "%s[" LUA_NUMBER_FMT "]", name, key); + _valPath = (char*) alloca(strlen(name) + 32 + 3); // +3 for [] and terminating 0 + sprintf(_valPath, "%s[" LUA_NUMBER_FMT "]", name, key); } else if (lua_type(L1, _key_i) == LUA_TLIGHTUSERDATA) { void* const key{ lua_touserdata(L1, _key_i) }; - valPath = (char*) alloca(strlen(name) + 16 + 5); - sprintf(valPath, "%s[U:%p]", name, key); + _valPath = (char*) alloca(strlen(name) + 16 + 5); // +5 for [U:] and terminating 0 + sprintf(_valPath, "%s[U:%p]", name, key); } else if (lua_type(L1, _key_i) == LUA_TBOOLEAN) { int const key{ lua_toboolean(L1, _key_i) }; - valPath = (char*) alloca(strlen(name) + 8); - sprintf(valPath, "%s[%s]", name, key ? "true" : "false"); + _valPath = (char*) alloca(strlen(name) + 8); // +8 for [], 'false' and terminating 0 + sprintf(_valPath, "%s[%s]", name, key ? "true" : "false"); } } _c.L1_i = SourceIndex{ _val_i }; // Contents of metatables are copied with cache checking. important to detect loops. _c.vt = VT::NORMAL; - _c.name = valPath ? valPath : name; + _c.name = _valPath ? _valPath : name; if (_c.inter_copy_one()) { LUA_ASSERT(L1, lua_istable(L2, -3)); lua_rawset(L2, -3); // add to table (pops key & val) } else { - raise_luaL_error(getErrL(), "Unable to copy %s entry '%s' because of value is of type '%s'", (vt == VT::NORMAL) ? "table" : "metatable", valPath, luaL_typename(L1, _val_i)); + raise_luaL_error(getErrL(), "Unable to copy %s entry '%s' because of value is of type '%s'", (vt == VT::NORMAL) ? "table" : "metatable", _valPath, luaL_typename(L1, _val_i)); } } @@ -931,10 +927,9 @@ void InterCopyContext::inter_copy_keyvaluepair() const [[nodiscard]] bool InterCopyContext::inter_copy_string() const { - size_t _len{ 0 }; - char const* const _s{ lua_tolstring(L1, L1_i, &_len) }; - DEBUGSPEW_CODE(fprintf(stderr, "'%s'\n", _s)); - lua_pushlstring(L2, _s, _len); + std::string_view const _s{ lua_tostringview(L1, L1_i) }; + DEBUGSPEW_CODE(fprintf(stderr, "'%s'\n", _s.data())); + lua_pushlstring(L2, _s.data(), _s.size()); return true; } diff --git a/src/lanes.cpp b/src/lanes.cpp index a68c3aa..74e2507 100644 --- a/src/lanes.cpp +++ b/src/lanes.cpp @@ -395,9 +395,8 @@ LUAG_FUNC(lane_new) raise_luaL_error(L_, "required module list should be a list of strings"); } else { // require the module in the target state, and populate the lookup table there too - size_t _len{ 0 }; - char const* _name{ lua_tolstring(L_, -1, &_len) }; - DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "lane_new: require '%s'\n" INDENT_END(_U), name)); + std::string_view const _name{ lua_tostringview(L_, -1) }; + DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "lane_new: require '%s'\n" INDENT_END(_U), _name.data())); // require the module in the target lane lua_getglobal(_L2, "require"); // L_: [fixed] args... n "modname" L2: require()? @@ -405,7 +404,7 @@ LUAG_FUNC(lane_new) lua_pop(_L2, 1); // L_: [fixed] args... n "modname" L2: raise_luaL_error(L_, "cannot pre-require modules without loading 'package' library first"); } else { - lua_pushlstring(_L2, _name, _len); // L_: [fixed] args... n "modname" L2: require() name + lua_pushlstring(_L2, _name.data(), _name.size()); // L_: [fixed] args... n "modname" L2: require() name LuaError const _rc{ lua_pcall(_L2, 1, 1, 0) }; // L_: [fixed] args... n "modname" L2: ret/errcode if (_rc != LuaError::OK) { // propagate error to main state if any @@ -415,7 +414,7 @@ LUAG_FUNC(lane_new) } // here the module was successfully required // L_: [fixed] args... n "modname" L2: ret // after requiring the module, register the functions it exported in our name<->function database - populate_func_lookup_table(_L2, -1, _name); + populate_func_lookup_table(_L2, -1, _name.data()); lua_pop(_L2, 1); // L_: [fixed] args... n "modname" L2: } } diff --git a/src/lindafactory.cpp b/src/lindafactory.cpp index 9bc56d9..015baf4 100644 --- a/src/lindafactory.cpp +++ b/src/lindafactory.cpp @@ -103,8 +103,7 @@ std::string_view LindaFactory::moduleName() const DeepPrelude* LindaFactory::newDeepObjectInternal(lua_State* L_) const { - size_t _name_len{ 0 }; - char const* _linda_name{ nullptr }; + std::string_view _linda_name{}; LindaGroup _linda_group{ 0 }; // should have a string and/or a number of the stack as parameters (name and group) switch (lua_gettop(L_)) { @@ -113,14 +112,14 @@ DeepPrelude* LindaFactory::newDeepObjectInternal(lua_State* L_) const case 1: // 1 parameter, either a name or a group if (lua_type(L_, -1) == LUA_TSTRING) { - _linda_name = lua_tolstring(L_, -1, &_name_len); + _linda_name = lua_tostringview(L_, -1); } else { _linda_group = LindaGroup{ static_cast(lua_tointeger(L_, -1)) }; } break; case 2: // 2 parameters, a name and group, in that order - _linda_name = lua_tolstring(L_, -2, &_name_len); + _linda_name = lua_tostringview(L_, -2); _linda_group = LindaGroup{ static_cast(lua_tointeger(L_, -1)) }; break; } @@ -128,6 +127,6 @@ DeepPrelude* LindaFactory::newDeepObjectInternal(lua_State* L_) const // The deep data is allocated separately of Lua stack; we might no longer be around when last reference to it is being released. // One can use any memory allocation scheme. Just don't use L's allocF because we don't know which state will get the honor of GCing the linda Universe* const _U{ universe_get(L_) }; - Linda* const _linda{ new (_U) Linda{ _U, _linda_group, _linda_name, _name_len } }; + Linda* const _linda{ new (_U) Linda{ _U, _linda_group, _linda_name.data(), _linda_name.size() } }; return _linda; } diff --git a/src/tools.cpp b/src/tools.cpp index 8ddce75..ba0785b 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -90,26 +90,26 @@ static constexpr int kWriterReturnCode{ 666 }; // ################################################################################################# // inspired from tconcat() in ltablib.c -[[nodiscard]] static char const* luaG_pushFQN(lua_State* L_, int t_, int last_, size_t* length_) +[[nodiscard]] static std::string_view luaG_pushFQN(lua_State* L_, int t_, int last_) { luaL_Buffer _b; STACK_CHECK_START_REL(L_, 0); // Lua 5.4 pushes &b as light userdata on the stack. be aware of it... luaL_buffinit(L_, &_b); // L_: ... {} ... &b? - int i = 1; - for (; i < last_; ++i) { - lua_rawgeti(L_, t_, i); + int _i{ 1 }; + for (; _i < last_; ++_i) { + lua_rawgeti(L_, t_, _i); luaL_addvalue(&_b); luaL_addlstring(&_b, "/", 1); } - if (i == last_) { // add last value (if interval was not empty) - lua_rawgeti(L_, t_, i); + if (_i == last_) { // add last value (if interval was not empty) + lua_rawgeti(L_, t_, _i); luaL_addvalue(&_b); } // &b is popped at that point (-> replaced by the result) luaL_pushresult(&_b); // L_: ... {} ... "" STACK_CHECK(L_, 1); - return lua_tolstring(L_, -1, length_); + return lua_tostringview(L_, -1); } // ################################################################################################# @@ -129,7 +129,6 @@ static void update_lookup_entry(DEBUGSPEW_PARAM_COMMA(Universe* U_) lua_State* L // slot 2 contains a table that, when concatenated, produces the fully qualified name of scanned elements in the table provided at slot _i int const _fqn{ ctxBase_ + 1 }; - DEBUGSPEW_CODE(char const* _newName); DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "update_lookup_entry()\n" INDENT_END(U_))); DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U_ }); @@ -137,16 +136,14 @@ static void update_lookup_entry(DEBUGSPEW_PARAM_COMMA(Universe* U_) lua_State* L // first, raise an error if the function is already known lua_pushvalue(L_, -1); // L_: ... {bfc} k o o lua_rawget(L_, _dest); // L_: ... {bfc} k o name? - size_t _prevNameLength; - char const* const _prevName{ lua_tolstring(L_, -1, &_prevNameLength) }; // nullptr if we got nil (first encounter of this object) + std::string_view const _prevName{ lua_tostringview(L_, -1) }; // nullptr if we got nil (first encounter of this object) // push name in fqn stack (note that concatenation will crash if name is a not string or a number) lua_pushvalue(L_, -3); // L_: ... {bfc} k o name? k LUA_ASSERT(L_, lua_type(L_, -1) == LUA_TNUMBER || lua_type(L_, -1) == LUA_TSTRING); ++depth_; lua_rawseti(L_, _fqn, depth_); // L_: ... {bfc} k o name? // generate name - size_t _newNameLength; - DEBUGSPEW_OR_NOT(_newName, std::ignore) = luaG_pushFQN(L_, _fqn, depth_, &_newNameLength); // L_: ... {bfc} k o name? "f.q.n" + std::string_view const _newName{ luaG_pushFQN(L_, _fqn, depth_) }; // L_: ... {bfc} k o name? "f.q.n" // Lua 5.2 introduced a hash randomizer seed which causes table iteration to yield a different key order // on different VMs even when the tables are populated the exact same way. // When Lua is built with compatibility options (such as LUA_COMPAT_ALL), @@ -156,13 +153,13 @@ static void update_lookup_entry(DEBUGSPEW_PARAM_COMMA(Universe* U_) lua_State* L // Also, nothing prevents any external module from exposing a given object under several names, so... // Therefore, when we encounter an object for which a name was previously registered, we need to select the names // based on some sorting order so that we end up with the same name in all databases whatever order the table walk yielded - if (_prevName != nullptr && (_prevNameLength < _newNameLength || lua_lessthan(L_, -2, -1))) { - DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "%s '%s' remained named '%s'\n" INDENT_END(U_), lua_typename(L_, lua_type(L_, -3)), _newName, _prevName)); + if (!_prevName.empty() && (_prevName.size() < _newName.size() || lua_lessthan(L_, -2, -1))) { + DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "%s '%s' remained named '%s'\n" INDENT_END(U_), lua_typename(L_, lua_type(L_, -3)), _newName.data(), _prevName.data())); // the previous name is 'smaller' than the one we just generated: keep it! lua_pop(L_, 3); // L_: ... {bfc} k } else { // the name we generated is either the first one, or a better fit for our purposes - if (_prevName) { + if (!_prevName.empty()) { // clear the previous name for the database to avoid clutter lua_insert(L_, -2); // L_: ... {bfc} k o "f.q.n" prevName // t[prevName] = nil @@ -171,7 +168,7 @@ static void update_lookup_entry(DEBUGSPEW_PARAM_COMMA(Universe* U_) lua_State* L } else { lua_remove(L_, -2); // L_: ... {bfc} k o "f.q.n" } - DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "%s '%s'\n" INDENT_END(U_), lua_typename(L_, lua_type(L_, -2)), _newName)); + DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "%s '%s'\n" INDENT_END(U_), lua_typename(L_, lua_type(L_, -2)), _newName.data())); // prepare the stack for database feed lua_pushvalue(L_, -1); // L_: ... {bfc} k o "f.q.n" "f.q.n" lua_pushvalue(L_, -3); // L_: ... {bfc} k o "f.q.n" "f.q.n" o @@ -390,7 +387,7 @@ void populate_func_lookup_table(lua_State* L_, int i_, char const* name_) // update shortest name if (depth_ < shortest_) { shortest_ = depth_; - std::ignore = luaG_pushFQN(L_, kFQN, depth_, nullptr); // L_: o "r" {c} {fqn} ... {?} k v "fqn" + std::ignore = luaG_pushFQN(L_, kFQN, depth_); // L_: o "r" {c} {fqn} ... {?} k v "fqn" lua_replace(L_, kResult); // L_: o "r" {c} {fqn} ... {?} k v } // no need to search further at this level diff --git a/src/universe.cpp b/src/universe.cpp index 9ab1290..52aa368 100644 --- a/src/universe.cpp +++ b/src/universe.cpp @@ -368,14 +368,14 @@ void Universe::terminateFreeRunningLanes(lua_State* L_, lua_Duration shutdownTim int universe_gc(lua_State* L_) { lua_Duration const _shutdown_timeout{ lua_tonumber(L_, lua_upvalueindex(1)) }; - [[maybe_unused]] char const* const _op_string{ lua_tostring(L_, lua_upvalueindex(2)) }; + std::string_view const _op_string{ lua_tostringview(L_, lua_upvalueindex(2)) }; Universe* const _U{ lua_tofulluserdata(L_, 1) }; _U->terminateFreeRunningLanes(L_, _shutdown_timeout, which_cancel_op(_op_string)); // no need to mutex-protect this as all threads in the universe are gone at that point if (_U->timerLinda != nullptr) { // test in case some early internal error prevented Lanes from creating the deep timer - [[maybe_unused]] int const prev_ref_count{ _U->timerLinda->refcount.fetch_sub(1, std::memory_order_relaxed) }; - LUA_ASSERT(L_, prev_ref_count == 1); // this should be the last reference + [[maybe_unused]] int const _prev_ref_count{ _U->timerLinda->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->timerLinda); _U->timerLinda = nullptr; } -- cgit v1.2.3-55-g6feb