mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 08:55:11 +01:00
Re-order the release/c code
Have the order of implementation code match the order of header code.
This commit is contained in:
1 parent
61d03537c2
commit
717d98441e
2 files changed
+452
-454
No files matched your search
@@ -235,12 +235,10 @@ func (h *genReleaseHelper) gen(w *bytes.Buffer, relFilename string, which int, d
|
|||||||
return fmt.Errorf("cannot resolve %q", relFilename)
|
return fmt.Errorf("cannot resolve %q", relFilename)
|
||||||
}
|
}
|
||||||
|
|
||||||
// For headers, process the files in #include-ee before #include-er order.
|
// Process the files in #include-ee before #include-er order.
|
||||||
if which == 0 {
|
for _, inc := range f.includes {
|
||||||
for _, inc := range f.includes {
|
if err := h.gen(w, inc, which, depth); err != nil {
|
||||||
if err := h.gen(w, inc, which, depth); err != nil {
|
return err
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6738,6 +6738,454 @@ exit:
|
|||||||
#endif // !defined(WUFFS_CONFIG__MODULES) ||
|
#endif // !defined(WUFFS_CONFIG__MODULES) ||
|
||||||
// defined(WUFFS_CONFIG__MODULE__DEFLATE)
|
// defined(WUFFS_CONFIG__MODULE__DEFLATE)
|
||||||
|
|
||||||
|
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__LZW)
|
||||||
|
|
||||||
|
// ---------------- Status Codes Implementations
|
||||||
|
|
||||||
|
const char* wuffs_lzw__error__bad_code = "?lzw: bad code";
|
||||||
|
const char* wuffs_lzw__error__internal_error_inconsistent_i_o =
|
||||||
|
"?lzw: internal error: inconsistent I/O";
|
||||||
|
|
||||||
|
// ---------------- Private Consts
|
||||||
|
|
||||||
|
// ---------------- Private Initializer Prototypes
|
||||||
|
|
||||||
|
// ---------------- Private Function Prototypes
|
||||||
|
|
||||||
|
static wuffs_base__status //
|
||||||
|
wuffs_lzw__decoder__flush(wuffs_lzw__decoder* self,
|
||||||
|
wuffs_base__io_writer a_dst);
|
||||||
|
|
||||||
|
// ---------------- Initializer Implementations
|
||||||
|
|
||||||
|
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
|
||||||
|
wuffs_lzw__decoder__check_wuffs_version(wuffs_lzw__decoder* self,
|
||||||
|
size_t sizeof_star_self,
|
||||||
|
uint64_t wuffs_version) {
|
||||||
|
if (!self) {
|
||||||
|
return wuffs_base__error__bad_receiver;
|
||||||
|
}
|
||||||
|
if (sizeof(*self) != sizeof_star_self) {
|
||||||
|
return wuffs_base__error__bad_sizeof_receiver;
|
||||||
|
}
|
||||||
|
if (((wuffs_version >> 32) != WUFFS_VERSION_MAJOR) ||
|
||||||
|
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
|
||||||
|
return wuffs_base__error__bad_wuffs_version;
|
||||||
|
}
|
||||||
|
if (self->private_impl.magic != 0) {
|
||||||
|
return wuffs_base__error__check_wuffs_version_not_applicable;
|
||||||
|
}
|
||||||
|
self->private_impl.magic = WUFFS_BASE__MAGIC;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t //
|
||||||
|
sizeof__wuffs_lzw__decoder() {
|
||||||
|
return sizeof((wuffs_lzw__decoder){});
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------- Function Implementations
|
||||||
|
|
||||||
|
// -------- func lzw.decoder.set_literal_width
|
||||||
|
|
||||||
|
WUFFS_BASE__MAYBE_STATIC void //
|
||||||
|
wuffs_lzw__decoder__set_literal_width(wuffs_lzw__decoder* self, uint32_t a_lw) {
|
||||||
|
if (!self) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (a_lw < 2 || a_lw > 8) {
|
||||||
|
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self->private_impl.f_literal_width = a_lw;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------- func lzw.decoder.decode
|
||||||
|
|
||||||
|
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
|
||||||
|
wuffs_lzw__decoder__decode(wuffs_lzw__decoder* self,
|
||||||
|
wuffs_base__io_writer a_dst,
|
||||||
|
wuffs_base__io_reader a_src) {
|
||||||
|
if (!self) {
|
||||||
|
return wuffs_base__error__bad_receiver;
|
||||||
|
}
|
||||||
|
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||||
|
return (self->private_impl.magic == WUFFS_BASE__DISABLED)
|
||||||
|
? wuffs_base__error__disabled_by_previous_error
|
||||||
|
: wuffs_base__error__check_wuffs_version_missing;
|
||||||
|
}
|
||||||
|
wuffs_base__status status = NULL;
|
||||||
|
|
||||||
|
uint32_t v_literal_width;
|
||||||
|
uint32_t v_clear_code;
|
||||||
|
uint32_t v_end_code;
|
||||||
|
uint32_t v_save_code;
|
||||||
|
uint32_t v_prev_code;
|
||||||
|
uint32_t v_width;
|
||||||
|
uint32_t v_j;
|
||||||
|
uint32_t v_bits;
|
||||||
|
uint32_t v_n_bits;
|
||||||
|
uint32_t v_code;
|
||||||
|
uint16_t v_lm1_a;
|
||||||
|
uint32_t v_c;
|
||||||
|
uint32_t v_o;
|
||||||
|
uint32_t v_steps;
|
||||||
|
uint8_t v_first_byte;
|
||||||
|
uint16_t v_lm1_b;
|
||||||
|
|
||||||
|
uint8_t* iop_a_src = NULL;
|
||||||
|
uint8_t* io0_a_src = NULL;
|
||||||
|
uint8_t* io1_a_src = NULL;
|
||||||
|
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
|
||||||
|
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
|
||||||
|
if (a_src.private_impl.buf) {
|
||||||
|
iop_a_src =
|
||||||
|
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
|
||||||
|
if (!a_src.private_impl.mark) {
|
||||||
|
a_src.private_impl.mark = iop_a_src;
|
||||||
|
a_src.private_impl.limit =
|
||||||
|
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.wi;
|
||||||
|
}
|
||||||
|
io0_a_src = a_src.private_impl.mark;
|
||||||
|
io1_a_src = a_src.private_impl.limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t coro_susp_point = self->private_impl.c_decode[0].coro_susp_point;
|
||||||
|
if (coro_susp_point) {
|
||||||
|
v_literal_width = self->private_impl.c_decode[0].v_literal_width;
|
||||||
|
v_clear_code = self->private_impl.c_decode[0].v_clear_code;
|
||||||
|
v_end_code = self->private_impl.c_decode[0].v_end_code;
|
||||||
|
v_save_code = self->private_impl.c_decode[0].v_save_code;
|
||||||
|
v_prev_code = self->private_impl.c_decode[0].v_prev_code;
|
||||||
|
v_width = self->private_impl.c_decode[0].v_width;
|
||||||
|
v_j = self->private_impl.c_decode[0].v_j;
|
||||||
|
v_bits = self->private_impl.c_decode[0].v_bits;
|
||||||
|
v_n_bits = self->private_impl.c_decode[0].v_n_bits;
|
||||||
|
v_code = self->private_impl.c_decode[0].v_code;
|
||||||
|
v_lm1_a = self->private_impl.c_decode[0].v_lm1_a;
|
||||||
|
v_c = self->private_impl.c_decode[0].v_c;
|
||||||
|
v_o = self->private_impl.c_decode[0].v_o;
|
||||||
|
v_steps = self->private_impl.c_decode[0].v_steps;
|
||||||
|
v_first_byte = self->private_impl.c_decode[0].v_first_byte;
|
||||||
|
v_lm1_b = self->private_impl.c_decode[0].v_lm1_b;
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
switch (coro_susp_point) {
|
||||||
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||||
|
|
||||||
|
v_literal_width = 8;
|
||||||
|
if (self->private_impl.f_literal_width >= 2) {
|
||||||
|
v_literal_width = self->private_impl.f_literal_width;
|
||||||
|
}
|
||||||
|
v_clear_code = (((uint32_t)(1)) << v_literal_width);
|
||||||
|
v_end_code = (v_clear_code + 1);
|
||||||
|
v_save_code = v_end_code;
|
||||||
|
v_prev_code = v_end_code;
|
||||||
|
v_width = (v_literal_width + 1);
|
||||||
|
v_j = 0;
|
||||||
|
while (v_j < v_clear_code) {
|
||||||
|
self->private_impl.f_lm1s[v_j] = 0;
|
||||||
|
self->private_impl.f_suffixes[v_j][0] = ((uint8_t)(v_j));
|
||||||
|
v_j += 1;
|
||||||
|
}
|
||||||
|
v_j = 0;
|
||||||
|
v_bits = 0;
|
||||||
|
v_n_bits = 0;
|
||||||
|
while (true) {
|
||||||
|
if (v_n_bits < v_width) {
|
||||||
|
if (((uint64_t)(io1_a_src - iop_a_src)) >= 4) {
|
||||||
|
v_bits |=
|
||||||
|
(((uint32_t)(wuffs_base__load_u32le(iop_a_src))) << v_n_bits);
|
||||||
|
(iop_a_src += ((31 - v_n_bits) >> 3),
|
||||||
|
wuffs_base__return_empty_struct());
|
||||||
|
v_n_bits |= 24;
|
||||||
|
} else {
|
||||||
|
while (true) {
|
||||||
|
while (((uint64_t)(io1_a_src - iop_a_src)) <= 0) {
|
||||||
|
if (v_j > 0) {
|
||||||
|
self->private_impl.f_flush_j = v_j;
|
||||||
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||||
|
status = wuffs_lzw__decoder__flush(self, a_dst);
|
||||||
|
if (status) {
|
||||||
|
goto suspend;
|
||||||
|
}
|
||||||
|
v_j = 0;
|
||||||
|
}
|
||||||
|
status = wuffs_base__suspension__short_read;
|
||||||
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
|
||||||
|
}
|
||||||
|
v_bits |=
|
||||||
|
(((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
|
||||||
|
(iop_a_src += 1, wuffs_base__return_empty_struct());
|
||||||
|
v_n_bits += 8;
|
||||||
|
if (v_n_bits >= v_width) {
|
||||||
|
goto label_0_break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
label_0_break:;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
v_code = ((v_bits)&WUFFS_BASE__LOW_BITS_MASK__U32(v_width));
|
||||||
|
v_bits >>= v_width;
|
||||||
|
v_n_bits -= v_width;
|
||||||
|
if (v_code < v_clear_code) {
|
||||||
|
self->private_impl.f_output[v_j] = ((uint8_t)(v_code));
|
||||||
|
v_j = ((v_j + 1) & 8191);
|
||||||
|
if (v_save_code <= 4095) {
|
||||||
|
v_lm1_a = ((self->private_impl.f_lm1s[v_prev_code] + 1) & 4095);
|
||||||
|
self->private_impl.f_lm1s[v_save_code] = v_lm1_a;
|
||||||
|
if ((v_lm1_a % 8) != 0) {
|
||||||
|
self->private_impl.f_prefixes[v_save_code] =
|
||||||
|
self->private_impl.f_prefixes[v_prev_code];
|
||||||
|
memcpy(self->private_impl.f_suffixes[v_save_code],
|
||||||
|
self->private_impl.f_suffixes[v_prev_code], 8);
|
||||||
|
self->private_impl.f_suffixes[v_save_code][(v_lm1_a % 8)] =
|
||||||
|
((uint8_t)(v_code));
|
||||||
|
} else {
|
||||||
|
self->private_impl.f_prefixes[v_save_code] =
|
||||||
|
((uint16_t)(v_prev_code));
|
||||||
|
self->private_impl.f_suffixes[v_save_code][0] = ((uint8_t)(v_code));
|
||||||
|
}
|
||||||
|
v_save_code += 1;
|
||||||
|
if ((v_save_code == (((uint32_t)(1)) << v_width)) && (v_width < 12)) {
|
||||||
|
v_width += 1;
|
||||||
|
}
|
||||||
|
v_prev_code = v_code;
|
||||||
|
}
|
||||||
|
} else if (v_code <= v_end_code) {
|
||||||
|
if (v_code == v_end_code) {
|
||||||
|
goto label_1_break;
|
||||||
|
}
|
||||||
|
v_save_code = v_end_code;
|
||||||
|
v_prev_code = v_end_code;
|
||||||
|
v_width = (v_literal_width + 1);
|
||||||
|
} else if (v_code <= v_save_code) {
|
||||||
|
v_c = v_code;
|
||||||
|
if (v_code == v_save_code) {
|
||||||
|
v_c = v_prev_code;
|
||||||
|
}
|
||||||
|
v_o = ((v_j +
|
||||||
|
(((uint32_t)(self->private_impl.f_lm1s[v_c])) & 4294967288)) &
|
||||||
|
8191);
|
||||||
|
v_j = ((v_j + 1 + ((uint32_t)(self->private_impl.f_lm1s[v_c]))) & 8191);
|
||||||
|
v_steps = (((uint32_t)(self->private_impl.f_lm1s[v_c])) >> 3);
|
||||||
|
while (true) {
|
||||||
|
memcpy((self->private_impl.f_output) + (v_o),
|
||||||
|
(self->private_impl.f_suffixes[v_c]), 8);
|
||||||
|
if (v_steps <= 0) {
|
||||||
|
goto label_2_break;
|
||||||
|
}
|
||||||
|
v_steps -= 1;
|
||||||
|
v_o = ((v_o - 8) & 8191);
|
||||||
|
v_c = ((uint32_t)(self->private_impl.f_prefixes[v_c]));
|
||||||
|
}
|
||||||
|
label_2_break:;
|
||||||
|
v_first_byte = self->private_impl.f_suffixes[v_c][0];
|
||||||
|
if (v_code == v_save_code) {
|
||||||
|
self->private_impl.f_output[v_j] = v_first_byte;
|
||||||
|
v_j = ((v_j + 1) & 8191);
|
||||||
|
}
|
||||||
|
if (v_save_code <= 4095) {
|
||||||
|
v_lm1_b = ((self->private_impl.f_lm1s[v_prev_code] + 1) & 4095);
|
||||||
|
self->private_impl.f_lm1s[v_save_code] = v_lm1_b;
|
||||||
|
if ((v_lm1_b % 8) != 0) {
|
||||||
|
self->private_impl.f_prefixes[v_save_code] =
|
||||||
|
self->private_impl.f_prefixes[v_prev_code];
|
||||||
|
memcpy(self->private_impl.f_suffixes[v_save_code],
|
||||||
|
self->private_impl.f_suffixes[v_prev_code], 8);
|
||||||
|
self->private_impl.f_suffixes[v_save_code][(v_lm1_b % 8)] =
|
||||||
|
v_first_byte;
|
||||||
|
} else {
|
||||||
|
self->private_impl.f_prefixes[v_save_code] =
|
||||||
|
((uint16_t)(v_prev_code));
|
||||||
|
self->private_impl.f_suffixes[v_save_code][0] =
|
||||||
|
((uint8_t)(v_first_byte));
|
||||||
|
}
|
||||||
|
v_save_code += 1;
|
||||||
|
if ((v_save_code == (((uint32_t)(1)) << v_width)) && (v_width < 12)) {
|
||||||
|
v_width += 1;
|
||||||
|
}
|
||||||
|
v_prev_code = v_code;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
status = wuffs_lzw__error__bad_code;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
if (v_j > 4095) {
|
||||||
|
while (v_n_bits >= 8) {
|
||||||
|
v_n_bits -= 8;
|
||||||
|
if (iop_a_src > io0_a_src) {
|
||||||
|
(iop_a_src--, wuffs_base__return_empty_struct());
|
||||||
|
} else {
|
||||||
|
status = wuffs_lzw__error__internal_error_inconsistent_i_o;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
v_bits = ((v_bits)&WUFFS_BASE__LOW_BITS_MASK__U32(v_n_bits));
|
||||||
|
self->private_impl.f_flush_j = v_j;
|
||||||
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||||
|
status = wuffs_lzw__decoder__flush(self, a_dst);
|
||||||
|
if (status) {
|
||||||
|
goto suspend;
|
||||||
|
}
|
||||||
|
v_j = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
label_1_break:;
|
||||||
|
if (v_j > 0) {
|
||||||
|
while (v_n_bits >= 8) {
|
||||||
|
v_n_bits -= 8;
|
||||||
|
if (iop_a_src > io0_a_src) {
|
||||||
|
(iop_a_src--, wuffs_base__return_empty_struct());
|
||||||
|
} else {
|
||||||
|
status = wuffs_lzw__error__internal_error_inconsistent_i_o;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
v_bits = ((v_bits)&WUFFS_BASE__LOW_BITS_MASK__U32(v_n_bits));
|
||||||
|
self->private_impl.f_flush_j = v_j;
|
||||||
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||||
|
status = wuffs_lzw__decoder__flush(self, a_dst);
|
||||||
|
if (status) {
|
||||||
|
goto suspend;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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_literal_width = v_literal_width;
|
||||||
|
self->private_impl.c_decode[0].v_clear_code = v_clear_code;
|
||||||
|
self->private_impl.c_decode[0].v_end_code = v_end_code;
|
||||||
|
self->private_impl.c_decode[0].v_save_code = v_save_code;
|
||||||
|
self->private_impl.c_decode[0].v_prev_code = v_prev_code;
|
||||||
|
self->private_impl.c_decode[0].v_width = v_width;
|
||||||
|
self->private_impl.c_decode[0].v_j = v_j;
|
||||||
|
self->private_impl.c_decode[0].v_bits = v_bits;
|
||||||
|
self->private_impl.c_decode[0].v_n_bits = v_n_bits;
|
||||||
|
self->private_impl.c_decode[0].v_code = v_code;
|
||||||
|
self->private_impl.c_decode[0].v_lm1_a = v_lm1_a;
|
||||||
|
self->private_impl.c_decode[0].v_c = v_c;
|
||||||
|
self->private_impl.c_decode[0].v_o = v_o;
|
||||||
|
self->private_impl.c_decode[0].v_steps = v_steps;
|
||||||
|
self->private_impl.c_decode[0].v_first_byte = v_first_byte;
|
||||||
|
self->private_impl.c_decode[0].v_lm1_b = v_lm1_b;
|
||||||
|
|
||||||
|
goto exit;
|
||||||
|
exit:
|
||||||
|
if (a_src.private_impl.buf) {
|
||||||
|
a_src.private_impl.buf->meta.ri =
|
||||||
|
iop_a_src - a_src.private_impl.buf->data.ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wuffs_base__status__is_error(status)) {
|
||||||
|
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------- func lzw.decoder.flush
|
||||||
|
|
||||||
|
static wuffs_base__status //
|
||||||
|
wuffs_lzw__decoder__flush(wuffs_lzw__decoder* self,
|
||||||
|
wuffs_base__io_writer a_dst) {
|
||||||
|
wuffs_base__status status = NULL;
|
||||||
|
|
||||||
|
uint32_t v_i;
|
||||||
|
uint32_t v_j;
|
||||||
|
wuffs_base__slice_u8 v_s;
|
||||||
|
uint64_t v_n;
|
||||||
|
|
||||||
|
uint8_t* iop_a_dst = NULL;
|
||||||
|
uint8_t* io0_a_dst = NULL;
|
||||||
|
uint8_t* io1_a_dst = NULL;
|
||||||
|
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_dst);
|
||||||
|
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_dst);
|
||||||
|
if (a_dst.private_impl.buf) {
|
||||||
|
iop_a_dst =
|
||||||
|
a_dst.private_impl.buf->data.ptr + a_dst.private_impl.buf->meta.wi;
|
||||||
|
if (!a_dst.private_impl.mark) {
|
||||||
|
a_dst.private_impl.mark = iop_a_dst;
|
||||||
|
a_dst.private_impl.limit =
|
||||||
|
a_dst.private_impl.buf->data.ptr + a_dst.private_impl.buf->data.len;
|
||||||
|
}
|
||||||
|
if (a_dst.private_impl.buf->meta.closed) {
|
||||||
|
a_dst.private_impl.limit = iop_a_dst;
|
||||||
|
}
|
||||||
|
io0_a_dst = a_dst.private_impl.mark;
|
||||||
|
io1_a_dst = a_dst.private_impl.limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t coro_susp_point = self->private_impl.c_flush[0].coro_susp_point;
|
||||||
|
if (coro_susp_point) {
|
||||||
|
v_i = self->private_impl.c_flush[0].v_i;
|
||||||
|
v_j = self->private_impl.c_flush[0].v_j;
|
||||||
|
v_s = ((wuffs_base__slice_u8){});
|
||||||
|
v_n = self->private_impl.c_flush[0].v_n;
|
||||||
|
} else {
|
||||||
|
v_s = ((wuffs_base__slice_u8){});
|
||||||
|
}
|
||||||
|
switch (coro_susp_point) {
|
||||||
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||||
|
|
||||||
|
v_i = 0;
|
||||||
|
v_j = self->private_impl.f_flush_j;
|
||||||
|
while (true) {
|
||||||
|
if (v_i > v_j) {
|
||||||
|
status = wuffs_lzw__error__internal_error_inconsistent_i_o;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
v_s = wuffs_base__slice_u8__subslice_ij(
|
||||||
|
((wuffs_base__slice_u8){
|
||||||
|
.ptr = self->private_impl.f_output,
|
||||||
|
.len = 8199,
|
||||||
|
}),
|
||||||
|
v_i, v_j);
|
||||||
|
v_n = wuffs_base__io_writer__copy_from_slice(&iop_a_dst, io1_a_dst, v_s);
|
||||||
|
if (v_n == ((uint64_t)(v_s.len))) {
|
||||||
|
status = NULL;
|
||||||
|
goto ok;
|
||||||
|
}
|
||||||
|
v_i = ((v_i + ((uint32_t)((v_n & 8191)))) & 8191);
|
||||||
|
status = wuffs_base__suspension__short_write;
|
||||||
|
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
goto ok;
|
||||||
|
ok:
|
||||||
|
self->private_impl.c_flush[0].coro_susp_point = 0;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
goto suspend;
|
||||||
|
suspend:
|
||||||
|
self->private_impl.c_flush[0].coro_susp_point = coro_susp_point;
|
||||||
|
self->private_impl.c_flush[0].v_i = v_i;
|
||||||
|
self->private_impl.c_flush[0].v_j = v_j;
|
||||||
|
self->private_impl.c_flush[0].v_n = v_n;
|
||||||
|
|
||||||
|
goto exit;
|
||||||
|
exit:
|
||||||
|
if (a_dst.private_impl.buf) {
|
||||||
|
a_dst.private_impl.buf->meta.wi =
|
||||||
|
iop_a_dst - a_dst.private_impl.buf->data.ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__LZW)
|
||||||
|
|
||||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GIF)
|
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__GIF)
|
||||||
|
|
||||||
// ---------------- Status Codes Implementations
|
// ---------------- Status Codes Implementations
|
||||||
@@ -9333,454 +9781,6 @@ exit:
|
|||||||
#endif // !defined(WUFFS_CONFIG__MODULES) ||
|
#endif // !defined(WUFFS_CONFIG__MODULES) ||
|
||||||
// defined(WUFFS_CONFIG__MODULE__GZIP)
|
// defined(WUFFS_CONFIG__MODULE__GZIP)
|
||||||
|
|
||||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__LZW)
|
|
||||||
|
|
||||||
// ---------------- Status Codes Implementations
|
|
||||||
|
|
||||||
const char* wuffs_lzw__error__bad_code = "?lzw: bad code";
|
|
||||||
const char* wuffs_lzw__error__internal_error_inconsistent_i_o =
|
|
||||||
"?lzw: internal error: inconsistent I/O";
|
|
||||||
|
|
||||||
// ---------------- Private Consts
|
|
||||||
|
|
||||||
// ---------------- Private Initializer Prototypes
|
|
||||||
|
|
||||||
// ---------------- Private Function Prototypes
|
|
||||||
|
|
||||||
static wuffs_base__status //
|
|
||||||
wuffs_lzw__decoder__flush(wuffs_lzw__decoder* self,
|
|
||||||
wuffs_base__io_writer a_dst);
|
|
||||||
|
|
||||||
// ---------------- Initializer Implementations
|
|
||||||
|
|
||||||
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
|
|
||||||
wuffs_lzw__decoder__check_wuffs_version(wuffs_lzw__decoder* self,
|
|
||||||
size_t sizeof_star_self,
|
|
||||||
uint64_t wuffs_version) {
|
|
||||||
if (!self) {
|
|
||||||
return wuffs_base__error__bad_receiver;
|
|
||||||
}
|
|
||||||
if (sizeof(*self) != sizeof_star_self) {
|
|
||||||
return wuffs_base__error__bad_sizeof_receiver;
|
|
||||||
}
|
|
||||||
if (((wuffs_version >> 32) != WUFFS_VERSION_MAJOR) ||
|
|
||||||
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
|
|
||||||
return wuffs_base__error__bad_wuffs_version;
|
|
||||||
}
|
|
||||||
if (self->private_impl.magic != 0) {
|
|
||||||
return wuffs_base__error__check_wuffs_version_not_applicable;
|
|
||||||
}
|
|
||||||
self->private_impl.magic = WUFFS_BASE__MAGIC;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t //
|
|
||||||
sizeof__wuffs_lzw__decoder() {
|
|
||||||
return sizeof((wuffs_lzw__decoder){});
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------- Function Implementations
|
|
||||||
|
|
||||||
// -------- func lzw.decoder.set_literal_width
|
|
||||||
|
|
||||||
WUFFS_BASE__MAYBE_STATIC void //
|
|
||||||
wuffs_lzw__decoder__set_literal_width(wuffs_lzw__decoder* self, uint32_t a_lw) {
|
|
||||||
if (!self) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (a_lw < 2 || a_lw > 8) {
|
|
||||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self->private_impl.f_literal_width = a_lw;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------- func lzw.decoder.decode
|
|
||||||
|
|
||||||
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
|
|
||||||
wuffs_lzw__decoder__decode(wuffs_lzw__decoder* self,
|
|
||||||
wuffs_base__io_writer a_dst,
|
|
||||||
wuffs_base__io_reader a_src) {
|
|
||||||
if (!self) {
|
|
||||||
return wuffs_base__error__bad_receiver;
|
|
||||||
}
|
|
||||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
|
||||||
return (self->private_impl.magic == WUFFS_BASE__DISABLED)
|
|
||||||
? wuffs_base__error__disabled_by_previous_error
|
|
||||||
: wuffs_base__error__check_wuffs_version_missing;
|
|
||||||
}
|
|
||||||
wuffs_base__status status = NULL;
|
|
||||||
|
|
||||||
uint32_t v_literal_width;
|
|
||||||
uint32_t v_clear_code;
|
|
||||||
uint32_t v_end_code;
|
|
||||||
uint32_t v_save_code;
|
|
||||||
uint32_t v_prev_code;
|
|
||||||
uint32_t v_width;
|
|
||||||
uint32_t v_j;
|
|
||||||
uint32_t v_bits;
|
|
||||||
uint32_t v_n_bits;
|
|
||||||
uint32_t v_code;
|
|
||||||
uint16_t v_lm1_a;
|
|
||||||
uint32_t v_c;
|
|
||||||
uint32_t v_o;
|
|
||||||
uint32_t v_steps;
|
|
||||||
uint8_t v_first_byte;
|
|
||||||
uint16_t v_lm1_b;
|
|
||||||
|
|
||||||
uint8_t* iop_a_src = NULL;
|
|
||||||
uint8_t* io0_a_src = NULL;
|
|
||||||
uint8_t* io1_a_src = NULL;
|
|
||||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
|
|
||||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
|
|
||||||
if (a_src.private_impl.buf) {
|
|
||||||
iop_a_src =
|
|
||||||
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
|
|
||||||
if (!a_src.private_impl.mark) {
|
|
||||||
a_src.private_impl.mark = iop_a_src;
|
|
||||||
a_src.private_impl.limit =
|
|
||||||
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.wi;
|
|
||||||
}
|
|
||||||
io0_a_src = a_src.private_impl.mark;
|
|
||||||
io1_a_src = a_src.private_impl.limit;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t coro_susp_point = self->private_impl.c_decode[0].coro_susp_point;
|
|
||||||
if (coro_susp_point) {
|
|
||||||
v_literal_width = self->private_impl.c_decode[0].v_literal_width;
|
|
||||||
v_clear_code = self->private_impl.c_decode[0].v_clear_code;
|
|
||||||
v_end_code = self->private_impl.c_decode[0].v_end_code;
|
|
||||||
v_save_code = self->private_impl.c_decode[0].v_save_code;
|
|
||||||
v_prev_code = self->private_impl.c_decode[0].v_prev_code;
|
|
||||||
v_width = self->private_impl.c_decode[0].v_width;
|
|
||||||
v_j = self->private_impl.c_decode[0].v_j;
|
|
||||||
v_bits = self->private_impl.c_decode[0].v_bits;
|
|
||||||
v_n_bits = self->private_impl.c_decode[0].v_n_bits;
|
|
||||||
v_code = self->private_impl.c_decode[0].v_code;
|
|
||||||
v_lm1_a = self->private_impl.c_decode[0].v_lm1_a;
|
|
||||||
v_c = self->private_impl.c_decode[0].v_c;
|
|
||||||
v_o = self->private_impl.c_decode[0].v_o;
|
|
||||||
v_steps = self->private_impl.c_decode[0].v_steps;
|
|
||||||
v_first_byte = self->private_impl.c_decode[0].v_first_byte;
|
|
||||||
v_lm1_b = self->private_impl.c_decode[0].v_lm1_b;
|
|
||||||
} else {
|
|
||||||
}
|
|
||||||
switch (coro_susp_point) {
|
|
||||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
|
||||||
|
|
||||||
v_literal_width = 8;
|
|
||||||
if (self->private_impl.f_literal_width >= 2) {
|
|
||||||
v_literal_width = self->private_impl.f_literal_width;
|
|
||||||
}
|
|
||||||
v_clear_code = (((uint32_t)(1)) << v_literal_width);
|
|
||||||
v_end_code = (v_clear_code + 1);
|
|
||||||
v_save_code = v_end_code;
|
|
||||||
v_prev_code = v_end_code;
|
|
||||||
v_width = (v_literal_width + 1);
|
|
||||||
v_j = 0;
|
|
||||||
while (v_j < v_clear_code) {
|
|
||||||
self->private_impl.f_lm1s[v_j] = 0;
|
|
||||||
self->private_impl.f_suffixes[v_j][0] = ((uint8_t)(v_j));
|
|
||||||
v_j += 1;
|
|
||||||
}
|
|
||||||
v_j = 0;
|
|
||||||
v_bits = 0;
|
|
||||||
v_n_bits = 0;
|
|
||||||
while (true) {
|
|
||||||
if (v_n_bits < v_width) {
|
|
||||||
if (((uint64_t)(io1_a_src - iop_a_src)) >= 4) {
|
|
||||||
v_bits |=
|
|
||||||
(((uint32_t)(wuffs_base__load_u32le(iop_a_src))) << v_n_bits);
|
|
||||||
(iop_a_src += ((31 - v_n_bits) >> 3),
|
|
||||||
wuffs_base__return_empty_struct());
|
|
||||||
v_n_bits |= 24;
|
|
||||||
} else {
|
|
||||||
while (true) {
|
|
||||||
while (((uint64_t)(io1_a_src - iop_a_src)) <= 0) {
|
|
||||||
if (v_j > 0) {
|
|
||||||
self->private_impl.f_flush_j = v_j;
|
|
||||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
|
||||||
status = wuffs_lzw__decoder__flush(self, a_dst);
|
|
||||||
if (status) {
|
|
||||||
goto suspend;
|
|
||||||
}
|
|
||||||
v_j = 0;
|
|
||||||
}
|
|
||||||
status = wuffs_base__suspension__short_read;
|
|
||||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
|
|
||||||
}
|
|
||||||
v_bits |=
|
|
||||||
(((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
|
|
||||||
(iop_a_src += 1, wuffs_base__return_empty_struct());
|
|
||||||
v_n_bits += 8;
|
|
||||||
if (v_n_bits >= v_width) {
|
|
||||||
goto label_0_break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
label_0_break:;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
v_code = ((v_bits)&WUFFS_BASE__LOW_BITS_MASK__U32(v_width));
|
|
||||||
v_bits >>= v_width;
|
|
||||||
v_n_bits -= v_width;
|
|
||||||
if (v_code < v_clear_code) {
|
|
||||||
self->private_impl.f_output[v_j] = ((uint8_t)(v_code));
|
|
||||||
v_j = ((v_j + 1) & 8191);
|
|
||||||
if (v_save_code <= 4095) {
|
|
||||||
v_lm1_a = ((self->private_impl.f_lm1s[v_prev_code] + 1) & 4095);
|
|
||||||
self->private_impl.f_lm1s[v_save_code] = v_lm1_a;
|
|
||||||
if ((v_lm1_a % 8) != 0) {
|
|
||||||
self->private_impl.f_prefixes[v_save_code] =
|
|
||||||
self->private_impl.f_prefixes[v_prev_code];
|
|
||||||
memcpy(self->private_impl.f_suffixes[v_save_code],
|
|
||||||
self->private_impl.f_suffixes[v_prev_code], 8);
|
|
||||||
self->private_impl.f_suffixes[v_save_code][(v_lm1_a % 8)] =
|
|
||||||
((uint8_t)(v_code));
|
|
||||||
} else {
|
|
||||||
self->private_impl.f_prefixes[v_save_code] =
|
|
||||||
((uint16_t)(v_prev_code));
|
|
||||||
self->private_impl.f_suffixes[v_save_code][0] = ((uint8_t)(v_code));
|
|
||||||
}
|
|
||||||
v_save_code += 1;
|
|
||||||
if ((v_save_code == (((uint32_t)(1)) << v_width)) && (v_width < 12)) {
|
|
||||||
v_width += 1;
|
|
||||||
}
|
|
||||||
v_prev_code = v_code;
|
|
||||||
}
|
|
||||||
} else if (v_code <= v_end_code) {
|
|
||||||
if (v_code == v_end_code) {
|
|
||||||
goto label_1_break;
|
|
||||||
}
|
|
||||||
v_save_code = v_end_code;
|
|
||||||
v_prev_code = v_end_code;
|
|
||||||
v_width = (v_literal_width + 1);
|
|
||||||
} else if (v_code <= v_save_code) {
|
|
||||||
v_c = v_code;
|
|
||||||
if (v_code == v_save_code) {
|
|
||||||
v_c = v_prev_code;
|
|
||||||
}
|
|
||||||
v_o = ((v_j +
|
|
||||||
(((uint32_t)(self->private_impl.f_lm1s[v_c])) & 4294967288)) &
|
|
||||||
8191);
|
|
||||||
v_j = ((v_j + 1 + ((uint32_t)(self->private_impl.f_lm1s[v_c]))) & 8191);
|
|
||||||
v_steps = (((uint32_t)(self->private_impl.f_lm1s[v_c])) >> 3);
|
|
||||||
while (true) {
|
|
||||||
memcpy((self->private_impl.f_output) + (v_o),
|
|
||||||
(self->private_impl.f_suffixes[v_c]), 8);
|
|
||||||
if (v_steps <= 0) {
|
|
||||||
goto label_2_break;
|
|
||||||
}
|
|
||||||
v_steps -= 1;
|
|
||||||
v_o = ((v_o - 8) & 8191);
|
|
||||||
v_c = ((uint32_t)(self->private_impl.f_prefixes[v_c]));
|
|
||||||
}
|
|
||||||
label_2_break:;
|
|
||||||
v_first_byte = self->private_impl.f_suffixes[v_c][0];
|
|
||||||
if (v_code == v_save_code) {
|
|
||||||
self->private_impl.f_output[v_j] = v_first_byte;
|
|
||||||
v_j = ((v_j + 1) & 8191);
|
|
||||||
}
|
|
||||||
if (v_save_code <= 4095) {
|
|
||||||
v_lm1_b = ((self->private_impl.f_lm1s[v_prev_code] + 1) & 4095);
|
|
||||||
self->private_impl.f_lm1s[v_save_code] = v_lm1_b;
|
|
||||||
if ((v_lm1_b % 8) != 0) {
|
|
||||||
self->private_impl.f_prefixes[v_save_code] =
|
|
||||||
self->private_impl.f_prefixes[v_prev_code];
|
|
||||||
memcpy(self->private_impl.f_suffixes[v_save_code],
|
|
||||||
self->private_impl.f_suffixes[v_prev_code], 8);
|
|
||||||
self->private_impl.f_suffixes[v_save_code][(v_lm1_b % 8)] =
|
|
||||||
v_first_byte;
|
|
||||||
} else {
|
|
||||||
self->private_impl.f_prefixes[v_save_code] =
|
|
||||||
((uint16_t)(v_prev_code));
|
|
||||||
self->private_impl.f_suffixes[v_save_code][0] =
|
|
||||||
((uint8_t)(v_first_byte));
|
|
||||||
}
|
|
||||||
v_save_code += 1;
|
|
||||||
if ((v_save_code == (((uint32_t)(1)) << v_width)) && (v_width < 12)) {
|
|
||||||
v_width += 1;
|
|
||||||
}
|
|
||||||
v_prev_code = v_code;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
status = wuffs_lzw__error__bad_code;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
if (v_j > 4095) {
|
|
||||||
while (v_n_bits >= 8) {
|
|
||||||
v_n_bits -= 8;
|
|
||||||
if (iop_a_src > io0_a_src) {
|
|
||||||
(iop_a_src--, wuffs_base__return_empty_struct());
|
|
||||||
} else {
|
|
||||||
status = wuffs_lzw__error__internal_error_inconsistent_i_o;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
v_bits = ((v_bits)&WUFFS_BASE__LOW_BITS_MASK__U32(v_n_bits));
|
|
||||||
self->private_impl.f_flush_j = v_j;
|
|
||||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
|
||||||
status = wuffs_lzw__decoder__flush(self, a_dst);
|
|
||||||
if (status) {
|
|
||||||
goto suspend;
|
|
||||||
}
|
|
||||||
v_j = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
label_1_break:;
|
|
||||||
if (v_j > 0) {
|
|
||||||
while (v_n_bits >= 8) {
|
|
||||||
v_n_bits -= 8;
|
|
||||||
if (iop_a_src > io0_a_src) {
|
|
||||||
(iop_a_src--, wuffs_base__return_empty_struct());
|
|
||||||
} else {
|
|
||||||
status = wuffs_lzw__error__internal_error_inconsistent_i_o;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
v_bits = ((v_bits)&WUFFS_BASE__LOW_BITS_MASK__U32(v_n_bits));
|
|
||||||
self->private_impl.f_flush_j = v_j;
|
|
||||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
|
||||||
status = wuffs_lzw__decoder__flush(self, a_dst);
|
|
||||||
if (status) {
|
|
||||||
goto suspend;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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_literal_width = v_literal_width;
|
|
||||||
self->private_impl.c_decode[0].v_clear_code = v_clear_code;
|
|
||||||
self->private_impl.c_decode[0].v_end_code = v_end_code;
|
|
||||||
self->private_impl.c_decode[0].v_save_code = v_save_code;
|
|
||||||
self->private_impl.c_decode[0].v_prev_code = v_prev_code;
|
|
||||||
self->private_impl.c_decode[0].v_width = v_width;
|
|
||||||
self->private_impl.c_decode[0].v_j = v_j;
|
|
||||||
self->private_impl.c_decode[0].v_bits = v_bits;
|
|
||||||
self->private_impl.c_decode[0].v_n_bits = v_n_bits;
|
|
||||||
self->private_impl.c_decode[0].v_code = v_code;
|
|
||||||
self->private_impl.c_decode[0].v_lm1_a = v_lm1_a;
|
|
||||||
self->private_impl.c_decode[0].v_c = v_c;
|
|
||||||
self->private_impl.c_decode[0].v_o = v_o;
|
|
||||||
self->private_impl.c_decode[0].v_steps = v_steps;
|
|
||||||
self->private_impl.c_decode[0].v_first_byte = v_first_byte;
|
|
||||||
self->private_impl.c_decode[0].v_lm1_b = v_lm1_b;
|
|
||||||
|
|
||||||
goto exit;
|
|
||||||
exit:
|
|
||||||
if (a_src.private_impl.buf) {
|
|
||||||
a_src.private_impl.buf->meta.ri =
|
|
||||||
iop_a_src - a_src.private_impl.buf->data.ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wuffs_base__status__is_error(status)) {
|
|
||||||
self->private_impl.magic = WUFFS_BASE__DISABLED;
|
|
||||||
}
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------- func lzw.decoder.flush
|
|
||||||
|
|
||||||
static wuffs_base__status //
|
|
||||||
wuffs_lzw__decoder__flush(wuffs_lzw__decoder* self,
|
|
||||||
wuffs_base__io_writer a_dst) {
|
|
||||||
wuffs_base__status status = NULL;
|
|
||||||
|
|
||||||
uint32_t v_i;
|
|
||||||
uint32_t v_j;
|
|
||||||
wuffs_base__slice_u8 v_s;
|
|
||||||
uint64_t v_n;
|
|
||||||
|
|
||||||
uint8_t* iop_a_dst = NULL;
|
|
||||||
uint8_t* io0_a_dst = NULL;
|
|
||||||
uint8_t* io1_a_dst = NULL;
|
|
||||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_dst);
|
|
||||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_dst);
|
|
||||||
if (a_dst.private_impl.buf) {
|
|
||||||
iop_a_dst =
|
|
||||||
a_dst.private_impl.buf->data.ptr + a_dst.private_impl.buf->meta.wi;
|
|
||||||
if (!a_dst.private_impl.mark) {
|
|
||||||
a_dst.private_impl.mark = iop_a_dst;
|
|
||||||
a_dst.private_impl.limit =
|
|
||||||
a_dst.private_impl.buf->data.ptr + a_dst.private_impl.buf->data.len;
|
|
||||||
}
|
|
||||||
if (a_dst.private_impl.buf->meta.closed) {
|
|
||||||
a_dst.private_impl.limit = iop_a_dst;
|
|
||||||
}
|
|
||||||
io0_a_dst = a_dst.private_impl.mark;
|
|
||||||
io1_a_dst = a_dst.private_impl.limit;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t coro_susp_point = self->private_impl.c_flush[0].coro_susp_point;
|
|
||||||
if (coro_susp_point) {
|
|
||||||
v_i = self->private_impl.c_flush[0].v_i;
|
|
||||||
v_j = self->private_impl.c_flush[0].v_j;
|
|
||||||
v_s = ((wuffs_base__slice_u8){});
|
|
||||||
v_n = self->private_impl.c_flush[0].v_n;
|
|
||||||
} else {
|
|
||||||
v_s = ((wuffs_base__slice_u8){});
|
|
||||||
}
|
|
||||||
switch (coro_susp_point) {
|
|
||||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
|
||||||
|
|
||||||
v_i = 0;
|
|
||||||
v_j = self->private_impl.f_flush_j;
|
|
||||||
while (true) {
|
|
||||||
if (v_i > v_j) {
|
|
||||||
status = wuffs_lzw__error__internal_error_inconsistent_i_o;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
v_s = wuffs_base__slice_u8__subslice_ij(
|
|
||||||
((wuffs_base__slice_u8){
|
|
||||||
.ptr = self->private_impl.f_output,
|
|
||||||
.len = 8199,
|
|
||||||
}),
|
|
||||||
v_i, v_j);
|
|
||||||
v_n = wuffs_base__io_writer__copy_from_slice(&iop_a_dst, io1_a_dst, v_s);
|
|
||||||
if (v_n == ((uint64_t)(v_s.len))) {
|
|
||||||
status = NULL;
|
|
||||||
goto ok;
|
|
||||||
}
|
|
||||||
v_i = ((v_i + ((uint32_t)((v_n & 8191)))) & 8191);
|
|
||||||
status = wuffs_base__suspension__short_write;
|
|
||||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
goto ok;
|
|
||||||
ok:
|
|
||||||
self->private_impl.c_flush[0].coro_susp_point = 0;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
goto suspend;
|
|
||||||
suspend:
|
|
||||||
self->private_impl.c_flush[0].coro_susp_point = coro_susp_point;
|
|
||||||
self->private_impl.c_flush[0].v_i = v_i;
|
|
||||||
self->private_impl.c_flush[0].v_j = v_j;
|
|
||||||
self->private_impl.c_flush[0].v_n = v_n;
|
|
||||||
|
|
||||||
goto exit;
|
|
||||||
exit:
|
|
||||||
if (a_dst.private_impl.buf) {
|
|
||||||
a_dst.private_impl.buf->meta.wi =
|
|
||||||
iop_a_dst - a_dst.private_impl.buf->data.ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__LZW)
|
|
||||||
|
|
||||||
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ZLIB)
|
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ZLIB)
|
||||||
|
|
||||||
// ---------------- Status Codes Implementations
|
// ---------------- Status Codes Implementations
|
||||||
|
|||||||
Reference in new issue
Block a user