Merge pull request #572 from hackerchai/fix/general-fix-libuv

fix(c/libuv): Fix return type FsType & struct rename
This commit is contained in:
xushiwei
2024-07-29 11:12:49 +08:00
committed by GitHub
3 changed files with 16 additions and 53 deletions

View File

@@ -47,7 +47,7 @@ func onOpen(req *libuv.Fs) {
// Init buffer
iov = libuv.InitBuf((*c.Char)(unsafe.Pointer(&buffer[0])), c.Uint(unsafe.Sizeof(buffer)))
// Read the file
readRes := libuv.FsRead(loop, &readReq, libuv.UvFile(libuv.FsGetResult(req)), &iov, 1, -1, onRead)
readRes := libuv.FsRead(loop, &readReq, libuv.File(libuv.FsGetResult(req)), &iov, 1, -1, onRead)
if readRes != 0 {
c.Printf(c.Str("Error in FsRead: %s (code: %d)\n"), libuv.Strerror(libuv.Errno(readRes)), readRes)
libuv.LoopClose(loop)
@@ -63,7 +63,7 @@ func onRead(req *libuv.Fs) {
} else if libuv.FsGetResult(req) == 0 {
c.Printf(c.Str("EOF\n"))
// Close the file
closeRes := libuv.FsClose(loop, &closeReq, libuv.UvFile(libuv.FsGetResult(&openReq)), onClose)
closeRes := libuv.FsClose(loop, &closeReq, libuv.File(libuv.FsGetResult(&openReq)), onClose)
if closeRes != 0 {
// Print the content
c.Printf(c.Str("Error in FsClose: %s (code: %d)\n"), libuv.Strerror(libuv.Errno(closeRes)), closeRes)

View File

@@ -62,7 +62,7 @@ type FsType c.Int
type DirentType c.Int
type UvFile c.Int
type File c.Int
// ----------------------------------------------
@@ -85,11 +85,6 @@ type Dirent struct {
Type DirentType
}
type File struct {
Loop *Loop
Req *Fs
}
type Stat struct {
Unused [0]byte
}
@@ -112,7 +107,7 @@ type FsPollCb func(handle *FsPoll, status c.Int, events c.Int)
/* Fs related function and method */
//go:linkname FsGetType C.uv_fs_get_type
func FsGetType(req *Fs) *FsType
func FsGetType(req *Fs) FsType
//go:linkname FsGetPath C.uv_fs_get_path
func FsGetPath(req *Fs) *c.Char
@@ -139,13 +134,13 @@ func DefaultLoop() *Loop
func FsOpen(loop *Loop, req *Fs, path *c.Char, flags c.Int, mode c.Int, cb FsCb) c.Int
//go:linkname FsClose C.uv_fs_close
func FsClose(loop *Loop, req *Fs, file UvFile, cb FsCb) c.Int
func FsClose(loop *Loop, req *Fs, file File, cb FsCb) c.Int
//go:linkname FsRead C.uv_fs_read
func FsRead(loop *Loop, req *Fs, file UvFile, bufs *Buf, nbufs c.Uint, offset c.LongLong, cb FsCb) c.Int
func FsRead(loop *Loop, req *Fs, file File, bufs *Buf, nbufs c.Uint, offset c.LongLong, cb FsCb) c.Int
//go:linkname FsWrite C.uv_fs_write
func FsWrite(loop *Loop, req *Fs, file UvFile, bufs *Buf, nbufs c.Uint, offset c.LongLong, cb FsCb) c.Int
func FsWrite(loop *Loop, req *Fs, file File, bufs *Buf, nbufs c.Uint, offset c.LongLong, cb FsCb) c.Int
//go:linkname FsUnlink C.uv_fs_unlink
func FsUnlink(loop *Loop, req *Fs, path *c.Char, cb FsCb) c.Int
@@ -166,19 +161,19 @@ func FsRmdir(loop *Loop, req *Fs, path *c.Char, cb FsCb) c.Int
func FsStat(loop *Loop, req *Fs, path *c.Char, cb FsCb) c.Int
//go:linkname FsFstat C.uv_fs_fstat
func FsFstat(loop *Loop, req *Fs, file UvFile, cb FsCb) c.Int
func FsFstat(loop *Loop, req *Fs, file File, cb FsCb) c.Int
//go:linkname FsRename C.uv_fs_rename
func FsRename(loop *Loop, req *Fs, path *c.Char, newPath *c.Char, cb FsCb) c.Int
//go:linkname FsFsync C.uv_fs_fsync
func FsFsync(loop *Loop, req *Fs, file UvFile, cb FsCb) c.Int
func FsFsync(loop *Loop, req *Fs, file File, cb FsCb) c.Int
//go:linkname FsFdatasync C.uv_fs_fdatasync
func FsFdatasync(loop *Loop, req *Fs, file UvFile, cb FsCb) c.Int
func FsFdatasync(loop *Loop, req *Fs, file File, cb FsCb) c.Int
//go:linkname FsFtruncate C.uv_fs_ftruncate
func FsFtruncate(loop *Loop, req *Fs, file UvFile, offset c.LongLong, cb FsCb) c.Int
func FsFtruncate(loop *Loop, req *Fs, file File, offset c.LongLong, cb FsCb) c.Int
//go:linkname FsSendfile C.uv_fs_sendfile
func FsSendfile(loop *Loop, req *Fs, outFd c.Int, inFd c.Int, inOffset c.LongLong, length c.Int, cb FsCb) c.Int
@@ -190,13 +185,13 @@ func FsAccess(loop *Loop, req *Fs, path *c.Char, flags c.Int, cb FsCb) c.Int
func FsChmod(loop *Loop, req *Fs, path *c.Char, mode c.Int, cb FsCb) c.Int
//go:linkname FsFchmod C.uv_fs_fchmod
func FsFchmod(loop *Loop, req *Fs, file UvFile, mode c.Int, cb FsCb) c.Int
func FsFchmod(loop *Loop, req *Fs, file File, mode c.Int, cb FsCb) c.Int
//go:linkname FsUtime C.uv_fs_utime
func FsUtime(loop *Loop, req *Fs, path *c.Char, atime c.Int, mtime c.Int, cb FsCb) c.Int
//go:linkname FsFutime C.uv_fs_futime
func FsFutime(loop *Loop, req *Fs, file UvFile, atime c.Int, mtime c.Int, cb FsCb) c.Int
func FsFutime(loop *Loop, req *Fs, file File, atime c.Int, mtime c.Int, cb FsCb) c.Int
//go:linkname FsLutime C.uv_fs_lutime
func FsLutime(loop *Loop, req *Fs, path *c.Char, atime c.Int, mtime c.Int, cb FsCb) c.Int
@@ -238,7 +233,7 @@ func FsStatfs(loop *Loop, req *Fs, path *c.Char, cb FsCb) c.Int
func FsChown(loop *Loop, req *Fs, path *c.Char, uid c.Int, gid c.Int, cb FsCb) c.Int
//go:linkname FsFchown C.uv_fs_fchown
func FsFchown(loop *Loop, req *Fs, file UvFile, uid c.Int, gid c.Int, cb FsCb) c.Int
func FsFchown(loop *Loop, req *Fs, file File, uid c.Int, gid c.Int, cb FsCb) c.Int
//go:linkname FsLchown C.uv_fs_lchown
func FsLchown(loop *Loop, req *Fs, path *c.Char, uid c.Int, gid c.Int, cb FsCb) c.Int

View File

@@ -101,46 +101,14 @@ type Handle struct {
Unused [96]byte
}
type Dir struct {
Unused [0]byte
}
type Stream struct {
Unused [264]byte
}
type Pipe struct {
Unused [0]byte
}
type Tty struct {
Unused [0]byte
}
type Poll struct {
Unused [0]byte
}
type Prepare struct {
Unused [0]byte
}
type Check struct {
Unused [0]byte
}
type Idle struct {
Unused [0]byte
}
type Async struct {
Unused [0]byte
}
type Process struct {
Unused [0]byte
}
/* Request types. */
type Req struct {
@@ -296,8 +264,8 @@ func (handle *Handle) Fileno(fd *OsFd) c.Int {
return 0
}
//go:linkname UvPipe C.uv_pipe
func UvPipe(fds [2]UvFile, readFlags c.Int, writeFlags c.Int) c.Int {
//go:linkname Pipe C.uv_pipe
func Pipe(fds [2]File, readFlags c.Int, writeFlags c.Int) c.Int {
return 0
}