From 62512d221964d64d4aea5726a6cec2df23e827c3 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Fri, 16 Oct 2026 07:10:38 +0000 Subject: [PATCH] Sys.syncAll over C asks whether fd is open; test/libc with -Werror The mend met in rless: the C Sys's syncAll never used fd, so a program over it failed with -Werror. Naming it _fd, as the proposal had it, can't be done while the seed builds src: the seed's interface check counts a parameter's name, though 5.9 says a signature doesn't. So syncAll asks fcntl(F_GETFD) whether fd is open first, and gives -9 (EBADF) for one that isn't, as Linux's syncfs does; each Sys's test says so. test/check.sh now builds test/libc with -Werror, so a warning in the C Sys fails make check. --- diff --git a/CLAUDE.md b/CLAUDE.md index 21ff8e4..1582ced 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -42,8 +42,8 @@ one. `test/msg` holds this compiler's `X.stderr` and `X.err` for the programs in `conform/`. `test/pretty/X.raz` must format to `X.expect`. Examples in `examples/` -work the same way, compiled with `-Werror`, as are the tools and the -library's tests: they must have no warnings. +work the same way, compiled with `-Werror`, as are `test/libc`, the +tools and the library's tests: they must have no warnings. ## How we work diff --git a/PROPOSALS.md b/PROPOSALS.md index fe8b06d..8a12cba 100644 --- a/PROPOSALS.md +++ b/PROPOSALS.md @@ -491,29 +491,6 @@ breaks a `match` on `Status` that names all four, so it is left out: the shell knows when it continues a job itself. -## `Sys.syncAll`'s unused parameter, in the C `Sys` - -`lib/Sys.raz`, the `Sys` over the C library, has `syncAll(fd)` call -C's `sync`, which takes no file and flushes every file system; so `fd` -is never used, and a program built over it with `-Werror` fails: - -``` -lib/Sys.raz:249:15: error: parameter fd is never used -``` - -Linux's `Sys` uses `fd` (`syncfs`), so only the C one warns, and only -for a program that imports `Sys`, which is most. raz's own checks -build `test/libc` without `-Werror`, so they don't see it. - -The proposal: call the parameter `_fd` in `lib/Sys.raz`, as the -warning says. A parameter's name isn't part of the signature (5.9), -so the interface check between the two files still holds, and no -program changes. It is a mend of the library, not a wish: it could -come with any release. - -Met in rless, whose `make rless-c` builds over the C `Sys` without -`-Werror` for this alone. - ## `Map.done` `Map` takes memory from its allocator as it grows and frees the old diff --git a/lib/Sys.linux-x86_64.raz b/lib/Sys.linux-x86_64.raz index eab234e..8133e81 100644 --- a/lib/Sys.linux-x86_64.raz +++ b/lib/Sys.linux-x86_64.raz @@ -1472,6 +1472,7 @@ m := INT(i.ino); i, err := info("/tmp/raz-sys-dir/h"); if (err # 0) or (INT(i.ino) # m) or (syncAll(fd) # 0) then exit(2); end; + if syncAll(-1) # -9 then exit(2); end; (* EBADF *) (* the lock: one open file holds it, another can't take it until the first is closed *) k := openRead("/tmp/raz-sys-dir/h"); diff --git a/lib/Sys.raz b/lib/Sys.raz index 5dec61d..12147e6 100644 --- a/lib/Sys.raz +++ b/lib/Sys.raz @@ -254,9 +254,12 @@ (* Returns once everything written to the file system that holds fd is on the disk: 0, or minus an errno. POSIX has no call for one file - system, so it is sync's, which flushes them all and does no less. *) + system, so it is sync's, which flushes them all and does no less; + fd is still asked whether it is open, for the -9 (EBADF) Linux's + syncfs gives one that isn't. *) proc syncAll*(fd: INT): INT; begin + if C.fcntl(I32(fd), 1, 0) < 0 then return failed(); end; (* F_GETFD *) C.sync; return 0; end; @@ -1455,6 +1458,7 @@ m := INT(i.ino); i, err := info("/tmp/raz-sys-dir/h"); if (err # 0) or (INT(i.ino) # m) or (syncAll(fd) # 0) then exit(2); end; + if syncAll(-1) # -9 then exit(2); end; (* EBADF *) (* the lock: one open file holds it, another can't take it until the first is closed *) k := openRead("/tmp/raz-sys-dir/h"); diff --git a/test/check.sh b/test/check.sh index 3146e72..d1b0e42 100755 --- a/test/check.sh +++ b/test/check.sh @@ -13,10 +13,10 @@ # A program without X.expect is compiled, not run. test/libc puts # lib/Sys.raz, over the C library, before the system call one. # Programs in test/err must not compile, and must print X.err; there -# X.args holds the compiler's options. The examples, the tools and the -# library's tests are compiled with -Werror, so warnings fail them. Then -# the version, tools/Doc.raz, the report's examples, the tutorial's, -# tools/Pretty.raz, and the library's own tests. +# X.args holds the compiler's options. The examples, test/libc, the +# tools and the library's tests are compiled with -Werror, so warnings +# fail them. Then the version, tools/Doc.raz, the report's examples, +# the tutorial's, tools/Pretty.raz, and the library's own tests. raz=./raz out=build/check @@ -34,7 +34,7 @@ run() { # run dir name dir=$1; name=$2 flags= - [ $dir = examples ] && flags=-Werror + [ $dir = examples ] || [ $dir = test/libc ] && flags=-Werror if ! $raz $flags -I $dir/mods -o $out/$name $dir/$name.raz 2>$out/$name.cerr; then echo "FAIL $dir/$name: doesn't compile: $(cat $out/$name.cerr)" fail=$((fail + 1)); return