Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix thread arguments limit #638

Merged
merged 2 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ used here to facilitate documenting consistent behavior:
metamethod
- `buffer`: a `string` or a sequential `table` of `string`s
- `threadargs`: variable arguments (`...`) of type `nil`, `boolean`, `number`,
`string`, or `userdata`
`string`, or `userdata`, numbers of argument limited to 9.

## Contents

Expand Down Expand Up @@ -3271,6 +3271,8 @@ provided. Currently accepted `option` fields are `stack_size`.

**Returns:** `luv_thread_t userdata` or `fail`

**Note:** unsafe, please make sure the thread end of life before the Lua state close.

### `uv.thread_equal(thread, other_thread)`

> method form `thread:equal(other_thread)`
Expand Down
2 changes: 1 addition & 1 deletion src/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static int luv_thread_arg_set(lua_State* L, luv_thread_arg_t* args, int idx, int
idx = idx > 0 ? idx : 1;
i = idx;
args->flags = flags;
while (i <= top && i <= LUV_THREAD_MAXNUM_ARG + idx)
while (i <= top && i < LUV_THREAD_MAXNUM_ARG + idx)
{
luv_val_t *arg = args->argv + i - idx;
arg->type = lua_type(L, i);
Expand Down
17 changes: 17 additions & 0 deletions tests/test-thread.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,21 @@ return require('lib/tap')(function (test)
assert(elapsed >= 100, "elapsed should be at least delay ")
end, "1.26.0")

test("test thread arguments limit", function(print, p, expect, uv)
local args = {}
args[1] = uv.new_async(expect(function (n)
assert(n==9)
args[1]:close()
end))
for i=2, 10 do
args[i] = i
end
local unpack = unpack or table.unpack
uv.new_thread(function(...)
local arg = {...}
assert(#arg == 9)
arg[1]:send(#arg)
end, unpack(args)):join()
assert(#args==10)
end)
end)