From 21771765a2c1f1fc86d87ad6e032d4050d8a651b Mon Sep 17 00:00:00 2001 From: metagn Date: Mon, 9 Sep 2024 15:44:49 +0300 Subject: [PATCH] add posix uint changes to changelog + fix Nlink, Dev on FreeBSD (#24088) refs #24078, refs #24076 Since these changes are potentially breaking, add them to changelog, also add Nlink as mentioned in https://github.com/nim-lang/Nim/issues/24076#issuecomment-2337666555. --- changelog.md | 9 +++++++++ lib/posix/posix_macos_amd64.nim | 8 ++++++-- lib/posix/posix_openbsd_amd64.nim | 8 ++++++-- tests/stdlib/{twronguidtype.nim => twrongstattype.nim} | 6 ++++++ 4 files changed, 27 insertions(+), 4 deletions(-) rename tests/stdlib/{twronguidtype.nim => twrongstattype.nim} (55%) diff --git a/changelog.md b/changelog.md index 46bc1a8724..3bee049937 100644 --- a/changelog.md +++ b/changelog.md @@ -52,6 +52,15 @@ const bar = a # error let baz = a # error ``` +- The following POSIX wrappers have had their types changed from signed to + unsigned types on OSX and FreeBSD/OpenBSD to correct codegen errors: + - `Gid` (was `int32`, is now `uint32`) + - `Uid` (was `int32`, is now `uint32`) + - `Dev` (was `int32`, is now `uint32` on FreeBSD) + - `Nlink` (was `int16`, is now `uint32` on OpenBSD and `uint16` on OSX/other BSD) + - `sin6_flowinfo` and `sin6_scope_id` fields of `Sockaddr_in6` + (were `int32`, are now `uint32`) + - `n_net` field of `Tnetent` (was `int32`, is now `uint32`) ## Standard library additions and changes diff --git a/lib/posix/posix_macos_amd64.nim b/lib/posix/posix_macos_amd64.nim index 366181846d..a4b64ed622 100644 --- a/lib/posix/posix_macos_amd64.nim +++ b/lib/posix/posix_macos_amd64.nim @@ -122,7 +122,11 @@ type ## used for block sizes Clock* {.importc: "clock_t", header: "".} = int ClockId* {.importc: "clockid_t", header: "".} = int - Dev* {.importc: "dev_t", header: "".} = int32 + Dev* {.importc: "dev_t", header: "".} = ( + when defined(freebsd): + uint32 + else: + int32) Fsblkcnt* {.importc: "fsblkcnt_t", header: "".} = int Fsfilcnt* {.importc: "fsfilcnt_t", header: "".} = int Gid* {.importc: "gid_t", header: "".} = uint32 @@ -135,7 +139,7 @@ type else: uint16 ) - Nlink* {.importc: "nlink_t", header: "".} = int16 + Nlink* {.importc: "nlink_t", header: "".} = uint16 Off* {.importc: "off_t", header: "".} = int64 Pid* {.importc: "pid_t", header: "".} = int32 Pthread_attr* {.importc: "pthread_attr_t", header: "".} = int diff --git a/lib/posix/posix_openbsd_amd64.nim b/lib/posix/posix_openbsd_amd64.nim index fbe72511cf..184cd89c07 100644 --- a/lib/posix/posix_openbsd_amd64.nim +++ b/lib/posix/posix_openbsd_amd64.nim @@ -131,7 +131,11 @@ type ## used for block sizes Clock* {.importc: "clock_t", header: "".} = int ClockId* {.importc: "clockid_t", header: "".} = int - Dev* {.importc: "dev_t", header: "".} = int32 + Dev* {.importc: "dev_t", header: "".} = ( + when defined(freebsd): + uint32 + else: + int32) Fsblkcnt* {.importc: "fsblkcnt_t", header: "".} = int Fsfilcnt* {.importc: "fsfilcnt_t", header: "".} = int Gid* {.importc: "gid_t", header: "".} = uint32 @@ -139,7 +143,7 @@ type Ino* {.importc: "ino_t", header: "".} = int Key* {.importc: "key_t", header: "".} = int Mode* {.importc: "mode_t", header: "".} = uint32 - Nlink* {.importc: "nlink_t", header: "".} = int16 + Nlink* {.importc: "nlink_t", header: "".} = uint32 Off* {.importc: "off_t", header: "".} = int64 Pid* {.importc: "pid_t", header: "".} = int32 Pthread_attr* {.importc: "pthread_attr_t", header: "".} = int diff --git a/tests/stdlib/twronguidtype.nim b/tests/stdlib/twrongstattype.nim similarity index 55% rename from tests/stdlib/twronguidtype.nim rename to tests/stdlib/twrongstattype.nim index 25f834d8a4..4a1fc30c65 100644 --- a/tests/stdlib/twronguidtype.nim +++ b/tests/stdlib/twrongstattype.nim @@ -6,3 +6,9 @@ when defined(macosx) or defined(freebsd) or defined(openbsd) or defined(netbsd): var y: uint32 let myUid = geteuid() discard myUid == uid(y) + proc dev(x: uint32): Dev = Dev(x) + let myDev = 1.Dev + discard myDev == dev(y) + proc nlink(x: uint32): Nlink = Nlink(x) + let myNlink = 1.Nlink + discard myNlink == nlink(y)