mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 08:32:11 +01:00
Reset coro_state to zero at function end.
This allows us to call that coroutine function multiple times.
This commit is contained in:
1 parent
004a583aaf
commit
d974988eab
3 files changed
+12
-10
No files matched your search
@@ -141,6 +141,8 @@ func (g *gen) writeFuncImpl(n *a.Func) error {
|
||||
g.writes("}\n")
|
||||
// Generate a coroutine switch similiar to the technique in
|
||||
// https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
|
||||
//
|
||||
// The matching } is written below. See "Close the coroutine switch".
|
||||
g.writes("switch (coro_state) {\nPUFFS_COROUTINE_STATE(0);\n\n")
|
||||
}
|
||||
|
||||
@@ -152,9 +154,9 @@ func (g *gen) writeFuncImpl(n *a.Func) error {
|
||||
}
|
||||
|
||||
if g.perFunc.suspendible {
|
||||
if err := g.writeSuspend(); err != nil {
|
||||
return err
|
||||
}
|
||||
// We've reached the end of the function body. Reset the coroutine
|
||||
// state so that the next call to this function starts at the top.
|
||||
g.writes("coro_state = 0;\n")
|
||||
g.writes("}\n\n") // Close the coroutine switch.
|
||||
|
||||
g.writes("goto suspend;\n") // Avoid the "unused label" warning.
|
||||
|
||||
+6
-6
@@ -536,7 +536,7 @@ puffs_gif_status puffs_gif_decoder_decode(puffs_gif_decoder* self,
|
||||
goto suspend;
|
||||
}
|
||||
}
|
||||
PUFFS_COROUTINE_STATE(6);
|
||||
coro_state = 0;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
@@ -613,7 +613,7 @@ puffs_gif_status puffs_gif_decoder_decode_header(puffs_gif_decoder* self,
|
||||
((v_c[4] != 55) && (v_c[4] != 57)) || (v_c[5] != 97)) {
|
||||
return puffs_gif_error_bad_gif_header;
|
||||
}
|
||||
PUFFS_COROUTINE_STATE(2);
|
||||
coro_state = 0;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
@@ -727,7 +727,7 @@ puffs_gif_status puffs_gif_decoder_decode_lsd(puffs_gif_decoder* self,
|
||||
v_i += 1;
|
||||
}
|
||||
}
|
||||
PUFFS_COROUTINE_STATE(5);
|
||||
coro_state = 0;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
@@ -823,7 +823,7 @@ puffs_gif_status puffs_gif_decoder_decode_extension(puffs_gif_decoder* self,
|
||||
b_rptr_src += t_2;
|
||||
}
|
||||
label_0_break:;
|
||||
PUFFS_COROUTINE_STATE(4);
|
||||
coro_state = 0;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
@@ -975,7 +975,7 @@ puffs_gif_status puffs_gif_decoder_decode_id(puffs_gif_decoder* self,
|
||||
}
|
||||
}
|
||||
label_0_break:;
|
||||
PUFFS_COROUTINE_STATE(5);
|
||||
coro_state = 0;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
@@ -1188,7 +1188,7 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
||||
}
|
||||
v_prev_code = v_code;
|
||||
}
|
||||
PUFFS_COROUTINE_STATE(4);
|
||||
coro_state = 0;
|
||||
}
|
||||
|
||||
goto suspend;
|
||||
|
||||
+1
-1
@@ -618,7 +618,7 @@ proc tests[] = {
|
||||
|
||||
// Mimic Tests
|
||||
test_gif_mimic_decode_bricks_dither, //
|
||||
// test_gif_mimic_decode_bricks_gray, // TODO
|
||||
test_gif_mimic_decode_bricks_gray, //
|
||||
test_gif_mimic_decode_bricks_nodither, //
|
||||
test_gif_mimic_decode_harvesters, //
|
||||
test_gif_mimic_decode_hat, //
|
||||
|
||||
Reference in new issue
Block a user