~sircmpwn/hare

3566d29c197908319a71f8b9c3148945c792664f — Eyal Sawady 7 months ago d4b4305
Fix further oversights in error handling

Signed-off-by: Eyal Sawady <ecs@d2evs.net>
M bufio/buffered.ha => bufio/buffered.ha +2 -2
@@ 130,7 130,7 @@ export fn unreadrune(s: *io::stream, rn: rune) void = {
fn buffered_close(s: *io::stream) void = {
	assert(s.closer == &buffered_close);
	if (s.writer != null) {
		flush(s);
		flush(s)!;
	};
	free(s);
};


@@ 138,7 138,7 @@ fn buffered_close(s: *io::stream) void = {
fn buffered_close_static(s: *io::stream) void = {
	assert(s.closer == &buffered_close_static);
	if (s.writer != null) {
		flush(s);
		flush(s)!;
	};
	free(s);
};

M cmd/hare/plan.ha => cmd/hare/plan.ha +2 -2
@@ 165,9 165,9 @@ fn execute(
) (void | exec::error | exec::exit_status!) = {
	if (verbose) {
		for (let i = 0z; i < len(task.cmd); i += 1) {
			fmt::errorf("{} ", task.cmd[i]);
			fmt::errorf("{} ", task.cmd[i])!;
		};
		fmt::errorln();
		fmt::errorln()!;
	};

	let cmd = exec::cmd(task.cmd[0], task.cmd[1..]...)?;

M cmd/harec/errors.ha => cmd/harec/errors.ha +1 -1
@@ 10,7 10,7 @@ use strings;
fn printerr(err: parse::error) void = {
	match (err) {
		err: lex::syntax => printerr_syntax(err),
		err: io::error => fmt::errorln(io::strerror(err)),
		err: io::error => fmt::errorln(io::strerror(err))!,
	};
};


M cmd/harec/main.ha => cmd/harec/main.ha +1 -1
@@ 59,6 59,6 @@ export fn main() void = {
		};
		defer ast::subunit_free(su);

		unparse::subunit(os::stdout, su);
		unparse::subunit(os::stdout, su)!;
	};
};

M cmd/haredoc/docstr.ha => cmd/haredoc/docstr.ha +1 -1
@@ 122,7 122,7 @@ fn scanref(par: *parser) (token | void) = {
				bufio::scanrune(par.src) as rune; // ]
				break;
			},
			* => strio::appendrune(buf, rn),
			* => strio::appendrune(buf, rn)!,
		},
		* => abort(),
	};

