Removing bio.status. Ripping off this bandaid might hurt a bit.
[Thread Prev] | [Thread Next]
[Date Prev] | [Date Next]
- Subject: Removing bio.status. Ripping off this bandaid might hurt a bit.
- From: Ori Bernstein <ori@xxxxxxxxxxxxxx>
- Reply-to: myrddin-dev@xxxxxxxxxxxxxx
- Date: Sat, 30 Sep 2017 22:47:03 -0700
- To: myrddin-dev@xxxxxxxxxxxxxx
When the language was yong, I wrote libbio. The API isn't too awful (IMO), but one wart it's always had is that it uses its own status instead of std.result. The attached patch fixes it, replacing bio.status with std.result, and turning EOF into an "error": match bio.read(f, buf) | `std.Ok b: process(b) | `std.Err `bio.Eof: break | `std.Err e: std.fatal("error reading {}: {}\n", path, e) ;; In some ways it's a bit clunkier than just having an EOF state, but I think it's better to have consistent types. I'm going to give people a bit of time to object before I land this, since it's probably going to break a lot. If you want help porting, ping me on IRC or by mail, and I'll send over a patch to fix your code. (Same goes for Lucas's upcoming hashing patch). Also, unrelatedly, I realized that a short while ago there was a bit of mailing list misconfiguration that lead to some spamming of "everything is fine" messages. Sorry about that. -- Ori Bernstein
From 8672ce0c95bf5d6e6b721694bd0e5944d4af556b Mon Sep 17 00:00:00 2001 From: Ori Bernstein <ori@xxxxxxxxxxxxxx> Date: Sat, 30 Sep 2017 22:18:21 -0700 Subject: [PATCH] Replace bio.status(@t) with std.result(@t, bio.err) It's more consistent. --- lib/bio/bio.myr | 187 +++++++++++++++++++----------------------- lib/bio/geti.myr | 36 ++++---- lib/bio/iter.myr | 10 +-- lib/bio/puti.myr | 28 +++---- lib/bio/test/bio-delim.myr | 12 +-- lib/bio/test/bio-endianrd.myr | 29 +++---- lib/bio/test/bio-peek.myr | 12 +-- lib/bio/test/bio-read.myr | 6 +- lib/bio/test/mem.myr | 6 +- lib/http/client.myr | 17 ++-- lib/http/parse.myr | 29 +++---- lib/http/session.myr | 10 +-- lib/inifile/parse.myr | 6 +- lib/inifile/write.myr | 2 +- lib/regex/redump.myr | 6 +- mbld/libs.myr | 27 +++--- mbld/subtest.myr | 8 +- support/dumpleak.myr | 12 +-- 18 files changed, 198 insertions(+), 245 deletions(-) diff --git a/lib/bio/bio.myr b/lib/bio/bio.myr index 0a611f36..437cde64 100644 --- a/lib/bio/bio.myr +++ b/lib/bio/bio.myr @@ -33,17 +33,10 @@ pkg bio = close : (-> bool) ;; - type status(@a) = union + type err = union `Eof - `Ok @a - `Err ioerr - ;; - - type ioerr = union - `Ebadfile - `Ebadbuf - `Ebadfd - `Eioerr + `Eio + `Ebadf ;; /* creation */ @@ -56,36 +49,36 @@ pkg bio = const free : (f : file# -> void) /* basic i/o. Returns sub-buffer when applicable. */ - const write : (f : file#, src : byte[:] -> status(std.size)) - const read : (f : file#, dst : byte[:] -> status(byte[:])) + const write : (f : file#, src : byte[:] -> std.result(std.size, err)) + const read : (f : file#, dst : byte[:] -> std.result(byte[:], err)) const flush : (f : file# -> bool) /* seeking */ - const seek : (f : file#, off : std.off -> std.result(std.off, ioerr)) + const seek : (f : file#, off : std.off -> std.result(std.off, err)) /* single unit operations */ - const putb : (f : file#, b : byte -> status(std.size)) - const putc : (f : file#, c : char -> status(std.size)) - const getb : (f : file# -> status(byte)) - const getc : (f : file# -> status(char)) + const putb : (f : file#, b : byte -> std.result(std.size, err)) + const putc : (f : file#, c : char -> std.result(std.size, err)) + const getb : (f : file# -> std.result(byte, err)) + const getc : (f : file# -> std.result(char, err)) /* peeking */ - const peekb : (f : file# -> status(byte)) - const peekc : (f : file# -> status(char)) + const peekb : (f : file# -> std.result(byte, err)) + const peekc : (f : file# -> std.result(char, err)) /* delimited read; returns freshly allocated buffer. */ - const readln : (f : file# -> status(byte[:])) - const readto : (f : file#, delim : byte[:] -> status(byte[:])) + const readln : (f : file# -> std.result(byte[:], err)) + const readto : (f : file#, delim : byte[:] -> std.result(byte[:], err)) const skipto : (f : file#, delim : byte[:] -> bool) const skipspace : (f : file# -> bool) /* formatted i/o */ - const put : (f : file#, fmt : byte[:], args : ... -> status(std.size)) - const putv : (f : file#, fmt : byte[:], ap : std.valist# -> status(std.size)) + const put : (f : file#, fmt : byte[:], args : ... -> std.result(std.size, err)) + const putv : (f : file#, fmt : byte[:], ap : std.valist# -> std.result(std.size, err)) /* pkg funcs */ - pkglocal const ensureread : (f : file#, n : std.size -> status(std.size)) - pkglocal const ensurewrite : (f : file#, n : std.size -> status(std.size)) + pkglocal const ensureread : (f : file#, n : std.size -> std.result(std.size, err)) + pkglocal const ensurewrite : (f : file#, n : std.size -> std.result(std.size, err)) ;; const Bufsz = 16*std.KiB @@ -208,7 +201,7 @@ const write = {f, src if src.len <= (f.wbuf.len - f.wend) std.slcp(f.wbuf[f.wend:f.wend+src.len], src) f.wend += src.len - -> `Ok src.len + -> `std.Ok src.len else flush(f) -> writebuf(f, src) @@ -225,7 +218,7 @@ const read = {f, dst /* Clear the error state so we can retry */ if f.lasterr != 0 - -> `Err geterr(f) + -> `std.Err geterr(f) ;; /* @@ -235,7 +228,7 @@ const read = {f, dst an EOF condition. */ if dst.len == 0 - -> `Ok dst + -> `std.Ok dst ;; std.assert(f.mode & Rd != 0, "File is not in read mode") /* @@ -268,7 +261,7 @@ const read = {f, dst d = d[n:] | `std.Err err: if count == 0 - -> `Err errtype(err) + -> `std.Err errtype(err) else f.lasterr = err ;; @@ -276,9 +269,9 @@ const read = {f, dst ;; ;; if count == 0 - -> `Eof + -> `std.Err `Eof else - -> `Ok dst[:count] + -> `std.Ok dst[:count] ;; } @@ -289,7 +282,7 @@ const flush = {f ret = true if f.mode & Wr != 0 match writebuf(f, f.wbuf[:f.wend]) - | `Ok n: ret = (n == f.wend) + | `std.Ok n: ret = (n == f.wend) | _: ret = false ;; ;; @@ -309,11 +302,10 @@ const seek = {f, off /* writes a single byte to the output stream */ const putb = {f, b match ensurewrite(f, 1) - | `Eof: -> `Eof - | `Err e: -> `Err e - | `Ok n: + | `std.Err e: -> `std.Err e + | `std.Ok n: f.wbuf[f.wend++] = b - -> `Ok 1 + -> `std.Ok 1 ;; } @@ -323,22 +315,20 @@ const putc = {f, c sz = std.charlen(c) match ensurewrite(f, sz) - | `Eof: -> `Eof - | `Err e: -> `Err e - | `Ok n: + | `std.Err e: -> `std.Err e + | `std.Ok n: std.encode(f.wbuf[f.wend:], c) f.wend += sz - -> `Ok sz + -> `std.Ok sz ;; } /* reads a single byte from the input stream */ const getb = {f match ensureread(f, 1) - | `Eof: -> `Eof - | `Err e: -> `Err e - | `Ok n: - -> `Ok f.rbuf[f.rstart++] + | `std.Err e: -> `std.Err e + | `std.Ok n: + -> `std.Ok f.rbuf[f.rstart++] ;; } @@ -347,12 +337,11 @@ const getc = {f var c match ensurecodepoint(f) - | `Eof: -> `Eof - | `Err e: -> `Err e - | `Ok n: + | `std.Err e: -> `std.Err e + | `std.Ok n: c = std.decode(f.rbuf[f.rstart:f.rend]) f.rstart += std.charlen(c) - -> `Ok c + -> `std.Ok c ;; } @@ -362,9 +351,8 @@ const ensurecodepoint = {f var len match ensureread(f, 1) - | `Eof: -> `Eof - | `Err e: -> `Err e - | `Ok n: + | `std.Err e: -> `std.Err e + | `std.Ok n: b = f.rbuf[f.rstart] if b & 0x80 == 0 /* 0b0xxx_xxxx */ len = 1 @@ -408,20 +396,18 @@ generic putbe = {f, v : @a::(numeric,integral) /* peeks a single byte from an input stream */ const peekb = {f match ensureread(f, 1) - | `Eof: -> `Eof - | `Err e: -> `Err e - | `Ok n: - -> `Ok f.rbuf[f.rstart] + | `std.Err e: -> `std.Err e + | `std.Ok n: + -> `std.Ok f.rbuf[f.rstart] ;; } /* peeks a single character from a utf8 encoded input stream */ const peekc = {f match ensurecodepoint(f) - | `Eof: -> `Eof - | `Err e: -> `Err e - | `Ok n: - -> `Ok std.decode(f.rbuf[f.rstart:f.rend]) + | `std.Err e: -> `std.Err e + | `std.Ok n: + -> `std.Ok std.decode(f.rbuf[f.rstart:f.rend]) ;; } @@ -441,23 +427,20 @@ const readto = {f, delim /* same as readto, but drops the read data. */ const skipto = {f, delim match readdelim(f, delim, true) - | `Ok ign: -> true - | `Eof: -> false - | `Err _: -> false + | `std.Ok ign: -> true + | `std.Err _: -> false ;; } const skipspace = {f while true match bio.peekc(f) - | `Ok c: + | `std.Ok c: if !std.isspace(c) break ;; bio.getc(f) - | `Err e: -> false - | `Eof: break - + | `std.Err e: -> false ;; ;; -> true @@ -471,15 +454,15 @@ const readln = {f while true /* get at least delimiter count of characters */ match ensureread(f, 1) - | `Ok _: - | `Err e: -> `Err e - | `Eof: + | `std.Err `Eof: ret = readinto(f, ret, f.rend - f.rstart) if ret.len > 0 - -> `Ok ret + -> `std.Ok ret else - -> `Eof + -> `std.Err `Eof ;; + | `std.Err e: -> `std.Err e + | `std.Ok _: ;; /* scan for delimiter */ for var i = f.rstart; i < f.rend; i++ @@ -491,7 +474,7 @@ const readln = {f if c == '\r' && unwrapc(peekc(f), -1) == '\n' f.rstart++ ;; - -> `Ok ret + -> `std.Ok ret ;; :nextitergetln ;; @@ -502,7 +485,7 @@ const readln = {f const unwrapc = {cc, v match cc - | `Ok c: -> c + | `std.Ok c: -> c | _: -> v ;; } @@ -514,17 +497,17 @@ const readdelim = {f, delim, drop while true /* get at least delimiter count of characters */ match ensureread(f, 1) - | `Ok _: - | `Err e: -> `Err e - | `Eof: + | `std.Err `Eof: if !drop ret = readinto(f, ret, f.rend - f.rstart) ;; if ret.len > 0 - -> `Ok ret + -> `std.Ok ret else - -> `Eof + -> `std.Err `Eof ;; + | `std.Err e: -> `std.Err e + | `std.Ok _: ;; for var i = f.rstart; i < f.rend; i++ if f.rbuf[i] == delim[0] @@ -537,7 +520,7 @@ const readdelim = {f, delim, drop ret = readinto(f, ret, i - f.rstart) ;; f.rstart += delim.len - -> `Ok ret + -> `std.Ok ret ;; :nextiterread ;; @@ -591,14 +574,13 @@ const ensurewrite = {f, n std.assert(n < f.wbuf.len, "ensured write capacity > buffer size") if n > f.wbuf.len - f.wend match writebuf(f, f.wbuf[:f.wend]) - | `Ok len: + | `std.Ok len: f.wend = 0 - -> `Ok len - | `Err e: -> `Err e - | `Eof: -> `Eof + -> `std.Ok len + | `std.Err e: -> `std.Err e ;; ;; - -> `Ok n + -> `std.Ok n } /* @@ -612,17 +594,16 @@ const ensureread = {f, n held = f.rend - f.rstart if n > held match fill(f, n) - | `Eof: -> `Eof - | `Err e: -> `Err e - | `Ok len: + | `std.Err e: -> `std.Err e + | `std.Ok len: if len >= n - -> `Ok len + -> `std.Ok len else - -> `Eof + -> `std.Err `Eof ;; ;; else - -> `Ok n + -> `std.Ok n ;; } @@ -634,16 +615,16 @@ const writebuf = {f, src while src.len != 0 match f.write(src) | `std.Ok 0: - -> `Eof + -> `std.Err `Eof | `std.Ok n: count += n src = src[n:] | `std.Err e: - -> `Err errtype(e) + -> `std.Err errtype(e) ;; ;; :writedone - -> `Ok count + -> `std.Ok count } @@ -658,7 +639,7 @@ const fill = {f, min count = 0 /* Clear the error state so we can retry */ if f.lasterr != 0 - -> `Err geterr(f) + -> `std.Err geterr(f) ;; /* if we need to shift the slice down to the start, do it */ @@ -684,16 +665,16 @@ const fill = {f, min if count > 0 f.lasterr = e else - -> `Err errtype(e) + -> `std.Err errtype(e) ;; break ;; ;; if count == 0 - -> `Eof + -> `std.Err `Eof else - -> `Ok count + -> `std.Ok count ;; } @@ -705,20 +686,18 @@ const geterr = {f -> errtype(e) } -const errtype = {e : std.errno -> ioerr +const errtype = {e : std.errno -> err var errno errno = (e : std.errno) if errno == std.Ebadf - -> `Ebadfile + -> `Ebadf elif errno == std.Einval - -> `Ebadfile + -> `Ebadf elif errno == std.Efault - -> `Ebadbuf - elif errno == std.Eio - -> `Eioerr + -> `Eio else - -> `Eioerr + -> `Eio ;; } diff --git a/lib/bio/geti.myr b/lib/bio/geti.myr index 70186b2a..3b6eb3e1 100644 --- a/lib/bio/geti.myr +++ b/lib/bio/geti.myr @@ -4,34 +4,34 @@ use "bio" pkg bio = /* unsigned big endian */ - generic getbe8 : (f : file# -> status(@a::(numeric,integral))) - generic getbe16 : (f : file# -> status(@a::(numeric,integral))) - generic getbe32 : (f : file# -> status(@a::(numeric,integral))) - generic getbe64 : (f : file# -> status(@a::(numeric,integral))) + generic getbe8 : (f : file# -> std.result(@a::(numeric,integral), err)) + generic getbe16 : (f : file# -> std.result(@a::(numeric,integral), err)) + generic getbe32 : (f : file# -> std.result(@a::(numeric,integral), err)) + generic getbe64 : (f : file# -> std.result(@a::(numeric,integral), err)) /* signed big endian */ - generic getle8 : (f : file# -> status(@a::(numeric,integral))) - generic getle16 : (f : file# -> status(@a::(numeric,integral))) - generic getle32 : (f : file# -> status(@a::(numeric,integral))) - generic getle64 : (f : file# -> status(@a::(numeric,integral))) + generic getle8 : (f : file# -> std.result(@a::(numeric,integral), err)) + generic getle16 : (f : file# -> std.result(@a::(numeric,integral), err)) + generic getle32 : (f : file# -> std.result(@a::(numeric,integral), err)) + generic getle64 : (f : file# -> std.result(@a::(numeric,integral), err)) ;; /* reads a single integer-like value to the output stream, in little endian format */ -generic getle = {f, n -> status(@a::(numeric,integral)) +generic getle = {f, n -> std.result(@a::(numeric,integral), err) var v, i v = 0 match ensureread(f, n) - | `Eof: -> `Eof - | `Err e : -> `Err e - | `Ok _: + | `std.Err e: + -> `std.Err e + | `std.Ok _: for i = 0; i < n; i++ v |= (f.rbuf[f.rstart++] : uint64) << (8*(i : uint64)) ;; - -> `Ok (v : @a::(numeric,integral)) + -> `std.Ok (v : @a::(numeric,integral)) ;; } @@ -39,19 +39,19 @@ generic getle = {f, n -> status(@a::(numeric,integral)) reads a single integer-like value to the output stream, in big endian format */ -generic getbe = {f, n -> status(@a::(numeric,integral)) +generic getbe = {f, n -> std.result(@a::(numeric,integral), err) var v, i v = 0 match ensureread(f, n) - | `Eof: -> `Eof - | `Err e : -> `Err e - | `Ok _: + | `std.Err e: + -> `std.Err e + | `std.Ok _: for i = 0; i < n; i++ v <<= 8 v |= (f.rbuf[f.rstart++] : uint64) ;; - -> `Ok (v : @a::(numeric,integral)) + -> `std.Ok (v : @a::(numeric,integral)) ;; } diff --git a/lib/bio/iter.myr b/lib/bio/iter.myr index dbdd025d..55379ed0 100644 --- a/lib/bio/iter.myr +++ b/lib/bio/iter.myr @@ -18,9 +18,8 @@ const byline = {f impl iterable lineiter -> byte[:] = __iternext__ = {itp, outp match bio.readln((itp# : file#)) - | `Ok ln: outp# = ln - | `Err _: -> false - | `Eof: -> false + | `std.Ok ln: outp# = ln + | `std.Err _: -> false ;; -> true } @@ -37,9 +36,8 @@ const bychar = {f impl iterable chariter -> char = __iternext__ = {itp, outp : char# match bio.getc((itp# : file#)) - | `Ok c: outp# = c - | `Err _: -> false - | `Eof: -> false + | `std.Ok c: outp# = c + | `std.Err _: -> false ;; -> true } diff --git a/lib/bio/puti.myr b/lib/bio/puti.myr index d4d7a3f2..056f6a4c 100644 --- a/lib/bio/puti.myr +++ b/lib/bio/puti.myr @@ -4,16 +4,16 @@ use "bio" pkg bio = /* unsigned big endian */ - generic putbe8 : (f : file#, v : @a::(numeric,integral) -> status(std.size)) - generic putbe16 : (f : file#, v : @a::(numeric,integral) -> status(std.size)) - generic putbe32 : (f : file#, v : @a::(numeric,integral) -> status(std.size)) - generic putbe64 : (f : file#, v : @a::(numeric,integral) -> status(std.size)) + generic putbe8 : (f : file#, v : @a::(numeric,integral) -> std.result(std.size, err)) + generic putbe16 : (f : file#, v : @a::(numeric,integral) -> std.result(std.size, err)) + generic putbe32 : (f : file#, v : @a::(numeric,integral) -> std.result(std.size, err)) + generic putbe64 : (f : file#, v : @a::(numeric,integral) -> std.result(std.size, err)) /* unsigned little endian */ - generic putle8 : (f : file#, v : @a::(numeric,integral) -> status(std.size)) - generic putle16 : (f : file#, v : @a::(numeric,integral) -> status(std.size)) - generic putle32 : (f : file#, v : @a::(numeric,integral) -> status(std.size)) - generic putle64 : (f : file#, v : @a::(numeric,integral) -> status(std.size)) + generic putle8 : (f : file#, v : @a::(numeric,integral) -> std.result(std.size, err)) + generic putle16 : (f : file#, v : @a::(numeric,integral) -> std.result(std.size, err)) + generic putle32 : (f : file#, v : @a::(numeric,integral) -> std.result(std.size, err)) + generic putle64 : (f : file#, v : @a::(numeric,integral) -> std.result(std.size, err)) ;; generic putbe8 = {f, v; -> putbe(f, (v : uint64), 1)} @@ -30,9 +30,9 @@ const putle = {f, v, n var buf : byte[8] match ensurewrite(f, n) - | `Eof: -> `Eof - | `Err e: -> `Err e - | `Ok _: + | `std.Err e: + -> `std.Err e + | `std.Ok _: buf[0] = ((v >> 0) & 0xff : byte) buf[1] = ((v >> 8) & 0xff : byte) buf[2] = ((v >> 16) & 0xff : byte) @@ -49,9 +49,9 @@ const putbe = {f, v, n var buf : byte[8] match ensurewrite(f, n) - | `Eof: -> `Eof - | `Err e: -> `Err e - | `Ok _: + | `std.Err e: + -> `std.Err e + | `std.Ok _: buf[0] = ((v >> 56) & 0xff : byte) buf[1] = ((v >> 48) & 0xff : byte) buf[2] = ((v >> 40) & 0xff : byte) diff --git a/lib/bio/test/bio-delim.myr b/lib/bio/test/bio-delim.myr index 354dc50a..dbc2f65e 100644 --- a/lib/bio/test/bio-delim.myr +++ b/lib/bio/test/bio-delim.myr @@ -67,11 +67,11 @@ const main = { const readln = {f match bio.readln(f) - | `bio.Ok d: -> d - | `bio.Eof: + | `std.Ok d: -> d + | `std.Err `bio.Eof: std.put("eof\n") -> [][:] - | `bio.Err e: + | `std.Err e: std.put("err\n") -> [][:] ;; @@ -79,11 +79,11 @@ const readln = {f const readto = {f, delim match bio.readto(f, delim) - | `bio.Ok d: -> d - | `bio.Eof: + | `std.Ok d: -> d + | `std.Err `bio.Eof: std.put("eof\n") -> [][:] - | `bio.Err e: + | `std.Err e: std.put("err\n") -> [][:] ;; diff --git a/lib/bio/test/bio-endianrd.myr b/lib/bio/test/bio-endianrd.myr index e4454593..8296c75b 100644 --- a/lib/bio/test/bio-endianrd.myr +++ b/lib/bio/test/bio-endianrd.myr @@ -1,13 +1,6 @@ use std use bio -generic try = {opt : bio.status(@a::(integral,numeric))-> @a::(integral,numeric) - match opt - | `bio.Ok val: -> val - | _: std.fatal("read failed") - ;; -} - const main = { var b : byte var w : uint16 @@ -23,31 +16,31 @@ const main = { /* byte */ b = 0xaa - var r = try(bio.getle8(f)) + var r = std.try(bio.getle8(f)) std.assert(r == b, "le byte broken: {x}\n", r) - std.assert(try(bio.getbe8(f)) == b, "be byte broken\n") + std.assert(std.try(bio.getbe8(f)) == b, "be byte broken\n") /* word */ w = 0xaabb - std.assert(try(bio.getle16(f)) == w, "le word broken\n") - std.assert(try(bio.getbe16(f)) == w, "be word broken\n") + std.assert(std.try(bio.getle16(f)) == w, "le word broken\n") + std.assert(std.try(bio.getbe16(f)) == w, "be word broken\n") /* long */ l = 0xaabbccdd - std.assert(try(bio.getle32(f)) == l, "le long broken\n") - std.assert(try(bio.getbe32(f)) == l, "be long broken\n") + std.assert(std.try(bio.getle32(f)) == l, "le long broken\n") + std.assert(std.try(bio.getbe32(f)) == l, "be long broken\n") /* quad */ q = (0x11223344aabbccdd : uint64) - std.assert(try(bio.getle64(f)) == q, "le quad broken\n") - std.assert(try(bio.getbe64(f)) == q, "be quad broken\n") + std.assert(std.try(bio.getle64(f)) == q, "le quad broken\n") + std.assert(std.try(bio.getbe64(f)) == q, "be quad broken\n") /* end of file */ match bio.getle64(f) - | `bio.Eof: - | `bio.Err _: + | `std.Err `bio.Eof: + | `std.Err _: std.die("error on reading file\n") - | `bio.Ok v: + | `std.Ok v: std.die("read past end of file\n") v = q /* shut up type inference */ ;; diff --git a/lib/bio/test/bio-peek.myr b/lib/bio/test/bio-peek.myr index 506dea0a..a0f47524 100644 --- a/lib/bio/test/bio-peek.myr +++ b/lib/bio/test/bio-peek.myr @@ -28,11 +28,11 @@ const main = { const peekc = {f match bio.peekc(f) - | `bio.Ok c: -> c - | `bio.Eof: + | `std.Ok c: -> c + | `std.Err `bio.Eof: std.put("eof\n") -> -1 - | `bio.Err e: + | `std.Err e: std.fatal("error reading\n") -> -1 ;; @@ -40,11 +40,11 @@ const peekc = {f const peekb = {f match bio.peekb(f) - | `bio.Ok b: -> b - | `bio.Eof: + | `std.Ok b: -> b + | `std.Err `bio.Eof: std.put("eof\n") -> -1 - | `bio.Err e: + | `std.Err e: std.fatal("error reading\n") -> -1 ;; diff --git a/lib/bio/test/bio-read.myr b/lib/bio/test/bio-read.myr index 829b4420..3e477c2c 100644 --- a/lib/bio/test/bio-read.myr +++ b/lib/bio/test/bio-read.myr @@ -40,12 +40,12 @@ const main = { const r = {f, buf match bio.read(f, buf) - | `bio.Ok b: + | `std.Ok b: -> b - | `bio.Eof: + | `std.Err `bio.Eof: std.put("eof\n") -> "" - | `bio.Err e: + | `std.Err e: std.put("err\n") -> "" ;; diff --git a/lib/bio/test/mem.myr b/lib/bio/test/mem.myr index f3135d26..a7cb6139 100644 --- a/lib/bio/test/mem.myr +++ b/lib/bio/test/mem.myr @@ -7,21 +7,21 @@ const main = { f = bio.mkmem("hello world") match bio.read(f, buf[:3]) - | `bio.Ok "hel": + | `std.Ok "hel": /* ok */ | _: std.fatal("invalid read from memfile") ;; match bio.read(f, buf[:]) - | `bio.Ok "lo world": + | `std.Ok "lo world": /* ok */ | _: std.fatal("invalid read from memfile") ;; match bio.read(f, buf[:]) - | `bio.Eof: + | `std.Err `bio.Eof: /* ok */ | _: std.fatal("expected eof in memfile") diff --git a/lib/http/client.myr b/lib/http/client.myr index 4fdf4814..770c233b 100644 --- a/lib/http/client.myr +++ b/lib/http/client.myr @@ -180,9 +180,8 @@ const readlenbody = {s, r buf = std.slalloc(r.len) match bio.read(s.f, buf) - | `bio.Err e: goto shortread - | `bio.Eof: goto shortread - | `bio.Ok rd: + | `std.Err e: goto shortread + | `std.Ok rd: if rd.len != r.len goto shortread ;; @@ -215,13 +214,10 @@ const readchunkedbody = {s, r | `std.Ok sz: std.slgrow(&buf, buf.len + sz) match bio.read(s.f, buf[len:len + sz]) - | `bio.Eof: - std.slfree(buf) - -> `std.Err `Eshort - | `bio.Err e: + | `std.Err e: std.slfree(buf) -> `std.Err `Econn - | `bio.Ok str: + | `std.Ok str: if str.len != sz std.slfree(buf) -> `std.Err `Eshort @@ -243,9 +239,8 @@ const checkendln = {s var r match bio.readln(s.f) - | `bio.Err e: r = `std.Err `Econn - | `bio.Eof: r = `std.Err `Econn - | `bio.Ok crlf: + | `std.Err e: r = `std.Err `Econn + | `std.Ok crlf: if std.strstrip(crlf).len == 0 r = `std.Ok void else diff --git a/lib/http/parse.myr b/lib/http/parse.myr index d9f8b343..fabf7a23 100644 --- a/lib/http/parse.myr +++ b/lib/http/parse.myr @@ -23,13 +23,10 @@ const parsereq = {s ]) match bio.readln(s.f) - | `bio.Err e: - err = `Econn - goto error - | `bio.Eof: + | `std.Err e: err = `Econn goto error - | `bio.Ok ln: + | `std.Ok ln: match parsereqstatus(s, r, ln) | `std.Ok void: | `std.Err e: @@ -42,13 +39,10 @@ const parsereq = {s while true match bio.readln(s.f) - | `bio.Err e: - err = `Econn - goto error - | `bio.Eof: + | `std.Err e: err = `Econn goto error - | `bio.Ok ln: + | `std.Ok ln: if std.strstrip(ln).len == 0 std.slfree(ln) break @@ -70,9 +64,8 @@ const parsereq = {s const parseresp = {s, r : resp# match bio.readln(s.f) - | `bio.Err e: r.err = `std.Some `Econn - | `bio.Eof: r.err = `std.Some `Econn - | `bio.Ok ln: + | `std.Err _: r.err = `std.Some `Econn + | `std.Ok ln: if !parserespstatus(s, r, ln) std.slfree(ln) -> false @@ -82,9 +75,8 @@ const parseresp = {s, r : resp# while true match bio.readln(s.f) - | `bio.Err e: r.err = `std.Some `Econn - | `bio.Eof: r.err = `std.Some `Econn - | `bio.Ok ln: + | `std.Err e: r.err = `std.Some `Econn + | `std.Ok ln: if std.strstrip(ln).len == 0 std.slfree(ln) break @@ -203,9 +195,8 @@ const parsechunksz = {s var ret, str match bio.readln(s.f) - | `bio.Eof: ret = `std.Err `Econn - | `bio.Err e: ret = `std.Err `Econn - | `bio.Ok ln: + | `std.Err e: ret = `std.Err `Econn + | `std.Ok ln: str = ln match parsenumber(&str, 16) | `std.Some n: ret = `std.Ok (n : std.size) diff --git a/lib/http/session.myr b/lib/http/session.myr index 2b6f65a2..40911651 100644 --- a/lib/http/session.myr +++ b/lib/http/session.myr @@ -58,9 +58,8 @@ const ioput = {s, fmt, args ;; ap = std.vastart(&args) match bio.putv(s.f, fmt, &ap) - | `bio.Ok _: /* nothing */ - | `bio.Err _: s.err = true - | `bio.Eof: s.err = true + | `std.Ok _: /* nothing */ + | `std.Err _: s.err = true ;; -> s.err } @@ -70,9 +69,8 @@ const iowrite = {s, buf -> false ;; match bio.write(s.f, buf) - | `bio.Ok _: /* nothing */ - | `bio.Err _: s.err = true - | `bio.Eof: s.err = true + | `std.Ok _: /* nothing */ + | `std.Err _: s.err = true ;; -> s.err } diff --git a/lib/inifile/parse.myr b/lib/inifile/parse.myr index cd78813d..6b9be91e 100644 --- a/lib/inifile/parse.myr +++ b/lib/inifile/parse.myr @@ -54,13 +54,13 @@ const loadf = {fd f = bio.mkfile(fd, bio.Rd) while true match bio.readln(f) - | `bio.Eof: + | `std.Err `bio.Eof: break - | `bio.Ok ln: + | `std.Ok ln: if !parseline(p, ini, ln) break ;; - | `bio.Err e: + | `std.Err e: p.err = `std.Some `Fileerr break ;; diff --git a/lib/inifile/write.myr b/lib/inifile/write.myr index 1c7071dc..ab4042ca 100644 --- a/lib/inifile/write.myr +++ b/lib/inifile/write.myr @@ -53,7 +53,7 @@ const writeini = {f, ini val = std.htgetv(ini.elts, (sect, key), "") match bio.put(f, "\t{} = {}\n", key, val) - | `bio.Err e: -> false + | `std.Err e: -> false | _: ;; ;; diff --git a/lib/regex/redump.myr b/lib/regex/redump.myr index e47b824c..2cbb4ada 100644 --- a/lib/regex/redump.myr +++ b/lib/regex/redump.myr @@ -57,12 +57,12 @@ const runall = {re, files const dump = {re, fd while true match bio.readln(fd) - | `bio.Ok ln: + | `std.Ok ln: show(re, ln, regex.exec(re, ln)) std.slfree(ln) - | `bio.Eof: + | `std.Err `bio.Eof: break - | `bio.Err e: + | `std.Err e: std.put("error reading from input: {}", e) break ;; diff --git a/mbld/libs.myr b/mbld/libs.myr index f3deec5f..487d1107 100644 --- a/mbld/libs.myr +++ b/mbld/libs.myr @@ -55,16 +55,14 @@ const scrapelib = {b, targ, lib, incs (f, dir) = openlib(lib, targ, incs) match bio.getc(f) - | `bio.Ok 'U': /* ok */ - | `bio.Ok _: std.fput(1, "{}/{}: not a usefile\n", dir, lib) - | `bio.Err e: std.fatal("{}/{}: error reading: {}\n", dir, lib, e) - | `bio.Eof: std.fatal("{}/{}: truncated\n", dir, lib) + | `std.Ok 'U': /* ok */ + | `std.Ok _: std.fput(1, "{}/{}: not a usefile\n", dir, lib) + | `std.Err e: std.fatal("{}/{}: error reading: {}\n", dir, lib, e) ;; match bio.getbe32(f) - | `bio.Ok Abiversion: /* nothing: version matches. */ - | `bio.Ok v: std.fput(1, "{}/{}: mismatched abi {}\n", dir, lib, v) - | `bio.Err e: std.fatal("{}/{}: error reading: {}\n", dir, lib, e) - | `bio.Eof: std.fatal("{}/{}: truncated\n", dir, lib) + | `std.Ok Abiversion: /* nothing: version matches. */ + | `std.Ok v: std.fput(1, "{}/{}: mismatched abi {}\n", dir, lib, v) + | `std.Err e: std.fatal("{}/{}: error reading: {}\n", dir, lib, e) ;; std.slfree(rdstr(f)) @@ -72,10 +70,10 @@ const scrapelib = {b, targ, lib, incs dyndep = [][:] while true match bio.getc(f) - | `bio.Ok 'L': std.slpush(&dep, rdstr(f)) - | `bio.Ok 'X': std.slpush(&dyndep, rdstr(f)) - | `bio.Err e: std.fatal("{}: error reading {}", lib, e) - | _: break; + | `std.Ok 'L': std.slpush(&dep, rdstr(f)) + | `std.Ok 'X': std.slpush(&dyndep, rdstr(f)) + | `std.Err e: std.fatal("{}: error reading {}\n", lib, e) + | _: break ;; ;; bio.close(f) @@ -179,11 +177,10 @@ const rdstr = {f -> byte[:] var sl match bio.getbe32(f) - | `bio.Ok l: + | `std.Ok l: len = l sl = std.slalloc(len) - | `bio.Eof: std.fatal("end of file while reading string") - | `bio.Err e: std.fatal("error while reading string: {}", e) + | `std.Err e: std.fatal("error while reading string: {}", e) ;; bio.read(f, sl) -> sl diff --git a/mbld/subtest.myr b/mbld/subtest.myr index 10781050..f631895d 100644 --- a/mbld/subtest.myr +++ b/mbld/subtest.myr @@ -29,9 +29,11 @@ const showsub = {b, cmd, fd, logfd, failed log = bio.mkfile(logfd, bio.Wr) res = `std.None match bio.readln(f) - | `bio.Err e: std.fatal("error reading subfile: {}\n", e) - | `bio.Eof: -> `std.None - | `bio.Ok ln: + | `std.Err `bio.Eof: + -> `std.None + | `std.Err e: + std.fatal("error reading subfile: {}\n", e) + | `std.Ok ln: match testplan(ln) | `std.None: bio.write(log, ln) diff --git a/support/dumpleak.myr b/support/dumpleak.myr index 557e8aa6..dcd6c07f 100644 --- a/support/dumpleak.myr +++ b/support/dumpleak.myr @@ -50,11 +50,11 @@ const main = {args const dump = {path, f, stats while true match bio.getle64(f) - | `bio.Ok 0: tracealloc(path, f, stats) - | `bio.Ok 1: tracefree(path, f, stats) - | `bio.Eof: break - | `bio.Ok wat: std.fatal("unknown action type {x}\n", wat) - | `bio.Err e: std.fatal("failed to read {}: {}\n", path, e) + | `std.Err `bio.Eof: break + | `std.Ok 0: tracealloc(path, f, stats) + | `std.Ok 1: tracefree(path, f, stats) + | `std.Ok wat: std.fatal("unknown action type {x}\n", wat) + | `std.Err e: std.fatal("failed to read {}: {}\n", path, e) ;; ;; if !summary @@ -116,7 +116,7 @@ const dumptrace = {tab const get64 = {path, f match bio.getle64(f) - | `bio.Ok v: -> v + | `std.Ok v: -> v | res: std.fatal("failed to read {}: {}\n", path, res) ;; } -- 2.13.5
Re: Removing bio.status. Ripping off this bandaid might hurt a bit. | Ori Bernstein <ori@xxxxxxxxxxxxxx> |
- Next by Date: Re: Removing bio.status. Ripping off this bandaid might hurt a bit.
- Next by thread: Re: Removing bio.status. Ripping off this bandaid might hurt a bit.
- Index(es):