diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-05-27 15:24:06 +0200 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-05-27 15:24:06 +0200 |
commit | 09c4750ef8973c08d6ef2aba70f5385ffd75f4c4 (patch) | |
tree | c52c8d60a45ad6149f4bb64708f63b54f1772010 /src | |
parent | b482ed9c30cddac31dcff2d19e517bf20af30d10 (diff) | |
download | lanes-09c4750ef8973c08d6ef2aba70f5385ffd75f4c4.tar.gz lanes-09c4750ef8973c08d6ef2aba70f5385ffd75f4c4.tar.bz2 lanes-09c4750ef8973c08d6ef2aba70f5385ffd75f4c4.zip |
More string_view
Diffstat (limited to 'src')
-rw-r--r-- | src/intercopycontext.cpp | 58 | ||||
-rw-r--r-- | src/lanes.cpp | 2 | ||||
-rw-r--r-- | src/threading.cpp | 30 | ||||
-rw-r--r-- | src/threading.h | 4 |
4 files changed, 49 insertions, 45 deletions
diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp index 67e4e03..6c72b1c 100644 --- a/src/intercopycontext.cpp +++ b/src/intercopycontext.cpp | |||
@@ -450,18 +450,18 @@ void InterCopyContext::copy_cached_func() const | |||
450 | return false; | 450 | return false; |
451 | } else if (!lua_istable(L2, -1)) { // this can happen if someone decides to replace same already registered item (for a example a standard lib function) with a table | 451 | } else if (!lua_istable(L2, -1)) { // this can happen if someone decides to replace same already registered item (for a example a standard lib function) with a table |
452 | lua_getglobal(L1, "decoda_name"); // L1: ... t ... decoda_name | 452 | lua_getglobal(L1, "decoda_name"); // L1: ... t ... decoda_name |
453 | char const* from{ lua_tostring(L1, -1) }; | 453 | char const* _from{ lua_tostring(L1, -1) }; |
454 | lua_pop(L1, 1); // L1: ... t ... | 454 | lua_pop(L1, 1); // L1: ... t ... |
455 | lua_getglobal(L2, "decoda_name"); // L1: ... t ... L2: {} t decoda_name | 455 | lua_getglobal(L2, "decoda_name"); // L1: ... t ... L2: {} t decoda_name |
456 | char const* to{ lua_tostring(L2, -1) }; | 456 | char const* _to{ lua_tostring(L2, -1) }; |
457 | lua_pop(L2, 1); // L1: ... t ... L2: {} t | 457 | lua_pop(L2, 1); // L1: ... t ... L2: {} t |
458 | raise_luaL_error( | 458 | raise_luaL_error( |
459 | getErrL(), | 459 | getErrL(), |
460 | "%s: source table '%s' found as %s in %s destination transfer database.", | 460 | "%s: source table '%s' found as %s in %s destination transfer database.", |
461 | from ? from : "main", | 461 | _from ? _from : "main", |
462 | _fqn, | 462 | _fqn, |
463 | lua_typename(L2, lua_type_as_enum(L2, -1)), | 463 | lua_typename(L2, lua_type_as_enum(L2, -1)), |
464 | to ? to : "main"); | 464 | _to ? _to : "main"); |
465 | } | 465 | } |
466 | lua_remove(L2, -2); // L1: ... t ... L2: t | 466 | lua_remove(L2, -2); // L1: ... t ... L2: t |
467 | break; | 467 | break; |
@@ -1051,24 +1051,28 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
1051 | // ################################################################################################# | 1051 | // ################################################################################################# |
1052 | 1052 | ||
1053 | #if USE_DEBUG_SPEW() | 1053 | #if USE_DEBUG_SPEW() |
1054 | static char const* lua_type_names[] = { | 1054 | namespace { |
1055 | "LUA_TNIL" | 1055 | namespace local { |
1056 | , "LUA_TBOOLEAN" | 1056 | static std::string_view const sLuaTypeNames[] = { |
1057 | , "LUA_TLIGHTUSERDATA" | 1057 | "LUA_TNIL" |
1058 | , "LUA_TNUMBER" | 1058 | , "LUA_TBOOLEAN" |
1059 | , "LUA_TSTRING" | 1059 | , "LUA_TLIGHTUSERDATA" |
1060 | , "LUA_TTABLE" | 1060 | , "LUA_TNUMBER" |
1061 | , "LUA_TFUNCTION" | 1061 | , "LUA_TSTRING" |
1062 | , "LUA_TUSERDATA" | 1062 | , "LUA_TTABLE" |
1063 | , "LUA_TTHREAD" | 1063 | , "LUA_TFUNCTION" |
1064 | , "<LUA_NUMTAGS>" // not really a type | 1064 | , "LUA_TUSERDATA" |
1065 | , "LUA_TJITCDATA" // LuaJIT specific | 1065 | , "LUA_TTHREAD" |
1066 | }; | 1066 | , "<LUA_NUMTAGS>" // not really a type |
1067 | static char const* vt_names[] = { | 1067 | , "LUA_TJITCDATA" // LuaJIT specific |
1068 | "VT::NORMAL" | 1068 | }; |
1069 | , "VT::KEY" | 1069 | static std::string_view const sValueTypeNames[] = { |
1070 | , "VT::METATABLE" | 1070 | "VT::NORMAL" |
1071 | }; | 1071 | , "VT::KEY" |
1072 | , "VT::METATABLE" | ||
1073 | }; | ||
1074 | } | ||
1075 | } | ||
1072 | #endif // USE_DEBUG_SPEW() | 1076 | #endif // USE_DEBUG_SPEW() |
1073 | 1077 | ||
1074 | /* | 1078 | /* |
@@ -1092,7 +1096,7 @@ static char const* vt_names[] = { | |||
1092 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); | 1096 | DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); |
1093 | 1097 | ||
1094 | LuaType _val_type{ lua_type_as_enum(L1, L1_i) }; | 1098 | LuaType _val_type{ lua_type_as_enum(L1, L1_i) }; |
1095 | DEBUGSPEW_CODE(DebugSpew(U) << lua_type_names[static_cast<int>(_val_type)] << " " << vt_names[static_cast<int>(vt)] << ": "); | 1099 | DEBUGSPEW_CODE(DebugSpew(U) << local::sLuaTypeNames[static_cast<int>(_val_type)] << " " << local::sValueTypeNames[static_cast<int>(vt)] << ": "); |
1096 | 1100 | ||
1097 | // Non-POD can be skipped if its metatable contains { __lanesignore = true } | 1101 | // Non-POD can be skipped if its metatable contains { __lanesignore = true } |
1098 | if (((1 << static_cast<int>(_val_type)) & kPODmask) == 0) { | 1102 | if (((1 << static_cast<int>(_val_type)) & kPODmask) == 0) { |
@@ -1203,9 +1207,9 @@ static char const* vt_names[] = { | |||
1203 | // but don't copy it anyway, as the function names change depending on the slot index! | 1207 | // but don't copy it anyway, as the function names change depending on the slot index! |
1204 | // users should provide an on_state_create function to setup custom loaders instead | 1208 | // users should provide an on_state_create function to setup custom loaders instead |
1205 | // don't copy package.preload in keeper states (they don't know how to translate functions) | 1209 | // don't copy package.preload in keeper states (they don't know how to translate functions) |
1206 | char const* _entries[] = { "path", "cpath", (mode == LookupMode::LaneBody) ? "preload" : nullptr /*, (LUA_VERSION_NUM == 501) ? "loaders" : "searchers"*/, nullptr }; | 1210 | std::string_view const _entries[] = { "path", "cpath", (mode == LookupMode::LaneBody) ? "preload" : "" /*, (LUA_VERSION_NUM == 501) ? "loaders" : "searchers"*/, "" }; |
1207 | for (char const* const _entry : _entries) { | 1211 | for (std::string_view const& _entry : _entries) { |
1208 | if (!_entry) { | 1212 | if (_entry.empty()) { |
1209 | continue; | 1213 | continue; |
1210 | } | 1214 | } |
1211 | DEBUGSPEW_CODE(DebugSpew(U) << "package." << _entry << std::endl); | 1215 | DEBUGSPEW_CODE(DebugSpew(U) << "package." << _entry << std::endl); |
@@ -1218,7 +1222,7 @@ static char const* vt_names[] = { | |||
1218 | STACK_CHECK(L1, 0); | 1222 | STACK_CHECK(L1, 0); |
1219 | } | 1223 | } |
1220 | if (_result == InterCopyResult::Success) { | 1224 | if (_result == InterCopyResult::Success) { |
1221 | lua_setfield(L2, -2, _entry); // set package[entry] | 1225 | lua_setfield(L2, -2, _entry.data()); // set package[entry] |
1222 | } else { | 1226 | } else { |
1223 | lua_pushfstring(L1, "failed to copy package entry %s", _entry); | 1227 | lua_pushfstring(L1, "failed to copy package entry %s", _entry); |
1224 | // raise the error when copying from lane to lane, else just leave it on the stack to be raised later | 1228 | // raise the error when copying from lane to lane, else just leave it on the stack to be raised later |
diff --git a/src/lanes.cpp b/src/lanes.cpp index 0369171..20636b2 100644 --- a/src/lanes.cpp +++ b/src/lanes.cpp | |||
@@ -548,7 +548,7 @@ LUAG_FUNC(wakeup_conv) | |||
548 | // .isdst (daylight saving on/off) | 548 | // .isdst (daylight saving on/off) |
549 | 549 | ||
550 | STACK_CHECK_START_REL(L_, 0); | 550 | STACK_CHECK_START_REL(L_, 0); |
551 | auto _readInteger = [L = L_](char const* name_) { | 551 | auto _readInteger = [L = L_](std::string_view const& name_) { |
552 | std::ignore = luaG_getfield(L, 1, name_); | 552 | std::ignore = luaG_getfield(L, 1, name_); |
553 | lua_Integer const val{ lua_tointeger(L, -1) }; | 553 | lua_Integer const val{ lua_tointeger(L, -1) }; |
554 | lua_pop(L, 1); | 554 | lua_pop(L, 1); |
diff --git a/src/threading.cpp b/src/threading.cpp index 254b2e3..43bd107 100644 --- a/src/threading.cpp +++ b/src/threading.cpp | |||
@@ -139,9 +139,9 @@ void JTHREAD_SET_PRIORITY(std::jthread& thread_, int prio_, [[maybe_unused]] boo | |||
139 | 139 | ||
140 | // ################################################################################################# | 140 | // ################################################################################################# |
141 | 141 | ||
142 | void THREAD_SET_AFFINITY(unsigned int aff) | 142 | void THREAD_SET_AFFINITY(unsigned int aff_) |
143 | { | 143 | { |
144 | if (!SetThreadAffinityMask(GetCurrentThread(), aff)) { | 144 | if (!SetThreadAffinityMask(GetCurrentThread(), aff_)) { |
145 | FAIL("THREAD_SET_AFFINITY", GetLastError()); | 145 | FAIL("THREAD_SET_AFFINITY", GetLastError()); |
146 | } | 146 | } |
147 | } | 147 | } |
@@ -162,12 +162,12 @@ typedef struct tagTHREADNAME_INFO | |||
162 | #pragma pack(pop) | 162 | #pragma pack(pop) |
163 | #endif // !__GNUC__ | 163 | #endif // !__GNUC__ |
164 | 164 | ||
165 | void THREAD_SETNAME(char const* _name) | 165 | void THREAD_SETNAME(std::string_view const& name_) |
166 | { | 166 | { |
167 | #if !defined __GNUC__ | 167 | #if !defined __GNUC__ |
168 | THREADNAME_INFO info; | 168 | THREADNAME_INFO info; |
169 | info.dwType = 0x1000; | 169 | info.dwType = 0x1000; |
170 | info.szName = _name; | 170 | info.szName = name_.data(); |
171 | info.dwThreadID = GetCurrentThreadId(); | 171 | info.dwThreadID = GetCurrentThreadId(); |
172 | info.dwFlags = 0; | 172 | info.dwFlags = 0; |
173 | 173 | ||
@@ -385,7 +385,7 @@ void JTHREAD_SET_PRIORITY(std::jthread& thread_, int prio_, [[maybe_unused]] boo | |||
385 | 385 | ||
386 | // ################################################################################################# | 386 | // ################################################################################################# |
387 | 387 | ||
388 | void THREAD_SET_AFFINITY(unsigned int aff) | 388 | void THREAD_SET_AFFINITY(unsigned int aff_) |
389 | { | 389 | { |
390 | int bit = 0; | 390 | int bit = 0; |
391 | #ifdef __NetBSD__ | 391 | #ifdef __NetBSD__ |
@@ -397,12 +397,12 @@ void THREAD_SET_AFFINITY(unsigned int aff) | |||
397 | cpu_set_t cpuset; | 397 | cpu_set_t cpuset; |
398 | CPU_ZERO(&cpuset); | 398 | CPU_ZERO(&cpuset); |
399 | #endif | 399 | #endif |
400 | while (aff != 0) { | 400 | while (aff_ != 0) { |
401 | if (aff & 1) { | 401 | if (aff_ & 1) { |
402 | CPU_SET(bit, &cpuset); | 402 | CPU_SET(bit, &cpuset); |
403 | } | 403 | } |
404 | ++bit; | 404 | ++bit; |
405 | aff >>= 1; | 405 | aff_ >>= 1; |
406 | } | 406 | } |
407 | #ifdef __ANDROID__ | 407 | #ifdef __ANDROID__ |
408 | PT_CALL(sched_setaffinity(pthread_self(), sizeof(cpu_set_t), &cpuset)); | 408 | PT_CALL(sched_setaffinity(pthread_self(), sizeof(cpu_set_t), &cpuset)); |
@@ -416,24 +416,24 @@ void THREAD_SET_AFFINITY(unsigned int aff) | |||
416 | 416 | ||
417 | // ################################################################################################# | 417 | // ################################################################################################# |
418 | 418 | ||
419 | void THREAD_SETNAME(char const* _name) | 419 | void THREAD_SETNAME(std::string_view const& name_) |
420 | { | 420 | { |
421 | // exact API to set the thread name is platform-dependant | 421 | // exact API to set the thread name is platform-dependant |
422 | // if you need to fix the build, or if you know how to fill a hole, tell me (bnt.germain@gmail.com) so that I can submit the fix in github. | 422 | // if you need to fix the build, or if you know how to fill a hole, tell me (bnt.germain@gmail.com) so that I can submit the fix in github. |
423 | #if defined PLATFORM_BSD && !defined __NetBSD__ | 423 | #if defined PLATFORM_BSD && !defined __NetBSD__ |
424 | pthread_set_name_np(pthread_self(), _name); | 424 | pthread_set_name_np(pthread_self(), name_.data()); |
425 | #elif defined PLATFORM_BSD && defined __NetBSD__ | 425 | #elif defined PLATFORM_BSD && defined __NetBSD__ |
426 | pthread_setname_np(pthread_self(), "%s", (void*) _name); | 426 | pthread_setname_np(pthread_self(), "%s", (void*) name_.data()); |
427 | #elif defined PLATFORM_LINUX | 427 | #elif defined PLATFORM_LINUX |
428 | #if LINUX_USE_PTHREAD_SETNAME_NP | 428 | #if LINUX_USE_PTHREAD_SETNAME_NP |
429 | pthread_setname_np(pthread_self(), _name); | 429 | pthread_setname_np(pthread_self(), name_.data()); |
430 | #else // LINUX_USE_PTHREAD_SETNAME_NP | 430 | #else // LINUX_USE_PTHREAD_SETNAME_NP |
431 | prctl(PR_SET_NAME, _name, 0, 0, 0); | 431 | prctl(PR_SET_NAME, name_.data(), 0, 0, 0); |
432 | #endif // LINUX_USE_PTHREAD_SETNAME_NP | 432 | #endif // LINUX_USE_PTHREAD_SETNAME_NP |
433 | #elif defined PLATFORM_QNX || defined PLATFORM_CYGWIN | 433 | #elif defined PLATFORM_QNX || defined PLATFORM_CYGWIN |
434 | pthread_setname_np(pthread_self(), _name); | 434 | pthread_setname_np(pthread_self(), name_.data()); |
435 | #elif defined PLATFORM_OSX | 435 | #elif defined PLATFORM_OSX |
436 | pthread_setname_np(_name); | 436 | pthread_setname_np(name_.data()); |
437 | #else | 437 | #else |
438 | fprintf(stderr, "THREAD_SETNAME: unsupported platform\n"); | 438 | fprintf(stderr, "THREAD_SETNAME: unsupported platform\n"); |
439 | abort(); | 439 | abort(); |
diff --git a/src/threading.h b/src/threading.h index d88d308..521618b 100644 --- a/src/threading.h +++ b/src/threading.h | |||
@@ -68,8 +68,8 @@ static constexpr int kThreadPrioMax{ +3 }; | |||
68 | // ################################################################################################# | 68 | // ################################################################################################# |
69 | // ################################################################################################# | 69 | // ################################################################################################# |
70 | 70 | ||
71 | void THREAD_SETNAME(char const* _name); | 71 | void THREAD_SETNAME(std::string_view const& name_); |
72 | void THREAD_SET_PRIORITY(int prio_, bool sudo_); | 72 | void THREAD_SET_PRIORITY(int prio_, bool sudo_); |
73 | void THREAD_SET_AFFINITY(unsigned int aff); | 73 | void THREAD_SET_AFFINITY(unsigned int aff_); |
74 | 74 | ||
75 | void JTHREAD_SET_PRIORITY(std::jthread& thread_, int prio_, bool sudo_); | 75 | void JTHREAD_SET_PRIORITY(std::jthread& thread_, int prio_, bool sudo_); |