~sircmpwn/hare-compress

da3635062048105ef29a0f6a5f0307c3f7c98268 — Alexey Yerin 9 months ago db4312a
Fix compilation with latest harec and stdlib
3 files changed, 37 insertions(+), 11 deletions(-)

M compress/flate/inflate.ha
M compress/zlib/+test.ha
M compress/zlib/reader.ha
M compress/flate/inflate.ha => compress/flate/inflate.ha +7 -7
@@ 3,12 3,12 @@
// (c) 2021 Bor Grošelj Simić <bor.groseljsimic@telemach.net>
// (c) 2021 Drew DeVault <sir@cmpwn.com>
// (c) 2021 Ember Sawady <ecs@d2evs.net>
use bufio;
use bytes;
use endian;
use errors;
use fmt;
use io;
use memio;

def BUFSIZE: size = 1 << 16;
def MAXBITS: size = 15;


@@ 277,9 277,9 @@ fn opaque_strerror(
	};
};

fn wraperror(err: inflate_err) errors::opaque = {
fn wraperror(err: inflate_err) errors::opaque_ = {
	static assert(size(inflate_err) <= size(errors::opaque_data));
	let wrapped = errors::opaque { strerror = &opaque_strerror, ... };
	let wrapped = errors::opaque_ { strerror = &opaque_strerror, ... };
	let myptr = &wrapped.data: *inflate_err;
	*myptr = err;
	return wrapped;


@@ 290,7 290,7 @@ fn wraperror(err: inflate_err) errors::opaque = {
// error.
export fn inflate_error(err: io::error) (inflate_err | io::error) = {
	match (err) {
	case let op: errors::opaque =>
	case let op: errors::opaque_ =>
		if (op.strerror != &opaque_strerror) {
			return err;
		};


@@ 456,8 456,8 @@ fn close(s: *io::stream) (void | io::error) = {
	];
	let expected: []u8 = [0xDE, 0xAD, 0xBE, 0xEF, 0x42, 0x69];

	let ins = bufio::fixed(in, io::mode::READ);
	let outs = bufio::dynamic(io::mode::WRITE);
	let ins = memio::fixed(in);
	let outs = memio::dynamic();
	let s = inflate(&ins);
	defer io::close(&s)!;
	match (io::copy(&outs, &s)) {


@@ 466,7 466,7 @@ fn close(s: *io::stream) (void | io::error) = {
		fmt::errorln(io::strerror(e))!;
		abort();
	};
	let out = bufio::buffer(&outs);
	let out = memio::buffer(&outs);
	defer free(out);
	assert(bytes::equal(expected, out));
};

M compress/zlib/+test.ha => compress/zlib/+test.ha +26 -0
@@ 1,5 1,31 @@
// License: MPL-2.0
// (c) 2021 Ember Sawady <ecs@d2evs.net>
use bytes;
use fmt;
use io;
use memio;

@test fn decompress() void = {
	for (let i = 1z; i < len(vectors); i += 1) {
		let in = memio::fixed(*vectors[i].1);
		let out = memio::dynamic();
		let d = match (decompress(&in)) {
		case let s: reader =>
			yield s;
		case let e: io::error =>
			fmt::errorln(io::strerror(e))!;
			abort();
		};
		match (io::copy(&out, &d)) {
		case size => void;
		case let e: io::error =>
			fmt::errorfln("vector {}: {}", i, io::strerror(e))!;
			abort();
		};
		let s = memio::buffer(&out);
		assert(bytes::equal(s, *vectors[i].0));
	};
};

@test fn decompress() void = {
	for (let i = 1z; i < len(vectors); i += 1) {

M compress/zlib/reader.ha => compress/zlib/reader.ha +4 -4
@@ 57,9 57,9 @@ fn opaque_strerror(
	};
};

fn wraperror(err: decompress_err) errors::opaque = {
fn wraperror(err: decompress_err) errors::opaque_ = {
	static assert(size(decompress_err) <= size(errors::opaque_data));
	let wrapped = errors::opaque { strerror = &opaque_strerror, ... };
	let wrapped = errors::opaque_ { strerror = &opaque_strerror, ... };
	let myptr = &wrapped.data: *decompress_err;
	*myptr = err;
	return wrapped;


@@ 73,7 73,7 @@ export fn decompress_error(
	err: io::error,
) (decompress_err | flate::inflate_err | io::error) = {
	match (err) {
	case let op: errors::opaque =>
	case let op: errors::opaque_ =>
		if (op.strerror != &opaque_strerror) {
			return flate::inflate_error(err);
		};


@@ 85,7 85,7 @@ export fn decompress_error(
};

fn verifysum(s: *reader) (io::EOF | io::error) = {
	let hash: [adler32::SIZE]u8 = [0...];
	let hash: [adler32::SZ]u8 = [0...];

	for (let n = 0z; n < len(hash)) {
		match (io::read(s.source, hash[n..])?) {