mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Be more consistent with pub/pri error handling.
This commit is contained in:
1 parent
70f2559d4e
commit
7b3628d78f
3 files changed
+69
-52
No files matched your search
+16
-33
@@ -641,20 +641,23 @@ func (g *gen) writeStatement(n *a.Node, depth uint32) error {
|
||||
|
||||
case a.KReturn:
|
||||
n := n.Return()
|
||||
ret := ""
|
||||
ret := status{}
|
||||
if n.Keyword() == 0 {
|
||||
ret = fmt.Sprintf("PUFFS_%s_STATUS_OK", g.PKGNAME)
|
||||
ret.name = fmt.Sprintf("PUFFS_%s_STATUS_OK", g.PKGNAME)
|
||||
} else {
|
||||
ret = g.statusMap[n.Message()].name
|
||||
ret = g.statusMap[n.Message()]
|
||||
}
|
||||
if !g.perFunc.suspendible {
|
||||
if g.perFunc.suspendible {
|
||||
g.printf("status = %s;", ret.name)
|
||||
if ret.isError {
|
||||
g.writes("goto exit;")
|
||||
} else {
|
||||
g.writes("goto suspend;")
|
||||
}
|
||||
} else {
|
||||
// TODO: consider the return values, especially if they involve
|
||||
// suspendible function calls.
|
||||
g.writes("return;\n")
|
||||
} else if g.perFunc.public {
|
||||
g.printf("status = %s; goto suspend;\n", ret)
|
||||
} else {
|
||||
g.printf("return %s;\n", ret)
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -827,11 +830,7 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error {
|
||||
|
||||
g.printf("status = %ssrc.buf->closed ? PUFFS_%s_ERROR_UNEXPECTED_EOF : PUFFS_%s_SUSPENSION_SHORT_READ;",
|
||||
aPrefix, g.PKGNAME, g.PKGNAME)
|
||||
if g.perFunc.public && g.perFunc.suspendible { // TODO: drop the g.perFunc.public?
|
||||
g.writes("goto suspend;")
|
||||
} else {
|
||||
g.writes("return status;")
|
||||
}
|
||||
g.writes("if (status < 0) { goto exit; } goto suspend;")
|
||||
|
||||
g.writes("}\n")
|
||||
g.printf("%srptr_src += %s%d;\n", bPrefix, tPrefix, temp)
|
||||
@@ -839,20 +838,12 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error {
|
||||
} else if isInDst(g.tm, n, t.KeyWrite, 1) {
|
||||
// TODO: don't assume that the argument is "this.stack[s:]".
|
||||
g.printf("if (%sdst.buf->closed) { status = PUFFS_%s_ERROR_CLOSED_FOR_WRITES;", aPrefix, g.PKGNAME)
|
||||
if g.perFunc.public && g.perFunc.suspendible {
|
||||
g.writes("goto suspend;")
|
||||
} else {
|
||||
g.writes("return status;")
|
||||
}
|
||||
g.writes("goto exit;")
|
||||
g.writes("}\n")
|
||||
g.printf("if ((%swend_dst - %swptr_dst) < (sizeof(self->private_impl.f_stack) - v_s)) {",
|
||||
bPrefix, bPrefix)
|
||||
g.printf("status = PUFFS_%s_SUSPENSION_SHORT_WRITE;", g.PKGNAME)
|
||||
if g.perFunc.public && g.perFunc.suspendible {
|
||||
g.writes("goto suspend;")
|
||||
} else {
|
||||
g.writes("return status;")
|
||||
}
|
||||
g.writes("goto suspend;")
|
||||
g.writes("}\n")
|
||||
g.printf("memmove(b_wptr_dst," +
|
||||
"self->private_impl.f_stack + v_s," +
|
||||
@@ -862,11 +853,7 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error {
|
||||
} else if isInDst(g.tm, n, t.KeyWriteU8, 1) {
|
||||
g.printf("if (%swptr_dst == %swend_dst) { status = PUFFS_%s_SUSPENSION_SHORT_WRITE;",
|
||||
bPrefix, bPrefix, g.PKGNAME)
|
||||
if g.perFunc.public && g.perFunc.suspendible {
|
||||
g.writes("goto suspend;")
|
||||
} else {
|
||||
g.writes("return status;")
|
||||
}
|
||||
g.writes("goto suspend;")
|
||||
g.writes("}\n")
|
||||
g.printf("*%swptr_dst++ = ", bPrefix)
|
||||
x := n.Args()[0].Arg().Value()
|
||||
@@ -989,11 +976,7 @@ func (g *gen) writeShortRead(name string) error {
|
||||
g.printf("status = ((%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, g.PKGNAME, g.PKGNAME)
|
||||
if g.perFunc.public && g.perFunc.suspendible { // TODO: drop the g.perFunc.public?
|
||||
g.writes("goto suspend;")
|
||||
} else {
|
||||
g.writes("return status;")
|
||||
}
|
||||
g.writes("if (status < 0) { goto exit; } goto suspend;")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
+15
-6
@@ -405,7 +405,7 @@ puffs_flate_status puffs_flate_decoder_decode(puffs_flate_decoder* self,
|
||||
}
|
||||
} else if (v_type == 1) {
|
||||
status = PUFFS_FLATE_ERROR_TODO_FIXED_HUFFMAN_BLOCKS;
|
||||
goto suspend;
|
||||
goto exit;
|
||||
} else if (v_type == 2) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(3);
|
||||
if (a_src.buf) {
|
||||
@@ -435,7 +435,7 @@ puffs_flate_status puffs_flate_decoder_decode(puffs_flate_decoder* self,
|
||||
}
|
||||
} else {
|
||||
status = PUFFS_FLATE_ERROR_BAD_FLATE_BLOCK;
|
||||
goto suspend;
|
||||
goto exit;
|
||||
}
|
||||
if (v_final != 0) {
|
||||
status = PUFFS_FLATE_STATUS_OK;
|
||||
@@ -471,6 +471,9 @@ short_read_src:
|
||||
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
|
||||
? PUFFS_FLATE_ERROR_UNEXPECTED_EOF
|
||||
: PUFFS_FLATE_SUSPENSION_SHORT_READ;
|
||||
if (status < 0) {
|
||||
goto exit;
|
||||
}
|
||||
goto suspend;
|
||||
}
|
||||
|
||||
@@ -528,7 +531,7 @@ puffs_flate_status puffs_flate_decoder_decode_uncompressed(
|
||||
|
||||
if (self->private_impl.f_n_bits >= 8) {
|
||||
status = PUFFS_FLATE_ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS;
|
||||
goto suspend;
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_n_bits = 0;
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(1);
|
||||
@@ -558,7 +561,7 @@ puffs_flate_status puffs_flate_decoder_decode_uncompressed(
|
||||
v_n = t_1;
|
||||
if ((((v_n) & ((1 << (16)) - 1)) + ((v_n) >> (32 - (16)))) != 65535) {
|
||||
status = PUFFS_FLATE_ERROR_INCONSISTENT_STORED_BLOCK_LENGTH;
|
||||
goto suspend;
|
||||
goto exit;
|
||||
}
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(3);
|
||||
{
|
||||
@@ -619,6 +622,9 @@ short_read_src:
|
||||
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
|
||||
? PUFFS_FLATE_ERROR_UNEXPECTED_EOF
|
||||
: PUFFS_FLATE_SUSPENSION_SHORT_READ;
|
||||
if (status < 0) {
|
||||
goto exit;
|
||||
}
|
||||
goto suspend;
|
||||
}
|
||||
|
||||
@@ -685,13 +691,13 @@ puffs_flate_status puffs_flate_decoder_decode_dynamic(
|
||||
v_hlit = (((v_bits) & ((1 << (5)) - 1)) + 257);
|
||||
if (v_hlit > 286) {
|
||||
status = PUFFS_FLATE_ERROR_BAD_LITERAL_LENGTH_CODE_COUNT;
|
||||
goto suspend;
|
||||
goto exit;
|
||||
}
|
||||
v_bits >>= 5;
|
||||
v_hdist = (((v_bits) & ((1 << (5)) - 1)) + 1);
|
||||
if (v_hdist > 30) {
|
||||
status = PUFFS_FLATE_ERROR_BAD_DISTANCE_CODE_COUNT;
|
||||
goto suspend;
|
||||
goto exit;
|
||||
}
|
||||
v_bits >>= 5;
|
||||
v_hclen = (((v_bits) & ((1 << (4)) - 1)) + 4);
|
||||
@@ -757,5 +763,8 @@ short_read_src:
|
||||
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
|
||||
? PUFFS_FLATE_ERROR_UNEXPECTED_EOF
|
||||
: PUFFS_FLATE_SUSPENSION_SHORT_READ;
|
||||
if (status < 0) {
|
||||
goto exit;
|
||||
}
|
||||
goto suspend;
|
||||
}
|
||||
+38
-13
@@ -565,7 +565,7 @@ puffs_gif_status puffs_gif_decoder_decode(puffs_gif_decoder* self,
|
||||
goto suspend;
|
||||
} else {
|
||||
status = PUFFS_GIF_ERROR_BAD_GIF_BLOCK;
|
||||
goto suspend;
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
coro_susp_point = 0;
|
||||
@@ -596,6 +596,9 @@ short_read_src:
|
||||
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
|
||||
? PUFFS_GIF_ERROR_UNEXPECTED_EOF
|
||||
: PUFFS_GIF_SUSPENSION_SHORT_READ;
|
||||
if (status < 0) {
|
||||
goto exit;
|
||||
}
|
||||
goto suspend;
|
||||
}
|
||||
|
||||
@@ -647,7 +650,8 @@ puffs_gif_status puffs_gif_decoder_decode_header(puffs_gif_decoder* self,
|
||||
}
|
||||
if ((v_c[0] != 71) || (v_c[1] != 73) || (v_c[2] != 70) || (v_c[3] != 56) ||
|
||||
((v_c[4] != 55) && (v_c[4] != 57)) || (v_c[5] != 97)) {
|
||||
return PUFFS_GIF_ERROR_BAD_GIF_HEADER;
|
||||
status = PUFFS_GIF_ERROR_BAD_GIF_HEADER;
|
||||
goto exit;
|
||||
}
|
||||
coro_susp_point = 0;
|
||||
}
|
||||
@@ -677,7 +681,10 @@ short_read_src:
|
||||
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
|
||||
? PUFFS_GIF_ERROR_UNEXPECTED_EOF
|
||||
: PUFFS_GIF_SUSPENSION_SHORT_READ;
|
||||
return status;
|
||||
if (status < 0) {
|
||||
goto exit;
|
||||
}
|
||||
goto suspend;
|
||||
}
|
||||
|
||||
puffs_gif_status puffs_gif_decoder_decode_lsd(puffs_gif_decoder* self,
|
||||
@@ -786,7 +793,10 @@ short_read_src:
|
||||
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
|
||||
? PUFFS_GIF_ERROR_UNEXPECTED_EOF
|
||||
: PUFFS_GIF_SUSPENSION_SHORT_READ;
|
||||
return status;
|
||||
if (status < 0) {
|
||||
goto exit;
|
||||
}
|
||||
goto suspend;
|
||||
}
|
||||
|
||||
puffs_gif_status puffs_gif_decoder_decode_extension(puffs_gif_decoder* self,
|
||||
@@ -830,7 +840,8 @@ puffs_gif_status puffs_gif_decoder_decode_extension(puffs_gif_decoder* self,
|
||||
} else if (v_label == 254) {
|
||||
} else if (v_label == 255) {
|
||||
} else {
|
||||
return PUFFS_GIF_ERROR_BAD_GIF_EXTENSION_LABEL;
|
||||
status = PUFFS_GIF_ERROR_BAD_GIF_EXTENSION_LABEL;
|
||||
goto exit;
|
||||
}
|
||||
while (true) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(2);
|
||||
@@ -849,7 +860,10 @@ puffs_gif_status puffs_gif_decoder_decode_extension(puffs_gif_decoder* self,
|
||||
a_src.buf->ri = a_src.buf->wi;
|
||||
status = a_src.buf->closed ? PUFFS_GIF_ERROR_UNEXPECTED_EOF
|
||||
: PUFFS_GIF_SUSPENSION_SHORT_READ;
|
||||
return status;
|
||||
if (status < 0) {
|
||||
goto exit;
|
||||
}
|
||||
goto suspend;
|
||||
}
|
||||
b_rptr_src += t_2;
|
||||
}
|
||||
@@ -882,7 +896,10 @@ short_read_src:
|
||||
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
|
||||
? PUFFS_GIF_ERROR_UNEXPECTED_EOF
|
||||
: PUFFS_GIF_SUSPENSION_SHORT_READ;
|
||||
return status;
|
||||
if (status < 0) {
|
||||
goto exit;
|
||||
}
|
||||
goto suspend;
|
||||
}
|
||||
|
||||
puffs_gif_status puffs_gif_decoder_decode_id(puffs_gif_decoder* self,
|
||||
@@ -945,7 +962,8 @@ puffs_gif_status puffs_gif_decoder_decode_id(puffs_gif_decoder* self,
|
||||
if (v_interlace) {
|
||||
}
|
||||
if ((v_c[8] & 128) != 0) {
|
||||
return PUFFS_GIF_ERROR_TODO_UNSUPPORTED_LOCAL_COLOR_TABLE;
|
||||
status = PUFFS_GIF_ERROR_TODO_UNSUPPORTED_LOCAL_COLOR_TABLE;
|
||||
goto exit;
|
||||
}
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(2);
|
||||
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
@@ -954,7 +972,8 @@ puffs_gif_status puffs_gif_decoder_decode_id(puffs_gif_decoder* self,
|
||||
uint8_t t_1 = *b_rptr_src++;
|
||||
v_lw = t_1;
|
||||
if ((v_lw < 2) || (8 < v_lw)) {
|
||||
return PUFFS_GIF_ERROR_BAD_LZW_LITERAL_WIDTH;
|
||||
status = PUFFS_GIF_ERROR_BAD_LZW_LITERAL_WIDTH;
|
||||
goto exit;
|
||||
}
|
||||
puffs_gif_lzw_decoder_set_literal_width(&self->private_impl.f_lzw,
|
||||
((uint32_t)(v_lw)));
|
||||
@@ -1036,7 +1055,10 @@ short_read_src:
|
||||
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
|
||||
? PUFFS_GIF_ERROR_UNEXPECTED_EOF
|
||||
: PUFFS_GIF_SUSPENSION_SHORT_READ;
|
||||
return status;
|
||||
if (status < 0) {
|
||||
goto exit;
|
||||
}
|
||||
goto suspend;
|
||||
}
|
||||
|
||||
void puffs_gif_lzw_decoder_set_literal_width(puffs_gif_lzw_decoder* self,
|
||||
@@ -1178,7 +1200,7 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
||||
self->private_impl.f_stack[v_s] = self->private_impl.f_suffixes[v_c];
|
||||
if (v_s == 0) {
|
||||
status = PUFFS_GIF_ERROR_LZW_PREFIX_CHAIN_IS_CYCLICAL;
|
||||
goto suspend;
|
||||
goto exit;
|
||||
}
|
||||
v_s -= 1;
|
||||
v_c = ((uint32_t)(self->private_impl.f_prefixes[v_c]));
|
||||
@@ -1190,7 +1212,7 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(3);
|
||||
if (a_dst.buf->closed) {
|
||||
status = PUFFS_GIF_ERROR_CLOSED_FOR_WRITES;
|
||||
goto suspend;
|
||||
goto exit;
|
||||
}
|
||||
if ((b_wend_dst - b_wptr_dst) <
|
||||
(sizeof(self->private_impl.f_stack) - v_s)) {
|
||||
@@ -1207,7 +1229,7 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
||||
}
|
||||
} else {
|
||||
status = PUFFS_GIF_ERROR_LZW_CODE_IS_OUT_OF_RANGE;
|
||||
goto suspend;
|
||||
goto exit;
|
||||
}
|
||||
if (v_save_code <= 4095) {
|
||||
v_save_code += 1;
|
||||
@@ -1264,5 +1286,8 @@ short_read_src:
|
||||
status = ((a_src.buf->closed) && (a_src.buf->ri == a_src.buf->wi))
|
||||
? PUFFS_GIF_ERROR_UNEXPECTED_EOF
|
||||
: PUFFS_GIF_SUSPENSION_SHORT_READ;
|
||||
if (status < 0) {
|
||||
goto exit;
|
||||
}
|
||||
goto suspend;
|
||||
}
|
||||
Reference in new issue
Block a user