v
v copied to clipboard
segmentation fault when trying to use an array return type for a pool_processor callback
Describe the bug
import sync.pool
pub struct Foo {
page string
}
mut pp := pool.new_pool_processor(
// array return types cause `SIGSEGV`
callback: fn (mut pp pool.PoolProcessor, idx int, wid int) []Foo {
page := pp.get_item[int](idx)
return [Foo{page.str()}]
}
)
mut pp_ := pool.new_pool_processor(
// non-array return types work.
callback: fn (mut pp pool.PoolProcessor, idx int, wid int) &Foo {
page := pp.get_item[int](idx)
return &Foo{page.str()}
}
)
pages := []int{len: 2, init: index}
// Comment out block and uncomment below for working version.
pp.work_on_items(pages)
res := pp.get_results[[]Foo]().map(it)
dump(res)
/* pp_.work_on_items(pages)
res := pp_.get_results[Foo]().map(it)
dump(res) */
Reproduction Steps
above
Expected Behavior
works, or error.
Current Behavior
segfault
Possible Solution
No response
Additional Information/Context
Workaround is to use another struct with an array field:
import sync.pool
pub struct Foo {
page string
}
struct Workaround {
foo_arr []Foo
}
mut pp := pool.new_pool_processor(
callback: fn (mut pp pool.PoolProcessor, idx int, wid int) &Workaround {
page := pp.get_item[int](idx)
res := &Workaround{
foo_arr: [Foo{page.str()}]
}
return res
}
)
pages := []int{len: 2, init: index}
pp.work_on_items(pages)
res := pp.get_results[[]Foo]().map(it)
dump(res)
V version
v0.4.6
Environment details (OS name and version, etc.)
linux amd64
[!NOTE] You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote. Other reactions and those to comments will not be taken into account.