Rename unread_u8? to undo_byte!; add can_undo_byte

This commit is contained in:
Nigel Tao committed 2018-07-08 21:02:29 +10:00
1 parent ce3d99a6d5
commit 9e300fc4f8
14 files changed
+148 -154

No files matched your search

+3 -2
View File
@@ -30,8 +30,9 @@ pub error (0x0D) "no Huffman codes"
pri error (0x40) "internal error: inconsistent Huffman decoder state"
pri error (0x41) "internal error: inconsistent Huffman end_of_block"
pri error (0x42) "internal error: inconsistent distance"
pri error (0x43) "internal error: inconsistent n_bits"
pub error (0x42) "internal error: inconsistent I/O"
pri error (0x43) "internal error: inconsistent distance"
pri error (0x44) "internal error: inconsistent n_bits"
// The next two tables were created by script/print-deflate-magic-numbers.go.
//
+6 -5
View File
@@ -368,21 +368,22 @@ pri func decoder.decode_huffman_fast?(dst base.io_writer, src base.io_reader)()
// Ensure n_bits < 8 by rewindng in.src, if we loaded too many of its bytes
// into the bits variable.
//
// Note that we can unconditionally call unread_u8 (without resulting in an
// Note that we can unconditionally call undo_read (without resulting in an
// "invalid I/O operation" error code) only because this whole function can
// never suspend, as all of its I/O operations were checked beforehand for
// sufficient buffer space. Otherwise, resuming from the suspension could
// mean that the (possibly different) in.src is no longer rewindable, even
// if conceptually, this function was responsible for reading the bytes we
// want to rewind.
//
// TODO: have the compiler enforce (via some explicit syntax) that this
// function is ProvenNotToSuspend?
while n_bits >= 8,
post n_bits < 8,
{
n_bits -= 8
in.src.unread_u8?()
if in.src.can_undo_byte() {
in.src.undo_byte!()
} else {
return error "internal error: inconsistent I/O"
}
}
this.bits = bits & (((1 as base.u32) << n_bits) - 1)