diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-06-14 15:45:00 +0200 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-06-14 15:45:00 +0200 |
commit | a925a9ee21c10184a08625e83d2b55850d6cb32f (patch) | |
tree | 210f8f69f2fb510cc841bd16c132a1b70a84b2ad /src | |
parent | 149d6d6d16b10da9915e3018237405f6fe8749cf (diff) | |
download | lanes-a925a9ee21c10184a08625e83d2b55850d6cb32f.tar.gz lanes-a925a9ee21c10184a08625e83d2b55850d6cb32f.tar.bz2 lanes-a925a9ee21c10184a08625e83d2b55850d6cb32f.zip |
More char* -> std::string_view conversions
Diffstat (limited to 'src')
-rw-r--r-- | src/intercopycontext.cpp | 29 | ||||
-rw-r--r-- | src/intercopycontext.h | 2 |
2 files changed, 16 insertions, 15 deletions
diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp index e56b9fd..9fa5911 100644 --- a/src/intercopycontext.cpp +++ b/src/intercopycontext.cpp | |||
@@ -262,13 +262,14 @@ void InterCopyContext::copyFunction() const | |||
262 | InterCopyContext _c{ U, L2, L1, L2_cache_i, {}, VT::NORMAL, mode, {} }; | 262 | InterCopyContext _c{ U, L2, L1, L2_cache_i, {}, VT::NORMAL, mode, {} }; |
263 | // if we encounter an upvalue equal to the global table in the source, bind it to the destination's global table | 263 | // if we encounter an upvalue equal to the global table in the source, bind it to the destination's global table |
264 | luaG_pushglobaltable(L1); // L1: ... _G | 264 | luaG_pushglobaltable(L1); // L1: ... _G |
265 | for (_n = 0; (_c.name = lua_getupvalue(L1, L1_i, 1 + _n)) != nullptr; ++_n) { // L1: ... _G up[n] | 265 | for (char const* _upname{}; (_upname = lua_getupvalue(L1, L1_i, 1 + _n)); ++_n) { // L1: ... _G up[n] |
266 | DEBUGSPEW_CODE(DebugSpew(U) << "UPNAME[" << _n << "]: " << _c.name << " -> "); | 266 | DEBUGSPEW_CODE(DebugSpew(U) << "UPNAME[" << _n << "]: " << _c.name << " -> "); |
267 | if (lua_rawequal(L1, -1, -2)) { // is the upvalue equal to the global table? | 267 | if (lua_rawequal(L1, -1, -2)) { // is the upvalue equal to the global table? |
268 | DEBUGSPEW_CODE(DebugSpew(nullptr) << "pushing destination global scope" << std::endl); | 268 | DEBUGSPEW_CODE(DebugSpew(nullptr) << "pushing destination global scope" << std::endl); |
269 | luaG_pushglobaltable(L2); // L2: ... {cache} ... function <upvalues> | 269 | luaG_pushglobaltable(L2); // L2: ... {cache} ... function <upvalues> |
270 | } else { | 270 | } else { |
271 | DEBUGSPEW_CODE(DebugSpew(nullptr) << "copying value" << std::endl); | 271 | DEBUGSPEW_CODE(DebugSpew(nullptr) << "copying value" << std::endl); |
272 | _c.name = _upname; | ||
272 | _c.L1_i = SourceIndex{ lua_gettop(L1) }; | 273 | _c.L1_i = SourceIndex{ lua_gettop(L1) }; |
273 | if (_c.interCopyOne() != InterCopyResult::Success) { // L2: ... {cache} ... function <upvalues> | 274 | if (_c.interCopyOne() != InterCopyResult::Success) { // L2: ... {cache} ... function <upvalues> |
274 | raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); | 275 | raise_luaL_error(getErrL(), "Cannot copy upvalue type '%s'", luaL_typename(L1, -1)); |
@@ -489,29 +490,29 @@ void InterCopyContext::interCopyKeyValuePair() const | |||
489 | // for debug purposes, let's try to build a useful name | 490 | // for debug purposes, let's try to build a useful name |
490 | if (luaG_type(L1, _key_i) == LuaType::STRING) { | 491 | if (luaG_type(L1, _key_i) == LuaType::STRING) { |
491 | std::string_view const _key{ luaG_tostring(L1, _key_i) }; | 492 | std::string_view const _key{ luaG_tostring(L1, _key_i) }; |
492 | size_t const _bufLen{ strlen(name) + _key.size() + 2 }; // +2 for separator dot and terminating 0 | 493 | size_t const _bufLen{ name.size() + _key.size() + 2 }; // +2 for separator dot and terminating 0 |
493 | _valPath = static_cast<char*>(alloca(_bufLen)); | 494 | _valPath = static_cast<char*>(alloca(_bufLen)); |
494 | sprintf(_valPath, "%s." STRINGVIEW_FMT, name, (int) _key.size(), _key.data()); | 495 | sprintf(_valPath, "%s." STRINGVIEW_FMT, name.data(), (int) _key.size(), _key.data()); |
495 | } | 496 | } |
496 | #if defined LUA_LNUM || LUA_VERSION_NUM >= 503 | 497 | #if defined LUA_LNUM || LUA_VERSION_NUM >= 503 |
497 | else if (lua_isinteger(L1, _key_i)) { | 498 | else if (lua_isinteger(L1, _key_i)) { |
498 | lua_Integer const key{ lua_tointeger(L1, _key_i) }; | 499 | lua_Integer const key{ lua_tointeger(L1, _key_i) }; |
499 | _valPath = (char*) alloca(strlen(name) + 32 + 3); // +3 for [] and terminating 0 | 500 | _valPath = (char*) alloca(name.size() + 32 + 3); // +3 for [] and terminating 0 |
500 | sprintf(_valPath, "%s[" LUA_INTEGER_FMT "]", name, key); | 501 | sprintf(_valPath, "%s[" LUA_INTEGER_FMT "]", name.data(), key); |
501 | } | 502 | } |
502 | #endif // defined LUA_LNUM || LUA_VERSION_NUM >= 503 | 503 | #endif // defined LUA_LNUM || LUA_VERSION_NUM >= 503 |
503 | else if (luaG_type(L1, _key_i) == LuaType::NUMBER) { | 504 | else if (luaG_type(L1, _key_i) == LuaType::NUMBER) { |
504 | lua_Number const key{ lua_tonumber(L1, _key_i) }; | 505 | lua_Number const key{ lua_tonumber(L1, _key_i) }; |
505 | _valPath = (char*) alloca(strlen(name) + 32 + 3); // +3 for [] and terminating 0 | 506 | _valPath = (char*) alloca(name.size() + 32 + 3); // +3 for [] and terminating 0 |
506 | sprintf(_valPath, "%s[" LUA_NUMBER_FMT "]", name, key); | 507 | sprintf(_valPath, "%s[" LUA_NUMBER_FMT "]", name.data(), key); |
507 | } else if (luaG_type(L1, _key_i) == LuaType::LIGHTUSERDATA) { | 508 | } else if (luaG_type(L1, _key_i) == LuaType::LIGHTUSERDATA) { |
508 | void* const key{ lua_touserdata(L1, _key_i) }; | 509 | void* const key{ lua_touserdata(L1, _key_i) }; |
509 | _valPath = (char*) alloca(strlen(name) + 16 + 5); // +5 for [U:] and terminating 0 | 510 | _valPath = (char*) alloca(name.size() + 16 + 5); // +5 for [U:] and terminating 0 |
510 | sprintf(_valPath, "%s[U:%p]", name, key); | 511 | sprintf(_valPath, "%s[U:%p]", name.data(), key); |
511 | } else if (luaG_type(L1, _key_i) == LuaType::BOOLEAN) { | 512 | } else if (luaG_type(L1, _key_i) == LuaType::BOOLEAN) { |
512 | int const key{ lua_toboolean(L1, _key_i) }; | 513 | int const key{ lua_toboolean(L1, _key_i) }; |
513 | _valPath = (char*) alloca(strlen(name) + 8); // +8 for [], 'false' and terminating 0 | 514 | _valPath = (char*) alloca(name.size() + 8); // +8 for [], 'false' and terminating 0 |
514 | sprintf(_valPath, "%s[%s]", name, key ? "true" : "false"); | 515 | sprintf(_valPath, "%s[%s]", name.data(), key ? "true" : "false"); |
515 | } | 516 | } |
516 | } | 517 | } |
517 | 518 | ||
@@ -1301,14 +1302,14 @@ namespace { | |||
1301 | int const _top_L2{ lua_gettop(L2) }; // L2: ... | 1302 | int const _top_L2{ lua_gettop(L2) }; // L2: ... |
1302 | lua_newtable(L2); // L2: ... cache | 1303 | lua_newtable(L2); // L2: ... cache |
1303 | 1304 | ||
1304 | char _tmpBuf[16]; | 1305 | InterCopyContext _c{ U, L2, L1, CacheIndex{ _top_L2 + 1 }, {}, VT::NORMAL, mode, "?" }; |
1305 | char const* const _pBuf{ U->verboseErrors ? _tmpBuf : "?" }; | ||
1306 | InterCopyContext _c{ U, L2, L1, CacheIndex{ _top_L2 + 1 }, {}, VT::NORMAL, mode, _pBuf }; | ||
1307 | InterCopyResult _copyok{ InterCopyResult::Success }; | 1306 | InterCopyResult _copyok{ InterCopyResult::Success }; |
1308 | STACK_CHECK_START_REL(L1, 0); | 1307 | STACK_CHECK_START_REL(L1, 0); |
1309 | for (int _i{ _top_L1 - n_ + 1 }, _j{ 1 }; _i <= _top_L1; ++_i, ++_j) { | 1308 | for (int _i{ _top_L1 - n_ + 1 }, _j{ 1 }; _i <= _top_L1; ++_i, ++_j) { |
1309 | char _tmpBuf[16]; | ||
1310 | if (U->verboseErrors) { | 1310 | if (U->verboseErrors) { |
1311 | sprintf(_tmpBuf, "arg_%d", _j); | 1311 | sprintf(_tmpBuf, "arg_%d", _j); |
1312 | _c.name = _tmpBuf; | ||
1312 | } | 1313 | } |
1313 | _c.L1_i = SourceIndex{ _i }; | 1314 | _c.L1_i = SourceIndex{ _i }; |
1314 | _copyok = _c.interCopyOne(); // L2: ... cache {}n | 1315 | _copyok = _c.interCopyOne(); // L2: ... cache {}n |
diff --git a/src/intercopycontext.h b/src/intercopycontext.h index 8615842..8d4b68f 100644 --- a/src/intercopycontext.h +++ b/src/intercopycontext.h | |||
@@ -35,7 +35,7 @@ class InterCopyContext | |||
35 | SourceIndex L1_i; // that one can change when we reuse the context | 35 | SourceIndex L1_i; // that one can change when we reuse the context |
36 | VT vt; // that one can change when we reuse the context | 36 | VT vt; // that one can change when we reuse the context |
37 | LookupMode const mode; | 37 | LookupMode const mode; |
38 | char const* name; // that one can change when we reuse the context | 38 | std::string_view name; // that one can change when we reuse the context |
39 | 39 | ||
40 | private: | 40 | private: |
41 | [[nodiscard]] std::string_view findLookupName() const; | 41 | [[nodiscard]] std::string_view findLookupName() const; |