mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-23 00:47:56 +01:00
Add reader1 and writer1 base types.
This commit is contained in:
1 parent
d16a25806f
commit
17e47fbc1e
11 files changed
+169
-138
No files matched your search
@@ -46,4 +46,14 @@ typedef struct {
|
|||||||
bool closed; // No further writes are expected.
|
bool closed; // No further writes are expected.
|
||||||
} puffs_base_buf1;
|
} puffs_base_buf1;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
puffs_base_buf1* buf;
|
||||||
|
// TODO: limits.
|
||||||
|
} puffs_base_reader1;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
puffs_base_buf1* buf;
|
||||||
|
// TODO: limits.
|
||||||
|
} puffs_base_writer1;
|
||||||
|
|
||||||
#endif // PUFFS_BASE_HEADER_H
|
#endif // PUFFS_BASE_HEADER_H
|
||||||
@@ -7,7 +7,7 @@ package main
|
|||||||
|
|
||||||
const baseHeader = "" +
|
const baseHeader = "" +
|
||||||
"#ifndef PUFFS_BASE_HEADER_H\n#define PUFFS_BASE_HEADER_H\n\n// Use of this source code is governed by a BSD-style license that can be found\n// in the LICENSE file.\n\n#include <stdbool.h>\n#include <stdint.h>\n#include <string.h>\n\n// Puffs requires a word size of at least 32 bits because it assumes that\n// converting a u32 to usize will never overflow. For example, the size of a\n// decoded image is often represented, explicitly or implicitly in an image\n// file, as a u32, and it is convenient to compare that to a buffer size.\n//\n// Similarly, the word size is at most 64 bits because it assumes that\n// converting a usize to u64 will never overflow.\n#if __WORDSIZE < 32\n#error \"Puffs requires a word size of at least 32 bits\"\n#elif __WORDSIZE > 64\n#error \"Puffs requires a word size of at most 64 bits\"\n#endif\n\n// PUFFS_VERSION is the major.minor version number as a uint32. The major\n// number is the high 16 bits. The minor number is the low 16 bits.\n//\n// The intention is to bump the version number at least on every API " +
|
"#ifndef PUFFS_BASE_HEADER_H\n#define PUFFS_BASE_HEADER_H\n\n// Use of this source code is governed by a BSD-style license that can be found\n// in the LICENSE file.\n\n#include <stdbool.h>\n#include <stdint.h>\n#include <string.h>\n\n// Puffs requires a word size of at least 32 bits because it assumes that\n// converting a u32 to usize will never overflow. For example, the size of a\n// decoded image is often represented, explicitly or implicitly in an image\n// file, as a u32, and it is convenient to compare that to a buffer size.\n//\n// Similarly, the word size is at most 64 bits because it assumes that\n// converting a usize to u64 will never overflow.\n#if __WORDSIZE < 32\n#error \"Puffs requires a word size of at least 32 bits\"\n#elif __WORDSIZE > 64\n#error \"Puffs requires a word size of at most 64 bits\"\n#endif\n\n// PUFFS_VERSION is the major.minor version number as a uint32. The major\n// number is the high 16 bits. The minor number is the low 16 bits.\n//\n// The intention is to bump the version number at least on every API " +
|
||||||
"/ ABI\n// backwards incompatible change.\n//\n// For now, the API and ABI are simply unstable and can change at any time.\n//\n// TODO: don't hard code this in base-header.h.\n#define PUFFS_VERSION (0x00001)\n\n// puffs_base_buf1 is a 1-dimensional buffer (a pointer and length) plus\n// additional indexes into that buffer.\n//\n// A value with all fields NULL or zero is a valid, empty buffer.\ntypedef struct {\n uint8_t* ptr; // Pointer.\n size_t len; // Length.\n size_t wi; // Write index. Invariant: wi <= len.\n size_t ri; // Read index. Invariant: ri <= wi.\n bool closed; // No further writes are expected.\n} puffs_base_buf1;\n\n#endif // PUFFS_BASE_HEADER_H\n" +
|
"/ ABI\n// backwards incompatible change.\n//\n// For now, the API and ABI are simply unstable and can change at any time.\n//\n// TODO: don't hard code this in base-header.h.\n#define PUFFS_VERSION (0x00001)\n\n// puffs_base_buf1 is a 1-dimensional buffer (a pointer and length) plus\n// additional indexes into that buffer.\n//\n// A value with all fields NULL or zero is a valid, empty buffer.\ntypedef struct {\n uint8_t* ptr; // Pointer.\n size_t len; // Length.\n size_t wi; // Write index. Invariant: wi <= len.\n size_t ri; // Read index. Invariant: ri <= wi.\n bool closed; // No further writes are expected.\n} puffs_base_buf1;\n\ntypedef struct {\n puffs_base_buf1* buf;\n // TODO: limits.\n} puffs_base_reader1;\n\ntypedef struct {\n puffs_base_buf1* buf;\n // TODO: limits.\n} puffs_base_writer1;\n\n#endif // PUFFS_BASE_HEADER_H\n" +
|
||||||
""
|
""
|
||||||
|
|
||||||
const baseImpl = "" +
|
const baseImpl = "" +
|
||||||
|
|||||||
+26
-21
@@ -954,6 +954,8 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: delete these hacks that only matches "in.src.read_u8?()" etc.
|
// TODO: delete these hacks that only matches "in.src.read_u8?()" etc.
|
||||||
|
//
|
||||||
|
// TODO: check reader1.buf and writer1.buf is non-NULL.
|
||||||
if isInSrcReadU8(g.tm, n) {
|
if isInSrcReadU8(g.tm, n) {
|
||||||
if g.perFunc.tempW > maxTemp {
|
if g.perFunc.tempW > maxTemp {
|
||||||
return fmt.Errorf("too many temporary variables required")
|
return fmt.Errorf("too many temporary variables required")
|
||||||
@@ -962,8 +964,8 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error {
|
|||||||
g.perFunc.tempW++
|
g.perFunc.tempW++
|
||||||
|
|
||||||
// TODO: suspend coroutine state.
|
// TODO: suspend coroutine state.
|
||||||
g.printf("if (%ssrc->ri >= %ssrc->wi) { status = "+
|
g.printf("if (%ssrc.buf->ri >= %ssrc.buf->wi) { status = "+
|
||||||
"%ssrc->closed ? puffs_%s_error_unexpected_eof : puffs_%s_status_short_read;",
|
"%ssrc.buf->closed ? puffs_%s_error_unexpected_eof : puffs_%s_status_short_read;",
|
||||||
aPrefix, aPrefix, aPrefix, g.pkgName, g.pkgName)
|
aPrefix, aPrefix, aPrefix, g.pkgName, g.pkgName)
|
||||||
if g.perFunc.public && g.perFunc.suspendible {
|
if g.perFunc.public && g.perFunc.suspendible {
|
||||||
g.writes("goto cleanup0;")
|
g.writes("goto cleanup0;")
|
||||||
@@ -976,20 +978,21 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error {
|
|||||||
if err := g.writeCTypeName(n.MType(), tPrefix, fmt.Sprint(temp)); err != nil {
|
if err := g.writeCTypeName(n.MType(), tPrefix, fmt.Sprint(temp)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
g.printf(" = %ssrc->ptr[%ssrc->ri++];\n", aPrefix, aPrefix)
|
g.printf(" = %ssrc.buf->ptr[%ssrc.buf->ri++];\n", aPrefix, aPrefix)
|
||||||
|
|
||||||
} else if isInDst(g.tm, n, t.KeyWrite) {
|
} else if isInDst(g.tm, n, t.KeyWrite) {
|
||||||
// TODO: suspend coroutine state.
|
// TODO: suspend coroutine state.
|
||||||
//
|
//
|
||||||
// TODO: don't assume that the argument is "this.stack[s:]".
|
// TODO: don't assume that the argument is "this.stack[s:]".
|
||||||
g.printf("if (%sdst->closed) { status = puffs_%s_error_closed_for_writes;", aPrefix, g.pkgName)
|
g.printf("if (%sdst.buf->closed) { status = puffs_%s_error_closed_for_writes;", aPrefix, g.pkgName)
|
||||||
if g.perFunc.public && g.perFunc.suspendible {
|
if g.perFunc.public && g.perFunc.suspendible {
|
||||||
g.writes("goto cleanup0;")
|
g.writes("goto cleanup0;")
|
||||||
} else {
|
} else {
|
||||||
g.writes("return status;")
|
g.writes("return status;")
|
||||||
}
|
}
|
||||||
g.writes("}\n")
|
g.writes("}\n")
|
||||||
g.printf("if ((%sdst->len - %sdst->wi) < (sizeof(self->private_impl.f_stack) - v_s)) {", aPrefix, aPrefix)
|
g.printf("if ((%sdst.buf->len - %sdst.buf->wi) < (sizeof(self->private_impl.f_stack) - v_s)) {",
|
||||||
|
aPrefix, aPrefix)
|
||||||
g.printf("status = puffs_%s_status_short_write;", g.pkgName)
|
g.printf("status = puffs_%s_status_short_write;", g.pkgName)
|
||||||
if g.perFunc.public && g.perFunc.suspendible {
|
if g.perFunc.public && g.perFunc.suspendible {
|
||||||
g.writes("goto cleanup0;")
|
g.writes("goto cleanup0;")
|
||||||
@@ -998,14 +1001,14 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error {
|
|||||||
}
|
}
|
||||||
g.writes("}\n")
|
g.writes("}\n")
|
||||||
g.printf("memmove(" +
|
g.printf("memmove(" +
|
||||||
"a_dst->ptr + a_dst->wi," +
|
"a_dst.buf->ptr + a_dst.buf->wi," +
|
||||||
"self->private_impl.f_stack + v_s," +
|
"self->private_impl.f_stack + v_s," +
|
||||||
"sizeof(self->private_impl.f_stack) - v_s);\n")
|
"sizeof(self->private_impl.f_stack) - v_s);\n")
|
||||||
g.printf("a_dst->wi += sizeof(self->private_impl.f_stack) - v_s;\n")
|
g.printf("a_dst.buf->wi += sizeof(self->private_impl.f_stack) - v_s;\n")
|
||||||
|
|
||||||
} else if isInDst(g.tm, n, t.KeyWriteU8) {
|
} else if isInDst(g.tm, n, t.KeyWriteU8) {
|
||||||
// TODO: suspend coroutine state.
|
// TODO: suspend coroutine state.
|
||||||
g.printf("if (%sdst->wi >= %sdst->len) { status = puffs_%s_status_short_write;",
|
g.printf("if (%sdst.buf->wi >= %sdst.buf->len) { status = puffs_%s_status_short_write;",
|
||||||
aPrefix, aPrefix, g.pkgName)
|
aPrefix, aPrefix, g.pkgName)
|
||||||
if g.perFunc.public && g.perFunc.suspendible {
|
if g.perFunc.public && g.perFunc.suspendible {
|
||||||
g.writes("goto cleanup0;")
|
g.writes("goto cleanup0;")
|
||||||
@@ -1013,7 +1016,7 @@ func (g *gen) writeCallSuspendibles(n *a.Expr, depth uint32) error {
|
|||||||
g.writes("return status;")
|
g.writes("return status;")
|
||||||
}
|
}
|
||||||
g.writes("}\n")
|
g.writes("}\n")
|
||||||
g.printf("%sdst->ptr[%sdst->wi++] = ", aPrefix, aPrefix)
|
g.printf("%sdst.buf->ptr[%sdst.buf->wi++] = ", aPrefix, aPrefix)
|
||||||
x := n.Args()[0].Arg().Value()
|
x := n.Args()[0].Arg().Value()
|
||||||
if err := g.writeExpr(x, replaceCallSuspendibles, parenthesesMandatory, depth); err != nil {
|
if err := g.writeExpr(x, replaceCallSuspendibles, parenthesesMandatory, depth); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -1339,18 +1342,20 @@ var numTypeBounds = [256][2]*big.Int{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var cTypeNames = [...]string{
|
var cTypeNames = [...]string{
|
||||||
t.KeyI8: "int8_t",
|
t.KeyI8: "int8_t",
|
||||||
t.KeyI16: "int16_t",
|
t.KeyI16: "int16_t",
|
||||||
t.KeyI32: "int32_t",
|
t.KeyI32: "int32_t",
|
||||||
t.KeyI64: "int64_t",
|
t.KeyI64: "int64_t",
|
||||||
t.KeyU8: "uint8_t",
|
t.KeyU8: "uint8_t",
|
||||||
t.KeyU16: "uint16_t",
|
t.KeyU16: "uint16_t",
|
||||||
t.KeyU32: "uint32_t",
|
t.KeyU32: "uint32_t",
|
||||||
t.KeyU64: "uint64_t",
|
t.KeyU64: "uint64_t",
|
||||||
t.KeyUsize: "size_t",
|
t.KeyUsize: "size_t",
|
||||||
t.KeyBool: "bool",
|
t.KeyBool: "bool",
|
||||||
t.KeyBuf1: "puffs_base_buf1",
|
t.KeyBuf1: "puffs_base_buf1",
|
||||||
t.KeyBuf2: "puffs_base_buf2",
|
t.KeyBuf2: "puffs_base_buf2",
|
||||||
|
t.KeyReader1: "puffs_base_reader1",
|
||||||
|
t.KeyWriter1: "puffs_base_writer1",
|
||||||
}
|
}
|
||||||
|
|
||||||
var cOpNames = [256]string{
|
var cOpNames = [256]string{
|
||||||
|
|||||||
+52
-50
@@ -49,6 +49,16 @@ typedef struct {
|
|||||||
bool closed; // No further writes are expected.
|
bool closed; // No further writes are expected.
|
||||||
} puffs_base_buf1;
|
} puffs_base_buf1;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
puffs_base_buf1* buf;
|
||||||
|
// TODO: limits.
|
||||||
|
} puffs_base_reader1;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
puffs_base_buf1* buf;
|
||||||
|
// TODO: limits.
|
||||||
|
} puffs_base_writer1;
|
||||||
|
|
||||||
#endif // PUFFS_BASE_HEADER_H
|
#endif // PUFFS_BASE_HEADER_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@@ -145,15 +155,15 @@ void puffs_gif_decoder_destructor(puffs_gif_decoder* self);
|
|||||||
// ---------------- Public Function Prototypes
|
// ---------------- Public Function Prototypes
|
||||||
|
|
||||||
puffs_gif_status puffs_gif_decoder_decode(puffs_gif_decoder* self,
|
puffs_gif_status puffs_gif_decoder_decode(puffs_gif_decoder* self,
|
||||||
puffs_base_buf1* a_dst,
|
puffs_base_writer1 a_dst,
|
||||||
puffs_base_buf1* a_src);
|
puffs_base_reader1 a_src);
|
||||||
|
|
||||||
void puffs_gif_lzw_decoder_set_literal_width(puffs_gif_lzw_decoder* self,
|
void puffs_gif_lzw_decoder_set_literal_width(puffs_gif_lzw_decoder* self,
|
||||||
uint32_t a_lw);
|
uint32_t a_lw);
|
||||||
|
|
||||||
puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
||||||
puffs_base_buf1* a_dst,
|
puffs_base_writer1 a_dst,
|
||||||
puffs_base_buf1* a_src);
|
puffs_base_reader1 a_src);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
@@ -210,10 +220,10 @@ const char* puffs_gif_status_string(puffs_gif_status s) {
|
|||||||
// ---------------- Private Function Prototypes
|
// ---------------- Private Function Prototypes
|
||||||
|
|
||||||
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_buf1* a_src);
|
puffs_base_reader1 a_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_buf1* a_src);
|
puffs_base_reader1 a_src);
|
||||||
|
|
||||||
// ---------------- Constructor and Destructor Implementations
|
// ---------------- Constructor and Destructor Implementations
|
||||||
|
|
||||||
@@ -282,8 +292,8 @@ void puffs_gif_decoder_destructor(puffs_gif_decoder* self) {
|
|||||||
// ---------------- Function Implementations
|
// ---------------- Function Implementations
|
||||||
|
|
||||||
puffs_gif_status puffs_gif_decoder_decode(puffs_gif_decoder* self,
|
puffs_gif_status puffs_gif_decoder_decode(puffs_gif_decoder* self,
|
||||||
puffs_base_buf1* a_dst,
|
puffs_base_writer1 a_dst,
|
||||||
puffs_base_buf1* a_src) {
|
puffs_base_reader1 a_src) {
|
||||||
if (!self) {
|
if (!self) {
|
||||||
return puffs_gif_error_bad_receiver;
|
return puffs_gif_error_bad_receiver;
|
||||||
}
|
}
|
||||||
@@ -295,10 +305,6 @@ puffs_gif_status puffs_gif_decoder_decode(puffs_gif_decoder* self,
|
|||||||
status = puffs_gif_error_constructor_not_called;
|
status = puffs_gif_error_constructor_not_called;
|
||||||
goto cleanup0;
|
goto cleanup0;
|
||||||
}
|
}
|
||||||
if (!a_dst || !a_src) {
|
|
||||||
status = puffs_gif_error_bad_argument;
|
|
||||||
goto cleanup0;
|
|
||||||
}
|
|
||||||
|
|
||||||
status = puffs_gif_decoder_decode_header(self, a_src);
|
status = puffs_gif_decoder_decode_header(self, a_src);
|
||||||
if (status) {
|
if (status) {
|
||||||
@@ -315,7 +321,7 @@ cleanup0:
|
|||||||
}
|
}
|
||||||
|
|
||||||
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_buf1* a_src) {
|
puffs_base_reader1 a_src) {
|
||||||
puffs_gif_status status = self->private_impl.status;
|
puffs_gif_status status = self->private_impl.status;
|
||||||
|
|
||||||
uint8_t v_c[6];
|
uint8_t v_c[6];
|
||||||
@@ -326,12 +332,12 @@ puffs_gif_status puffs_gif_decoder_decode_header(puffs_gif_decoder* self,
|
|||||||
};
|
};
|
||||||
v_i = 0;
|
v_i = 0;
|
||||||
while (v_i < 6) {
|
while (v_i < 6) {
|
||||||
if (a_src->ri >= a_src->wi) {
|
if (a_src.buf->ri >= a_src.buf->wi) {
|
||||||
status = a_src->closed ? puffs_gif_error_unexpected_eof
|
status = a_src.buf->closed ? puffs_gif_error_unexpected_eof
|
||||||
: puffs_gif_status_short_read;
|
: puffs_gif_status_short_read;
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
uint8_t t_0 = a_src->ptr[a_src->ri++];
|
uint8_t t_0 = a_src.buf->ptr[a_src.buf->ri++];
|
||||||
v_c[v_i] = t_0;
|
v_c[v_i] = t_0;
|
||||||
v_i += 1;
|
v_i += 1;
|
||||||
}
|
}
|
||||||
@@ -344,7 +350,7 @@ puffs_gif_status puffs_gif_decoder_decode_header(puffs_gif_decoder* self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
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_buf1* a_src) {
|
puffs_base_reader1 a_src) {
|
||||||
puffs_gif_status status = self->private_impl.status;
|
puffs_gif_status status = self->private_impl.status;
|
||||||
|
|
||||||
uint8_t v_c[7];
|
uint8_t v_c[7];
|
||||||
@@ -356,12 +362,12 @@ puffs_gif_status puffs_gif_decoder_decode_lsd(puffs_gif_decoder* self,
|
|||||||
};
|
};
|
||||||
v_i = 0;
|
v_i = 0;
|
||||||
while (v_i < 7) {
|
while (v_i < 7) {
|
||||||
if (a_src->ri >= a_src->wi) {
|
if (a_src.buf->ri >= a_src.buf->wi) {
|
||||||
status = a_src->closed ? puffs_gif_error_unexpected_eof
|
status = a_src.buf->closed ? puffs_gif_error_unexpected_eof
|
||||||
: puffs_gif_status_short_read;
|
: puffs_gif_status_short_read;
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
uint8_t t_0 = a_src->ptr[a_src->ri++];
|
uint8_t t_0 = a_src.buf->ptr[a_src.buf->ri++];
|
||||||
v_c[v_i] = t_0;
|
v_c[v_i] = t_0;
|
||||||
v_i += 1;
|
v_i += 1;
|
||||||
}
|
}
|
||||||
@@ -374,26 +380,26 @@ puffs_gif_status puffs_gif_decoder_decode_lsd(puffs_gif_decoder* self,
|
|||||||
v_gct_size = (((uint32_t)(1)) << (1 + (v_c[4] & 7)));
|
v_gct_size = (((uint32_t)(1)) << (1 + (v_c[4] & 7)));
|
||||||
v_i = 0;
|
v_i = 0;
|
||||||
while (v_i < v_gct_size) {
|
while (v_i < v_gct_size) {
|
||||||
if (a_src->ri >= a_src->wi) {
|
if (a_src.buf->ri >= a_src.buf->wi) {
|
||||||
status = a_src->closed ? puffs_gif_error_unexpected_eof
|
status = a_src.buf->closed ? puffs_gif_error_unexpected_eof
|
||||||
: puffs_gif_status_short_read;
|
: puffs_gif_status_short_read;
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
uint8_t t_1 = a_src->ptr[a_src->ri++];
|
uint8_t t_1 = a_src.buf->ptr[a_src.buf->ri++];
|
||||||
self->private_impl.f_gct[(3 * v_i) + 0] = t_1;
|
self->private_impl.f_gct[(3 * v_i) + 0] = t_1;
|
||||||
if (a_src->ri >= a_src->wi) {
|
if (a_src.buf->ri >= a_src.buf->wi) {
|
||||||
status = a_src->closed ? puffs_gif_error_unexpected_eof
|
status = a_src.buf->closed ? puffs_gif_error_unexpected_eof
|
||||||
: puffs_gif_status_short_read;
|
: puffs_gif_status_short_read;
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
uint8_t t_2 = a_src->ptr[a_src->ri++];
|
uint8_t t_2 = a_src.buf->ptr[a_src.buf->ri++];
|
||||||
self->private_impl.f_gct[(3 * v_i) + 1] = t_2;
|
self->private_impl.f_gct[(3 * v_i) + 1] = t_2;
|
||||||
if (a_src->ri >= a_src->wi) {
|
if (a_src.buf->ri >= a_src.buf->wi) {
|
||||||
status = a_src->closed ? puffs_gif_error_unexpected_eof
|
status = a_src.buf->closed ? puffs_gif_error_unexpected_eof
|
||||||
: puffs_gif_status_short_read;
|
: puffs_gif_status_short_read;
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
uint8_t t_3 = a_src->ptr[a_src->ri++];
|
uint8_t t_3 = a_src.buf->ptr[a_src.buf->ri++];
|
||||||
self->private_impl.f_gct[(3 * v_i) + 2] = t_3;
|
self->private_impl.f_gct[(3 * v_i) + 2] = t_3;
|
||||||
v_i += 1;
|
v_i += 1;
|
||||||
}
|
}
|
||||||
@@ -423,8 +429,8 @@ void puffs_gif_lzw_decoder_set_literal_width(puffs_gif_lzw_decoder* self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
||||||
puffs_base_buf1* a_dst,
|
puffs_base_writer1 a_dst,
|
||||||
puffs_base_buf1* a_src) {
|
puffs_base_reader1 a_src) {
|
||||||
if (!self) {
|
if (!self) {
|
||||||
return puffs_gif_error_bad_receiver;
|
return puffs_gif_error_bad_receiver;
|
||||||
}
|
}
|
||||||
@@ -436,10 +442,6 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
|||||||
status = puffs_gif_error_constructor_not_called;
|
status = puffs_gif_error_constructor_not_called;
|
||||||
goto cleanup0;
|
goto cleanup0;
|
||||||
}
|
}
|
||||||
if (!a_dst || !a_src) {
|
|
||||||
status = puffs_gif_error_bad_argument;
|
|
||||||
goto cleanup0;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t v_clear_code;
|
uint32_t v_clear_code;
|
||||||
uint32_t v_end_code;
|
uint32_t v_end_code;
|
||||||
@@ -464,12 +466,12 @@ puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
|||||||
label_0_continue:;
|
label_0_continue:;
|
||||||
while (true) {
|
while (true) {
|
||||||
while (v_n_bits < v_width) {
|
while (v_n_bits < v_width) {
|
||||||
if (a_src->ri >= a_src->wi) {
|
if (a_src.buf->ri >= a_src.buf->wi) {
|
||||||
status = a_src->closed ? puffs_gif_error_unexpected_eof
|
status = a_src.buf->closed ? puffs_gif_error_unexpected_eof
|
||||||
: puffs_gif_status_short_read;
|
: 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.buf->ptr[a_src.buf->ri++];
|
||||||
v_bits |= (((uint32_t)(t_0)) << v_n_bits);
|
v_bits |= (((uint32_t)(t_0)) << v_n_bits);
|
||||||
v_n_bits += 8;
|
v_n_bits += 8;
|
||||||
}
|
}
|
||||||
@@ -477,11 +479,11 @@ label_0_continue:;
|
|||||||
v_bits >>= v_width;
|
v_bits >>= v_width;
|
||||||
v_n_bits -= v_width;
|
v_n_bits -= v_width;
|
||||||
if (v_code < v_clear_code) {
|
if (v_code < v_clear_code) {
|
||||||
if (a_dst->wi >= a_dst->len) {
|
if (a_dst.buf->wi >= a_dst.buf->len) {
|
||||||
status = puffs_gif_status_short_write;
|
status = puffs_gif_status_short_write;
|
||||||
goto cleanup0;
|
goto cleanup0;
|
||||||
}
|
}
|
||||||
a_dst->ptr[a_dst->wi++] = ((uint8_t)(v_code));
|
a_dst.buf->ptr[a_dst.buf->wi++] = ((uint8_t)(v_code));
|
||||||
if (v_use_save_code) {
|
if (v_use_save_code) {
|
||||||
self->private_impl.f_suffixes[v_save_code] = ((uint8_t)(v_code));
|
self->private_impl.f_suffixes[v_save_code] = ((uint8_t)(v_code));
|
||||||
self->private_impl.f_prefixes[v_save_code] = ((uint16_t)(v_prev_code));
|
self->private_impl.f_prefixes[v_save_code] = ((uint16_t)(v_prev_code));
|
||||||
@@ -515,18 +517,18 @@ label_0_continue:;
|
|||||||
if ((v_code == v_save_code) && v_use_save_code) {
|
if ((v_code == v_save_code) && v_use_save_code) {
|
||||||
self->private_impl.f_stack[4095] = ((uint8_t)(v_c));
|
self->private_impl.f_stack[4095] = ((uint8_t)(v_c));
|
||||||
}
|
}
|
||||||
if (a_dst->closed) {
|
if (a_dst.buf->closed) {
|
||||||
status = puffs_gif_error_closed_for_writes;
|
status = puffs_gif_error_closed_for_writes;
|
||||||
goto cleanup0;
|
goto cleanup0;
|
||||||
}
|
}
|
||||||
if ((a_dst->len - a_dst->wi) <
|
if ((a_dst.buf->len - a_dst.buf->wi) <
|
||||||
(sizeof(self->private_impl.f_stack) - v_s)) {
|
(sizeof(self->private_impl.f_stack) - v_s)) {
|
||||||
status = puffs_gif_status_short_write;
|
status = puffs_gif_status_short_write;
|
||||||
goto cleanup0;
|
goto cleanup0;
|
||||||
}
|
}
|
||||||
memmove(a_dst->ptr + a_dst->wi, self->private_impl.f_stack + v_s,
|
memmove(a_dst.buf->ptr + a_dst.buf->wi, self->private_impl.f_stack + v_s,
|
||||||
sizeof(self->private_impl.f_stack) - v_s);
|
sizeof(self->private_impl.f_stack) - v_s);
|
||||||
a_dst->wi += sizeof(self->private_impl.f_stack) - v_s;
|
a_dst.buf->wi += sizeof(self->private_impl.f_stack) - v_s;
|
||||||
if (v_use_save_code) {
|
if (v_use_save_code) {
|
||||||
self->private_impl.f_suffixes[v_save_code] = ((uint8_t)(v_c));
|
self->private_impl.f_suffixes[v_save_code] = ((uint8_t)(v_c));
|
||||||
self->private_impl.f_prefixes[v_save_code] = ((uint16_t)(v_prev_code));
|
self->private_impl.f_prefixes[v_save_code] = ((uint16_t)(v_prev_code));
|
||||||
|
|||||||
+14
-4
@@ -49,6 +49,16 @@ typedef struct {
|
|||||||
bool closed; // No further writes are expected.
|
bool closed; // No further writes are expected.
|
||||||
} puffs_base_buf1;
|
} puffs_base_buf1;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
puffs_base_buf1* buf;
|
||||||
|
// TODO: limits.
|
||||||
|
} puffs_base_reader1;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
puffs_base_buf1* buf;
|
||||||
|
// TODO: limits.
|
||||||
|
} puffs_base_writer1;
|
||||||
|
|
||||||
#endif // PUFFS_BASE_HEADER_H
|
#endif // PUFFS_BASE_HEADER_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@@ -145,15 +155,15 @@ void puffs_gif_decoder_destructor(puffs_gif_decoder* self);
|
|||||||
// ---------------- Public Function Prototypes
|
// ---------------- Public Function Prototypes
|
||||||
|
|
||||||
puffs_gif_status puffs_gif_decoder_decode(puffs_gif_decoder* self,
|
puffs_gif_status puffs_gif_decoder_decode(puffs_gif_decoder* self,
|
||||||
puffs_base_buf1* a_dst,
|
puffs_base_writer1 a_dst,
|
||||||
puffs_base_buf1* a_src);
|
puffs_base_reader1 a_src);
|
||||||
|
|
||||||
void puffs_gif_lzw_decoder_set_literal_width(puffs_gif_lzw_decoder* self,
|
void puffs_gif_lzw_decoder_set_literal_width(puffs_gif_lzw_decoder* self,
|
||||||
uint32_t a_lw);
|
uint32_t a_lw);
|
||||||
|
|
||||||
puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
puffs_gif_status puffs_gif_lzw_decoder_decode(puffs_gif_lzw_decoder* self,
|
||||||
puffs_base_buf1* a_dst,
|
puffs_base_writer1 a_dst,
|
||||||
puffs_base_buf1* a_src);
|
puffs_base_reader1 a_src);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|||||||
@@ -852,6 +852,10 @@ func (q *checker) bcheckTypeExpr(n *a.TypeExpr) (*big.Int, *big.Int, error) {
|
|||||||
case t.KeyPtr, t.KeyOpenBracket:
|
case t.KeyPtr, t.KeyOpenBracket:
|
||||||
return nil, nil, nil
|
return nil, nil, nil
|
||||||
}
|
}
|
||||||
|
switch n.Name().Key() {
|
||||||
|
case t.KeyReader1, t.KeyWriter1:
|
||||||
|
return nil, nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
b := [2]*big.Int{}
|
b := [2]*big.Int{}
|
||||||
if key := n.Name().Key(); key < t.Key(len(numTypeBounds)) {
|
if key := n.Name().Key(); key < t.Key(len(numTypeBounds)) {
|
||||||
|
|||||||
+3
-3
@@ -467,9 +467,9 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
|
|||||||
s = q.f.Func.In()
|
s = q.f.Func.In()
|
||||||
case t.KeyOut:
|
case t.KeyOut:
|
||||||
s = q.f.Func.Out()
|
s = q.f.Func.Out()
|
||||||
case t.KeyBuf1:
|
case t.KeyReader1, t.KeyWriter1:
|
||||||
// TODO: remove this hack and be more principled about the built-in
|
// TODO: remove this hack and be more principled about the built-in
|
||||||
// buf1 type.
|
// buf1, reader1, writer1 types.
|
||||||
//
|
//
|
||||||
// Another hack is using typeExprPlaceholder until a TypeExpr can
|
// Another hack is using typeExprPlaceholder until a TypeExpr can
|
||||||
// represent function types.
|
// represent function types.
|
||||||
@@ -730,7 +730,7 @@ swtch:
|
|||||||
if n.Min() != nil || n.Max() != nil {
|
if n.Min() != nil || n.Max() != nil {
|
||||||
// TODO: reject. You can only refine numeric types.
|
// TODO: reject. You can only refine numeric types.
|
||||||
}
|
}
|
||||||
if name := n.Name().Key(); name == t.KeyBool || name == t.KeyBuf1 {
|
if name := n.Name().Key(); name == t.KeyBool || name == t.KeyReader1 || name == t.KeyWriter1 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
for _, s := range q.c.structs {
|
for _, s := range q.c.structs {
|
||||||
|
|||||||
+42
-36
@@ -214,18 +214,20 @@ const (
|
|||||||
KeyTrue = Key(IDTrue >> KeyShift)
|
KeyTrue = Key(IDTrue >> KeyShift)
|
||||||
KeyZero = Key(IDZero >> KeyShift)
|
KeyZero = Key(IDZero >> KeyShift)
|
||||||
|
|
||||||
KeyI8 = Key(IDI8 >> KeyShift)
|
KeyI8 = Key(IDI8 >> KeyShift)
|
||||||
KeyI16 = Key(IDI16 >> KeyShift)
|
KeyI16 = Key(IDI16 >> KeyShift)
|
||||||
KeyI32 = Key(IDI32 >> KeyShift)
|
KeyI32 = Key(IDI32 >> KeyShift)
|
||||||
KeyI64 = Key(IDI64 >> KeyShift)
|
KeyI64 = Key(IDI64 >> KeyShift)
|
||||||
KeyU8 = Key(IDU8 >> KeyShift)
|
KeyU8 = Key(IDU8 >> KeyShift)
|
||||||
KeyU16 = Key(IDU16 >> KeyShift)
|
KeyU16 = Key(IDU16 >> KeyShift)
|
||||||
KeyU32 = Key(IDU32 >> KeyShift)
|
KeyU32 = Key(IDU32 >> KeyShift)
|
||||||
KeyU64 = Key(IDU64 >> KeyShift)
|
KeyU64 = Key(IDU64 >> KeyShift)
|
||||||
KeyUsize = Key(IDUsize >> KeyShift)
|
KeyUsize = Key(IDUsize >> KeyShift)
|
||||||
KeyBool = Key(IDBool >> KeyShift)
|
KeyBool = Key(IDBool >> KeyShift)
|
||||||
KeyBuf1 = Key(IDBuf1 >> KeyShift)
|
KeyBuf1 = Key(IDBuf1 >> KeyShift)
|
||||||
KeyBuf2 = Key(IDBuf2 >> KeyShift)
|
KeyBuf2 = Key(IDBuf2 >> KeyShift)
|
||||||
|
KeyReader1 = Key(IDReader1 >> KeyShift)
|
||||||
|
KeyWriter1 = Key(IDWriter1 >> KeyShift)
|
||||||
|
|
||||||
KeyUnderscore = Key(IDUnderscore >> KeyShift)
|
KeyUnderscore = Key(IDUnderscore >> KeyShift)
|
||||||
KeyThis = Key(IDThis >> KeyShift)
|
KeyThis = Key(IDThis >> KeyShift)
|
||||||
@@ -366,18 +368,20 @@ const (
|
|||||||
IDTrue = ID(0x81<<KeyShift | FlagsLiteral | FlagsImplicitSemicolon)
|
IDTrue = ID(0x81<<KeyShift | FlagsLiteral | FlagsImplicitSemicolon)
|
||||||
IDZero = ID(0x82<<KeyShift | FlagsLiteral | FlagsImplicitSemicolon | FlagsNumLiteral)
|
IDZero = ID(0x82<<KeyShift | FlagsLiteral | FlagsImplicitSemicolon | FlagsNumLiteral)
|
||||||
|
|
||||||
IDI8 = ID(0x90<<KeyShift | FlagsIdent | FlagsImplicitSemicolon | FlagsNumType)
|
IDI8 = ID(0x90<<KeyShift | FlagsIdent | FlagsImplicitSemicolon | FlagsNumType)
|
||||||
IDI16 = ID(0x91<<KeyShift | FlagsIdent | FlagsImplicitSemicolon | FlagsNumType)
|
IDI16 = ID(0x91<<KeyShift | FlagsIdent | FlagsImplicitSemicolon | FlagsNumType)
|
||||||
IDI32 = ID(0x92<<KeyShift | FlagsIdent | FlagsImplicitSemicolon | FlagsNumType)
|
IDI32 = ID(0x92<<KeyShift | FlagsIdent | FlagsImplicitSemicolon | FlagsNumType)
|
||||||
IDI64 = ID(0x93<<KeyShift | FlagsIdent | FlagsImplicitSemicolon | FlagsNumType)
|
IDI64 = ID(0x93<<KeyShift | FlagsIdent | FlagsImplicitSemicolon | FlagsNumType)
|
||||||
IDU8 = ID(0x94<<KeyShift | FlagsIdent | FlagsImplicitSemicolon | FlagsNumType)
|
IDU8 = ID(0x94<<KeyShift | FlagsIdent | FlagsImplicitSemicolon | FlagsNumType)
|
||||||
IDU16 = ID(0x95<<KeyShift | FlagsIdent | FlagsImplicitSemicolon | FlagsNumType)
|
IDU16 = ID(0x95<<KeyShift | FlagsIdent | FlagsImplicitSemicolon | FlagsNumType)
|
||||||
IDU32 = ID(0x96<<KeyShift | FlagsIdent | FlagsImplicitSemicolon | FlagsNumType)
|
IDU32 = ID(0x96<<KeyShift | FlagsIdent | FlagsImplicitSemicolon | FlagsNumType)
|
||||||
IDU64 = ID(0x97<<KeyShift | FlagsIdent | FlagsImplicitSemicolon | FlagsNumType)
|
IDU64 = ID(0x97<<KeyShift | FlagsIdent | FlagsImplicitSemicolon | FlagsNumType)
|
||||||
IDUsize = ID(0x98<<KeyShift | FlagsIdent | FlagsImplicitSemicolon | FlagsNumType)
|
IDUsize = ID(0x98<<KeyShift | FlagsIdent | FlagsImplicitSemicolon | FlagsNumType)
|
||||||
IDBool = ID(0x99<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
IDBool = ID(0x99<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
IDBuf1 = ID(0x9A<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
IDBuf1 = ID(0x9A<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
IDBuf2 = ID(0x9B<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
IDBuf2 = ID(0x9B<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
|
IDReader1 = ID(0x9C<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
|
IDWriter1 = ID(0x9D<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
|
|
||||||
IDUnderscore = ID(0xA0<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
IDUnderscore = ID(0xA0<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
IDThis = ID(0xA1<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
IDThis = ID(0xA1<<KeyShift | FlagsIdent | FlagsImplicitSemicolon)
|
||||||
@@ -540,18 +544,20 @@ var builtInsByKey = [nBuiltInKeys]struct {
|
|||||||
|
|
||||||
// Change MaxIntBits if a future update adds an i128 or u128 type.
|
// Change MaxIntBits if a future update adds an i128 or u128 type.
|
||||||
|
|
||||||
KeyI8: {"i8", IDI8},
|
KeyI8: {"i8", IDI8},
|
||||||
KeyI16: {"i16", IDI16},
|
KeyI16: {"i16", IDI16},
|
||||||
KeyI32: {"i32", IDI32},
|
KeyI32: {"i32", IDI32},
|
||||||
KeyI64: {"i64", IDI64},
|
KeyI64: {"i64", IDI64},
|
||||||
KeyU8: {"u8", IDU8},
|
KeyU8: {"u8", IDU8},
|
||||||
KeyU16: {"u16", IDU16},
|
KeyU16: {"u16", IDU16},
|
||||||
KeyU32: {"u32", IDU32},
|
KeyU32: {"u32", IDU32},
|
||||||
KeyU64: {"u64", IDU64},
|
KeyU64: {"u64", IDU64},
|
||||||
KeyUsize: {"usize", IDUsize},
|
KeyUsize: {"usize", IDUsize},
|
||||||
KeyBool: {"bool", IDBool},
|
KeyBool: {"bool", IDBool},
|
||||||
KeyBuf1: {"buf1", IDBuf1},
|
KeyBuf1: {"buf1", IDBuf1},
|
||||||
KeyBuf2: {"buf2", IDBuf2},
|
KeyBuf2: {"buf2", IDBuf2},
|
||||||
|
KeyReader1: {"reader1", IDReader1},
|
||||||
|
KeyWriter1: {"writer1", IDWriter1},
|
||||||
|
|
||||||
KeyUnderscore: {"_", IDUnderscore},
|
KeyUnderscore: {"_", IDUnderscore},
|
||||||
KeyThis: {"this", IDThis},
|
KeyThis: {"this", IDThis},
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ pub struct decoder?(
|
|||||||
lzw lzw_decoder,
|
lzw lzw_decoder,
|
||||||
)
|
)
|
||||||
|
|
||||||
pub func decoder.decode?(dst ptr buf1, src ptr buf1)() {
|
pub func decoder.decode?(dst writer1, src reader1)() {
|
||||||
this.decode_header?(src:in.src)
|
this.decode_header?(src:in.src)
|
||||||
this.decode_lsd?(src:in.src)
|
this.decode_lsd?(src:in.src)
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,7 @@ pub func decoder.decode?(dst ptr buf1, src ptr buf1)() {
|
|||||||
// decode_header reads either "GIF87a" or "GIF89a".
|
// decode_header reads either "GIF87a" or "GIF89a".
|
||||||
//
|
//
|
||||||
// See the spec section 17 "Header" on page 7.
|
// See the spec section 17 "Header" on page 7.
|
||||||
pri func decoder.decode_header?(src ptr buf1)() {
|
pri func decoder.decode_header?(src reader1)() {
|
||||||
var c[6] u8
|
var c[6] u8
|
||||||
var i u32
|
var i u32
|
||||||
while i < 6 {
|
while i < 6 {
|
||||||
@@ -40,7 +40,7 @@ pri func decoder.decode_header?(src ptr buf1)() {
|
|||||||
// decode_lsd reads the Logical Screen Descriptor.
|
// decode_lsd reads the Logical Screen Descriptor.
|
||||||
//
|
//
|
||||||
// See the spec section 18 "Logical Screen Descriptor" on page 8.
|
// See the spec section 18 "Logical Screen Descriptor" on page 8.
|
||||||
pri func decoder.decode_lsd?(src ptr buf1)() {
|
pri func decoder.decode_lsd?(src reader1)() {
|
||||||
var c[7] u8
|
var c[7] u8
|
||||||
var i u32
|
var i u32
|
||||||
while i < 7 {
|
while i < 7 {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ pub func lzw_decoder.set_literal_width(lw u32[2..8] = 8)() {
|
|||||||
this.literal_width = in.lw
|
this.literal_width = in.lw
|
||||||
}
|
}
|
||||||
|
|
||||||
pub func lzw_decoder.decode?(dst ptr buf1, src ptr buf1)() {
|
pub func lzw_decoder.decode?(dst writer1, src reader1)() {
|
||||||
// These variables don't change over the lifetime of this func.
|
// These variables don't change over the lifetime of this func.
|
||||||
var clear_code u32[4..256] = (1 as u32) << this.literal_width
|
var clear_code u32[4..256] = (1 as u32) << this.literal_width
|
||||||
var end_code u32[5..257] = clear_code + 1
|
var end_code u32[5..257] = clear_code + 1
|
||||||
|
|||||||
+13
-19
@@ -26,16 +26,6 @@ uint8_t global_palette_buffer[3 * 256];
|
|||||||
|
|
||||||
// ---------------- Basic Tests
|
// ---------------- Basic Tests
|
||||||
|
|
||||||
void test_basic_bad_argument_null() {
|
|
||||||
test_funcname = __func__;
|
|
||||||
puffs_gif_lzw_decoder dec;
|
|
||||||
puffs_gif_lzw_decoder_constructor(&dec, PUFFS_VERSION, 0);
|
|
||||||
puffs_gif_status status = puffs_gif_lzw_decoder_decode(&dec, NULL, NULL);
|
|
||||||
if (status != puffs_gif_error_bad_argument) {
|
|
||||||
FAIL("status: got %d, want %d", status, puffs_gif_error_bad_argument);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_basic_bad_argument_out_of_range() {
|
void test_basic_bad_argument_out_of_range() {
|
||||||
test_funcname = __func__;
|
test_funcname = __func__;
|
||||||
puffs_gif_lzw_decoder dec;
|
puffs_gif_lzw_decoder dec;
|
||||||
@@ -65,9 +55,9 @@ void test_basic_bad_argument_out_of_range() {
|
|||||||
|
|
||||||
void test_basic_bad_receiver() {
|
void test_basic_bad_receiver() {
|
||||||
test_funcname = __func__;
|
test_funcname = __func__;
|
||||||
puffs_base_buf1 dst = {0};
|
puffs_base_writer1 dst = {0};
|
||||||
puffs_base_buf1 src = {0};
|
puffs_base_reader1 src = {0};
|
||||||
puffs_gif_status status = puffs_gif_lzw_decoder_decode(NULL, &dst, &src);
|
puffs_gif_status status = puffs_gif_lzw_decoder_decode(NULL, dst, src);
|
||||||
if (status != puffs_gif_error_bad_receiver) {
|
if (status != puffs_gif_error_bad_receiver) {
|
||||||
FAIL("status: got %d, want %d", status, puffs_gif_error_bad_receiver);
|
FAIL("status: got %d, want %d", status, puffs_gif_error_bad_receiver);
|
||||||
}
|
}
|
||||||
@@ -76,9 +66,9 @@ void test_basic_bad_receiver() {
|
|||||||
void test_basic_constructor_not_called() {
|
void test_basic_constructor_not_called() {
|
||||||
test_funcname = __func__;
|
test_funcname = __func__;
|
||||||
puffs_gif_lzw_decoder dec = {{0}};
|
puffs_gif_lzw_decoder dec = {{0}};
|
||||||
puffs_base_buf1 dst = {0};
|
puffs_base_writer1 dst = {0};
|
||||||
puffs_base_buf1 src = {0};
|
puffs_base_reader1 src = {0};
|
||||||
puffs_gif_status status = puffs_gif_lzw_decoder_decode(&dec, &dst, &src);
|
puffs_gif_status status = puffs_gif_lzw_decoder_decode(&dec, dst, src);
|
||||||
if (status != puffs_gif_error_constructor_not_called) {
|
if (status != puffs_gif_error_constructor_not_called) {
|
||||||
FAIL("status: got %d, want %d", status,
|
FAIL("status: got %d, want %d", status,
|
||||||
puffs_gif_error_constructor_not_called);
|
puffs_gif_error_constructor_not_called);
|
||||||
@@ -224,7 +214,10 @@ void test_lzw_decode() {
|
|||||||
puffs_gif_lzw_decoder dec;
|
puffs_gif_lzw_decoder dec;
|
||||||
puffs_gif_lzw_decoder_constructor(&dec, PUFFS_VERSION, 0);
|
puffs_gif_lzw_decoder_constructor(&dec, PUFFS_VERSION, 0);
|
||||||
puffs_gif_lzw_decoder_set_literal_width(&dec, literal_width);
|
puffs_gif_lzw_decoder_set_literal_width(&dec, literal_width);
|
||||||
puffs_gif_status status = puffs_gif_lzw_decoder_decode(&dec, &got, &src);
|
puffs_base_writer1 got_writer = {.buf = &got};
|
||||||
|
puffs_base_reader1 src_reader = {.buf = &src};
|
||||||
|
puffs_gif_status status =
|
||||||
|
puffs_gif_lzw_decoder_decode(&dec, got_writer, src_reader);
|
||||||
if (status != puffs_gif_status_ok) {
|
if (status != puffs_gif_status_ok) {
|
||||||
FAIL("status: got %d, want %d", status, puffs_gif_status_ok);
|
FAIL("status: got %d, want %d", status, puffs_gif_status_ok);
|
||||||
goto cleanup1;
|
goto cleanup1;
|
||||||
@@ -259,7 +252,9 @@ void test_gif_decode_input_is_a_xxx(const char* filename,
|
|||||||
|
|
||||||
puffs_gif_decoder dec;
|
puffs_gif_decoder dec;
|
||||||
puffs_gif_decoder_constructor(&dec, PUFFS_VERSION, 0);
|
puffs_gif_decoder_constructor(&dec, PUFFS_VERSION, 0);
|
||||||
puffs_gif_status got = puffs_gif_decoder_decode(&dec, &dst, &src);
|
puffs_base_writer1 dst_writer = {.buf = &dst};
|
||||||
|
puffs_base_reader1 src_reader = {.buf = &src};
|
||||||
|
puffs_gif_status got = puffs_gif_decoder_decode(&dec, dst_writer, src_reader);
|
||||||
if (got != want) {
|
if (got != want) {
|
||||||
FAIL("status: got %d, want %d", got, want);
|
FAIL("status: got %d, want %d", got, want);
|
||||||
goto cleanup1;
|
goto cleanup1;
|
||||||
@@ -313,7 +308,6 @@ void test_gif_decode_input_is_a_png() {
|
|||||||
// The empty comments forces clang-format to place one element per line.
|
// The empty comments forces clang-format to place one element per line.
|
||||||
test tests[] = {
|
test tests[] = {
|
||||||
// Basic Tests
|
// Basic Tests
|
||||||
test_basic_bad_argument_null, //
|
|
||||||
test_basic_bad_argument_out_of_range, //
|
test_basic_bad_argument_out_of_range, //
|
||||||
test_basic_bad_receiver, //
|
test_basic_bad_receiver, //
|
||||||
test_basic_constructor_not_called, //
|
test_basic_constructor_not_called, //
|
||||||
|
|||||||
Reference in new issue
Block a user