diff options
author | Randy Reddig <[email protected]> | 2024-11-04 23:32:17 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2024-11-04 14:32:17 -0800 |
commit | c02a8141c7974e3e3a3deebd38c9ff64c6511c33 (patch) | |
tree | 7012413514e210e7b9ef7bb3c83d28b4b540ab76 | |
parent | 5862b481a4e1801cecbc1daa891de2289ac734f7 (diff) | |
download | tinygo-c02a8141c7974e3e3a3deebd38c9ff64c6511c33.tar.gz tinygo-c02a8141c7974e3e3a3deebd38c9ff64c6511c33.zip |
internal/wasm-tools, syscall: update to [email protected] (#4577)
* internal/wasm-tools, internal/cm: update wasm-tools-go to v0.3.1 and regenerate bindings
* syscall: use new (cm.Result).Result() method instead of OK() and Err()
-rw-r--r-- | internal/wasm-tools/go.mod | 5 | ||||
-rw-r--r-- | internal/wasm-tools/go.sum | 14 | ||||
-rw-r--r-- | src/internal/cm/result.go | 10 | ||||
-rw-r--r-- | src/syscall/libc_wasip2.go | 147 |
4 files changed, 90 insertions, 86 deletions
diff --git a/internal/wasm-tools/go.mod b/internal/wasm-tools/go.mod index fbc3b20f0..3404ab78c 100644 --- a/internal/wasm-tools/go.mod +++ b/internal/wasm-tools/go.mod @@ -2,7 +2,7 @@ module github.com/tinygo-org/tinygo/internal/tools go 1.22.4 -require github.com/bytecodealliance/wasm-tools-go v0.3.0 +require github.com/bytecodealliance/wasm-tools-go v0.3.1 require ( github.com/coreos/go-semver v0.3.1 // indirect @@ -12,8 +12,7 @@ require ( github.com/regclient/regclient v0.7.1 // indirect github.com/sirupsen/logrus v1.9.3 // indirect github.com/ulikunitz/xz v0.5.12 // indirect - github.com/urfave/cli/v3 v3.0.0-alpha9 // indirect - github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect + github.com/urfave/cli/v3 v3.0.0-alpha9.2 // indirect golang.org/x/mod v0.21.0 // indirect golang.org/x/sys v0.26.0 // indirect ) diff --git a/internal/wasm-tools/go.sum b/internal/wasm-tools/go.sum index 72f90a316..2f4bef21b 100644 --- a/internal/wasm-tools/go.sum +++ b/internal/wasm-tools/go.sum @@ -1,5 +1,5 @@ -github.com/bytecodealliance/wasm-tools-go v0.3.0 h1:9aeDFYpbi3gtIW/nJCH+P+LhFMqezGoOfzqbUZLadho= -github.com/bytecodealliance/wasm-tools-go v0.3.0/go.mod h1:VY+9FlpLi6jnhCrZLkyJjF9rjU4aEekgaRTk28MS2JE= +github.com/bytecodealliance/wasm-tools-go v0.3.1 h1:9Q9PjSzkbiVmkUvZ7nYCfJ02mcQDBalxycA3s8g7kR4= +github.com/bytecodealliance/wasm-tools-go v0.3.1/go.mod h1:vNAQ8DAEp6xvvk+TUHah5DslLEa76f4H6e737OeaxuY= github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4= github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -23,14 +23,12 @@ github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc= github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= -github.com/urfave/cli/v3 v3.0.0-alpha9 h1:P0RMy5fQm1AslQS+XCmy9UknDXctOmG/q/FZkUFnJSo= -github.com/urfave/cli/v3 v3.0.0-alpha9/go.mod h1:0kK/RUFHyh+yIKSfWxwheGndfnrvYSmYFVeKCh03ZUc= -github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= -github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= +github.com/urfave/cli/v3 v3.0.0-alpha9.2 h1:CL8llQj3dGRLVQQzHxS+ZYRLanOuhyK1fXgLKD+qV+Y= +github.com/urfave/cli/v3 v3.0.0-alpha9.2/go.mod h1:FnIeEMYu+ko8zP1F9Ypr3xkZMIDqW3DR92yUtY39q1Y= golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0= golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= diff --git a/src/internal/cm/result.go b/src/internal/cm/result.go index 82200e278..781dccc1a 100644 --- a/src/internal/cm/result.go +++ b/src/internal/cm/result.go @@ -71,6 +71,16 @@ func (r *result[Shape, OK, Err]) Err() *Err { return (*Err)(unsafe.Pointer(&r.data)) } +// Result returns (OK, zero value of Err, false) if r represents the OK case, +// or (zero value of OK, Err, true) if r represents the error case. +// This does not have a pointer receiver, so it can be chained. +func (r result[Shape, OK, Err]) Result() (ok OK, err Err, isErr bool) { + if r.isErr { + return ok, *(*Err)(unsafe.Pointer(&r.data)), true + } + return *(*OK)(unsafe.Pointer(&r.data)), err, false +} + // This function is sized so it can be inlined and optimized away. func (r *result[Shape, OK, Err]) validate() { var shape Shape diff --git a/src/syscall/libc_wasip2.go b/src/syscall/libc_wasip2.go index 7123f2db2..a89e64a80 100644 --- a/src/syscall/libc_wasip2.go +++ b/src/syscall/libc_wasip2.go @@ -162,8 +162,8 @@ func readStream(stream *wasiStream, buf *byte, count uint, offset int64) int { } libcErrno = 0 - result := stream.in.BlockingRead(uint64(count)) - if err := result.Err(); err != nil { + list, err, isErr := stream.in.BlockingRead(uint64(count)).Result() + if isErr { if err.Closed() { libcErrno = 0 return 0 @@ -174,9 +174,7 @@ func readStream(stream *wasiStream, buf *byte, count uint, offset int64) int { return -1 } - dst := unsafe.Slice(buf, count) - list := result.OK() - copy(dst, list.Slice()) + copy(unsafe.Slice(buf, count), list.Slice()) return int(list.Len()) } @@ -202,8 +200,8 @@ func writeStream(stream *wasiStream, buf *byte, count uint, offset int64) int { if len > remaining { len = remaining } - result := stream.out.BlockingWriteAndFlush(cm.ToList(src[:len])) - if err := result.Err(); err != nil { + _, err, isErr := stream.out.BlockingWriteAndFlush(cm.ToList(src[:len])).Result() + if isErr { if err.Closed() { libcErrno = 0 return 0 @@ -248,13 +246,13 @@ func pread(fd int32, buf *byte, count uint, offset int64) int { return -1 } - result := streams.d.Read(types.FileSize(count), types.FileSize(offset)) - if err := result.Err(); err != nil { - libcErrno = errorCodeToErrno(*err) + listEOF, err, isErr := streams.d.Read(types.FileSize(count), types.FileSize(offset)).Result() + if isErr { + libcErrno = errorCodeToErrno(err) return -1 } - list := result.OK().F0 + list := listEOF.F0 copy(unsafe.Slice(buf, count), list.Slice()) // TODO(dgryski): EOF bool is ignored? @@ -285,14 +283,14 @@ func pwrite(fd int32, buf *byte, count uint, offset int64) int { return -1 } - result := streams.d.Write(cm.NewList(buf, count), types.FileSize(offset)) - if err := result.Err(); err != nil { + n, err, isErr := streams.d.Write(cm.NewList(buf, count), types.FileSize(offset)).Result() + if isErr { // TODO(dgryski): - libcErrno = errorCodeToErrno(*err) + libcErrno = errorCodeToErrno(err) return -1 } - return int(*result.OK()) + return int(n) } // ssize_t lseek(int fd, off_t offset, int whence); @@ -321,12 +319,12 @@ func lseek(fd int32, offset int64, whence int) int64 { case 1: // SEEK_CUR stream.offset += offset case 2: // SEEK_END - result := stream.d.Stat() - if err := result.Err(); err != nil { - libcErrno = errorCodeToErrno(*err) + stat, err, isErr := stream.d.Stat().Result() + if isErr { + libcErrno = errorCodeToErrno(err) return -1 } - stream.offset = int64(result.OK().Size) + offset + stream.offset = int64(stat.Size) + offset } return int64(stream.offset) @@ -439,9 +437,9 @@ func mkdir(pathname *byte, mode uint32) int32 { return -1 } - result := dir.d.CreateDirectoryAt(relPath) - if err := result.Err(); err != nil { - libcErrno = errorCodeToErrno(*err) + _, err, isErr := dir.d.CreateDirectoryAt(relPath).Result() + if isErr { + libcErrno = errorCodeToErrno(err) return -1 } @@ -459,9 +457,9 @@ func rmdir(pathname *byte) int32 { return -1 } - result := dir.d.RemoveDirectoryAt(relPath) - if err := result.Err(); err != nil { - libcErrno = errorCodeToErrno(*err) + _, err, isErr := dir.d.RemoveDirectoryAt(relPath).Result() + if isErr { + libcErrno = errorCodeToErrno(err) return -1 } @@ -486,9 +484,9 @@ func rename(from, to *byte) int32 { return -1 } - result := fromDir.d.RenameAt(fromRelPath, toDir.d, toRelPath) - if err := result.Err(); err != nil { - libcErrno = errorCodeToErrno(*err) + _, err, isErr := fromDir.d.RenameAt(fromRelPath, toDir.d, toRelPath).Result() + if isErr { + libcErrno = errorCodeToErrno(err) return -1 } @@ -520,9 +518,9 @@ func symlink(from, to *byte) int32 { // TODO(dgryski): check fromDir == toDir? - result := fromDir.d.SymlinkAt(fromRelPath, toRelPath) - if err := result.Err(); err != nil { - libcErrno = errorCodeToErrno(*err) + _, err, isErr := fromDir.d.SymlinkAt(fromRelPath, toRelPath).Result() + if isErr { + libcErrno = errorCodeToErrno(err) return -1 } @@ -554,9 +552,9 @@ func link(from, to *byte) int32 { // TODO(dgryski): check fromDir == toDir? - result := fromDir.d.LinkAt(0, fromRelPath, toDir.d, toRelPath) - if err := result.Err(); err != nil { - libcErrno = errorCodeToErrno(*err) + _, err, isErr := fromDir.d.LinkAt(0, fromRelPath, toDir.d, toRelPath).Result() + if isErr { + libcErrno = errorCodeToErrno(err) return -1 } @@ -587,9 +585,9 @@ func fsync(fd int32) int32 { return -1 } - result := streams.d.SyncData() - if err := result.Err(); err != nil { - libcErrno = errorCodeToErrno(*err) + _, err, isErr := streams.d.SyncData().Result() + if isErr { + libcErrno = errorCodeToErrno(err) return -1 } @@ -607,13 +605,12 @@ func readlink(pathname *byte, buf *byte, count uint) int { return -1 } - result := dir.d.ReadLinkAt(relPath) - if err := result.Err(); err != nil { - libcErrno = errorCodeToErrno(*err) + s, err, isErr := dir.d.ReadLinkAt(relPath).Result() + if isErr { + libcErrno = errorCodeToErrno(err) return -1 } - s := *result.OK() size := uintptr(count) if size > uintptr(len(s)) { size = uintptr(len(s)) @@ -634,9 +631,9 @@ func unlink(pathname *byte) int32 { return -1 } - result := dir.d.UnlinkFileAt(relPath) - if err := result.Err(); err != nil { - libcErrno = errorCodeToErrno(*err) + _, err, isErr := dir.d.UnlinkFileAt(relPath).Result() + if isErr { + libcErrno = errorCodeToErrno(err) return -1 } @@ -661,13 +658,13 @@ func stat(pathname *byte, dst *Stat_t) int32 { return -1 } - result := dir.d.StatAt(0, relPath) - if err := result.Err(); err != nil { - libcErrno = errorCodeToErrno(*err) + stat, err, isErr := dir.d.StatAt(0, relPath).Result() + if isErr { + libcErrno = errorCodeToErrno(err) return -1 } - setStatFromWASIStat(dst, result.OK()) + setStatFromWASIStat(dst, &stat) return 0 } @@ -690,13 +687,13 @@ func fstat(fd int32, dst *Stat_t) int32 { libcErrno = EBADF return -1 } - result := stream.d.Stat() - if err := result.Err(); err != nil { - libcErrno = errorCodeToErrno(*err) + stat, err, isErr := stream.d.Stat().Result() + if isErr { + libcErrno = errorCodeToErrno(err) return -1 } - setStatFromWASIStat(dst, result.OK()) + setStatFromWASIStat(dst, &stat) return 0 } @@ -745,13 +742,13 @@ func lstat(pathname *byte, dst *Stat_t) int32 { return -1 } - result := dir.d.StatAt(0, relPath) - if err := result.Err(); err != nil { - libcErrno = errorCodeToErrno(*err) + stat, err, isErr := dir.d.StatAt(0, relPath).Result() + if isErr { + libcErrno = errorCodeToErrno(err) return -1 } - setStatFromWASIStat(dst, result.OK()) + setStatFromWASIStat(dst, &stat) return 0 } @@ -981,25 +978,25 @@ func open(pathname *byte, flags int32, mode uint32) int32 { pflags &^= types.PathFlagsSymlinkFollow } - result := dir.d.OpenAt(pflags, relPath, oflags, dflags) - if err := result.Err(); err != nil { - libcErrno = errorCodeToErrno(*err) + descriptor, err, isErr := dir.d.OpenAt(pflags, relPath, oflags, dflags).Result() + if isErr { + libcErrno = errorCodeToErrno(err) return -1 } stream := wasiFile{ - d: *result.OK(), + d: descriptor, oflag: flags, refs: 1, } if flags&(O_WRONLY|O_APPEND) == (O_WRONLY | O_APPEND) { - result := stream.d.Stat() - if err := result.Err(); err != nil { - libcErrno = errorCodeToErrno(*err) + stat, err, isErr := stream.d.Stat().Result() + if isErr { + libcErrno = errorCodeToErrno(err) return -1 } - stream.offset = int64(result.OK().Size) + stream.offset = int64(stat.Size) } libcfd := findFreeFD() @@ -1112,13 +1109,13 @@ func fdopendir(fd int32) unsafe.Pointer { return nil } - result := stream.d.ReadDirectory() - if err := result.Err(); err != nil { - libcErrno = errorCodeToErrno(*err) + dir, err, isErr := stream.d.ReadDirectory().Result() + if isErr { + libcErrno = errorCodeToErrno(err) return nil } - return unsafe.Pointer(&libc_DIR{d: *result.OK()}) + return unsafe.Pointer(&libc_DIR{d: dir}) } // int fdclosedir(DIR *); @@ -1153,13 +1150,13 @@ func readdir(dirp unsafe.Pointer) *Dirent { return nil } - result := dir.d.ReadDirectoryEntry() - if err := result.Err(); err != nil { - libcErrno = errorCodeToErrno(*err) + someEntry, err, isErr := dir.d.ReadDirectoryEntry().Result() + if isErr { + libcErrno = errorCodeToErrno(err) return nil } - entry := result.OK().Some() + entry := someEntry.Some() if entry == nil { libcErrno = 0 return nil @@ -1311,9 +1308,9 @@ func chdir(name *byte) int { return -1 } - result := dir.d.OpenAt(types.PathFlagsSymlinkFollow, rel, types.OpenFlagsDirectory, types.DescriptorFlagsRead) - if err := result.Err(); err != nil { - libcErrno = errorCodeToErrno(*err) + _, err, isErr := dir.d.OpenAt(types.PathFlagsSymlinkFollow, rel, types.OpenFlagsDirectory, types.DescriptorFlagsRead).Result() + if isErr { + libcErrno = errorCodeToErrno(err) return -1 } |