summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-04-27 23:51:56 +0800
committerruki <[email protected]>2025-08-28 11:35:53 +0800
commit568e22b7879e47616ba96e35a750cf950321742c (patch)
tree97db472b586be75c50ac3a20d9d5aafa81eab81c
parent8b976dd744fc18d617e00655631cbca8a1f19035 (diff)
fix thread envs
-rw-r--r--tests/modules/thread/sleep.lua2
-rw-r--r--xmake/core/base/compat/env.lua2
-rw-r--r--xmake/core/thread/thread.lua7
3 files changed, 6 insertions, 5 deletions
diff --git a/tests/modules/thread/sleep.lua b/tests/modules/thread/sleep.lua
index cfc314c4c..59c22dc07 100644
--- a/tests/modules/thread/sleep.lua
+++ b/tests/modules/thread/sleep.lua
@@ -1,7 +1,7 @@
import("core.thread.thread")
function callback(id)
- print(import)
+ print("import", import)
--[[
import("core.thread.thread")
print("%s: %d starting ..", thread.running(), id)
diff --git a/xmake/core/base/compat/env.lua b/xmake/core/base/compat/env.lua
index b7956866e..722c5f97c 100644
--- a/xmake/core/base/compat/env.lua
+++ b/xmake/core/base/compat/env.lua
@@ -53,7 +53,7 @@ else -- >= Lua 5.2
elseif f < 1 then
error("thread environments unsupported in Lua 5.2", 3) --[*]
end
- f = debug.getinfo(f+2, 'f').func
+ f = debug.getinfo(f + 2, 'f').func
elseif type(f) ~= 'function' then
error(("bad argument #1 to '%s' (number expected, got %s)"):format(type(name, f)), 2)
end
diff --git a/xmake/core/thread/thread.lua b/xmake/core/thread/thread.lua
index dcb74e282..19546c878 100644
--- a/xmake/core/thread/thread.lua
+++ b/xmake/core/thread/thread.lua
@@ -93,7 +93,8 @@ function _instance:start()
-- serialize and pass callback and arguments to this thread
-- we do not use string.serialize to serialize callback, because it's slower (deserialize)
- local callinfo = string._dump(self._CALLBACK, true)
+ -- and we cannot strip function debug info, we need to reserve _ENV, and other upvalue names
+ local callinfo = string._dump(self._CALLBACK)
local argv = self._ARGV
if argv ~= nil then
callinfo = string.serialize(argv, {strip = true, indent = false}) .. "<Argv\27>" .. callinfo
@@ -217,10 +218,10 @@ function thread._run_thread(callinfo_str)
end
-- load callback
- local fenv = debug.getfenv(debug.getinfo(2, "f").func)
local callback
+ local fenvs = {}
if callback_str then
- local script, errors = load(callback_str, "=(thread)", "b", fenv)
+ local script, errors = load(callback_str, "=(thread)", "b", fenvs)
if not script then
return false, string.format("cannot load thread callback, %s!", errors or "unknown")
end