mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 08:52:18 +01:00
Refactor short read status code calculations.
This commit is contained in:
1 parent
e1fa0e8a34
commit
21bb96d756
3 files changed
+39
-46
No files matched your search
@@ -830,9 +830,10 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error {
|
|||||||
g.printf("%s%d -= %srend_src - %srptr_src;\n", tPrefix, temp, bPrefix, bPrefix)
|
g.printf("%s%d -= %srend_src - %srptr_src;\n", tPrefix, temp, bPrefix, bPrefix)
|
||||||
g.printf("%ssrc.buf->ri = %ssrc.buf->wi;\n", aPrefix, aPrefix)
|
g.printf("%ssrc.buf->ri = %ssrc.buf->wi;\n", aPrefix, aPrefix)
|
||||||
|
|
||||||
g.printf("status = %ssrc.buf->closed ? PUFFS_%s_ERROR_UNEXPECTED_EOF : PUFFS_%s_SUSPENSION_SHORT_READ;",
|
// TODO: check limits too.
|
||||||
aPrefix, g.PKGNAME, g.PKGNAME)
|
g.printf("if (%ssrc.buf->closed) {", aPrefix)
|
||||||
g.writes("if (status < 0) { goto exit; } goto suspend;")
|
g.printf("status = PUFFS_%s_ERROR_UNEXPECTED_EOF; goto exit; }", g.PKGNAME)
|
||||||
|
g.printf("status = PUFFS_%s_SUSPENSION_SHORT_READ; goto suspend;\n", g.PKGNAME)
|
||||||
|
|
||||||
g.writes("}\n")
|
g.writes("}\n")
|
||||||
g.printf("%srptr_src += %s%d;\n", bPrefix, tPrefix, temp)
|
g.printf("%srptr_src += %s%d;\n", bPrefix, tPrefix, temp)
|
||||||
@@ -975,10 +976,11 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error {
|
|||||||
func (g *gen) writeShortRead(name string) error {
|
func (g *gen) writeShortRead(name string) error {
|
||||||
g.printf("\nshort_read_%s:\n", name)
|
g.printf("\nshort_read_%s:\n", name)
|
||||||
// TODO: ri == wi isn't the right condition.
|
// TODO: ri == wi isn't the right condition.
|
||||||
g.printf("status = ((%s%s.buf->closed) && (%s%s.buf->ri == %s%s.buf->wi)) ?"+
|
g.printf("if ((%s%s.buf->closed) && (%s%s.buf->ri == %s%s.buf->wi)) {",
|
||||||
"PUFFS_%s_ERROR_UNEXPECTED_EOF : PUFFS_%s_SUSPENSION_SHORT_READ;",
|
aPrefix, name, aPrefix, name, aPrefix, name)
|
||||||
aPrefix, name, aPrefix, name, aPrefix, name, g.PKGNAME, g.PKGNAME)
|
g.printf("status = PUFFS_%s_ERROR_UNEXPECTED_EOF; goto exit;", g.PKGNAME)
|
||||||
g.writes("if (status < 0) { goto exit; } goto suspend;")
|
g.writes("}")
|
||||||
|
g.printf("status = PUFFS_%s_SUSPENSION_SHORT_READ; goto suspend;\n", g.PKGNAME)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+9
-12
@@ -468,12 +468,11 @@ exit:
|
|||||||
return status;
|
return status;
|
||||||
|
|
||||||
short_read_src:
|
short_read_src:
|
||||||
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
|
if ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi)) {
|
||||||
? PUFFS_FLATE_ERROR_UNEXPECTED_EOF
|
status = PUFFS_FLATE_ERROR_UNEXPECTED_EOF;
|
||||||
: PUFFS_FLATE_SUSPENSION_SHORT_READ;
|
|
||||||
if (status < 0) {
|
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
status = PUFFS_FLATE_SUSPENSION_SHORT_READ;
|
||||||
goto suspend;
|
goto suspend;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -619,12 +618,11 @@ exit:
|
|||||||
return status;
|
return status;
|
||||||
|
|
||||||
short_read_src:
|
short_read_src:
|
||||||
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
|
if ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi)) {
|
||||||
? PUFFS_FLATE_ERROR_UNEXPECTED_EOF
|
status = PUFFS_FLATE_ERROR_UNEXPECTED_EOF;
|
||||||
: PUFFS_FLATE_SUSPENSION_SHORT_READ;
|
|
||||||
if (status < 0) {
|
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
status = PUFFS_FLATE_SUSPENSION_SHORT_READ;
|
||||||
goto suspend;
|
goto suspend;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -760,11 +758,10 @@ exit:
|
|||||||
return status;
|
return status;
|
||||||
|
|
||||||
short_read_src:
|
short_read_src:
|
||||||
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
|
if ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi)) {
|
||||||
? PUFFS_FLATE_ERROR_UNEXPECTED_EOF
|
status = PUFFS_FLATE_ERROR_UNEXPECTED_EOF;
|
||||||
: PUFFS_FLATE_SUSPENSION_SHORT_READ;
|
|
||||||
if (status < 0) {
|
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
status = PUFFS_FLATE_SUSPENSION_SHORT_READ;
|
||||||
goto suspend;
|
goto suspend;
|
||||||
}
|
}
|
||||||
+21
-27
@@ -593,12 +593,11 @@ exit:
|
|||||||
return status;
|
return status;
|
||||||
|
|
||||||
short_read_src:
|
short_read_src:
|
||||||
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
|
if ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi)) {
|
||||||
? PUFFS_GIF_ERROR_UNEXPECTED_EOF
|
status = PUFFS_GIF_ERROR_UNEXPECTED_EOF;
|
||||||
: PUFFS_GIF_SUSPENSION_SHORT_READ;
|
|
||||||
if (status < 0) {
|
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
status = PUFFS_GIF_SUSPENSION_SHORT_READ;
|
||||||
goto suspend;
|
goto suspend;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -678,12 +677,11 @@ exit:
|
|||||||
return status;
|
return status;
|
||||||
|
|
||||||
short_read_src:
|
short_read_src:
|
||||||
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
|
if ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi)) {
|
||||||
? PUFFS_GIF_ERROR_UNEXPECTED_EOF
|
status = PUFFS_GIF_ERROR_UNEXPECTED_EOF;
|
||||||
: PUFFS_GIF_SUSPENSION_SHORT_READ;
|
|
||||||
if (status < 0) {
|
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
status = PUFFS_GIF_SUSPENSION_SHORT_READ;
|
||||||
goto suspend;
|
goto suspend;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -790,12 +788,11 @@ exit:
|
|||||||
return status;
|
return status;
|
||||||
|
|
||||||
short_read_src:
|
short_read_src:
|
||||||
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
|
if ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi)) {
|
||||||
? PUFFS_GIF_ERROR_UNEXPECTED_EOF
|
status = PUFFS_GIF_ERROR_UNEXPECTED_EOF;
|
||||||
: PUFFS_GIF_SUSPENSION_SHORT_READ;
|
|
||||||
if (status < 0) {
|
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
status = PUFFS_GIF_SUSPENSION_SHORT_READ;
|
||||||
goto suspend;
|
goto suspend;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -858,11 +855,11 @@ puffs_gif_status puffs_gif_decoder_decode_extension(puffs_gif_decoder* self,
|
|||||||
if (t_2 > b_rend_src - b_rptr_src) {
|
if (t_2 > b_rend_src - b_rptr_src) {
|
||||||
t_2 -= b_rend_src - b_rptr_src;
|
t_2 -= b_rend_src - b_rptr_src;
|
||||||
a_src.buf->ri = a_src.buf->wi;
|
a_src.buf->ri = a_src.buf->wi;
|
||||||
status = a_src.buf->closed ? PUFFS_GIF_ERROR_UNEXPECTED_EOF
|
if (a_src.buf->closed) {
|
||||||
: PUFFS_GIF_SUSPENSION_SHORT_READ;
|
status = PUFFS_GIF_ERROR_UNEXPECTED_EOF;
|
||||||
if (status < 0) {
|
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
status = PUFFS_GIF_SUSPENSION_SHORT_READ;
|
||||||
goto suspend;
|
goto suspend;
|
||||||
}
|
}
|
||||||
b_rptr_src += t_2;
|
b_rptr_src += t_2;
|
||||||
@@ -893,12 +890,11 @@ exit:
|
|||||||
return status;
|
return status;
|
||||||
|
|
||||||
short_read_src:
|
short_read_src:
|
||||||
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
|
if ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi)) {
|
||||||
? PUFFS_GIF_ERROR_UNEXPECTED_EOF
|
status = PUFFS_GIF_ERROR_UNEXPECTED_EOF;
|
||||||
: PUFFS_GIF_SUSPENSION_SHORT_READ;
|
|
||||||
if (status < 0) {
|
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
status = PUFFS_GIF_SUSPENSION_SHORT_READ;
|
||||||
goto suspend;
|
goto suspend;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1052,12 +1048,11 @@ exit:
|
|||||||
return status;
|
return status;
|
||||||
|
|
||||||
short_read_src:
|
short_read_src:
|
||||||
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
|
if ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi)) {
|
||||||
? PUFFS_GIF_ERROR_UNEXPECTED_EOF
|
status = PUFFS_GIF_ERROR_UNEXPECTED_EOF;
|
||||||
: PUFFS_GIF_SUSPENSION_SHORT_READ;
|
|
||||||
if (status < 0) {
|
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
status = PUFFS_GIF_SUSPENSION_SHORT_READ;
|
||||||
goto suspend;
|
goto suspend;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1283,11 +1278,10 @@ exit:
|
|||||||
return status;
|
return status;
|
||||||
|
|
||||||
short_read_src:
|
short_read_src:
|
||||||
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
|
if ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi)) {
|
||||||
? PUFFS_GIF_ERROR_UNEXPECTED_EOF
|
status = PUFFS_GIF_ERROR_UNEXPECTED_EOF;
|
||||||
: PUFFS_GIF_SUSPENSION_SHORT_READ;
|
|
||||||
if (status < 0) {
|
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
status = PUFFS_GIF_SUSPENSION_SHORT_READ;
|
||||||
goto suspend;
|
goto suspend;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user