mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 16:47:28 +01:00
Add a dst argument to std/gif's decoder.decode_id.
This commit is contained in:
1 parent
f857d777ee
commit
1d39b1e173
5 files changed
+27
-25
No files matched your search
+12
-12
@@ -1021,7 +1021,7 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error {
|
||||
g.writes("}\n")
|
||||
g.printf("%ssrc.buf->ri += %s%d;\n", aPrefix, tPrefix, temp)
|
||||
|
||||
} else if isInDst(g.tm, n, t.KeyWrite) {
|
||||
} else if isInDst(g.tm, n, t.KeyWrite, 1) {
|
||||
// TODO: suspend coroutine state.
|
||||
//
|
||||
// TODO: don't assume that the argument is "this.stack[s:]".
|
||||
@@ -1047,7 +1047,7 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error {
|
||||
"sizeof(self->private_impl.f_stack) - v_s);\n")
|
||||
g.printf("a_dst.buf->wi += sizeof(self->private_impl.f_stack) - v_s;\n")
|
||||
|
||||
} else if isInDst(g.tm, n, t.KeyWriteU8) {
|
||||
} else if isInDst(g.tm, n, t.KeyWriteU8, 1) {
|
||||
// TODO: suspend coroutine state.
|
||||
g.printf("if (%sdst.buf->wi >= %sdst.buf->len) { status = puffs_%s_status_short_write;",
|
||||
aPrefix, aPrefix, g.pkgName)
|
||||
@@ -1064,24 +1064,24 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error {
|
||||
}
|
||||
g.writes(";\n")
|
||||
|
||||
} else if isThisMethod(g.tm, n, "decode_header") {
|
||||
} else if isThisMethod(g.tm, n, "decode_header", 1) {
|
||||
g.printf("status = puffs_%s_%s_decode_header(self, %ssrc);\n",
|
||||
g.pkgName, g.perFunc.funk.Receiver().String(g.tm), aPrefix)
|
||||
g.writes("if (status) { goto cleanup0; }\n")
|
||||
|
||||
} else if isThisMethod(g.tm, n, "decode_lsd") {
|
||||
} else if isThisMethod(g.tm, n, "decode_lsd", 1) {
|
||||
g.printf("status = puffs_%s_%s_decode_lsd(self, %ssrc);\n",
|
||||
g.pkgName, g.perFunc.funk.Receiver().String(g.tm), aPrefix)
|
||||
g.writes("if (status) { goto cleanup0; }\n")
|
||||
|
||||
} else if isThisMethod(g.tm, n, "decode_extension") {
|
||||
} else if isThisMethod(g.tm, n, "decode_extension", 1) {
|
||||
g.printf("status = puffs_%s_%s_decode_extension(self, %ssrc);\n",
|
||||
g.pkgName, g.perFunc.funk.Receiver().String(g.tm), aPrefix)
|
||||
g.writes("if (status) { goto cleanup0; }\n")
|
||||
|
||||
} else if isThisMethod(g.tm, n, "decode_id") {
|
||||
g.printf("status = puffs_%s_%s_decode_id(self, %ssrc);\n",
|
||||
g.pkgName, g.perFunc.funk.Receiver().String(g.tm), aPrefix)
|
||||
} else if isThisMethod(g.tm, n, "decode_id", 2) {
|
||||
g.printf("status = puffs_%s_%s_decode_id(self, %sdst, %ssrc);\n",
|
||||
g.pkgName, g.perFunc.funk.Receiver().String(g.tm), aPrefix, aPrefix)
|
||||
g.writes("if (status) { goto cleanup0; }\n")
|
||||
|
||||
} else {
|
||||
@@ -1232,9 +1232,9 @@ func isInSrc(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool {
|
||||
return n.ID0() == 0 && n.ID1().Key() == t.KeyIn
|
||||
}
|
||||
|
||||
func isInDst(tm *t.Map, n *a.Expr, methodName t.Key) bool {
|
||||
func isInDst(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool {
|
||||
// TODO: check that n.Args() is "(x:bar)".
|
||||
if n.ID0().Key() != t.KeyOpenParen || !n.CallSuspendible() || len(n.Args()) != 1 {
|
||||
if n.ID0().Key() != t.KeyOpenParen || !n.CallSuspendible() || len(n.Args()) != nArgs {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
@@ -1249,9 +1249,9 @@ func isInDst(tm *t.Map, n *a.Expr, methodName t.Key) bool {
|
||||
return n.ID0() == 0 && n.ID1().Key() == t.KeyIn
|
||||
}
|
||||
|
||||
func isThisMethod(tm *t.Map, n *a.Expr, methodName string) bool {
|
||||
func isThisMethod(tm *t.Map, n *a.Expr, methodName string, nArgs int) bool {
|
||||
// TODO: check that n.Args() is "(src:in.src)".
|
||||
if n.ID0().Key() != t.KeyOpenParen || !n.CallSuspendible() || len(n.Args()) != 1 {
|
||||
if n.ID0().Key() != t.KeyOpenParen || !n.CallSuspendible() || len(n.Args()) != nArgs {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
|
||||
+3
-1
@@ -237,6 +237,7 @@ puffs_gif_status puffs_gif_decoder_decode_extension(puffs_gif_decoder* self,
|
||||
puffs_base_reader1 a_src);
|
||||
|
||||
puffs_gif_status puffs_gif_decoder_decode_id(puffs_gif_decoder* self,
|
||||
puffs_base_writer1 a_dst,
|
||||
puffs_base_reader1 a_src);
|
||||
|
||||
// ---------------- Constructor and Destructor Implementations
|
||||
@@ -344,7 +345,7 @@ puffs_gif_status puffs_gif_decoder_decode(puffs_gif_decoder* self,
|
||||
goto cleanup0;
|
||||
}
|
||||
} else if (v_c == 44) {
|
||||
status = puffs_gif_decoder_decode_id(self, a_src);
|
||||
status = puffs_gif_decoder_decode_id(self, a_dst, a_src);
|
||||
if (status) {
|
||||
goto cleanup0;
|
||||
}
|
||||
@@ -498,6 +499,7 @@ label_0_break:;
|
||||
}
|
||||
|
||||
puffs_gif_status puffs_gif_decoder_decode_id(puffs_gif_decoder* self,
|
||||
puffs_base_writer1 a_dst,
|
||||
puffs_base_reader1 a_src) {
|
||||
puffs_gif_status status = self->private_impl.status;
|
||||
|
||||
|
||||
@@ -616,9 +616,9 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
|
||||
case t.KeyOpenParen:
|
||||
// TODO: delete this hack that only matches "in.src.read_u8?()" etc.
|
||||
if isInSrc(q.tm, n, t.KeyReadU8, 0) || isInSrc(q.tm, n, t.KeySkip32, 1) ||
|
||||
isInDst(q.tm, n, t.KeyWrite) || isInDst(q.tm, n, t.KeyWriteU8) ||
|
||||
isThisMethod(q.tm, n, "decode_header") || isThisMethod(q.tm, n, "decode_lsd") ||
|
||||
isThisMethod(q.tm, n, "decode_extension") || isThisMethod(q.tm, n, "decode_id") {
|
||||
isInDst(q.tm, n, t.KeyWrite, 1) || isInDst(q.tm, n, t.KeyWriteU8, 1) ||
|
||||
isThisMethod(q.tm, n, "decode_header", 1) || isThisMethod(q.tm, n, "decode_lsd", 1) ||
|
||||
isThisMethod(q.tm, n, "decode_extension", 1) || isThisMethod(q.tm, n, "decode_id", 2) {
|
||||
|
||||
for _, o := range n.Args() {
|
||||
// TODO: check that the arg range at the caller and the
|
||||
|
||||
+7
-7
@@ -337,9 +337,9 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
||||
// n is a function call.
|
||||
// TODO: delete this hack that only matches "in.src.read_u8?()" etc.
|
||||
if isInSrc(q.tm, n, t.KeyReadU8, 0) || isInSrc(q.tm, n, t.KeySkip32, 1) ||
|
||||
isInDst(q.tm, n, t.KeyWrite) || isInDst(q.tm, n, t.KeyWriteU8) ||
|
||||
isThisMethod(q.tm, n, "decode_header") || isThisMethod(q.tm, n, "decode_lsd") ||
|
||||
isThisMethod(q.tm, n, "decode_extension") || isThisMethod(q.tm, n, "decode_id") {
|
||||
isInDst(q.tm, n, t.KeyWrite, 1) || isInDst(q.tm, n, t.KeyWriteU8, 1) ||
|
||||
isThisMethod(q.tm, n, "decode_header", 1) || isThisMethod(q.tm, n, "decode_lsd", 1) ||
|
||||
isThisMethod(q.tm, n, "decode_extension", 1) || isThisMethod(q.tm, n, "decode_id", 2) {
|
||||
|
||||
if err := q.tcheckExpr(n.LHS().Expr(), depth); err != nil {
|
||||
return err
|
||||
@@ -434,9 +434,9 @@ func isInSrc(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool {
|
||||
return n.ID0() == 0 && n.ID1().Key() == t.KeyIn
|
||||
}
|
||||
|
||||
func isInDst(tm *t.Map, n *a.Expr, methodName t.Key) bool {
|
||||
func isInDst(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool {
|
||||
// TODO: check that n.Args() is "(x:bar)".
|
||||
if n.ID0().Key() != t.KeyOpenParen || !n.CallSuspendible() || len(n.Args()) != 1 {
|
||||
if n.ID0().Key() != t.KeyOpenParen || !n.CallSuspendible() || len(n.Args()) != nArgs {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
@@ -451,9 +451,9 @@ func isInDst(tm *t.Map, n *a.Expr, methodName t.Key) bool {
|
||||
return n.ID0() == 0 && n.ID1().Key() == t.KeyIn
|
||||
}
|
||||
|
||||
func isThisMethod(tm *t.Map, n *a.Expr, methodName string) bool {
|
||||
func isThisMethod(tm *t.Map, n *a.Expr, methodName string, nArgs int) bool {
|
||||
// TODO: check that n.Args() is "(src:in.src)".
|
||||
if n.ID0().Key() != t.KeyOpenParen || !n.CallSuspendible() || len(n.Args()) != 1 {
|
||||
if n.ID0().Key() != t.KeyOpenParen || !n.CallSuspendible() || len(n.Args()) != nArgs {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
|
||||
@@ -32,7 +32,7 @@ pub func decoder.decode?(dst writer1, src reader1)() {
|
||||
// TODO: animated GIFs can have multiple Image Descriptors.
|
||||
//
|
||||
// TODO: reset this.lzw if it's not the first ID.
|
||||
this.decode_id?(src:in.src)
|
||||
this.decode_id?(dst:in.dst, src:in.src)
|
||||
} else if c == 0x3B { // The spec calls 0x3B the "Trailer".
|
||||
return
|
||||
} else {
|
||||
@@ -117,7 +117,7 @@ pri func decoder.decode_extension?(src reader1)() {
|
||||
// been read.
|
||||
//
|
||||
// See the spec section 20 "Image Descriptor" on page 11.
|
||||
pri func decoder.decode_id?(src reader1)() {
|
||||
pri func decoder.decode_id?(dst writer1, src reader1)() {
|
||||
var c[9] u8
|
||||
var i u32
|
||||
while i < 9 {
|
||||
|
||||
Reference in new issue
Block a user