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

add uvwasi_options_init() #141

Merged
merged 1 commit into from
May 23, 2020
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
1 change: 1 addition & 0 deletions include/uvwasi.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ typedef struct uvwasi_options_s {
/* Embedder API. */
uvwasi_errno_t uvwasi_init(uvwasi_t* uvwasi, uvwasi_options_t* options);
void uvwasi_destroy(uvwasi_t* uvwasi);
void uvwasi_options_init(uvwasi_options_t* options);
/* Use int instead of uv_file to avoid needing uv.h */
uvwasi_errno_t uvwasi_embedder_remap_fd(uvwasi_t* uvwasi,
const uvwasi_fd_t fd,
Expand Down
17 changes: 17 additions & 0 deletions src/uvwasi.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,23 @@ void uvwasi_destroy(uvwasi_t* uvwasi) {
}


void uvwasi_options_init(uvwasi_options_t* options) {
if (options == NULL)
return;

options->in = 0;
options->out = 1;
options->err = 2;
options->fd_table_size = 3;
options->argc = 0;
options->argv = NULL;
options->envp = NULL;
options->preopenc = 0;
options->preopens = NULL;
options->allocator = NULL;
}


uvwasi_errno_t uvwasi_embedder_remap_fd(uvwasi_t* uvwasi,
const uvwasi_fd_t fd,
uv_file new_host_fd) {
Expand Down
9 changes: 1 addition & 8 deletions test/test-args-get.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,12 @@ int main(void) {
char** args_get_argv;
char* buf;

init_options.in = 0;
init_options.out = 1;
init_options.err = 2;
init_options.fd_table_size = 3;
uvwasi_options_init(&init_options);
init_options.argc = 3;
init_options.argv = calloc(3, sizeof(char*));
init_options.argv[0] = "--foo=bar";
init_options.argv[1] = "-baz";
init_options.argv[2] = "100";
init_options.envp = NULL;
init_options.preopenc = 0;
init_options.preopens = NULL;
init_options.allocator = NULL;

err = uvwasi_init(&uvwasi, &init_options);
assert(err == 0);
Expand Down
9 changes: 1 addition & 8 deletions test/test-basic-file-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,11 @@ int main(void) {
uv_fs_req_cleanup(&req);
assert(r == 0 || r == UV_EEXIST);

init_options.in = 0;
init_options.out = 1;
init_options.err = 2;
init_options.fd_table_size = 3;
init_options.argc = 0;
init_options.argv = NULL;
init_options.envp = NULL;
uvwasi_options_init(&init_options);
init_options.preopenc = 1;
init_options.preopens = calloc(1, sizeof(uvwasi_preopen_t));
init_options.preopens[0].mapped_path = "/var";
init_options.preopens[0].real_path = TEST_TMP_DIR;
init_options.allocator = NULL;

err = uvwasi_init(&uvwasi, &init_options);
assert(err == 0);
Expand Down
11 changes: 1 addition & 10 deletions test/test-ebadf-input-validation.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,7 @@ int main(void) {

test_void = (void*) &test_fdstat;

init_options.in = 0;
init_options.out = 1;
init_options.err = 2;
init_options.fd_table_size = 3;
init_options.argc = 0;
init_options.argv = NULL;
init_options.envp = NULL;
init_options.preopenc = 0;
init_options.preopens = NULL;
init_options.allocator = NULL;
uvwasi_options_init(&init_options);
err = uvwasi_init(&uvw, &init_options);
assert(err == 0);

Expand Down
10 changes: 1 addition & 9 deletions test/test-environ-get.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,8 @@ int main(void) {
char** env_get_env;
char* buf;

init_options.in = 0;
init_options.out = 1;
init_options.err = 2;
init_options.fd_table_size = 3;
init_options.argc = 0;
init_options.argv = NULL;
uvwasi_options_init(&init_options);
init_options.envp = (const char**) environ;
init_options.preopenc = 0;
init_options.preopens = NULL;
init_options.allocator = NULL;

err = uvwasi_init(&uvwasi, &init_options);
assert(err == 0);
Expand Down
9 changes: 1 addition & 8 deletions test/test-fd-prestat-dir-name.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,11 @@ int main(void) {
uv_fs_req_cleanup(&req);
assert(r == 0 || r == UV_EEXIST);

init_options.in = 0;
init_options.out = 1;
init_options.err = 2;
init_options.fd_table_size = 3;
init_options.argc = 0;
init_options.argv = NULL;
init_options.envp = NULL;
uvwasi_options_init(&init_options);
init_options.preopenc = 1;
init_options.preopens = calloc(1, sizeof(uvwasi_preopen_t));
init_options.preopens[0].mapped_path = "/var";
init_options.preopens[0].real_path = TEST_TMP_DIR;
init_options.allocator = NULL;

err = uvwasi_init(&uvwasi, &init_options);
assert(err == 0);
Expand Down
21 changes: 11 additions & 10 deletions test/test-multiple-wasi-destroys.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ int main(void) {
uvwasi_t uvwasi;
uvwasi_options_t init_options;

init_options.in = 0;
init_options.out = 1;
init_options.err = 2;
init_options.fd_table_size = 3;
init_options.argc = 0;
init_options.argv = NULL;
init_options.envp = NULL;
init_options.preopenc = 0;
init_options.preopens = NULL;
init_options.allocator = NULL;
uvwasi_options_init(&init_options);
assert(init_options.in == 0);
assert(init_options.out == 1);
assert(init_options.err == 2);
assert(init_options.fd_table_size == 3);
assert(init_options.argc == 0);
assert(init_options.argv == NULL);
assert(init_options.envp == NULL);
assert(init_options.preopenc == 0);
assert(init_options.preopens == NULL);
assert(init_options.allocator == NULL);

assert(0 == uvwasi_init(&uvwasi, &init_options));
/* Calling uvwasi_destroy() multiple times should be fine. */
Expand Down
9 changes: 1 addition & 8 deletions test/test-path-create-remove-directory.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,11 @@ int main(void) {
uv_fs_req_cleanup(&req);
assert(r == 0 || r == UV_ENOENT);

init_options.in = 0;
init_options.out = 1;
init_options.err = 2;
init_options.fd_table_size = 3;
init_options.argc = 0;
init_options.argv = NULL;
init_options.envp = NULL;
uvwasi_options_init(&init_options);
init_options.preopenc = 1;
init_options.preopens = calloc(1, sizeof(uvwasi_preopen_t));
init_options.preopens[0].mapped_path = "/var";
init_options.preopens[0].real_path = TEST_TMP_DIR;
init_options.allocator = NULL;

err = uvwasi_init(&uvwasi, &init_options);
assert(err == 0);
Expand Down
11 changes: 1 addition & 10 deletions test/test-path-resolution.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,7 @@ static void fail(char* mp, char* rp, char* path, uvwasi_errno_t expected) {
}

int main(void) {
init_options.in = 0;
init_options.out = 1;
init_options.err = 2;
init_options.fd_table_size = 3;
init_options.argc = 0;
init_options.argv = NULL;
init_options.envp = NULL;
init_options.preopenc = 0;
init_options.preopens = NULL;
init_options.allocator = NULL;
uvwasi_options_init(&init_options);
assert(0 == uvwasi_init(&uvwasi, &init_options));

/* Arguments: input path, expected normalized path */
Expand Down
12 changes: 1 addition & 11 deletions test/test-random-get.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,7 @@ int main(void) {
int success;
int i;

init_options.in = 0;
init_options.out = 1;
init_options.err = 2;
init_options.fd_table_size = 3;
init_options.argc = 0;
init_options.argv = NULL;
init_options.envp = NULL;
init_options.preopenc = 0;
init_options.preopens = NULL;
init_options.allocator = NULL;

uvwasi_options_init(&init_options);
err = uvwasi_init(&uvwasi, &init_options);
assert(err == 0);

Expand Down