mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
Don't make previous non-error statuses sticky.
This commit is contained in:
1 parent
faaf3542c6
commit
940417ec6a
3 files changed
+53
-63
No files matched your search
+27
-32
@@ -67,50 +67,45 @@ func (g *gen) writeFuncPrototype(n *a.Func) error {
|
||||
}
|
||||
|
||||
func (g *gen) writeFuncImpl(n *a.Func) error {
|
||||
g.perFunc = perFunc{funk: n}
|
||||
g.perFunc = perFunc{
|
||||
funk: n,
|
||||
public: n.Public(),
|
||||
suspendible: n.Suspendible(),
|
||||
}
|
||||
if err := g.writeFuncSignature(n); err != nil {
|
||||
return err
|
||||
}
|
||||
g.writes("{\n")
|
||||
|
||||
// Check the previous status and the "self" arg.
|
||||
if n.Public() {
|
||||
g.perFunc.public = true
|
||||
if n.Receiver() != 0 {
|
||||
g.writes("if (!self) {\n")
|
||||
if n.Suspendible() {
|
||||
g.printf("return PUFFS_%s_ERROR_BAD_RECEIVER;", g.PKGNAME)
|
||||
} else {
|
||||
g.printf("return;")
|
||||
}
|
||||
g.writes("}\n")
|
||||
if g.perFunc.public && n.Receiver() != 0 {
|
||||
g.writes("if (!self) {")
|
||||
if g.perFunc.suspendible {
|
||||
g.printf("return PUFFS_%s_ERROR_BAD_RECEIVER;", g.PKGNAME)
|
||||
} else {
|
||||
g.printf("return;")
|
||||
}
|
||||
g.writes("}")
|
||||
|
||||
g.printf("if (self->private_impl.magic != PUFFS_MAGIC) {"+
|
||||
"self->private_impl.status = PUFFS_%s_ERROR_CONSTRUCTOR_NOT_CALLED; }", g.PKGNAME)
|
||||
|
||||
g.writes("if (self->private_impl.status < 0) {")
|
||||
if g.perFunc.suspendible {
|
||||
g.writes("return self->private_impl.status;")
|
||||
} else {
|
||||
g.writes("return;")
|
||||
}
|
||||
g.writes("}\n")
|
||||
}
|
||||
|
||||
if n.Suspendible() {
|
||||
g.perFunc.suspendible = true
|
||||
g.printf("puffs_%s_status status = ", g.pkgName)
|
||||
if n.Receiver() != 0 {
|
||||
g.writes("self->private_impl.status;\n")
|
||||
if n.Public() {
|
||||
g.writes("if (status < 0) { return status; }")
|
||||
}
|
||||
} else {
|
||||
g.printf("PUFFS_%s_STATUS_OK;\n", g.PKGNAME)
|
||||
}
|
||||
if n.Public() {
|
||||
g.printf("if (self->private_impl.magic != PUFFS_MAGIC) {"+
|
||||
"status = PUFFS_%s_ERROR_CONSTRUCTOR_NOT_CALLED; goto exit; }\n", g.PKGNAME)
|
||||
}
|
||||
} else if n.Receiver() != 0 && n.Public() {
|
||||
g.writes("if (self->private_impl.status < 0) { return; }")
|
||||
g.printf("if (self->private_impl.magic != PUFFS_MAGIC) {"+
|
||||
"self->private_impl.status = PUFFS_%s_ERROR_CONSTRUCTOR_NOT_CALLED; return; }\n", g.PKGNAME)
|
||||
if g.perFunc.suspendible {
|
||||
g.printf("puffs_%s_status status = PUFFS_%s_STATUS_OK;\n", g.pkgName, g.PKGNAME)
|
||||
}
|
||||
|
||||
// For public functions, check (at runtime) the other args for bounds and
|
||||
// null-ness. For private functions, those checks are done at compile time.
|
||||
if n.Public() {
|
||||
if g.perFunc.public {
|
||||
if err := g.writeFuncImplArgChecks(n); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -259,7 +254,7 @@ func (g *gen) writeFuncImplArgChecks(n *a.Func) error {
|
||||
g.writes(c)
|
||||
}
|
||||
g.writes(") {")
|
||||
if n.Suspendible() {
|
||||
if g.perFunc.suspendible {
|
||||
g.printf("status = PUFFS_%s_ERROR_BAD_ARGUMENT; goto exit;", g.PKGNAME)
|
||||
} else if n.Receiver() != 0 {
|
||||
g.printf("self->private_impl.status = PUFFS_%s_ERROR_BAD_ARGUMENT; return;", g.PKGNAME)
|
||||
|
||||
+10
-12
@@ -295,14 +295,13 @@ puffs_flate_status puffs_flate_decoder_decode(puffs_flate_decoder* self,
|
||||
if (!self) {
|
||||
return PUFFS_FLATE_ERROR_BAD_RECEIVER;
|
||||
}
|
||||
puffs_flate_status status = self->private_impl.status;
|
||||
if (status < 0) {
|
||||
return status;
|
||||
}
|
||||
if (self->private_impl.magic != PUFFS_MAGIC) {
|
||||
status = PUFFS_FLATE_ERROR_CONSTRUCTOR_NOT_CALLED;
|
||||
goto exit;
|
||||
self->private_impl.status = PUFFS_FLATE_ERROR_CONSTRUCTOR_NOT_CALLED;
|
||||
}
|
||||
if (self->private_impl.status < 0) {
|
||||
return self->private_impl.status;
|
||||
}
|
||||
puffs_flate_status status = PUFFS_FLATE_STATUS_OK;
|
||||
|
||||
uint32_t v_final;
|
||||
uint32_t v_type;
|
||||
@@ -425,14 +424,13 @@ puffs_flate_status puffs_flate_decoder_decode_uncompressed(
|
||||
if (!self) {
|
||||
return PUFFS_FLATE_ERROR_BAD_RECEIVER;
|
||||
}
|
||||
puffs_flate_status status = self->private_impl.status;
|
||||
if (status < 0) {
|
||||
return status;
|
||||
}
|
||||
if (self->private_impl.magic != PUFFS_MAGIC) {
|
||||
status = PUFFS_FLATE_ERROR_CONSTRUCTOR_NOT_CALLED;
|
||||
goto exit;
|
||||
self->private_impl.status = PUFFS_FLATE_ERROR_CONSTRUCTOR_NOT_CALLED;
|
||||
}
|
||||
if (self->private_impl.status < 0) {
|
||||
return self->private_impl.status;
|
||||
}
|
||||
puffs_flate_status status = PUFFS_FLATE_STATUS_OK;
|
||||
|
||||
uint8_t v_n0;
|
||||
uint8_t v_n1;
|
||||
|
||||
+16
-19
@@ -404,14 +404,13 @@ puffs_gif_status puffs_gif_decoder_decode(puffs_gif_decoder* self,
|
||||
if (!self) {
|
||||
return PUFFS_GIF_ERROR_BAD_RECEIVER;
|
||||
}
|
||||
puffs_gif_status status = self->private_impl.status;
|
||||
if (status < 0) {
|
||||
return status;
|
||||
}
|
||||
if (self->private_impl.magic != PUFFS_MAGIC) {
|
||||
status = PUFFS_GIF_ERROR_CONSTRUCTOR_NOT_CALLED;
|
||||
goto exit;
|
||||
self->private_impl.status = PUFFS_GIF_ERROR_CONSTRUCTOR_NOT_CALLED;
|
||||
}
|
||||
if (self->private_impl.status < 0) {
|
||||
return self->private_impl.status;
|
||||
}
|
||||
puffs_gif_status status = PUFFS_GIF_STATUS_OK;
|
||||
|
||||
uint8_t v_c;
|
||||
|
||||
@@ -590,7 +589,7 @@ short_read_src:
|
||||
|
||||
puffs_gif_status puffs_gif_decoder_decode_header(puffs_gif_decoder* self,
|
||||
puffs_base_reader1 a_src) {
|
||||
puffs_gif_status status = self->private_impl.status;
|
||||
puffs_gif_status status = PUFFS_GIF_STATUS_OK;
|
||||
|
||||
uint8_t v_c[6];
|
||||
uint32_t v_i;
|
||||
@@ -670,7 +669,7 @@ short_read_src:
|
||||
|
||||
puffs_gif_status puffs_gif_decoder_decode_lsd(puffs_gif_decoder* self,
|
||||
puffs_base_reader1 a_src) {
|
||||
puffs_gif_status status = self->private_impl.status;
|
||||
puffs_gif_status status = PUFFS_GIF_STATUS_OK;
|
||||
|
||||
uint8_t v_c[7];
|
||||
uint32_t v_i;
|
||||
@@ -779,7 +778,7 @@ short_read_src:
|
||||
|
||||
puffs_gif_status puffs_gif_decoder_decode_extension(puffs_gif_decoder* self,
|
||||
puffs_base_reader1 a_src) {
|
||||
puffs_gif_status status = self->private_impl.status;
|
||||
puffs_gif_status status = PUFFS_GIF_STATUS_OK;
|
||||
|
||||
uint8_t v_label;
|
||||
uint8_t v_block_size;
|
||||
@@ -875,7 +874,7 @@ short_read_src:
|
||||
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;
|
||||
puffs_gif_status status = PUFFS_GIF_STATUS_OK;
|
||||
|
||||
uint8_t v_c[9];
|
||||
uint32_t v_i;
|
||||
@@ -1031,11 +1030,10 @@ void puffs_gif_lzw_decoder_set_literal_width(puffs_gif_lzw_decoder* self,
|
||||
if (!self) {
|
||||
return;
|
||||
}
|
||||
if (self->private_impl.status < 0) {
|
||||
return;
|
||||
}
|
||||
if (self->private_impl.magic != PUFFS_MAGIC) {
|
||||
self->private_impl.status = PUFFS_GIF_ERROR_CONSTRUCTOR_NOT_CALLED;
|
||||
}
|
||||
if (self->private_impl.status < 0) {
|
||||
return;
|
||||
}
|
||||
if (a_lw < 2 || a_lw > 8) {
|
||||
@@ -1052,14 +1050,13 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
||||
if (!self) {
|
||||
return PUFFS_GIF_ERROR_BAD_RECEIVER;
|
||||
}
|
||||
puffs_gif_status status = self->private_impl.status;
|
||||
if (status < 0) {
|
||||
return status;
|
||||
}
|
||||
if (self->private_impl.magic != PUFFS_MAGIC) {
|
||||
status = PUFFS_GIF_ERROR_CONSTRUCTOR_NOT_CALLED;
|
||||
goto exit;
|
||||
self->private_impl.status = PUFFS_GIF_ERROR_CONSTRUCTOR_NOT_CALLED;
|
||||
}
|
||||
if (self->private_impl.status < 0) {
|
||||
return self->private_impl.status;
|
||||
}
|
||||
puffs_gif_status status = PUFFS_GIF_STATUS_OK;
|
||||
|
||||
uint32_t v_clear_code;
|
||||
uint32_t v_end_code;
|
||||
|
||||
Reference in new issue
Block a user