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

segmentation fault when trying to use an array return type for a pool_processor callback #21543

Open
ttytm opened this issue May 21, 2024 · 0 comments
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@ttytm
Copy link
Member

ttytm commented May 21, 2024

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.

@ttytm ttytm added the Bug This tag is applied to issues which reports bugs. label May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

No branches or pull requests

1 participant