diff --git a/gen/c/std/flate.c b/gen/c/std/flate.c index f7457d24..604774c4 100644 --- a/gen/c/std/flate.c +++ b/gen/c/std/flate.c @@ -129,20 +129,6 @@ const char* puffs_flate_status_string(puffs_flate_status s); // ---------------- Structs -typedef struct { - // Do not access the private_impl's fields directly. There is no API/ABI - // compatibility or safety guarantee if you do so. Instead, use the - // puffs_flate_huffman_decoder_etc functions. - // - // In C++, these fields would be "private", but C does not support that. - // - // It is a struct, not a struct*, so that it can be stack allocated. - struct { - uint16_t f_counts[16]; - uint16_t f_symbols[290]; - } private_impl; -} puffs_flate_huffman_decoder; - typedef struct { // Do not access the private_impl's fields directly. There is no API/ABI // compatibility or safety guarantee if you do so. Instead, use the @@ -158,8 +144,9 @@ typedef struct { uint32_t f_bits; uint32_t f_n_bits; - puffs_flate_huffman_decoder f_huffs[2]; uint8_t f_code_lengths[316]; + uint16_t f_counts[16]; + uint16_t f_symbols[290]; struct { uint32_t coro_susp_point; @@ -846,8 +833,7 @@ puffs_flate_status puffs_flate_decoder_init_huffs(puffs_flate_decoder* self, } v_bits >>= 1; v_n_bits -= 1; - v_count = ((uint32_t)( - self->private_impl.f_huffs[0].private_impl.f_counts[v_length])); + v_count = ((uint32_t)(self->private_impl.f_counts[v_length])); if (v_count > 65535) { status = PUFFS_FLATE_ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE; @@ -866,8 +852,7 @@ puffs_flate_status puffs_flate_decoder_init_huffs(puffs_flate_decoder* self, PUFFS_FLATE_ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE; goto exit; } - v_symbol = ((uint32_t)( - self->private_impl.f_huffs[0].private_impl.f_symbols[v_index])); + v_symbol = ((uint32_t)(self->private_impl.f_symbols[v_index])); goto label_1_break; } v_index += v_count; @@ -1014,25 +999,21 @@ puffs_flate_status puffs_flate_decoder_init_huff(puffs_flate_decoder* self, v_i = 0; while (v_i < 16) { - self->private_impl.f_huffs[a_which].private_impl.f_counts[v_i] = 0; + self->private_impl.f_counts[v_i] = 0; v_i += 1; } v_i = 0; while (v_i < a_n_codes) { - if (self->private_impl.f_huffs[a_which] - .private_impl.f_counts[self->private_impl.f_code_lengths[v_i]] >= + if (self->private_impl.f_counts[self->private_impl.f_code_lengths[v_i]] >= 289) { status = PUFFS_FLATE_ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE; goto exit; } - self->private_impl.f_huffs[a_which] - .private_impl.f_counts[self->private_impl.f_code_lengths[v_i]] += 1; + self->private_impl.f_counts[self->private_impl.f_code_lengths[v_i]] += 1; v_i += 1; } - if (((uint32_t)( - self->private_impl.f_huffs[a_which].private_impl.f_counts[0])) == - a_n_codes) { + if (((uint32_t)(self->private_impl.f_counts[0])) == a_n_codes) { status = PUFFS_FLATE_ERROR_NO_HUFFMAN_CODES; goto exit; } @@ -1046,7 +1027,7 @@ puffs_flate_status puffs_flate_decoder_init_huff(puffs_flate_decoder* self, v_i = 1; while (v_i <= 15) { v_offsets[v_i] = v_total; - v_count = self->private_impl.f_huffs[a_which].private_impl.f_counts[v_i]; + v_count = self->private_impl.f_counts[v_i]; if (v_total > (289 - v_count)) { status = PUFFS_FLATE_ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE; @@ -1058,8 +1039,7 @@ puffs_flate_status puffs_flate_decoder_init_huff(puffs_flate_decoder* self, v_i = 0; while (v_i < a_n_codes) { if (self->private_impl.f_code_lengths[v_i] != 0) { - self->private_impl.f_huffs[a_which] - .private_impl + self->private_impl .f_symbols[v_offsets[self->private_impl.f_code_lengths[v_i]]] = ((uint16_t)(v_i)); if (v_offsets[self->private_impl.f_code_lengths[v_i]] >= 289) { diff --git a/gen/h/std/flate.h b/gen/h/std/flate.h index 37d35afe..fb4ed265 100644 --- a/gen/h/std/flate.h +++ b/gen/h/std/flate.h @@ -129,20 +129,6 @@ const char* puffs_flate_status_string(puffs_flate_status s); // ---------------- Structs -typedef struct { - // Do not access the private_impl's fields directly. There is no API/ABI - // compatibility or safety guarantee if you do so. Instead, use the - // puffs_flate_huffman_decoder_etc functions. - // - // In C++, these fields would be "private", but C does not support that. - // - // It is a struct, not a struct*, so that it can be stack allocated. - struct { - uint16_t f_counts[16]; - uint16_t f_symbols[290]; - } private_impl; -} puffs_flate_huffman_decoder; - typedef struct { // Do not access the private_impl's fields directly. There is no API/ABI // compatibility or safety guarantee if you do so. Instead, use the @@ -158,8 +144,9 @@ typedef struct { uint32_t f_bits; uint32_t f_n_bits; - puffs_flate_huffman_decoder f_huffs[2]; uint8_t f_code_lengths[316]; + uint16_t f_counts[16]; + uint16_t f_symbols[290]; struct { uint32_t coro_susp_point; diff --git a/std/flate/decode_flate.puffs b/std/flate/decode_flate.puffs index 4b452e7f..3f200ba4 100644 --- a/std/flate/decode_flate.puffs +++ b/std/flate/decode_flate.puffs @@ -28,9 +28,13 @@ pub struct decoder?( // package's README.md: // - huffs[0] is used for clcode and lcode. // - huffs[1] is used for dcode. - huffs[2] huffman_decoder, + // TODO: define the huffs field. + // These fields are used as scratch space when constructing the huffs + // tables. code_lengths[316] u8[..15], + counts[16] u16[..289], + symbols[290] u16[..289], ) pub func decoder.decode?(dst writer1, src reader1)() { @@ -182,7 +186,7 @@ pri func decoder.init_huffs?(src reader1)() { bits >>= 1 n_bits -= 1 - count = this.huffs[0].counts[length] as u32 + count = this.counts[length] as u32 if count > 0xFFFF { return error "internal error: inconsistent Huffman decoder state" } @@ -224,7 +228,7 @@ pri func decoder.init_huffs?(src reader1)() { if index >= 290 { return error "internal error: inconsistent Huffman decoder state" } - symbol = this.huffs[0].symbols[index] as u32 + symbol = this.symbols[index] as u32 break } @@ -345,7 +349,7 @@ pri func decoder.init_huff?(which u32[..1], n_codes u32[..289])() { var i u32 while i < 16 { - this.huffs[in.which].counts[i] = 0 + this.counts[i] = 0 i += 1 } i = 0 @@ -353,13 +357,13 @@ pri func decoder.init_huff?(which u32[..1], n_codes u32[..289])() { assert i < 289 via "a < b: a < c; c <= b"(c:in.n_codes) // 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 this.huffs[in.which].counts[this.code_lengths[i]] >= 289 { + if this.counts[this.code_lengths[i]] >= 289 { return error "internal error: inconsistent Huffman decoder state" } - this.huffs[in.which].counts[this.code_lengths[i]] += 1 + this.counts[this.code_lengths[i]] += 1 i += 1 } - if (this.huffs[in.which].counts[0] as u32) == in.n_codes { + if (this.counts[0] as u32) == in.n_codes { return error "no Huffman codes" } @@ -379,7 +383,7 @@ pri func decoder.init_huff?(which u32[..1], n_codes u32[..289])() { i = 1 while i <= 15 { offsets[i] = total - var count u16[..289] = this.huffs[in.which].counts[i] + var count u16[..289] = this.counts[i] if total > (289 - count) { return error "internal error: inconsistent Huffman decoder state" } @@ -404,7 +408,7 @@ pri func decoder.init_huff?(which u32[..1], n_codes u32[..289])() { while i < in.n_codes { assert i < 289 via "a < b: a < c; c <= b"(c:in.n_codes) if this.code_lengths[i] != 0 { - this.huffs[in.which].symbols[offsets[this.code_lengths[i]]] = i as u16 + this.symbols[offsets[this.code_lengths[i]]] = i as u16 if offsets[this.code_lengths[i]] >= 289 { return error "internal error: inconsistent Huffman decoder state" } @@ -430,8 +434,3 @@ pri func decoder.init_huff?(which u32[..1], n_codes u32[..289])() { // - offsets[4] = 8, formerly 7 // - offsets[5] = 10, formerly 8 } - -pri struct huffman_decoder( - counts[16] u16[..289], - symbols[290] u16[..289], -)