raz / commit 62512d22

commit
62512d221964d64d4aea5726a6cec2df23e827c3
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
8ea6aa4d
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.

patch · log

5 files changed, +13 -31

CLAUDE.md modified +2 -2

@@ -42,8 +42,8 @@
4242 one. `test/msg` holds this compiler's `X.stderr` and `X.err` for the
4343 programs in `conform/`.
4444 `test/pretty/X.raz` must format to `X.expect`. Examples in `examples/`
45-work the same way, compiled with `-Werror`, as are the tools and the
46-library's tests: they must have no warnings.
45+work the same way, compiled with `-Werror`, as are `test/libc`, the
46+tools and the library's tests: they must have no warnings.
4747
4848 ## How we work
4949

PROPOSALS.md modified +0 -23

@@ -491,29 +491,6 @@
491491 breaks a `match` on `Status` that names all four, so it is left out:
492492 the shell knows when it continues a job itself.
493493
494-## `Sys.syncAll`'s unused parameter, in the C `Sys`
495-
496-`lib/Sys.raz`, the `Sys` over the C library, has `syncAll(fd)` call
497-C's `sync`, which takes no file and flushes every file system; so `fd`
498-is never used, and a program built over it with `-Werror` fails:
499-
500-```
501-lib/Sys.raz:249:15: error: parameter fd is never used
502-```
503-
504-Linux's `Sys` uses `fd` (`syncfs`), so only the C one warns, and only
505-for a program that imports `Sys`, which is most. raz's own checks
506-build `test/libc` without `-Werror`, so they don't see it.
507-
508-The proposal: call the parameter `_fd` in `lib/Sys.raz`, as the
509-warning says. A parameter's name isn't part of the signature (5.9),
510-so the interface check between the two files still holds, and no
511-program changes. It is a mend of the library, not a wish: it could
512-come with any release.
513-
514-Met in rless, whose `make rless-c` builds over the C `Sys` without
515-`-Werror` for this alone.
516-
517494 ## `Map.done`
518495
519496 `Map` takes memory from its allocator as it grows and frees the old

lib/Sys.linux-x86_64.raz (history) modified +1 -0

@@ -1472,6 +1472,7 @@
14721472 m := INT(i.ino);
14731473 i, err := info("/tmp/raz-sys-dir/h");
14741474 if (err # 0) or (INT(i.ino) # m) or (syncAll(fd) # 0) then exit(2); end;
1475+ if syncAll(-1) # -9 then exit(2); end; (* EBADF *)
14751476 (* the lock: one open file holds it, another can't take it until
14761477 the first is closed *)
14771478 k := openRead("/tmp/raz-sys-dir/h");

lib/Sys.raz (history) modified +5 -1

@@ -254,9 +254,12 @@
254254
255255 (* Returns once everything written to the file system that holds fd
256256 is on the disk: 0, or minus an errno. POSIX has no call for one file
257- system, so it is sync's, which flushes them all and does no less. *)
257+ system, so it is sync's, which flushes them all and does no less;
258+ fd is still asked whether it is open, for the -9 (EBADF) Linux's
259+ syncfs gives one that isn't. *)
258260 proc syncAll*(fd: INT): INT;
259261 begin
262+ if C.fcntl(I32(fd), 1, 0) < 0 then return failed(); end; (* F_GETFD *)
260263 C.sync;
261264 return 0;
262265 end;
@@ -1455,6 +1458,7 @@
14551458 m := INT(i.ino);
14561459 i, err := info("/tmp/raz-sys-dir/h");
14571460 if (err # 0) or (INT(i.ino) # m) or (syncAll(fd) # 0) then exit(2); end;
1461+ if syncAll(-1) # -9 then exit(2); end; (* EBADF *)
14581462 (* the lock: one open file holds it, another can't take it until
14591463 the first is closed *)
14601464 k := openRead("/tmp/raz-sys-dir/h");

test/check.sh (history) modified +5 -5

@@ -13,10 +13,10 @@
1313 # A program without X.expect is compiled, not run. test/libc puts
1414 # lib/Sys.raz, over the C library, before the system call one.
1515 # Programs in test/err must not compile, and must print X.err; there
16-# X.args holds the compiler's options. The examples, the tools and the
17-# library's tests are compiled with -Werror, so warnings fail them. Then
18-# the version, tools/Doc.raz, the report's examples, the tutorial's,
19-# tools/Pretty.raz, and the library's own tests.
16+# X.args holds the compiler's options. The examples, test/libc, the
17+# tools and the library's tests are compiled with -Werror, so warnings
18+# fail them. Then the version, tools/Doc.raz, the report's examples,
19+# the tutorial's, tools/Pretty.raz, and the library's own tests.
2020
2121 raz=./raz
2222 out=build/check
@@ -34,7 +34,7 @@
3434 run() { # run dir name
3535 dir=$1; name=$2
3636 flags=
37- [ $dir = examples ] && flags=-Werror
37+ [ $dir = examples ] || [ $dir = test/libc ] && flags=-Werror
3838 if ! $raz $flags -I $dir/mods -o $out/$name $dir/$name.raz 2>$out/$name.cerr; then
3939 echo "FAIL $dir/$name: doesn't compile: $(cat $out/$name.cerr)"
4040 fail=$((fail + 1)); return