Skip to content

Commit a8fa405

Browse files
committed
update unions
Unions became tagged unions in snapsnot preview 2. Refs: #59
1 parent 2315bf6 commit a8fa405

File tree

4 files changed

+33
-24
lines changed

4 files changed

+33
-24
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,13 +1702,13 @@ Members:
17021702

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

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

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

17091709
The number of bytes available for reading or writing.
17101710

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

17131713
The state of the file descriptor.
17141714

include/wasi_types.h

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ typedef uint8_t uvwasi_preopentype_t;
169169
#define UVWASI_PREOPENTYPE_DIR 0
170170

171171
typedef struct uvwasi_prestat_s {
172-
uvwasi_preopentype_t pr_type;
172+
uvwasi_preopentype_t tag;
173173
union uvwasi_prestat_u {
174174
struct uvwasi_prestat_dir_t {
175175
size_t pr_name_len;
@@ -236,20 +236,29 @@ typedef uint64_t uvwasi_timestamp_t;
236236

237237
typedef uint64_t uvwasi_userdata_t;
238238

239+
typedef union uvwasi_subscription_u_u_s {
240+
struct {
241+
uvwasi_clockid_t clock_id;
242+
uvwasi_timestamp_t timeout;
243+
uvwasi_timestamp_t precision;
244+
uvwasi_subclockflags_t flags;
245+
} clock;
246+
struct {
247+
uvwasi_fd_t fd;
248+
} fd_read;
249+
struct {
250+
uvwasi_fd_t fd;
251+
} fd_write;
252+
} uvwasi_subscription_u_u_t;
253+
254+
typedef struct uvwasi_subscription_u_s {
255+
uvwasi_eventtype_t tag;
256+
uvwasi_subscription_u_u_t u;
257+
} uvwasi_subscription_u_t;
258+
239259
typedef struct uvwasi_subscription_s {
240260
uvwasi_userdata_t userdata;
241-
uvwasi_eventtype_t type;
242-
union {
243-
struct {
244-
uvwasi_clockid_t clock_id;
245-
uvwasi_timestamp_t timeout;
246-
uvwasi_timestamp_t precision;
247-
uvwasi_subclockflags_t flags;
248-
} clock;
249-
struct {
250-
uvwasi_fd_t fd;
251-
} fd_readwrite;
252-
} u;
261+
uvwasi_subscription_u_t u;
253262
} uvwasi_subscription_t;
254263

255264
typedef struct uvwasi_dirent_s {
@@ -278,16 +287,16 @@ typedef struct uvwasi_filestat_s {
278287
uvwasi_timestamp_t st_ctim;
279288
} uvwasi_filestat_t;
280289

290+
typedef struct uvwasi_event_fd_readwrite_s {
291+
uvwasi_filesize_t nbytes;
292+
uvwasi_eventrwflags_t flags;
293+
} uvwasi_event_fd_readwrite_t;
294+
281295
typedef struct uvwasi_event_s {
282296
uvwasi_userdata_t userdata;
283297
uvwasi_errno_t error;
284298
uvwasi_eventtype_t type;
285-
union {
286-
struct {
287-
uvwasi_filesize_t nbytes;
288-
uvwasi_eventrwflags_t flags;
289-
} fd_readwrite;
290-
} u;
299+
uvwasi_event_fd_readwrite_t fd_readwrite;
291300
} uvwasi_event_t;
292301

293302
typedef uint8_t uvwasi_whence_t;

src/uvwasi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ uvwasi_errno_t uvwasi_fd_prestat_get(uvwasi_t* uvwasi,
12631263
goto exit;
12641264
}
12651265

1266-
buf->pr_type = UVWASI_PREOPENTYPE_DIR;
1266+
buf->tag = UVWASI_PREOPENTYPE_DIR;
12671267
buf->u.dir.pr_name_len = strlen(wrap->path) + 1;
12681268
err = UVWASI_ESUCCESS;
12691269
exit:

test/test-fd-prestat-dir-name.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ int main(void) {
3838
/* Verify uvwasi_fd_prestat_get(). */
3939
err = uvwasi_fd_prestat_get(&uvwasi, 3, &prestat);
4040
assert(err == 0);
41-
assert(prestat.pr_type == UVWASI_PREOPENTYPE_DIR);
41+
assert(prestat.tag == UVWASI_PREOPENTYPE_DIR);
4242
assert(prestat.u.dir.pr_name_len ==
4343
strlen(init_options.preopens[0].mapped_path) + 1);
4444

0 commit comments

Comments
 (0)