mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
Handle suspending inside a skip32 call.
This commit is contained in:
1 parent
fa18eec3e9
commit
fe7e6ed10e
3 files changed
+33
-22
No files matched your search
+12
-13
@@ -810,24 +810,23 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error {
|
||||
return g.writeReadUXX(n, "src", 32, "le")
|
||||
|
||||
} else if isInSrc(g.tm, n, t.KeySkip32, 1) {
|
||||
if g.perFunc.tempW > maxTemp {
|
||||
return fmt.Errorf("too many temporary variables required")
|
||||
}
|
||||
temp := g.perFunc.tempW
|
||||
g.perFunc.tempW++
|
||||
g.perFunc.tempR++
|
||||
|
||||
g.printf("size_t %s%d = ", tPrefix, temp)
|
||||
// TODO: is the scratch variable safe to use if callers can trap
|
||||
// LIMITED_READ and then go down different code paths?
|
||||
g.writes("self->private_impl.scratch = ")
|
||||
x := n.Args()[0].Arg().Value()
|
||||
if err := g.writeExpr(x, replaceCallSuspendibles, parenthesesMandatory, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
g.writes(";\n")
|
||||
|
||||
g.printf("if (%s%d > %srend_src - %srptr_src) {\n", tPrefix, temp, bPrefix, bPrefix)
|
||||
// TODO: save tPrefix+temp as coroutine state, and suspend.
|
||||
g.printf("%s%d -= %srend_src - %srptr_src;\n", tPrefix, temp, bPrefix, bPrefix)
|
||||
g.printf("%ssrc.buf->ri += %srend_src - %srptr_src;\n", aPrefix, bPrefix, bPrefix)
|
||||
// TODO: the CSP prior to this is probably unnecessary.
|
||||
if err := g.writeCoroSuspPoint(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
g.printf("if (self->private_impl.scratch > %srend_src - %srptr_src) {\n", bPrefix, bPrefix)
|
||||
g.printf("self->private_impl.scratch -= %srend_src - %srptr_src;\n", bPrefix, bPrefix)
|
||||
g.printf("%srptr_src = %srend_src;\n", bPrefix, bPrefix)
|
||||
|
||||
// TODO: is ptr_to_len the right check?
|
||||
g.printf("if (%ssrc.limit.ptr_to_len) {", aPrefix)
|
||||
@@ -837,7 +836,7 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error {
|
||||
g.printf("} else { status = %sSUSPENSION_SHORT_READ; } goto suspend;\n", g.PKGPREFIX)
|
||||
|
||||
g.writes("}\n")
|
||||
g.printf("%srptr_src += %s%d;\n", bPrefix, tPrefix, temp)
|
||||
g.printf("%srptr_src += self->private_impl.scratch;\n", bPrefix)
|
||||
|
||||
} else if isInDst(g.tm, n, t.KeyWrite, 1) {
|
||||
// TODO: don't assume that the argument is "this.stack[s:]".
|
||||
|
||||
+6
-5
@@ -864,10 +864,11 @@ puffs_gif_status puffs_gif_decoder_decode_extension(puffs_gif_decoder* self,
|
||||
goto label_0_break;
|
||||
}
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(3);
|
||||
size_t t_2 = ((uint32_t)(v_block_size));
|
||||
if (t_2 > b_rend_src - b_rptr_src) {
|
||||
t_2 -= b_rend_src - b_rptr_src;
|
||||
a_src.buf->ri += b_rend_src - b_rptr_src;
|
||||
self->private_impl.scratch = ((uint32_t)(v_block_size));
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(4);
|
||||
if (self->private_impl.scratch > b_rend_src - b_rptr_src) {
|
||||
self->private_impl.scratch -= b_rend_src - b_rptr_src;
|
||||
b_rptr_src = b_rend_src;
|
||||
if (a_src.limit.ptr_to_len) {
|
||||
status = PUFFS_GIF_SUSPENSION_LIMITED_READ;
|
||||
} else if (a_src.buf->closed) {
|
||||
@@ -878,7 +879,7 @@ puffs_gif_status puffs_gif_decoder_decode_extension(puffs_gif_decoder* self,
|
||||
}
|
||||
goto suspend;
|
||||
}
|
||||
b_rptr_src += t_2;
|
||||
b_rptr_src += self->private_impl.scratch;
|
||||
}
|
||||
label_0_break:;
|
||||
self->private_impl.c_decode_extension[0].coro_susp_point = 0;
|
||||
|
||||
+15
-4
@@ -476,12 +476,22 @@ void test_puffs_gif_decode_input_is_a_gif_few_big_reads() {
|
||||
PUFFS_GIF_STATUS_OK, 1 << 30);
|
||||
}
|
||||
|
||||
void test_puffs_gif_decode_input_is_a_gif_many_medium_reads() {
|
||||
proc_funcname = __func__;
|
||||
test_puffs_gif_decode("../../testdata/bricks-dither.gif",
|
||||
"../../testdata/bricks-dither.palette",
|
||||
"../../testdata/bricks-dither.indexes",
|
||||
PUFFS_GIF_STATUS_OK, 4096);
|
||||
}
|
||||
|
||||
void test_puffs_gif_decode_input_is_a_gif_many_small_reads() {
|
||||
proc_funcname = __func__;
|
||||
test_puffs_gif_decode("../../testdata/bricks-dither.gif",
|
||||
"../../testdata/bricks-dither.palette",
|
||||
"../../testdata/bricks-dither.indexes",
|
||||
PUFFS_GIF_STATUS_OK, 1000);
|
||||
PUFFS_GIF_STATUS_OK,
|
||||
787); // 787 tickles being in the middle of a
|
||||
// decode_extension skip32 call.
|
||||
}
|
||||
|
||||
void test_puffs_gif_decode_input_is_a_png() {
|
||||
@@ -661,9 +671,10 @@ proc tests[] = {
|
||||
test_puffs_gif_lzw_decode_pi, //
|
||||
|
||||
// GIF Tests
|
||||
test_puffs_gif_decode_input_is_a_gif_few_big_reads, //
|
||||
test_puffs_gif_decode_input_is_a_gif_many_small_reads, //
|
||||
test_puffs_gif_decode_input_is_a_png, //
|
||||
test_puffs_gif_decode_input_is_a_gif_few_big_reads, //
|
||||
test_puffs_gif_decode_input_is_a_gif_many_medium_reads, //
|
||||
test_puffs_gif_decode_input_is_a_gif_many_small_reads, //
|
||||
test_puffs_gif_decode_input_is_a_png, //
|
||||
|
||||
#ifdef PUFFS_MIMIC
|
||||
|
||||
|
||||
Reference in new issue
Block a user