M crypto/md5/+test.ha => crypto/md5/+test.ha +1 -1
@@ 30,7 30,7 @@ use io;
		let hex = strio::dynamic();
		defer io::close(hex);
		for (let j = 0z; j < SIZE; j += 1) {
			fmt::fprintf(hex, "{:02x}", sum[j]);
			fmt::fprintf(hex, "{:02x}", sum[j])!;
		};
		if (strio::string(hex) != vector.1) {
			fmt::errorfln("Vector {}: {} != {}",

M crypto/sha1/+test.ha => crypto/sha1/+test.ha +1 -1
@@ 34,7 34,7 @@ use io;
		let hex = strio::dynamic();
		defer io::close(hex);
		for (let j = 0z; j < SIZE; j += 1) {
			fmt::fprintf(hex, "{:02x}", sum[j]);
			fmt::fprintf(hex, "{:02x}", sum[j])!;
		};
		if (strio::string(hex) != vector.1) {
			fmt::errorfln("Vector {}: {} != {}",

M crypto/sha256/+test.ha => crypto/sha256/+test.ha +1 -1
@@ 31,7 31,7 @@ use strio;
		let hex = strio::dynamic();
		defer io::close(hex);
		for (let i = 0z; i < SIZE; i += 1) {
			fmt::fprintf(hex, "{:02x}", sum[i]);
			fmt::fprintf(hex, "{:02x}", sum[i])!;
		};

		if (strio::string(hex) != vector.1) {

M crypto/sha512/+test.ha => crypto/sha512/+test.ha +1 -1
@@ 66,7 66,7 @@ use io;
		defer io::close(hex);

		for (let j = 0z; j < len(sum); j += 1)
			fmt::fprintf(hex, "{:02x}", sum[j]);
			fmt::fprintf(hex, "{:02x}", sum[j])!;

		if (strio::string(hex) != vector.1) {
			fmt::errorfln("Vector {}: {} != {}",

M fmt/fmt.ha => fmt/fmt.ha +2 -2
@@ 221,7 221,7 @@ fn format(out: *io::stream, arg: formattable, mod: *modifiers) (size | io::error
	};

	if (mod.padding == padding::ALIGN_LEFT) {
		format_raw(out, arg, mod);
		format_raw(out, arg, mod)?;
	};

	for (z < mod.width: size) {


@@ 229,7 229,7 @@ fn format(out: *io::stream, arg: formattable, mod: *modifiers) (size | io::error
	};

	if (mod.padding != padding::ALIGN_LEFT) {
		format_raw(out, arg, mod);
		format_raw(out, arg, mod)?;
	};

	return z;

M format/xml/parser.ha => format/xml/parser.ha +3 -3
@@ 143,7 143,7 @@ fn scan_attr(par: *parser) (token | error) = {
				* => rn,
			};
			if (rn == quot) break;
			strio::appendrune(par.textbuf, rn);
			strio::appendrune(par.textbuf, rn)?;
		},
	};
	return (name, strio::string(par.textbuf)): attribute;


@@ 231,7 231,7 @@ fn scan_content(par: *parser) (text | error) = {
					scan_entity(par)?;
				},
			};
			strio::appendrune(par.textbuf, rn);
			strio::appendrune(par.textbuf, rn)?;
		},
	};
	return strio::string(par.textbuf);


@@ 289,7 289,7 @@ fn scan_charref(par: *parser) (rune | error) = {
			rn: rune => rn,
		};
		if (ascii::isdigit(rn)) {
			strio::appendrune(par.entbuf, rn);
			strio::appendrune(par.entbuf, rn)?;
		} else if (rn == ';') {
			break;
		} else {

M fs/mem/+test.ha => fs/mem/+test.ha +1 -1
@@ 138,7 138,7 @@ use strconv;
	assert(count == limit);

	for (let i = 0z; i < limit; i += 1) {
		fs::remove(memfs, strconv::ztos(i));
		fs::remove(memfs, strconv::ztos(i))!;
	};
	let ino = memfs: *inode;
	let dir = ino.data as directory;

M fs/mem/mem.ha => fs/mem/mem.ha +1 -3
@@ 249,9 249,7 @@ fn remove(fs: *fs::fs, path: str) (void | fs::error) = {

fn close(fs: *fs::fs) void = {
	let ino = fs: *inode;
	if (!(ino.data is directory)) {
		return fs::wrongtype;
	};
	assert(ino.data is directory);
	ino.opencount -= 1;
	close_rec(ino);
};

M fs/mem/stream.ha => fs/mem/stream.ha +2 -2
@@ 44,7 44,7 @@ fn stream_open(
		ino.opencount = types::SIZE_MAX;
		s.source = bufio::dynamic_from(f, mode);
		if (!appnd) {
			bufio::truncate(s.source);
			bufio::truncate(s.source)?;
		};
	};
	io::seek(s.source, 0, io::whence::SET)?;


@@ 58,7 58,7 @@ fn read(s: *io::stream, buf: []u8) (size | io::EOF | io::error) = {
fn write(s: *io::stream, buf: const []u8) (size | io::error) = {
	let s = s: *stream;
	if (s.appnd) {
		io::seek(s.source, 0, io::whence::END);
		io::seek(s.source, 0, io::whence::END)?;
	};
	let sz = io::write(s.source, buf)?;
	s.inode.data = bufio::buffer(s.source);

M getopt/getopts.ha => getopt/getopts.ha +1 -1
@@ 219,7 219,7 @@ export fn printusage(s: *io::stream, name: str, help: []help) void = {
// Prints command help to the provided stream.
export fn printhelp(s: *io::stream, name: str, help: []help) void = {
	if (help[0] is cmd_help) {
		fmt::fprintfln(s, "{}: {}\n", name, help[0] as cmd_help: str);
		fmt::fprintfln(s, "{}: {}\n", name, help[0] as cmd_help: str)!;
	};

	printusage(s, name, help);

M hare/lex/lex.ha => hare/lex/lex.ha +2 -2
@@ 185,7 185,7 @@ fn lex_string(lex: *lexer, loc: location) (token | error) = {
			else {
				unget(lex, r);
				r = lex_rune(lex, loc)?;
				strio::appendrune(buf, r);
				strio::appendrune(buf, r)?;
			},
	};
	match (nextw(lex)?) {


@@ 244,7 244,7 @@ fn lex_name(lex: *lexer, loc: location, keyword: bool) (token | error) = {
				unget(lex, r);
				break;
			};
			strio::appendrune(buf, r);
			strio::appendrune(buf, r)?;
		},
	};


M hare/module/manifest.ha => hare/module/manifest.ha +1 -1
@@ 256,7 256,7 @@ export fn manifest_write(ctx: *context, manifest: *manifest) (void | error) = {
		assert(input.stat.mask & want == want);
		fmt::fprintfln(fd, "input {} {} {} {}",
			hash, input.path, input.stat.inode,
			time::unix(input.stat.mtime));
			time::unix(input.stat.mtime))?;
	};

	for (let i = 0z; i < len(manifest.versions); i += 1) {

M hare/module/scan.ha => hare/module/scan.ha +1 -1
@@ 353,7 353,7 @@ export fn parsetags(in: str) ([]tag | void) = {
			_: void => break,
			r: rune => {
				if (ascii::isalnum(r) || r == '_') {
					strio::appendrune(buf, r);
					strio::appendrune(buf, r)!;
				} else {
					strings::push(&iter, r);
					break;

M hare/unparse/expr.ha => hare/unparse/expr.ha +1 -1
@@ 377,7 377,7 @@ fn struct_constant(
	};
	if (sc.autofill) {
		newline(out, indent)?;
		fmt::fprint(out, "...");
		fmt::fprint(out, "...")?;
	};
	indent -= 1;
	newline(out, indent)?;

M net/+linux/socket.ha => net/+linux/socket.ha +4 -4
@@ 13,7 13,7 @@ fn connect_fd(
	const sockfd = mksockfd(addr)?;
	for (let i = 0z; i < len(options); i += 1) {
		// The only option is keepalive right now
		setsockopt(sockfd, rt::SO_KEEPALIVE, true);
		setsockopt(sockfd, rt::SO_KEEPALIVE, true)?;
	};
	wrap(rt::connect(sockfd, &addr, sockasz(addr)))?;
	return sockfd;


@@ 63,9 63,9 @@ fn listen_fd(

	for (let i = 0z; i < len(options); i += 1) {
		match (options[i]) {
			_: reuseaddr => setsockopt(sockfd, rt::SO_REUSEADDR, true),
			_: reuseport => setsockopt(sockfd, rt::SO_REUSEPORT, true),
			_: keepalive => setsockopt(sockfd, rt::SO_KEEPALIVE, true),
			_: reuseaddr => setsockopt(sockfd, rt::SO_REUSEADDR, true)?,
			_: reuseport => setsockopt(sockfd, rt::SO_REUSEPORT, true)?,
			_: keepalive => setsockopt(sockfd, rt::SO_KEEPALIVE, true)?,
			b: backlog => bk = b,
			p: portassignment => portout = p,
		};

M os/exec/exec+linux.ha => os/exec/exec+linux.ha +1 -1
@@ 25,7 25,7 @@ fn open(path: str) (platform_cmd | errors::opaque) = {
	};
};

fn platform_finish(cmd: *command) void = rt::close(cmd.platform);
fn platform_finish(cmd: *command) void = rt::close(cmd.platform)!;

fn platform_exec(cmd: *command) errors::opaque = {
	// We don't worry about freeing the return values from strings::to_c

M rt/+linux/segmalloc.ha => rt/+linux/segmalloc.ha +2 -2
@@ 20,7 20,7 @@ fn segfree(p: *void, s: size) void = {
};

// Marks a segment as writable and drops the execute bit.
fn segwrite(seg: *void, n: size) void = mprotect(seg, n, PROT_READ | PROT_WRITE);
fn segwrite(seg: *void, n: size) void = mprotect(seg, n, PROT_READ | PROT_WRITE)!;

// Marks a segment as executable and drops the write bit.
fn segexec(seg: *void, n: size) void = mprotect(seg, n, PROT_READ | PROT_EXEC);
fn segexec(seg: *void, n: size) void = mprotect(seg, n, PROT_READ | PROT_EXEC)!;

M rt/+test/run.ha => rt/+test/run.ha +1 -1
@@ 85,7 85,7 @@ export fn tests_main() size = {
	return nfail;
};

fn print(msg: str) void = write(1, *(&msg: **void): *const char, len(msg));
fn print(msg: str) void = write(1, *(&msg: **void): *const char, len(msg))!;

fn dots(n: size) void = {
	// XXX: this is slow, I guess