mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-23 16:52:18 +01:00
Let a short_src be either an error or a status.
Error-ness depends on whether there's possibly more source data. Also rename short_dst and short_src to short_write and short_read, as the new names don't depend on the function arguments being named exactly dst and src.
This commit is contained in:
1 parent
9a27953faf
commit
e49ec3fd90
5 files changed
+40
-35
No files matched your search
+24
-19
@@ -56,20 +56,20 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var builtInStatuses = [...]string{
|
var builtInStatuses = [...]string{
|
||||||
// For API/ABI compatibility, the very first two status values must be
|
// For API/ABI compatibility, the very first two statuses must be "status
|
||||||
// status_ok (with generated value 0) and error_bad_version (with generated
|
// ok" (with generated value 0) and "error bad version" (with generated
|
||||||
// value -2 + 1). This lets caller code check the constructor return value
|
// value -2 + 1). This lets caller code check the constructor return value
|
||||||
// for error_bad_version even if the caller and callee were built with
|
// for "error bad version" even if the caller and callee were built with
|
||||||
// different versions.
|
// different versions.
|
||||||
"status_ok",
|
"status ok",
|
||||||
"error_bad_version",
|
"error bad version",
|
||||||
// The order of the remaining status values is less important.
|
// The order of the remaining statuses is less important.
|
||||||
"error_bad_receiver",
|
"error bad receiver",
|
||||||
"error_bad_argument",
|
"error bad argument",
|
||||||
"error_constructor_not_called",
|
"error constructor not called",
|
||||||
"status_short_dst",
|
"error unexpected EOF", // Used if read foo passed final == true.
|
||||||
"status_short_src",
|
"status short read", // Used if read foo passed final == false.
|
||||||
"status_short_buffer",
|
"status short write",
|
||||||
}
|
}
|
||||||
|
|
||||||
type replacementPolicy bool
|
type replacementPolicy bool
|
||||||
@@ -138,9 +138,11 @@ func (g *gen) generate() error {
|
|||||||
g.writes("typedef enum {\n")
|
g.writes("typedef enum {\n")
|
||||||
for i, s := range builtInStatuses {
|
for i, s := range builtInStatuses {
|
||||||
nudge := ""
|
nudge := ""
|
||||||
if strings.HasPrefix(s, "error_") {
|
if strings.HasPrefix(s, "error ") {
|
||||||
nudge = "+1"
|
nudge = "+1"
|
||||||
}
|
}
|
||||||
|
s = strings.Replace(s, " ", "_", -1)
|
||||||
|
s = strings.ToLower(s)
|
||||||
g.printf("puffs_%s_%s = %d%s,\n", g.pkgName, s, -2*i, nudge)
|
g.printf("puffs_%s_%s = %d%s,\n", g.pkgName, s, -2*i, nudge)
|
||||||
}
|
}
|
||||||
g.printf("} puffs_%s_status;\n\n", g.pkgName)
|
g.printf("} puffs_%s_status;\n\n", g.pkgName)
|
||||||
@@ -174,12 +176,12 @@ func (g *gen) generate() error {
|
|||||||
"return s & 1; }\n\n", g.pkgName, g.pkgName)
|
"return s & 1; }\n\n", g.pkgName, g.pkgName)
|
||||||
g.printf("const char* puffs_%s_status_strings[%d] = {\n", g.pkgName, len(builtInStatuses))
|
g.printf("const char* puffs_%s_status_strings[%d] = {\n", g.pkgName, len(builtInStatuses))
|
||||||
for _, s := range builtInStatuses {
|
for _, s := range builtInStatuses {
|
||||||
if strings.HasPrefix(s, "status_") {
|
if strings.HasPrefix(s, "status ") {
|
||||||
s = s[len("status_"):]
|
s = s[len("status "):]
|
||||||
} else if strings.HasPrefix(s, "error_") {
|
} else if strings.HasPrefix(s, "error ") {
|
||||||
s = s[len("error_"):]
|
s = s[len("error "):]
|
||||||
}
|
}
|
||||||
s = g.pkgName + ": " + strings.Replace(s, "_", " ", -1)
|
s = g.pkgName + ": " + s
|
||||||
g.printf("%q,", s)
|
g.printf("%q,", s)
|
||||||
}
|
}
|
||||||
g.writes("};\n\n")
|
g.writes("};\n\n")
|
||||||
@@ -695,7 +697,10 @@ func (g *gen) writeCallSuspendibles(n *a.Expr) error {
|
|||||||
// TODO: delete this hack that only matches "in.src.read_u8?()".
|
// TODO: delete this hack that only matches "in.src.read_u8?()".
|
||||||
if isInSrcReadU8(g.idMap, n.LHS().Expr()) && n.CallSuspendible() && len(n.Args()) == 0 {
|
if isInSrcReadU8(g.idMap, n.LHS().Expr()) && n.CallSuspendible() && len(n.Args()) == 0 {
|
||||||
// TODO: suspend coroutine state.
|
// TODO: suspend coroutine state.
|
||||||
g.printf("if (%ssrc->ri >= %ssrc->wi) { status = puffs_%s_status_short_src;",
|
//
|
||||||
|
// TODO: choose error_unexpected_eof versus status_short_read based on
|
||||||
|
// src_final.
|
||||||
|
g.printf("if (%ssrc->ri >= %ssrc->wi) { status = puffs_%s_status_short_read;",
|
||||||
aPrefix, aPrefix, g.pkgName)
|
aPrefix, aPrefix, g.pkgName)
|
||||||
if g.perFunc.cleanup0 {
|
if g.perFunc.cleanup0 {
|
||||||
g.writes("goto cleanup0;")
|
g.writes("goto cleanup0;")
|
||||||
|
|||||||
+7
-7
@@ -60,9 +60,9 @@ typedef enum {
|
|||||||
puffs_gif_error_bad_receiver = -4 + 1,
|
puffs_gif_error_bad_receiver = -4 + 1,
|
||||||
puffs_gif_error_bad_argument = -6 + 1,
|
puffs_gif_error_bad_argument = -6 + 1,
|
||||||
puffs_gif_error_constructor_not_called = -8 + 1,
|
puffs_gif_error_constructor_not_called = -8 + 1,
|
||||||
puffs_gif_status_short_dst = -10,
|
puffs_gif_error_unexpected_eof = -10 + 1,
|
||||||
puffs_gif_status_short_src = -12,
|
puffs_gif_status_short_read = -12,
|
||||||
puffs_gif_status_short_buffer = -14,
|
puffs_gif_status_short_write = -14,
|
||||||
} puffs_gif_status;
|
} puffs_gif_status;
|
||||||
|
|
||||||
bool puffs_gif_status_is_error(puffs_gif_status s);
|
bool puffs_gif_status_is_error(puffs_gif_status s);
|
||||||
@@ -127,9 +127,9 @@ const char* puffs_gif_status_strings[8] = {
|
|||||||
"gif: bad receiver",
|
"gif: bad receiver",
|
||||||
"gif: bad argument",
|
"gif: bad argument",
|
||||||
"gif: constructor not called",
|
"gif: constructor not called",
|
||||||
"gif: short dst",
|
"gif: unexpected EOF",
|
||||||
"gif: short src",
|
"gif: short read",
|
||||||
"gif: short buffer",
|
"gif: short write",
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* puffs_gif_status_string(puffs_gif_status s) {
|
const char* puffs_gif_status_string(puffs_gif_status s) {
|
||||||
@@ -217,7 +217,7 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
|||||||
while (1) {
|
while (1) {
|
||||||
while ((v_n_bits < v_width)) {
|
while ((v_n_bits < v_width)) {
|
||||||
if (a_src->ri >= a_src->wi) {
|
if (a_src->ri >= a_src->wi) {
|
||||||
status = puffs_gif_status_short_src;
|
status = puffs_gif_status_short_read;
|
||||||
goto cleanup0;
|
goto cleanup0;
|
||||||
}
|
}
|
||||||
uint8_t t_0 = a_src->ptr[a_src->ri++];
|
uint8_t t_0 = a_src->ptr[a_src->ri++];
|
||||||
|
|||||||
+3
-3
@@ -60,9 +60,9 @@ typedef enum {
|
|||||||
puffs_gif_error_bad_receiver = -4 + 1,
|
puffs_gif_error_bad_receiver = -4 + 1,
|
||||||
puffs_gif_error_bad_argument = -6 + 1,
|
puffs_gif_error_bad_argument = -6 + 1,
|
||||||
puffs_gif_error_constructor_not_called = -8 + 1,
|
puffs_gif_error_constructor_not_called = -8 + 1,
|
||||||
puffs_gif_status_short_dst = -10,
|
puffs_gif_error_unexpected_eof = -10 + 1,
|
||||||
puffs_gif_status_short_src = -12,
|
puffs_gif_status_short_read = -12,
|
||||||
puffs_gif_status_short_buffer = -14,
|
puffs_gif_status_short_write = -14,
|
||||||
} puffs_gif_status;
|
} puffs_gif_status;
|
||||||
|
|
||||||
bool puffs_gif_status_is_error(puffs_gif_status s);
|
bool puffs_gif_status_is_error(puffs_gif_status s);
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ pub func lzw_decoder.decode?(dst ptr buf1, src ptr buf1, src_final bool)() {
|
|||||||
post n_bits >= width,
|
post n_bits >= width,
|
||||||
{
|
{
|
||||||
assert n_bits < 12 via "a < b: a < c; c <= b"(c:width)
|
assert n_bits < 12 via "a < b: a < c; c <= b"(c:width)
|
||||||
bits |= in.src.read_u8?() as u32 // TODO
|
bits |= in.src.read_u8?() as u32 // TODO: read_u8 should take src_final.
|
||||||
n_bits += 8
|
n_bits += 8
|
||||||
}
|
}
|
||||||
// TODO: var code u32[..4095] = bits.low_bits(width)
|
// TODO: var code u32[..4095] = bits.low_bits(width)
|
||||||
|
|||||||
+5
-5
@@ -89,8 +89,8 @@ void test_status_is_error() {
|
|||||||
FAIL("test_status_is_error: is_error(bad_version) returned false");
|
FAIL("test_status_is_error: is_error(bad_version) returned false");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (puffs_gif_status_is_error(puffs_gif_status_short_dst)) {
|
if (puffs_gif_status_is_error(puffs_gif_status_short_write)) {
|
||||||
FAIL("test_status_is_error: is_error(short_dst) returned true");
|
FAIL("test_status_is_error: is_error(short_write) returned true");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -106,9 +106,9 @@ void test_status_strings() {
|
|||||||
FAIL("test_status_strings: got \"%s\", want \"gif: bad version\"", s1);
|
FAIL("test_status_strings: got \"%s\", want \"gif: bad version\"", s1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const char* s2 = puffs_gif_status_string(puffs_gif_status_short_dst);
|
const char* s2 = puffs_gif_status_string(puffs_gif_status_short_write);
|
||||||
if (strcmp(s2, "gif: short dst")) {
|
if (strcmp(s2, "gif: short write")) {
|
||||||
FAIL("test_status_strings: got \"%s\", want \"gif: short dst\"", s2);
|
FAIL("test_status_strings: got \"%s\", want \"gif: short write\"", s2);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user