Skip to content

c-api: add wasi_config_set_stdin_bytes#5179

Merged
alexcrichton merged 2 commits into
bytecodealliance:mainfrom
ShuP1:c-api-stdio-buffer
Nov 2, 2022
Merged

c-api: add wasi_config_set_stdin_bytes#5179
alexcrichton merged 2 commits into
bytecodealliance:mainfrom
ShuP1:c-api-stdio-buffer

Conversation

@ShuP1
Copy link
Copy Markdown
Contributor

@ShuP1 ShuP1 commented Nov 2, 2022

As discussed in issue #4372 and respective issues about python and go bindings.

Can replace wasi_config_inherit_stdin in examples/wasi/main.c:78

wasi_config_t *wasi_config = wasi_config_new();
assert(wasi_config);
wasm_byte_vec_t binary;
wasm_name_new_from_string_nt(&binary, "sent to stdin");
wasi_config_set_stdin_bytes(wasi_config, &binary);
error = wasmtime_context_set_wasi(context, wasi_config);

(cc @alexcrichton)

@github-actions github-actions Bot added the wasmtime:c-api Issues pertaining to the C API. label Nov 2, 2022
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Nov 2, 2022

Subscribe to Label Action

cc @peterhuene

Details This issue or pull request has been labeled: "wasmtime:c-api"

Thus the following users have been cc'd because of the following labels:

  • peterhuene: wasmtime:c-api

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

Copy link
Copy Markdown
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.

Looks good to me, thanks for this! One small nit on the C side but otherwise I think this might also need a cargo fmt to pass CI.

Comment thread crates/c-api/include/wasi.h Outdated
*
* This function takes ownership of the `binary` argument.
*/
WASI_API_EXTERN void wasi_config_set_stdin_bytes(wasi_config_t* config, const wasm_byte_vec_t* binary);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since this takes owneship of the argument here I think it might be good to drop the const qualifier since it's actually mutated.

@ShuP1 ShuP1 force-pushed the c-api-stdio-buffer branch from 87a64dd to ca1a1c5 Compare November 2, 2022 17:16
@alexcrichton alexcrichton merged commit 348f962 into bytecodealliance:main Nov 2, 2022
@alexcrichton
Copy link
Copy Markdown
Member

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasmtime:c-api Issues pertaining to the C API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants