Skip to content

feat: add binding for wasi_config_set_stdin_bytes #245

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ramilmsh
Copy link

Adding a binding for wasi_config_set_stdin_bytes

I've never worked with cgo before, so no idea if this is safe/free of memory leaks, but seems to have worked for me

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I think this'll want some tweaks ownership-wise though. The wasi_config_set_stdin_bytes API is defined as taking ownership of its vector argument. That means you'll want to construct the vector with wasm_byte_vec_new_uninitialized and then copy the bytes from Go into the allocated vector, then pass that vector off to the API. That'll avoid using Cbytes and free here I believe.

You can see an example here of passing byte arrays from Go into Rust, and you can use wasm_byte_vec_copy to copy from Go into the Rust-allocated vector.

Also, would it be possible to write a test for this as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants