aboutsummaryrefslogtreecommitdiff
path: root/src/lane.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lane.cpp')
-rw-r--r--src/lane.cpp18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/lane.cpp b/src/lane.cpp
index 3017806..e838b7d 100644
--- a/src/lane.cpp
+++ b/src/lane.cpp
@@ -46,7 +46,7 @@ static LUAG_FUNC(get_debug_threadname)
46{ 46{
47 Lane* const _lane{ ToLane(L_, 1) }; 47 Lane* const _lane{ ToLane(L_, 1) };
48 luaL_argcheck(L_, lua_gettop(L_) == 1, 2, "too many arguments"); 48 luaL_argcheck(L_, lua_gettop(L_) == 1, 2, "too many arguments");
49 lua_pushstring(L_, _lane->debugName); 49 std::ignore = lua_pushstringview(L_, _lane->debugName);
50 return 1; 50 return 1;
51} 51}
52 52
@@ -278,7 +278,7 @@ static int thread_index_number(lua_State* L_)
278 lua_replace(L_, -3); // L_: lane n error() "error" 278 lua_replace(L_, -3); // L_: lane n error() "error"
279 lua_pushinteger(L_, 3); // L_: lane n error() "error" 3 279 lua_pushinteger(L_, 3); // L_: lane n error() "error" 3
280 lua_call(L_, 2, 0); // error(tostring(errstring), 3) -> doesn't return // L_: lane n 280 lua_call(L_, 2, 0); // error(tostring(errstring), 3) -> doesn't return // L_: lane n
281 raise_luaL_error(L_, "%s: should not get here!", _lane->debugName); 281 raise_luaL_error(L_, "%s: should not get here!", _lane->debugName.data());
282 } else { 282 } else {
283 lua_pop(L_, 1); // L_: lane n {uv} 283 lua_pop(L_, 1); // L_: lane n {uv}
284 } 284 }
@@ -345,7 +345,7 @@ static LUAG_FUNC(thread_index)
345 lua_pushvalue(L_, kKey); // L_: mt error "Unknown key: " k 345 lua_pushvalue(L_, kKey); // L_: mt error "Unknown key: " k
346 lua_concat(L_, 2); // L_: mt error "Unknown key: <k>" 346 lua_concat(L_, 2); // L_: mt error "Unknown key: <k>"
347 lua_call(L_, 1, 0); // error( "Unknown key: " .. key) -> doesn't return // L_: mt 347 lua_call(L_, 1, 0); // error( "Unknown key: " .. key) -> doesn't return // L_: mt
348 raise_luaL_error(L_, "%s[%s]: should not get here!", _lane->debugName, lua_typename(L_, lua_type(L_, kKey))); 348 raise_luaL_error(L_, "%s[%s]: should not get here!", _lane->debugName.data(), lua_typename(L_, lua_type(L_, kKey)));
349 } 349 }
350} 350}
351 351
@@ -739,7 +739,7 @@ static void lane_main(Lane* lane_)
739 lua_rawget(L_, -2); // L_: ud uservalue gc_cb|nil 739 lua_rawget(L_, -2); // L_: ud uservalue gc_cb|nil
740 if (!lua_isnil(L_, -1)) { 740 if (!lua_isnil(L_, -1)) {
741 lua_remove(L_, -2); // L_: ud gc_cb|nil 741 lua_remove(L_, -2); // L_: ud gc_cb|nil
742 lua_pushstring(L_, _lane->debugName); // L_: ud gc_cb name 742 std::ignore = lua_pushstringview(L_, _lane->debugName); // L_: ud gc_cb name
743 _have_gc_cb = true; 743 _have_gc_cb = true;
744 } else { 744 } else {
745 lua_pop(L_, 2); // L_: ud 745 lua_pop(L_, 2); // L_: ud
@@ -759,7 +759,7 @@ static void lane_main(Lane* lane_)
759 // no longer accessing the Lua VM: we can close right now 759 // no longer accessing the Lua VM: we can close right now
760 _lane->close(); 760 _lane->close();
761 // just in case, but _lane will be freed soon so... 761 // just in case, but _lane will be freed soon so...
762 _lane->debugName = "<gc>"; 762 _lane->debugName = std::string_view{ "<gc>" };
763 } 763 }
764 764
765 // Clean up after a (finished) thread 765 // Clean up after a (finished) thread
@@ -812,12 +812,12 @@ void Lane::changeDebugName(int nameIdx_)
812 // store a hidden reference in the registry to make sure the string is kept around even if a lane decides to manually change the "decoda_name" global... 812 // store a hidden reference in the registry to make sure the string is kept around even if a lane decides to manually change the "decoda_name" global...
813 kRegKey.setValue(L, [nameIdx = nameIdx_](lua_State* L_) { lua_pushvalue(L_, nameIdx); }); // L: ... "name" ... 813 kRegKey.setValue(L, [nameIdx = nameIdx_](lua_State* L_) { lua_pushvalue(L_, nameIdx); }); // L: ... "name" ...
814 // keep a direct pointer on the string 814 // keep a direct pointer on the string
815 debugName = lua_tostring(L, nameIdx_); 815 debugName = lua_tostringview(L, nameIdx_);
816 // to see VM name in Decoda debugger Virtual Machine window 816 // to see VM name in Decoda debugger Virtual Machine window
817 lua_pushvalue(L, nameIdx_); // L: ... "name" ... "name" 817 lua_pushvalue(L, nameIdx_); // L: ... "name" ... "name"
818 lua_setglobal(L, "decoda_name"); // L: ... "name" ... 818 lua_setglobal(L, "decoda_name"); // L: ... "name" ...
819 // and finally set the OS thread name 819 // and finally set the OS thread name
820 THREAD_SETNAME(debugName); 820 THREAD_SETNAME(debugName.data());
821 STACK_CHECK(L, 0); 821 STACK_CHECK(L, 0);
822} 822}
823 823
@@ -920,9 +920,7 @@ void Lane::securizeDebugName(lua_State* L_)
920 LUA_ASSERT(L_, lua_istable(L_, -1)); 920 LUA_ASSERT(L_, lua_istable(L_, -1));
921 // we don't care about the actual key, so long as it's unique and can't collide with anything. 921 // we don't care about the actual key, so long as it's unique and can't collide with anything.
922 lua_newtable(L_); // L_: lane ... {uv} {} 922 lua_newtable(L_); // L_: lane ... {uv} {}
923 // Lua 5.1 can't do 'lane_->debugName = lua_pushstring(L_, lane_->debugName);' 923 debugName = lua_pushstringview(L_, debugName); // L_: lane ... {uv} {} name
924 lua_pushstring(L_, debugName); // L_: lane ... {uv} {} name
925 debugName = lua_tostring(L_, -1);
926 lua_rawset(L_, -3); // L_: lane ... {uv} 924 lua_rawset(L_, -3); // L_: lane ... {uv}
927 lua_pop(L_, 1); // L_: lane 925 lua_pop(L_, 1); // L_: lane
928 STACK_CHECK(L_, 0); 926 STACK_CHECK(L_, 0);