Skip to content

Commit

Permalink
update unions
Browse files Browse the repository at this point in the history
Unions became tagged unions in snapsnot preview 2.

Refs: #59
  • Loading branch information
cjihrig committed Feb 21, 2020
1 parent 931f0ac commit 9e47162
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 24 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1694,13 +1694,13 @@ Members:

- When `type` is [`UVWASI_EVENTTYPE_FD_READ`](#eventtype.fd_read) or [`UVWASI_EVENTTYPE_FD_WRITE`](#eventtype.fd_write):

- <a href="#event.u.fd_readwrite" name="event.u.fd_readwrite"></a>**`u.fd_readwrite`**
- <a href="#event.fd_readwrite" name="event.fd_readwrite"></a>**`fd_readwrite`**

- <a href="#event.u.fd_readwrite.nbytes" name="event.u.fd_readwrite.nbytes"></a><code>[\_\_wasi\_filesize\_t](#filesize) <strong>nbytes</strong></code>
- <a href="#event.fd_readwrite.nbytes" name="event.fd_readwrite.nbytes"></a><code>[\_\_wasi\_filesize\_t](#filesize) <strong>nbytes</strong></code>

The number of bytes available for reading or writing.

- <a href="#event.u.fd_readwrite.flags" name="event.u.fd_readwrite.flags"></a><code>[\_\_wasi\_eventrwflags\_t](#eventrwflags) <strong>flags</strong></code>
- <a href="#event.fd_readwrite.flags" name="event.fd_readwrite.flags"></a><code>[\_\_wasi\_eventrwflags\_t](#eventrwflags) <strong>flags</strong></code>

The state of the file descriptor.

Expand Down
47 changes: 28 additions & 19 deletions include/wasi_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ typedef uint8_t uvwasi_preopentype_t;
#define UVWASI_PREOPENTYPE_DIR 0

typedef struct uvwasi_prestat_s {
uvwasi_preopentype_t pr_type;
uvwasi_preopentype_t tag;
union uvwasi_prestat_u {
struct uvwasi_prestat_dir_t {
size_t pr_name_len;
Expand Down Expand Up @@ -236,20 +236,29 @@ typedef uint64_t uvwasi_timestamp_t;

typedef uint64_t uvwasi_userdata_t;

typedef union uvwasi_subscription_u_u_s {
struct {
uvwasi_clockid_t clock_id;
uvwasi_timestamp_t timeout;
uvwasi_timestamp_t precision;
uvwasi_subclockflags_t flags;
} clock;
struct {
uvwasi_fd_t fd;
} fd_read;
struct {
uvwasi_fd_t fd;
} fd_write;
} uvwasi_subscription_u_u_t;

typedef struct uvwasi_subscription_u_s {
uvwasi_eventtype_t tag;
uvwasi_subscription_u_u_t u;
} uvwasi_subscription_u_t;

typedef struct uvwasi_subscription_s {
uvwasi_userdata_t userdata;
uvwasi_eventtype_t type;
union {
struct {
uvwasi_clockid_t clock_id;
uvwasi_timestamp_t timeout;
uvwasi_timestamp_t precision;
uvwasi_subclockflags_t flags;
} clock;
struct {
uvwasi_fd_t fd;
} fd_readwrite;
} u;
uvwasi_subscription_u_t u;
} uvwasi_subscription_t;

typedef struct uvwasi_dirent_s {
Expand Down Expand Up @@ -278,16 +287,16 @@ typedef struct uvwasi_filestat_s {
uvwasi_timestamp_t st_ctim;
} uvwasi_filestat_t;

typedef struct uvwasi_event_fd_readwrite_s {
uvwasi_filesize_t nbytes;
uvwasi_eventrwflags_t flags;
} uvwasi_event_fd_readwrite_t;

typedef struct uvwasi_event_s {
uvwasi_userdata_t userdata;
uvwasi_errno_t error;
uvwasi_eventtype_t type;
union {
struct {
uvwasi_filesize_t nbytes;
uvwasi_eventrwflags_t flags;
} fd_readwrite;
} u;
uvwasi_event_fd_readwrite_t fd_readwrite;
} uvwasi_event_t;

typedef uint8_t uvwasi_whence_t;
Expand Down
2 changes: 1 addition & 1 deletion src/uvwasi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ uvwasi_errno_t uvwasi_fd_prestat_get(uvwasi_t* uvwasi,
goto exit;
}

buf->pr_type = UVWASI_PREOPENTYPE_DIR;
buf->tag = UVWASI_PREOPENTYPE_DIR;
buf->u.dir.pr_name_len = strlen(wrap->path) + 1;
err = UVWASI_ESUCCESS;
exit:
Expand Down
2 changes: 1 addition & 1 deletion test/test-fd-prestat-dir-name.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int main(void) {
/* Verify uvwasi_fd_prestat_get(). */
err = uvwasi_fd_prestat_get(&uvwasi, 3, &prestat);
assert(err == 0);
assert(prestat.pr_type == UVWASI_PREOPENTYPE_DIR);
assert(prestat.tag == UVWASI_PREOPENTYPE_DIR);
assert(prestat.u.dir.pr_name_len ==
strlen(init_options.preopens[0].mapped_path) + 1);

Expand Down

0 comments on commit 9e47162

Please sign in to comment.