-
Notifications
You must be signed in to change notification settings - Fork 231
P3 stdout implementation #718
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
Merged
+350
−38
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d5e16c8
working stdout
cpetig 1cd7e12
integrate changes from the wasip3_file branch and adapt Alex' suggest…
cpetig 389f72b
small patch corrections
cpetig 1a167e5
report known errors before write and document more
cpetig 7714fbb
use more fitting integer types for function result
cpetig a80d202
delay stream creation to the first read/write
cpetig 074197a
don't block on zero length reads or writes
cpetig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| #include <wasi/version.h> | ||
|
|
||
| #ifdef __wasip3__ | ||
| #include <assert.h> | ||
| #include <stdlib.h> | ||
| #include <wasi/wasip3_block.h> | ||
|
|
||
| void wasip3_subtask_block_on(wasip3_subtask_status_t status) { | ||
| // we don't encounter cancelled state because this function won't cancel | ||
| if (WASIP3_SUBTASK_STATE(status) == WASIP3_SUBTASK_STARTING || | ||
| WASIP3_SUBTASK_STATE(status) == WASIP3_SUBTASK_STARTED) { | ||
| wasip3_subtask_t handle = WASIP3_SUBTASK_HANDLE(status); | ||
| wasip3_waitable_set_t set = wasip3_waitable_set_new(); | ||
| wasip3_waitable_join(handle, set); | ||
| wasip3_event_t event; | ||
| event.code = WASIP3_SUBTASK_STATE(status); | ||
| while (event.code != WASIP3_SUBTASK_RETURNED) { | ||
| wasip3_waitable_set_wait(set, &event); | ||
| assert(event.event == WASIP3_EVENT_SUBTASK); | ||
| assert(event.waitable == handle); | ||
| } | ||
| wasip3_subtask_drop(event.waitable); | ||
| wasip3_waitable_set_drop(set); | ||
| } | ||
| } | ||
|
|
||
| ssize_t wasip3_waitable_block_on(wasip3_waitable_status_t status, | ||
| waitable_t stream) { | ||
| if (status == WASIP3_WAITABLE_STATUS_BLOCKED) { | ||
| wasip3_waitable_set_t set = wasip3_waitable_set_new(); | ||
| wasip3_waitable_join(stream, set); | ||
| wasip3_event_t event; | ||
| wasip3_waitable_set_wait(set, &event); | ||
| assert(event.event == WASIP3_EVENT_STREAM_WRITE || | ||
| event.event == WASIP3_EVENT_STREAM_READ || | ||
| event.event == WASIP3_EVENT_FUTURE_READ); | ||
| assert(event.waitable == stream); | ||
| // remove from set | ||
| wasip3_waitable_join(stream, 0); | ||
| wasip3_waitable_set_drop(set); | ||
| ssize_t amount = event.event == WASIP3_EVENT_FUTURE_READ ? 1 : event.code; | ||
| return amount; | ||
| } else if (WASIP3_WAITABLE_STATE(status) == WASIP3_WAITABLE_COMPLETED || | ||
| WASIP3_WAITABLE_STATE(status) == WASIP3_WAITABLE_DROPPED) { | ||
| ssize_t amount = WASIP3_WAITABLE_COUNT(status); | ||
| return amount; | ||
| } else { | ||
| abort(); | ||
| } | ||
| } | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #include <wasi/version.h> | ||
|
|
||
| #ifdef __wasip3__ | ||
| #include <wasi/file_utils.h> | ||
|
|
||
| ssize_t __wasilibc_write_stream3(int fildes, wasip3_write_t **write_end, | ||
| off_t **off) { | ||
| descriptor_table_entry_t *entry = descriptor_table_get_ref(fildes); | ||
| if (!entry) | ||
| return -1; | ||
| if (!entry->vtable->get_write_stream3) { | ||
| errno = EOPNOTSUPP; | ||
| return -1; | ||
| } | ||
| return (*entry->vtable->get_write_stream3)(entry->data, write_end, off); | ||
| } | ||
|
|
||
| ssize_t __wasilibc_read_stream3( | ||
| int fildes, | ||
| filesystem_tuple2_stream_u8_future_result_void_error_code_t **stream, | ||
| off_t **off) { | ||
| descriptor_table_entry_t *entry = descriptor_table_get_ref(fildes); | ||
| if (!entry) | ||
| return -1; | ||
| if (!entry->vtable->get_read_stream3) { | ||
| errno = EOPNOTSUPP; | ||
| return -1; | ||
| } | ||
| return (*entry->vtable->get_read_stream3)(entry->data, stream, off); | ||
| } | ||
| #endif // __wasip3__ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.