From 526385280a21b23e432d734a41c6054888ccd5ea Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sat, 8 Feb 2025 16:29:56 +0100 Subject: [PATCH] Improved error handling for struct types --- lib/sys/net_linux.q | 2 +- lib/sys/time_linux.q | 7 ++++++- lib/time/time.q | 2 +- lib/time/timespec.q | 4 ---- src/types/ByName.go | 16 ++++++++++++++-- 5 files changed, 22 insertions(+), 9 deletions(-) delete mode 100644 lib/time/timespec.q diff --git a/lib/sys/net_linux.q b/lib/sys/net_linux.q index 91b0da6..dc6b3eb 100644 --- a/lib/sys/net_linux.q +++ b/lib/sys/net_linux.q @@ -13,7 +13,7 @@ accept(fd Int, address Pointer, length Int) -> Int { return syscall(43, fd, address, length) } -bind(fd Int, address Pointer, length Int) -> Int { +bind(fd Int, address *sockaddr_in, length Int) -> Int { return syscall(49, fd, address, length) } diff --git a/lib/sys/time_linux.q b/lib/sys/time_linux.q index 6727476..f2957d3 100644 --- a/lib/sys/time_linux.q +++ b/lib/sys/time_linux.q @@ -1,3 +1,8 @@ -nanosleep(duration Pointer) -> Int { +struct timespec { + seconds Int + nanoseconds Int +} + +nanosleep(duration *timespec) -> Int { return syscall(35, duration, 0) } \ No newline at end of file diff --git a/lib/time/time.q b/lib/time/time.q index bd22148..b39dbe8 100644 --- a/lib/time/time.q +++ b/lib/time/time.q @@ -7,7 +7,7 @@ sleep(nanoseconds Int) { seconds, nanoseconds = nanoseconds / 1000000000 } - duration := new(timespec) + duration := new(sys.timespec) duration.seconds = seconds duration.nanoseconds = nanoseconds sys.nanosleep(duration) diff --git a/lib/time/timespec.q b/lib/time/timespec.q deleted file mode 100644 index 84d53d6..0000000 --- a/lib/time/timespec.q +++ /dev/null @@ -1,4 +0,0 @@ -struct timespec { - seconds Int - nanoseconds Int -} \ No newline at end of file diff --git a/src/types/ByName.go b/src/types/ByName.go index 1f402c1..765fb8f 100644 --- a/src/types/ByName.go +++ b/src/types/ByName.go @@ -8,7 +8,13 @@ import ( func ByName(name string, pkg string, structs map[string]*Struct) Type { if strings.HasPrefix(name, "*") { to := strings.TrimPrefix(name, "*") - return &Pointer{To: ByName(to, pkg, structs)} + typ := ByName(to, pkg, structs) + + if typ != nil { + return &Pointer{To: typ} + } + + return nil } switch name { @@ -32,5 +38,11 @@ func ByName(name string, pkg string, structs map[string]*Struct) Type { return PointerAny } - return structs[pkg+"."+name] + typ, exists := structs[pkg+"."+name] + + if !exists { + return nil + } + + return typ }