Change status "?foo" to just "?foo"

This commit is contained in:
Nigel Tao committed 2018-11-24 12:36:42 +11:00
1 parent 5f9d007b1c
commit 875362ea07
14 files changed
+136 -152

No files matched your search

+22 -22
View File
@@ -72,15 +72,35 @@ func (g *gen) writeExpr(b *buffer, n *a.Expr, rp replacementPolicy, depth uint32
func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, depth uint32) error { func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, depth uint32) error {
switch n.Operator() { switch n.Operator() {
case 0: case 0:
if id1 := n.Ident(); id1 == t.IDThis { if ident := n.Ident(); ident == t.IDThis {
b.writes("self") b.writes("self")
} else if ident.IsStrLiteral(g.tm) {
if z := g.statusMap[n.StatusQID()]; z.cName != "" {
b.writes(z.cName)
} else {
msg, _ := t.Unescape(n.Ident().Str(g.tm))
if !builtin.StatusMap[msg] {
return fmt.Errorf("no status code for %q", msg)
}
b.writes("wuffs_base__")
if statusMsgIsError(msg) {
b.writes("error__")
} else if statusMsgIsSuspension(msg) {
b.writes("suspension__")
} else {
b.writes("warning__")
}
b.writes(cName(msg, ""))
}
} else { } else {
if n.GlobalIdent() { if n.GlobalIdent() {
b.writes(g.pkgPrefix) b.writes(g.pkgPrefix)
} else { } else {
b.writes(vPrefix) b.writes(vPrefix)
} }
b.writes(id1.Str(g.tm)) b.writes(ident.Str(g.tm))
} }
return nil return nil
@@ -212,26 +232,6 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, depth u
b.writes("private_impl." + fPrefix) b.writes("private_impl." + fPrefix)
b.writes(n.Ident().Str(g.tm)) b.writes(n.Ident().Str(g.tm))
return nil return nil
case t.IDStatus:
if z := g.statusMap[n.StatusQID()]; z.cName != "" {
b.writes(z.cName)
} else {
msg, _ := t.Unescape(n.Ident().Str(g.tm))
if !builtin.StatusMap[msg] {
return fmt.Errorf("no status code for %q", msg)
}
b.writes("wuffs_base__")
if statusMsgIsError(msg) {
b.writes("error__")
} else if statusMsgIsSuspension(msg) {
b.writes("suspension__")
} else {
b.writes("warning__")
}
b.writes(cName(msg, ""))
}
return nil
} }
return fmt.Errorf("unrecognized token (0x%X) for writeExprOther", n.Operator()) return fmt.Errorf("unrecognized token (0x%X) for writeExprOther", n.Operator())
} }
+1 -1
View File
@@ -331,7 +331,7 @@ func (g *gen) writeStatementRet(b *buffer, n *a.Ret, depth uint32) error {
b.writes("NULL") b.writes("NULL")
isOK = true isOK = true
} else { } else {
if retExpr.Operator() == t.IDStatus { if retExpr.Ident().IsStrLiteral(g.tm) {
msg, _ := t.Unescape(retExpr.Ident().Str(g.tm)) msg, _ := t.Unescape(retExpr.Ident().Str(g.tm))
isError = statusMsgIsError(msg) isError = statusMsgIsError(msg)
isOK = statusMsgIsWarning(msg) isOK = statusMsgIsWarning(msg)
+1 -1
View File
@@ -36,7 +36,7 @@
- Marked some internal status codes as private. - Marked some internal status codes as private.
- Removed closed-for-read/write built-in status codes. - Removed closed-for-read/write built-in status codes.
- Changed the string messages for built-in status codes. - Changed the string messages for built-in status codes.
- Changed `error "foo"` to `status "?foo"`. - Changed `error "foo"` to `"?foo"`.
- Added warnings as another status code category. - Added warnings as another status code category.
- Made the status type a `const char *`, not an `int32_t`. - Made the status type a `const char *`, not an `int32_t`.
- Disallowed `__double_underscore` prefixed names. - Disallowed `__double_underscore` prefixed names.
+3 -4
View File
@@ -307,7 +307,9 @@ const MaxExprDepth = 255
// - RHS: <nil|Expr|TypeExpr> // - RHS: <nil|Expr|TypeExpr>
// - List0: <Arg|Expr> function call args, assoc. op args or list members. // - List0: <Arg|Expr> function call args, assoc. op args or list members.
// //
// A zero ID0 means an identifier or literal in ID2, like "foo" or "42". // A zero ID0 means an identifier or literal in ID2, like `foo`, `42` or a
// status literal like `"?foo"` or `pkg."$bar"`. For status literals, ID1 is
// the package.
// //
// For unary operators, ID0 is the operator and RHS is the operand. // For unary operators, ID0 is the operator and RHS is the operand.
// //
@@ -329,9 +331,6 @@ const MaxExprDepth = 255
// For selectors, like "LHS.ID2", ID0 is IDDot. // For selectors, like "LHS.ID2", ID0 is IDDot.
// //
// For lists, like "[0, 1, 2]", ID0 is IDComma. // For lists, like "[0, 1, 2]", ID0 is IDComma.
//
// For statuses like "?foo" and bar."$baz", ID0 is IDStatus, ID1 is the package
// and ID2 is the message.
type Expr Node type Expr Node
func (n *Expr) AsNode() *Node { return (*Node)(n) } func (n *Expr) AsNode() *Node { return (*Node)(n) }
-3
View File
@@ -872,9 +872,6 @@ 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)) n.Ident().Str(q.tm), lTyp.QID().Str(q.tm), n.Str(q.tm))
} }
case t.IDStatus:
// No-op.
case t.IDComma: case t.IDComma:
for _, o := range n.Args() { for _, o := range n.Args() {
if _, err := q.bcheckExpr(o.AsExpr(), depth); err != nil { if _, err := q.bcheckExpr(o.AsExpr(), depth); err != nil {
+10 -10
View File
@@ -383,6 +383,16 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
n.SetMType(typeExprIdeal) n.SetMType(typeExprIdeal)
return nil return nil
} else if id1.IsStrLiteral(q.tm) {
if _, ok := q.c.statuses[n.StatusQID()]; !ok {
msg, _ := t.Unescape(n.Ident().Str(q.tm))
if _, ok := builtin.StatusMap[msg]; !ok {
return fmt.Errorf("check: no error or status with message %q", msg)
}
}
n.SetMType(typeExprStatus)
return nil
} else if id1.IsIdent(q.tm) { } else if id1.IsIdent(q.tm) {
if q.localVars != nil { if q.localVars != nil {
if typ, ok := q.localVars[id1]; ok { if typ, ok := q.localVars[id1]; ok {
@@ -489,16 +499,6 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
case t.IDDot: case t.IDDot:
return q.tcheckDot(n, depth) return q.tcheckDot(n, depth)
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 {
return fmt.Errorf("check: no error or status with message %q", msg)
}
}
n.SetMType(typeExprStatus)
return nil
case t.IDComma: case t.IDComma:
for _, o := range n.Args() { for _, o := range n.Args() {
o := o.AsExpr() o := o.AsExpr()
-12
View File
@@ -1008,18 +1008,6 @@ func (p *parser) parseOperand() (*a.Expr, error) {
} }
p.src = p.src[1:] p.src = p.src[1:]
return expr, nil return expr, nil
case t.IDStatus:
p.src = p.src[1:]
message := p.peek1()
// TODO: parse the "pkg" in `error pkg."foo"`.
statusPkg := t.ID(0)
if !message.IsStrLiteral(p.tm) {
got := p.tm.ByID(message)
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, t.IDStatus, statusPkg, message, nil, nil, nil, nil), nil
} }
} }
+36 -36
View File
@@ -195,7 +195,7 @@ pri func decoder.decode_blocks!??(dst base.io_writer, src base.io_reader) {
} else if type == 2 { } else if type == 2 {
this.init_dynamic_huffman!??(src:args.src) this.init_dynamic_huffman!??(src:args.src)
} else { } else {
return status "?bad block" return "?bad block"
} }
this.end_of_block = false this.end_of_block = false
@@ -207,7 +207,7 @@ pri func decoder.decode_blocks!??(dst base.io_writer, src base.io_reader) {
if this.end_of_block { if this.end_of_block {
continue continue
} }
return status "?internal error: inconsistent Huffman end_of_block" return "?internal error: inconsistent Huffman end_of_block"
} }
} }
@@ -218,14 +218,14 @@ pri func decoder.decode_uncompressed!??(dst base.io_writer, src base.io_reader)
// //
// Ditto for decode_huffman_slow and decode_huffman_fast. // Ditto for decode_huffman_slow and decode_huffman_fast.
if (this.n_bits >= 8) or ((this.bits >> this.n_bits) != 0) { if (this.n_bits >= 8) or ((this.bits >> this.n_bits) != 0) {
return status "?internal error: inconsistent n_bits" return "?internal error: inconsistent n_bits"
} }
this.n_bits = 0 this.n_bits = 0
this.bits = 0 this.bits = 0
var length base.u32 = args.src.read_u32le!??() var length base.u32 = args.src.read_u32le!??()
if (length.low_bits(n:16) + length.high_bits(n:16)) != 0xFFFF { if (length.low_bits(n:16) + length.high_bits(n:16)) != 0xFFFF {
return status "?inconsistent stored block length" return "?inconsistent stored block length"
} }
length = length.low_bits(n:16) length = length.low_bits(n:16)
while true { while true {
@@ -235,9 +235,9 @@ pri func decoder.decode_uncompressed!??(dst base.io_writer, src base.io_reader)
} }
length -= n_copied length -= n_copied
if args.dst.available() == 0 { if args.dst.available() == 0 {
yield status "$short write" yield "$short write"
} else { } else {
yield status "$short read" yield "$short read"
} }
} }
} }
@@ -281,12 +281,12 @@ pri func decoder.init_dynamic_huffman!??(src base.io_reader) {
} }
var n_lit base.u32[257..288] = bits.low_bits(n:5) + 257 var n_lit base.u32[257..288] = bits.low_bits(n:5) + 257
if n_lit > 286 { if n_lit > 286 {
return status "?bad literal/length code count" return "?bad literal/length code count"
} }
bits >>= 5 bits >>= 5
var n_dist base.u32[1..32] = bits.low_bits(n:5) + 1 var n_dist base.u32[1..32] = bits.low_bits(n:5) + 1
if n_dist > 30 { if n_dist > 30 {
return status "?bad distance code count" return "?bad distance code count"
} }
bits >>= 5 bits >>= 5
var n_clen base.u32[4..19] = bits.low_bits(n:4) + 4 var n_clen base.u32[4..19] = bits.low_bits(n:4) + 4
@@ -340,7 +340,7 @@ pri func decoder.init_dynamic_huffman!??(src base.io_reader) {
// For H-CL, there should be no redirections and all symbols should be // For H-CL, there should be no redirections and all symbols should be
// literals. // literals.
if (table_entry >> 24) != 0x80 { if (table_entry >> 24) != 0x80 {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
table_entry = (table_entry >> 8) & 0xFF table_entry = (table_entry >> 8) & 0xFF
@@ -358,7 +358,7 @@ pri func decoder.init_dynamic_huffman!??(src base.io_reader) {
if table_entry == 16 { if table_entry == 16 {
n_extra_bits = 2 n_extra_bits = 2
if i <= 0 { if i <= 0 {
return status "?bad Huffman code length repetition" return "?bad Huffman code length repetition"
} }
rep_symbol = this.code_lengths[i - 1] rep_symbol = this.code_lengths[i - 1]
rep_count = 3 rep_count = 3
@@ -374,7 +374,7 @@ pri func decoder.init_dynamic_huffman!??(src base.io_reader) {
rep_count = 11 rep_count = 11
assert rep_count <= 11 assert rep_count <= 11
} else { } else {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
while n_bits < n_extra_bits, while n_bits < n_extra_bits,
inv i < 320, inv i < 320,
@@ -392,7 +392,7 @@ pri func decoder.init_dynamic_huffman!??(src base.io_reader) {
while rep_count > 0 { while rep_count > 0 {
// TODO: hoist this check up one level? // TODO: hoist this check up one level?
if i >= (n_lit + n_dist) { if i >= (n_lit + n_dist) {
return status "?bad Huffman code length count" return "?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) 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 this.code_lengths[i] = rep_symbol
@@ -402,10 +402,10 @@ pri func decoder.init_dynamic_huffman!??(src base.io_reader) {
} }
if i != (n_lit + n_dist) { if i != (n_lit + n_dist) {
return status "?bad Huffman code length count" return "?bad Huffman code length count"
} }
if this.code_lengths[256] == 0 { if this.code_lengths[256] == 0 {
return status "?missing end-of-block code" return "?missing end-of-block code"
} }
this.init_huff!??(which:0, n_codes0:0, n_codes1:n_lit, base_symbol:257) this.init_huff!??(which:0, n_codes0:0, n_codes1:n_lit, base_symbol:257)
@@ -461,13 +461,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, // 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. // for all j, counts[j] <= i, and thus counts[j]++ will not overflow.
if counts[this.code_lengths[i]] >= 320 { if counts[this.code_lengths[i]] >= 320 {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
counts[this.code_lengths[i]] += 1 counts[this.code_lengths[i]] += 1
i += 1 i += 1
} }
if ((counts[0] as base.u32) + args.n_codes0) == args.n_codes1 { if ((counts[0] as base.u32) + args.n_codes0) == args.n_codes1 {
return status "?no Huffman codes" return "?no Huffman codes"
} }
// Check that the Huffman code completely covers all possible input bits. // Check that the Huffman code completely covers all possible input bits.
@@ -475,19 +475,19 @@ pri func decoder.init_huff!??(which base.u32[..1], n_codes0 base.u32[..320], n_c
i = 1 i = 1
while i <= 15 { while i <= 15 {
if remaining > (1 << 30) { if remaining > (1 << 30) {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
// Each iteration doubles the number of possible remaining codes. // Each iteration doubles the number of possible remaining codes.
remaining <<= 1 remaining <<= 1
if remaining < (counts[i] as base.u32) { if remaining < (counts[i] as base.u32) {
return status "?bad Huffman code (over-subscribed)" return "?bad Huffman code (over-subscribed)"
} }
remaining -= counts[i] as base.u32 remaining -= counts[i] as base.u32
i += 1 i += 1
} }
if remaining != 0 { if remaining != 0 {
// TODO: when is a degenerate Huffman table valid? // TODO: when is a degenerate Huffman table valid?
return status "?bad Huffman code (under-subscribed)" return "?bad Huffman code (under-subscribed)"
} }
// Calculate offsets and n_symbols. // Calculate offsets and n_symbols.
@@ -509,7 +509,7 @@ pri func decoder.init_huff!??(which base.u32[..1], n_codes0 base.u32[..320], n_c
offsets[i] = n_symbols as base.u16 offsets[i] = n_symbols as base.u16
var count base.u32[..320] = counts[i] as base.u32 var count base.u32[..320] = counts[i] as base.u32
if n_symbols > (320 - count) { if n_symbols > (320 - count) {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
assert (n_symbols + count) <= 320 via "(a + b) <= c: a <= (c - b)"() assert (n_symbols + count) <= 320 via "(a + b) <= c: a <= (c - b)"()
// TODO: change this to n_symbols += count, once the proof engine's // TODO: change this to n_symbols += count, once the proof engine's
@@ -518,7 +518,7 @@ pri func decoder.init_huff!??(which base.u32[..1], n_codes0 base.u32[..320], n_c
i += 1 i += 1
} }
if n_symbols > 288 { if n_symbols > 288 {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
// Calculate symbols. // Calculate symbols.
@@ -547,11 +547,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) assert i < 320 via "a < b: a < c; c <= b"(c:args.n_codes1)
// TODO: this if check should be unnecessary. // TODO: this if check should be unnecessary.
if i < args.n_codes0 { if i < args.n_codes0 {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
if this.code_lengths[i] != 0 { if this.code_lengths[i] != 0 {
if offsets[this.code_lengths[i]] >= 320 { if offsets[this.code_lengths[i]] >= 320 {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
symbols[offsets[this.code_lengths[i]]] = (i - args.n_codes0) as base.u16 symbols[offsets[this.code_lengths[i]]] = (i - args.n_codes0) as base.u16
offsets[this.code_lengths[i]] += 1 offsets[this.code_lengths[i]] += 1
@@ -572,7 +572,7 @@ pri func decoder.init_huff!??(which base.u32[..1], n_codes0 base.u32[..320], n_c
break break
} }
if min_cl >= 9 { if min_cl >= 9 {
return status "?bad Huffman minimum code length" return "?bad Huffman minimum code length"
} }
min_cl += 1 min_cl += 1
} }
@@ -585,7 +585,7 @@ pri func decoder.init_huff!??(which base.u32[..1], n_codes0 base.u32[..320], n_c
} }
if max_cl <= 1 { if max_cl <= 1 {
// TODO: when is a degenerate Huffman table valid? // TODO: when is a degenerate Huffman table valid?
return status "?no Huffman codes" return "?no Huffman codes"
} }
max_cl -= 1 max_cl -= 1
} }
@@ -610,10 +610,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) // - this.huffs[0][0b11111] = 0x80001805 (literal, symbols[9]=0x18, code_length=5)
i = 0 i = 0
if (n_symbols != (offsets[max_cl] as base.u32)) or (n_symbols != (offsets[15] as base.u32)) { if (n_symbols != (offsets[max_cl] as base.u32)) or (n_symbols != (offsets[15] as base.u32)) {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
if (args.n_codes0 + (symbols[0] as base.u32)) >= 320 { if (args.n_codes0 + (symbols[0] as base.u32)) >= 320 {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
var initial_high_bits base.u32 = 1 << 9 var initial_high_bits base.u32 = 1 << 9
@@ -633,13 +633,13 @@ pri func decoder.init_huff!??(which base.u32[..1], n_codes0 base.u32[..320], n_c
inv n_symbols <= 288, inv n_symbols <= 288,
{ {
if (args.n_codes0 + (symbols[i] as base.u32)) >= 320 { if (args.n_codes0 + (symbols[i] as base.u32)) >= 320 {
return status "?internal error: inconsistent Huffman decoder state" return "?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 var cl base.u32[..15] = this.code_lengths[args.n_codes0 + (symbols[i] as base.u32)] as base.u32
if cl > prev_cl { if cl > prev_cl {
code <<= cl - prev_cl code <<= cl - prev_cl
if code >= (1 << 15) { if code >= (1 << 15) {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
} }
// For the remainder of this loop body, prev_cl is the original code // For the remainder of this loop body, prev_cl is the original code
@@ -674,20 +674,20 @@ pri func decoder.init_huff!??(which base.u32[..1], n_codes0 base.u32[..320], n_c
} }
remaining -= counts[j] as base.u32 remaining -= counts[j] as base.u32
if remaining > (1 << 30) { if remaining > (1 << 30) {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
remaining <<= 1 remaining <<= 1
j += 1 j += 1
} }
if (j <= 9) or (15 < j) { if (j <= 9) or (15 < j) {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
tmp = j - 9 tmp = j - 9
initial_high_bits = (1 as base.u32) << tmp initial_high_bits = (1 as base.u32) << tmp
top = next_top top = next_top
if (top + ((1 as base.u32) << tmp)) > 1234 { if (top + ((1 as base.u32) << tmp)) > 1234 {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
next_top = top + ((1 as base.u32) << tmp) next_top = top + ((1 as base.u32) << tmp)
@@ -696,7 +696,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) { if (key >= (1 << 9)) or (counts[prev_cl] <= 0) {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
counts[prev_cl] -= 1 counts[prev_cl] -= 1
@@ -719,7 +719,7 @@ pri func decoder.init_huff!??(which base.u32[..1], n_codes0 base.u32[..320], n_c
value = dcode_magic_numbers[symbol & 31] | cl value = dcode_magic_numbers[symbol & 31] | cl
} }
} else { } else {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
// The table uses log2(initial_high_bits) bits, but reversed_key only // The table uses log2(initial_high_bits) bits, but reversed_key only
@@ -734,7 +734,7 @@ pri func decoder.init_huff!??(which base.u32[..1], n_codes0 base.u32[..320], n_c
{ {
high_bits -= delta high_bits -= delta
if (top + ((high_bits | reversed_key) & 511)) >= 1234 { if (top + ((high_bits | reversed_key) & 511)) >= 1234 {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
this.huffs[args.which][top + ((high_bits | reversed_key) & 511)] = value this.huffs[args.which][top + ((high_bits | reversed_key) & 511)] = value
} }
@@ -746,7 +746,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) assert i < 288 via "a < b: a < c; c <= b"(c:n_symbols)
code += 1 code += 1
if code >= (1 << 15) { if code >= (1 << 15) {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
} }
} }
+16 -16
View File
@@ -21,7 +21,7 @@ pri func decoder.decode_huffman_fast!??(dst base.io_writer, src base.io_reader)
// correctness and performance. // correctness and performance.
if (this.n_bits >= 8) or ((this.bits >> this.n_bits) != 0) { if (this.n_bits >= 8) or ((this.bits >> this.n_bits) != 0) {
return status "?internal error: inconsistent n_bits" return "?internal error: inconsistent n_bits"
} }
var bits base.u32 = this.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_top base.u32[..0xFFFF] = (table_entry >> 8) & 0xFFFF
var redir_mask base.u32[..0x7FFF] = ((1 as base.u32) << ((table_entry >> 4) & 0x0F)) - 1 var redir_mask base.u32[..0x7FFF] = ((1 as base.u32) << ((table_entry >> 4) & 0x0F)) - 1
if (redir_top + (bits & redir_mask)) >= 1234 { if (redir_top + (bits & redir_mask)) >= 1234 {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
table_entry = this.huffs[0][redir_top + (bits & redir_mask)] table_entry = this.huffs[0][redir_top + (bits & redir_mask)]
table_entry_n_bits = table_entry & 0x0F 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 this.end_of_block = true
break:loop break:loop
} else if (table_entry >> 28) != 0 { } else if (table_entry >> 28) != 0 {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} else if (table_entry >> 27) != 0 { } else if (table_entry >> 27) != 0 {
return status "?bad Huffman code" return "?bad Huffman code"
} else { } else {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
// Once again, redundant but explicit assertions. // Once again, redundant but explicit assertions.
assert args.src.available() >= 8 assert args.src.available() >= 8
} else if (table_entry >> 27) != 0 { } else if (table_entry >> 27) != 0 {
return status "?bad Huffman code" return "?bad Huffman code"
} else { } else {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
// length = base_number + extra_bits. // 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 assert args.src.available() >= 6
} }
if length > 258 { if length > 258 {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
// Ensure that we have at least 15 bits of input. // 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_top = (table_entry >> 8) & 0xFFFF
redir_mask = ((1 as base.u32) << ((table_entry >> 4) & 0x0F)) - 1 redir_mask = ((1 as base.u32) << ((table_entry >> 4) & 0x0F)) - 1
if (redir_top + (bits & redir_mask)) >= 1234 { if (redir_top + (bits & redir_mask)) >= 1234 {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
table_entry = this.huffs[1][redir_top + (bits & redir_mask)] table_entry = this.huffs[1][redir_top + (bits & redir_mask)]
table_entry_n_bits = table_entry & 0x0F 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. // For H-D, all symbols should be base_number + extra_bits.
if (table_entry >> 24) != 0x40 { if (table_entry >> 24) != 0x40 {
if (table_entry >> 24) == 0x08 { if (table_entry >> 24) == 0x08 {
return status "?bad Huffman code" return "?bad Huffman code"
} }
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
// dist_minus_1 = base_number_minus_1 + extra_bits. // 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 hlen = hdist
// TODO: this if check should be redundant. // TODO: this if check should be redundant.
if length > 258 { if length > 258 {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
} else { } else {
hlen = length hlen = length
@@ -307,7 +307,7 @@ pri func decoder.decode_huffman_fast!??(dst base.io_writer, src base.io_reader)
assert length <= 258 assert length <= 258
} }
if this.history_index < hdist { if this.history_index < hdist {
return status "?bad distance" return "?bad distance"
} }
// Re-purpose the hdist variable as the this.history index to // Re-purpose the hdist variable as the this.history index to
// start copying from. // 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() { if ((dist_minus_1 + 1) as base.u64) > args.dst.since_mark().length() {
return status "?internal error: inconsistent distance" return "?internal error: inconsistent distance"
} }
} }
// Once again, redundant but explicit assertions. // 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() { if args.src.can_undo_byte() {
args.src.undo_byte!() args.src.undo_byte!()
} else { } else {
return status "?internal error: inconsistent I/O" return "?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 this.n_bits = n_bits
if (this.n_bits >= 8) or ((this.bits >> this.n_bits) != 0) { if (this.n_bits >= 8) or ((this.bits >> this.n_bits) != 0) {
return status "?internal error: inconsistent n_bits" return "?internal error: inconsistent n_bits"
} }
} }
+15 -15
View File
@@ -19,7 +19,7 @@ pri func decoder.decode_huffman_slow!??(dst base.io_writer, src base.io_reader)
// correctness and performance. // correctness and performance.
if (this.n_bits >= 8) or ((this.bits >> this.n_bits) != 0) { if (this.n_bits >= 8) or ((this.bits >> this.n_bits) != 0) {
return status "?internal error: inconsistent n_bits" return "?internal error: inconsistent n_bits"
} }
var bits base.u32 = this.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 var redir_mask base.u32[..0x7FFF] = ((1 as base.u32) << ((table_entry >> 4) & 0x0F)) - 1
while true { while true {
if (redir_top + (bits & redir_mask)) >= 1234 { if (redir_top + (bits & redir_mask)) >= 1234 {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
table_entry = this.huffs[0][redir_top + (bits & redir_mask)] table_entry = this.huffs[0][redir_top + (bits & redir_mask)]
table_entry_n_bits = table_entry & 0x0F 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 this.end_of_block = true
break:loop break:loop
} else if (table_entry >> 28) != 0 { } else if (table_entry >> 28) != 0 {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} else if (table_entry >> 27) != 0 { } else if (table_entry >> 27) != 0 {
return status "?bad Huffman code" return "?bad Huffman code"
} else { } else {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
} else if (table_entry >> 27) != 0 { } else if (table_entry >> 27) != 0 {
return status "?bad Huffman code" return "?bad Huffman code"
} else { } else {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
// length = base_number + extra_bits. // 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 redir_mask = ((1 as base.u32) << ((table_entry >> 4) & 0x0F)) - 1
while true { while true {
if (redir_top + (bits & redir_mask)) >= 1234 { if (redir_top + (bits & redir_mask)) >= 1234 {
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
table_entry = this.huffs[1][redir_top + (bits & redir_mask)] table_entry = this.huffs[1][redir_top + (bits & redir_mask)]
table_entry_n_bits = table_entry & 0x0F 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. // For H-D, all symbols should be base_number + extra_bits.
if (table_entry >> 24) != 0x40 { if (table_entry >> 24) != 0x40 {
if (table_entry >> 24) == 0x08 { if (table_entry >> 24) == 0x08 {
return status "?bad Huffman code" return "?bad Huffman code"
} }
return status "?internal error: inconsistent Huffman decoder state" return "?internal error: inconsistent Huffman decoder state"
} }
// dist_minus_1 = base_number_minus_1 + extra_bits. // 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 length = 0
} }
if this.history_index < hdist { if this.history_index < hdist {
return status "?bad distance" return "?bad distance"
} }
// Re-purpose the hdist variable as the this.history index to // Re-purpose the hdist variable as the this.history index to
// start copying from. // start copying from.
@@ -220,7 +220,7 @@ pri func decoder.decode_huffman_slow!??(dst base.io_writer, src base.io_reader)
break break
} }
} }
yield status "$short write" yield "$short write"
} }
// Copy from the start of this.history, if we wrapped around. // Copy from the start of this.history, if we wrapped around.
if hlen > 0 { if hlen > 0 {
@@ -233,7 +233,7 @@ pri func decoder.decode_huffman_slow!??(dst base.io_writer, src base.io_reader)
} }
hlen -= n_copied hlen -= n_copied
hdist ~mod+= n_copied hdist ~mod+= n_copied
yield status "$short write" yield "$short write"
} }
} }
@@ -250,7 +250,7 @@ pri func decoder.decode_huffman_slow!??(dst base.io_writer, src base.io_reader)
break break
} }
length -= n_copied length -= n_copied
yield status "$short write" yield "$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 this.n_bits = n_bits
if (this.n_bits >= 8) or ((this.bits >> this.n_bits) != 0) { if (this.n_bits >= 8) or ((this.bits >> this.n_bits) != 0) {
return status "?internal error: inconsistent n_bits" return "?internal error: inconsistent n_bits"
} }
} }
+16 -16
View File
@@ -120,7 +120,7 @@ pub struct decoder?(
pub func decoder.decode_image_config!??(dst nptr base.image_config, src base.io_reader) { pub func decoder.decode_image_config!??(dst nptr base.image_config, src base.io_reader) {
if this.call_sequence >= 1 { if this.call_sequence >= 1 {
return status "?bad call sequence" return "?bad call sequence"
} }
this.dirty_y.reset!() this.dirty_y.reset!()
@@ -187,7 +187,7 @@ pub func decoder.workbuf_len() base.range_ii_u64 {
pub func decoder.restart_frame!??(index base.u64, io_position base.u64) { pub func decoder.restart_frame!??(index base.u64, io_position base.u64) {
if this.call_sequence == 0 { if this.call_sequence == 0 {
return status "?bad call sequence" return "?bad call sequence"
} }
this.end_of_data = false this.end_of_data = false
this.restarted = true this.restarted = true
@@ -212,7 +212,7 @@ pub func decoder.decode_frame_config!??(dst nptr base.frame_config, src base.io_
// This is a new "if", not an "else", because the calls above can modify // This is a new "if", not an "else", because the calls above can modify
// this.end_of_data. // this.end_of_data.
if this.end_of_data { if this.end_of_data {
return status "~end of data" return "~end of data"
} }
var blend base.u8 = 0 var blend base.u8 = 0
@@ -255,7 +255,7 @@ pri func decoder.skip_frame!??(src base.io_reader) {
// TODO: honor args.opts. // TODO: honor args.opts.
pub func decoder.decode_frame!??(dst ptr base.pixel_buffer, src base.io_reader, workbuf slice base.u8, opts nptr base.decode_frame_options) { pub func decoder.decode_frame!??(dst ptr base.pixel_buffer, src base.io_reader, workbuf slice base.u8, opts nptr base.decode_frame_options) {
if args.workbuf.length() < (this.width as base.u64) { if args.workbuf.length() < (this.width as base.u64) {
return status "?bad workbuf length" return "?bad workbuf length"
} }
if this.call_sequence != 2 { if this.call_sequence != 2 {
this.decode_frame_config!??(dst:nullptr, src:args.src) this.decode_frame_config!??(dst:nullptr, src:args.src)
@@ -281,7 +281,7 @@ pri func decoder.decode_up_to_id_part1!??(src base.io_reader) {
if not this.restarted { if not this.restarted {
this.frame_config_io_position = args.src.position() this.frame_config_io_position = args.src.position()
} else if this.frame_config_io_position != args.src.position() { } else if this.frame_config_io_position != args.src.position() {
return status "?bad restart" return "?bad restart"
} else { } else {
this.restarted = false this.restarted = false
} }
@@ -297,7 +297,7 @@ pri func decoder.decode_up_to_id_part1!??(src base.io_reader) {
this.end_of_data = true this.end_of_data = true
break break
} else { } else {
return status "?bad block" return "?bad block"
} }
} }
} }
@@ -314,7 +314,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 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) { ((c[4] != 0x37) and (c[4] != 0x39)) or (c[5] != 0x61) {
return status "?bad header" return "?bad header"
} }
} }
@@ -465,11 +465,11 @@ pri func decoder.decode_ae!??(src base.io_reader) {
// decode_gc reads a Graphic Control. // decode_gc reads a Graphic Control.
pri func decoder.decode_gc!??(src base.io_reader) { pri func decoder.decode_gc!??(src base.io_reader) {
if this.seen_graphic_control { if this.seen_graphic_control {
return status "?bad graphic control" return "?bad graphic control"
} }
var c base.u8 = args.src.read_u8!??() var c base.u8 = args.src.read_u8!??()
if c != 4 { if c != 4 {
return status "?bad graphic control" return "?bad graphic control"
} }
var flags base.u8 = args.src.read_u8!??() var flags base.u8 = args.src.read_u8!??()
@@ -499,7 +499,7 @@ pri func decoder.decode_gc!??(src base.io_reader) {
c = args.src.read_u8!??() c = args.src.read_u8!??()
if c != 0 { if c != 0 {
return status "?bad graphic control" return "?bad graphic control"
} }
this.seen_graphic_control = true this.seen_graphic_control = true
} }
@@ -600,7 +600,7 @@ pri func decoder.decode_id_part1!??(dst ptr base.pixel_buffer, src base.io_reade
var lw base.u8 = args.src.read_u8!??() var lw base.u8 = args.src.read_u8!??()
if (lw < 2) or (8 < lw) { if (lw < 2) or (8 < lw) {
return status "?bad literal width" return "?bad literal width"
} }
this.lzw.set_literal_width!(lw:lw as base.u32) this.lzw.set_literal_width!(lw:lw as base.u32)
@@ -634,7 +634,7 @@ pri func decoder.decode_id_part1!??(dst ptr base.pixel_buffer, src base.io_reade
block_size ~sat-= args.src.since_mark().length() block_size ~sat-= args.src.since_mark().length()
} }
if (block_size == 0) and (z == status "$short read") { if (block_size == 0) and (z == "$short read") {
break:inner break:inner
} }
@@ -647,7 +647,7 @@ pri func decoder.decode_id_part1!??(dst ptr base.pixel_buffer, src base.io_reade
this.previous_lzw_decode_ended_abruptly = false this.previous_lzw_decode_ended_abruptly = false
break:inner break:inner
} }
if z == status "$short write" { if z == "$short write" {
continue:inner continue:inner
} }
yield z yield z
@@ -676,7 +676,7 @@ pri func decoder.copy_to_image_buffer!??(pb ptr base.pixel_buffer) {
src = this.uncompressed[this.uncompressed_ri:this.uncompressed_wi] src = this.uncompressed[this.uncompressed_ri:this.uncompressed_wi]
if this.dst_y >= this.frame_rect_y1 { if this.dst_y >= this.frame_rect_y1 {
return status "?too much pixel data" return "?too much pixel data"
} }
// First, copy from src to that part of the frame rect that is inside // First, copy from src to that part of the frame rect that is inside
@@ -715,7 +715,7 @@ pri func decoder.copy_to_image_buffer!??(pb ptr base.pixel_buffer) {
if this.uncompressed_wi == this.uncompressed_ri { if this.uncompressed_wi == this.uncompressed_ri {
break break
} else if this.uncompressed_wi < this.uncompressed_ri { } else if this.uncompressed_wi < this.uncompressed_ri {
return status "?internal error: inconsistent ri/wi" return "?internal error: inconsistent ri/wi"
} }
// Second, skip over src for that part of the frame rect that is // Second, skip over src for that part of the frame rect that is
@@ -740,7 +740,7 @@ pri func decoder.copy_to_image_buffer!??(pb ptr base.pixel_buffer) {
} }
if this.uncompressed_ri != this.uncompressed_wi { if this.uncompressed_ri != this.uncompressed_wi {
return status "?internal error: inconsistent ri/wi" return "?internal error: inconsistent ri/wi"
} }
break break
} }
+5 -5
View File
@@ -34,15 +34,15 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
// Read the header. // Read the header.
var c base.u8 = args.src.read_u8!??() var c base.u8 = args.src.read_u8!??()
if c != 0x1F { if c != 0x1F {
return status "?bad header" return "?bad header"
} }
c = args.src.read_u8!??() c = args.src.read_u8!??()
if c != 0x8B { if c != 0x8B {
return status "?bad header" return "?bad header"
} }
c = args.src.read_u8!??() c = args.src.read_u8!??()
if c != 0x08 { if c != 0x08 {
return status "?bad compression method" return "?bad compression method"
} }
var flags base.u8 = args.src.read_u8!??() var flags base.u8 = args.src.read_u8!??()
// TODO: API for returning the header's MTIME field. // TODO: API for returning the header's MTIME field.
@@ -85,7 +85,7 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
// Reserved flags bits must be zero. // Reserved flags bits must be zero.
if (flags & 0xE0) != 0 { if (flags & 0xE0) != 0 {
return status "?bad encoding flags" return "?bad encoding flags"
} }
// Decode and checksum the DEFLATE-encoded payload. // Decode and checksum the DEFLATE-encoded payload.
@@ -107,6 +107,6 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
var decoded_length_want base.u32 = args.src.read_u32le!??() var decoded_length_want base.u32 = args.src.read_u32le!??()
if (not this.ignore_checksum) and if (not this.ignore_checksum) and
((checksum_got != checksum_want) or (decoded_length_got != decoded_length_want)) { ((checksum_got != checksum_want) or (decoded_length_got != decoded_length_want)) {
return status "?bad checksum" return "?bad checksum"
} }
} }
+6 -6
View File
@@ -90,7 +90,7 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
this.flush!??(dst:args.dst) this.flush!??(dst:args.dst)
j = 0 j = 0
} }
yield status "$short read" yield "$short read"
} }
bits |= (args.src.peek_u8() as base.u32) << n_bits bits |= (args.src.peek_u8() as base.u32) << n_bits
args.src.skip_fast!(actual:1, worst_case:1) args.src.skip_fast!(actual:1, worst_case:1)
@@ -204,7 +204,7 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
} }
} else { } else {
return status "?bad code" return "?bad code"
} }
// Flush the output if it could be too full to contain the entire // Flush the output if it could be too full to contain the entire
@@ -218,7 +218,7 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
if args.src.can_undo_byte() { if args.src.can_undo_byte() {
args.src.undo_byte!() args.src.undo_byte!()
} else { } else {
return status "?internal error: inconsistent I/O" return "?internal error: inconsistent I/O"
} }
} }
bits = bits.low_bits(n:n_bits) bits = bits.low_bits(n:n_bits)
@@ -236,7 +236,7 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
if args.src.can_undo_byte() { if args.src.can_undo_byte() {
args.src.undo_byte!() args.src.undo_byte!()
} else { } else {
return status "?internal error: inconsistent I/O" return "?internal error: inconsistent I/O"
} }
} }
bits = bits.low_bits(n:n_bits) bits = bits.low_bits(n:n_bits)
@@ -251,7 +251,7 @@ pri func decoder.flush!??(dst base.io_writer) {
var j base.u32[..8191] = this.flush_j var j base.u32[..8191] = this.flush_j
while true { while true {
if i > j { if i > j {
return status "?internal error: inconsistent I/O" return "?internal error: inconsistent I/O"
} }
var s slice base.u8 = this.output[i:j] var s slice base.u8 = this.output[i:j]
var n base.u64 = args.dst.copy_from_slice!(s:s) var n base.u64 = args.dst.copy_from_slice!(s:s)
@@ -259,6 +259,6 @@ pri func decoder.flush!??(dst base.io_writer) {
return return
} }
i = (i + ((n & 8191) as base.u32)) & 8191 i = (i + ((n & 8191) as base.u32)) & 8191
yield status "$short write" yield "$short write"
} }
} }
+5 -5
View File
@@ -35,16 +35,16 @@ pub func decoder.set_ignore_checksum!(ic base.bool) {
pub func decoder.decode!??(dst base.io_writer, src base.io_reader) { pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
var x base.u16 = args.src.read_u16be!??() var x base.u16 = args.src.read_u16be!??()
if ((x >> 8) & 0x0F) != 0x08 { if ((x >> 8) & 0x0F) != 0x08 {
return status "?bad compression method" return "?bad compression method"
} }
if (x >> 12) > 0x07 { if (x >> 12) > 0x07 {
return status "?bad compression window size" return "?bad compression window size"
} }
if (x & 0x20) != 0 { if (x & 0x20) != 0 {
return status "?TODO: unsupported preset dictionary" return "?TODO: unsupported preset dictionary"
} }
if (x % 31) != 0 { if (x % 31) != 0 {
return status "?bad parity check" return "?bad parity check"
} }
// Decode and checksum the DEFLATE-encoded payload. // Decode and checksum the DEFLATE-encoded payload.
@@ -62,6 +62,6 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) {
} }
var checksum_want base.u32 = args.src.read_u32be!??() var checksum_want base.u32 = args.src.read_u32be!??()
if (not this.ignore_checksum) and (checksum_got != checksum_want) { if (not this.ignore_checksum) and (checksum_got != checksum_want) {
return status "?bad checksum" return "?bad checksum"
} }
} }