From 56e7c75e0384bbe7f0a78fa4bde4aa4dd78f3ab0 Mon Sep 17 00:00:00 2001 From: metagn Date: Mon, 9 Sep 2024 10:46:47 +0300 Subject: [PATCH] fix int32's that should be uint32 on BSD & OSX (#24078) fixes #24076 As described in #24076, misannotating these types causes codegen errors. Sources for the types are https://github.com/openbsd/src/blob/master/sys for BSD and https://opensource.apple.com/source/Libinfo/Libinfo-391/ and [_types.h](https://opensource.apple.com/source/xnu/xnu-1456.1.26/bsd/sys/_types.h.auto.html) for OSX. (cherry picked from commit 7de4ace94908f515a98fbe6f3a4a022b6fa9e3f8) --- lib/posix/posix_macos_amd64.nim | 10 +++++----- lib/posix/posix_openbsd_amd64.nim | 10 +++++----- tests/stdlib/twronguidtype.nim | 8 ++++++++ 3 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 tests/stdlib/twronguidtype.nim diff --git a/lib/posix/posix_macos_amd64.nim b/lib/posix/posix_macos_amd64.nim index d6b5834cb6..366181846d 100644 --- a/lib/posix/posix_macos_amd64.nim +++ b/lib/posix/posix_macos_amd64.nim @@ -125,7 +125,7 @@ type Dev* {.importc: "dev_t", header: "".} = int32 Fsblkcnt* {.importc: "fsblkcnt_t", header: "".} = int Fsfilcnt* {.importc: "fsfilcnt_t", header: "".} = int - Gid* {.importc: "gid_t", header: "".} = int32 + Gid* {.importc: "gid_t", header: "".} = uint32 Id* {.importc: "id_t", header: "".} = int Ino* {.importc: "ino_t", header: "".} = int Key* {.importc: "key_t", header: "".} = int @@ -167,7 +167,7 @@ type Trace_event_set* {.importc: "trace_event_set_t", header: "".} = int Trace_id* {.importc: "trace_id_t", header: "".} = int - Uid* {.importc: "uid_t", header: "".} = int32 + Uid* {.importc: "uid_t", header: "".} = uint32 Useconds* {.importc: "useconds_t", header: "".} = int Utsname* {.importc: "struct utsname", @@ -462,9 +462,9 @@ type header: "".} = object ## struct sockaddr_in6 sin6_family*: TSa_Family ## AF_INET6. sin6_port*: InPort ## Port number. - sin6_flowinfo*: int32 ## IPv6 traffic class and flow information. + sin6_flowinfo*: uint32 ## IPv6 traffic class and flow information. sin6_addr*: In6Addr ## IPv6 address. - sin6_scope_id*: int32 ## Set of interfaces for a scope. + sin6_scope_id*: uint32 ## Set of interfaces for a scope. Tipv6_mreq* {.importc: "struct ipv6_mreq", pure, final, header: "".} = object ## struct ipv6_mreq @@ -491,7 +491,7 @@ type ## alternative network names, terminated by a ## null pointer. n_addrtype*: cint ## The address type of the network. - n_net*: int32 ## The network number, in host byte order. + n_net*: uint32 ## The network number, in host byte order. Protoent* {.importc: "struct protoent", pure, final, header: "".} = object ## struct protoent diff --git a/lib/posix/posix_openbsd_amd64.nim b/lib/posix/posix_openbsd_amd64.nim index 1ef4a4182d..fbe72511cf 100644 --- a/lib/posix/posix_openbsd_amd64.nim +++ b/lib/posix/posix_openbsd_amd64.nim @@ -134,7 +134,7 @@ type Dev* {.importc: "dev_t", header: "".} = int32 Fsblkcnt* {.importc: "fsblkcnt_t", header: "".} = int Fsfilcnt* {.importc: "fsfilcnt_t", header: "".} = int - Gid* {.importc: "gid_t", header: "".} = int32 + Gid* {.importc: "gid_t", header: "".} = uint32 Id* {.importc: "id_t", header: "".} = int Ino* {.importc: "ino_t", header: "".} = int Key* {.importc: "key_t", header: "".} = int @@ -171,7 +171,7 @@ type Trace_event_set* {.importc: "trace_event_set_t", header: "".} = int Trace_id* {.importc: "trace_id_t", header: "".} = int - Uid* {.importc: "uid_t", header: "".} = int32 + Uid* {.importc: "uid_t", header: "".} = uint32 Useconds* {.importc: "useconds_t", header: "".} = int Utsname* {.importc: "struct utsname", @@ -446,9 +446,9 @@ type header: "".} = object ## struct sockaddr_in6 sin6_family*: TSa_Family ## AF_INET6. sin6_port*: InPort ## Port number. - sin6_flowinfo*: int32 ## IPv6 traffic class and flow information. + sin6_flowinfo*: uint32 ## IPv6 traffic class and flow information. sin6_addr*: In6Addr ## IPv6 address. - sin6_scope_id*: int32 ## Set of interfaces for a scope. + sin6_scope_id*: uint32 ## Set of interfaces for a scope. Tipv6_mreq* {.importc: "struct ipv6_mreq", pure, final, header: "".} = object ## struct ipv6_mreq @@ -475,7 +475,7 @@ type ## alternative network names, terminated by a ## null pointer. n_addrtype*: cint ## The address type of the network. - n_net*: int32 ## The network number, in host byte order. + n_net*: uint32 ## The network number, in host byte order. Protoent* {.importc: "struct protoent", pure, final, header: "".} = object ## struct protoent diff --git a/tests/stdlib/twronguidtype.nim b/tests/stdlib/twronguidtype.nim new file mode 100644 index 0000000000..25f834d8a4 --- /dev/null +++ b/tests/stdlib/twronguidtype.nim @@ -0,0 +1,8 @@ +# issue #24076 + +when defined(macosx) or defined(freebsd) or defined(openbsd) or defined(netbsd): + import std/posix + proc uid(x: uint32): Uid = Uid(x) + var y: uint32 + let myUid = geteuid() + discard myUid == uid(y)