lib/os+selfhost: *u8→str path migration (#23)
Path-shaped entrypoints now take str: open, tryopen, access, remove, mkdir, rmdir, mkdirs, stat, lstat, exists, execve (path arg only). Each cites its Hare source (ref/hare/os/*.ha, ref/hare/sys/+linux/ *.ha). New internal kpath(str) *u8 copies into module-level pathbuf: [4096]u8 and NUL-terminates; mirrors ref/hare/sys/+linux/syscalls.ha:25,53. Non-reentrant — graduates with thread story. mkdirs flattens to one kpath at entry then walks pathbuf invoking raw SYS_mkdir to avoid nested kpath clobber. One Hare divergence at kpath: ships *u8 with nil ENAMETOOLONG sentinel instead of (*const u8 | errno). Reason: wwstage over-allocates 1-word-payload tagged returns to 24B (cstage emits 16B); filed as follow-up. Repro at .ai/probe_tagged_return_pointer_payload.ww; graduates when fix lands. Each selfhost cmd grew a private pathstr(*u8) str (cstrlen + bs) for remaining *u8 path sites; w6l shares via obj.ww. Probe 7 in smoke updated. Tests 975/976/981 cover migrated entrypoints; 976 extended with two ENAMETOOLONG rows (-36 for stat, false for exists).
This commit is contained in:
@@ -56,7 +56,7 @@ fn istype(m: os.mode, t: os.mode) bool = {
|
||||
| os.stat_mask.SIZE | os.stat_mask.INODE
|
||||
| os.stat_mask.ATIME | os.stat_mask.MTIME
|
||||
| os.stat_mask.CTIME) as u32;
|
||||
match (os.stat(&fi, p.ptr)) {
|
||||
match (os.stat(&fi, p)) {
|
||||
case let e: os.oserror => fail();
|
||||
case void => {
|
||||
if ((fi.mask as u32) != wantmask) { fail(); };
|
||||
@@ -87,7 +87,7 @@ fn istype(m: os.mode, t: os.mode) bool = {
|
||||
@test fn test_stat_subdir() void = {
|
||||
let p = envpath("WW_TEST_STAT_SUBDIR");
|
||||
let fi: os.filestat;
|
||||
match (os.stat(&fi, p.ptr)) {
|
||||
match (os.stat(&fi, p)) {
|
||||
case let e: os.oserror => fail();
|
||||
case void => {
|
||||
if (!istype(fi.mode, os.mode.DIR)) { fail(); };
|
||||
@@ -100,7 +100,7 @@ fn istype(m: os.mode, t: os.mode) bool = {
|
||||
@test fn test_stat_noent() void = {
|
||||
let p = envpath("WW_TEST_STAT_NOENT");
|
||||
let fi: os.filestat;
|
||||
match (os.stat(&fi, p.ptr)) {
|
||||
match (os.stat(&fi, p)) {
|
||||
case void => fail();
|
||||
case let e: os.oserror => {
|
||||
// ENOENT = 2 → raw errno is -2.
|
||||
@@ -117,7 +117,7 @@ fn istype(m: os.mode, t: os.mode) bool = {
|
||||
@test fn test_stat_symlink_follow() void = {
|
||||
let p = envpath("WW_TEST_STAT_SYMLINK");
|
||||
let fi: os.filestat;
|
||||
match (os.stat(&fi, p.ptr)) {
|
||||
match (os.stat(&fi, p)) {
|
||||
case let e: os.oserror => fail();
|
||||
case void => {
|
||||
if (!istype(fi.mode, os.mode.REG)) { fail(); };
|
||||
@@ -129,7 +129,7 @@ fn istype(m: os.mode, t: os.mode) bool = {
|
||||
@test fn test_lstat_symlink_nofollow() void = {
|
||||
let p = envpath("WW_TEST_STAT_SYMLINK");
|
||||
let fi: os.filestat;
|
||||
match (os.lstat(&fi, p.ptr)) {
|
||||
match (os.lstat(&fi, p)) {
|
||||
case let e: os.oserror => fail();
|
||||
case void => {
|
||||
if (!istype(fi.mode, os.mode.LINK)) { fail(); };
|
||||
@@ -141,7 +141,7 @@ fn istype(m: os.mode, t: os.mode) bool = {
|
||||
|
||||
@test fn test_fstat_regfile() void = {
|
||||
let p = envpath("WW_TEST_STAT_REGFILE");
|
||||
let fd: i32 = os.open(p.ptr, os.flag.RDONLY, 0i32);
|
||||
let fd: i32 = os.open(p, os.flag.RDONLY, 0i32);
|
||||
if (fd < 0) { fail(); };
|
||||
let fi: os.filestat;
|
||||
match (os.fstat(&fi, fd)) {
|
||||
@@ -158,17 +158,53 @@ fn istype(m: os.mode, t: os.mode) bool = {
|
||||
|
||||
@test fn test_exists_regfile() void = {
|
||||
let p = envpath("WW_TEST_STAT_REGFILE");
|
||||
if (!os.exists(p.ptr)) { fail(); };
|
||||
if (!os.exists(p)) { fail(); };
|
||||
};
|
||||
|
||||
@test fn test_exists_subdir() void = {
|
||||
let p = envpath("WW_TEST_STAT_SUBDIR");
|
||||
if (!os.exists(p.ptr)) { fail(); };
|
||||
if (!os.exists(p)) { fail(); };
|
||||
};
|
||||
|
||||
@test fn test_exists_noent() void = {
|
||||
let p = envpath("WW_TEST_STAT_NOENT");
|
||||
if (os.exists(p.ptr)) { fail(); };
|
||||
if (os.exists(p)) { fail(); };
|
||||
};
|
||||
|
||||
// ---- ENAMETOOLONG: kpath rejects paths >= PATH_MAX -------------------
|
||||
//
|
||||
// kpath copies into a single [PATH_MAX]u8 buffer and reserves one byte
|
||||
// for the NUL terminator (`p.len + 1 >= PATH_MAX` → reject). The
|
||||
// rejection surfaces as `oserror = -36` (ENAMETOOLONG) on (... |
|
||||
// oserror)-returning wrappers, and as `false` on [[os.exists]]
|
||||
// (Hare's os::exists doc: "true if a node exists at the given path,
|
||||
// or false if not.").
|
||||
|
||||
let bigbuf: [4200]u8;
|
||||
|
||||
fn makebig(n: i32) str = {
|
||||
let i: i32 = 0;
|
||||
for (i < n) { bigbuf[i] = 97u8; i += 1; }; // 'a'
|
||||
let r: str;
|
||||
r.ptr = &bigbuf[0];
|
||||
r.len = n;
|
||||
return r;
|
||||
};
|
||||
|
||||
@test fn test_stat_toolong() void = {
|
||||
let bp = makebig(os.PATH_MAX);
|
||||
let fi: os.filestat;
|
||||
match (os.stat(&fi, bp)) {
|
||||
case void => fail();
|
||||
case let e: os.oserror => {
|
||||
if ((e: i64) != -36i64) { fail(); }; // ENAMETOOLONG
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@test fn test_exists_toolong() void = {
|
||||
let bp = makebig(os.PATH_MAX);
|
||||
if (os.exists(bp)) { fail(); };
|
||||
};
|
||||
|
||||
export fn main() i32 = {
|
||||
@@ -181,5 +217,7 @@ export fn main() i32 = {
|
||||
signalled = 7; test_exists_regfile();
|
||||
signalled = 8; test_exists_subdir();
|
||||
signalled = 9; test_exists_noent();
|
||||
signalled = 10; test_stat_toolong();
|
||||
signalled = 11; test_exists_toolong();
|
||||
return 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user