mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Don't skip derived I/O vars for !? methods
This commit is contained in:
1 parent
cf51406fcf
commit
ec0fd9649d
3 files changed
+84
-53
No files matched your search
@@ -252,7 +252,7 @@ func (g *gen) writeFuncImplPrologue(b *buffer) error {
|
||||
}
|
||||
}
|
||||
|
||||
if g.currFunk.astFunc.Effect().Coroutine() {
|
||||
if g.currFunk.astFunc.Effect().Optional() {
|
||||
b.printf("wuffs_base__status status = NULL;\n")
|
||||
}
|
||||
b.writes("\n")
|
||||
@@ -263,7 +263,7 @@ func (g *gen) writeFuncImplPrologue(b *buffer) error {
|
||||
}
|
||||
b.writes("\n")
|
||||
|
||||
if g.currFunk.astFunc.Effect().Coroutine() {
|
||||
if g.currFunk.astFunc.Effect().Optional() {
|
||||
g.findDerivedVars()
|
||||
for _, o := range g.currFunk.astFunc.In().Fields() {
|
||||
o := o.AsField()
|
||||
@@ -331,7 +331,7 @@ func (g *gen) writeFuncImplBodySuspend(b *buffer) error {
|
||||
}
|
||||
|
||||
func (g *gen) writeFuncImplEpilogue(b *buffer) error {
|
||||
if effect := g.currFunk.astFunc.Effect(); effect.Coroutine() {
|
||||
if g.currFunk.astFunc.Effect().Optional() {
|
||||
b.writes("goto exit;exit:") // The goto avoids the "unused label" warning.
|
||||
|
||||
for _, o := range g.currFunk.astFunc.In().Fields() {
|
||||
@@ -347,8 +347,6 @@ func (g *gen) writeFuncImplEpilogue(b *buffer) error {
|
||||
"self->private_impl.magic = WUFFS_BASE__DISABLED; }\n")
|
||||
}
|
||||
b.writes("return status;\n")
|
||||
} else if effect.Optional() {
|
||||
b.writes("return NULL;\n")
|
||||
} else if g.currFunk.astFunc.Out() == nil {
|
||||
b.writes("return ((wuffs_base__empty_struct){});\n")
|
||||
}
|
||||
|
||||
@@ -163,11 +163,7 @@ func (g *gen) writeStatementExpr(b *buffer, n *a.Expr, depth uint32) error {
|
||||
if n.Effect().Coroutine() {
|
||||
return nil
|
||||
} else if n.Effect().Optional() {
|
||||
if g.currFunk.astFunc.Effect().Coroutine() {
|
||||
b.writes("status = ")
|
||||
} else {
|
||||
b.writes("{ wuffs_base__status status = ")
|
||||
}
|
||||
b.writes("status = ")
|
||||
checkStatus = true
|
||||
}
|
||||
}
|
||||
@@ -176,11 +172,7 @@ func (g *gen) writeStatementExpr(b *buffer, n *a.Expr, depth uint32) error {
|
||||
}
|
||||
b.writes(";\n")
|
||||
if checkStatus {
|
||||
if g.currFunk.astFunc.Effect().Coroutine() {
|
||||
b.writes("if (status) { goto exit; }\n")
|
||||
} else {
|
||||
b.writes("if (status) { return status; }}\n")
|
||||
}
|
||||
b.writes("if (status) { goto exit; }\n")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -341,7 +333,7 @@ func (g *gen) writeStatementJump(b *buffer, n *a.Jump, depth uint32) error {
|
||||
func (g *gen) writeStatementRet(b *buffer, n *a.Ret, depth uint32) error {
|
||||
retExpr := n.Value()
|
||||
|
||||
if g.currFunk.astFunc.Effect().Coroutine() {
|
||||
if g.currFunk.astFunc.Effect().Optional() {
|
||||
isError, isOK := false, false
|
||||
b.writes("status = ")
|
||||
if retExpr.Operator() == 0 && retExpr.Ident() == t.IDOk {
|
||||
@@ -381,7 +373,7 @@ func (g *gen) writeStatementRet(b *buffer, n *a.Ret, depth uint32) error {
|
||||
}
|
||||
|
||||
b.writes("return ")
|
||||
if g.currFunk.astFunc.Out() == nil && !g.currFunk.astFunc.Effect().Optional() {
|
||||
if g.currFunk.astFunc.Out() == nil {
|
||||
return fmt.Errorf("TODO: allow empty return type (when not suspendible)")
|
||||
} else if err := g.writeExpr(b, retExpr, replaceCallSuspendibles, depth); err != nil {
|
||||
return err
|
||||
|
||||
@@ -5419,6 +5419,8 @@ exit:
|
||||
|
||||
static wuffs_base__status //
|
||||
wuffs_deflate__decoder__init_fixed_huffman(wuffs_deflate__decoder* self) {
|
||||
wuffs_base__status status = NULL;
|
||||
|
||||
uint32_t v_i;
|
||||
|
||||
v_i = 0;
|
||||
@@ -5442,21 +5444,17 @@ wuffs_deflate__decoder__init_fixed_huffman(wuffs_deflate__decoder* self) {
|
||||
self->private_impl.f_code_lengths[v_i] = 5;
|
||||
v_i += 1;
|
||||
}
|
||||
{
|
||||
wuffs_base__status status =
|
||||
wuffs_deflate__decoder__init_huff(self, 0, 0, 288, 257);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
status = wuffs_deflate__decoder__init_huff(self, 0, 0, 288, 257);
|
||||
if (status) {
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
wuffs_base__status status =
|
||||
wuffs_deflate__decoder__init_huff(self, 1, 288, 320, 0);
|
||||
if (status) {
|
||||
return status;
|
||||
}
|
||||
status = wuffs_deflate__decoder__init_huff(self, 1, 288, 320, 0);
|
||||
if (status) {
|
||||
goto exit;
|
||||
}
|
||||
return NULL;
|
||||
goto exit;
|
||||
exit:
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func deflate.decoder.init_dynamic_huffman
|
||||
@@ -5719,6 +5717,8 @@ wuffs_deflate__decoder__init_huff(wuffs_deflate__decoder* self,
|
||||
uint32_t a_n_codes0,
|
||||
uint32_t a_n_codes1,
|
||||
uint32_t a_base_symbol) {
|
||||
wuffs_base__status status = NULL;
|
||||
|
||||
uint16_t v_counts[16];
|
||||
uint32_t v_i;
|
||||
uint32_t v_remaining;
|
||||
@@ -5749,29 +5749,36 @@ wuffs_deflate__decoder__init_huff(wuffs_deflate__decoder* self,
|
||||
v_i = a_n_codes0;
|
||||
while (v_i < a_n_codes1) {
|
||||
if (v_counts[self->private_impl.f_code_lengths[v_i]] >= 320) {
|
||||
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
status =
|
||||
wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
goto exit;
|
||||
}
|
||||
v_counts[self->private_impl.f_code_lengths[v_i]] += 1;
|
||||
v_i += 1;
|
||||
}
|
||||
if ((((uint32_t)(v_counts[0])) + a_n_codes0) == a_n_codes1) {
|
||||
return wuffs_deflate__error__no_huffman_codes;
|
||||
status = wuffs_deflate__error__no_huffman_codes;
|
||||
goto exit;
|
||||
}
|
||||
v_remaining = 1;
|
||||
v_i = 1;
|
||||
while (v_i <= 15) {
|
||||
if (v_remaining > 1073741824) {
|
||||
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
status =
|
||||
wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
goto exit;
|
||||
}
|
||||
v_remaining <<= 1;
|
||||
if (v_remaining < ((uint32_t)(v_counts[v_i]))) {
|
||||
return wuffs_deflate__error__bad_huffman_code_over_subscribed;
|
||||
status = wuffs_deflate__error__bad_huffman_code_over_subscribed;
|
||||
goto exit;
|
||||
}
|
||||
v_remaining -= ((uint32_t)(v_counts[v_i]));
|
||||
v_i += 1;
|
||||
}
|
||||
if (v_remaining != 0) {
|
||||
return wuffs_deflate__error__bad_huffman_code_under_subscribed;
|
||||
status = wuffs_deflate__error__bad_huffman_code_under_subscribed;
|
||||
goto exit;
|
||||
}
|
||||
memset(v_offsets, 0, sizeof(v_offsets));
|
||||
v_n_symbols = 0;
|
||||
@@ -5780,23 +5787,31 @@ wuffs_deflate__decoder__init_huff(wuffs_deflate__decoder* self,
|
||||
v_offsets[v_i] = ((uint16_t)(v_n_symbols));
|
||||
v_count = ((uint32_t)(v_counts[v_i]));
|
||||
if (v_n_symbols > (320 - v_count)) {
|
||||
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
status =
|
||||
wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
goto exit;
|
||||
}
|
||||
v_n_symbols = (v_n_symbols + v_count);
|
||||
v_i += 1;
|
||||
}
|
||||
if (v_n_symbols > 288) {
|
||||
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
status =
|
||||
wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
goto exit;
|
||||
}
|
||||
memset(v_symbols, 0, sizeof(v_symbols));
|
||||
v_i = a_n_codes0;
|
||||
while (v_i < a_n_codes1) {
|
||||
if (v_i < a_n_codes0) {
|
||||
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
status =
|
||||
wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
goto exit;
|
||||
}
|
||||
if (self->private_impl.f_code_lengths[v_i] != 0) {
|
||||
if (v_offsets[self->private_impl.f_code_lengths[v_i]] >= 320) {
|
||||
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
status =
|
||||
wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
goto exit;
|
||||
}
|
||||
v_symbols[v_offsets[self->private_impl.f_code_lengths[v_i]]] =
|
||||
((uint16_t)((v_i - a_n_codes0)));
|
||||
@@ -5810,7 +5825,8 @@ wuffs_deflate__decoder__init_huff(wuffs_deflate__decoder* self,
|
||||
goto label_0_break;
|
||||
}
|
||||
if (v_min_cl >= 9) {
|
||||
return wuffs_deflate__error__bad_huffman_minimum_code_length;
|
||||
status = wuffs_deflate__error__bad_huffman_minimum_code_length;
|
||||
goto exit;
|
||||
}
|
||||
v_min_cl += 1;
|
||||
}
|
||||
@@ -5821,7 +5837,8 @@ label_0_break:;
|
||||
goto label_1_break;
|
||||
}
|
||||
if (v_max_cl <= 1) {
|
||||
return wuffs_deflate__error__no_huffman_codes;
|
||||
status = wuffs_deflate__error__no_huffman_codes;
|
||||
goto exit;
|
||||
}
|
||||
v_max_cl -= 1;
|
||||
}
|
||||
@@ -5834,10 +5851,14 @@ label_1_break:;
|
||||
v_i = 0;
|
||||
if ((v_n_symbols != ((uint32_t)(v_offsets[v_max_cl]))) ||
|
||||
(v_n_symbols != ((uint32_t)(v_offsets[15])))) {
|
||||
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
status =
|
||||
wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
goto exit;
|
||||
}
|
||||
if ((a_n_codes0 + ((uint32_t)(v_symbols[0]))) >= 320) {
|
||||
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
status =
|
||||
wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
goto exit;
|
||||
}
|
||||
v_initial_high_bits = 512;
|
||||
if (v_max_cl < 9) {
|
||||
@@ -5853,14 +5874,18 @@ label_1_break:;
|
||||
v_value = 0;
|
||||
while (true) {
|
||||
if ((a_n_codes0 + ((uint32_t)(v_symbols[v_i]))) >= 320) {
|
||||
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
status =
|
||||
wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
goto exit;
|
||||
}
|
||||
v_cl = ((uint32_t)(self->private_impl.f_code_lengths[(
|
||||
a_n_codes0 + ((uint32_t)(v_symbols[v_i])))]));
|
||||
if (v_cl > v_prev_cl) {
|
||||
v_code <<= (v_cl - v_prev_cl);
|
||||
if (v_code >= 32768) {
|
||||
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
status =
|
||||
wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
v_prev_cl = v_cl;
|
||||
@@ -5880,20 +5905,26 @@ label_1_break:;
|
||||
}
|
||||
v_remaining -= ((uint32_t)(v_counts[v_j]));
|
||||
if (v_remaining > 1073741824) {
|
||||
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
status =
|
||||
wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
goto exit;
|
||||
}
|
||||
v_remaining <<= 1;
|
||||
v_j += 1;
|
||||
}
|
||||
label_2_break:;
|
||||
if ((v_j <= 9) || (15 < v_j)) {
|
||||
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
status =
|
||||
wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
goto exit;
|
||||
}
|
||||
v_tmp = (v_j - 9);
|
||||
v_initial_high_bits = (((uint32_t)(1)) << v_tmp);
|
||||
v_top = v_next_top;
|
||||
if ((v_top + (((uint32_t)(1)) << v_tmp)) > 1234) {
|
||||
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
status =
|
||||
wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
goto exit;
|
||||
}
|
||||
v_next_top = (v_top + (((uint32_t)(1)) << v_tmp));
|
||||
v_redirect_key =
|
||||
@@ -5904,7 +5935,9 @@ label_1_break:;
|
||||
}
|
||||
}
|
||||
if ((v_key >= 512) || (v_counts[v_prev_cl] <= 0)) {
|
||||
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
status =
|
||||
wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
goto exit;
|
||||
}
|
||||
v_counts[v_prev_cl] -= 1;
|
||||
v_reversed_key = (((uint32_t)(wuffs_deflate__reverse8[(v_key >> 1)])) |
|
||||
@@ -5923,14 +5956,18 @@ label_1_break:;
|
||||
v_value = (wuffs_deflate__dcode_magic_numbers[(v_symbol & 31)] | v_cl);
|
||||
}
|
||||
} else {
|
||||
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
status =
|
||||
wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
goto exit;
|
||||
}
|
||||
v_high_bits = v_initial_high_bits;
|
||||
v_delta = (((uint32_t)(1)) << v_cl);
|
||||
while (v_high_bits >= v_delta) {
|
||||
v_high_bits -= v_delta;
|
||||
if ((v_top + ((v_high_bits | v_reversed_key) & 511)) >= 1234) {
|
||||
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
status =
|
||||
wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl
|
||||
.f_huffs[a_which][(v_top + ((v_high_bits | v_reversed_key) & 511))] =
|
||||
@@ -5942,11 +5979,15 @@ label_1_break:;
|
||||
}
|
||||
v_code += 1;
|
||||
if (v_code >= 32768) {
|
||||
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
status =
|
||||
wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
label_3_break:;
|
||||
return NULL;
|
||||
goto exit;
|
||||
exit:
|
||||
return status;
|
||||
}
|
||||
|
||||
// -------- func deflate.decoder.decode_huffman_fast
|
||||
|
||||
Reference in new issue
Block a user