mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 00:52:18 +01:00
Delete std/flate's zlib code (moved to std/zlib)
This commit is contained in:
1 parent
7e73a5ac5f
commit
530605a16b
8 files changed
+42
-736
No files matched your search
@@ -635,7 +635,7 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
|
|||||||
isThatMethod(g.tm, n, g.tm.ByName("decode").Key(), 3) {
|
isThatMethod(g.tm, n, g.tm.ByName("decode").Key(), 3) {
|
||||||
|
|
||||||
switch g.pkgName {
|
switch g.pkgName {
|
||||||
case "flate", "zlib": // TODO: remove "flate".
|
case "zlib":
|
||||||
// TODO: don't hard code being inside a try call.
|
// TODO: don't hard code being inside a try call.
|
||||||
if g.currFunk.tempW > maxTemp {
|
if g.currFunk.tempW > maxTemp {
|
||||||
return fmt.Errorf("too many temporary variables required")
|
return fmt.Errorf("too many temporary variables required")
|
||||||
|
|||||||
+10
-419
@@ -154,27 +154,19 @@ typedef int32_t wuffs_flate__status;
|
|||||||
#define WUFFS_FLATE__ERROR_BAD_DISTANCE_CODE_COUNT -1157040121 // 0xBB08F807
|
#define WUFFS_FLATE__ERROR_BAD_DISTANCE_CODE_COUNT -1157040121 // 0xBB08F807
|
||||||
#define WUFFS_FLATE__ERROR_BAD_FLATE_BLOCK -1157040120 // 0xBB08F808
|
#define WUFFS_FLATE__ERROR_BAD_FLATE_BLOCK -1157040120 // 0xBB08F808
|
||||||
#define WUFFS_FLATE__ERROR_BAD_LITERAL_LENGTH_CODE_COUNT \
|
#define WUFFS_FLATE__ERROR_BAD_LITERAL_LENGTH_CODE_COUNT \
|
||||||
-1157040119 // 0xBB08F809
|
-1157040119 // 0xBB08F809
|
||||||
#define WUFFS_FLATE__ERROR_CHECKSUM_MISMATCH -1157040118 // 0xBB08F80A
|
|
||||||
#define WUFFS_FLATE__ERROR_INCONSISTENT_STORED_BLOCK_LENGTH \
|
#define WUFFS_FLATE__ERROR_INCONSISTENT_STORED_BLOCK_LENGTH \
|
||||||
-1157040117 // 0xBB08F80B
|
-1157040118 // 0xBB08F80A
|
||||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE \
|
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE \
|
||||||
-1157040116 // 0xBB08F80C
|
-1157040117 // 0xBB08F80B
|
||||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_END_OF_BLOCK \
|
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_END_OF_BLOCK \
|
||||||
-1157040115 // 0xBB08F80D
|
-1157040116 // 0xBB08F80C
|
||||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_DISTANCE \
|
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_DISTANCE \
|
||||||
-1157040114 // 0xBB08F80E
|
-1157040115 // 0xBB08F80D
|
||||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS \
|
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS \
|
||||||
-1157040113 // 0xBB08F80F
|
-1157040114 // 0xBB08F80E
|
||||||
#define WUFFS_FLATE__ERROR_MISSING_END_OF_BLOCK_CODE -1157040112 // 0xBB08F810
|
#define WUFFS_FLATE__ERROR_MISSING_END_OF_BLOCK_CODE -1157040113 // 0xBB08F80F
|
||||||
#define WUFFS_FLATE__ERROR_NO_HUFFMAN_CODES -1157040111 // 0xBB08F811
|
#define WUFFS_FLATE__ERROR_NO_HUFFMAN_CODES -1157040112 // 0xBB08F810
|
||||||
#define WUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_METHOD \
|
|
||||||
-1157040110 // 0xBB08F812
|
|
||||||
#define WUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_WINDOW_SIZE \
|
|
||||||
-1157040109 // 0xBB08F813
|
|
||||||
#define WUFFS_FLATE__ERROR_INVALID_ZLIB_PARITY_CHECK -1157040108 // 0xBB08F814
|
|
||||||
#define WUFFS_FLATE__ERROR_TODO_UNSUPPORTED_ZLIB_PRESET_DICTIONARY \
|
|
||||||
-1157040107 // 0xBB08F815
|
|
||||||
|
|
||||||
bool wuffs_flate__status__is_error(wuffs_flate__status s);
|
bool wuffs_flate__status__is_error(wuffs_flate__status s);
|
||||||
|
|
||||||
@@ -260,48 +252,6 @@ typedef struct {
|
|||||||
} private_impl;
|
} private_impl;
|
||||||
} wuffs_flate__flate_decoder;
|
} wuffs_flate__flate_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
|
|
||||||
// wuffs_flate__adler32__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 {
|
|
||||||
wuffs_flate__status status;
|
|
||||||
uint32_t magic;
|
|
||||||
|
|
||||||
uint32_t f_state;
|
|
||||||
|
|
||||||
} private_impl;
|
|
||||||
} wuffs_flate__adler32;
|
|
||||||
|
|
||||||
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
|
|
||||||
// wuffs_flate__zlib_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 {
|
|
||||||
wuffs_flate__status status;
|
|
||||||
uint32_t magic;
|
|
||||||
|
|
||||||
wuffs_flate__flate_decoder f_flate;
|
|
||||||
wuffs_flate__adler32 f_adler;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
uint32_t coro_susp_point;
|
|
||||||
uint16_t v_x;
|
|
||||||
uint32_t v_checksum;
|
|
||||||
wuffs_flate__status v_z;
|
|
||||||
uint64_t scratch;
|
|
||||||
} c_decode[1];
|
|
||||||
} private_impl;
|
|
||||||
} wuffs_flate__zlib_decoder;
|
|
||||||
|
|
||||||
// ---------------- Public Initializer Prototypes
|
// ---------------- Public Initializer Prototypes
|
||||||
|
|
||||||
// wuffs_flate__flate_decoder__initialize is an initializer function.
|
// wuffs_flate__flate_decoder__initialize is an initializer function.
|
||||||
@@ -313,15 +263,6 @@ void wuffs_flate__flate_decoder__initialize(wuffs_flate__flate_decoder* self,
|
|||||||
uint32_t wuffs_version,
|
uint32_t wuffs_version,
|
||||||
uint32_t for_internal_use_only);
|
uint32_t for_internal_use_only);
|
||||||
|
|
||||||
// wuffs_flate__zlib_decoder__initialize is an initializer function.
|
|
||||||
//
|
|
||||||
// It should be called before any other wuffs_flate__zlib_decoder__* function.
|
|
||||||
//
|
|
||||||
// Pass WUFFS_VERSION and 0 for wuffs_version and for_internal_use_only.
|
|
||||||
void wuffs_flate__zlib_decoder__initialize(wuffs_flate__zlib_decoder* self,
|
|
||||||
uint32_t wuffs_version,
|
|
||||||
uint32_t for_internal_use_only);
|
|
||||||
|
|
||||||
// ---------------- Public Function Prototypes
|
// ---------------- Public Function Prototypes
|
||||||
|
|
||||||
wuffs_flate__status wuffs_flate__flate_decoder__decode(
|
wuffs_flate__status wuffs_flate__flate_decoder__decode(
|
||||||
@@ -329,11 +270,6 @@ wuffs_flate__status wuffs_flate__flate_decoder__decode(
|
|||||||
wuffs_base__writer1 a_dst,
|
wuffs_base__writer1 a_dst,
|
||||||
wuffs_base__reader1 a_src);
|
wuffs_base__reader1 a_src);
|
||||||
|
|
||||||
wuffs_flate__status wuffs_flate__zlib_decoder__decode(
|
|
||||||
wuffs_flate__zlib_decoder* self,
|
|
||||||
wuffs_base__writer1 a_dst,
|
|
||||||
wuffs_base__reader1 a_src);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
#endif
|
#endif
|
||||||
@@ -707,7 +643,7 @@ const char* wuffs_flate__status__strings0[11] = {
|
|||||||
"flate: cannot return a suspension",
|
"flate: cannot return a suspension",
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* wuffs_flate__status__strings1[22] = {
|
const char* wuffs_flate__status__strings1[17] = {
|
||||||
"flate: bad Huffman code (over-subscribed)",
|
"flate: bad Huffman code (over-subscribed)",
|
||||||
"flate: bad Huffman code (under-subscribed)",
|
"flate: bad Huffman code (under-subscribed)",
|
||||||
"flate: bad Huffman code length count",
|
"flate: bad Huffman code length count",
|
||||||
@@ -718,7 +654,6 @@ const char* wuffs_flate__status__strings1[22] = {
|
|||||||
"flate: bad distance code count",
|
"flate: bad distance code count",
|
||||||
"flate: bad flate block",
|
"flate: bad flate block",
|
||||||
"flate: bad literal/length code count",
|
"flate: bad literal/length code count",
|
||||||
"flate: checksum mismatch",
|
|
||||||
"flate: inconsistent stored block length",
|
"flate: inconsistent stored block length",
|
||||||
"flate: internal error: inconsistent Huffman decoder state",
|
"flate: internal error: inconsistent Huffman decoder state",
|
||||||
"flate: internal error: inconsistent Huffman end_of_block",
|
"flate: internal error: inconsistent Huffman end_of_block",
|
||||||
@@ -726,10 +661,6 @@ const char* wuffs_flate__status__strings1[22] = {
|
|||||||
"flate: internal error: inconsistent n_bits",
|
"flate: internal error: inconsistent n_bits",
|
||||||
"flate: missing end-of-block code",
|
"flate: missing end-of-block code",
|
||||||
"flate: no Huffman codes",
|
"flate: no Huffman codes",
|
||||||
"flate: invalid zlib compression method",
|
|
||||||
"flate: invalid zlib compression window size",
|
|
||||||
"flate: invalid zlib parity check",
|
|
||||||
"flate: TODO: unsupported zlib preset dictionary",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* wuffs_flate__status__string(wuffs_flate__status s) {
|
const char* wuffs_flate__status__string(wuffs_flate__status s) {
|
||||||
@@ -742,7 +673,7 @@ const char* wuffs_flate__status__string(wuffs_flate__status s) {
|
|||||||
break;
|
break;
|
||||||
case wuffs_flate__packageid:
|
case wuffs_flate__packageid:
|
||||||
a = wuffs_flate__status__strings1;
|
a = wuffs_flate__status__strings1;
|
||||||
n = 22;
|
n = 17;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
uint32_t i = s & 0xFF;
|
uint32_t i = s & 0xFF;
|
||||||
@@ -794,10 +725,6 @@ static const uint32_t wuffs_flate__dcode_magic_numbers[32] = {
|
|||||||
|
|
||||||
// ---------------- Private Initializer Prototypes
|
// ---------------- Private Initializer Prototypes
|
||||||
|
|
||||||
void wuffs_flate__adler32__initialize(wuffs_flate__adler32* self,
|
|
||||||
uint32_t wuffs_version,
|
|
||||||
uint32_t for_internal_use_only);
|
|
||||||
|
|
||||||
// ---------------- Private Function Prototypes
|
// ---------------- Private Function Prototypes
|
||||||
|
|
||||||
static wuffs_flate__status wuffs_flate__flate_decoder__decode_blocks(
|
static wuffs_flate__status wuffs_flate__flate_decoder__decode_blocks(
|
||||||
@@ -834,9 +761,6 @@ static wuffs_flate__status wuffs_flate__flate_decoder__decode_huffman_slow(
|
|||||||
wuffs_base__writer1 a_dst,
|
wuffs_base__writer1 a_dst,
|
||||||
wuffs_base__reader1 a_src);
|
wuffs_base__reader1 a_src);
|
||||||
|
|
||||||
static uint32_t wuffs_flate__adler32__update(wuffs_flate__adler32* self,
|
|
||||||
wuffs_base__slice_u8 a_x);
|
|
||||||
|
|
||||||
// ---------------- Initializer Implementations
|
// ---------------- Initializer Implementations
|
||||||
|
|
||||||
void wuffs_flate__flate_decoder__initialize(wuffs_flate__flate_decoder* self,
|
void wuffs_flate__flate_decoder__initialize(wuffs_flate__flate_decoder* self,
|
||||||
@@ -855,43 +779,6 @@ void wuffs_flate__flate_decoder__initialize(wuffs_flate__flate_decoder* self,
|
|||||||
self->private_impl.magic = WUFFS_BASE__MAGIC;
|
self->private_impl.magic = WUFFS_BASE__MAGIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wuffs_flate__adler32__initialize(wuffs_flate__adler32* self,
|
|
||||||
uint32_t wuffs_version,
|
|
||||||
uint32_t for_internal_use_only) {
|
|
||||||
if (!self) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (wuffs_version != WUFFS_VERSION) {
|
|
||||||
self->private_impl.status = WUFFS_FLATE__ERROR_BAD_WUFFS_VERSION;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (for_internal_use_only != WUFFS_BASE__ALREADY_ZEROED) {
|
|
||||||
memset(self, 0, sizeof(*self));
|
|
||||||
}
|
|
||||||
self->private_impl.magic = WUFFS_BASE__MAGIC;
|
|
||||||
self->private_impl.f_state = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void wuffs_flate__zlib_decoder__initialize(wuffs_flate__zlib_decoder* self,
|
|
||||||
uint32_t wuffs_version,
|
|
||||||
uint32_t for_internal_use_only) {
|
|
||||||
if (!self) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (wuffs_version != WUFFS_VERSION) {
|
|
||||||
self->private_impl.status = WUFFS_FLATE__ERROR_BAD_WUFFS_VERSION;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (for_internal_use_only != WUFFS_BASE__ALREADY_ZEROED) {
|
|
||||||
memset(self, 0, sizeof(*self));
|
|
||||||
}
|
|
||||||
self->private_impl.magic = WUFFS_BASE__MAGIC;
|
|
||||||
wuffs_flate__flate_decoder__initialize(
|
|
||||||
&self->private_impl.f_flate, WUFFS_VERSION, WUFFS_BASE__ALREADY_ZEROED);
|
|
||||||
wuffs_flate__adler32__initialize(&self->private_impl.f_adler, WUFFS_VERSION,
|
|
||||||
WUFFS_BASE__ALREADY_ZEROED);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------- Function Implementations
|
// ---------------- Function Implementations
|
||||||
|
|
||||||
wuffs_flate__status wuffs_flate__flate_decoder__decode(
|
wuffs_flate__status wuffs_flate__flate_decoder__decode(
|
||||||
@@ -2829,299 +2716,3 @@ short_read_src:
|
|||||||
status = WUFFS_FLATE__SUSPENSION_SHORT_READ;
|
status = WUFFS_FLATE__SUSPENSION_SHORT_READ;
|
||||||
goto suspend;
|
goto suspend;
|
||||||
}
|
}
|
||||||
|
|
||||||
wuffs_flate__status wuffs_flate__zlib_decoder__decode(
|
|
||||||
wuffs_flate__zlib_decoder* self,
|
|
||||||
wuffs_base__writer1 a_dst,
|
|
||||||
wuffs_base__reader1 a_src) {
|
|
||||||
if (!self) {
|
|
||||||
return WUFFS_FLATE__ERROR_BAD_RECEIVER;
|
|
||||||
}
|
|
||||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
|
||||||
self->private_impl.status = WUFFS_FLATE__ERROR_INITIALIZER_NOT_CALLED;
|
|
||||||
}
|
|
||||||
if (self->private_impl.status < 0) {
|
|
||||||
return self->private_impl.status;
|
|
||||||
}
|
|
||||||
wuffs_flate__status status = WUFFS_FLATE__STATUS_OK;
|
|
||||||
|
|
||||||
uint16_t v_x;
|
|
||||||
uint32_t v_checksum;
|
|
||||||
wuffs_flate__status v_z;
|
|
||||||
|
|
||||||
uint8_t* b_wptr_dst = NULL;
|
|
||||||
uint8_t* b_wstart_dst = NULL;
|
|
||||||
uint8_t* b_wend_dst = NULL;
|
|
||||||
if (a_dst.buf) {
|
|
||||||
b_wptr_dst = a_dst.buf->ptr + a_dst.buf->wi;
|
|
||||||
b_wstart_dst = b_wptr_dst;
|
|
||||||
b_wend_dst = b_wptr_dst;
|
|
||||||
if (!a_dst.buf->closed) {
|
|
||||||
uint64_t len = a_dst.buf->len - a_dst.buf->wi;
|
|
||||||
wuffs_base__limit1* lim;
|
|
||||||
for (lim = &a_dst.private_impl.limit; lim; lim = lim->next) {
|
|
||||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
|
||||||
len = *lim->ptr_to_len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
b_wend_dst += len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
uint8_t* b_rptr_src = NULL;
|
|
||||||
uint8_t* b_rstart_src = NULL;
|
|
||||||
uint8_t* b_rend_src = NULL;
|
|
||||||
if (a_src.buf) {
|
|
||||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
|
||||||
b_rstart_src = b_rptr_src;
|
|
||||||
uint64_t len = a_src.buf->wi - a_src.buf->ri;
|
|
||||||
wuffs_base__limit1* lim;
|
|
||||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
|
||||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
|
||||||
len = *lim->ptr_to_len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
b_rend_src = b_rptr_src + len;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t coro_susp_point = self->private_impl.c_decode[0].coro_susp_point;
|
|
||||||
if (coro_susp_point) {
|
|
||||||
v_x = self->private_impl.c_decode[0].v_x;
|
|
||||||
v_checksum = self->private_impl.c_decode[0].v_checksum;
|
|
||||||
v_z = self->private_impl.c_decode[0].v_z;
|
|
||||||
}
|
|
||||||
switch (coro_susp_point) {
|
|
||||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
|
||||||
|
|
||||||
{
|
|
||||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
|
||||||
uint16_t t_1;
|
|
||||||
if (WUFFS_BASE__LIKELY(b_rend_src - b_rptr_src >= 2)) {
|
|
||||||
t_1 = wuffs_base__load_u16be(b_rptr_src);
|
|
||||||
b_rptr_src += 2;
|
|
||||||
} else {
|
|
||||||
self->private_impl.c_decode[0].scratch = 0;
|
|
||||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
|
||||||
while (true) {
|
|
||||||
if (WUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
|
||||||
goto short_read_src;
|
|
||||||
}
|
|
||||||
uint32_t t_0 = self->private_impl.c_decode[0].scratch & 0xFF;
|
|
||||||
self->private_impl.c_decode[0].scratch >>= 8;
|
|
||||||
self->private_impl.c_decode[0].scratch <<= 8;
|
|
||||||
self->private_impl.c_decode[0].scratch |= ((uint64_t)(*b_rptr_src++))
|
|
||||||
<< (64 - t_0);
|
|
||||||
if (t_0 == 8) {
|
|
||||||
t_1 = self->private_impl.c_decode[0].scratch >> (64 - 16);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
t_0 += 8;
|
|
||||||
self->private_impl.c_decode[0].scratch |= ((uint64_t)(t_0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
v_x = t_1;
|
|
||||||
}
|
|
||||||
if (((v_x >> 8) & 15) != 8) {
|
|
||||||
status = WUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_METHOD;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
if ((v_x >> 12) > 7) {
|
|
||||||
status = WUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_WINDOW_SIZE;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
if ((v_x & 32) != 0) {
|
|
||||||
status = WUFFS_FLATE__ERROR_TODO_UNSUPPORTED_ZLIB_PRESET_DICTIONARY;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
if ((v_x % 31) != 0) {
|
|
||||||
status = WUFFS_FLATE__ERROR_INVALID_ZLIB_PARITY_CHECK;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
v_checksum = 0;
|
|
||||||
while (true) {
|
|
||||||
wuffs_base__writer1__mark(&a_dst, b_wptr_dst);
|
|
||||||
{
|
|
||||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
|
||||||
if (a_dst.buf) {
|
|
||||||
size_t n = b_wptr_dst - (a_dst.buf->ptr + a_dst.buf->wi);
|
|
||||||
a_dst.buf->wi += n;
|
|
||||||
wuffs_base__limit1* lim;
|
|
||||||
for (lim = &a_dst.private_impl.limit; lim; lim = lim->next) {
|
|
||||||
if (lim->ptr_to_len) {
|
|
||||||
*lim->ptr_to_len -= n;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (a_src.buf) {
|
|
||||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
|
||||||
a_src.buf->ri += n;
|
|
||||||
wuffs_base__limit1* lim;
|
|
||||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
|
||||||
if (lim->ptr_to_len) {
|
|
||||||
*lim->ptr_to_len -= n;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
wuffs_flate__status t_2 = wuffs_flate__flate_decoder__decode(
|
|
||||||
&self->private_impl.f_flate, a_dst, a_src);
|
|
||||||
if (a_dst.buf) {
|
|
||||||
b_wptr_dst = a_dst.buf->ptr + a_dst.buf->wi;
|
|
||||||
}
|
|
||||||
if (a_src.buf) {
|
|
||||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
|
||||||
}
|
|
||||||
v_z = t_2;
|
|
||||||
}
|
|
||||||
v_checksum = wuffs_flate__adler32__update(
|
|
||||||
&self->private_impl.f_adler,
|
|
||||||
((wuffs_base__slice_u8){
|
|
||||||
.ptr = a_dst.private_impl.mark,
|
|
||||||
.len = a_dst.private_impl.mark
|
|
||||||
? (size_t)(b_wptr_dst - a_dst.private_impl.mark)
|
|
||||||
: 0,
|
|
||||||
}));
|
|
||||||
if (v_z == 0) {
|
|
||||||
goto label_0_break;
|
|
||||||
}
|
|
||||||
status = v_z;
|
|
||||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
|
||||||
}
|
|
||||||
label_0_break:;
|
|
||||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
|
||||||
uint32_t t_4;
|
|
||||||
if (WUFFS_BASE__LIKELY(b_rend_src - b_rptr_src >= 4)) {
|
|
||||||
t_4 = wuffs_base__load_u32be(b_rptr_src);
|
|
||||||
b_rptr_src += 4;
|
|
||||||
} else {
|
|
||||||
self->private_impl.c_decode[0].scratch = 0;
|
|
||||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
|
||||||
while (true) {
|
|
||||||
if (WUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
|
||||||
goto short_read_src;
|
|
||||||
}
|
|
||||||
uint32_t t_3 = self->private_impl.c_decode[0].scratch & 0xFF;
|
|
||||||
self->private_impl.c_decode[0].scratch >>= 8;
|
|
||||||
self->private_impl.c_decode[0].scratch <<= 8;
|
|
||||||
self->private_impl.c_decode[0].scratch |= ((uint64_t)(*b_rptr_src++))
|
|
||||||
<< (64 - t_3);
|
|
||||||
if (t_3 == 24) {
|
|
||||||
t_4 = self->private_impl.c_decode[0].scratch >> (64 - 32);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
t_3 += 8;
|
|
||||||
self->private_impl.c_decode[0].scratch |= ((uint64_t)(t_3));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (v_checksum != t_4) {
|
|
||||||
status = WUFFS_FLATE__ERROR_CHECKSUM_MISMATCH;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
goto ok;
|
|
||||||
ok:
|
|
||||||
self->private_impl.c_decode[0].coro_susp_point = 0;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
goto suspend;
|
|
||||||
suspend:
|
|
||||||
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_checksum = v_checksum;
|
|
||||||
self->private_impl.c_decode[0].v_z = v_z;
|
|
||||||
|
|
||||||
exit:
|
|
||||||
if (a_dst.buf) {
|
|
||||||
size_t n = b_wptr_dst - (a_dst.buf->ptr + a_dst.buf->wi);
|
|
||||||
a_dst.buf->wi += n;
|
|
||||||
wuffs_base__limit1* lim;
|
|
||||||
for (lim = &a_dst.private_impl.limit; lim; lim = lim->next) {
|
|
||||||
if (lim->ptr_to_len) {
|
|
||||||
*lim->ptr_to_len -= n;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wstart_dst);
|
|
||||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wend_dst);
|
|
||||||
}
|
|
||||||
if (a_src.buf) {
|
|
||||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
|
||||||
a_src.buf->ri += n;
|
|
||||||
wuffs_base__limit1* lim;
|
|
||||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
|
||||||
if (lim->ptr_to_len) {
|
|
||||||
*lim->ptr_to_len -= n;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
|
||||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
|
||||||
}
|
|
||||||
|
|
||||||
self->private_impl.status = status;
|
|
||||||
return status;
|
|
||||||
|
|
||||||
short_read_src:
|
|
||||||
if (a_src.buf && a_src.buf->closed && !a_src.private_impl.limit.ptr_to_len) {
|
|
||||||
status = WUFFS_FLATE__ERROR_UNEXPECTED_EOF;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
status = WUFFS_FLATE__SUSPENSION_SHORT_READ;
|
|
||||||
goto suspend;
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint32_t wuffs_flate__adler32__update(wuffs_flate__adler32* self,
|
|
||||||
wuffs_base__slice_u8 a_x) {
|
|
||||||
uint32_t v_s1;
|
|
||||||
uint32_t v_s2;
|
|
||||||
wuffs_base__slice_u8 v_remaining;
|
|
||||||
|
|
||||||
v_s1 = ((self->private_impl.f_state) & ((1 << (16)) - 1));
|
|
||||||
v_s2 = ((self->private_impl.f_state) >> (32 - (16)));
|
|
||||||
while (((uint64_t)(a_x.len)) > 0) {
|
|
||||||
v_remaining = ((wuffs_base__slice_u8){});
|
|
||||||
if (((uint64_t)(a_x.len)) > 5552) {
|
|
||||||
v_remaining = wuffs_base__slice_u8__subslice_i(a_x, 5552);
|
|
||||||
a_x = wuffs_base__slice_u8__subslice_j(a_x, 5552);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
wuffs_base__slice_u8 i_slice_p = a_x;
|
|
||||||
uint8_t* v_p = i_slice_p.ptr;
|
|
||||||
uint8_t* i_end0_p = i_slice_p.ptr + (i_slice_p.len / 8) * 8;
|
|
||||||
while (v_p < i_end0_p) {
|
|
||||||
v_s1 += ((uint32_t)(*v_p));
|
|
||||||
v_s2 += v_s1;
|
|
||||||
v_p++;
|
|
||||||
v_s1 += ((uint32_t)(*v_p));
|
|
||||||
v_s2 += v_s1;
|
|
||||||
v_p++;
|
|
||||||
v_s1 += ((uint32_t)(*v_p));
|
|
||||||
v_s2 += v_s1;
|
|
||||||
v_p++;
|
|
||||||
v_s1 += ((uint32_t)(*v_p));
|
|
||||||
v_s2 += v_s1;
|
|
||||||
v_p++;
|
|
||||||
v_s1 += ((uint32_t)(*v_p));
|
|
||||||
v_s2 += v_s1;
|
|
||||||
v_p++;
|
|
||||||
v_s1 += ((uint32_t)(*v_p));
|
|
||||||
v_s2 += v_s1;
|
|
||||||
v_p++;
|
|
||||||
v_s1 += ((uint32_t)(*v_p));
|
|
||||||
v_s2 += v_s1;
|
|
||||||
v_p++;
|
|
||||||
v_s1 += ((uint32_t)(*v_p));
|
|
||||||
v_s2 += v_s1;
|
|
||||||
v_p++;
|
|
||||||
}
|
|
||||||
uint8_t* i_end1_p = i_slice_p.ptr + i_slice_p.len;
|
|
||||||
while (v_p < i_end1_p) {
|
|
||||||
v_s1 += ((uint32_t)(*v_p));
|
|
||||||
v_s2 += v_s1;
|
|
||||||
v_p++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
v_s1 %= 65521;
|
|
||||||
v_s2 %= 65521;
|
|
||||||
a_x = v_remaining;
|
|
||||||
}
|
|
||||||
self->private_impl.f_state = (((v_s2 & 65535) << 16) | (v_s1 & 65535));
|
|
||||||
return self->private_impl.f_state;
|
|
||||||
}
|
|
||||||
+8
-72
@@ -163,27 +163,19 @@ typedef int32_t wuffs_flate__status;
|
|||||||
#define WUFFS_FLATE__ERROR_BAD_DISTANCE_CODE_COUNT -1157040121 // 0xBB08F807
|
#define WUFFS_FLATE__ERROR_BAD_DISTANCE_CODE_COUNT -1157040121 // 0xBB08F807
|
||||||
#define WUFFS_FLATE__ERROR_BAD_FLATE_BLOCK -1157040120 // 0xBB08F808
|
#define WUFFS_FLATE__ERROR_BAD_FLATE_BLOCK -1157040120 // 0xBB08F808
|
||||||
#define WUFFS_FLATE__ERROR_BAD_LITERAL_LENGTH_CODE_COUNT \
|
#define WUFFS_FLATE__ERROR_BAD_LITERAL_LENGTH_CODE_COUNT \
|
||||||
-1157040119 // 0xBB08F809
|
-1157040119 // 0xBB08F809
|
||||||
#define WUFFS_FLATE__ERROR_CHECKSUM_MISMATCH -1157040118 // 0xBB08F80A
|
|
||||||
#define WUFFS_FLATE__ERROR_INCONSISTENT_STORED_BLOCK_LENGTH \
|
#define WUFFS_FLATE__ERROR_INCONSISTENT_STORED_BLOCK_LENGTH \
|
||||||
-1157040117 // 0xBB08F80B
|
-1157040118 // 0xBB08F80A
|
||||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE \
|
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE \
|
||||||
-1157040116 // 0xBB08F80C
|
-1157040117 // 0xBB08F80B
|
||||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_END_OF_BLOCK \
|
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_END_OF_BLOCK \
|
||||||
-1157040115 // 0xBB08F80D
|
-1157040116 // 0xBB08F80C
|
||||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_DISTANCE \
|
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_DISTANCE \
|
||||||
-1157040114 // 0xBB08F80E
|
-1157040115 // 0xBB08F80D
|
||||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS \
|
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS \
|
||||||
-1157040113 // 0xBB08F80F
|
-1157040114 // 0xBB08F80E
|
||||||
#define WUFFS_FLATE__ERROR_MISSING_END_OF_BLOCK_CODE -1157040112 // 0xBB08F810
|
#define WUFFS_FLATE__ERROR_MISSING_END_OF_BLOCK_CODE -1157040113 // 0xBB08F80F
|
||||||
#define WUFFS_FLATE__ERROR_NO_HUFFMAN_CODES -1157040111 // 0xBB08F811
|
#define WUFFS_FLATE__ERROR_NO_HUFFMAN_CODES -1157040112 // 0xBB08F810
|
||||||
#define WUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_METHOD \
|
|
||||||
-1157040110 // 0xBB08F812
|
|
||||||
#define WUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_WINDOW_SIZE \
|
|
||||||
-1157040109 // 0xBB08F813
|
|
||||||
#define WUFFS_FLATE__ERROR_INVALID_ZLIB_PARITY_CHECK -1157040108 // 0xBB08F814
|
|
||||||
#define WUFFS_FLATE__ERROR_TODO_UNSUPPORTED_ZLIB_PRESET_DICTIONARY \
|
|
||||||
-1157040107 // 0xBB08F815
|
|
||||||
|
|
||||||
bool wuffs_flate__status__is_error(wuffs_flate__status s);
|
bool wuffs_flate__status__is_error(wuffs_flate__status s);
|
||||||
|
|
||||||
@@ -269,48 +261,6 @@ typedef struct {
|
|||||||
} private_impl;
|
} private_impl;
|
||||||
} wuffs_flate__flate_decoder;
|
} wuffs_flate__flate_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
|
|
||||||
// wuffs_flate__adler32__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 {
|
|
||||||
wuffs_flate__status status;
|
|
||||||
uint32_t magic;
|
|
||||||
|
|
||||||
uint32_t f_state;
|
|
||||||
|
|
||||||
} private_impl;
|
|
||||||
} wuffs_flate__adler32;
|
|
||||||
|
|
||||||
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
|
|
||||||
// wuffs_flate__zlib_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 {
|
|
||||||
wuffs_flate__status status;
|
|
||||||
uint32_t magic;
|
|
||||||
|
|
||||||
wuffs_flate__flate_decoder f_flate;
|
|
||||||
wuffs_flate__adler32 f_adler;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
uint32_t coro_susp_point;
|
|
||||||
uint16_t v_x;
|
|
||||||
uint32_t v_checksum;
|
|
||||||
wuffs_flate__status v_z;
|
|
||||||
uint64_t scratch;
|
|
||||||
} c_decode[1];
|
|
||||||
} private_impl;
|
|
||||||
} wuffs_flate__zlib_decoder;
|
|
||||||
|
|
||||||
// ---------------- Public Initializer Prototypes
|
// ---------------- Public Initializer Prototypes
|
||||||
|
|
||||||
// wuffs_flate__flate_decoder__initialize is an initializer function.
|
// wuffs_flate__flate_decoder__initialize is an initializer function.
|
||||||
@@ -322,15 +272,6 @@ void wuffs_flate__flate_decoder__initialize(wuffs_flate__flate_decoder* self,
|
|||||||
uint32_t wuffs_version,
|
uint32_t wuffs_version,
|
||||||
uint32_t for_internal_use_only);
|
uint32_t for_internal_use_only);
|
||||||
|
|
||||||
// wuffs_flate__zlib_decoder__initialize is an initializer function.
|
|
||||||
//
|
|
||||||
// It should be called before any other wuffs_flate__zlib_decoder__* function.
|
|
||||||
//
|
|
||||||
// Pass WUFFS_VERSION and 0 for wuffs_version and for_internal_use_only.
|
|
||||||
void wuffs_flate__zlib_decoder__initialize(wuffs_flate__zlib_decoder* self,
|
|
||||||
uint32_t wuffs_version,
|
|
||||||
uint32_t for_internal_use_only);
|
|
||||||
|
|
||||||
// ---------------- Public Function Prototypes
|
// ---------------- Public Function Prototypes
|
||||||
|
|
||||||
wuffs_flate__status wuffs_flate__flate_decoder__decode(
|
wuffs_flate__status wuffs_flate__flate_decoder__decode(
|
||||||
@@ -338,11 +279,6 @@ wuffs_flate__status wuffs_flate__flate_decoder__decode(
|
|||||||
wuffs_base__writer1 a_dst,
|
wuffs_base__writer1 a_dst,
|
||||||
wuffs_base__reader1 a_src);
|
wuffs_base__reader1 a_src);
|
||||||
|
|
||||||
wuffs_flate__status wuffs_flate__zlib_decoder__decode(
|
|
||||||
wuffs_flate__zlib_decoder* self,
|
|
||||||
wuffs_base__writer1 a_dst,
|
|
||||||
wuffs_base__reader1 a_src);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+8
-72
@@ -154,27 +154,19 @@ typedef int32_t wuffs_flate__status;
|
|||||||
#define WUFFS_FLATE__ERROR_BAD_DISTANCE_CODE_COUNT -1157040121 // 0xBB08F807
|
#define WUFFS_FLATE__ERROR_BAD_DISTANCE_CODE_COUNT -1157040121 // 0xBB08F807
|
||||||
#define WUFFS_FLATE__ERROR_BAD_FLATE_BLOCK -1157040120 // 0xBB08F808
|
#define WUFFS_FLATE__ERROR_BAD_FLATE_BLOCK -1157040120 // 0xBB08F808
|
||||||
#define WUFFS_FLATE__ERROR_BAD_LITERAL_LENGTH_CODE_COUNT \
|
#define WUFFS_FLATE__ERROR_BAD_LITERAL_LENGTH_CODE_COUNT \
|
||||||
-1157040119 // 0xBB08F809
|
-1157040119 // 0xBB08F809
|
||||||
#define WUFFS_FLATE__ERROR_CHECKSUM_MISMATCH -1157040118 // 0xBB08F80A
|
|
||||||
#define WUFFS_FLATE__ERROR_INCONSISTENT_STORED_BLOCK_LENGTH \
|
#define WUFFS_FLATE__ERROR_INCONSISTENT_STORED_BLOCK_LENGTH \
|
||||||
-1157040117 // 0xBB08F80B
|
-1157040118 // 0xBB08F80A
|
||||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE \
|
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE \
|
||||||
-1157040116 // 0xBB08F80C
|
-1157040117 // 0xBB08F80B
|
||||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_END_OF_BLOCK \
|
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_END_OF_BLOCK \
|
||||||
-1157040115 // 0xBB08F80D
|
-1157040116 // 0xBB08F80C
|
||||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_DISTANCE \
|
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_DISTANCE \
|
||||||
-1157040114 // 0xBB08F80E
|
-1157040115 // 0xBB08F80D
|
||||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS \
|
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS \
|
||||||
-1157040113 // 0xBB08F80F
|
-1157040114 // 0xBB08F80E
|
||||||
#define WUFFS_FLATE__ERROR_MISSING_END_OF_BLOCK_CODE -1157040112 // 0xBB08F810
|
#define WUFFS_FLATE__ERROR_MISSING_END_OF_BLOCK_CODE -1157040113 // 0xBB08F80F
|
||||||
#define WUFFS_FLATE__ERROR_NO_HUFFMAN_CODES -1157040111 // 0xBB08F811
|
#define WUFFS_FLATE__ERROR_NO_HUFFMAN_CODES -1157040112 // 0xBB08F810
|
||||||
#define WUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_METHOD \
|
|
||||||
-1157040110 // 0xBB08F812
|
|
||||||
#define WUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_WINDOW_SIZE \
|
|
||||||
-1157040109 // 0xBB08F813
|
|
||||||
#define WUFFS_FLATE__ERROR_INVALID_ZLIB_PARITY_CHECK -1157040108 // 0xBB08F814
|
|
||||||
#define WUFFS_FLATE__ERROR_TODO_UNSUPPORTED_ZLIB_PRESET_DICTIONARY \
|
|
||||||
-1157040107 // 0xBB08F815
|
|
||||||
|
|
||||||
bool wuffs_flate__status__is_error(wuffs_flate__status s);
|
bool wuffs_flate__status__is_error(wuffs_flate__status s);
|
||||||
|
|
||||||
@@ -260,48 +252,6 @@ typedef struct {
|
|||||||
} private_impl;
|
} private_impl;
|
||||||
} wuffs_flate__flate_decoder;
|
} wuffs_flate__flate_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
|
|
||||||
// wuffs_flate__adler32__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 {
|
|
||||||
wuffs_flate__status status;
|
|
||||||
uint32_t magic;
|
|
||||||
|
|
||||||
uint32_t f_state;
|
|
||||||
|
|
||||||
} private_impl;
|
|
||||||
} wuffs_flate__adler32;
|
|
||||||
|
|
||||||
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
|
|
||||||
// wuffs_flate__zlib_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 {
|
|
||||||
wuffs_flate__status status;
|
|
||||||
uint32_t magic;
|
|
||||||
|
|
||||||
wuffs_flate__flate_decoder f_flate;
|
|
||||||
wuffs_flate__adler32 f_adler;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
uint32_t coro_susp_point;
|
|
||||||
uint16_t v_x;
|
|
||||||
uint32_t v_checksum;
|
|
||||||
wuffs_flate__status v_z;
|
|
||||||
uint64_t scratch;
|
|
||||||
} c_decode[1];
|
|
||||||
} private_impl;
|
|
||||||
} wuffs_flate__zlib_decoder;
|
|
||||||
|
|
||||||
// ---------------- Public Initializer Prototypes
|
// ---------------- Public Initializer Prototypes
|
||||||
|
|
||||||
// wuffs_flate__flate_decoder__initialize is an initializer function.
|
// wuffs_flate__flate_decoder__initialize is an initializer function.
|
||||||
@@ -313,15 +263,6 @@ void wuffs_flate__flate_decoder__initialize(wuffs_flate__flate_decoder* self,
|
|||||||
uint32_t wuffs_version,
|
uint32_t wuffs_version,
|
||||||
uint32_t for_internal_use_only);
|
uint32_t for_internal_use_only);
|
||||||
|
|
||||||
// wuffs_flate__zlib_decoder__initialize is an initializer function.
|
|
||||||
//
|
|
||||||
// It should be called before any other wuffs_flate__zlib_decoder__* function.
|
|
||||||
//
|
|
||||||
// Pass WUFFS_VERSION and 0 for wuffs_version and for_internal_use_only.
|
|
||||||
void wuffs_flate__zlib_decoder__initialize(wuffs_flate__zlib_decoder* self,
|
|
||||||
uint32_t wuffs_version,
|
|
||||||
uint32_t for_internal_use_only);
|
|
||||||
|
|
||||||
// ---------------- Public Function Prototypes
|
// ---------------- Public Function Prototypes
|
||||||
|
|
||||||
wuffs_flate__status wuffs_flate__flate_decoder__decode(
|
wuffs_flate__status wuffs_flate__flate_decoder__decode(
|
||||||
@@ -329,11 +270,6 @@ wuffs_flate__status wuffs_flate__flate_decoder__decode(
|
|||||||
wuffs_base__writer1 a_dst,
|
wuffs_base__writer1 a_dst,
|
||||||
wuffs_base__reader1 a_src);
|
wuffs_base__reader1 a_src);
|
||||||
|
|
||||||
wuffs_flate__status wuffs_flate__zlib_decoder__decode(
|
|
||||||
wuffs_flate__zlib_decoder* self,
|
|
||||||
wuffs_base__writer1 a_dst,
|
|
||||||
wuffs_base__reader1 a_src);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+8
-72
@@ -163,27 +163,19 @@ typedef int32_t wuffs_flate__status;
|
|||||||
#define WUFFS_FLATE__ERROR_BAD_DISTANCE_CODE_COUNT -1157040121 // 0xBB08F807
|
#define WUFFS_FLATE__ERROR_BAD_DISTANCE_CODE_COUNT -1157040121 // 0xBB08F807
|
||||||
#define WUFFS_FLATE__ERROR_BAD_FLATE_BLOCK -1157040120 // 0xBB08F808
|
#define WUFFS_FLATE__ERROR_BAD_FLATE_BLOCK -1157040120 // 0xBB08F808
|
||||||
#define WUFFS_FLATE__ERROR_BAD_LITERAL_LENGTH_CODE_COUNT \
|
#define WUFFS_FLATE__ERROR_BAD_LITERAL_LENGTH_CODE_COUNT \
|
||||||
-1157040119 // 0xBB08F809
|
-1157040119 // 0xBB08F809
|
||||||
#define WUFFS_FLATE__ERROR_CHECKSUM_MISMATCH -1157040118 // 0xBB08F80A
|
|
||||||
#define WUFFS_FLATE__ERROR_INCONSISTENT_STORED_BLOCK_LENGTH \
|
#define WUFFS_FLATE__ERROR_INCONSISTENT_STORED_BLOCK_LENGTH \
|
||||||
-1157040117 // 0xBB08F80B
|
-1157040118 // 0xBB08F80A
|
||||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE \
|
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE \
|
||||||
-1157040116 // 0xBB08F80C
|
-1157040117 // 0xBB08F80B
|
||||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_END_OF_BLOCK \
|
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_END_OF_BLOCK \
|
||||||
-1157040115 // 0xBB08F80D
|
-1157040116 // 0xBB08F80C
|
||||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_DISTANCE \
|
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_DISTANCE \
|
||||||
-1157040114 // 0xBB08F80E
|
-1157040115 // 0xBB08F80D
|
||||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS \
|
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS \
|
||||||
-1157040113 // 0xBB08F80F
|
-1157040114 // 0xBB08F80E
|
||||||
#define WUFFS_FLATE__ERROR_MISSING_END_OF_BLOCK_CODE -1157040112 // 0xBB08F810
|
#define WUFFS_FLATE__ERROR_MISSING_END_OF_BLOCK_CODE -1157040113 // 0xBB08F80F
|
||||||
#define WUFFS_FLATE__ERROR_NO_HUFFMAN_CODES -1157040111 // 0xBB08F811
|
#define WUFFS_FLATE__ERROR_NO_HUFFMAN_CODES -1157040112 // 0xBB08F810
|
||||||
#define WUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_METHOD \
|
|
||||||
-1157040110 // 0xBB08F812
|
|
||||||
#define WUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_WINDOW_SIZE \
|
|
||||||
-1157040109 // 0xBB08F813
|
|
||||||
#define WUFFS_FLATE__ERROR_INVALID_ZLIB_PARITY_CHECK -1157040108 // 0xBB08F814
|
|
||||||
#define WUFFS_FLATE__ERROR_TODO_UNSUPPORTED_ZLIB_PRESET_DICTIONARY \
|
|
||||||
-1157040107 // 0xBB08F815
|
|
||||||
|
|
||||||
bool wuffs_flate__status__is_error(wuffs_flate__status s);
|
bool wuffs_flate__status__is_error(wuffs_flate__status s);
|
||||||
|
|
||||||
@@ -269,48 +261,6 @@ typedef struct {
|
|||||||
} private_impl;
|
} private_impl;
|
||||||
} wuffs_flate__flate_decoder;
|
} wuffs_flate__flate_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
|
|
||||||
// wuffs_flate__adler32__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 {
|
|
||||||
wuffs_flate__status status;
|
|
||||||
uint32_t magic;
|
|
||||||
|
|
||||||
uint32_t f_state;
|
|
||||||
|
|
||||||
} private_impl;
|
|
||||||
} wuffs_flate__adler32;
|
|
||||||
|
|
||||||
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
|
|
||||||
// wuffs_flate__zlib_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 {
|
|
||||||
wuffs_flate__status status;
|
|
||||||
uint32_t magic;
|
|
||||||
|
|
||||||
wuffs_flate__flate_decoder f_flate;
|
|
||||||
wuffs_flate__adler32 f_adler;
|
|
||||||
|
|
||||||
struct {
|
|
||||||
uint32_t coro_susp_point;
|
|
||||||
uint16_t v_x;
|
|
||||||
uint32_t v_checksum;
|
|
||||||
wuffs_flate__status v_z;
|
|
||||||
uint64_t scratch;
|
|
||||||
} c_decode[1];
|
|
||||||
} private_impl;
|
|
||||||
} wuffs_flate__zlib_decoder;
|
|
||||||
|
|
||||||
// ---------------- Public Initializer Prototypes
|
// ---------------- Public Initializer Prototypes
|
||||||
|
|
||||||
// wuffs_flate__flate_decoder__initialize is an initializer function.
|
// wuffs_flate__flate_decoder__initialize is an initializer function.
|
||||||
@@ -322,15 +272,6 @@ void wuffs_flate__flate_decoder__initialize(wuffs_flate__flate_decoder* self,
|
|||||||
uint32_t wuffs_version,
|
uint32_t wuffs_version,
|
||||||
uint32_t for_internal_use_only);
|
uint32_t for_internal_use_only);
|
||||||
|
|
||||||
// wuffs_flate__zlib_decoder__initialize is an initializer function.
|
|
||||||
//
|
|
||||||
// It should be called before any other wuffs_flate__zlib_decoder__* function.
|
|
||||||
//
|
|
||||||
// Pass WUFFS_VERSION and 0 for wuffs_version and for_internal_use_only.
|
|
||||||
void wuffs_flate__zlib_decoder__initialize(wuffs_flate__zlib_decoder* self,
|
|
||||||
uint32_t wuffs_version,
|
|
||||||
uint32_t for_internal_use_only);
|
|
||||||
|
|
||||||
// ---------------- Public Function Prototypes
|
// ---------------- Public Function Prototypes
|
||||||
|
|
||||||
wuffs_flate__status wuffs_flate__flate_decoder__decode(
|
wuffs_flate__status wuffs_flate__flate_decoder__decode(
|
||||||
@@ -338,11 +279,6 @@ wuffs_flate__status wuffs_flate__flate_decoder__decode(
|
|||||||
wuffs_base__writer1 a_dst,
|
wuffs_base__writer1 a_dst,
|
||||||
wuffs_base__reader1 a_src);
|
wuffs_base__reader1 a_src);
|
||||||
|
|
||||||
wuffs_flate__status wuffs_flate__zlib_decoder__decode(
|
|
||||||
wuffs_flate__zlib_decoder* self,
|
|
||||||
wuffs_base__writer1 a_dst,
|
|
||||||
wuffs_base__reader1 a_src);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+7
-3
@@ -15,8 +15,11 @@ file formats.
|
|||||||
is another wrapper, similar to combining gzip with tar, that can compress
|
is another wrapper, similar to combining gzip with tar, that can compress
|
||||||
multiple files into a single archive. Zip is widely used by the ECMA Office
|
multiple files into a single archive. Zip is widely used by the ECMA Office
|
||||||
Open XML format, the OASIS Open Document Format for Office Applications and the
|
Open XML format, the OASIS Open Document Format for Office Applications and the
|
||||||
Java JAR format. Parsing zip is not provided by this package, look at the
|
Java JAR format.
|
||||||
`std/zip` package instead (TODO).
|
|
||||||
|
Wrangling those formats that build on flate (gzip, zip and zlib) is not
|
||||||
|
provided by this package. For zlib, look at the `std/zlib` package instead. The
|
||||||
|
other formats are TODO.
|
||||||
|
|
||||||
For example, look at `test/testdata/romeo.txt*`. First, the uncompressed text:
|
For example, look at `test/testdata/romeo.txt*`. First, the uncompressed text:
|
||||||
|
|
||||||
@@ -50,7 +53,8 @@ uncompressed file (0x3ae = 942 bytes).
|
|||||||
00000220: 7a59 610d 7f01 ef07 e5ab ae03 0000 zYa...........
|
00000220: 7a59 610d 7f01 ef07 e5ab ae03 0000 zYa...........
|
||||||
|
|
||||||
The zlib format wraps a 2 byte header and 4 byte footer around the raw flate
|
The zlib format wraps a 2 byte header and 4 byte footer around the raw flate
|
||||||
data. The footer contains a 4 byte Adler32 checksum.
|
data. The footer contains a 4 byte Adler32 checksum. TODO: move this to
|
||||||
|
std/zlib/README.md.
|
||||||
|
|
||||||
$ xxd test/testdata/romeo.txt.zlib
|
$ xxd test/testdata/romeo.txt.zlib
|
||||||
00000000: 789c 4d53 c16e db30 0cbd f32b d853 2e46 x.MS.n.0...+.S.F
|
00000000: 789c 4d53 c16e db30 0cbd f32b d853 2e46 x.MS.n.0...+.S.F
|
||||||
|
|||||||
@@ -16,10 +16,6 @@ packageid "flte"
|
|||||||
|
|
||||||
// TODO: rename "struct flate_decoder" to just "struct decoder", to avoid
|
// TODO: rename "struct flate_decoder" to just "struct decoder", to avoid
|
||||||
// stutter in the fully qualified C name such as "wuffs_flate__flate_decoder".
|
// stutter in the fully qualified C name such as "wuffs_flate__flate_decoder".
|
||||||
//
|
|
||||||
// TODO: delete std/flate/decode_zlib.wuffs, and update std/flate/README.md.
|
|
||||||
//
|
|
||||||
// Would we then need to somehow share code between test/c/std/{flate,gzip}.c?
|
|
||||||
|
|
||||||
// TODO: rename flate to deflate, since that's what RFC 1951 calls it.
|
// TODO: rename flate to deflate, since that's what RFC 1951 calls it.
|
||||||
|
|
||||||
@@ -33,7 +29,6 @@ pub error "bad distance"
|
|||||||
pub error "bad distance code count"
|
pub error "bad distance code count"
|
||||||
pub error "bad flate block"
|
pub error "bad flate block"
|
||||||
pub error "bad literal/length code count"
|
pub error "bad literal/length code count"
|
||||||
pub error "checksum mismatch" // TODO: delete this.
|
|
||||||
pub error "inconsistent stored block length"
|
pub error "inconsistent stored block length"
|
||||||
pub error "internal error: inconsistent Huffman decoder state"
|
pub error "internal error: inconsistent Huffman decoder state"
|
||||||
pub error "internal error: inconsistent Huffman end_of_block"
|
pub error "internal error: inconsistent Huffman end_of_block"
|
||||||
|
|||||||
@@ -1,92 +0,0 @@
|
|||||||
// Copyright 2017 The Wuffs Authors.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// TODO: delete this file. Its contents have been copy/pasted to std/zlib.
|
|
||||||
|
|
||||||
pub error "invalid zlib compression method"
|
|
||||||
pub error "invalid zlib compression window size"
|
|
||||||
pub error "invalid zlib parity check"
|
|
||||||
|
|
||||||
pub error "TODO: unsupported zlib preset dictionary"
|
|
||||||
|
|
||||||
pub struct zlib_decoder?(
|
|
||||||
flate flate_decoder,
|
|
||||||
adler adler32,
|
|
||||||
)
|
|
||||||
|
|
||||||
pub func zlib_decoder.decode?(dst writer1, src reader1)() {
|
|
||||||
var x u16 = in.src.read_u16be?()
|
|
||||||
if ((x >> 8) & 0x0F) != 0x08 {
|
|
||||||
return error "invalid zlib compression method"
|
|
||||||
}
|
|
||||||
if (x >> 12) > 0x07 {
|
|
||||||
return error "invalid zlib compression window size"
|
|
||||||
}
|
|
||||||
if (x & 0x20) != 0 {
|
|
||||||
return error "TODO: unsupported zlib preset dictionary"
|
|
||||||
}
|
|
||||||
if (x % 31) != 0 {
|
|
||||||
return error "invalid zlib parity check"
|
|
||||||
}
|
|
||||||
var checksum u32
|
|
||||||
while true {
|
|
||||||
in.dst.mark()
|
|
||||||
var z status = try this.flate.decode?(dst:in.dst, src:in.src)
|
|
||||||
// TODO: expose some API to opt out of checksumming, trading off error
|
|
||||||
// detection for throughput.
|
|
||||||
checksum = this.adler.update(x:in.dst.since_mark())
|
|
||||||
if z.is_ok() {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
yield z
|
|
||||||
}
|
|
||||||
if checksum != in.src.read_u32be?() {
|
|
||||||
return error "checksum mismatch"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: drop the '?' but still generate wuffs_flate_adler_initialize?
|
|
||||||
pri struct adler32?(
|
|
||||||
state u32 = 1,
|
|
||||||
)
|
|
||||||
|
|
||||||
// TODO: add a ! as this function is impure.
|
|
||||||
pri func adler32.update(x[] u8)(checksum u32) {
|
|
||||||
// The Adler-32 checksum's magic 65521 and 5552 numbers are discussed in
|
|
||||||
// RFC 1950.
|
|
||||||
|
|
||||||
var s1 u32 = this.state.low_bits(n:16)
|
|
||||||
var s2 u32 = this.state.high_bits(n:16)
|
|
||||||
|
|
||||||
while in.x.length() > 0 {
|
|
||||||
var remaining[] u8
|
|
||||||
if in.x.length() > 5552 {
|
|
||||||
remaining = in.x[5552:]
|
|
||||||
in.x = in.x[:5552]
|
|
||||||
}
|
|
||||||
|
|
||||||
iterate.8 (p ptr u8:in.x) {
|
|
||||||
s1 ~+= deref p as u32
|
|
||||||
s2 ~+= s1
|
|
||||||
}
|
|
||||||
|
|
||||||
s1 %= 65521
|
|
||||||
s2 %= 65521
|
|
||||||
|
|
||||||
in.x = remaining
|
|
||||||
}
|
|
||||||
|
|
||||||
this.state = ((s2 & 0xFFFF) << 16) | (s1 & 0xFFFF)
|
|
||||||
return this.state
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user