mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 00:52:18 +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")
|
return g.writeReadUXX(n, "src", 32, "le")
|
||||||
|
|
||||||
} else if isInSrc(g.tm, n, t.KeySkip32, 1) {
|
} else if isInSrc(g.tm, n, t.KeySkip32, 1) {
|
||||||
if g.perFunc.tempW > maxTemp {
|
// TODO: is the scratch variable safe to use if callers can trap
|
||||||
return fmt.Errorf("too many temporary variables required")
|
// LIMITED_READ and then go down different code paths?
|
||||||
}
|
g.writes("self->private_impl.scratch = ")
|
||||||
temp := g.perFunc.tempW
|
|
||||||
g.perFunc.tempW++
|
|
||||||
g.perFunc.tempR++
|
|
||||||
|
|
||||||
g.printf("size_t %s%d = ", tPrefix, temp)
|
|
||||||
x := n.Args()[0].Arg().Value()
|
x := n.Args()[0].Arg().Value()
|
||||||
if err := g.writeExpr(x, replaceCallSuspendibles, parenthesesMandatory, depth); err != nil {
|
if err := g.writeExpr(x, replaceCallSuspendibles, parenthesesMandatory, depth); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
g.writes(";\n")
|
g.writes(";\n")
|
||||||
|
|
||||||
g.printf("if (%s%d > %srend_src - %srptr_src) {\n", tPrefix, temp, bPrefix, bPrefix)
|
// TODO: the CSP prior to this is probably unnecessary.
|
||||||
// TODO: save tPrefix+temp as coroutine state, and suspend.
|
if err := g.writeCoroSuspPoint(); err != nil {
|
||||||
g.printf("%s%d -= %srend_src - %srptr_src;\n", tPrefix, temp, bPrefix, bPrefix)
|
return err
|
||||||
g.printf("%ssrc.buf->ri += %srend_src - %srptr_src;\n", aPrefix, bPrefix, bPrefix)
|
}
|
||||||
|
|
||||||
|
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?
|
// TODO: is ptr_to_len the right check?
|
||||||
g.printf("if (%ssrc.limit.ptr_to_len) {", aPrefix)
|
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.printf("} else { status = %sSUSPENSION_SHORT_READ; } goto suspend;\n", g.PKGPREFIX)
|
||||||
|
|
||||||
g.writes("}\n")
|
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) {
|
} else if isInDst(g.tm, n, t.KeyWrite, 1) {
|
||||||
// TODO: don't assume that the argument is "this.stack[s:]".
|
// 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;
|
goto label_0_break;
|
||||||
}
|
}
|
||||||
PUFFS_COROUTINE_SUSPENSION_POINT(3);
|
PUFFS_COROUTINE_SUSPENSION_POINT(3);
|
||||||
size_t t_2 = ((uint32_t)(v_block_size));
|
self->private_impl.scratch = ((uint32_t)(v_block_size));
|
||||||
if (t_2 > b_rend_src - b_rptr_src) {
|
PUFFS_COROUTINE_SUSPENSION_POINT(4);
|
||||||
t_2 -= b_rend_src - b_rptr_src;
|
if (self->private_impl.scratch > b_rend_src - b_rptr_src) {
|
||||||
a_src.buf->ri += 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) {
|
if (a_src.limit.ptr_to_len) {
|
||||||
status = PUFFS_GIF_SUSPENSION_LIMITED_READ;
|
status = PUFFS_GIF_SUSPENSION_LIMITED_READ;
|
||||||
} else if (a_src.buf->closed) {
|
} else if (a_src.buf->closed) {
|
||||||
@@ -878,7 +879,7 @@ puffs_gif_status puffs_gif_decoder_decode_extension(puffs_gif_decoder* self,
|
|||||||
}
|
}
|
||||||
goto suspend;
|
goto suspend;
|
||||||
}
|
}
|
||||||
b_rptr_src += t_2;
|
b_rptr_src += self->private_impl.scratch;
|
||||||
}
|
}
|
||||||
label_0_break:;
|
label_0_break:;
|
||||||
self->private_impl.c_decode_extension[0].coro_susp_point = 0;
|
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);
|
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() {
|
void test_puffs_gif_decode_input_is_a_gif_many_small_reads() {
|
||||||
proc_funcname = __func__;
|
proc_funcname = __func__;
|
||||||
test_puffs_gif_decode("../../testdata/bricks-dither.gif",
|
test_puffs_gif_decode("../../testdata/bricks-dither.gif",
|
||||||
"../../testdata/bricks-dither.palette",
|
"../../testdata/bricks-dither.palette",
|
||||||
"../../testdata/bricks-dither.indexes",
|
"../../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() {
|
void test_puffs_gif_decode_input_is_a_png() {
|
||||||
@@ -661,9 +671,10 @@ proc tests[] = {
|
|||||||
test_puffs_gif_lzw_decode_pi, //
|
test_puffs_gif_lzw_decode_pi, //
|
||||||
|
|
||||||
// GIF Tests
|
// GIF Tests
|
||||||
test_puffs_gif_decode_input_is_a_gif_few_big_reads, //
|
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_gif_many_medium_reads, //
|
||||||
test_puffs_gif_decode_input_is_a_png, //
|
test_puffs_gif_decode_input_is_a_gif_many_small_reads, //
|
||||||
|
test_puffs_gif_decode_input_is_a_png, //
|
||||||
|
|
||||||
#ifdef PUFFS_MIMIC
|
#ifdef PUFFS_MIMIC
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user