raz / commit c8d9a160

commit
c8d9a1603d310069428108159191a472fcf44f84
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
ccd59f55
Sys's directories take the Dir by var (report 2026-10.33)

Sys.openDir, nextEntry, entryKind and closeDir take var d: Dir, in both
Sys files; none kept the pointer. entryKind only reads, but Sys is
compiled by the seed, which doesn't know const: it takes const when the
seed is gone, which breaks no caller. nextEntry returns a slice of the
caller's Dir, which a var parameter is. The fixpoint holds; test/libc
passes over glibc and musl.

patch · log

5 files changed, +55 -55

doc/raz-lib.md (history) modified +4 -4

@@ -266,10 +266,10 @@
266266 proc infoOf*(fd: INT): (Info, INT); (* the open file's *)
267267 proc space*(path: []U8): (I64, I64, INT); (* the bytes free and in all on path's file system *)
268268
269-proc openDir*(d: ^Dir; path: []U8): INT;
270-proc nextEntry*(d: ^Dir): ([]U8, BOOL); (* a name, good until the next call; false at the end *)
271-proc entryKind*(d: ^Dir): Kind; (* what the name nextEntry gave last is *)
272-proc closeDir*(d: ^Dir);
269+proc openDir*(var d: Dir; path: []U8): INT;
270+proc nextEntry*(var d: Dir): ([]U8, BOOL); (* a name, good until the next call; false at the end *)
271+proc entryKind*(var d: Dir): Kind; (* what the name nextEntry gave last is *)
272+proc closeDir*(var d: Dir);
273273
274274 proc rawMode*(fd: INT): BOOL; (* the terminal on fd: no echo, no lines, no signals *)
275275 proc restoreMode*(fd: INT); (* as rawMode found it *)

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

@@ -526,38 +526,38 @@
526526 end;
527527
528528 (* Opens the directory at path, for nextEntry. *)
529-proc openDir*(d: ^Dir; path: []U8): INT;
529+proc openDir*(var d: Dir; path: []U8): INT;
530530 var a: [4096]U8;
531531 begin
532- d^.kind := unknown;
533- d^.pos := 0;
534- d^.len := 0;
532+ d.kind := unknown;
533+ d.pos := 0;
534+ d.len := 0;
535535 if not cstr(path, a) then return -36; end;
536- d^.fd := SYSCALL(2, ADR(a), 10000H); (* open, O_RDONLY, O_DIRECTORY *)
537- if d^.fd < 0 then return d^.fd; end;
536+ d.fd := SYSCALL(2, ADR(a), 10000H); (* open, O_RDONLY, O_DIRECTORY *)
537+ if d.fd < 0 then return d.fd; end;
538538 return 0;
539539 end;
540540
541541 (* The next name in the directory, good until the next call, but . and
542542 .., in no order; false at the end. *)
543-proc nextEntry*(d: ^Dir): ([]U8, BOOL);
543+proc nextEntry*(var d: Dir): ([]U8, BOOL);
544544 var n, at: INT;
545545 begin
546546 while true do
547- if d^.pos >= d^.len then
548- d^.len := SYSCALL(217, d^.fd, ADR(d^.buf), LEN(d^.buf)); (* getdents64 *)
549- d^.pos := 0;
550- if d^.len <= 0 then return "", false; end;
547+ if d.pos >= d.len then
548+ d.len := SYSCALL(217, d.fd, ADR(d.buf), LEN(d.buf)); (* getdents64 *)
549+ d.pos := 0;
550+ if d.len <= 0 then return "", false; end;
551551 end;
552552 (* a record: d_ino and d_off, 8 bytes each; d_reclen, 2; d_type,
553553 1; then d_name, ending in a zero *)
554- at := d^.pos + 19;
554+ at := d.pos + 19;
555555 n := 0;
556- while d^.buf[at + n] # 0 do INC(n); end;
557- d^.kind := kindOf(d^.buf[d^.pos + 18]);
558- INC(d^.pos, INT(d^.buf[d^.pos + 16]) + INT(d^.buf[d^.pos + 17]) * 256);
559- if (d^.buf[at..at + n] # ".") and (d^.buf[at..at + n] # "..") then
560- return d^.buf[at..at + n], true;
556+ while d.buf[at + n] # 0 do INC(n); end;
557+ d.kind := kindOf(d.buf[d.pos + 18]);
558+ INC(d.pos, INT(d.buf[d.pos + 16]) + INT(d.buf[d.pos + 17]) * 256);
559+ if (d.buf[at..at + n] # ".") and (d.buf[at..at + n] # "..") then
560+ return d.buf[at..at + n], true;
561561 end;
562562 end;
563563 return "", false;
@@ -566,15 +566,15 @@
566566 (* What the name nextEntry gave last is, as the directory says, so that
567567 a walk needn't ask each file with linkInfo; unknown where the file
568568 system doesn't say. A link is isLink, whatever it names. *)
569-proc entryKind*(d: ^Dir): Kind;
569+proc entryKind*(var d: Dir): Kind;
570570 begin
571- return d^.kind;
571+ return d.kind;
572572 end;
573573
574574 (* Closes the directory d that openDir opened. *)
575-proc closeDir*(d: ^Dir);
575+proc closeDir*(var d: Dir);
576576 begin
577- _ := SYSCALL(3, d^.fd);
577+ _ := SYSCALL(3, d.fd);
578578 end;
579579
580580 (* Puts the terminal on fd into raw mode: no echo, no lines, no signals,
@@ -2249,18 +2249,18 @@
22492249 _ := remove("/tmp/raz-sys-dir/h");
22502250 i, err := info("/no/such/file");
22512251 if err >= 0 then exit(2); end;
2252- if openDir(ADR(d), "/tmp/raz-sys-dir") # 0 then exit(2); end;
2253- name, ok := nextEntry(ADR(d));
2252+ if openDir(d, "/tmp/raz-sys-dir") # 0 then exit(2); end;
2253+ name, ok := nextEntry(d);
22542254 if not ok or (name # "g") then exit(2); end;
2255- if (entryKind(ADR(d)) # isFile) and (entryKind(ADR(d)) # unknown) then exit(2); end;
2255+ if (entryKind(d) # isFile) and (entryKind(d) # unknown) then exit(2); end;
22562256 i, err := info("/tmp/raz-sys-dir/g");
22572257 j, err := info("/tmp/raz-sys-dir");
22582258 if (err # 0) or (i.dev # j.dev) or (i.ino = j.ino) or (i.links # 1) then exit(2); end;
2259- name, ok := nextEntry(ADR(d));
2259+ name, ok := nextEntry(d);
22602260 if ok then exit(2); end;
2261- closeDir(ADR(d));
2261+ closeDir(d);
22622262 if (remove("/tmp/raz-sys-dir/g") # 0) or (remove("/tmp/raz-sys-dir/g") >= 0) then exit(2); end;
2263- if openDir(ADR(d), "/no/such/dir") >= 0 then exit(2); end;
2263+ if openDir(d, "/no/such/dir") >= 0 then exit(2); end;
22642264 (* the terminal: none here, fd -1 *)
22652265 if rawMode(-1) or ready(-1, 0) then exit(2); end;
22662266 w, h := termSize(-1);

lib/Sys.raz (history) modified +17 -17

@@ -599,25 +599,25 @@
599599 end;
600600
601601 (* Opens the directory at path, for nextEntry. *)
602-proc openDir*(d: ^Dir; path: []U8): INT;
602+proc openDir*(var d: Dir; path: []U8): INT;
603603 var a: [4096]U8;
604604 begin
605- d^.kind := unknown;
605+ d.kind := unknown;
606606 if not cstr(path, a) then return -36; end;
607- d^.d := C.opendir(ADR(a[0]));
608- if d^.d = nil then return failed(); end;
607+ d.d := C.opendir(ADR(a[0]));
608+ if d.d = nil then return failed(); end;
609609 return 0;
610610 end;
611611
612612 (* The next name in the directory, good until the next call, but . and
613613 .., in no order; false at the end. *)
614-proc nextEntry*(d: ^Dir): ([]U8, BOOL);
614+proc nextEntry*(var d: Dir): ([]U8, BOOL);
615615 var e: ^U8; n: INT;
616616 begin
617617 while true do
618- e := C.readdir(d^.d);
618+ e := C.readdir(d.d);
619619 if e = nil then return "", false; end;
620- d^.kind := kindOf(e[CAbi.dTypeAt]);
620+ d.kind := kindOf(e[CAbi.dTypeAt]);
621621 e := e + CAbi.dNameAt;
622622 n := 0;
623623 while e[n] # 0 do INC(n); end;
@@ -629,15 +629,15 @@
629629 (* What the name nextEntry gave last is, as the directory says, so that
630630 a walk needn't ask each file with linkInfo; unknown where the file
631631 system doesn't say. A link is isLink, whatever it names. *)
632-proc entryKind*(d: ^Dir): Kind;
632+proc entryKind*(var d: Dir): Kind;
633633 begin
634- return d^.kind;
634+ return d.kind;
635635 end;
636636
637637 (* Closes the directory d that openDir opened. *)
638-proc closeDir*(d: ^Dir);
638+proc closeDir*(var d: Dir);
639639 begin
640- _ := C.closedir(d^.d);
640+ _ := C.closedir(d.d);
641641 end;
642642
643643 (* Puts the terminal on fd into raw mode, as cfmakeraw makes it: no
@@ -2173,18 +2173,18 @@
21732173 _ := remove("/tmp/raz-sys-dir/h");
21742174 i, err := info("/no/such/file");
21752175 if err >= 0 then exit(2); end;
2176- if openDir(ADR(d), "/tmp/raz-sys-dir") # 0 then exit(2); end;
2177- name, ok := nextEntry(ADR(d));
2176+ if openDir(d, "/tmp/raz-sys-dir") # 0 then exit(2); end;
2177+ name, ok := nextEntry(d);
21782178 if not ok or (name # "g") then exit(2); end;
2179- if (entryKind(ADR(d)) # isFile) and (entryKind(ADR(d)) # unknown) then exit(2); end;
2179+ if (entryKind(d) # isFile) and (entryKind(d) # unknown) then exit(2); end;
21802180 i, err := info("/tmp/raz-sys-dir/g");
21812181 j, err := info("/tmp/raz-sys-dir");
21822182 if (err # 0) or (i.dev # j.dev) or (i.ino = j.ino) or (i.links # 1) then exit(2); end;
2183- name, ok := nextEntry(ADR(d));
2183+ name, ok := nextEntry(d);
21842184 if ok then exit(2); end;
2185- closeDir(ADR(d));
2185+ closeDir(d);
21862186 if (remove("/tmp/raz-sys-dir/g") # 0) or (remove("/tmp/raz-sys-dir/g") >= 0) then exit(2); end;
2187- if openDir(ADR(d), "/no/such/dir") >= 0 then exit(2); end;
2187+ if openDir(d, "/no/such/dir") >= 0 then exit(2); end;
21882188 (* the terminal: none here, fd -1 *)
21892189 if rawMode(-1) or ready(-1, 0) then exit(2); end;
21902190 w, h := termSize(-1);

site/content/advanced/04-files.txt (history) modified +4 -4

@@ -109,15 +109,15 @@
109109 _ := Sys.makeDir("proj/src");
110110 put("proj/b.txt", "bb");
111111 put("proj/a.txt", "a");
112- if Sys.openDir(ADR(d), "proj") < 0 then return; end;
112+ if Sys.openDir(d, "proj") < 0 then return; end;
113113 n := 0;
114- name, more := Sys.nextEntry(ADR(d));
114+ name, more := Sys.nextEntry(d);
115115 while more do
116116 copy, ok := Str.copy(Heap.heap, name);
117117 if ok and (n < 16) then names[n] := copy; INC(n); end;
118- name, more := Sys.nextEntry(ADR(d));
118+ name, more := Sys.nextEntry(d);
119119 end;
120- Sys.closeDir(ADR(d));
120+ Sys.closeDir(d);
121121 Order.sort(names[0..n]);
122122 Buf.init(path, Heap.heap);
123123 for i := 0 to n - 1 do

src/Parse.raz (history) modified +3 -3

@@ -3992,9 +3992,9 @@
39923992 begin
39933993 prefix := say1("{}.", nameOf(n));
39943994 numOthers := 0;
3995- if Sys.openDir(ADR(dp), dir) # 0 then return nil; end;
3995+ if Sys.openDir(dp, dir) # 0 then return nil; end;
39963996 repeat
3997- e, more := Sys.nextEntry(ADR(dp));
3997+ e, more := Sys.nextEntry(dp);
39983998 if not more then break; end;
39993999 if (LEN(e) > 4) and Str.hasPrefix(e, prefix) and (e[LEN(e) - 4..LEN(e)] = ".raz")
40004000 and (e # chosen) and (numOthers < 32) then
@@ -4002,7 +4002,7 @@
40024002 INC(numOthers);
40034003 end;
40044004 until false;
4005- Sys.closeDir(ADR(dp));
4005+ Sys.closeDir(dp);
40064006 for i := 0 to numOthers - 1 do
40074007 sib := try compileFile(say2("{}/{}", dir, others[i]), n, args, true);
40084008 compareIface(m, sib);