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

fix(stdlib): Return early from Process.argv() if length is zero #1817

Merged
merged 2 commits into from
Apr 19, 2023

Conversation

phated
Copy link
Member

@phated phated commented Apr 18, 2023

This returns early from the Process.argv() function if the argsLength is zero. This avoids some differences between wasi implementations, and is also probably just a good idea to avoid extra sys calls.

Fixes an issue I was encountering in #1585

Copy link
Member

@marcusroberts marcusroberts left a comment

Choose a reason for hiding this comment

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

Nice fix.

let arr = allocateArray(argc)

if (WasmI32.eqz(argsLength)) {
return Ok(WasmI32.toGrain(arr): Array<String>)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return Ok(WasmI32.toGrain(arr): Array<String>)
Memory.free(argcPtr)
return Ok(WasmI32.toGrain(arr): Array<String>)

could also refactor a bit to do the free after we read argc so we don't need to do it in multiple places.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to do the refactor. Let me know if it is correct!

Copy link
Member

@ospencer ospencer left a comment

Choose a reason for hiding this comment

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

Looks great!

@ospencer ospencer added this pull request to the merge queue Apr 19, 2023
Merged via the queue into main with commit 8ccea28 Apr 19, 2023
@ospencer ospencer deleted the phated/process-argv branch April 19, 2023 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants