mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Change error "?foo" to status "?foo"
This commit is contained in:
1 parent
203b45e869
commit
eec0fce647
18 files changed
+196
-231
No files matched your search
@@ -113,17 +113,15 @@ func Do(args []string) error {
|
||||
"// !! INSERT base-public.h.\n": insertBasePublicH,
|
||||
"// !! INSERT wuffs_base__status strings.\n": func(b *buffer) error {
|
||||
for _, z := range builtin.StatusList {
|
||||
pre := ""
|
||||
switch z.Keyword {
|
||||
case t.IDError:
|
||||
pre = "error"
|
||||
case t.IDSuspension:
|
||||
pre = "suspension"
|
||||
default:
|
||||
if z == "" {
|
||||
continue
|
||||
}
|
||||
pre := "error"
|
||||
if z[0] == '$' {
|
||||
pre = "suspension"
|
||||
}
|
||||
b.printf("const char* wuffs_base__%s__%s = \"%sbase: %s\";\n",
|
||||
pre, cName(z.Message, ""), z.Message[:1], z.Message[1:])
|
||||
pre, cName(z, ""), z[:1], z[1:])
|
||||
}
|
||||
return nil
|
||||
},
|
||||
@@ -186,6 +184,10 @@ type status struct {
|
||||
public bool
|
||||
}
|
||||
|
||||
func statusMsgIsError(msg string) bool {
|
||||
return (len(msg) == 0) || (msg[0] != '$')
|
||||
}
|
||||
|
||||
type buffer []byte
|
||||
|
||||
func (b *buffer) Write(p []byte) (int, error) {
|
||||
@@ -245,16 +247,11 @@ func insertBasePublicH(buf *buffer) error {
|
||||
if err := expandBangBangInsert(buf, baseBasePublicH, map[string]func(*buffer) error{
|
||||
"// !! INSERT wuffs_base__status names.\n": func(b *buffer) error {
|
||||
for _, z := range builtin.StatusList {
|
||||
pre := ""
|
||||
switch z.Keyword {
|
||||
case t.IDError:
|
||||
pre = "error"
|
||||
case t.IDSuspension:
|
||||
pre := "error"
|
||||
if !statusMsgIsError(z) {
|
||||
pre = "suspension"
|
||||
default:
|
||||
continue
|
||||
}
|
||||
b.printf("extern const char* wuffs_base__%s__%s;\n", pre, cName(z.Message, ""))
|
||||
b.printf("extern const char* wuffs_base__%s__%s;\n", pre, cName(z, ""))
|
||||
}
|
||||
return nil
|
||||
},
|
||||
|
||||
@@ -208,22 +208,21 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, depth u
|
||||
b.writes(n.Ident().Str(g.tm))
|
||||
return nil
|
||||
|
||||
case t.IDError, t.IDStatus, t.IDSuspension:
|
||||
case t.IDStatus:
|
||||
if z := g.statusMap[n.StatusQID()]; z.cName != "" {
|
||||
b.writes(z.cName)
|
||||
} else {
|
||||
msg, _ := t.Unescape(n.Ident().Str(g.tm))
|
||||
z := builtin.StatusMap[msg]
|
||||
if z.Message == "" {
|
||||
if !builtin.StatusMap[msg] {
|
||||
return fmt.Errorf("no status code for %q", msg)
|
||||
}
|
||||
b.writes("wuffs_base__")
|
||||
if z.Keyword == t.IDSuspension {
|
||||
b.writes("suspension__")
|
||||
} else {
|
||||
if statusMsgIsError(msg) {
|
||||
b.writes("error__")
|
||||
} else {
|
||||
b.writes("suspension__")
|
||||
}
|
||||
b.writes(cName(z.Message, ""))
|
||||
b.writes(cName(msg, ""))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -306,12 +306,16 @@ func (g *gen) writeStatementRet(b *buffer, n *a.Ret, depth uint32) error {
|
||||
retExpr := n.Value()
|
||||
|
||||
if g.currFunk.suspendible {
|
||||
isError, isOK := false, false
|
||||
b.writes("status = ")
|
||||
retKeyword := t.IDStatus
|
||||
if retExpr == nil {
|
||||
b.writes("NULL")
|
||||
isOK = true
|
||||
} else {
|
||||
retKeyword = retExpr.Operator()
|
||||
if retExpr.Operator() == t.IDStatus {
|
||||
msg, _ := t.Unescape(retExpr.Ident().Str(g.tm))
|
||||
isError = statusMsgIsError(msg)
|
||||
}
|
||||
// TODO: check that retExpr has no call-suspendibles.
|
||||
if err := g.writeExpr(
|
||||
b, retExpr, replaceCallSuspendibles, depth); err != nil {
|
||||
@@ -324,13 +328,12 @@ func (g *gen) writeStatementRet(b *buffer, n *a.Ret, depth uint32) error {
|
||||
return g.writeCoroSuspPoint(b, true)
|
||||
}
|
||||
|
||||
switch retKeyword {
|
||||
case t.IDError:
|
||||
if isError {
|
||||
b.writes("goto exit;")
|
||||
case t.IDStatus:
|
||||
} else if isOK {
|
||||
g.currFunk.hasGotoOK = true
|
||||
b.writes("goto ok;")
|
||||
default:
|
||||
} else {
|
||||
g.currFunk.hasGotoOK = true
|
||||
b.writes("if (!status) { goto ok; }" +
|
||||
"else if (wuffs_base__status__is_suspension(status)) { " +
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
- Marked some internal status codes as private.
|
||||
- Removed closed-for-read/write built-in status codes.
|
||||
- Changed the string messages for built-in status codes.
|
||||
- Changed `error "foo"` to `status "?foo"`.
|
||||
- Made the status type a `const char *`, not an `int32_t`.
|
||||
- Made a packageid declaration mandatory.
|
||||
- Disallowed certain packageid's like `base` or `config`.
|
||||
|
||||
+3
-6
@@ -277,11 +277,8 @@ func (n *Raw) SetPackage(tm *t.Map, pkg t.ID) error {
|
||||
// No-op.
|
||||
|
||||
case KExpr:
|
||||
switch o.id0 {
|
||||
default:
|
||||
if o.id0 != t.IDStatus {
|
||||
return nil
|
||||
case t.IDError, t.IDStatus, t.IDSuspension:
|
||||
// No-op.
|
||||
}
|
||||
|
||||
case KTypeExpr:
|
||||
@@ -337,8 +334,8 @@ const MaxExprDepth = 255
|
||||
//
|
||||
// For lists, like "$(0, 1, 2)", ID0 is IDDollar.
|
||||
//
|
||||
// For statuses, like `error "foo"` and `suspension bar."baz"`, ID0 is the
|
||||
// keyword, ID1 is the package and ID2 is the message.
|
||||
// For statuses like "?foo" and bar."$baz", ID0 is IDStatus, ID1 is the package
|
||||
// and ID2 is the message.
|
||||
type Expr Node
|
||||
|
||||
func (n *Expr) AsNode() *Node { return (*Node)(n) }
|
||||
|
||||
+2
-9
@@ -78,15 +78,8 @@ func (n *Expr) appendStr(buf []byte, tm *t.Map, parenthesize bool, depth uint32)
|
||||
|
||||
} else {
|
||||
switch n.id0 {
|
||||
case t.IDError, t.IDStatus, t.IDSuspension:
|
||||
switch n.id0 {
|
||||
case t.IDError:
|
||||
buf = append(buf, "error "...)
|
||||
case t.IDStatus:
|
||||
buf = append(buf, "status "...)
|
||||
case t.IDSuspension:
|
||||
buf = append(buf, "suspension "...)
|
||||
}
|
||||
case t.IDStatus:
|
||||
buf = append(buf, "status "...)
|
||||
if n.id1 != 0 {
|
||||
buf = append(buf, tm.ByID(n.id1)...)
|
||||
buf = append(buf, '.')
|
||||
|
||||
+18
-37
@@ -19,48 +19,29 @@ import (
|
||||
t "github.com/google/wuffs/lang/token"
|
||||
)
|
||||
|
||||
type Status struct {
|
||||
Keyword t.ID
|
||||
Value int8
|
||||
Message string
|
||||
var StatusList = [...]string{
|
||||
"?bad wuffs version",
|
||||
"?bad sizeof receiver",
|
||||
"?bad receiver",
|
||||
"?bad argument",
|
||||
"?bad argument (length too short)",
|
||||
|
||||
"?check_wuffs_version missing",
|
||||
"?check_wuffs_version called twice",
|
||||
"?invalid call sequence",
|
||||
|
||||
"?cannot return a suspension",
|
||||
|
||||
"$end of data",
|
||||
"$short read",
|
||||
"$short write",
|
||||
}
|
||||
|
||||
func (z Status) String() string {
|
||||
prefix := "status "
|
||||
switch z.Keyword {
|
||||
case t.IDError:
|
||||
prefix = "error "
|
||||
case t.IDSuspension:
|
||||
prefix = "suspension "
|
||||
}
|
||||
return prefix + z.Message
|
||||
}
|
||||
|
||||
var StatusList = [...]Status{
|
||||
{0, 0x00, "+ok"},
|
||||
|
||||
{t.IDError, -0x01, "?bad wuffs version"},
|
||||
{t.IDError, -0x02, "?bad sizeof receiver"},
|
||||
{t.IDError, -0x03, "?bad receiver"},
|
||||
{t.IDError, -0x04, "?bad argument"},
|
||||
{t.IDError, -0x05, "?bad argument (length too short)"},
|
||||
|
||||
{t.IDError, -0x10, "?check_wuffs_version missing"},
|
||||
{t.IDError, -0x11, "?check_wuffs_version called twice"},
|
||||
{t.IDError, -0x12, "?invalid call sequence"},
|
||||
|
||||
{t.IDError, -0x20, "?cannot return a suspension"},
|
||||
|
||||
{t.IDSuspension, +0x01, "$end of data"},
|
||||
{t.IDSuspension, +0x02, "$short read"},
|
||||
{t.IDSuspension, +0x03, "$short write"},
|
||||
}
|
||||
|
||||
var StatusMap = map[string]Status{}
|
||||
var StatusMap = map[string]bool{}
|
||||
|
||||
func init() {
|
||||
for _, s := range StatusList {
|
||||
StatusMap[s.Message] = s
|
||||
StatusMap[s] = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -866,7 +866,7 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (a.Bounds, error) {
|
||||
n.Ident().Str(q.tm), lTyp.QID().Str(q.tm), n.Str(q.tm))
|
||||
}
|
||||
|
||||
case t.IDError, t.IDStatus, t.IDSuspension:
|
||||
case t.IDStatus:
|
||||
// No-op.
|
||||
|
||||
case t.IDDollar:
|
||||
|
||||
+1
-2
@@ -489,8 +489,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
||||
case t.IDDot:
|
||||
return q.tcheckDot(n, depth)
|
||||
|
||||
// TODO: remove all but t.IDStatus.
|
||||
case t.IDError, t.IDStatus, t.IDSuspension:
|
||||
case t.IDStatus:
|
||||
if _, ok := q.c.statuses[n.StatusQID()]; !ok {
|
||||
msg, _ := t.Unescape(n.Ident().Str(q.tm))
|
||||
if _, ok := builtin.StatusMap[msg]; !ok {
|
||||
|
||||
+2
-3
@@ -1022,8 +1022,7 @@ func (p *parser) parseOperand() (*a.Expr, error) {
|
||||
p.src = p.src[1:]
|
||||
return expr, nil
|
||||
|
||||
case t.IDError, t.IDStatus, t.IDSuspension:
|
||||
keyword := x
|
||||
case t.IDStatus:
|
||||
p.src = p.src[1:]
|
||||
message := p.peek1()
|
||||
// TODO: parse the "pkg" in `error pkg."foo"`.
|
||||
@@ -1033,7 +1032,7 @@ func (p *parser) parseOperand() (*a.Expr, error) {
|
||||
return nil, fmt.Errorf(`parse: expected string literal, got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
return a.NewExpr(0, keyword, statusPkg, message, nil, nil, nil, nil), nil
|
||||
return a.NewExpr(0, t.IDStatus, statusPkg, message, nil, nil, nil, nil), nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+46
-50
@@ -331,31 +331,29 @@ const (
|
||||
maxKeyword = 0x9F
|
||||
|
||||
// TODO: sort these by name, when the list has stabilized.
|
||||
IDFunc = ID(0x80)
|
||||
IDAssert = ID(0x81)
|
||||
IDWhile = ID(0x82)
|
||||
IDIf = ID(0x83)
|
||||
IDElse = ID(0x84)
|
||||
IDReturn = ID(0x85)
|
||||
IDBreak = ID(0x86)
|
||||
IDContinue = ID(0x87)
|
||||
IDStruct = ID(0x88)
|
||||
IDUse = ID(0x89)
|
||||
IDVar = ID(0x8A)
|
||||
IDPre = ID(0x8B)
|
||||
IDInv = ID(0x8C)
|
||||
IDPost = ID(0x8D)
|
||||
IDVia = ID(0x8E)
|
||||
IDPub = ID(0x8F)
|
||||
IDPri = ID(0x90)
|
||||
IDError = ID(0x91)
|
||||
IDSuspension = ID(0x92)
|
||||
IDPackageID = ID(0x93)
|
||||
IDConst = ID(0x94)
|
||||
IDTry = ID(0x95)
|
||||
IDIterate = ID(0x96)
|
||||
IDYield = ID(0x97)
|
||||
IDIOBind = ID(0x98)
|
||||
IDFunc = ID(0x80)
|
||||
IDAssert = ID(0x81)
|
||||
IDWhile = ID(0x82)
|
||||
IDIf = ID(0x83)
|
||||
IDElse = ID(0x84)
|
||||
IDReturn = ID(0x85)
|
||||
IDBreak = ID(0x86)
|
||||
IDContinue = ID(0x87)
|
||||
IDStruct = ID(0x88)
|
||||
IDUse = ID(0x89)
|
||||
IDVar = ID(0x8A)
|
||||
IDPre = ID(0x8B)
|
||||
IDInv = ID(0x8C)
|
||||
IDPost = ID(0x8D)
|
||||
IDVia = ID(0x8E)
|
||||
IDPub = ID(0x8F)
|
||||
IDPri = ID(0x90)
|
||||
IDPackageID = ID(0x91)
|
||||
IDConst = ID(0x92)
|
||||
IDTry = ID(0x93)
|
||||
IDIterate = ID(0x94)
|
||||
IDYield = ID(0x95)
|
||||
IDIOBind = ID(0x96)
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -621,31 +619,29 @@ var builtInsByID = [nBuiltInIDs]string{
|
||||
IDRef: "ref",
|
||||
IDDeref: "deref",
|
||||
|
||||
IDFunc: "func",
|
||||
IDAssert: "assert",
|
||||
IDWhile: "while",
|
||||
IDIf: "if",
|
||||
IDElse: "else",
|
||||
IDReturn: "return",
|
||||
IDBreak: "break",
|
||||
IDContinue: "continue",
|
||||
IDStruct: "struct",
|
||||
IDUse: "use",
|
||||
IDVar: "var",
|
||||
IDPre: "pre",
|
||||
IDInv: "inv",
|
||||
IDPost: "post",
|
||||
IDVia: "via",
|
||||
IDPub: "pub",
|
||||
IDPri: "pri",
|
||||
IDError: "error",
|
||||
IDSuspension: "suspension",
|
||||
IDPackageID: "packageid",
|
||||
IDConst: "const",
|
||||
IDTry: "try",
|
||||
IDIterate: "iterate",
|
||||
IDYield: "yield",
|
||||
IDIOBind: "io_bind",
|
||||
IDFunc: "func",
|
||||
IDAssert: "assert",
|
||||
IDWhile: "while",
|
||||
IDIf: "if",
|
||||
IDElse: "else",
|
||||
IDReturn: "return",
|
||||
IDBreak: "break",
|
||||
IDContinue: "continue",
|
||||
IDStruct: "struct",
|
||||
IDUse: "use",
|
||||
IDVar: "var",
|
||||
IDPre: "pre",
|
||||
IDInv: "inv",
|
||||
IDPost: "post",
|
||||
IDVia: "via",
|
||||
IDPub: "pub",
|
||||
IDPri: "pri",
|
||||
IDPackageID: "packageid",
|
||||
IDConst: "const",
|
||||
IDTry: "try",
|
||||
IDIterate: "iterate",
|
||||
IDYield: "yield",
|
||||
IDIOBind: "io_bind",
|
||||
|
||||
IDArray: "array",
|
||||
IDNptr: "nptr",
|
||||
|
||||
@@ -197,7 +197,7 @@ pri func decoder.decode_blocks!??(dst base.io_writer, src base.io_reader) {
|
||||
} else if type == 2 {
|
||||
this.init_dynamic_huffman!??(src:args.src)
|
||||
} else {
|
||||
return error "?bad block"
|
||||
return status "?bad block"
|
||||
}
|
||||
|
||||
this.end_of_block = false
|
||||
@@ -209,7 +209,7 @@ pri func decoder.decode_blocks!??(dst base.io_writer, src base.io_reader) {
|
||||
if this.end_of_block {
|
||||
continue
|
||||
}
|
||||
return error "?internal error: inconsistent Huffman end_of_block"
|
||||
return status "?internal error: inconsistent Huffman end_of_block"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,14 +220,14 @@ pri func decoder.decode_uncompressed!??(dst base.io_writer, src base.io_reader)
|
||||
//
|
||||
// Ditto for decode_huffman_slow and decode_huffman_fast.
|
||||
if (this.n_bits >= 8) or ((this.bits >> this.n_bits) != 0) {
|
||||
return error "?internal error: inconsistent n_bits"
|
||||
return status "?internal error: inconsistent n_bits"
|
||||
}
|
||||
this.n_bits = 0
|
||||
this.bits = 0
|
||||
|
||||
var length base.u32 = args.src.read_u32le!??()
|
||||
if (length.low_bits(n:16) + length.high_bits(n:16)) != 0xFFFF {
|
||||
return error "?inconsistent stored block length"
|
||||
return status "?inconsistent stored block length"
|
||||
}
|
||||
length = length.low_bits(n:16)
|
||||
while true {
|
||||
@@ -237,9 +237,9 @@ pri func decoder.decode_uncompressed!??(dst base.io_writer, src base.io_reader)
|
||||
}
|
||||
length -= n_copied
|
||||
if args.dst.available() == 0 {
|
||||
yield suspension "$short write"
|
||||
yield status "$short write"
|
||||
} else {
|
||||
yield suspension "$short read"
|
||||
yield status "$short read"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -283,12 +283,12 @@ pri func decoder.init_dynamic_huffman!??(src base.io_reader) {
|
||||
}
|
||||
var n_lit base.u32[257..288] = bits.low_bits(n:5) + 257
|
||||
if n_lit > 286 {
|
||||
return error "?bad literal/length code count"
|
||||
return status "?bad literal/length code count"
|
||||
}
|
||||
bits >>= 5
|
||||
var n_dist base.u32[1..32] = bits.low_bits(n:5) + 1
|
||||
if n_dist > 30 {
|
||||
return error "?bad distance code count"
|
||||
return status "?bad distance code count"
|
||||
}
|
||||
bits >>= 5
|
||||
var n_clen base.u32[4..19] = bits.low_bits(n:4) + 4
|
||||
@@ -342,7 +342,7 @@ pri func decoder.init_dynamic_huffman!??(src base.io_reader) {
|
||||
// For H-CL, there should be no redirections and all symbols should be
|
||||
// literals.
|
||||
if (table_entry >> 24) != 0x80 {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
table_entry = (table_entry >> 8) & 0xFF
|
||||
|
||||
@@ -360,7 +360,7 @@ pri func decoder.init_dynamic_huffman!??(src base.io_reader) {
|
||||
if table_entry == 16 {
|
||||
n_extra_bits = 2
|
||||
if i <= 0 {
|
||||
return error "?bad Huffman code length repetition"
|
||||
return status "?bad Huffman code length repetition"
|
||||
}
|
||||
rep_symbol = this.code_lengths[i - 1]
|
||||
rep_count = 3
|
||||
@@ -376,7 +376,7 @@ pri func decoder.init_dynamic_huffman!??(src base.io_reader) {
|
||||
rep_count = 11
|
||||
assert rep_count <= 11
|
||||
} else {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
while n_bits < n_extra_bits,
|
||||
inv i < 320,
|
||||
@@ -394,7 +394,7 @@ pri func decoder.init_dynamic_huffman!??(src base.io_reader) {
|
||||
while rep_count > 0 {
|
||||
// TODO: hoist this check up one level?
|
||||
if i >= (n_lit + n_dist) {
|
||||
return error "?bad Huffman code length count"
|
||||
return status "?bad Huffman code length count"
|
||||
}
|
||||
assert i < (288 + 32) via "a < (b + c): a < (b0 + c0); b0 <= b; c0 <= c"(b0:n_lit, c0:n_dist)
|
||||
this.code_lengths[i] = rep_symbol
|
||||
@@ -404,10 +404,10 @@ pri func decoder.init_dynamic_huffman!??(src base.io_reader) {
|
||||
}
|
||||
|
||||
if i != (n_lit + n_dist) {
|
||||
return error "?bad Huffman code length count"
|
||||
return status "?bad Huffman code length count"
|
||||
}
|
||||
if this.code_lengths[256] == 0 {
|
||||
return error "?missing end-of-block code"
|
||||
return status "?missing end-of-block code"
|
||||
}
|
||||
|
||||
this.init_huff!??(which:0, n_codes0:0, n_codes1:n_lit, base_symbol:257)
|
||||
@@ -463,13 +463,13 @@ pri func decoder.init_huff!??(which base.u32[..1], n_codes0 base.u32[..320], n_c
|
||||
// TODO: this if should be unnecessary. Have some way to assert that,
|
||||
// for all j, counts[j] <= i, and thus counts[j]++ will not overflow.
|
||||
if counts[this.code_lengths[i]] >= 320 {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
counts[this.code_lengths[i]] += 1
|
||||
i += 1
|
||||
}
|
||||
if ((counts[0] as base.u32) + args.n_codes0) == args.n_codes1 {
|
||||
return error "?no Huffman codes"
|
||||
return status "?no Huffman codes"
|
||||
}
|
||||
|
||||
// Check that the Huffman code completely covers all possible input bits.
|
||||
@@ -477,19 +477,19 @@ pri func decoder.init_huff!??(which base.u32[..1], n_codes0 base.u32[..320], n_c
|
||||
i = 1
|
||||
while i <= 15 {
|
||||
if remaining > (1 << 30) {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
// Each iteration doubles the number of possible remaining codes.
|
||||
remaining <<= 1
|
||||
if remaining < (counts[i] as base.u32) {
|
||||
return error "?bad Huffman code (over-subscribed)"
|
||||
return status "?bad Huffman code (over-subscribed)"
|
||||
}
|
||||
remaining -= counts[i] as base.u32
|
||||
i += 1
|
||||
}
|
||||
if remaining != 0 {
|
||||
// TODO: when is a degenerate Huffman table valid?
|
||||
return error "?bad Huffman code (under-subscribed)"
|
||||
return status "?bad Huffman code (under-subscribed)"
|
||||
}
|
||||
|
||||
// Calculate offsets and n_symbols.
|
||||
@@ -511,7 +511,7 @@ pri func decoder.init_huff!??(which base.u32[..1], n_codes0 base.u32[..320], n_c
|
||||
offsets[i] = n_symbols as base.u16
|
||||
var count base.u32[..320] = counts[i] as base.u32
|
||||
if n_symbols > (320 - count) {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
assert (n_symbols + count) <= 320 via "(a + b) <= c: a <= (c - b)"()
|
||||
// TODO: change this to n_symbols += count, once the proof engine's
|
||||
@@ -520,7 +520,7 @@ pri func decoder.init_huff!??(which base.u32[..1], n_codes0 base.u32[..320], n_c
|
||||
i += 1
|
||||
}
|
||||
if n_symbols > 288 {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
|
||||
// Calculate symbols.
|
||||
@@ -549,11 +549,11 @@ pri func decoder.init_huff!??(which base.u32[..1], n_codes0 base.u32[..320], n_c
|
||||
assert i < 320 via "a < b: a < c; c <= b"(c:args.n_codes1)
|
||||
// TODO: this if check should be unnecessary.
|
||||
if i < args.n_codes0 {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
if this.code_lengths[i] != 0 {
|
||||
if offsets[this.code_lengths[i]] >= 320 {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
symbols[offsets[this.code_lengths[i]]] = (i - args.n_codes0) as base.u16
|
||||
offsets[this.code_lengths[i]] += 1
|
||||
@@ -574,7 +574,7 @@ pri func decoder.init_huff!??(which base.u32[..1], n_codes0 base.u32[..320], n_c
|
||||
break
|
||||
}
|
||||
if min_cl >= 9 {
|
||||
return error "?bad Huffman minimum code length"
|
||||
return status "?bad Huffman minimum code length"
|
||||
}
|
||||
min_cl += 1
|
||||
}
|
||||
@@ -587,7 +587,7 @@ pri func decoder.init_huff!??(which base.u32[..1], n_codes0 base.u32[..320], n_c
|
||||
}
|
||||
if max_cl <= 1 {
|
||||
// TODO: when is a degenerate Huffman table valid?
|
||||
return error "?no Huffman codes"
|
||||
return status "?no Huffman codes"
|
||||
}
|
||||
max_cl -= 1
|
||||
}
|
||||
@@ -612,10 +612,10 @@ pri func decoder.init_huff!??(which base.u32[..1], n_codes0 base.u32[..320], n_c
|
||||
// - this.huffs[0][0b11111] = 0x80001805 (literal, symbols[9]=0x18, code_length=5)
|
||||
i = 0
|
||||
if (n_symbols != (offsets[max_cl] as base.u32)) or (n_symbols != (offsets[15] as base.u32)) {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
if (args.n_codes0 + (symbols[0] as base.u32)) >= 320 {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
|
||||
var initial_high_bits base.u32 = 1 << 9
|
||||
@@ -635,13 +635,13 @@ pri func decoder.init_huff!??(which base.u32[..1], n_codes0 base.u32[..320], n_c
|
||||
inv n_symbols <= 288,
|
||||
{
|
||||
if (args.n_codes0 + (symbols[i] as base.u32)) >= 320 {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
var cl base.u32[..15] = this.code_lengths[args.n_codes0 + (symbols[i] as base.u32)] as base.u32
|
||||
if cl > prev_cl {
|
||||
code <<= cl - prev_cl
|
||||
if code >= (1 << 15) {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
}
|
||||
// For the remainder of this loop body, prev_cl is the original code
|
||||
@@ -676,20 +676,20 @@ pri func decoder.init_huff!??(which base.u32[..1], n_codes0 base.u32[..320], n_c
|
||||
}
|
||||
remaining -= counts[j] as base.u32
|
||||
if remaining > (1 << 30) {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
remaining <<= 1
|
||||
j += 1
|
||||
}
|
||||
if (j <= 9) or (15 < j) {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
tmp = j - 9
|
||||
initial_high_bits = (1 as base.u32) << tmp
|
||||
|
||||
top = next_top
|
||||
if (top + ((1 as base.u32) << tmp)) > 1234 {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
next_top = top + ((1 as base.u32) << tmp)
|
||||
|
||||
@@ -698,7 +698,7 @@ pri func decoder.init_huff!??(which base.u32[..1], n_codes0 base.u32[..320], n_c
|
||||
}
|
||||
}
|
||||
if (key >= (1 << 9)) or (counts[prev_cl] <= 0) {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
counts[prev_cl] -= 1
|
||||
|
||||
@@ -721,7 +721,7 @@ pri func decoder.init_huff!??(which base.u32[..1], n_codes0 base.u32[..320], n_c
|
||||
value = dcode_magic_numbers[symbol & 31] | cl
|
||||
}
|
||||
} else {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
|
||||
// The table uses log2(initial_high_bits) bits, but reversed_key only
|
||||
@@ -736,7 +736,7 @@ pri func decoder.init_huff!??(which base.u32[..1], n_codes0 base.u32[..320], n_c
|
||||
{
|
||||
high_bits -= delta
|
||||
if (top + ((high_bits | reversed_key) & 511)) >= 1234 {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
this.huffs[args.which][top + ((high_bits | reversed_key) & 511)] = value
|
||||
}
|
||||
@@ -748,7 +748,7 @@ pri func decoder.init_huff!??(which base.u32[..1], n_codes0 base.u32[..320], n_c
|
||||
assert i < 288 via "a < b: a < c; c <= b"(c:n_symbols)
|
||||
code += 1
|
||||
if code >= (1 << 15) {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ pri func decoder.decode_huffman_fast!??(dst base.io_writer, src base.io_reader)
|
||||
// correctness and performance.
|
||||
|
||||
if (this.n_bits >= 8) or ((this.bits >> this.n_bits) != 0) {
|
||||
return error "?internal error: inconsistent n_bits"
|
||||
return status "?internal error: inconsistent n_bits"
|
||||
}
|
||||
|
||||
var bits base.u32 = this.bits
|
||||
@@ -119,7 +119,7 @@ pri func decoder.decode_huffman_fast!??(dst base.io_writer, src base.io_reader)
|
||||
var redir_top base.u32[..0xFFFF] = (table_entry >> 8) & 0xFFFF
|
||||
var redir_mask base.u32[..0x7FFF] = ((1 as base.u32) << ((table_entry >> 4) & 0x0F)) - 1
|
||||
if (redir_top + (bits & redir_mask)) >= 1234 {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
table_entry = this.huffs[0][redir_top + (bits & redir_mask)]
|
||||
table_entry_n_bits = table_entry & 0x0F
|
||||
@@ -137,20 +137,20 @@ pri func decoder.decode_huffman_fast!??(dst base.io_writer, src base.io_reader)
|
||||
this.end_of_block = true
|
||||
break:loop
|
||||
} else if (table_entry >> 28) != 0 {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
} else if (table_entry >> 27) != 0 {
|
||||
return error "?bad Huffman code"
|
||||
return status "?bad Huffman code"
|
||||
} else {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
|
||||
// Once again, redundant but explicit assertions.
|
||||
assert args.src.available() >= 8
|
||||
|
||||
} else if (table_entry >> 27) != 0 {
|
||||
return error "?bad Huffman code"
|
||||
return status "?bad Huffman code"
|
||||
} else {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
|
||||
// length = base_number + extra_bits.
|
||||
@@ -182,7 +182,7 @@ pri func decoder.decode_huffman_fast!??(dst base.io_writer, src base.io_reader)
|
||||
assert args.src.available() >= 6
|
||||
}
|
||||
if length > 258 {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
|
||||
// Ensure that we have at least 15 bits of input.
|
||||
@@ -230,7 +230,7 @@ pri func decoder.decode_huffman_fast!??(dst base.io_writer, src base.io_reader)
|
||||
redir_top = (table_entry >> 8) & 0xFFFF
|
||||
redir_mask = ((1 as base.u32) << ((table_entry >> 4) & 0x0F)) - 1
|
||||
if (redir_top + (bits & redir_mask)) >= 1234 {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
table_entry = this.huffs[1][redir_top + (bits & redir_mask)]
|
||||
table_entry_n_bits = table_entry & 0x0F
|
||||
@@ -243,9 +243,9 @@ pri func decoder.decode_huffman_fast!??(dst base.io_writer, src base.io_reader)
|
||||
// For H-D, all symbols should be base_number + extra_bits.
|
||||
if (table_entry >> 24) != 0x40 {
|
||||
if (table_entry >> 24) == 0x08 {
|
||||
return error "?bad Huffman code"
|
||||
return status "?bad Huffman code"
|
||||
}
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
|
||||
// dist_minus_1 = base_number_minus_1 + extra_bits.
|
||||
@@ -299,7 +299,7 @@ pri func decoder.decode_huffman_fast!??(dst base.io_writer, src base.io_reader)
|
||||
hlen = hdist
|
||||
// TODO: this if check should be redundant.
|
||||
if length > 258 {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
} else {
|
||||
hlen = length
|
||||
@@ -307,7 +307,7 @@ pri func decoder.decode_huffman_fast!??(dst base.io_writer, src base.io_reader)
|
||||
assert length <= 258
|
||||
}
|
||||
if this.history_index < hdist {
|
||||
return error "?bad distance"
|
||||
return status "?bad distance"
|
||||
}
|
||||
// Re-purpose the hdist variable as the this.history index to
|
||||
// start copying from.
|
||||
@@ -346,7 +346,7 @@ pri func decoder.decode_huffman_fast!??(dst base.io_writer, src base.io_reader)
|
||||
}
|
||||
|
||||
if ((dist_minus_1 + 1) as base.u64) > args.dst.since_mark().length() {
|
||||
return error "?internal error: inconsistent distance"
|
||||
return status "?internal error: inconsistent distance"
|
||||
}
|
||||
}
|
||||
// Once again, redundant but explicit assertions.
|
||||
@@ -382,7 +382,7 @@ pri func decoder.decode_huffman_fast!??(dst base.io_writer, src base.io_reader)
|
||||
if args.src.can_undo_byte() {
|
||||
args.src.undo_byte!()
|
||||
} else {
|
||||
return error "?internal error: inconsistent I/O"
|
||||
return status "?internal error: inconsistent I/O"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -390,6 +390,6 @@ pri func decoder.decode_huffman_fast!??(dst base.io_writer, src base.io_reader)
|
||||
this.n_bits = n_bits
|
||||
|
||||
if (this.n_bits >= 8) or ((this.bits >> this.n_bits) != 0) {
|
||||
return error "?internal error: inconsistent n_bits"
|
||||
return status "?internal error: inconsistent n_bits"
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ pri func decoder.decode_huffman_slow!??(dst base.io_writer, src base.io_reader)
|
||||
// correctness and performance.
|
||||
|
||||
if (this.n_bits >= 8) or ((this.bits >> this.n_bits) != 0) {
|
||||
return error "?internal error: inconsistent n_bits"
|
||||
return status "?internal error: inconsistent n_bits"
|
||||
}
|
||||
|
||||
var bits base.u32 = this.bits
|
||||
@@ -61,7 +61,7 @@ pri func decoder.decode_huffman_slow!??(dst base.io_writer, src base.io_reader)
|
||||
var redir_mask base.u32[..0x7FFF] = ((1 as base.u32) << ((table_entry >> 4) & 0x0F)) - 1
|
||||
while true {
|
||||
if (redir_top + (bits & redir_mask)) >= 1234 {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
table_entry = this.huffs[0][redir_top + (bits & redir_mask)]
|
||||
table_entry_n_bits = table_entry & 0x0F
|
||||
@@ -86,17 +86,17 @@ pri func decoder.decode_huffman_slow!??(dst base.io_writer, src base.io_reader)
|
||||
this.end_of_block = true
|
||||
break:loop
|
||||
} else if (table_entry >> 28) != 0 {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
} else if (table_entry >> 27) != 0 {
|
||||
return error "?bad Huffman code"
|
||||
return status "?bad Huffman code"
|
||||
} else {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
|
||||
} else if (table_entry >> 27) != 0 {
|
||||
return error "?bad Huffman code"
|
||||
return status "?bad Huffman code"
|
||||
} else {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
|
||||
// length = base_number + extra_bits.
|
||||
@@ -134,7 +134,7 @@ pri func decoder.decode_huffman_slow!??(dst base.io_writer, src base.io_reader)
|
||||
redir_mask = ((1 as base.u32) << ((table_entry >> 4) & 0x0F)) - 1
|
||||
while true {
|
||||
if (redir_top + (bits & redir_mask)) >= 1234 {
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
table_entry = this.huffs[1][redir_top + (bits & redir_mask)]
|
||||
table_entry_n_bits = table_entry & 0x0F
|
||||
@@ -152,9 +152,9 @@ pri func decoder.decode_huffman_slow!??(dst base.io_writer, src base.io_reader)
|
||||
// For H-D, all symbols should be base_number + extra_bits.
|
||||
if (table_entry >> 24) != 0x40 {
|
||||
if (table_entry >> 24) == 0x08 {
|
||||
return error "?bad Huffman code"
|
||||
return status "?bad Huffman code"
|
||||
}
|
||||
return error "?internal error: inconsistent Huffman decoder state"
|
||||
return status "?internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
|
||||
// dist_minus_1 = base_number_minus_1 + extra_bits.
|
||||
@@ -198,7 +198,7 @@ pri func decoder.decode_huffman_slow!??(dst base.io_writer, src base.io_reader)
|
||||
length = 0
|
||||
}
|
||||
if this.history_index < hdist {
|
||||
return error "?bad distance"
|
||||
return status "?bad distance"
|
||||
}
|
||||
// Re-purpose the hdist variable as the this.history index to
|
||||
// start copying from.
|
||||
@@ -220,7 +220,7 @@ pri func decoder.decode_huffman_slow!??(dst base.io_writer, src base.io_reader)
|
||||
break
|
||||
}
|
||||
}
|
||||
yield suspension "$short write"
|
||||
yield status "$short write"
|
||||
}
|
||||
// Copy from the start of this.history, if we wrapped around.
|
||||
if hlen > 0 {
|
||||
@@ -233,7 +233,7 @@ pri func decoder.decode_huffman_slow!??(dst base.io_writer, src base.io_reader)
|
||||
}
|
||||
hlen -= n_copied
|
||||
hdist ~mod+= n_copied
|
||||
yield suspension "$short write"
|
||||
yield status "$short write"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ pri func decoder.decode_huffman_slow!??(dst base.io_writer, src base.io_reader)
|
||||
break
|
||||
}
|
||||
length -= n_copied
|
||||
yield suspension "$short write"
|
||||
yield status "$short write"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,6 +260,6 @@ pri func decoder.decode_huffman_slow!??(dst base.io_writer, src base.io_reader)
|
||||
this.n_bits = n_bits
|
||||
|
||||
if (this.n_bits >= 8) or ((this.bits >> this.n_bits) != 0) {
|
||||
return error "?internal error: inconsistent n_bits"
|
||||
return status "?internal error: inconsistent n_bits"
|
||||
}
|
||||
}
|
||||
+14
-14
@@ -124,7 +124,7 @@ pub struct decoder?(
|
||||
|
||||
pub func decoder.decode_image_config!??(dst nptr base.image_config, src base.io_reader) {
|
||||
if this.call_sequence >= 1 {
|
||||
return error "?invalid call sequence"
|
||||
return status "?invalid call sequence"
|
||||
}
|
||||
this.decode_header!??(src:args.src)
|
||||
this.decode_lsd!??(src:args.src)
|
||||
@@ -184,7 +184,7 @@ pub func decoder.decode_frame_config!??(dst nptr base.frame_config, src base.io_
|
||||
// this.end_of_data.
|
||||
if this.end_of_data {
|
||||
while true {
|
||||
yield suspension "$end of data"
|
||||
yield status "$end of data"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,7 +263,7 @@ pri func decoder.decode_up_to_id_part1!??(src base.io_reader) {
|
||||
this.end_of_data = true
|
||||
break
|
||||
} else {
|
||||
return error "?bad block"
|
||||
return status "?bad block"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -280,7 +280,7 @@ pri func decoder.decode_header!??(src base.io_reader) {
|
||||
}
|
||||
if (c[0] != 0x47) or (c[1] != 0x49) or (c[2] != 0x46) or (c[3] != 0x38) or
|
||||
((c[4] != 0x37) and (c[4] != 0x39)) or (c[5] != 0x61) {
|
||||
return error "?bad header"
|
||||
return status "?bad header"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -432,11 +432,11 @@ pri func decoder.decode_ae!??(src base.io_reader) {
|
||||
// decode_gc reads a Graphic Control.
|
||||
pri func decoder.decode_gc!??(src base.io_reader) {
|
||||
if this.seen_graphic_control {
|
||||
return error "?bad graphic control"
|
||||
return status "?bad graphic control"
|
||||
}
|
||||
var c base.u8 = args.src.read_u8!??()
|
||||
if c != 4 {
|
||||
return error "?bad graphic control"
|
||||
return status "?bad graphic control"
|
||||
}
|
||||
|
||||
var flags base.u8 = args.src.read_u8!??()
|
||||
@@ -466,7 +466,7 @@ pri func decoder.decode_gc!??(src base.io_reader) {
|
||||
|
||||
c = args.src.read_u8!??()
|
||||
if c != 0 {
|
||||
return error "?bad graphic control"
|
||||
return status "?bad graphic control"
|
||||
}
|
||||
this.seen_graphic_control = true
|
||||
}
|
||||
@@ -569,7 +569,7 @@ pri func decoder.decode_id_part1!??(dst ptr base.pixel_buffer, src base.io_reade
|
||||
|
||||
var lw base.u8 = args.src.read_u8!??()
|
||||
if (lw < 2) or (8 < lw) {
|
||||
return error "?bad literal width"
|
||||
return status "?bad literal width"
|
||||
}
|
||||
this.lzw.set_literal_width!(lw:lw as base.u32)
|
||||
|
||||
@@ -598,17 +598,17 @@ pri func decoder.decode_id_part1!??(dst ptr base.pixel_buffer, src base.io_reade
|
||||
block_size ~sat-= args.src.since_mark().length()
|
||||
}
|
||||
|
||||
if z.is_ok() or (z == suspension "$short write") {
|
||||
if z.is_ok() or (z == status "$short write") {
|
||||
this.copy_to_image_buffer!??(pb:args.dst)
|
||||
|
||||
if z == suspension "$short write" {
|
||||
if z == status "$short write" {
|
||||
continue:inner
|
||||
}
|
||||
// TODO: check that block_size is zero?
|
||||
this.previous_lzw_decode_ended_abruptly = false
|
||||
break:inner
|
||||
}
|
||||
if (block_size == 0) and (z == suspension "$short read") {
|
||||
if (block_size == 0) and (z == status "$short read") {
|
||||
break:inner
|
||||
}
|
||||
yield z
|
||||
@@ -637,7 +637,7 @@ pri func decoder.copy_to_image_buffer!??(pb ptr base.pixel_buffer) {
|
||||
src = this.uncompressed[this.uncompressed_ri:this.uncompressed_wi]
|
||||
|
||||
if this.dst_y >= this.frame_rect_y1 {
|
||||
return error "?too much pixel data"
|
||||
return status "?too much pixel data"
|
||||
}
|
||||
|
||||
// First, copy from src to that part of the frame rect that is inside
|
||||
@@ -672,7 +672,7 @@ pri func decoder.copy_to_image_buffer!??(pb ptr base.pixel_buffer) {
|
||||
if this.uncompressed_wi == this.uncompressed_ri {
|
||||
break
|
||||
} else if this.uncompressed_wi < this.uncompressed_ri {
|
||||
return error "?internal error: inconsistent ri/wi"
|
||||
return status "?internal error: inconsistent ri/wi"
|
||||
}
|
||||
|
||||
// Second, skip over src for that part of the frame rect that is
|
||||
@@ -697,7 +697,7 @@ pri func decoder.copy_to_image_buffer!??(pb ptr base.pixel_buffer) {
|
||||
}
|
||||
|
||||
if this.uncompressed_ri != this.uncompressed_wi {
|
||||
return error "?internal error: inconsistent ri/wi"
|
||||
return status "?internal error: inconsistent ri/wi"
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
@@ -36,15 +36,15 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
|
||||
// Read the header.
|
||||
var c base.u8 = args.src.read_u8!??()
|
||||
if c != 0x1F {
|
||||
return error "?bad header"
|
||||
return status "?bad header"
|
||||
}
|
||||
c = args.src.read_u8!??()
|
||||
if c != 0x8B {
|
||||
return error "?bad header"
|
||||
return status "?bad header"
|
||||
}
|
||||
c = args.src.read_u8!??()
|
||||
if c != 0x08 {
|
||||
return error "?bad compression method"
|
||||
return status "?bad compression method"
|
||||
}
|
||||
var flags base.u8 = args.src.read_u8!??()
|
||||
// TODO: API for returning the header's MTIME field.
|
||||
@@ -87,7 +87,7 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
|
||||
|
||||
// Reserved flags bits must be zero.
|
||||
if (flags & 0xE0) != 0 {
|
||||
return error "?bad encoding flags"
|
||||
return status "?bad encoding flags"
|
||||
}
|
||||
|
||||
// Decode and checksum the DEFLATE-encoded payload.
|
||||
@@ -109,6 +109,6 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
|
||||
var decoded_length_want base.u32 = args.src.read_u32le!??()
|
||||
if (not this.ignore_checksum) and
|
||||
((checksum_got != checksum_want) or (decoded_length_got != decoded_length_want)) {
|
||||
return error "?bad checksum"
|
||||
return status "?bad checksum"
|
||||
}
|
||||
}
|
||||
@@ -102,7 +102,7 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
|
||||
{
|
||||
this.stack[s] = this.suffixes[c]
|
||||
if s == 0 {
|
||||
return error "?cyclical prefix chain"
|
||||
return status "?cyclical prefix chain"
|
||||
}
|
||||
s -= 1
|
||||
c = this.prefixes[c] as base.u32
|
||||
@@ -123,7 +123,7 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
|
||||
break
|
||||
}
|
||||
s = (s + ((n_copied & 4095) as base.u32)) & 4095
|
||||
yield suspension "$short write"
|
||||
yield status "$short write"
|
||||
}
|
||||
|
||||
if save_code <= 4095 {
|
||||
@@ -137,7 +137,7 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
|
||||
}
|
||||
|
||||
} else {
|
||||
return error "?bad code"
|
||||
return status "?bad code"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,16 +37,16 @@ pub func decoder.set_ignore_checksum!(ic base.bool) {
|
||||
pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
|
||||
var x base.u16 = args.src.read_u16be!??()
|
||||
if ((x >> 8) & 0x0F) != 0x08 {
|
||||
return error "?bad compression method"
|
||||
return status "?bad compression method"
|
||||
}
|
||||
if (x >> 12) > 0x07 {
|
||||
return error "?bad compression window size"
|
||||
return status "?bad compression window size"
|
||||
}
|
||||
if (x & 0x20) != 0 {
|
||||
return error "?TODO: unsupported preset dictionary"
|
||||
return status "?TODO: unsupported preset dictionary"
|
||||
}
|
||||
if (x % 31) != 0 {
|
||||
return error "?bad parity check"
|
||||
return status "?bad parity check"
|
||||
}
|
||||
|
||||
// Decode and checksum the DEFLATE-encoded payload.
|
||||
@@ -64,6 +64,6 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
|
||||
}
|
||||
var checksum_want base.u32 = args.src.read_u32be!??()
|
||||
if (not this.ignore_checksum) and (checksum_got != checksum_want) {
|
||||
return error "?bad checksum"
|
||||
return status "?bad checksum"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user