Rename checksum fields and variables

This commit is contained in:
Nigel Tao committed 2018-03-28 11:15:13 +11:00
1 parent 86d0ade206
commit 72449fa0ec
7 files changed
+28 -28

No files matched your search

+2 -2
View File
@@ -324,8 +324,8 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
return nil return nil
} }
if isThatMethod(g.tm, n, g.tm.ByName("update").Key(), 1) { if isThatMethod(g.tm, n, g.tm.ByName("update").Key(), 1) {
// TODO: don't hard-code this.adler. // TODO: don't hard-code this.checksum.
b.printf("%sadler32__update(&self->private_impl.f_adler, ", g.pkgPrefix) b.printf("%sadler32__update(&self->private_impl.f_checksum, ", g.pkgPrefix)
a := n.Args()[0].Arg().Value() a := n.Args()[0].Arg().Value()
if err := g.writeExpr(b, a, rp, parenthesesMandatory, depth); err != nil { if err := g.writeExpr(b, a, rp, parenthesesMandatory, depth); err != nil {
return err return err
+6 -6
View File
@@ -518,7 +518,7 @@ typedef struct {
uint8_t v_flags; uint8_t v_flags;
uint8_t v_c; uint8_t v_c;
uint16_t v_xlen; uint16_t v_xlen;
uint32_t v_checksum; uint32_t v_checksum_got;
wuffs_gzip__status v_z; wuffs_gzip__status v_z;
uint64_t scratch; uint64_t scratch;
} c_decode[1]; } c_decode[1];
@@ -1022,7 +1022,7 @@ wuffs_gzip__status wuffs_gzip__decoder__decode(wuffs_gzip__decoder* self,
uint8_t v_flags; uint8_t v_flags;
uint8_t v_c; uint8_t v_c;
uint16_t v_xlen; uint16_t v_xlen;
uint32_t v_checksum; uint32_t v_checksum_got;
wuffs_gzip__status v_z; wuffs_gzip__status v_z;
uint8_t* b_wptr_dst = NULL; uint8_t* b_wptr_dst = NULL;
@@ -1064,7 +1064,7 @@ wuffs_gzip__status wuffs_gzip__decoder__decode(wuffs_gzip__decoder* self,
v_flags = self->private_impl.c_decode[0].v_flags; v_flags = self->private_impl.c_decode[0].v_flags;
v_c = self->private_impl.c_decode[0].v_c; v_c = self->private_impl.c_decode[0].v_c;
v_xlen = self->private_impl.c_decode[0].v_xlen; v_xlen = self->private_impl.c_decode[0].v_xlen;
v_checksum = self->private_impl.c_decode[0].v_checksum; v_checksum_got = self->private_impl.c_decode[0].v_checksum_got;
v_z = self->private_impl.c_decode[0].v_z; v_z = self->private_impl.c_decode[0].v_z;
} else { } else {
} }
@@ -1202,7 +1202,7 @@ wuffs_gzip__status wuffs_gzip__decoder__decode(wuffs_gzip__decoder* self,
status = WUFFS_GZIP__ERROR_INVALID_GZIP_ENCODING_FLAGS; status = WUFFS_GZIP__ERROR_INVALID_GZIP_ENCODING_FLAGS;
goto exit; goto exit;
} }
v_checksum = 0; v_checksum_got = 0;
while (true) { while (true) {
wuffs_base__writer1__mark(&a_dst, b_wptr_dst); wuffs_base__writer1__mark(&a_dst, b_wptr_dst);
{ {
@@ -1271,7 +1271,7 @@ wuffs_gzip__status wuffs_gzip__decoder__decode(wuffs_gzip__decoder* self,
self->private_impl.c_decode[0].scratch |= ((uint64_t)(t_9)); self->private_impl.c_decode[0].scratch |= ((uint64_t)(t_9));
} }
} }
if (!self->private_impl.f_ignore_checksum && (v_checksum != t_10)) { if (!self->private_impl.f_ignore_checksum && (v_checksum_got != t_10)) {
} }
goto ok; goto ok;
@@ -1286,7 +1286,7 @@ suspend:
self->private_impl.c_decode[0].v_flags = v_flags; self->private_impl.c_decode[0].v_flags = v_flags;
self->private_impl.c_decode[0].v_c = v_c; self->private_impl.c_decode[0].v_c = v_c;
self->private_impl.c_decode[0].v_xlen = v_xlen; self->private_impl.c_decode[0].v_xlen = v_xlen;
self->private_impl.c_decode[0].v_checksum = v_checksum; self->private_impl.c_decode[0].v_checksum_got = v_checksum_got;
self->private_impl.c_decode[0].v_z = v_z; self->private_impl.c_decode[0].v_z = v_z;
goto exit; goto exit;
+10 -10
View File
@@ -440,13 +440,13 @@ typedef struct {
uint32_t magic; uint32_t magic;
wuffs_deflate__decoder f_flate; wuffs_deflate__decoder f_flate;
wuffs_zlib__adler32 f_adler; wuffs_zlib__adler32 f_checksum;
bool f_ignore_checksum; bool f_ignore_checksum;
struct { struct {
uint32_t coro_susp_point; uint32_t coro_susp_point;
uint16_t v_x; uint16_t v_x;
uint32_t v_checksum; uint32_t v_checksum_got;
wuffs_zlib__status v_z; wuffs_zlib__status v_z;
uint64_t scratch; uint64_t scratch;
} c_decode[1]; } c_decode[1];
@@ -935,7 +935,7 @@ void wuffs_zlib__decoder__initialize(wuffs_zlib__decoder* self,
self->private_impl.magic = WUFFS_BASE__MAGIC; self->private_impl.magic = WUFFS_BASE__MAGIC;
wuffs_deflate__decoder__initialize(&self->private_impl.f_flate, WUFFS_VERSION, wuffs_deflate__decoder__initialize(&self->private_impl.f_flate, WUFFS_VERSION,
WUFFS_BASE__ALREADY_ZEROED); WUFFS_BASE__ALREADY_ZEROED);
wuffs_zlib__adler32__initialize(&self->private_impl.f_adler, WUFFS_VERSION, wuffs_zlib__adler32__initialize(&self->private_impl.f_checksum, WUFFS_VERSION,
WUFFS_BASE__ALREADY_ZEROED); WUFFS_BASE__ALREADY_ZEROED);
} }
@@ -971,7 +971,7 @@ wuffs_zlib__status wuffs_zlib__decoder__decode(wuffs_zlib__decoder* self,
wuffs_zlib__status status = WUFFS_ZLIB__STATUS_OK; wuffs_zlib__status status = WUFFS_ZLIB__STATUS_OK;
uint16_t v_x; uint16_t v_x;
uint32_t v_checksum; uint32_t v_checksum_got;
wuffs_zlib__status v_z; wuffs_zlib__status v_z;
uint8_t* b_wptr_dst = NULL; uint8_t* b_wptr_dst = NULL;
@@ -1011,7 +1011,7 @@ wuffs_zlib__status wuffs_zlib__decoder__decode(wuffs_zlib__decoder* self,
uint32_t coro_susp_point = self->private_impl.c_decode[0].coro_susp_point; uint32_t coro_susp_point = self->private_impl.c_decode[0].coro_susp_point;
if (coro_susp_point) { if (coro_susp_point) {
v_x = self->private_impl.c_decode[0].v_x; v_x = self->private_impl.c_decode[0].v_x;
v_checksum = self->private_impl.c_decode[0].v_checksum; v_checksum_got = self->private_impl.c_decode[0].v_checksum_got;
v_z = self->private_impl.c_decode[0].v_z; v_z = self->private_impl.c_decode[0].v_z;
} else { } else {
} }
@@ -1062,7 +1062,7 @@ wuffs_zlib__status wuffs_zlib__decoder__decode(wuffs_zlib__decoder* self,
status = WUFFS_ZLIB__ERROR_INVALID_ZLIB_PARITY_CHECK; status = WUFFS_ZLIB__ERROR_INVALID_ZLIB_PARITY_CHECK;
goto exit; goto exit;
} }
v_checksum = 0; v_checksum_got = 0;
while (true) { while (true) {
wuffs_base__writer1__mark(&a_dst, b_wptr_dst); wuffs_base__writer1__mark(&a_dst, b_wptr_dst);
{ {
@@ -1098,8 +1098,8 @@ wuffs_zlib__status wuffs_zlib__decoder__decode(wuffs_zlib__decoder* self,
v_z = t_2; v_z = t_2;
} }
if (!self->private_impl.f_ignore_checksum) { if (!self->private_impl.f_ignore_checksum) {
v_checksum = wuffs_zlib__adler32__update( v_checksum_got = wuffs_zlib__adler32__update(
&self->private_impl.f_adler, &self->private_impl.f_checksum,
((wuffs_base__slice_u8){ ((wuffs_base__slice_u8){
.ptr = a_dst.private_impl.mark, .ptr = a_dst.private_impl.mark,
.len = a_dst.private_impl.mark .len = a_dst.private_impl.mark
@@ -1139,7 +1139,7 @@ wuffs_zlib__status wuffs_zlib__decoder__decode(wuffs_zlib__decoder* self,
self->private_impl.c_decode[0].scratch |= ((uint64_t)(t_3)); self->private_impl.c_decode[0].scratch |= ((uint64_t)(t_3));
} }
} }
if (!self->private_impl.f_ignore_checksum && (v_checksum != t_4)) { if (!self->private_impl.f_ignore_checksum && (v_checksum_got != t_4)) {
status = WUFFS_ZLIB__ERROR_CHECKSUM_MISMATCH; status = WUFFS_ZLIB__ERROR_CHECKSUM_MISMATCH;
goto exit; goto exit;
} }
@@ -1154,7 +1154,7 @@ wuffs_zlib__status wuffs_zlib__decoder__decode(wuffs_zlib__decoder* self,
suspend: suspend:
self->private_impl.c_decode[0].coro_susp_point = coro_susp_point; self->private_impl.c_decode[0].coro_susp_point = coro_susp_point;
self->private_impl.c_decode[0].v_x = v_x; self->private_impl.c_decode[0].v_x = v_x;
self->private_impl.c_decode[0].v_checksum = v_checksum; self->private_impl.c_decode[0].v_checksum_got = v_checksum_got;
self->private_impl.c_decode[0].v_z = v_z; self->private_impl.c_decode[0].v_z = v_z;
goto exit; goto exit;
+1 -1
View File
@@ -518,7 +518,7 @@ typedef struct {
uint8_t v_flags; uint8_t v_flags;
uint8_t v_c; uint8_t v_c;
uint16_t v_xlen; uint16_t v_xlen;
uint32_t v_checksum; uint32_t v_checksum_got;
wuffs_gzip__status v_z; wuffs_gzip__status v_z;
uint64_t scratch; uint64_t scratch;
} c_decode[1]; } c_decode[1];
+2 -2
View File
@@ -440,13 +440,13 @@ typedef struct {
uint32_t magic; uint32_t magic;
wuffs_deflate__decoder f_flate; wuffs_deflate__decoder f_flate;
wuffs_zlib__adler32 f_adler; wuffs_zlib__adler32 f_checksum;
bool f_ignore_checksum; bool f_ignore_checksum;
struct { struct {
uint32_t coro_susp_point; uint32_t coro_susp_point;
uint16_t v_x; uint16_t v_x;
uint32_t v_checksum; uint32_t v_checksum_got;
wuffs_zlib__status v_z; wuffs_zlib__status v_z;
uint64_t scratch; uint64_t scratch;
} c_decode[1]; } c_decode[1];
+3 -3
View File
@@ -89,12 +89,12 @@ pub func decoder.decode?(dst writer1, src reader1)() {
} }
// Decode and checksum the DEFLATE-encoded payload. // Decode and checksum the DEFLATE-encoded payload.
var checksum u32 var checksum_got u32
while true { while true {
in.dst.mark() in.dst.mark()
var z status = try this.flate.decode?(dst:in.dst, src:in.src) var z status = try this.flate.decode?(dst:in.dst, src:in.src)
if not this.ignore_checksum { if not this.ignore_checksum {
// TODO: checksum = this.checksum.update(x:in.dst.since_mark()) // TODO: checksum_got = this.checksum.update(x:in.dst.since_mark())
} }
if z.is_ok() { if z.is_ok() {
break break
@@ -102,7 +102,7 @@ pub func decoder.decode?(dst writer1, src reader1)() {
yield z yield z
} }
// TODO: read the 4 bytes regardless of this.ignore_checksum. // TODO: read the 4 bytes regardless of this.ignore_checksum.
if (not this.ignore_checksum) and (checksum != in.src.read_u32be?()) { if (not this.ignore_checksum) and (checksum_got != in.src.read_u32be?()) {
// TODO: return error "checksum mismatch" // TODO: return error "checksum mismatch"
} }
// TODO: handle the 4 byte ISIZE field. // TODO: handle the 4 byte ISIZE field.
+4 -4
View File
@@ -25,7 +25,7 @@ pub error "TODO: unsupported zlib preset dictionary"
pub struct decoder?( pub struct decoder?(
flate deflate.decoder, flate deflate.decoder,
adler adler32, checksum adler32,
ignore_checksum bool, ignore_checksum bool,
) )
@@ -49,12 +49,12 @@ pub func decoder.decode?(dst writer1, src reader1)() {
} }
// Decode and checksum the DEFLATE-encoded payload. // Decode and checksum the DEFLATE-encoded payload.
var checksum u32 var checksum_got u32
while true { while true {
in.dst.mark() in.dst.mark()
var z status = try this.flate.decode?(dst:in.dst, src:in.src) var z status = try this.flate.decode?(dst:in.dst, src:in.src)
if not this.ignore_checksum { if not this.ignore_checksum {
checksum = this.adler.update(x:in.dst.since_mark()) checksum_got = this.checksum.update(x:in.dst.since_mark())
} }
if z.is_ok() { if z.is_ok() {
break break
@@ -62,7 +62,7 @@ pub func decoder.decode?(dst writer1, src reader1)() {
yield z yield z
} }
// TODO: read the 4 bytes regardless of this.ignore_checksum. // TODO: read the 4 bytes regardless of this.ignore_checksum.
if (not this.ignore_checksum) and (checksum != in.src.read_u32be?()) { if (not this.ignore_checksum) and (checksum_got != in.src.read_u32be?()) {
return error "checksum mismatch" return error "checksum mismatch"
} }
} }