From 3543de16864b082764a176983502c7041e3743fe Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Mon, 19 Oct 2026 10:37:20 +0100 Subject: [PATCH] Sys: PTR in place of the private bytes recvfrom, sendto and recvmsg take PTR(buf), now that BOOT, v0.20.0, has it. An empty slice gives what it holds, not nil, which the kernel and the C library never read with a length of 0. write, read and send keep their test for an empty slice, which is behaviour: no call is made. --- diff --git a/lib/Sys.linux-x86_64.raz b/lib/Sys.linux-x86_64.raz index 024102d..61c529e 100644 --- a/lib/Sys.linux-x86_64.raz +++ b/lib/Sys.linux-x86_64.raz @@ -915,14 +915,6 @@ return SYSCALL(72, fd, 4, flags); (* F_SETFL *) end; -(* The address of b's first byte, or nil if it has none, for a system - call that takes an address and a length. *) -proc bytes(b: []U8): ^U8; -begin - if LEN(b) = 0 then return nil; end; - return ADR(b[0]); -end; - (* A stream socket connected to port at addr, as connectTcp makes it, or -110 (ETIMEDOUT) if it isn't connected within ms milliseconds. It starts to connect without waiting, then waits for the socket to @@ -966,7 +958,7 @@ var p: Peer; size: I32; n: INT; begin size := I32(SIZE(Sockaddr)); - n := SYSCALL(45, fd, bytes(buf), LEN(buf), 0, ADR(p.a), ADR(size)); (* recvfrom *) + n := SYSCALL(45, fd, PTR(buf), LEN(buf), 0, ADR(p.a), ADR(size)); (* recvfrom *) p.size := INT(size); return n, p; end; @@ -975,7 +967,7 @@ gave it: the bytes sent, or minus an errno. *) proc reply*(fd: INT; peer: Peer; s: []U8): INT; begin - return SYSCALL(44, fd, bytes(s), LEN(s), 4000H, ADR(peer.a), peer.size); (* sendto, MSG_NOSIGNAL *) + return SYSCALL(44, fd, PTR(s), LEN(s), 4000H, ADR(peer.a), peer.size); (* sendto, MSG_NOSIGNAL *) end; (* Sends s, at least one byte, to the Unix socket fd, as send does, and @@ -1003,7 +995,7 @@ proc receiveFds*(fd: INT; buf: []U8; fds: []INT): (INT, INT); var m: Msghdr; v: Iovec; c: Rights; n, k, i: INT; begin - v := {base: bytes(buf), size: LEN(buf)}; + v := {base: PTR(buf), size: LEN(buf)}; m := {iov: ADR(v), iovLen: 1, control: ^U8(ADR(c)), controlSize: SIZE(Rights)}; n := SYSCALL(47, fd, ADR(m), 40000000H); (* recvmsg, MSG_CMSG_CLOEXEC *) if n < 0 then return n, 0; end; diff --git a/lib/Sys.raz b/lib/Sys.raz index c61f380..b37506f 100644 --- a/lib/Sys.raz +++ b/lib/Sys.raz @@ -955,14 +955,6 @@ return 0; end; -(* The address of b's first byte, or nil if it has none, for a call - that takes an address and a length. *) -proc bytes(b: []U8): ^U8; -begin - if LEN(b) = 0 then return nil; end; - return ADR(b[0]); -end; - (* A stream socket connected to port at addr, as connectTcp makes it, or -110 (ETIMEDOUT) if it isn't connected within ms milliseconds. It starts to connect without waiting, then waits for the socket to @@ -1009,7 +1001,7 @@ var p: Peer; size: U32; n: INT; begin size := U32(SIZE(Sockaddr)); - n := C.recvfrom(I32(fd), bytes(buf), UINT(LEN(buf)), 0, ^U8(ADR(p.a)), ADR(size)); + n := C.recvfrom(I32(fd), PTR(buf), UINT(LEN(buf)), 0, ^U8(ADR(p.a)), ADR(size)); if n < 0 then n := failed(); end; p.size := INT(size); return n, p; @@ -1020,7 +1012,7 @@ proc reply*(fd: INT; peer: Peer; s: []U8): INT; var r: INT; begin - r := C.sendto(I32(fd), bytes(s), UINT(LEN(s)), CAbi.msgNosignal, ^U8(ADR(peer.a)), U32(peer.size)); + r := C.sendto(I32(fd), PTR(s), UINT(LEN(s)), CAbi.msgNosignal, ^U8(ADR(peer.a)), U32(peer.size)); if r < 0 then return failed(); end; return r; end; @@ -1061,7 +1053,7 @@ proc receiveFds*(fd: INT; buf: []U8; fds: []INT): (INT, INT); var m: Msghdr; v: Iovec; c: Control; mp, cp: ^U8; got: ^I32; n, k, i, size: INT; begin - v := {base: bytes(buf), size: LEN(buf)}; + v := {base: PTR(buf), size: LEN(buf)}; mp := ^U8(ADR(m)); cp := ^U8(ADR(c)); setField(mp, CAbi.msgIovAt, SIZE(^U8), INT(ADR(v)));