Skip to content

Commit

Permalink
fix int32's that should be uint32 on BSD & OSX (#24078)
Browse files Browse the repository at this point in the history
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 7de4ace)
  • Loading branch information
metagn authored and narimiran committed Dec 16, 2024
1 parent d51236e commit 56e7c75
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
10 changes: 5 additions & 5 deletions lib/posix/posix_macos_amd64.nim
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ type
Dev* {.importc: "dev_t", header: "<sys/types.h>".} = int32
Fsblkcnt* {.importc: "fsblkcnt_t", header: "<sys/types.h>".} = int
Fsfilcnt* {.importc: "fsfilcnt_t", header: "<sys/types.h>".} = int
Gid* {.importc: "gid_t", header: "<sys/types.h>".} = int32
Gid* {.importc: "gid_t", header: "<sys/types.h>".} = uint32
Id* {.importc: "id_t", header: "<sys/types.h>".} = int
Ino* {.importc: "ino_t", header: "<sys/types.h>".} = int
Key* {.importc: "key_t", header: "<sys/types.h>".} = int
Expand Down Expand Up @@ -167,7 +167,7 @@ type
Trace_event_set* {.importc: "trace_event_set_t",
header: "<sys/types.h>".} = int
Trace_id* {.importc: "trace_id_t", header: "<sys/types.h>".} = int
Uid* {.importc: "uid_t", header: "<sys/types.h>".} = int32
Uid* {.importc: "uid_t", header: "<sys/types.h>".} = uint32
Useconds* {.importc: "useconds_t", header: "<sys/types.h>".} = int

Utsname* {.importc: "struct utsname",
Expand Down Expand Up @@ -462,9 +462,9 @@ type
header: "<netinet/in.h>".} = 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: "<netinet/in.h>".} = object ## struct ipv6_mreq
Expand All @@ -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: "<netdb.h>".} = object ## struct protoent
Expand Down
10 changes: 5 additions & 5 deletions lib/posix/posix_openbsd_amd64.nim
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ type
Dev* {.importc: "dev_t", header: "<sys/types.h>".} = int32
Fsblkcnt* {.importc: "fsblkcnt_t", header: "<sys/types.h>".} = int
Fsfilcnt* {.importc: "fsfilcnt_t", header: "<sys/types.h>".} = int
Gid* {.importc: "gid_t", header: "<sys/types.h>".} = int32
Gid* {.importc: "gid_t", header: "<sys/types.h>".} = uint32
Id* {.importc: "id_t", header: "<sys/types.h>".} = int
Ino* {.importc: "ino_t", header: "<sys/types.h>".} = int
Key* {.importc: "key_t", header: "<sys/types.h>".} = int
Expand Down Expand Up @@ -171,7 +171,7 @@ type
Trace_event_set* {.importc: "trace_event_set_t",
header: "<sys/types.h>".} = int
Trace_id* {.importc: "trace_id_t", header: "<sys/types.h>".} = int
Uid* {.importc: "uid_t", header: "<sys/types.h>".} = int32
Uid* {.importc: "uid_t", header: "<sys/types.h>".} = uint32
Useconds* {.importc: "useconds_t", header: "<sys/types.h>".} = int

Utsname* {.importc: "struct utsname",
Expand Down Expand Up @@ -446,9 +446,9 @@ type
header: "<netinet/in.h>".} = 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: "<netinet/in.h>".} = object ## struct ipv6_mreq
Expand All @@ -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: "<netdb.h>".} = object ## struct protoent
Expand Down
8 changes: 8 additions & 0 deletions tests/stdlib/twronguidtype.nim
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 56e7c75

Please sign in to comment.