Rename std/flate's decoder to flate_decoder.

This commit is contained in:
Nigel Tao committed 2017-10-21 13:05:19 +11:00
1 parent 1c75edb32e
commit 2639f8f46a
8 files changed
+132 -119

No files matched your search

+1 -1
View File
@@ -556,7 +556,7 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
temp := g.currFunk.tempW temp := g.currFunk.tempW
g.currFunk.tempW++ g.currFunk.tempW++
b.printf("%sstatus %s%d = %sdecoder_decode(&self->private_impl.f_dec, %sdst, %ssrc);\n", b.printf("%sstatus %s%d = %sflate_decoder_decode(&self->private_impl.f_flate, %sdst, %ssrc);\n",
g.pkgPrefix, tPrefix, temp, g.pkgPrefix, tPrefix, temp,
g.pkgPrefix, aPrefix, aPrefix) g.pkgPrefix, aPrefix, aPrefix)
if err := g.writeLoadExprDerivedVars(b, n); err != nil { if err := g.writeLoadExprDerivedVars(b, n); err != nil {
+3 -3
View File
@@ -54,10 +54,10 @@ static const char* decode() {
puffs_base_writer1 dst_writer = {.buf = &dst}; puffs_base_writer1 dst_writer = {.buf = &dst};
puffs_base_reader1 src_reader = {.buf = &src}; puffs_base_reader1 src_reader = {.buf = &src};
puffs_flate_decoder dec; puffs_flate_flate_decoder dec;
puffs_flate_decoder_initialize(&dec, PUFFS_VERSION, 0); puffs_flate_flate_decoder_initialize(&dec, PUFFS_VERSION, 0);
puffs_flate_status s = puffs_flate_status s =
puffs_flate_decoder_decode(&dec, dst_writer, src_reader); puffs_flate_flate_decoder_decode(&dec, dst_writer, src_reader);
if (s) { if (s) {
return puffs_flate_status_string(s); return puffs_flate_status_string(s);
} }
+76 -68
View File
@@ -163,7 +163,7 @@ const char* puffs_flate_status_string(puffs_flate_status s);
typedef struct { typedef struct {
// Do not access the private_impl's fields directly. There is no API/ABI // 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 // compatibility or safety guarantee if you do so. Instead, use the
// puffs_flate_decoder_etc functions. // puffs_flate_flate_decoder_etc functions.
// //
// In C++, these fields would be "private", but C does not support that. // In C++, these fields would be "private", but C does not support that.
// //
@@ -233,7 +233,7 @@ typedef struct {
uint32_t v_rep_count; uint32_t v_rep_count;
} c_init_dynamic_huffman[1]; } c_init_dynamic_huffman[1];
} private_impl; } private_impl;
} puffs_flate_decoder; } puffs_flate_flate_decoder;
typedef struct { typedef struct {
// Do not access the private_impl's fields directly. There is no API/ABI // Do not access the private_impl's fields directly. There is no API/ABI
@@ -264,7 +264,7 @@ typedef struct {
puffs_flate_status status; puffs_flate_status status;
uint32_t magic; uint32_t magic;
puffs_flate_decoder f_dec; puffs_flate_flate_decoder f_flate;
puffs_flate_adler32 f_adler; puffs_flate_adler32 f_adler;
struct { struct {
@@ -279,14 +279,14 @@ typedef struct {
// ---------------- Public Initializer Prototypes // ---------------- Public Initializer Prototypes
// puffs_flate_decoder_initialize is an initializer function. // puffs_flate_flate_decoder_initialize is an initializer function.
// //
// It should be called before any other puffs_flate_decoder_* function. // It should be called before any other puffs_flate_flate_decoder_* function.
// //
// Pass PUFFS_VERSION and 0 for puffs_version and for_internal_use_only. // Pass PUFFS_VERSION and 0 for puffs_version and for_internal_use_only.
void puffs_flate_decoder_initialize(puffs_flate_decoder* self, void puffs_flate_flate_decoder_initialize(puffs_flate_flate_decoder* self,
uint32_t puffs_version, uint32_t puffs_version,
uint32_t for_internal_use_only); uint32_t for_internal_use_only);
// puffs_flate_zlib_decoder_initialize is an initializer function. // puffs_flate_zlib_decoder_initialize is an initializer function.
// //
@@ -299,9 +299,10 @@ void puffs_flate_zlib_decoder_initialize(puffs_flate_zlib_decoder* self,
// ---------------- Public Function Prototypes // ---------------- Public Function Prototypes
puffs_flate_status puffs_flate_decoder_decode(puffs_flate_decoder* self, puffs_flate_status puffs_flate_flate_decoder_decode(
puffs_base_writer1 a_dst, puffs_flate_flate_decoder* self,
puffs_base_reader1 a_src); puffs_base_writer1 a_dst,
puffs_base_reader1 a_src);
puffs_flate_status puffs_flate_zlib_decoder_decode( puffs_flate_status puffs_flate_zlib_decoder_decode(
puffs_flate_zlib_decoder* self, puffs_flate_zlib_decoder* self,
@@ -674,31 +675,34 @@ void puffs_flate_adler32_initialize(puffs_flate_adler32* self,
// ---------------- Private Function Prototypes // ---------------- Private Function Prototypes
puffs_flate_status puffs_flate_decoder_decode_blocks(puffs_flate_decoder* self, puffs_flate_status puffs_flate_flate_decoder_decode_blocks(
puffs_base_writer1 a_dst, puffs_flate_flate_decoder* self,
puffs_base_reader1 a_src);
puffs_flate_status puffs_flate_decoder_decode_uncompressed(
puffs_flate_decoder* self,
puffs_base_writer1 a_dst, puffs_base_writer1 a_dst,
puffs_base_reader1 a_src); puffs_base_reader1 a_src);
puffs_flate_status puffs_flate_decoder_decode_huffman(puffs_flate_decoder* self, puffs_flate_status puffs_flate_flate_decoder_decode_uncompressed(
puffs_base_writer1 a_dst, puffs_flate_flate_decoder* self,
puffs_base_reader1 a_src); puffs_base_writer1 a_dst,
puffs_flate_status puffs_flate_decoder_init_fixed_huffman(
puffs_flate_decoder* self);
puffs_flate_status puffs_flate_decoder_init_dynamic_huffman(
puffs_flate_decoder* self,
puffs_base_reader1 a_src); puffs_base_reader1 a_src);
puffs_flate_status puffs_flate_decoder_init_huff(puffs_flate_decoder* self, puffs_flate_status puffs_flate_flate_decoder_decode_huffman(
uint32_t a_which, puffs_flate_flate_decoder* self,
uint32_t a_n_codes0, puffs_base_writer1 a_dst,
uint32_t a_n_codes1, puffs_base_reader1 a_src);
uint32_t a_base_symbol);
puffs_flate_status puffs_flate_flate_decoder_init_fixed_huffman(
puffs_flate_flate_decoder* self);
puffs_flate_status puffs_flate_flate_decoder_init_dynamic_huffman(
puffs_flate_flate_decoder* self,
puffs_base_reader1 a_src);
puffs_flate_status puffs_flate_flate_decoder_init_huff(
puffs_flate_flate_decoder* self,
uint32_t a_which,
uint32_t a_n_codes0,
uint32_t a_n_codes1,
uint32_t a_base_symbol);
uint32_t puffs_flate_adler32_update(puffs_flate_adler32* self, uint32_t puffs_flate_adler32_update(puffs_flate_adler32* self,
puffs_base_slice_u8 a_x); puffs_base_slice_u8 a_x);
@@ -719,9 +723,9 @@ uint32_t puffs_flate_adler32_update(puffs_flate_adler32* self,
// Its (non-zero) value is arbitrary, based on md5sum("zeroed"). // Its (non-zero) value is arbitrary, based on md5sum("zeroed").
#define PUFFS_ALREADY_ZEROED (0x68602EF1U) #define PUFFS_ALREADY_ZEROED (0x68602EF1U)
void puffs_flate_decoder_initialize(puffs_flate_decoder* self, void puffs_flate_flate_decoder_initialize(puffs_flate_flate_decoder* self,
uint32_t puffs_version, uint32_t puffs_version,
uint32_t for_internal_use_only) { uint32_t for_internal_use_only) {
if (!self) { if (!self) {
return; return;
} }
@@ -766,17 +770,18 @@ void puffs_flate_zlib_decoder_initialize(puffs_flate_zlib_decoder* self,
memset(self, 0, sizeof(*self)); memset(self, 0, sizeof(*self));
} }
self->private_impl.magic = PUFFS_MAGIC; self->private_impl.magic = PUFFS_MAGIC;
puffs_flate_decoder_initialize(&self->private_impl.f_dec, PUFFS_VERSION, puffs_flate_flate_decoder_initialize(&self->private_impl.f_flate,
PUFFS_ALREADY_ZEROED); PUFFS_VERSION, PUFFS_ALREADY_ZEROED);
puffs_flate_adler32_initialize(&self->private_impl.f_adler, PUFFS_VERSION, puffs_flate_adler32_initialize(&self->private_impl.f_adler, PUFFS_VERSION,
PUFFS_ALREADY_ZEROED); PUFFS_ALREADY_ZEROED);
} }
// ---------------- Function Implementations // ---------------- Function Implementations
puffs_flate_status puffs_flate_decoder_decode(puffs_flate_decoder* self, puffs_flate_status puffs_flate_flate_decoder_decode(
puffs_base_writer1 a_dst, puffs_flate_flate_decoder* self,
puffs_base_reader1 a_src) { puffs_base_writer1 a_dst,
puffs_base_reader1 a_src) {
if (!self) { if (!self) {
return PUFFS_FLATE_ERROR_BAD_RECEIVER; return PUFFS_FLATE_ERROR_BAD_RECEIVER;
} }
@@ -835,7 +840,7 @@ puffs_flate_status puffs_flate_decoder_decode(puffs_flate_decoder* self,
} }
} }
puffs_flate_status t_0 = puffs_flate_status t_0 =
puffs_flate_decoder_decode_blocks(self, a_dst, a_src); puffs_flate_flate_decoder_decode_blocks(self, a_dst, a_src);
if (a_dst.buf) { if (a_dst.buf) {
b_wptr_dst = a_dst.buf->ptr + a_dst.buf->wi; b_wptr_dst = a_dst.buf->ptr + a_dst.buf->wi;
b_wend_dst = b_wptr_dst; b_wend_dst = b_wptr_dst;
@@ -926,9 +931,10 @@ exit:
return status; return status;
} }
puffs_flate_status puffs_flate_decoder_decode_blocks(puffs_flate_decoder* self, puffs_flate_status puffs_flate_flate_decoder_decode_blocks(
puffs_base_writer1 a_dst, puffs_flate_flate_decoder* self,
puffs_base_reader1 a_src) { puffs_base_writer1 a_dst,
puffs_base_reader1 a_src) {
puffs_flate_status status = PUFFS_FLATE_STATUS_OK; puffs_flate_status status = PUFFS_FLATE_STATUS_OK;
uint32_t v_final; uint32_t v_final;
@@ -988,7 +994,8 @@ puffs_flate_status puffs_flate_decoder_decode_blocks(puffs_flate_decoder* self,
} }
} }
} }
status = puffs_flate_decoder_decode_uncompressed(self, a_dst, a_src); status =
puffs_flate_flate_decoder_decode_uncompressed(self, a_dst, a_src);
if (a_src.buf) { if (a_src.buf) {
b_rptr_src = a_src.buf->ptr + a_src.buf->ri; b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
size_t len = a_src.buf->wi - a_src.buf->ri; size_t len = a_src.buf->wi - a_src.buf->ri;
@@ -1006,7 +1013,7 @@ puffs_flate_status puffs_flate_decoder_decode_blocks(puffs_flate_decoder* self,
goto label_0_continue; goto label_0_continue;
} else if (v_type == 1) { } else if (v_type == 1) {
PUFFS_COROUTINE_SUSPENSION_POINT(3); PUFFS_COROUTINE_SUSPENSION_POINT(3);
status = puffs_flate_decoder_init_fixed_huffman(self); status = puffs_flate_flate_decoder_init_fixed_huffman(self);
if (status) { if (status) {
goto suspend; goto suspend;
} }
@@ -1022,7 +1029,7 @@ puffs_flate_status puffs_flate_decoder_decode_blocks(puffs_flate_decoder* self,
} }
} }
} }
status = puffs_flate_decoder_init_dynamic_huffman(self, a_src); status = puffs_flate_flate_decoder_init_dynamic_huffman(self, a_src);
if (a_src.buf) { if (a_src.buf) {
b_rptr_src = a_src.buf->ptr + a_src.buf->ri; b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
size_t len = a_src.buf->wi - a_src.buf->ri; size_t len = a_src.buf->wi - a_src.buf->ri;
@@ -1052,7 +1059,7 @@ puffs_flate_status puffs_flate_decoder_decode_blocks(puffs_flate_decoder* self,
} }
} }
} }
status = puffs_flate_decoder_decode_huffman(self, a_dst, a_src); status = puffs_flate_flate_decoder_decode_huffman(self, a_dst, a_src);
if (a_src.buf) { if (a_src.buf) {
b_rptr_src = a_src.buf->ptr + a_src.buf->ri; b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
size_t len = a_src.buf->wi - a_src.buf->ri; size_t len = a_src.buf->wi - a_src.buf->ri;
@@ -1106,8 +1113,8 @@ short_read_src:
goto suspend; goto suspend;
} }
puffs_flate_status puffs_flate_decoder_decode_uncompressed( puffs_flate_status puffs_flate_flate_decoder_decode_uncompressed(
puffs_flate_decoder* self, puffs_flate_flate_decoder* self,
puffs_base_writer1 a_dst, puffs_base_writer1 a_dst,
puffs_base_reader1 a_src) { puffs_base_reader1 a_src) {
puffs_flate_status status = PUFFS_FLATE_STATUS_OK; puffs_flate_status status = PUFFS_FLATE_STATUS_OK;
@@ -1264,8 +1271,8 @@ short_read_src:
goto suspend; goto suspend;
} }
puffs_flate_status puffs_flate_decoder_decode_huffman( puffs_flate_status puffs_flate_flate_decoder_decode_huffman(
puffs_flate_decoder* self, puffs_flate_flate_decoder* self,
puffs_base_writer1 a_dst, puffs_base_writer1 a_dst,
puffs_base_reader1 a_src) { puffs_base_reader1 a_src) {
puffs_flate_status status = PUFFS_FLATE_STATUS_OK; puffs_flate_status status = PUFFS_FLATE_STATUS_OK;
@@ -1650,8 +1657,8 @@ short_read_src:
goto suspend; goto suspend;
} }
puffs_flate_status puffs_flate_decoder_init_fixed_huffman( puffs_flate_status puffs_flate_flate_decoder_init_fixed_huffman(
puffs_flate_decoder* self) { puffs_flate_flate_decoder* self) {
puffs_flate_status status = PUFFS_FLATE_STATUS_OK; puffs_flate_status status = PUFFS_FLATE_STATUS_OK;
uint32_t v_i; uint32_t v_i;
@@ -1686,12 +1693,12 @@ puffs_flate_status puffs_flate_decoder_init_fixed_huffman(
v_i += 1; v_i += 1;
} }
PUFFS_COROUTINE_SUSPENSION_POINT(1); PUFFS_COROUTINE_SUSPENSION_POINT(1);
status = puffs_flate_decoder_init_huff(self, 0, 0, 288, 257); status = puffs_flate_flate_decoder_init_huff(self, 0, 0, 288, 257);
if (status) { if (status) {
goto suspend; goto suspend;
} }
PUFFS_COROUTINE_SUSPENSION_POINT(2); PUFFS_COROUTINE_SUSPENSION_POINT(2);
status = puffs_flate_decoder_init_huff(self, 1, 288, 320, 0); status = puffs_flate_flate_decoder_init_huff(self, 1, 288, 320, 0);
if (status) { if (status) {
goto suspend; goto suspend;
} }
@@ -1711,8 +1718,8 @@ exit:
return status; return status;
} }
puffs_flate_status puffs_flate_decoder_init_dynamic_huffman( puffs_flate_status puffs_flate_flate_decoder_init_dynamic_huffman(
puffs_flate_decoder* self, puffs_flate_flate_decoder* self,
puffs_base_reader1 a_src) { puffs_base_reader1 a_src) {
puffs_flate_status status = PUFFS_FLATE_STATUS_OK; puffs_flate_status status = PUFFS_FLATE_STATUS_OK;
@@ -1814,7 +1821,7 @@ puffs_flate_status puffs_flate_decoder_init_dynamic_huffman(
v_i += 1; v_i += 1;
} }
PUFFS_COROUTINE_SUSPENSION_POINT(3); PUFFS_COROUTINE_SUSPENSION_POINT(3);
status = puffs_flate_decoder_init_huff(self, 0, 0, 19, 4095); status = puffs_flate_flate_decoder_init_huff(self, 0, 0, 19, 4095);
if (status) { if (status) {
goto suspend; goto suspend;
} }
@@ -1906,13 +1913,13 @@ puffs_flate_status puffs_flate_decoder_init_dynamic_huffman(
goto exit; goto exit;
} }
PUFFS_COROUTINE_SUSPENSION_POINT(6); PUFFS_COROUTINE_SUSPENSION_POINT(6);
status = puffs_flate_decoder_init_huff(self, 0, 0, v_n_lit, 257); status = puffs_flate_flate_decoder_init_huff(self, 0, 0, v_n_lit, 257);
if (status) { if (status) {
goto suspend; goto suspend;
} }
PUFFS_COROUTINE_SUSPENSION_POINT(7); PUFFS_COROUTINE_SUSPENSION_POINT(7);
status = puffs_flate_decoder_init_huff(self, 1, v_n_lit, status = puffs_flate_flate_decoder_init_huff(self, 1, v_n_lit,
(v_n_lit + v_n_dist), 0); (v_n_lit + v_n_dist), 0);
if (status) { if (status) {
goto suspend; goto suspend;
} }
@@ -1968,11 +1975,12 @@ short_read_src:
goto suspend; goto suspend;
} }
puffs_flate_status puffs_flate_decoder_init_huff(puffs_flate_decoder* self, puffs_flate_status puffs_flate_flate_decoder_init_huff(
uint32_t a_which, puffs_flate_flate_decoder* self,
uint32_t a_n_codes0, uint32_t a_which,
uint32_t a_n_codes1, uint32_t a_n_codes0,
uint32_t a_base_symbol) { uint32_t a_n_codes1,
uint32_t a_base_symbol) {
puffs_flate_status status = PUFFS_FLATE_STATUS_OK; puffs_flate_status status = PUFFS_FLATE_STATUS_OK;
uint16_t v_counts[16]; uint16_t v_counts[16];
@@ -2374,8 +2382,8 @@ puffs_flate_status puffs_flate_zlib_decoder_decode(
} }
} }
} }
puffs_flate_status t_2 = puffs_flate_status t_2 = puffs_flate_flate_decoder_decode(
puffs_flate_decoder_decode(&self->private_impl.f_dec, a_dst, a_src); &self->private_impl.f_flate, a_dst, a_src);
if (a_dst.buf) { if (a_dst.buf) {
b_wptr_dst = a_dst.buf->ptr + a_dst.buf->wi; b_wptr_dst = a_dst.buf->ptr + a_dst.buf->wi;
b_wend_dst = b_wptr_dst; b_wend_dst = b_wptr_dst;
+12 -11
View File
@@ -163,7 +163,7 @@ const char* puffs_flate_status_string(puffs_flate_status s);
typedef struct { typedef struct {
// Do not access the private_impl's fields directly. There is no API/ABI // 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 // compatibility or safety guarantee if you do so. Instead, use the
// puffs_flate_decoder_etc functions. // puffs_flate_flate_decoder_etc functions.
// //
// In C++, these fields would be "private", but C does not support that. // In C++, these fields would be "private", but C does not support that.
// //
@@ -233,7 +233,7 @@ typedef struct {
uint32_t v_rep_count; uint32_t v_rep_count;
} c_init_dynamic_huffman[1]; } c_init_dynamic_huffman[1];
} private_impl; } private_impl;
} puffs_flate_decoder; } puffs_flate_flate_decoder;
typedef struct { typedef struct {
// Do not access the private_impl's fields directly. There is no API/ABI // Do not access the private_impl's fields directly. There is no API/ABI
@@ -264,7 +264,7 @@ typedef struct {
puffs_flate_status status; puffs_flate_status status;
uint32_t magic; uint32_t magic;
puffs_flate_decoder f_dec; puffs_flate_flate_decoder f_flate;
puffs_flate_adler32 f_adler; puffs_flate_adler32 f_adler;
struct { struct {
@@ -279,14 +279,14 @@ typedef struct {
// ---------------- Public Initializer Prototypes // ---------------- Public Initializer Prototypes
// puffs_flate_decoder_initialize is an initializer function. // puffs_flate_flate_decoder_initialize is an initializer function.
// //
// It should be called before any other puffs_flate_decoder_* function. // It should be called before any other puffs_flate_flate_decoder_* function.
// //
// Pass PUFFS_VERSION and 0 for puffs_version and for_internal_use_only. // Pass PUFFS_VERSION and 0 for puffs_version and for_internal_use_only.
void puffs_flate_decoder_initialize(puffs_flate_decoder* self, void puffs_flate_flate_decoder_initialize(puffs_flate_flate_decoder* self,
uint32_t puffs_version, uint32_t puffs_version,
uint32_t for_internal_use_only); uint32_t for_internal_use_only);
// puffs_flate_zlib_decoder_initialize is an initializer function. // puffs_flate_zlib_decoder_initialize is an initializer function.
// //
@@ -299,9 +299,10 @@ void puffs_flate_zlib_decoder_initialize(puffs_flate_zlib_decoder* self,
// ---------------- Public Function Prototypes // ---------------- Public Function Prototypes
puffs_flate_status puffs_flate_decoder_decode(puffs_flate_decoder* self, puffs_flate_status puffs_flate_flate_decoder_decode(
puffs_base_writer1 a_dst, puffs_flate_flate_decoder* self,
puffs_base_reader1 a_src); puffs_base_writer1 a_dst,
puffs_base_reader1 a_src);
puffs_flate_status puffs_flate_zlib_decoder_decode( puffs_flate_status puffs_flate_zlib_decoder_decode(
puffs_flate_zlib_decoder* self, puffs_flate_zlib_decoder* self,
@@ -40,6 +40,8 @@
// //
// status = puffs_flate_decoder_decode_huffman(self, a_dst, a_src); // status = puffs_flate_decoder_decode_huffman(self, a_dst, a_src);
// //
// TODO: "puffs_flate_decoder" should be "puffs_flate_flate_decoder".
//
// Change the "puffs" to "c_puffs", i.e. add a "c_" prefix. The net result // Change the "puffs" to "c_puffs", i.e. add a "c_" prefix. The net result
// should look something like: // should look something like:
// //
+20 -19
View File
@@ -33,9 +33,9 @@ pub error "no Huffman codes"
// The next two tables were created by script/print-flate-magic-numbers.go. // The next two tables were created by script/print-flate-magic-numbers.go.
// //
// The u32 values' meanings are the same as the decoder.huffs u32 values. In // The u32 values' meanings are the same as the flate_decoder.huffs u32 values.
// particular, bit 30 indicates a base number + extra bits, bits 23-8 are the // In particular, bit 30 indicates a base number + extra bits, bits 23-8 are
// base number and bits 7-4 are the number of those extra bits. // the base number and bits 7-4 are the number of those extra bits.
// //
// Some trailing elements are 0x08000000. Bit 27 indicates an invalid value. // Some trailing elements are 0x08000000. Bit 27 indicates an invalid value.
@@ -53,7 +53,7 @@ pri const dcode_magic_numbers[32] u32 = $(
0x401001B0, 0x401801B0, 0x402001C0, 0x403001C0, 0x404001D0, 0x406001D0, 0x08000000, 0x08000000, 0x401001B0, 0x401801B0, 0x402001C0, 0x403001C0, 0x404001D0, 0x406001D0, 0x08000000, 0x08000000,
) )
pub struct decoder?( pub struct flate_decoder?(
// These fields yield src's bits in Least Significant Bits order. // These fields yield src's bits in Least Significant Bits order.
bits u32, bits u32,
n_bits u32, n_bits u32,
@@ -65,16 +65,17 @@ pub struct decoder?(
// - huffs[0] is used for clcode and lcode. // - huffs[0] is used for clcode and lcode.
// - huffs[1] is used for dcode. // - huffs[1] is used for dcode.
// //
// The initial table key is the low n_huffs_bits of the decoder.bits field. // The initial table key is the low n_huffs_bits of the flate_decoder.bits
// Keys longer than 9 bits require a two step lookup, the first step // field. Keys longer than 9 bits require a two step lookup, the first step
// examines the low 9 bits, the second step examines the remaining bits. // examines the low 9 bits, the second step examines the remaining bits.
// Two steps are required at most, as keys are at most 15 bits long. // Two steps are required at most, as keys are at most 15 bits long.
// //
// Using decoder.bits's low n_huffs_bits as a table key is valid even if // Using flate_decoder.bits's low n_huffs_bits as a table key is valid even
// decoder.n_bits is less than n_huffs_bits, because the immediate next // if flate_decoder.n_bits is less than n_huffs_bits, because the immediate
// step after indexing the table by the key is to compare decoder.n_bits to // next step after indexing the table by the key is to compare
// the table value's number of decoder.bits to consume. If it compares // flate_decoder.n_bits to the table value's number of flate_decoder.bits
// less, then more source bytes are read and the table lookup re-tried. // to consume. If it compares less, then more source bytes are read and the
// table lookup re-tried.
// //
// The table value is: // The table value is:
// - bit 31 indicates the symbol is a literal. // - bit 31 indicates the symbol is a literal.
@@ -85,7 +86,7 @@ pub struct decoder?(
// - bits 26-24 are zero. // - bits 26-24 are zero.
// - bits 23- 8 is the redirect offset, literal (in bits 15-8) or base number. // - bits 23- 8 is the redirect offset, literal (in bits 15-8) or base number.
// - bits 7- 4 is the redirected table's bits or number of extra bits. // - bits 7- 4 is the redirected table's bits or number of extra bits.
// - bits 3- 0 are the number of decoder.bits to consume. // - bits 3- 0 are the number of flate_decoder.bits to consume.
// //
// Exactly one of the eight bits 31-24 should be set. // Exactly one of the eight bits 31-24 should be set.
// //
@@ -114,7 +115,7 @@ pub struct decoder?(
code_lengths[320] u8[..15], code_lengths[320] u8[..15],
) )
pub func decoder.decode?(dst writer1, src reader1)() { pub func flate_decoder.decode?(dst writer1, src reader1)() {
while true { while true {
var z status = try this.decode_blocks?(dst:in.dst, src:in.src) var z status = try this.decode_blocks?(dst:in.dst, src:in.src)
if not z.is_suspension() { if not z.is_suspension() {
@@ -168,7 +169,7 @@ pub func decoder.decode?(dst writer1, src reader1)() {
} }
} }
pri func decoder.decode_blocks?(dst writer1, src reader1)() { pri func flate_decoder.decode_blocks?(dst writer1, src reader1)() {
var final u32 var final u32
while final == 0 { while final == 0 {
while this.n_bits < 3, while this.n_bits < 3,
@@ -198,7 +199,7 @@ pri func decoder.decode_blocks?(dst writer1, src reader1)() {
// decode_uncompressed decodes an uncompresed block as per the RFC section // decode_uncompressed decodes an uncompresed block as per the RFC section
// 3.2.4. // 3.2.4.
pri func decoder.decode_uncompressed?(dst writer1, src reader1)() { pri func flate_decoder.decode_uncompressed?(dst writer1, src reader1)() {
if this.n_bits >= 8 { if this.n_bits >= 8 {
return error "internal error: inconsistent n_bits" return error "internal error: inconsistent n_bits"
} }
@@ -225,7 +226,7 @@ pri func decoder.decode_uncompressed?(dst writer1, src reader1)() {
} }
} }
pri func decoder.decode_huffman?(dst writer1, src reader1)() { pri func flate_decoder.decode_huffman?(dst writer1, src reader1)() {
var bits u32 = this.bits var bits u32 = this.bits
var n_bits u32 = this.n_bits var n_bits u32 = this.n_bits
@@ -444,7 +445,7 @@ pri func decoder.decode_huffman?(dst writer1, src reader1)() {
} }
// init_fixed_huffman initializes this.huffs as per the RFC section 3.2.6. // init_fixed_huffman initializes this.huffs as per the RFC section 3.2.6.
pri func decoder.init_fixed_huffman?()() { pri func flate_decoder.init_fixed_huffman?()() {
var i u32 var i u32
while i < 144 { while i < 144 {
this.code_lengths[i] = 8 this.code_lengths[i] = 8
@@ -471,7 +472,7 @@ pri func decoder.init_fixed_huffman?()() {
} }
// init_dynamic_huffman initializes this.huffs as per the RFC section 3.2.7. // init_dynamic_huffman initializes this.huffs as per the RFC section 3.2.7.
pri func decoder.init_dynamic_huffman?(src reader1)() { pri func flate_decoder.init_dynamic_huffman?(src reader1)() {
var bits u32 = this.bits var bits u32 = this.bits
var n_bits u32 = this.n_bits var n_bits u32 = this.n_bits
while n_bits < 14, while n_bits < 14,
@@ -621,7 +622,7 @@ pri func decoder.init_dynamic_huffman?(src reader1)() {
// TODO: skip generating PUFFS_COROUTINE_SUSPENSION_POINTs for *callers* of // TODO: skip generating PUFFS_COROUTINE_SUSPENSION_POINTs for *callers* of
// this function, as it can only return errors, not suspensions. // this function, as it can only return errors, not suspensions.
pri func decoder.init_huff?(which u32[..1], n_codes0 u32[..320], n_codes1 u32[..320], base_symbol u32)() { pri func flate_decoder.init_huff?(which u32[..1], n_codes0 u32[..320], n_codes1 u32[..320], base_symbol u32)() {
// For the clcode example in this package's README.md: // For the clcode example in this package's README.md:
// - n_codes0 = 0 // - n_codes0 = 0
// - n_codes1 = 19 // - n_codes1 = 19
+2 -2
View File
@@ -19,7 +19,7 @@ pub error "invalid zlib parity check"
pub error "TODO: unsupported zlib preset dictionary" pub error "TODO: unsupported zlib preset dictionary"
pub struct zlib_decoder?( pub struct zlib_decoder?(
dec decoder, flate flate_decoder,
adler adler32, adler adler32,
) )
@@ -39,7 +39,7 @@ pub func zlib_decoder.decode?(dst writer1, src reader1)() {
} }
var checksum u32 var checksum u32
while true { while true {
var z status = try this.dec.decode?(dst:in.dst, src:in.src) var z status = try this.flate.decode?(dst:in.dst, src:in.src)
checksum = this.adler.update(x:in.dst.slice()) checksum = this.adler.update(x:in.dst.slice())
if z.is_ok() { if z.is_ok() {
break break
+16 -15
View File
@@ -178,8 +178,8 @@ const char* puffs_flate_decode(puffs_base_buf1* dst,
puffs_base_buf1* src, puffs_base_buf1* src,
uint64_t wlimit, uint64_t wlimit,
uint64_t rlimit) { uint64_t rlimit) {
puffs_flate_decoder dec; puffs_flate_flate_decoder dec;
puffs_flate_decoder_initialize(&dec, PUFFS_VERSION, 0); puffs_flate_flate_decoder_initialize(&dec, PUFFS_VERSION, 0);
puffs_base_writer1 dst_writer = {.buf = dst}; puffs_base_writer1 dst_writer = {.buf = dst};
puffs_base_reader1 src_reader = {.buf = src}; puffs_base_reader1 src_reader = {.buf = src};
while (true) { while (true) {
@@ -193,7 +193,7 @@ const char* puffs_flate_decode(puffs_base_buf1* dst,
} }
puffs_flate_status s = puffs_flate_status s =
puffs_flate_decoder_decode(&dec, dst_writer, src_reader); puffs_flate_flate_decoder_decode(&dec, dst_writer, src_reader);
if (s == PUFFS_FLATE_STATUS_OK) { if (s == PUFFS_FLATE_STATUS_OK) {
return NULL; return NULL;
@@ -294,7 +294,7 @@ void test_puffs_flate_decode_split_src() {
return; return;
} }
puffs_flate_decoder dec; puffs_flate_flate_decoder dec;
puffs_base_writer1 dst_writer = {.buf = &got}; puffs_base_writer1 dst_writer = {.buf = &got};
puffs_base_reader1 src_reader = {.buf = &src}; puffs_base_reader1 src_reader = {.buf = &src};
@@ -307,19 +307,19 @@ void test_puffs_flate_decode_split_src() {
} }
got.wi = 0; got.wi = 0;
puffs_flate_decoder_initialize(&dec, PUFFS_VERSION, 0); puffs_flate_flate_decoder_initialize(&dec, PUFFS_VERSION, 0);
src.closed = false; src.closed = false;
src.ri = gt->src_offset0; src.ri = gt->src_offset0;
src.wi = split; src.wi = split;
puffs_flate_status s0 = puffs_flate_status s0 =
puffs_flate_decoder_decode(&dec, dst_writer, src_reader); puffs_flate_flate_decoder_decode(&dec, dst_writer, src_reader);
src.closed = true; src.closed = true;
src.ri = split; src.ri = split;
src.wi = gt->src_offset1; src.wi = gt->src_offset1;
puffs_flate_status s1 = puffs_flate_status s1 =
puffs_flate_decoder_decode(&dec, dst_writer, src_reader); puffs_flate_flate_decoder_decode(&dec, dst_writer, src_reader);
if (s0 != PUFFS_FLATE_SUSPENSION_SHORT_READ) { if (s0 != PUFFS_FLATE_SUSPENSION_SHORT_READ) {
FAIL("i=%d: s0: got %" PRIi32 " (%s), want %" PRIi32 " (%s)", i, s0, FAIL("i=%d: s0: got %" PRIi32 " (%s), want %" PRIi32 " (%s)", i, s0,
@@ -347,7 +347,7 @@ bool do_test_puffs_flate_history(int i,
golden_test* gt, golden_test* gt,
puffs_base_buf1* src, puffs_base_buf1* src,
puffs_base_buf1* got, puffs_base_buf1* got,
puffs_flate_decoder* dec, puffs_flate_flate_decoder* dec,
uint32_t starting_history_index, uint32_t starting_history_index,
uint64_t limit, uint64_t limit,
puffs_flate_status want_s) { puffs_flate_status want_s) {
@@ -356,7 +356,7 @@ bool do_test_puffs_flate_history(int i,
got->ri = 0; got->ri = 0;
got->wi = 0; got->wi = 0;
puffs_flate_decoder_initialize(dec, PUFFS_VERSION, 0); puffs_flate_flate_decoder_initialize(dec, PUFFS_VERSION, 0);
puffs_base_writer1 dst_writer = {.buf = got}; puffs_base_writer1 dst_writer = {.buf = got};
puffs_base_reader1 src_reader = {.buf = src}; puffs_base_reader1 src_reader = {.buf = src};
@@ -365,7 +365,7 @@ bool do_test_puffs_flate_history(int i,
dst_writer.limit.ptr_to_len = &limit; dst_writer.limit.ptr_to_len = &limit;
puffs_flate_status got_s = puffs_flate_status got_s =
puffs_flate_decoder_decode(dec, dst_writer, src_reader); puffs_flate_flate_decoder_decode(dec, dst_writer, src_reader);
if (got_s != want_s) { if (got_s != want_s) {
FAIL("i=%d: starting_history_index=0x%04" PRIX32 FAIL("i=%d: starting_history_index=0x%04" PRIX32
": decode status: got %" PRIi32 " (%s), want %" PRIi32 " (%s)", ": decode status: got %" PRIi32 " (%s), want %" PRIi32 " (%s)",
@@ -394,7 +394,7 @@ void test_puffs_flate_history_full() {
const int full_history_size = 0x8000; const int full_history_size = 0x8000;
int i; int i;
for (i = -2; i <= +2; i++) { for (i = -2; i <= +2; i++) {
puffs_flate_decoder dec; puffs_flate_flate_decoder dec;
if (!do_test_puffs_flate_history( if (!do_test_puffs_flate_history(
i, gt, &src, &got, &dec, 0, want.wi + i, i, gt, &src, &got, &dec, 0, want.wi + i,
i >= 0 ? PUFFS_FLATE_STATUS_OK i >= 0 ? PUFFS_FLATE_STATUS_OK
@@ -456,7 +456,7 @@ void test_puffs_flate_history_partial() {
const char* fragment = "3.14"; const char* fragment = "3.14";
const uint32_t fragment_length = 4; const uint32_t fragment_length = 4;
puffs_flate_decoder dec; puffs_flate_flate_decoder dec;
if (!do_test_puffs_flate_history(i, gt, &src, &got, &dec, if (!do_test_puffs_flate_history(i, gt, &src, &got, &dec,
starting_history_index, fragment_length, starting_history_index, fragment_length,
PUFFS_FLATE_SUSPENSION_SHORT_WRITE)) { PUFFS_FLATE_SUSPENSION_SHORT_WRITE)) {
@@ -537,8 +537,8 @@ void test_puffs_flate_table_redirect() {
// 1st is the key in the first level table (9 bits). // 1st is the key in the first level table (9 bits).
// 2nd is the key in the second level table (variable bits). // 2nd is the key in the second level table (variable bits).
puffs_flate_decoder dec; puffs_flate_flate_decoder dec;
puffs_flate_decoder_initialize(&dec, PUFFS_VERSION, 0); puffs_flate_flate_decoder_initialize(&dec, PUFFS_VERSION, 0);
// The initializer should zero out dec's fields, but to be paranoid, we zero // The initializer should zero out dec's fields, but to be paranoid, we zero
// it out explicitly. // it out explicitly.
@@ -561,7 +561,8 @@ void test_puffs_flate_table_redirect() {
dec.private_impl.f_code_lengths[n++] = 13; dec.private_impl.f_code_lengths[n++] = 13;
dec.private_impl.f_code_lengths[n++] = 13; dec.private_impl.f_code_lengths[n++] = 13;
puffs_flate_status s = puffs_flate_decoder_init_huff(&dec, 0, 0, n, 257); puffs_flate_status s =
puffs_flate_flate_decoder_init_huff(&dec, 0, 0, n, 257);
if (s) { if (s) {
FAIL("%s", puffs_flate_status_string(s)); FAIL("%s", puffs_flate_status_string(s));
return; return;