mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-22 08:47:28 +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 {
|
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 {
|
if err := g.writeFuncSignature(n); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
g.writes("{\n")
|
g.writes("{\n")
|
||||||
|
|
||||||
// Check the previous status and the "self" arg.
|
// Check the previous status and the "self" arg.
|
||||||
if n.Public() {
|
if g.perFunc.public && n.Receiver() != 0 {
|
||||||
g.perFunc.public = true
|
g.writes("if (!self) {")
|
||||||
if n.Receiver() != 0 {
|
if g.perFunc.suspendible {
|
||||||
g.writes("if (!self) {\n")
|
g.printf("return PUFFS_%s_ERROR_BAD_RECEIVER;", g.PKGNAME)
|
||||||
if n.Suspendible() {
|
} else {
|
||||||
g.printf("return PUFFS_%s_ERROR_BAD_RECEIVER;", g.PKGNAME)
|
g.printf("return;")
|
||||||
} else {
|
|
||||||
g.printf("return;")
|
|
||||||
}
|
|
||||||
g.writes("}\n")
|
|
||||||
}
|
}
|
||||||
|
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() {
|
if g.perFunc.suspendible {
|
||||||
g.perFunc.suspendible = true
|
g.printf("puffs_%s_status status = PUFFS_%s_STATUS_OK;\n", g.pkgName, g.PKGNAME)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// For public functions, check (at runtime) the other args for bounds and
|
// For public functions, check (at runtime) the other args for bounds and
|
||||||
// null-ness. For private functions, those checks are done at compile time.
|
// 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 {
|
if err := g.writeFuncImplArgChecks(n); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -259,7 +254,7 @@ func (g *gen) writeFuncImplArgChecks(n *a.Func) error {
|
|||||||
g.writes(c)
|
g.writes(c)
|
||||||
}
|
}
|
||||||
g.writes(") {")
|
g.writes(") {")
|
||||||
if n.Suspendible() {
|
if g.perFunc.suspendible {
|
||||||
g.printf("status = PUFFS_%s_ERROR_BAD_ARGUMENT; goto exit;", g.PKGNAME)
|
g.printf("status = PUFFS_%s_ERROR_BAD_ARGUMENT; goto exit;", g.PKGNAME)
|
||||||
} else if n.Receiver() != 0 {
|
} else if n.Receiver() != 0 {
|
||||||
g.printf("self->private_impl.status = PUFFS_%s_ERROR_BAD_ARGUMENT; return;", g.PKGNAME)
|
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) {
|
if (!self) {
|
||||||
return PUFFS_FLATE_ERROR_BAD_RECEIVER;
|
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) {
|
if (self->private_impl.magic != PUFFS_MAGIC) {
|
||||||
status = PUFFS_FLATE_ERROR_CONSTRUCTOR_NOT_CALLED;
|
self->private_impl.status = PUFFS_FLATE_ERROR_CONSTRUCTOR_NOT_CALLED;
|
||||||
goto exit;
|
|
||||||
}
|
}
|
||||||
|
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_final;
|
||||||
uint32_t v_type;
|
uint32_t v_type;
|
||||||
@@ -425,14 +424,13 @@ puffs_flate_status puffs_flate_decoder_decode_uncompressed(
|
|||||||
if (!self) {
|
if (!self) {
|
||||||
return PUFFS_FLATE_ERROR_BAD_RECEIVER;
|
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) {
|
if (self->private_impl.magic != PUFFS_MAGIC) {
|
||||||
status = PUFFS_FLATE_ERROR_CONSTRUCTOR_NOT_CALLED;
|
self->private_impl.status = PUFFS_FLATE_ERROR_CONSTRUCTOR_NOT_CALLED;
|
||||||
goto exit;
|
|
||||||
}
|
}
|
||||||
|
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_n0;
|
||||||
uint8_t v_n1;
|
uint8_t v_n1;
|
||||||
|
|||||||
+16
-19
@@ -404,14 +404,13 @@ puffs_gif_status puffs_gif_decoder_decode(puffs_gif_decoder* self,
|
|||||||
if (!self) {
|
if (!self) {
|
||||||
return PUFFS_GIF_ERROR_BAD_RECEIVER;
|
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) {
|
if (self->private_impl.magic != PUFFS_MAGIC) {
|
||||||
status = PUFFS_GIF_ERROR_CONSTRUCTOR_NOT_CALLED;
|
self->private_impl.status = PUFFS_GIF_ERROR_CONSTRUCTOR_NOT_CALLED;
|
||||||
goto exit;
|
|
||||||
}
|
}
|
||||||
|
if (self->private_impl.status < 0) {
|
||||||
|
return self->private_impl.status;
|
||||||
|
}
|
||||||
|
puffs_gif_status status = PUFFS_GIF_STATUS_OK;
|
||||||
|
|
||||||
uint8_t v_c;
|
uint8_t v_c;
|
||||||
|
|
||||||
@@ -590,7 +589,7 @@ short_read_src:
|
|||||||
|
|
||||||
puffs_gif_status puffs_gif_decoder_decode_header(puffs_gif_decoder* self,
|
puffs_gif_status puffs_gif_decoder_decode_header(puffs_gif_decoder* self,
|
||||||
puffs_base_reader1 a_src) {
|
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];
|
uint8_t v_c[6];
|
||||||
uint32_t v_i;
|
uint32_t v_i;
|
||||||
@@ -670,7 +669,7 @@ short_read_src:
|
|||||||
|
|
||||||
puffs_gif_status puffs_gif_decoder_decode_lsd(puffs_gif_decoder* self,
|
puffs_gif_status puffs_gif_decoder_decode_lsd(puffs_gif_decoder* self,
|
||||||
puffs_base_reader1 a_src) {
|
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];
|
uint8_t v_c[7];
|
||||||
uint32_t v_i;
|
uint32_t v_i;
|
||||||
@@ -779,7 +778,7 @@ short_read_src:
|
|||||||
|
|
||||||
puffs_gif_status puffs_gif_decoder_decode_extension(puffs_gif_decoder* self,
|
puffs_gif_status puffs_gif_decoder_decode_extension(puffs_gif_decoder* self,
|
||||||
puffs_base_reader1 a_src) {
|
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_label;
|
||||||
uint8_t v_block_size;
|
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_gif_status puffs_gif_decoder_decode_id(puffs_gif_decoder* self,
|
||||||
puffs_base_writer1 a_dst,
|
puffs_base_writer1 a_dst,
|
||||||
puffs_base_reader1 a_src) {
|
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];
|
uint8_t v_c[9];
|
||||||
uint32_t v_i;
|
uint32_t v_i;
|
||||||
@@ -1031,11 +1030,10 @@ void puffs_gif_lzw_decoder_set_literal_width(puffs_gif_lzw_decoder* self,
|
|||||||
if (!self) {
|
if (!self) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (self->private_impl.status < 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (self->private_impl.magic != PUFFS_MAGIC) {
|
if (self->private_impl.magic != PUFFS_MAGIC) {
|
||||||
self->private_impl.status = PUFFS_GIF_ERROR_CONSTRUCTOR_NOT_CALLED;
|
self->private_impl.status = PUFFS_GIF_ERROR_CONSTRUCTOR_NOT_CALLED;
|
||||||
|
}
|
||||||
|
if (self->private_impl.status < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (a_lw < 2 || a_lw > 8) {
|
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) {
|
if (!self) {
|
||||||
return PUFFS_GIF_ERROR_BAD_RECEIVER;
|
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) {
|
if (self->private_impl.magic != PUFFS_MAGIC) {
|
||||||
status = PUFFS_GIF_ERROR_CONSTRUCTOR_NOT_CALLED;
|
self->private_impl.status = PUFFS_GIF_ERROR_CONSTRUCTOR_NOT_CALLED;
|
||||||
goto exit;
|
|
||||||
}
|
}
|
||||||
|
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_clear_code;
|
||||||
uint32_t v_end_code;
|
uint32_t v_end_code;
|
||||||
|
|||||||
Reference in new issue
Block a user