-
Notifications
You must be signed in to change notification settings - Fork 10
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
WASI: add args_get and args_sizes_get #308
Conversation
src/wasi/WASI.cpp
Outdated
uvwasi_size_t bufSize; | ||
uvwasi_args_sizes_get(WASI::g_uvwasi, &argc, &bufSize); | ||
|
||
char** uvArgv = reinterpret_cast<char**>(get_memory_pointer(instance, argv[0], argc * sizeof(char*))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is correct. char* pointers can be 32 or 64 bit long depending on the cpu, while the output is 32 bit long offsets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have created a TemporaryData
class in the #307 patch which should help.
6c6123d
to
6637b32
Compare
Please rebase this patch |
6637b32
to
ed91832
Compare
src/shell/Shell.cpp
Outdated
@@ -1117,7 +1128,7 @@ static void parseArguments(int argc, char* argv[], ParseOptions& options) | |||
} | |||
} | |||
|
|||
int main(int argc, char* argv[]) | |||
int main(const int argc, const char* argv[]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for an int
const is pointless.
src/wasi/WASI.cpp
Outdated
@@ -242,6 +242,42 @@ void WASI::random_get(ExecutionState& state, Value* argv, Value* result, Instanc | |||
result[0] = Value(uvwasi_random_get(WASI::g_uvwasi, buf, length)); | |||
} | |||
|
|||
void WASI::args_get(ExecutionState& state, Value* argv, Value* result, Instance* instance) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to follow the uvwasi order of API functions for these wasi functions, so put it above, not to the last place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell uvwasi sorts the functions alphabetically; But the order we have them in already is not alphabetical. Would you want me to sort the existing ones as well, or to just put the new args functions at the top?
src/wasi/WASI.h
Outdated
@@ -47,7 +47,9 @@ class WASI { | |||
F(fd_seek, I32I64I32I32_RI32) \ | |||
F(path_open, I32I32I32I32I32I64I64I32I32_RI32) \ | |||
F(environ_get, I32I32_RI32) \ | |||
F(environ_sizes_get, I32I32_RI32) | |||
F(environ_sizes_get, I32I32_RI32) \ | |||
F(args_get, I32I32_RI32) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Order here as well.
c824015
to
e9a6258
Compare
tools/run-tests.py
Outdated
@@ -136,6 +145,24 @@ def run_wasi_tests(engine): | |||
if fail_total > 0: | |||
raise Exception("basic wasi tests failed") | |||
|
|||
@runner('wasi-args', default=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about merging this wasi-args
runner into wasi
test runner?
#309 should land first. |
acc9e86
to
0271239
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice patch!
src/shell/Shell.cpp
Outdated
@@ -1083,6 +1084,15 @@ static void parseArguments(int argc, char* argv[], ParseOptions& options) | |||
options.wasi_dirs.push_back(std::make_pair(argv[i + 2], argv[i + 1])); | |||
i += 2; | |||
continue; | |||
} else if (strcmp(argv[i], "--args") == 0) { | |||
if (i + 1 == argc || argv[i + 1][0] == '-') { | |||
fprintf(stderr, "error: --args requires an argument\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment: requires an argument list
, or requires one or more arguments
test/wasi/args.wast
Outdated
local.tee $argc | ||
i32.const 4 | ||
call $wasi_args_sizes_get | ||
drop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we throw an error on nonzero return code? If you pass a buffer outside the memory area, it should throw error.
test/wasi/args.wast
Outdated
(import "wasi_snapshot_preview1" "args_sizes_get" (func $wasi_args_sizes_get (param i32 i32) (result i32))) | ||
(memory 1) | ||
|
||
(export "memory" (memory 0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this needs to be exported? (memory 1 1)
creates a 64K buffer.
test/wasi/args.wast
Outdated
(memory 1) | ||
|
||
(export "memory" (memory 0)) | ||
(data (i32.const 32) "Hello" ) ;; Memory[32] = "Hello," |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello
or Hello,
test/wasi/args.wast
Outdated
local.set $mismatched_char_count | ||
|
||
;; Check if each arg matches the expect values of "Hello," and "World!" | ||
i32.const 1 ;; start at 1, skip argv[0] (name of currently running file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the function returns with two buffers in an expected layout, we could check them in one step (without a loop for arguments).
test/wasi/args.wast
Outdated
(if | ||
(then | ||
i32.const -1 | ||
local.set $memory_error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about return
?
Update the test script to test passing the arguments as well Signed-off-by: Máté Tokodi mate.tokodi@szteszoftver.hu
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
WASI: add args_get and args_sizes_get
Extend testing script for passing arguments.
Depends on #307 and #309