mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 16:55:11 +01:00
Fix some hasher methods' effects
This commit is contained in:
1 parent
131732e7eb
commit
dfc8e14f4f
4 files changed
+6
-7
No files matched your search
@@ -19,8 +19,7 @@ pub struct hasher?(
|
|||||||
state base.u32 = 1,
|
state base.u32 = 1,
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: add a ! as this function is impure.
|
pub func hasher.update!(x slice base.u8)(checksum base.u32) {
|
||||||
pub func hasher.update(x slice base.u8)(checksum base.u32) {
|
|
||||||
// The Adler-32 checksum's magic 65521 and 5552 numbers are discussed in
|
// The Adler-32 checksum's magic 65521 and 5552 numbers are discussed in
|
||||||
// RFC 1950.
|
// RFC 1950.
|
||||||
|
|
||||||
@@ -45,6 +44,8 @@ pub func hasher.update(x slice base.u8)(checksum base.u32) {
|
|||||||
in.x = remaining
|
in.x = remaining
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: check that you can't assign to this.foo unless the method's effect
|
||||||
|
// is "!" impure or "?" impure coroutine.
|
||||||
this.state = ((s2 & 0xFFFF) << 16) | (s1 & 0xFFFF)
|
this.state = ((s2 & 0xFFFF) << 16) | (s1 & 0xFFFF)
|
||||||
return this.state
|
return this.state
|
||||||
}
|
}
|
||||||
@@ -19,12 +19,10 @@ pub struct ieee_hasher?(
|
|||||||
state base.u32,
|
state base.u32,
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: add a ! as this function is impure.
|
|
||||||
//
|
|
||||||
// TODO: should it be ? instead of ! because it's public, and might need a way
|
// TODO: should it be ? instead of ! because it's public, and might need a way
|
||||||
// to signal "initializer not called"? Should the return type, in the generated
|
// to signal "initializer not called"? Should the return type, in the generated
|
||||||
// C code, be "struct{ uint32_t checksum; wuffs_crc32__status status }"?
|
// C code, be "struct{ uint32_t checksum; wuffs_crc32__status status }"?
|
||||||
pub func ieee_hasher.update(x slice base.u8)(checksum base.u32) {
|
pub func ieee_hasher.update!(x slice base.u8)(checksum base.u32) {
|
||||||
var s base.u32 = 0xFFFFFFFF ^ this.state
|
var s base.u32 = 0xFFFFFFFF ^ this.state
|
||||||
|
|
||||||
iterate (p slice base.u8 =: in.x)(length:8, unroll:8) {
|
iterate (p slice base.u8 =: in.x)(length:8, unroll:8) {
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ pub func decoder.decode?(dst base.io_writer, src base.io_reader)() {
|
|||||||
in.dst.set_mark!()
|
in.dst.set_mark!()
|
||||||
var z base.status = try this.flate.decode?(dst:in.dst, src:in.src)
|
var z base.status = try this.flate.decode?(dst:in.dst, src:in.src)
|
||||||
if not this.ignore_checksum {
|
if not this.ignore_checksum {
|
||||||
checksum_got = this.checksum.update(x:in.dst.since_mark())
|
checksum_got = this.checksum.update!(x:in.dst.since_mark())
|
||||||
decoded_length_got ~mod+= ((in.dst.since_mark().length() & 0xFFFFFFFF) as base.u32)
|
decoded_length_got ~mod+= ((in.dst.since_mark().length() & 0xFFFFFFFF) as base.u32)
|
||||||
}
|
}
|
||||||
if z.is_ok() {
|
if z.is_ok() {
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ pub func decoder.decode?(dst base.io_writer, src base.io_reader)() {
|
|||||||
in.dst.set_mark!()
|
in.dst.set_mark!()
|
||||||
var z base.status = try this.flate.decode?(dst:in.dst, src:in.src)
|
var z base.status = try this.flate.decode?(dst:in.dst, src:in.src)
|
||||||
if not this.ignore_checksum {
|
if not this.ignore_checksum {
|
||||||
checksum_got = this.checksum.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
|
||||||
|
|||||||
Reference in new issue
Block a user