lib/fmt+lib/log: drop rt_syscall stubs; use os
After #9 (f1440bf) fn labels mangle by module, so lib/fmt and lib/log
can use os; without colliding with lib/io on the read/write/close
leaves at link.
Drop the @symbol("rt_syscall") rtsyscall3/rtsyscall1 + rawwrite/
rawexit wrappers in both files; route the 7 fmt + 3 log call sites
through os.write / os.exit. Trim the workaround-rationale comments.
Mechanical rename; underlying syscall numbers and args unchanged.
This commit is contained in:
@@ -20,27 +20,7 @@
|
||||
// via `args...`.
|
||||
|
||||
use io;
|
||||
|
||||
// Direct rt_syscall / rt_exit bindings rather than `use os;` because
|
||||
// os exports read/write/close, which collide with io.read/write/close
|
||||
// under the driver's flat-scope concat — same workaround used by
|
||||
// lib/memio. Both fmt's fd sink and io.stream sink need to coexist
|
||||
// in this module, so the os surface has to come in à la carte.
|
||||
@symbol("rt_syscall") fn rtsyscall3(num: i64, a: i64, b: i64, c: i64) i64;
|
||||
@symbol("rt_syscall") fn rtsyscall1(num: i64, a: i64) i64;
|
||||
|
||||
// rawwrite — Linux write(2) syscall (nr=1). The fd sinks below call
|
||||
// this directly instead of [[os.write]] to keep the collision off
|
||||
// fmt's exported surface. Same signature, same negative-errno
|
||||
// convention.
|
||||
fn rawwrite(fd: i32, buf: *u8, n: u64) i64 = {
|
||||
return rtsyscall3(1i64, fd: i64, buf: i64, n: i64);
|
||||
};
|
||||
|
||||
// rawexit — Linux exit(2) syscall (nr=60). Used only by `fatal`.
|
||||
fn rawexit(code: i32) void = {
|
||||
rtsyscall1(60i64, code: i64);
|
||||
};
|
||||
use os;
|
||||
|
||||
// i64dec_buf — scratch buffer for [[i64dec]] below. Module-level
|
||||
// because Hare's `strconv::i64tos` is a static-buffer view and we
|
||||
@@ -102,33 +82,33 @@ export fn fdprint(fd: i32, args: formattable...) i64 = {
|
||||
let i: i32 = 0;
|
||||
for (i < args.len) {
|
||||
if (i > 0) {
|
||||
let r: i64 = rawwrite(fd, " ".ptr, 1u64);
|
||||
let r: i64 = os.write(fd, " ".ptr, 1u64);
|
||||
if (r < 0) { return r; };
|
||||
total += r;
|
||||
};
|
||||
match (args[i]) {
|
||||
case let n: i64 => {
|
||||
let s: str = i64dec(n);
|
||||
let r: i64 = rawwrite(fd, s.ptr, s.len: u64);
|
||||
let r: i64 = os.write(fd, s.ptr, s.len: u64);
|
||||
if (r < 0) { return r; };
|
||||
total += r;
|
||||
};
|
||||
case let s: str => {
|
||||
let r: i64 = rawwrite(fd, s.ptr, s.len: u64);
|
||||
let r: i64 = os.write(fd, s.ptr, s.len: u64);
|
||||
if (r < 0) { return r; };
|
||||
total += r;
|
||||
};
|
||||
case let b: bool => {
|
||||
let s: str = "false";
|
||||
if (b) { s = "true"; };
|
||||
let r: i64 = rawwrite(fd, s.ptr, s.len: u64);
|
||||
let r: i64 = os.write(fd, s.ptr, s.len: u64);
|
||||
if (r < 0) { return r; };
|
||||
total += r;
|
||||
};
|
||||
case let r: rune => {
|
||||
let buf: [4]u8;
|
||||
buf[0] = r: u8;
|
||||
let n: i64 = rawwrite(fd, &buf[0], 1u64);
|
||||
let n: i64 = os.write(fd, &buf[0], 1u64);
|
||||
if (n < 0) { return n; };
|
||||
total += n;
|
||||
};
|
||||
@@ -142,7 +122,7 @@ export fn fdprint(fd: i32, args: formattable...) i64 = {
|
||||
export fn fdprintln(fd: i32, args: formattable...) i64 = {
|
||||
let n: i64 = fdprint(fd, args...);
|
||||
if (n < 0) { return n; };
|
||||
let m: i64 = rawwrite(fd, "\n".ptr, 1u64);
|
||||
let m: i64 = os.write(fd, "\n".ptr, 1u64);
|
||||
if (m < 0) { return m; };
|
||||
return n + m;
|
||||
};
|
||||
@@ -267,5 +247,5 @@ export fn errorln(args: formattable...) i64 = {
|
||||
// follows immediately).
|
||||
export fn fatal(args: formattable...) never = {
|
||||
fdprintln(2, args...);
|
||||
rawexit(255);
|
||||
os.exit(255);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user