mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
Follow the pkg__type__method convention for base.
This commit is contained in:
1 parent
362bb94e68
commit
f29c4e278f
19 files changed
+747
-734
No files matched your search
@@ -45,15 +45,15 @@
|
||||
// TODO: don't hard code this in base-header.h.
|
||||
#define PUFFS_VERSION (0x00001)
|
||||
|
||||
// puffs_base_slice_u8 is a 1-dimensional buffer (a pointer and length).
|
||||
// puffs_base__slice_u8 is a 1-dimensional buffer (a pointer and length).
|
||||
//
|
||||
// A value with all fields NULL or zero is a valid, empty slice.
|
||||
typedef struct {
|
||||
uint8_t* ptr;
|
||||
size_t len;
|
||||
} puffs_base_slice_u8;
|
||||
} puffs_base__slice_u8;
|
||||
|
||||
// puffs_base_buf1 is a 1-dimensional buffer (a pointer and length), plus
|
||||
// puffs_base__buf1 is a 1-dimensional buffer (a pointer and length), plus
|
||||
// additional indexes into that buffer, plus an opened / closed flag.
|
||||
//
|
||||
// A value with all fields NULL or zero is a valid, empty buffer.
|
||||
@@ -63,27 +63,27 @@ typedef struct {
|
||||
size_t wi; // Write index. Invariant: wi <= len.
|
||||
size_t ri; // Read index. Invariant: ri <= wi.
|
||||
bool closed; // No further writes are expected.
|
||||
} puffs_base_buf1;
|
||||
} puffs_base__buf1;
|
||||
|
||||
// puffs_base_limit1 provides a limited view of a 1-dimensional byte stream:
|
||||
// puffs_base__limit1 provides a limited view of a 1-dimensional byte stream:
|
||||
// its first N bytes. That N can be greater than a buffer's current read or
|
||||
// write capacity. N decreases naturally over time as bytes are read from or
|
||||
// written to the stream.
|
||||
//
|
||||
// A value with all fields NULL or zero is a valid, unlimited view.
|
||||
typedef struct puffs_base_limit1 {
|
||||
uint64_t* ptr_to_len; // Pointer to N.
|
||||
struct puffs_base_limit1* next; // Linked list of limits.
|
||||
} puffs_base_limit1;
|
||||
typedef struct puffs_base__limit1 {
|
||||
uint64_t* ptr_to_len; // Pointer to N.
|
||||
struct puffs_base__limit1* next; // Linked list of limits.
|
||||
} puffs_base__limit1;
|
||||
|
||||
typedef struct {
|
||||
puffs_base_buf1* buf;
|
||||
puffs_base_limit1 limit;
|
||||
} puffs_base_reader1;
|
||||
puffs_base__buf1* buf;
|
||||
puffs_base__limit1 limit;
|
||||
} puffs_base__reader1;
|
||||
|
||||
typedef struct {
|
||||
puffs_base_buf1* buf;
|
||||
puffs_base_limit1 limit;
|
||||
} puffs_base_writer1;
|
||||
puffs_base__buf1* buf;
|
||||
puffs_base__limit1 limit;
|
||||
} puffs_base__writer1;
|
||||
|
||||
#endif // PUFFS_BASE_HEADER_H
|
||||
@@ -17,51 +17,51 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#define PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(x) (void)(x)
|
||||
#define PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(x) (void)(x)
|
||||
|
||||
// PUFFS_MAGIC is a magic number to check that initializers are called. It's
|
||||
// not foolproof, given C doesn't automatically zero memory before use, but it
|
||||
// should catch 99.99% of cases.
|
||||
// PUFFS_BASE__MAGIC is a magic number to check that initializers are called.
|
||||
// It's not foolproof, given C doesn't automatically zero memory before use,
|
||||
// but it should catch 99.99% of cases.
|
||||
//
|
||||
// Its (non-zero) value is arbitrary, based on md5sum("puffs").
|
||||
#define PUFFS_MAGIC (0xCB3699CCU)
|
||||
#define PUFFS_BASE__MAGIC (0xCB3699CCU)
|
||||
|
||||
// PUFFS_ALREADY_ZEROED is passed from a container struct's initializer to a
|
||||
// containee struct's initializer when the container has already zeroed the
|
||||
// containee's memory.
|
||||
// PUFFS_BASE__ALREADY_ZEROED is passed from a container struct's initializer
|
||||
// to a containee struct's initializer when the container has already zeroed
|
||||
// the containee's memory.
|
||||
//
|
||||
// Its (non-zero) value is arbitrary, based on md5sum("zeroed").
|
||||
#define PUFFS_ALREADY_ZEROED (0x68602EF1U)
|
||||
#define PUFFS_BASE__ALREADY_ZEROED (0x68602EF1U)
|
||||
|
||||
// Use switch cases for coroutine suspension points, similar to the technique
|
||||
// in https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
|
||||
//
|
||||
// We use a trivial macro instead of an explicit assignment and case statement
|
||||
// so that clang-format doesn't get confused by the unusual "case"s.
|
||||
#define PUFFS_COROUTINE_SUSPENSION_POINT(n) \
|
||||
coro_susp_point = n; \
|
||||
#define PUFFS_BASE__COROUTINE_SUSPENSION_POINT(n) \
|
||||
coro_susp_point = n; \
|
||||
case n:;
|
||||
|
||||
#define PUFFS_COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \
|
||||
if (status < 0) { \
|
||||
goto exit; \
|
||||
} else if (status == 0) { \
|
||||
goto ok; \
|
||||
} \
|
||||
coro_susp_point = n; \
|
||||
goto suspend; \
|
||||
#define PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \
|
||||
if (status < 0) { \
|
||||
goto exit; \
|
||||
} else if (status == 0) { \
|
||||
goto ok; \
|
||||
} \
|
||||
coro_susp_point = n; \
|
||||
goto suspend; \
|
||||
case n:;
|
||||
|
||||
// Clang also defines "__GNUC__".
|
||||
#if defined(__GNUC__)
|
||||
#define PUFFS_LIKELY(expr) (__builtin_expect(!!(expr), 1))
|
||||
#define PUFFS_UNLIKELY(expr) (__builtin_expect(!!(expr), 0))
|
||||
#define PUFFS_BASE__LIKELY(expr) (__builtin_expect(!!(expr), 1))
|
||||
#define PUFFS_BASE__UNLIKELY(expr) (__builtin_expect(!!(expr), 0))
|
||||
// Declare the printf prototype. The generated code shouldn't need this at all,
|
||||
// but it's useful for manual printf debugging.
|
||||
extern int printf(const char* __restrict __format, ...);
|
||||
#else
|
||||
#define PUFFS_LIKELY(expr) (expr)
|
||||
#define PUFFS_UNLIKELY(expr) (expr)
|
||||
#define PUFFS_BASE__LIKELY(expr) (expr)
|
||||
#define PUFFS_BASE__UNLIKELY(expr) (expr)
|
||||
#endif
|
||||
|
||||
// ---------------- Static Inline Functions
|
||||
@@ -82,59 +82,61 @@ extern int printf(const char* __restrict __format, ...);
|
||||
// inline attribute to guide optimizations such as inlining, to avoid the
|
||||
// -Wunused-function warning, and we like to compile with -Wall -Werror.
|
||||
|
||||
static inline uint16_t puffs_base_load_u16be(uint8_t* p) {
|
||||
static inline uint16_t puffs_base__load_u16be(uint8_t* p) {
|
||||
return ((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0);
|
||||
}
|
||||
|
||||
static inline uint16_t puffs_base_load_u16le(uint8_t* p) {
|
||||
static inline uint16_t puffs_base__load_u16le(uint8_t* p) {
|
||||
return ((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8);
|
||||
}
|
||||
|
||||
static inline uint32_t puffs_base_load_u32be(uint8_t* p) {
|
||||
static inline uint32_t puffs_base__load_u32be(uint8_t* p) {
|
||||
return ((uint32_t)(p[0]) << 24) | ((uint32_t)(p[1]) << 16) |
|
||||
((uint32_t)(p[2]) << 8) | ((uint32_t)(p[3]) << 0);
|
||||
}
|
||||
|
||||
static inline uint32_t puffs_base_load_u32le(uint8_t* p) {
|
||||
static inline uint32_t puffs_base__load_u32le(uint8_t* p) {
|
||||
return ((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) |
|
||||
((uint32_t)(p[2]) << 16) | ((uint32_t)(p[3]) << 24);
|
||||
}
|
||||
|
||||
static inline puffs_base_slice_u8 puffs_base_slice_u8_subslice_i(
|
||||
puffs_base_slice_u8 s,
|
||||
static inline puffs_base__slice_u8 puffs_base__slice_u8__subslice_i(
|
||||
puffs_base__slice_u8 s,
|
||||
uint64_t i) {
|
||||
if ((i <= SIZE_MAX) && (i <= s.len)) {
|
||||
return ((puffs_base_slice_u8){
|
||||
return ((puffs_base__slice_u8){
|
||||
.ptr = s.ptr + i,
|
||||
.len = s.len - i,
|
||||
});
|
||||
}
|
||||
return ((puffs_base_slice_u8){});
|
||||
return ((puffs_base__slice_u8){});
|
||||
}
|
||||
|
||||
static inline puffs_base_slice_u8 puffs_base_slice_u8_subslice_j(
|
||||
puffs_base_slice_u8 s,
|
||||
static inline puffs_base__slice_u8 puffs_base__slice_u8__subslice_j(
|
||||
puffs_base__slice_u8 s,
|
||||
uint64_t j) {
|
||||
if ((j <= SIZE_MAX) && (j <= s.len)) {
|
||||
return ((puffs_base_slice_u8){.ptr = s.ptr, .len = j});
|
||||
return ((puffs_base__slice_u8){.ptr = s.ptr, .len = j});
|
||||
}
|
||||
return ((puffs_base_slice_u8){});
|
||||
return ((puffs_base__slice_u8){});
|
||||
}
|
||||
|
||||
static inline puffs_base_slice_u8
|
||||
puffs_base_slice_u8_subslice_ij(puffs_base_slice_u8 s, uint64_t i, uint64_t j) {
|
||||
static inline puffs_base__slice_u8 puffs_base__slice_u8__subslice_ij(
|
||||
puffs_base__slice_u8 s,
|
||||
uint64_t i,
|
||||
uint64_t j) {
|
||||
if ((i <= j) && (j <= SIZE_MAX) && (j <= s.len)) {
|
||||
return ((puffs_base_slice_u8){
|
||||
return ((puffs_base__slice_u8){
|
||||
.ptr = s.ptr + i,
|
||||
.len = j - i,
|
||||
});
|
||||
}
|
||||
return ((puffs_base_slice_u8){});
|
||||
return ((puffs_base__slice_u8){});
|
||||
}
|
||||
|
||||
// puffs_base_slice_u8_prefix returns up to the first up_to bytes of s.
|
||||
static inline puffs_base_slice_u8 puffs_base_slice_u8_prefix(
|
||||
puffs_base_slice_u8 s,
|
||||
// puffs_base__slice_u8__prefix returns up to the first up_to bytes of s.
|
||||
static inline puffs_base__slice_u8 puffs_base__slice_u8__prefix(
|
||||
puffs_base__slice_u8 s,
|
||||
uint64_t up_to) {
|
||||
if ((uint64_t)(s.len) > up_to) {
|
||||
s.len = up_to;
|
||||
@@ -142,9 +144,9 @@ static inline puffs_base_slice_u8 puffs_base_slice_u8_prefix(
|
||||
return s;
|
||||
}
|
||||
|
||||
// puffs_base_slice_u8_suffix returns up to the last up_to bytes of s.
|
||||
static inline puffs_base_slice_u8 puffs_base_slice_u8_suffix(
|
||||
puffs_base_slice_u8 s,
|
||||
// puffs_base__slice_u8__suffix returns up to the last up_to bytes of s.
|
||||
static inline puffs_base__slice_u8 puffs_base__slice_u8_suffix(
|
||||
puffs_base__slice_u8 s,
|
||||
uint64_t up_to) {
|
||||
if ((uint64_t)(s.len) > up_to) {
|
||||
s.ptr += (uint64_t)(s.len) - up_to;
|
||||
@@ -153,14 +155,14 @@ static inline puffs_base_slice_u8 puffs_base_slice_u8_suffix(
|
||||
return s;
|
||||
}
|
||||
|
||||
// puffs_base_slice_u8_copy_from_slice calls memmove(dst.ptr, src.ptr, length)
|
||||
// where length is the minimum of dst.len and src.len.
|
||||
// puffs_base__slice_u8__copy_from_slice calls memmove(dst.ptr, src.ptr,
|
||||
// length) where length is the minimum of dst.len and src.len.
|
||||
//
|
||||
// Passing a puffs_base_slice_u8 with all fields NULL or zero (a valid, empty
|
||||
// Passing a puffs_base__slice_u8 with all fields NULL or zero (a valid, empty
|
||||
// slice) is valid and results in a no-op.
|
||||
static inline uint64_t puffs_base_slice_u8_copy_from_slice(
|
||||
puffs_base_slice_u8 dst,
|
||||
puffs_base_slice_u8 src) {
|
||||
static inline uint64_t puffs_base__slice_u8__copy_from_slice(
|
||||
puffs_base__slice_u8 dst,
|
||||
puffs_base__slice_u8 src) {
|
||||
size_t length = dst.len < src.len ? dst.len : src.len;
|
||||
if (length > 0) {
|
||||
memmove(dst.ptr, src.ptr, length);
|
||||
@@ -168,11 +170,12 @@ static inline uint64_t puffs_base_slice_u8_copy_from_slice(
|
||||
return length;
|
||||
}
|
||||
|
||||
static inline uint32_t puffs_base_writer1_copy_from_history32(uint8_t** ptr_ptr,
|
||||
uint8_t* start,
|
||||
uint8_t* end,
|
||||
uint32_t distance,
|
||||
uint32_t length) {
|
||||
static inline uint32_t puffs_base__writer1__copy_from_history32(
|
||||
uint8_t** ptr_ptr,
|
||||
uint8_t* start,
|
||||
uint8_t* end,
|
||||
uint32_t distance,
|
||||
uint32_t length) {
|
||||
uint8_t* ptr = *ptr_ptr;
|
||||
size_t d = ptr - start;
|
||||
if ((d == 0) || (d < (size_t)(distance))) {
|
||||
@@ -203,11 +206,12 @@ static inline uint32_t puffs_base_writer1_copy_from_history32(uint8_t** ptr_ptr,
|
||||
return length;
|
||||
}
|
||||
|
||||
static inline uint32_t puffs_base_writer1_copy_from_reader32(uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
uint8_t** ptr_rptr,
|
||||
uint8_t* rend,
|
||||
uint32_t length) {
|
||||
static inline uint32_t puffs_base__writer1__copy_from_reader32(
|
||||
uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
uint8_t** ptr_rptr,
|
||||
uint8_t* rend,
|
||||
uint32_t length) {
|
||||
uint8_t* wptr = *ptr_wptr;
|
||||
size_t n = length;
|
||||
if (n > wend - wptr) {
|
||||
@@ -225,10 +229,10 @@ static inline uint32_t puffs_base_writer1_copy_from_reader32(uint8_t** ptr_wptr,
|
||||
return n;
|
||||
}
|
||||
|
||||
static inline uint64_t puffs_base_writer1_copy_from_slice(
|
||||
static inline uint64_t puffs_base__writer1__copy_from_slice(
|
||||
uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
puffs_base_slice_u8 src) {
|
||||
puffs_base__slice_u8 src) {
|
||||
uint8_t* wptr = *ptr_wptr;
|
||||
size_t n = src.len;
|
||||
if (n > wend - wptr) {
|
||||
@@ -241,10 +245,10 @@ static inline uint64_t puffs_base_writer1_copy_from_slice(
|
||||
return n;
|
||||
}
|
||||
|
||||
static inline uint32_t puffs_base_writer1_copy_from_slice32(
|
||||
static inline uint32_t puffs_base__writer1__copy_from_slice32(
|
||||
uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
puffs_base_slice_u8 src,
|
||||
puffs_base__slice_u8 src,
|
||||
uint32_t length) {
|
||||
uint8_t* wptr = *ptr_wptr;
|
||||
size_t n = src.len;
|
||||
|
||||
@@ -598,9 +598,9 @@ func (g *gen) writeInitializerImpl(b *buffer, n *a.Struct) error {
|
||||
b.printf("return;\n")
|
||||
b.printf("}\n")
|
||||
|
||||
b.writes("if (for_internal_use_only != PUFFS_ALREADY_ZEROED) {" +
|
||||
b.writes("if (for_internal_use_only != PUFFS_BASE__ALREADY_ZEROED) {" +
|
||||
"memset(self, 0, sizeof(*self)); }\n")
|
||||
b.writes("self->private_impl.magic = PUFFS_MAGIC;\n")
|
||||
b.writes("self->private_impl.magic = PUFFS_BASE__MAGIC;\n")
|
||||
|
||||
for _, f := range n.Fields() {
|
||||
f := f.Field()
|
||||
@@ -622,7 +622,7 @@ func (g *gen) writeInitializerImpl(b *buffer, n *a.Struct) error {
|
||||
continue
|
||||
}
|
||||
b.printf("%s%s__initialize(&self->private_impl.%s%s,"+
|
||||
"PUFFS_VERSION, PUFFS_ALREADY_ZEROED);\n",
|
||||
"PUFFS_VERSION, PUFFS_BASE__ALREADY_ZEROED);\n",
|
||||
g.pkgPrefix, x.Name().String(g.tm), fPrefix, f.Name().String(g.tm))
|
||||
}
|
||||
|
||||
|
||||
@@ -18,21 +18,20 @@ package cgen
|
||||
|
||||
const baseHeader = "" +
|
||||
"#ifndef PUFFS_BASE_HEADER_H\n#define PUFFS_BASE_HEADER_H\n\n// Copyright 2017 The Puffs Authors.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\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// Si" +
|
||||
"milarly, 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_slice_u8 is a 1-dimensional buffer (a pointer and length).\n//\n// A value with all fields NULL or zero is a valid, empty slice.\ntypedef struct {\n uint8_t* ptr;\n size_t len;\n} puffs_base_slice_u8;\n\n// puffs_base_buf1 is a 1-dimensional buffer (a pointer and length), plus\n// additional indexes into that buffer, plus" +
|
||||
" an opened / closed flag.\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// puffs_base_limit1 provides a limited view of a 1-dimensional byte stream:\n// its first N bytes. That N can be greater than a buffer's current read or\n// write capacity. N decreases naturally over time as bytes are read from or\n// written to the stream.\n//\n// A value with all fields NULL or zero is a valid, unlimited view.\ntypedef struct puffs_base_limit1 {\n uint64_t* ptr_to_len; // Pointer to N.\n struct puffs_base_limit1* next; // Linked list of limits.\n} puffs_base_limit1;\n\ntypedef struct {\n puffs_base_buf1* buf;\n puffs_base_limit1 limit;\n} puffs_base_reader1;\n\ntypedef struct {\n puffs_base_buf1* buf;\n puffs_base_limit1 limit;\n} puffs_base_write" +
|
||||
"r1;\n\n#endif // PUFFS_BASE_HEADER_H\n" +
|
||||
"milarly, 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__slice_u8 is a 1-dimensional buffer (a pointer and length).\n//\n// A value with all fields NULL or zero is a valid, empty slice.\ntypedef struct {\n uint8_t* ptr;\n size_t len;\n} puffs_base__slice_u8;\n\n// puffs_base__buf1 is a 1-dimensional buffer (a pointer and length), plus\n// additional indexes into that buffer, p" +
|
||||
"lus an opened / closed flag.\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// puffs_base__limit1 provides a limited view of a 1-dimensional byte stream:\n// its first N bytes. That N can be greater than a buffer's current read or\n// write capacity. N decreases naturally over time as bytes are read from or\n// written to the stream.\n//\n// A value with all fields NULL or zero is a valid, unlimited view.\ntypedef struct puffs_base__limit1 {\n uint64_t* ptr_to_len; // Pointer to N.\n struct puffs_base__limit1* next; // Linked list of limits.\n} puffs_base__limit1;\n\ntypedef struct {\n puffs_base__buf1* buf;\n puffs_base__limit1 limit;\n} puffs_base__reader1;\n\ntypedef struct {\n puffs_base__buf1* buf;\n puffs_base__limit1 limit;\n} pu" +
|
||||
"ffs_base__writer1;\n\n#endif // PUFFS_BASE_HEADER_H\n" +
|
||||
""
|
||||
|
||||
const baseImpl = "" +
|
||||
"#ifndef PUFFS_BASE_IMPL_H\n#define PUFFS_BASE_IMPL_H\n\n// Copyright 2017 The Puffs Authors.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#define PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(x) (void)(x)\n\n// PUFFS_MAGIC is a magic number to check that initializers are called. It's\n// not foolproof, given C doesn't automatically zero memory before use, but it\n// should catch 99.99% of cases.\n//\n// Its (non-zero) value is arbitrary, based on md5sum(\"puffs\").\n#define PUFFS_MAGIC (0xCB3699CCU)\n\n// PUFFS_ALREADY_ZERO" +
|
||||
"ED is passed from a container struct's initializer to a\n// containee struct's initializer when the container has already zeroed the\n// containee's memory.\n//\n// Its (non-zero) value is arbitrary, based on md5sum(\"zeroed\").\n#define PUFFS_ALREADY_ZEROED (0x68602EF1U)\n\n// Use switch cases for coroutine suspension points, similar to the technique\n// in https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html\n//\n// We use a trivial macro instead of an explicit assignment and case statement\n// so that clang-format doesn't get confused by the unusual \"case\"s.\n#define PUFFS_COROUTINE_SUSPENSION_POINT(n) \\\n coro_susp_point = n; \\\n case n:;\n\n#define PUFFS_COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \\\n if (status < 0) { \\\n goto exit; \\\n } else if (status == 0) { \\\n goto ok; \\\n } " +
|
||||
" \\\n coro_susp_point = n; \\\n goto suspend; \\\n case n:;\n\n// Clang also defines \"__GNUC__\".\n#if defined(__GNUC__)\n#define PUFFS_LIKELY(expr) (__builtin_expect(!!(expr), 1))\n#define PUFFS_UNLIKELY(expr) (__builtin_expect(!!(expr), 0))\n// Declare the printf prototype. The generated code shouldn't need this at all,\n// but it's useful for manual printf debugging.\nextern int printf(const char* __restrict __format, ...);\n#else\n#define PUFFS_LIKELY(expr) (expr)\n#define PUFFS_UNLIKELY(expr) (expr)\n#endif\n\n// ---------------- Static Inline Functions\n//\n// The helpers below are functions, instead of macros, because their arguments\n// can be an expression that we shouldn't evaluate more than once.\n//\n// They are in base-impl.h and hence copy/pasted into every generated C file,\n// instead of being in some \"base.c\" file, since a design goal is that users of\n// the generated C code can often just #include a single .c file, such as\n// \"gif.c\", with" +
|
||||
"out having to additionally include or otherwise build and link\n// a \"base.c\" file.\n//\n// They are static, so that linking multiple puffs .o files won't complain about\n// duplicate function definitions.\n//\n// They are explicitly marked inline, even if modern compilers don't use the\n// inline attribute to guide optimizations such as inlining, to avoid the\n// -Wunused-function warning, and we like to compile with -Wall -Werror.\n\nstatic inline uint16_t puffs_base_load_u16be(uint8_t* p) {\n return ((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0);\n}\n\nstatic inline uint16_t puffs_base_load_u16le(uint8_t* p) {\n return ((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8);\n}\n\nstatic inline uint32_t puffs_base_load_u32be(uint8_t* p) {\n return ((uint32_t)(p[0]) << 24) | ((uint32_t)(p[1]) << 16) |\n ((uint32_t)(p[2]) << 8) | ((uint32_t)(p[3]) << 0);\n}\n\nstatic inline uint32_t puffs_base_load_u32le(uint8_t* p) {\n return ((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) |\n ((uint32_t)(p[2]) << 16) | ((uint32_" +
|
||||
"t)(p[3]) << 24);\n}\n\nstatic inline puffs_base_slice_u8 puffs_base_slice_u8_subslice_i(\n puffs_base_slice_u8 s,\n uint64_t i) {\n if ((i <= SIZE_MAX) && (i <= s.len)) {\n return ((puffs_base_slice_u8){\n .ptr = s.ptr + i,\n .len = s.len - i,\n });\n }\n return ((puffs_base_slice_u8){});\n}\n\nstatic inline puffs_base_slice_u8 puffs_base_slice_u8_subslice_j(\n puffs_base_slice_u8 s,\n uint64_t j) {\n if ((j <= SIZE_MAX) && (j <= s.len)) {\n return ((puffs_base_slice_u8){.ptr = s.ptr, .len = j});\n }\n return ((puffs_base_slice_u8){});\n}\n\nstatic inline puffs_base_slice_u8\npuffs_base_slice_u8_subslice_ij(puffs_base_slice_u8 s, uint64_t i, uint64_t j) {\n if ((i <= j) && (j <= SIZE_MAX) && (j <= s.len)) {\n return ((puffs_base_slice_u8){\n .ptr = s.ptr + i,\n .len = j - i,\n });\n }\n return ((puffs_base_slice_u8){});\n}\n\n// puffs_base_slice_u8_prefix returns up to the first up_to bytes of s.\nstatic inline puffs_base_slice_u8 puffs_base_slice_u8_prefix(\n puffs_base_slice_u8" +
|
||||
" s,\n uint64_t up_to) {\n if ((uint64_t)(s.len) > up_to) {\n s.len = up_to;\n }\n return s;\n}\n\n// puffs_base_slice_u8_suffix returns up to the last up_to bytes of s.\nstatic inline puffs_base_slice_u8 puffs_base_slice_u8_suffix(\n puffs_base_slice_u8 s,\n uint64_t up_to) {\n if ((uint64_t)(s.len) > up_to) {\n s.ptr += (uint64_t)(s.len) - up_to;\n s.len = up_to;\n }\n return s;\n}\n\n// puffs_base_slice_u8_copy_from_slice calls memmove(dst.ptr, src.ptr, length)\n// where length is the minimum of dst.len and src.len.\n//\n// Passing a puffs_base_slice_u8 with all fields NULL or zero (a valid, empty\n// slice) is valid and results in a no-op.\nstatic inline uint64_t puffs_base_slice_u8_copy_from_slice(\n puffs_base_slice_u8 dst,\n puffs_base_slice_u8 src) {\n size_t length = dst.len < src.len ? dst.len : src.len;\n if (length > 0) {\n memmove(dst.ptr, src.ptr, length);\n }\n return length;\n}\n\nstatic inline uint32_t puffs_base_writer1_copy_from_history32(uint8_t** ptr_ptr,\n " +
|
||||
" uint8_t* start,\n uint8_t* end,\n uint32_t distance,\n uint32_t length) {\n uint8_t* ptr = *ptr_ptr;\n size_t d = ptr - start;\n if ((d == 0) || (d < (size_t)(distance))) {\n return 0;\n }\n start = ptr - distance;\n size_t n = end - ptr;\n if ((size_t)(length) > n) {\n length = n;\n } else {\n n = length;\n }\n // TODO: is manual unrolling actually helpful?\n for (; n >= 8; n -= 8) {\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n }\n for (; n; n--) {\n *ptr++ = *start++;\n }\n *ptr_ptr = ptr;\n return length;\n}\n\nstatic inline uint32_t puffs_base_writer1_copy_from_reader32(uint8_t** ptr_wptr,\n uint8" +
|
||||
"_t* wend,\n uint8_t** ptr_rptr,\n uint8_t* rend,\n uint32_t length) {\n uint8_t* wptr = *ptr_wptr;\n size_t n = length;\n if (n > wend - wptr) {\n n = wend - wptr;\n }\n uint8_t* rptr = *ptr_rptr;\n if (n > rend - rptr) {\n n = rend - rptr;\n }\n if (n > 0) {\n memmove(wptr, rptr, n);\n *ptr_wptr += n;\n *ptr_rptr += n;\n }\n return n;\n}\n\nstatic inline uint64_t puffs_base_writer1_copy_from_slice(\n uint8_t** ptr_wptr,\n uint8_t* wend,\n puffs_base_slice_u8 src) {\n uint8_t* wptr = *ptr_wptr;\n size_t n = src.len;\n if (n > wend - wptr) {\n n = wend - wptr;\n }\n if (n > 0) {\n memmove(wptr, src.ptr, n);\n *ptr_wptr += n;\n }\n return n;\n}\n\nstatic inline uint32_t puffs_base_writer1_copy_from_slice32(\n uint8_t** ptr_wptr,\n uint8_t* wend,\n puffs_base_slice_u8 src,\n uint32_t length) {\n uint8_t* wptr = *pt" +
|
||||
"r_wptr;\n size_t n = src.len;\n if (n > length) {\n n = length;\n }\n if (n > wend - wptr) {\n n = wend - wptr;\n }\n if (n > 0) {\n memmove(wptr, src.ptr, n);\n *ptr_wptr += n;\n }\n return n;\n}\n\n#endif // PUFFS_BASE_IMPL_H\n" +
|
||||
"#ifndef PUFFS_BASE_IMPL_H\n#define PUFFS_BASE_IMPL_H\n\n// Copyright 2017 The Puffs Authors.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#define PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(x) (void)(x)\n\n// PUFFS_BASE__MAGIC is a magic number to check that initializers are called.\n// It's not foolproof, given C doesn't automatically zero memory before use,\n// but it should catch 99.99% of cases.\n//\n// Its (non-zero) value is arbitrary, based on md5sum(\"puffs\").\n#define PUFFS_BASE__MAGIC (0xCB3699CCU)\n\n// " +
|
||||
"PUFFS_BASE__ALREADY_ZEROED is passed from a container struct's initializer\n// to a containee struct's initializer when the container has already zeroed\n// the containee's memory.\n//\n// Its (non-zero) value is arbitrary, based on md5sum(\"zeroed\").\n#define PUFFS_BASE__ALREADY_ZEROED (0x68602EF1U)\n\n// Use switch cases for coroutine suspension points, similar to the technique\n// in https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html\n//\n// We use a trivial macro instead of an explicit assignment and case statement\n// so that clang-format doesn't get confused by the unusual \"case\"s.\n#define PUFFS_BASE__COROUTINE_SUSPENSION_POINT(n) \\\n coro_susp_point = n; \\\n case n:;\n\n#define PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \\\n if (status < 0) { \\\n goto exit; \\\n } else if (status == 0) { \\\n goto ok; " +
|
||||
" \\\n } \\\n coro_susp_point = n; \\\n goto suspend; \\\n case n:;\n\n// Clang also defines \"__GNUC__\".\n#if defined(__GNUC__)\n#define PUFFS_BASE__LIKELY(expr) (__builtin_expect(!!(expr), 1))\n#define PUFFS_BASE__UNLIKELY(expr) (__builtin_expect(!!(expr), 0))\n// Declare the printf prototype. The generated code shouldn't need this at all,\n// but it's useful for manual printf debugging.\nextern int printf(const char* __restrict __format, ...);\n#else\n#define PUFFS_BASE__LIKELY(expr) (expr)\n#define PUFFS_BASE__UNLIKELY(expr) (expr)\n#endif\n\n// ---------------- Static Inline Functions\n//\n// The helpers below are functions, instead of macros, because their arguments\n// can be an expression that we shouldn't evaluate more than once.\n//\n// They are in base-impl.h and hence copy/pasted into every generated C file,\n// instead of being in some \"base.c\" file, since a desig" +
|
||||
"n goal is that users of\n// the generated C code can often just #include a single .c file, such as\n// \"gif.c\", without having to additionally include or otherwise build and link\n// a \"base.c\" file.\n//\n// They are static, so that linking multiple puffs .o files won't complain about\n// duplicate function definitions.\n//\n// They are explicitly marked inline, even if modern compilers don't use the\n// inline attribute to guide optimizations such as inlining, to avoid the\n// -Wunused-function warning, and we like to compile with -Wall -Werror.\n\nstatic inline uint16_t puffs_base__load_u16be(uint8_t* p) {\n return ((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0);\n}\n\nstatic inline uint16_t puffs_base__load_u16le(uint8_t* p) {\n return ((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8);\n}\n\nstatic inline uint32_t puffs_base__load_u32be(uint8_t* p) {\n return ((uint32_t)(p[0]) << 24) | ((uint32_t)(p[1]) << 16) |\n ((uint32_t)(p[2]) << 8) | ((uint32_t)(p[3]) << 0);\n}\n\nstatic inline uint32_t puffs_base__load_u32le(ui" +
|
||||
"nt8_t* p) {\n return ((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) |\n ((uint32_t)(p[2]) << 16) | ((uint32_t)(p[3]) << 24);\n}\n\nstatic inline puffs_base__slice_u8 puffs_base__slice_u8__subslice_i(\n puffs_base__slice_u8 s,\n uint64_t i) {\n if ((i <= SIZE_MAX) && (i <= s.len)) {\n return ((puffs_base__slice_u8){\n .ptr = s.ptr + i,\n .len = s.len - i,\n });\n }\n return ((puffs_base__slice_u8){});\n}\n\nstatic inline puffs_base__slice_u8 puffs_base__slice_u8__subslice_j(\n puffs_base__slice_u8 s,\n uint64_t j) {\n if ((j <= SIZE_MAX) && (j <= s.len)) {\n return ((puffs_base__slice_u8){.ptr = s.ptr, .len = j});\n }\n return ((puffs_base__slice_u8){});\n}\n\nstatic inline puffs_base__slice_u8 puffs_base__slice_u8__subslice_ij(\n puffs_base__slice_u8 s,\n uint64_t i,\n uint64_t j) {\n if ((i <= j) && (j <= SIZE_MAX) && (j <= s.len)) {\n return ((puffs_base__slice_u8){\n .ptr = s.ptr + i,\n .len = j - i,\n });\n }\n return ((puffs_base__slice_u8){});\n}\n\n// puffs" +
|
||||
"_base__slice_u8__prefix returns up to the first up_to bytes of s.\nstatic inline puffs_base__slice_u8 puffs_base__slice_u8__prefix(\n puffs_base__slice_u8 s,\n uint64_t up_to) {\n if ((uint64_t)(s.len) > up_to) {\n s.len = up_to;\n }\n return s;\n}\n\n// puffs_base__slice_u8__suffix returns up to the last up_to bytes of s.\nstatic inline puffs_base__slice_u8 puffs_base__slice_u8_suffix(\n puffs_base__slice_u8 s,\n uint64_t up_to) {\n if ((uint64_t)(s.len) > up_to) {\n s.ptr += (uint64_t)(s.len) - up_to;\n s.len = up_to;\n }\n return s;\n}\n\n// puffs_base__slice_u8__copy_from_slice calls memmove(dst.ptr, src.ptr,\n// length) where length is the minimum of dst.len and src.len.\n//\n// Passing a puffs_base__slice_u8 with all fields NULL or zero (a valid, empty\n// slice) is valid and results in a no-op.\nstatic inline uint64_t puffs_base__slice_u8__copy_from_slice(\n puffs_base__slice_u8 dst,\n puffs_base__slice_u8 src) {\n size_t length = dst.len < src.len ? dst.len : src.len;\n if (length > 0) {\n memm" +
|
||||
"ove(dst.ptr, src.ptr, length);\n }\n return length;\n}\n\nstatic inline uint32_t puffs_base__writer1__copy_from_history32(\n uint8_t** ptr_ptr,\n uint8_t* start,\n uint8_t* end,\n uint32_t distance,\n uint32_t length) {\n uint8_t* ptr = *ptr_ptr;\n size_t d = ptr - start;\n if ((d == 0) || (d < (size_t)(distance))) {\n return 0;\n }\n start = ptr - distance;\n size_t n = end - ptr;\n if ((size_t)(length) > n) {\n length = n;\n } else {\n n = length;\n }\n // TODO: is manual unrolling actually helpful?\n for (; n >= 8; n -= 8) {\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n }\n for (; n; n--) {\n *ptr++ = *start++;\n }\n *ptr_ptr = ptr;\n return length;\n}\n\nstatic inline uint32_t puffs_base__writer1__copy_from_reader32(\n uint8_t** ptr_wptr,\n uint8_t* wend,\n uint8_t** ptr_rptr,\n uint8_t* rend,\n uint32_t length) {\n uint8_t* wptr = *ptr_wptr;\n s" +
|
||||
"ize_t n = length;\n if (n > wend - wptr) {\n n = wend - wptr;\n }\n uint8_t* rptr = *ptr_rptr;\n if (n > rend - rptr) {\n n = rend - rptr;\n }\n if (n > 0) {\n memmove(wptr, rptr, n);\n *ptr_wptr += n;\n *ptr_rptr += n;\n }\n return n;\n}\n\nstatic inline uint64_t puffs_base__writer1__copy_from_slice(\n uint8_t** ptr_wptr,\n uint8_t* wend,\n puffs_base__slice_u8 src) {\n uint8_t* wptr = *ptr_wptr;\n size_t n = src.len;\n if (n > wend - wptr) {\n n = wend - wptr;\n }\n if (n > 0) {\n memmove(wptr, src.ptr, n);\n *ptr_wptr += n;\n }\n return n;\n}\n\nstatic inline uint32_t puffs_base__writer1__copy_from_slice32(\n uint8_t** ptr_wptr,\n uint8_t* wend,\n puffs_base__slice_u8 src,\n uint32_t length) {\n uint8_t* wptr = *ptr_wptr;\n size_t n = src.len;\n if (n > length) {\n n = length;\n }\n if (n > wend - wptr) {\n n = wend - wptr;\n }\n if (n > 0) {\n memmove(wptr, src.ptr, n);\n *ptr_wptr += n;\n }\n return n;\n}\n\n#endif // PUFFS_BASE_IMPL_H\n" +
|
||||
""
|
||||
|
||||
type template_args_short_read struct {
|
||||
|
||||
@@ -156,7 +156,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
}
|
||||
if isThatMethod(g.tm, n, t.KeySuffix, 1) {
|
||||
// TODO: don't assume that the slice is a slice of u8.
|
||||
b.writes("puffs_base_slice_u8_suffix(")
|
||||
b.writes("puffs_base__slice_u8_suffix(")
|
||||
x := n.LHS().Expr().LHS().Expr()
|
||||
if err := g.writeExpr(b, x, rp, parenthesesOptional, depth); err != nil {
|
||||
return err
|
||||
@@ -169,12 +169,12 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
return nil
|
||||
}
|
||||
if isInDst(g.tm, n, t.KeySlice, 0) {
|
||||
b.printf("((puffs_base_slice_u8){ .ptr = %swstart_dst, .len = %swptr_dst - %swstart_dst, })",
|
||||
b.printf("((puffs_base__slice_u8){ .ptr = %swstart_dst, .len = %swptr_dst - %swstart_dst, })",
|
||||
bPrefix, bPrefix, bPrefix)
|
||||
return nil
|
||||
}
|
||||
if isInDst(g.tm, n, t.KeyCopyFromReader32, 2) {
|
||||
b.printf("puffs_base_writer1_copy_from_reader32(&%swptr_dst, %swend_dst", bPrefix, bPrefix)
|
||||
b.printf("puffs_base__writer1__copy_from_reader32(&%swptr_dst, %swend_dst", bPrefix, bPrefix)
|
||||
// TODO: don't assume that the first argument is "in.src".
|
||||
b.printf(", &%srptr_src, %srend_src,", bPrefix, bPrefix)
|
||||
a := n.Args()[1].Arg().Value()
|
||||
@@ -185,7 +185,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
return nil
|
||||
}
|
||||
if isInDst(g.tm, n, t.KeyCopyFromHistory32, 2) {
|
||||
b.printf("puffs_base_writer1_copy_from_history32(&%swptr_dst, %swstart_dst, %swend_dst",
|
||||
b.printf("puffs_base__writer1__copy_from_history32(&%swptr_dst, %swstart_dst, %swend_dst",
|
||||
bPrefix, bPrefix, bPrefix)
|
||||
for _, o := range n.Args() {
|
||||
b.writeb(',')
|
||||
@@ -197,7 +197,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
return nil
|
||||
}
|
||||
if isInDst(g.tm, n, t.KeyCopyFromSlice32, 2) {
|
||||
b.printf("puffs_base_writer1_copy_from_slice32(&%swptr_dst, %swend_dst", bPrefix, bPrefix)
|
||||
b.printf("puffs_base__writer1__copy_from_slice32(&%swptr_dst, %swend_dst", bPrefix, bPrefix)
|
||||
for _, o := range n.Args() {
|
||||
b.writeb(',')
|
||||
if err := g.writeExpr(b, o.Arg().Value(), rp, parenthesesOptional, depth); err != nil {
|
||||
@@ -208,7 +208,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
return nil
|
||||
}
|
||||
if isInDst(g.tm, n, t.KeyCopyFromSlice, 1) {
|
||||
b.printf("puffs_base_writer1_copy_from_slice(&%swptr_dst, %swend_dst,", bPrefix, bPrefix)
|
||||
b.printf("puffs_base__writer1__copy_from_slice(&%swptr_dst, %swend_dst,", bPrefix, bPrefix)
|
||||
a := n.Args()[0].Arg().Value()
|
||||
if err := g.writeExpr(b, a, rp, parenthesesOptional, depth); err != nil {
|
||||
return err
|
||||
@@ -217,7 +217,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
return nil
|
||||
}
|
||||
if isThatMethod(g.tm, n, t.KeyCopyFromSlice, 1) {
|
||||
b.writes("puffs_base_slice_u8_copy_from_slice(")
|
||||
b.writes("puffs_base__slice_u8__copy_from_slice(")
|
||||
receiver := n.LHS().Expr().LHS().Expr()
|
||||
if err := g.writeExpr(b, receiver, rp, parenthesesOptional, depth); err != nil {
|
||||
return err
|
||||
@@ -310,17 +310,17 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
rhs := n.RHS().Expr()
|
||||
switch {
|
||||
case mhs != nil && rhs == nil:
|
||||
b.writes("puffs_base_slice_u8_subslice_i(")
|
||||
b.writes("puffs_base__slice_u8__subslice_i(")
|
||||
case mhs == nil && rhs != nil:
|
||||
b.writes("puffs_base_slice_u8_subslice_j(")
|
||||
b.writes("puffs_base__slice_u8__subslice_j(")
|
||||
case mhs != nil && rhs != nil:
|
||||
b.writes("puffs_base_slice_u8_subslice_ij(")
|
||||
b.writes("puffs_base__slice_u8__subslice_ij(")
|
||||
}
|
||||
|
||||
lhsIsArray := lhs.MType().Decorator().Key() == t.KeyOpenBracket
|
||||
if lhsIsArray {
|
||||
// TODO: don't assume that the slice is a slice of u8.
|
||||
b.writes("((puffs_base_slice_u8){.ptr=")
|
||||
b.writes("((puffs_base__slice_u8){.ptr=")
|
||||
}
|
||||
if err := g.writeExpr(b, lhs, rp, parenthesesOptional, depth); err != nil {
|
||||
return err
|
||||
@@ -368,9 +368,9 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
|
||||
case t.KeyLimit:
|
||||
// TODO: don't hard code so much detail.
|
||||
b.writes("(puffs_base_reader1) {")
|
||||
b.writes("(puffs_base__reader1) {")
|
||||
b.writes(".buf = a_src.buf,")
|
||||
b.writes(".limit = (puffs_base_limit1) {")
|
||||
b.writes(".limit = (puffs_base__limit1) {")
|
||||
b.printf(".ptr_to_len = &%s%s,", lPrefix, g.currFunk.limitVarName)
|
||||
b.writes(".next = &a_src.limit,")
|
||||
b.writes("}}")
|
||||
@@ -449,7 +449,7 @@ func (g *gen) writeCTypeName(b *buffer, n *a.TypeExpr, varNamePrefix string, var
|
||||
if n.Decorator().Key() == t.KeyColon {
|
||||
o := n.Inner()
|
||||
if o.Decorator() == 0 && o.Name().Key() == t.KeyU8 && !o.IsRefined() {
|
||||
b.writes("puffs_base_slice_u8")
|
||||
b.writes("puffs_base__slice_u8")
|
||||
b.writeb(' ')
|
||||
b.writes(varNamePrefix)
|
||||
b.writes(varName)
|
||||
@@ -519,10 +519,10 @@ var cTypeNames = [...]string{
|
||||
t.KeyU64: "uint64_t",
|
||||
t.KeyUsize: "size_t",
|
||||
t.KeyBool: "bool",
|
||||
t.KeyBuf1: "puffs_base_buf1",
|
||||
t.KeyReader1: "puffs_base_reader1",
|
||||
t.KeyWriter1: "puffs_base_writer1",
|
||||
t.KeyBuf2: "puffs_base_buf2",
|
||||
t.KeyBuf1: "puffs_base__buf1",
|
||||
t.KeyReader1: "puffs_base__reader1",
|
||||
t.KeyWriter1: "puffs_base__writer1",
|
||||
t.KeyBuf2: "puffs_base__buf2",
|
||||
}
|
||||
|
||||
var cOpNames = [256]string{
|
||||
|
||||
@@ -168,7 +168,7 @@ func (g *gen) writeFuncImplHeader(b *buffer) error {
|
||||
}
|
||||
b.writes("}")
|
||||
|
||||
b.printf("if (self->private_impl.magic != PUFFS_MAGIC) {"+
|
||||
b.printf("if (self->private_impl.magic != PUFFS_BASE__MAGIC) {"+
|
||||
"self->private_impl.status = %sERROR_INITIALIZER_NOT_CALLED; }", g.PKGPREFIX)
|
||||
|
||||
b.writes("if (self->private_impl.status < 0) {")
|
||||
@@ -226,7 +226,7 @@ func (g *gen) writeFuncImplBodyResume(b *buffer) error {
|
||||
// https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
|
||||
//
|
||||
// The matching } is written below. See "Close the coroutine switch".
|
||||
b.writes("switch (coro_susp_point) {\nPUFFS_COROUTINE_SUSPENSION_POINT(0);\n\n")
|
||||
b.writes("switch (coro_susp_point) {\nPUFFS_BASE__COROUTINE_SUSPENSION_POINT(0);\n\n")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
|
||||
}
|
||||
} else if n.XType().Decorator().Key() == t.KeyColon {
|
||||
// TODO: don't assume that the slice is a slice of u8.
|
||||
b.printf("((puffs_base_slice_u8){})")
|
||||
b.printf("((puffs_base__slice_u8){})")
|
||||
} else {
|
||||
b.writeb('0')
|
||||
}
|
||||
@@ -250,7 +250,7 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
|
||||
// TODO: don't assume that the slice is a slice of u8. In particular,
|
||||
// the code gen can be subtle if the slice element type has zero size,
|
||||
// such as the empty struct.
|
||||
b.printf("puffs_base_slice_u8 %sslice_%s =", iPrefix, name)
|
||||
b.printf("puffs_base__slice_u8 %sslice_%s =", iPrefix, name)
|
||||
if err := g.writeExpr(b, v.Value(), replaceCallSuspendibles, parenthesesOptional, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -334,7 +334,7 @@ func (g *gen) writeCoroSuspPoint(b *buffer, maybeSuspend bool) error {
|
||||
if maybeSuspend {
|
||||
macro = "_MAYBE_SUSPEND"
|
||||
}
|
||||
b.printf("PUFFS_COROUTINE_SUSPENSION_POINT%s(%d);\n", macro, g.currFunk.coroSuspPoint)
|
||||
b.printf("PUFFS_BASE__COROUTINE_SUSPENSION_POINT%s(%d);\n", macro, g.currFunk.coroSuspPoint)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -388,7 +388,8 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
|
||||
temp := g.currFunk.tempW
|
||||
g.currFunk.tempW++
|
||||
|
||||
b.printf("if (PUFFS_UNLIKELY(%srptr_src == %srend_src)) { goto short_read_src; }", bPrefix, bPrefix)
|
||||
b.printf("if (PUFFS_BASE__UNLIKELY(%srptr_src == %srend_src)) { goto short_read_src; }",
|
||||
bPrefix, bPrefix)
|
||||
g.currFunk.shortReads = append(g.currFunk.shortReads, "src")
|
||||
// TODO: watch for passing an array type to writeCTypeName? In C, an
|
||||
// array type can decay into a pointer.
|
||||
@@ -612,8 +613,8 @@ func (g *gen) writeReadUXX(b *buffer, n *a.Expr, name string, size uint32, endia
|
||||
scratchName := fmt.Sprintf("self->private_impl.%s%s[0].scratch",
|
||||
cPrefix, g.currFunk.astFunc.Name().String(g.tm))
|
||||
|
||||
b.printf("if (PUFFS_LIKELY(%srend_src - %srptr_src >= %d)) {", bPrefix, bPrefix, size/8)
|
||||
b.printf("%s%d = puffs_base_load_u%d%s(%srptr_src);\n", tPrefix, temp1, size, endianness, bPrefix)
|
||||
b.printf("if (PUFFS_BASE__LIKELY(%srend_src - %srptr_src >= %d)) {", bPrefix, bPrefix, size/8)
|
||||
b.printf("%s%d = puffs_base__load_u%d%s(%srptr_src);\n", tPrefix, temp1, size, endianness, bPrefix)
|
||||
b.printf("%srptr_src += %d;\n", bPrefix, size/8)
|
||||
b.printf("} else {")
|
||||
b.printf("%s = 0;\n", scratchName)
|
||||
@@ -622,7 +623,7 @@ func (g *gen) writeReadUXX(b *buffer, n *a.Expr, name string, size uint32, endia
|
||||
}
|
||||
b.printf("while (true) {")
|
||||
|
||||
b.printf("if (PUFFS_UNLIKELY(%srptr_%s == %srend_%s)) { goto short_read_%s; }",
|
||||
b.printf("if (PUFFS_BASE__UNLIKELY(%srptr_%s == %srend_%s)) { goto short_read_%s; }",
|
||||
bPrefix, name, bPrefix, name, name)
|
||||
g.currFunk.shortReads = append(g.currFunk.shortReads, name)
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ func (g *gen) writeLoadDerivedVar(b *buffer, name t.ID, typ *a.TypeExpr, header
|
||||
b.printf("%srstart_%s = %srptr_%s;", bPrefix, nameStr, bPrefix, nameStr)
|
||||
}
|
||||
b.printf("size_t len = %s%s.buf->wi - %s%s.buf->ri;", aPrefix, nameStr, aPrefix, nameStr)
|
||||
b.printf("puffs_base_limit1* lim;")
|
||||
b.printf("puffs_base__limit1* lim;")
|
||||
b.printf("for (lim = &%s%s.limit; lim; lim = lim->next) {", aPrefix, nameStr)
|
||||
b.printf("if (lim->ptr_to_len && (len > *lim->ptr_to_len)) { len = *lim->ptr_to_len; }")
|
||||
b.printf("}")
|
||||
@@ -123,7 +123,7 @@ func (g *gen) writeLoadDerivedVar(b *buffer, name t.ID, typ *a.TypeExpr, header
|
||||
b.printf("%swend_%s = %swptr_%s;", bPrefix, nameStr, bPrefix, nameStr)
|
||||
b.printf("if (!%s%s.buf->closed) {", aPrefix, nameStr)
|
||||
b.printf("size_t len = %s%s.buf->len - %s%s.buf->wi;", aPrefix, nameStr, aPrefix, nameStr)
|
||||
b.printf("puffs_base_limit1* lim;")
|
||||
b.printf("puffs_base__limit1* lim;")
|
||||
b.printf("for (lim = &%s%s.limit; lim; lim = lim->next) {", aPrefix, nameStr)
|
||||
b.printf("if (lim->ptr_to_len && (len > *lim->ptr_to_len)) { len = *lim->ptr_to_len; }")
|
||||
b.printf("}")
|
||||
@@ -150,14 +150,14 @@ func (g *gen) writeSaveDerivedVar(b *buffer, name t.ID, typ *a.TypeExpr, footer
|
||||
b.printf("size_t n = %srptr_%s - (%s%s.buf->ptr + %s%s.buf->ri);",
|
||||
bPrefix, nameStr, aPrefix, nameStr, aPrefix, nameStr)
|
||||
b.printf("%s%s.buf->ri += n;", aPrefix, nameStr)
|
||||
b.printf("puffs_base_limit1* lim;")
|
||||
b.printf("puffs_base__limit1* lim;")
|
||||
b.printf("for (lim = &%s%s.limit; lim; lim = lim->next) {", aPrefix, nameStr)
|
||||
b.printf("if (lim->ptr_to_len) { *lim->ptr_to_len -= n; }")
|
||||
b.printf("}")
|
||||
|
||||
if footer {
|
||||
b.printf("PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(%srstart_%s);", bPrefix, nameStr)
|
||||
b.printf("PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(%srend_%s);", bPrefix, nameStr)
|
||||
b.printf("PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(%srstart_%s);", bPrefix, nameStr)
|
||||
b.printf("PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(%srend_%s);", bPrefix, nameStr)
|
||||
}
|
||||
|
||||
b.printf("}\n")
|
||||
@@ -168,14 +168,14 @@ func (g *gen) writeSaveDerivedVar(b *buffer, name t.ID, typ *a.TypeExpr, footer
|
||||
b.printf("size_t n = %swptr_%s - (%s%s.buf->ptr + %s%s.buf->wi);",
|
||||
bPrefix, nameStr, aPrefix, nameStr, aPrefix, nameStr)
|
||||
b.printf("%s%s.buf->wi += n;", aPrefix, nameStr)
|
||||
b.printf("puffs_base_limit1* lim;")
|
||||
b.printf("puffs_base__limit1* lim;")
|
||||
b.printf("for (lim = &%s%s.limit; lim; lim = lim->next) {", aPrefix, nameStr)
|
||||
b.printf("if (lim->ptr_to_len) { *lim->ptr_to_len -= n; }")
|
||||
b.printf("}")
|
||||
|
||||
if footer {
|
||||
b.printf("PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(%swstart_%s);", bPrefix, nameStr)
|
||||
b.printf("PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(%swend_%s);", bPrefix, nameStr)
|
||||
b.printf("PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(%swstart_%s);", bPrefix, nameStr)
|
||||
b.printf("PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(%swend_%s);", bPrefix, nameStr)
|
||||
}
|
||||
|
||||
b.printf("}\n")
|
||||
@@ -280,7 +280,7 @@ func (g *gen) writeResumeSuspend1(b *buffer, n *a.Var, prefix string, suspend bo
|
||||
}
|
||||
case t.KeyColon:
|
||||
// TODO: don't assume that the slice is a slice of u8.
|
||||
rhs = "puffs_base_slice_u8"
|
||||
rhs = "puffs_base__slice_u8"
|
||||
}
|
||||
if rhs != "" {
|
||||
b.printf("%s = ((%s){});\n", local, rhs)
|
||||
|
||||
@@ -48,11 +48,11 @@ static void ignore_return_value(int ignored) {}
|
||||
|
||||
static const char* decode() {
|
||||
uint8_t dst_buffer[DST_BUFFER_SIZE];
|
||||
puffs_base_buf1 dst = {.ptr = dst_buffer, .len = DST_BUFFER_SIZE};
|
||||
puffs_base_buf1 src = {
|
||||
puffs_base__buf1 dst = {.ptr = dst_buffer, .len = DST_BUFFER_SIZE};
|
||||
puffs_base__buf1 src = {
|
||||
.ptr = lgtm_ptr, .len = lgtm_len, .wi = lgtm_len, .closed = true};
|
||||
puffs_base_writer1 dst_writer = {.buf = &dst};
|
||||
puffs_base_reader1 src_reader = {.buf = &src};
|
||||
puffs_base__writer1 dst_writer = {.buf = &dst};
|
||||
puffs_base__reader1 src_reader = {.buf = &src};
|
||||
|
||||
puffs_flate__flate_decoder dec;
|
||||
puffs_flate__flate_decoder__initialize(&dec, PUFFS_VERSION, 0);
|
||||
|
||||
@@ -47,11 +47,11 @@ static void ignore_return_value(int ignored) {}
|
||||
|
||||
static const char* decode() {
|
||||
uint8_t dst_buffer[DST_BUFFER_SIZE];
|
||||
puffs_base_buf1 dst = {.ptr = dst_buffer, .len = DST_BUFFER_SIZE};
|
||||
puffs_base_buf1 src = {
|
||||
puffs_base__buf1 dst = {.ptr = dst_buffer, .len = DST_BUFFER_SIZE};
|
||||
puffs_base__buf1 src = {
|
||||
.ptr = pjw_ptr, .len = pjw_len, .wi = pjw_len, .closed = true};
|
||||
puffs_base_writer1 dst_writer = {.buf = &dst};
|
||||
puffs_base_reader1 src_reader = {.buf = &src};
|
||||
puffs_base__writer1 dst_writer = {.buf = &dst};
|
||||
puffs_base__reader1 src_reader = {.buf = &src};
|
||||
|
||||
puffs_gif__decoder dec;
|
||||
puffs_gif__decoder__initialize(&dec, PUFFS_VERSION, 0);
|
||||
|
||||
+261
-257
@@ -48,15 +48,15 @@
|
||||
// TODO: don't hard code this in base-header.h.
|
||||
#define PUFFS_VERSION (0x00001)
|
||||
|
||||
// puffs_base_slice_u8 is a 1-dimensional buffer (a pointer and length).
|
||||
// puffs_base__slice_u8 is a 1-dimensional buffer (a pointer and length).
|
||||
//
|
||||
// A value with all fields NULL or zero is a valid, empty slice.
|
||||
typedef struct {
|
||||
uint8_t* ptr;
|
||||
size_t len;
|
||||
} puffs_base_slice_u8;
|
||||
} puffs_base__slice_u8;
|
||||
|
||||
// puffs_base_buf1 is a 1-dimensional buffer (a pointer and length), plus
|
||||
// puffs_base__buf1 is a 1-dimensional buffer (a pointer and length), plus
|
||||
// additional indexes into that buffer, plus an opened / closed flag.
|
||||
//
|
||||
// A value with all fields NULL or zero is a valid, empty buffer.
|
||||
@@ -66,28 +66,28 @@ typedef struct {
|
||||
size_t wi; // Write index. Invariant: wi <= len.
|
||||
size_t ri; // Read index. Invariant: ri <= wi.
|
||||
bool closed; // No further writes are expected.
|
||||
} puffs_base_buf1;
|
||||
} puffs_base__buf1;
|
||||
|
||||
// puffs_base_limit1 provides a limited view of a 1-dimensional byte stream:
|
||||
// puffs_base__limit1 provides a limited view of a 1-dimensional byte stream:
|
||||
// its first N bytes. That N can be greater than a buffer's current read or
|
||||
// write capacity. N decreases naturally over time as bytes are read from or
|
||||
// written to the stream.
|
||||
//
|
||||
// A value with all fields NULL or zero is a valid, unlimited view.
|
||||
typedef struct puffs_base_limit1 {
|
||||
uint64_t* ptr_to_len; // Pointer to N.
|
||||
struct puffs_base_limit1* next; // Linked list of limits.
|
||||
} puffs_base_limit1;
|
||||
typedef struct puffs_base__limit1 {
|
||||
uint64_t* ptr_to_len; // Pointer to N.
|
||||
struct puffs_base__limit1* next; // Linked list of limits.
|
||||
} puffs_base__limit1;
|
||||
|
||||
typedef struct {
|
||||
puffs_base_buf1* buf;
|
||||
puffs_base_limit1 limit;
|
||||
} puffs_base_reader1;
|
||||
puffs_base__buf1* buf;
|
||||
puffs_base__limit1 limit;
|
||||
} puffs_base__reader1;
|
||||
|
||||
typedef struct {
|
||||
puffs_base_buf1* buf;
|
||||
puffs_base_limit1 limit;
|
||||
} puffs_base_writer1;
|
||||
puffs_base__buf1* buf;
|
||||
puffs_base__limit1 limit;
|
||||
} puffs_base__writer1;
|
||||
|
||||
#endif // PUFFS_BASE_HEADER_H
|
||||
|
||||
@@ -301,13 +301,13 @@ void puffs_flate__zlib_decoder__initialize(puffs_flate__zlib_decoder* self,
|
||||
|
||||
puffs_flate__status puffs_flate__flate_decoder__decode(
|
||||
puffs_flate__flate_decoder* self,
|
||||
puffs_base_writer1 a_dst,
|
||||
puffs_base_reader1 a_src);
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src);
|
||||
|
||||
puffs_flate__status puffs_flate__zlib_decoder__decode(
|
||||
puffs_flate__zlib_decoder* self,
|
||||
puffs_base_writer1 a_dst,
|
||||
puffs_base_reader1 a_src);
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
@@ -334,51 +334,51 @@ puffs_flate__status puffs_flate__zlib_decoder__decode(
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#define PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(x) (void)(x)
|
||||
#define PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(x) (void)(x)
|
||||
|
||||
// PUFFS_MAGIC is a magic number to check that initializers are called. It's
|
||||
// not foolproof, given C doesn't automatically zero memory before use, but it
|
||||
// should catch 99.99% of cases.
|
||||
// PUFFS_BASE__MAGIC is a magic number to check that initializers are called.
|
||||
// It's not foolproof, given C doesn't automatically zero memory before use,
|
||||
// but it should catch 99.99% of cases.
|
||||
//
|
||||
// Its (non-zero) value is arbitrary, based on md5sum("puffs").
|
||||
#define PUFFS_MAGIC (0xCB3699CCU)
|
||||
#define PUFFS_BASE__MAGIC (0xCB3699CCU)
|
||||
|
||||
// PUFFS_ALREADY_ZEROED is passed from a container struct's initializer to a
|
||||
// containee struct's initializer when the container has already zeroed the
|
||||
// containee's memory.
|
||||
// PUFFS_BASE__ALREADY_ZEROED is passed from a container struct's initializer
|
||||
// to a containee struct's initializer when the container has already zeroed
|
||||
// the containee's memory.
|
||||
//
|
||||
// Its (non-zero) value is arbitrary, based on md5sum("zeroed").
|
||||
#define PUFFS_ALREADY_ZEROED (0x68602EF1U)
|
||||
#define PUFFS_BASE__ALREADY_ZEROED (0x68602EF1U)
|
||||
|
||||
// Use switch cases for coroutine suspension points, similar to the technique
|
||||
// in https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
|
||||
//
|
||||
// We use a trivial macro instead of an explicit assignment and case statement
|
||||
// so that clang-format doesn't get confused by the unusual "case"s.
|
||||
#define PUFFS_COROUTINE_SUSPENSION_POINT(n) \
|
||||
coro_susp_point = n; \
|
||||
#define PUFFS_BASE__COROUTINE_SUSPENSION_POINT(n) \
|
||||
coro_susp_point = n; \
|
||||
case n:;
|
||||
|
||||
#define PUFFS_COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \
|
||||
if (status < 0) { \
|
||||
goto exit; \
|
||||
} else if (status == 0) { \
|
||||
goto ok; \
|
||||
} \
|
||||
coro_susp_point = n; \
|
||||
goto suspend; \
|
||||
#define PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \
|
||||
if (status < 0) { \
|
||||
goto exit; \
|
||||
} else if (status == 0) { \
|
||||
goto ok; \
|
||||
} \
|
||||
coro_susp_point = n; \
|
||||
goto suspend; \
|
||||
case n:;
|
||||
|
||||
// Clang also defines "__GNUC__".
|
||||
#if defined(__GNUC__)
|
||||
#define PUFFS_LIKELY(expr) (__builtin_expect(!!(expr), 1))
|
||||
#define PUFFS_UNLIKELY(expr) (__builtin_expect(!!(expr), 0))
|
||||
#define PUFFS_BASE__LIKELY(expr) (__builtin_expect(!!(expr), 1))
|
||||
#define PUFFS_BASE__UNLIKELY(expr) (__builtin_expect(!!(expr), 0))
|
||||
// Declare the printf prototype. The generated code shouldn't need this at all,
|
||||
// but it's useful for manual printf debugging.
|
||||
extern int printf(const char* __restrict __format, ...);
|
||||
#else
|
||||
#define PUFFS_LIKELY(expr) (expr)
|
||||
#define PUFFS_UNLIKELY(expr) (expr)
|
||||
#define PUFFS_BASE__LIKELY(expr) (expr)
|
||||
#define PUFFS_BASE__UNLIKELY(expr) (expr)
|
||||
#endif
|
||||
|
||||
// ---------------- Static Inline Functions
|
||||
@@ -399,59 +399,61 @@ extern int printf(const char* __restrict __format, ...);
|
||||
// inline attribute to guide optimizations such as inlining, to avoid the
|
||||
// -Wunused-function warning, and we like to compile with -Wall -Werror.
|
||||
|
||||
static inline uint16_t puffs_base_load_u16be(uint8_t* p) {
|
||||
static inline uint16_t puffs_base__load_u16be(uint8_t* p) {
|
||||
return ((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0);
|
||||
}
|
||||
|
||||
static inline uint16_t puffs_base_load_u16le(uint8_t* p) {
|
||||
static inline uint16_t puffs_base__load_u16le(uint8_t* p) {
|
||||
return ((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8);
|
||||
}
|
||||
|
||||
static inline uint32_t puffs_base_load_u32be(uint8_t* p) {
|
||||
static inline uint32_t puffs_base__load_u32be(uint8_t* p) {
|
||||
return ((uint32_t)(p[0]) << 24) | ((uint32_t)(p[1]) << 16) |
|
||||
((uint32_t)(p[2]) << 8) | ((uint32_t)(p[3]) << 0);
|
||||
}
|
||||
|
||||
static inline uint32_t puffs_base_load_u32le(uint8_t* p) {
|
||||
static inline uint32_t puffs_base__load_u32le(uint8_t* p) {
|
||||
return ((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) |
|
||||
((uint32_t)(p[2]) << 16) | ((uint32_t)(p[3]) << 24);
|
||||
}
|
||||
|
||||
static inline puffs_base_slice_u8 puffs_base_slice_u8_subslice_i(
|
||||
puffs_base_slice_u8 s,
|
||||
static inline puffs_base__slice_u8 puffs_base__slice_u8__subslice_i(
|
||||
puffs_base__slice_u8 s,
|
||||
uint64_t i) {
|
||||
if ((i <= SIZE_MAX) && (i <= s.len)) {
|
||||
return ((puffs_base_slice_u8){
|
||||
return ((puffs_base__slice_u8){
|
||||
.ptr = s.ptr + i,
|
||||
.len = s.len - i,
|
||||
});
|
||||
}
|
||||
return ((puffs_base_slice_u8){});
|
||||
return ((puffs_base__slice_u8){});
|
||||
}
|
||||
|
||||
static inline puffs_base_slice_u8 puffs_base_slice_u8_subslice_j(
|
||||
puffs_base_slice_u8 s,
|
||||
static inline puffs_base__slice_u8 puffs_base__slice_u8__subslice_j(
|
||||
puffs_base__slice_u8 s,
|
||||
uint64_t j) {
|
||||
if ((j <= SIZE_MAX) && (j <= s.len)) {
|
||||
return ((puffs_base_slice_u8){.ptr = s.ptr, .len = j});
|
||||
return ((puffs_base__slice_u8){.ptr = s.ptr, .len = j});
|
||||
}
|
||||
return ((puffs_base_slice_u8){});
|
||||
return ((puffs_base__slice_u8){});
|
||||
}
|
||||
|
||||
static inline puffs_base_slice_u8
|
||||
puffs_base_slice_u8_subslice_ij(puffs_base_slice_u8 s, uint64_t i, uint64_t j) {
|
||||
static inline puffs_base__slice_u8 puffs_base__slice_u8__subslice_ij(
|
||||
puffs_base__slice_u8 s,
|
||||
uint64_t i,
|
||||
uint64_t j) {
|
||||
if ((i <= j) && (j <= SIZE_MAX) && (j <= s.len)) {
|
||||
return ((puffs_base_slice_u8){
|
||||
return ((puffs_base__slice_u8){
|
||||
.ptr = s.ptr + i,
|
||||
.len = j - i,
|
||||
});
|
||||
}
|
||||
return ((puffs_base_slice_u8){});
|
||||
return ((puffs_base__slice_u8){});
|
||||
}
|
||||
|
||||
// puffs_base_slice_u8_prefix returns up to the first up_to bytes of s.
|
||||
static inline puffs_base_slice_u8 puffs_base_slice_u8_prefix(
|
||||
puffs_base_slice_u8 s,
|
||||
// puffs_base__slice_u8__prefix returns up to the first up_to bytes of s.
|
||||
static inline puffs_base__slice_u8 puffs_base__slice_u8__prefix(
|
||||
puffs_base__slice_u8 s,
|
||||
uint64_t up_to) {
|
||||
if ((uint64_t)(s.len) > up_to) {
|
||||
s.len = up_to;
|
||||
@@ -459,9 +461,9 @@ static inline puffs_base_slice_u8 puffs_base_slice_u8_prefix(
|
||||
return s;
|
||||
}
|
||||
|
||||
// puffs_base_slice_u8_suffix returns up to the last up_to bytes of s.
|
||||
static inline puffs_base_slice_u8 puffs_base_slice_u8_suffix(
|
||||
puffs_base_slice_u8 s,
|
||||
// puffs_base__slice_u8__suffix returns up to the last up_to bytes of s.
|
||||
static inline puffs_base__slice_u8 puffs_base__slice_u8_suffix(
|
||||
puffs_base__slice_u8 s,
|
||||
uint64_t up_to) {
|
||||
if ((uint64_t)(s.len) > up_to) {
|
||||
s.ptr += (uint64_t)(s.len) - up_to;
|
||||
@@ -470,14 +472,14 @@ static inline puffs_base_slice_u8 puffs_base_slice_u8_suffix(
|
||||
return s;
|
||||
}
|
||||
|
||||
// puffs_base_slice_u8_copy_from_slice calls memmove(dst.ptr, src.ptr, length)
|
||||
// where length is the minimum of dst.len and src.len.
|
||||
// puffs_base__slice_u8__copy_from_slice calls memmove(dst.ptr, src.ptr,
|
||||
// length) where length is the minimum of dst.len and src.len.
|
||||
//
|
||||
// Passing a puffs_base_slice_u8 with all fields NULL or zero (a valid, empty
|
||||
// Passing a puffs_base__slice_u8 with all fields NULL or zero (a valid, empty
|
||||
// slice) is valid and results in a no-op.
|
||||
static inline uint64_t puffs_base_slice_u8_copy_from_slice(
|
||||
puffs_base_slice_u8 dst,
|
||||
puffs_base_slice_u8 src) {
|
||||
static inline uint64_t puffs_base__slice_u8__copy_from_slice(
|
||||
puffs_base__slice_u8 dst,
|
||||
puffs_base__slice_u8 src) {
|
||||
size_t length = dst.len < src.len ? dst.len : src.len;
|
||||
if (length > 0) {
|
||||
memmove(dst.ptr, src.ptr, length);
|
||||
@@ -485,11 +487,12 @@ static inline uint64_t puffs_base_slice_u8_copy_from_slice(
|
||||
return length;
|
||||
}
|
||||
|
||||
static inline uint32_t puffs_base_writer1_copy_from_history32(uint8_t** ptr_ptr,
|
||||
uint8_t* start,
|
||||
uint8_t* end,
|
||||
uint32_t distance,
|
||||
uint32_t length) {
|
||||
static inline uint32_t puffs_base__writer1__copy_from_history32(
|
||||
uint8_t** ptr_ptr,
|
||||
uint8_t* start,
|
||||
uint8_t* end,
|
||||
uint32_t distance,
|
||||
uint32_t length) {
|
||||
uint8_t* ptr = *ptr_ptr;
|
||||
size_t d = ptr - start;
|
||||
if ((d == 0) || (d < (size_t)(distance))) {
|
||||
@@ -520,11 +523,12 @@ static inline uint32_t puffs_base_writer1_copy_from_history32(uint8_t** ptr_ptr,
|
||||
return length;
|
||||
}
|
||||
|
||||
static inline uint32_t puffs_base_writer1_copy_from_reader32(uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
uint8_t** ptr_rptr,
|
||||
uint8_t* rend,
|
||||
uint32_t length) {
|
||||
static inline uint32_t puffs_base__writer1__copy_from_reader32(
|
||||
uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
uint8_t** ptr_rptr,
|
||||
uint8_t* rend,
|
||||
uint32_t length) {
|
||||
uint8_t* wptr = *ptr_wptr;
|
||||
size_t n = length;
|
||||
if (n > wend - wptr) {
|
||||
@@ -542,10 +546,10 @@ static inline uint32_t puffs_base_writer1_copy_from_reader32(uint8_t** ptr_wptr,
|
||||
return n;
|
||||
}
|
||||
|
||||
static inline uint64_t puffs_base_writer1_copy_from_slice(
|
||||
static inline uint64_t puffs_base__writer1__copy_from_slice(
|
||||
uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
puffs_base_slice_u8 src) {
|
||||
puffs_base__slice_u8 src) {
|
||||
uint8_t* wptr = *ptr_wptr;
|
||||
size_t n = src.len;
|
||||
if (n > wend - wptr) {
|
||||
@@ -558,10 +562,10 @@ static inline uint64_t puffs_base_writer1_copy_from_slice(
|
||||
return n;
|
||||
}
|
||||
|
||||
static inline uint32_t puffs_base_writer1_copy_from_slice32(
|
||||
static inline uint32_t puffs_base__writer1__copy_from_slice32(
|
||||
uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
puffs_base_slice_u8 src,
|
||||
puffs_base__slice_u8 src,
|
||||
uint32_t length) {
|
||||
uint8_t* wptr = *ptr_wptr;
|
||||
size_t n = src.len;
|
||||
@@ -691,25 +695,25 @@ void puffs_flate__adler32__initialize(puffs_flate__adler32* self,
|
||||
|
||||
puffs_flate__status puffs_flate__flate_decoder__decode_blocks(
|
||||
puffs_flate__flate_decoder* self,
|
||||
puffs_base_writer1 a_dst,
|
||||
puffs_base_reader1 a_src);
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src);
|
||||
|
||||
puffs_flate__status puffs_flate__flate_decoder__decode_uncompressed(
|
||||
puffs_flate__flate_decoder* self,
|
||||
puffs_base_writer1 a_dst,
|
||||
puffs_base_reader1 a_src);
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src);
|
||||
|
||||
puffs_flate__status puffs_flate__flate_decoder__decode_huffman(
|
||||
puffs_flate__flate_decoder* self,
|
||||
puffs_base_writer1 a_dst,
|
||||
puffs_base_reader1 a_src);
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src);
|
||||
|
||||
puffs_flate__status puffs_flate__flate_decoder__init_fixed_huffman(
|
||||
puffs_flate__flate_decoder* self);
|
||||
|
||||
puffs_flate__status puffs_flate__flate_decoder__init_dynamic_huffman(
|
||||
puffs_flate__flate_decoder* self,
|
||||
puffs_base_reader1 a_src);
|
||||
puffs_base__reader1 a_src);
|
||||
|
||||
puffs_flate__status puffs_flate__flate_decoder__init_huff(
|
||||
puffs_flate__flate_decoder* self,
|
||||
@@ -719,7 +723,7 @@ puffs_flate__status puffs_flate__flate_decoder__init_huff(
|
||||
uint32_t a_base_symbol);
|
||||
|
||||
uint32_t puffs_flate__adler32__update(puffs_flate__adler32* self,
|
||||
puffs_base_slice_u8 a_x);
|
||||
puffs_base__slice_u8 a_x);
|
||||
|
||||
// ---------------- Initializer Implementations
|
||||
|
||||
@@ -733,10 +737,10 @@ void puffs_flate__flate_decoder__initialize(puffs_flate__flate_decoder* self,
|
||||
self->private_impl.status = PUFFS_FLATE__ERROR_BAD_PUFFS_VERSION;
|
||||
return;
|
||||
}
|
||||
if (for_internal_use_only != PUFFS_ALREADY_ZEROED) {
|
||||
if (for_internal_use_only != PUFFS_BASE__ALREADY_ZEROED) {
|
||||
memset(self, 0, sizeof(*self));
|
||||
}
|
||||
self->private_impl.magic = PUFFS_MAGIC;
|
||||
self->private_impl.magic = PUFFS_BASE__MAGIC;
|
||||
}
|
||||
|
||||
void puffs_flate__adler32__initialize(puffs_flate__adler32* self,
|
||||
@@ -749,10 +753,10 @@ void puffs_flate__adler32__initialize(puffs_flate__adler32* self,
|
||||
self->private_impl.status = PUFFS_FLATE__ERROR_BAD_PUFFS_VERSION;
|
||||
return;
|
||||
}
|
||||
if (for_internal_use_only != PUFFS_ALREADY_ZEROED) {
|
||||
if (for_internal_use_only != PUFFS_BASE__ALREADY_ZEROED) {
|
||||
memset(self, 0, sizeof(*self));
|
||||
}
|
||||
self->private_impl.magic = PUFFS_MAGIC;
|
||||
self->private_impl.magic = PUFFS_BASE__MAGIC;
|
||||
self->private_impl.f_state = 1;
|
||||
}
|
||||
|
||||
@@ -766,26 +770,26 @@ void puffs_flate__zlib_decoder__initialize(puffs_flate__zlib_decoder* self,
|
||||
self->private_impl.status = PUFFS_FLATE__ERROR_BAD_PUFFS_VERSION;
|
||||
return;
|
||||
}
|
||||
if (for_internal_use_only != PUFFS_ALREADY_ZEROED) {
|
||||
if (for_internal_use_only != PUFFS_BASE__ALREADY_ZEROED) {
|
||||
memset(self, 0, sizeof(*self));
|
||||
}
|
||||
self->private_impl.magic = PUFFS_MAGIC;
|
||||
puffs_flate__flate_decoder__initialize(&self->private_impl.f_flate,
|
||||
PUFFS_VERSION, PUFFS_ALREADY_ZEROED);
|
||||
self->private_impl.magic = PUFFS_BASE__MAGIC;
|
||||
puffs_flate__flate_decoder__initialize(
|
||||
&self->private_impl.f_flate, PUFFS_VERSION, PUFFS_BASE__ALREADY_ZEROED);
|
||||
puffs_flate__adler32__initialize(&self->private_impl.f_adler, PUFFS_VERSION,
|
||||
PUFFS_ALREADY_ZEROED);
|
||||
PUFFS_BASE__ALREADY_ZEROED);
|
||||
}
|
||||
|
||||
// ---------------- Function Implementations
|
||||
|
||||
puffs_flate__status puffs_flate__flate_decoder__decode(
|
||||
puffs_flate__flate_decoder* self,
|
||||
puffs_base_writer1 a_dst,
|
||||
puffs_base_reader1 a_src) {
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src) {
|
||||
if (!self) {
|
||||
return PUFFS_FLATE__ERROR_BAD_RECEIVER;
|
||||
}
|
||||
if (self->private_impl.magic != PUFFS_MAGIC) {
|
||||
if (self->private_impl.magic != PUFFS_BASE__MAGIC) {
|
||||
self->private_impl.status = PUFFS_FLATE__ERROR_INITIALIZER_NOT_CALLED;
|
||||
}
|
||||
if (self->private_impl.status < 0) {
|
||||
@@ -794,7 +798,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode(
|
||||
puffs_flate__status status = PUFFS_FLATE__STATUS_OK;
|
||||
|
||||
puffs_flate__status v_z;
|
||||
puffs_base_slice_u8 v_written;
|
||||
puffs_base__slice_u8 v_written;
|
||||
uint64_t v_n_copied;
|
||||
uint32_t v_already_full;
|
||||
|
||||
@@ -807,7 +811,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode(
|
||||
b_wend_dst = b_wptr_dst;
|
||||
if (!a_dst.buf->closed) {
|
||||
size_t len = a_dst.buf->len - a_dst.buf->wi;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_dst.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -820,19 +824,19 @@ puffs_flate__status puffs_flate__flate_decoder__decode(
|
||||
uint32_t coro_susp_point = self->private_impl.c_decode[0].coro_susp_point;
|
||||
if (coro_susp_point) {
|
||||
v_z = self->private_impl.c_decode[0].v_z;
|
||||
v_written = ((puffs_base_slice_u8){});
|
||||
v_written = ((puffs_base__slice_u8){});
|
||||
v_n_copied = self->private_impl.c_decode[0].v_n_copied;
|
||||
v_already_full = self->private_impl.c_decode[0].v_already_full;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(0);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(0);
|
||||
|
||||
while (true) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(1);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (a_dst.buf) {
|
||||
size_t n = b_wptr_dst - (a_dst.buf->ptr + a_dst.buf->wi);
|
||||
a_dst.buf->wi += n;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_dst.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
@@ -846,7 +850,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode(
|
||||
b_wend_dst = b_wptr_dst;
|
||||
if (!a_dst.buf->closed) {
|
||||
size_t len = a_dst.buf->len - a_dst.buf->wi;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_dst.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -858,31 +862,31 @@ puffs_flate__status puffs_flate__flate_decoder__decode(
|
||||
v_z = t_0;
|
||||
if (!(v_z > 0)) {
|
||||
status = v_z;
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
|
||||
}
|
||||
v_written = ((puffs_base_slice_u8){
|
||||
v_written = ((puffs_base__slice_u8){
|
||||
.ptr = b_wstart_dst,
|
||||
.len = b_wptr_dst - b_wstart_dst,
|
||||
});
|
||||
if (((uint64_t)(v_written.len)) >= 32768) {
|
||||
v_written = puffs_base_slice_u8_suffix(v_written, 32768);
|
||||
puffs_base_slice_u8_copy_from_slice(
|
||||
((puffs_base_slice_u8){.ptr = self->private_impl.f_history,
|
||||
.len = 32768}),
|
||||
v_written = puffs_base__slice_u8_suffix(v_written, 32768);
|
||||
puffs_base__slice_u8__copy_from_slice(
|
||||
((puffs_base__slice_u8){.ptr = self->private_impl.f_history,
|
||||
.len = 32768}),
|
||||
v_written);
|
||||
self->private_impl.f_history_index = 32768;
|
||||
} else {
|
||||
v_n_copied = puffs_base_slice_u8_copy_from_slice(
|
||||
puffs_base_slice_u8_subslice_i(
|
||||
((puffs_base_slice_u8){.ptr = self->private_impl.f_history,
|
||||
.len = 32768}),
|
||||
v_n_copied = puffs_base__slice_u8__copy_from_slice(
|
||||
puffs_base__slice_u8__subslice_i(
|
||||
((puffs_base__slice_u8){.ptr = self->private_impl.f_history,
|
||||
.len = 32768}),
|
||||
self->private_impl.f_history_index & 32767),
|
||||
v_written);
|
||||
if (v_n_copied < ((uint64_t)(v_written.len))) {
|
||||
v_written = puffs_base_slice_u8_subslice_i(v_written, v_n_copied);
|
||||
v_n_copied = puffs_base_slice_u8_copy_from_slice(
|
||||
((puffs_base_slice_u8){.ptr = self->private_impl.f_history,
|
||||
.len = 32768}),
|
||||
v_written = puffs_base__slice_u8__subslice_i(v_written, v_n_copied);
|
||||
v_n_copied = puffs_base__slice_u8__copy_from_slice(
|
||||
((puffs_base__slice_u8){.ptr = self->private_impl.f_history,
|
||||
.len = 32768}),
|
||||
v_written);
|
||||
self->private_impl.f_history_index =
|
||||
(((uint32_t)((v_n_copied & 32767))) + 32768);
|
||||
@@ -897,7 +901,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode(
|
||||
}
|
||||
}
|
||||
status = v_z;
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
}
|
||||
|
||||
goto ok;
|
||||
@@ -917,14 +921,14 @@ exit:
|
||||
if (a_dst.buf) {
|
||||
size_t n = b_wptr_dst - (a_dst.buf->ptr + a_dst.buf->wi);
|
||||
a_dst.buf->wi += n;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_dst.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wstart_dst);
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wend_dst);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wstart_dst);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wend_dst);
|
||||
}
|
||||
|
||||
self->private_impl.status = status;
|
||||
@@ -933,8 +937,8 @@ exit:
|
||||
|
||||
puffs_flate__status puffs_flate__flate_decoder__decode_blocks(
|
||||
puffs_flate__flate_decoder* self,
|
||||
puffs_base_writer1 a_dst,
|
||||
puffs_base_reader1 a_src) {
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src) {
|
||||
puffs_flate__status status = PUFFS_FLATE__STATUS_OK;
|
||||
|
||||
uint32_t v_final;
|
||||
@@ -947,7 +951,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode_blocks(
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
b_rstart_src = b_rptr_src;
|
||||
size_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -963,14 +967,14 @@ puffs_flate__status puffs_flate__flate_decoder__decode_blocks(
|
||||
v_type = self->private_impl.c_decode_blocks[0].v_type;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(0);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(0);
|
||||
|
||||
v_final = 0;
|
||||
label_0_continue:;
|
||||
while (v_final == 0) {
|
||||
while (self->private_impl.f_n_bits < 3) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(1);
|
||||
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_0 = *b_rptr_src++;
|
||||
@@ -983,11 +987,11 @@ puffs_flate__status puffs_flate__flate_decoder__decode_blocks(
|
||||
self->private_impl.f_bits >>= 3;
|
||||
self->private_impl.f_n_bits -= 3;
|
||||
if (v_type == 0) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(2);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (a_src.buf) {
|
||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||
a_src.buf->ri += n;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
@@ -999,7 +1003,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode_blocks(
|
||||
if (a_src.buf) {
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
size_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -1012,17 +1016,17 @@ puffs_flate__status puffs_flate__flate_decoder__decode_blocks(
|
||||
}
|
||||
goto label_0_continue;
|
||||
} else if (v_type == 1) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(3);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
status = puffs_flate__flate_decoder__init_fixed_huffman(self);
|
||||
if (status) {
|
||||
goto suspend;
|
||||
}
|
||||
} else if (v_type == 2) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(4);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
if (a_src.buf) {
|
||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||
a_src.buf->ri += n;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
@@ -1033,7 +1037,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode_blocks(
|
||||
if (a_src.buf) {
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
size_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -1048,11 +1052,11 @@ puffs_flate__status puffs_flate__flate_decoder__decode_blocks(
|
||||
status = PUFFS_FLATE__ERROR_BAD_FLATE_BLOCK;
|
||||
goto exit;
|
||||
}
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(5);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
if (a_src.buf) {
|
||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||
a_src.buf->ri += n;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
@@ -1063,7 +1067,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode_blocks(
|
||||
if (a_src.buf) {
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
size_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -1092,14 +1096,14 @@ exit:
|
||||
if (a_src.buf) {
|
||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||
a_src.buf->ri += n;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -1115,8 +1119,8 @@ short_read_src:
|
||||
|
||||
puffs_flate__status puffs_flate__flate_decoder__decode_uncompressed(
|
||||
puffs_flate__flate_decoder* self,
|
||||
puffs_base_writer1 a_dst,
|
||||
puffs_base_reader1 a_src) {
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src) {
|
||||
puffs_flate__status status = PUFFS_FLATE__STATUS_OK;
|
||||
|
||||
uint32_t v_length;
|
||||
@@ -1131,7 +1135,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode_uncompressed(
|
||||
b_wend_dst = b_wptr_dst;
|
||||
if (!a_dst.buf->closed) {
|
||||
size_t len = a_dst.buf->len - a_dst.buf->wi;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_dst.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -1147,7 +1151,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode_uncompressed(
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
b_rstart_src = b_rptr_src;
|
||||
size_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -1163,23 +1167,23 @@ puffs_flate__status puffs_flate__flate_decoder__decode_uncompressed(
|
||||
v_n_copied = self->private_impl.c_decode_uncompressed[0].v_n_copied;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(0);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(0);
|
||||
|
||||
if (self->private_impl.f_n_bits >= 8) {
|
||||
status = PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS;
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_n_bits = 0;
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(1);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
uint32_t t_1;
|
||||
if (PUFFS_LIKELY(b_rend_src - b_rptr_src >= 4)) {
|
||||
t_1 = puffs_base_load_u32le(b_rptr_src);
|
||||
if (PUFFS_BASE__LIKELY(b_rend_src - b_rptr_src >= 4)) {
|
||||
t_1 = puffs_base__load_u32le(b_rptr_src);
|
||||
b_rptr_src += 4;
|
||||
} else {
|
||||
self->private_impl.c_decode_uncompressed[0].scratch = 0;
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(2);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
while (true) {
|
||||
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint32_t t_0 =
|
||||
@@ -1205,7 +1209,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode_uncompressed(
|
||||
}
|
||||
v_length = ((v_length) & ((1 << (16)) - 1));
|
||||
while (true) {
|
||||
v_n_copied = puffs_base_writer1_copy_from_reader32(
|
||||
v_n_copied = puffs_base__writer1__copy_from_reader32(
|
||||
&b_wptr_dst, b_wend_dst, &b_rptr_src, b_rend_src, v_length);
|
||||
if (v_length <= v_n_copied) {
|
||||
v_length = 0;
|
||||
@@ -1214,10 +1218,10 @@ puffs_flate__status puffs_flate__flate_decoder__decode_uncompressed(
|
||||
v_length -= v_n_copied;
|
||||
if (((uint64_t)(b_wend_dst - b_wptr_dst)) == 0) {
|
||||
status = PUFFS_FLATE__SUSPENSION_SHORT_WRITE;
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
} else {
|
||||
status = PUFFS_FLATE__SUSPENSION_SHORT_READ;
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
||||
}
|
||||
}
|
||||
label_0_break:;
|
||||
@@ -1238,26 +1242,26 @@ exit:
|
||||
if (a_dst.buf) {
|
||||
size_t n = b_wptr_dst - (a_dst.buf->ptr + a_dst.buf->wi);
|
||||
a_dst.buf->wi += n;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_dst.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wstart_dst);
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wend_dst);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wstart_dst);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wend_dst);
|
||||
}
|
||||
if (a_src.buf) {
|
||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||
a_src.buf->ri += n;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -1273,8 +1277,8 @@ short_read_src:
|
||||
|
||||
puffs_flate__status puffs_flate__flate_decoder__decode_huffman(
|
||||
puffs_flate__flate_decoder* self,
|
||||
puffs_base_writer1 a_dst,
|
||||
puffs_base_reader1 a_src) {
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src) {
|
||||
puffs_flate__status status = PUFFS_FLATE__STATUS_OK;
|
||||
|
||||
uint32_t v_bits;
|
||||
@@ -1300,7 +1304,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode_huffman(
|
||||
b_wend_dst = b_wptr_dst;
|
||||
if (!a_dst.buf->closed) {
|
||||
size_t len = a_dst.buf->len - a_dst.buf->wi;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_dst.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -1316,7 +1320,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode_huffman(
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
b_rstart_src = b_rptr_src;
|
||||
size_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -1344,7 +1348,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode_huffman(
|
||||
v_hdist = self->private_impl.c_decode_huffman[0].v_hdist;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(0);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(0);
|
||||
|
||||
v_bits = self->private_impl.f_bits;
|
||||
v_n_bits = self->private_impl.f_n_bits;
|
||||
@@ -1362,8 +1366,8 @@ puffs_flate__status puffs_flate__flate_decoder__decode_huffman(
|
||||
v_n_bits -= v_table_entry_n_bits;
|
||||
goto label_1_break;
|
||||
}
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(1);
|
||||
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_0 = *b_rptr_src++;
|
||||
@@ -1389,8 +1393,8 @@ puffs_flate__status puffs_flate__flate_decoder__decode_huffman(
|
||||
v_n_bits -= v_table_entry_n_bits;
|
||||
goto label_2_break;
|
||||
}
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(2);
|
||||
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_1 = *b_rptr_src++;
|
||||
@@ -1405,7 +1409,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode_huffman(
|
||||
}
|
||||
}
|
||||
if ((v_table_entry >> 31) != 0) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(3);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
if (b_wptr_dst == b_wend_dst) {
|
||||
status = PUFFS_FLATE__SUSPENSION_SHORT_WRITE;
|
||||
goto suspend;
|
||||
@@ -1426,8 +1430,8 @@ puffs_flate__status puffs_flate__flate_decoder__decode_huffman(
|
||||
v_length = ((v_table_entry >> 8) & 32767);
|
||||
v_table_entry_n_bits = ((v_table_entry >> 4) & 15);
|
||||
while (v_n_bits < v_table_entry_n_bits) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(4);
|
||||
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_2 = *b_rptr_src++;
|
||||
@@ -1447,8 +1451,8 @@ puffs_flate__status puffs_flate__flate_decoder__decode_huffman(
|
||||
v_n_bits -= v_table_entry_n_bits;
|
||||
goto label_3_break;
|
||||
}
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(5);
|
||||
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_3 = *b_rptr_src++;
|
||||
@@ -1474,8 +1478,8 @@ puffs_flate__status puffs_flate__flate_decoder__decode_huffman(
|
||||
v_n_bits -= v_table_entry_n_bits;
|
||||
goto label_4_break;
|
||||
}
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(6);
|
||||
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_4 = *b_rptr_src++;
|
||||
@@ -1501,8 +1505,8 @@ puffs_flate__status puffs_flate__flate_decoder__decode_huffman(
|
||||
v_distance = ((v_table_entry >> 8) & 32767);
|
||||
v_table_entry_n_bits = ((v_table_entry >> 4) & 15);
|
||||
while (v_n_bits < v_table_entry_n_bits) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(7);
|
||||
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_5 = *b_rptr_src++;
|
||||
@@ -1534,11 +1538,11 @@ puffs_flate__status puffs_flate__flate_decoder__decode_huffman(
|
||||
}
|
||||
v_hdist = ((self->private_impl.f_history_index - v_hdist) & 32767);
|
||||
while (true) {
|
||||
v_n_copied = puffs_base_writer1_copy_from_slice32(
|
||||
v_n_copied = puffs_base__writer1__copy_from_slice32(
|
||||
&b_wptr_dst, b_wend_dst,
|
||||
puffs_base_slice_u8_subslice_i(
|
||||
((puffs_base_slice_u8){.ptr = self->private_impl.f_history,
|
||||
.len = 32768}),
|
||||
puffs_base__slice_u8__subslice_i(
|
||||
((puffs_base__slice_u8){.ptr = self->private_impl.f_history,
|
||||
.len = 32768}),
|
||||
v_hdist),
|
||||
v_hlen);
|
||||
if (v_hlen <= v_n_copied) {
|
||||
@@ -1553,15 +1557,15 @@ puffs_flate__status puffs_flate__flate_decoder__decode_huffman(
|
||||
}
|
||||
}
|
||||
status = PUFFS_FLATE__SUSPENSION_SHORT_WRITE;
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(8);
|
||||
}
|
||||
label_5_break:;
|
||||
if (v_hlen > 0) {
|
||||
while (true) {
|
||||
v_n_copied = puffs_base_writer1_copy_from_slice32(
|
||||
v_n_copied = puffs_base__writer1__copy_from_slice32(
|
||||
&b_wptr_dst, b_wend_dst,
|
||||
puffs_base_slice_u8_subslice_i(
|
||||
((puffs_base_slice_u8){
|
||||
puffs_base__slice_u8__subslice_i(
|
||||
((puffs_base__slice_u8){
|
||||
.ptr = self->private_impl.f_history, .len = 32768}),
|
||||
v_hdist),
|
||||
v_hlen);
|
||||
@@ -1572,7 +1576,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode_huffman(
|
||||
v_hlen -= v_n_copied;
|
||||
v_hdist = ((v_hdist + (v_n_copied & 32767)) & 32767);
|
||||
status = PUFFS_FLATE__SUSPENSION_SHORT_WRITE;
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
|
||||
}
|
||||
label_6_break:;
|
||||
}
|
||||
@@ -1580,7 +1584,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode_huffman(
|
||||
goto label_0_continue;
|
||||
}
|
||||
}
|
||||
v_n_copied = puffs_base_writer1_copy_from_history32(
|
||||
v_n_copied = puffs_base__writer1__copy_from_history32(
|
||||
&b_wptr_dst, b_wstart_dst, b_wend_dst, v_distance, v_length);
|
||||
if (v_length <= v_n_copied) {
|
||||
v_length = 0;
|
||||
@@ -1588,7 +1592,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode_huffman(
|
||||
}
|
||||
v_length -= v_n_copied;
|
||||
status = PUFFS_FLATE__SUSPENSION_SHORT_WRITE;
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
}
|
||||
label_7_break:;
|
||||
}
|
||||
@@ -1624,26 +1628,26 @@ exit:
|
||||
if (a_dst.buf) {
|
||||
size_t n = b_wptr_dst - (a_dst.buf->ptr + a_dst.buf->wi);
|
||||
a_dst.buf->wi += n;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_dst.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wstart_dst);
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wend_dst);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wstart_dst);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wend_dst);
|
||||
}
|
||||
if (a_src.buf) {
|
||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||
a_src.buf->ri += n;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -1669,7 +1673,7 @@ puffs_flate__status puffs_flate__flate_decoder__init_fixed_huffman(
|
||||
v_i = self->private_impl.c_init_fixed_huffman[0].v_i;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(0);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(0);
|
||||
|
||||
v_i = 0;
|
||||
while (v_i < 144) {
|
||||
@@ -1692,12 +1696,12 @@ puffs_flate__status puffs_flate__flate_decoder__init_fixed_huffman(
|
||||
self->private_impl.f_code_lengths[v_i] = 5;
|
||||
v_i += 1;
|
||||
}
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(1);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
status = puffs_flate__flate_decoder__init_huff(self, 0, 0, 288, 257);
|
||||
if (status) {
|
||||
goto suspend;
|
||||
}
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(2);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
status = puffs_flate__flate_decoder__init_huff(self, 1, 288, 320, 0);
|
||||
if (status) {
|
||||
goto suspend;
|
||||
@@ -1720,7 +1724,7 @@ exit:
|
||||
|
||||
puffs_flate__status puffs_flate__flate_decoder__init_dynamic_huffman(
|
||||
puffs_flate__flate_decoder* self,
|
||||
puffs_base_reader1 a_src) {
|
||||
puffs_base__reader1 a_src) {
|
||||
puffs_flate__status status = PUFFS_FLATE__STATUS_OK;
|
||||
|
||||
uint32_t v_bits;
|
||||
@@ -1743,7 +1747,7 @@ puffs_flate__status puffs_flate__flate_decoder__init_dynamic_huffman(
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
b_rstart_src = b_rptr_src;
|
||||
size_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -1771,13 +1775,13 @@ puffs_flate__status puffs_flate__flate_decoder__init_dynamic_huffman(
|
||||
v_rep_count = self->private_impl.c_init_dynamic_huffman[0].v_rep_count;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(0);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(0);
|
||||
|
||||
v_bits = self->private_impl.f_bits;
|
||||
v_n_bits = self->private_impl.f_n_bits;
|
||||
while (v_n_bits < 14) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(1);
|
||||
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_0 = *b_rptr_src++;
|
||||
@@ -1802,8 +1806,8 @@ puffs_flate__status puffs_flate__flate_decoder__init_dynamic_huffman(
|
||||
v_i = 0;
|
||||
while (v_i < v_n_clen) {
|
||||
while (v_n_bits < 3) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(2);
|
||||
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_1 = *b_rptr_src++;
|
||||
@@ -1820,7 +1824,7 @@ puffs_flate__status puffs_flate__flate_decoder__init_dynamic_huffman(
|
||||
self->private_impl.f_code_lengths[puffs_flate__code_order[v_i]] = 0;
|
||||
v_i += 1;
|
||||
}
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(3);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
status = puffs_flate__flate_decoder__init_huff(self, 0, 0, 19, 4095);
|
||||
if (status) {
|
||||
goto suspend;
|
||||
@@ -1838,8 +1842,8 @@ puffs_flate__status puffs_flate__flate_decoder__init_dynamic_huffman(
|
||||
v_n_bits -= v_table_entry_n_bits;
|
||||
goto label_1_break;
|
||||
}
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(4);
|
||||
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_2 = *b_rptr_src++;
|
||||
@@ -1883,8 +1887,8 @@ puffs_flate__status puffs_flate__flate_decoder__init_dynamic_huffman(
|
||||
goto exit;
|
||||
}
|
||||
while (v_n_bits < v_n_extra_bits) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(5);
|
||||
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_3 = *b_rptr_src++;
|
||||
@@ -1912,12 +1916,12 @@ puffs_flate__status puffs_flate__flate_decoder__init_dynamic_huffman(
|
||||
status = PUFFS_FLATE__ERROR_MISSING_END_OF_BLOCK_CODE;
|
||||
goto exit;
|
||||
}
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(6);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
status = puffs_flate__flate_decoder__init_huff(self, 0, 0, v_n_lit, 257);
|
||||
if (status) {
|
||||
goto suspend;
|
||||
}
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(7);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
status = puffs_flate__flate_decoder__init_huff(self, 1, v_n_lit,
|
||||
(v_n_lit + v_n_dist), 0);
|
||||
if (status) {
|
||||
@@ -1954,14 +1958,14 @@ exit:
|
||||
if (a_src.buf) {
|
||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||
a_src.buf->ri += n;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -2257,12 +2261,12 @@ exit:
|
||||
|
||||
puffs_flate__status puffs_flate__zlib_decoder__decode(
|
||||
puffs_flate__zlib_decoder* self,
|
||||
puffs_base_writer1 a_dst,
|
||||
puffs_base_reader1 a_src) {
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src) {
|
||||
if (!self) {
|
||||
return PUFFS_FLATE__ERROR_BAD_RECEIVER;
|
||||
}
|
||||
if (self->private_impl.magic != PUFFS_MAGIC) {
|
||||
if (self->private_impl.magic != PUFFS_BASE__MAGIC) {
|
||||
self->private_impl.status = PUFFS_FLATE__ERROR_INITIALIZER_NOT_CALLED;
|
||||
}
|
||||
if (self->private_impl.status < 0) {
|
||||
@@ -2283,7 +2287,7 @@ puffs_flate__status puffs_flate__zlib_decoder__decode(
|
||||
b_wend_dst = b_wptr_dst;
|
||||
if (!a_dst.buf->closed) {
|
||||
size_t len = a_dst.buf->len - a_dst.buf->wi;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_dst.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -2299,7 +2303,7 @@ puffs_flate__status puffs_flate__zlib_decoder__decode(
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
b_rstart_src = b_rptr_src;
|
||||
size_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -2315,18 +2319,18 @@ puffs_flate__status puffs_flate__zlib_decoder__decode(
|
||||
v_z = self->private_impl.c_decode[0].v_z;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(0);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(0);
|
||||
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(1);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
uint16_t t_1;
|
||||
if (PUFFS_LIKELY(b_rend_src - b_rptr_src >= 2)) {
|
||||
t_1 = puffs_base_load_u16be(b_rptr_src);
|
||||
if (PUFFS_BASE__LIKELY(b_rend_src - b_rptr_src >= 2)) {
|
||||
t_1 = puffs_base__load_u16be(b_rptr_src);
|
||||
b_rptr_src += 2;
|
||||
} else {
|
||||
self->private_impl.c_decode[0].scratch = 0;
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(2);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
while (true) {
|
||||
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint32_t t_0 = self->private_impl.c_decode[0].scratch & 0xFF;
|
||||
@@ -2361,11 +2365,11 @@ puffs_flate__status puffs_flate__zlib_decoder__decode(
|
||||
}
|
||||
v_checksum = 0;
|
||||
while (true) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(3);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
if (a_dst.buf) {
|
||||
size_t n = b_wptr_dst - (a_dst.buf->ptr + a_dst.buf->wi);
|
||||
a_dst.buf->wi += n;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_dst.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
@@ -2375,7 +2379,7 @@ puffs_flate__status puffs_flate__zlib_decoder__decode(
|
||||
if (a_src.buf) {
|
||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||
a_src.buf->ri += n;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
@@ -2389,7 +2393,7 @@ puffs_flate__status puffs_flate__zlib_decoder__decode(
|
||||
b_wend_dst = b_wptr_dst;
|
||||
if (!a_dst.buf->closed) {
|
||||
size_t len = a_dst.buf->len - a_dst.buf->wi;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_dst.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -2401,7 +2405,7 @@ puffs_flate__status puffs_flate__zlib_decoder__decode(
|
||||
if (a_src.buf) {
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
size_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -2411,7 +2415,7 @@ puffs_flate__status puffs_flate__zlib_decoder__decode(
|
||||
}
|
||||
v_z = t_2;
|
||||
v_checksum = puffs_flate__adler32__update(
|
||||
&self->private_impl.f_adler, ((puffs_base_slice_u8){
|
||||
&self->private_impl.f_adler, ((puffs_base__slice_u8){
|
||||
.ptr = b_wstart_dst,
|
||||
.len = b_wptr_dst - b_wstart_dst,
|
||||
}));
|
||||
@@ -2419,19 +2423,19 @@ puffs_flate__status puffs_flate__zlib_decoder__decode(
|
||||
goto label_0_break;
|
||||
}
|
||||
status = v_z;
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
||||
}
|
||||
label_0_break:;
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(5);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
uint32_t t_4;
|
||||
if (PUFFS_LIKELY(b_rend_src - b_rptr_src >= 4)) {
|
||||
t_4 = puffs_base_load_u32be(b_rptr_src);
|
||||
if (PUFFS_BASE__LIKELY(b_rend_src - b_rptr_src >= 4)) {
|
||||
t_4 = puffs_base__load_u32be(b_rptr_src);
|
||||
b_rptr_src += 4;
|
||||
} else {
|
||||
self->private_impl.c_decode[0].scratch = 0;
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(6);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
while (true) {
|
||||
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint32_t t_3 = self->private_impl.c_decode[0].scratch & 0xFF;
|
||||
@@ -2469,26 +2473,26 @@ exit:
|
||||
if (a_dst.buf) {
|
||||
size_t n = b_wptr_dst - (a_dst.buf->ptr + a_dst.buf->wi);
|
||||
a_dst.buf->wi += n;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_dst.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wstart_dst);
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wend_dst);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wstart_dst);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wend_dst);
|
||||
}
|
||||
if (a_src.buf) {
|
||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||
a_src.buf->ri += n;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
}
|
||||
|
||||
self->private_impl.status = status;
|
||||
@@ -2504,21 +2508,21 @@ short_read_src:
|
||||
}
|
||||
|
||||
uint32_t puffs_flate__adler32__update(puffs_flate__adler32* self,
|
||||
puffs_base_slice_u8 a_x) {
|
||||
puffs_base__slice_u8 a_x) {
|
||||
uint32_t v_s1;
|
||||
uint32_t v_s2;
|
||||
puffs_base_slice_u8 v_remaining;
|
||||
puffs_base__slice_u8 v_remaining;
|
||||
|
||||
v_s1 = ((self->private_impl.f_state) & ((1 << (16)) - 1));
|
||||
v_s2 = ((self->private_impl.f_state) >> (32 - (16)));
|
||||
while (((uint64_t)(a_x.len)) > 0) {
|
||||
v_remaining = ((puffs_base_slice_u8){});
|
||||
v_remaining = ((puffs_base__slice_u8){});
|
||||
if (((uint64_t)(a_x.len)) > 5552) {
|
||||
v_remaining = puffs_base_slice_u8_subslice_i(a_x, 5552);
|
||||
a_x = puffs_base_slice_u8_subslice_j(a_x, 5552);
|
||||
v_remaining = puffs_base__slice_u8__subslice_i(a_x, 5552);
|
||||
a_x = puffs_base__slice_u8__subslice_j(a_x, 5552);
|
||||
}
|
||||
{
|
||||
puffs_base_slice_u8 i_slice_p = a_x;
|
||||
puffs_base__slice_u8 i_slice_p = a_x;
|
||||
uint8_t* v_p = i_slice_p.ptr;
|
||||
uint8_t* i_end0_p = i_slice_p.ptr + (i_slice_p.len / 8) * 8;
|
||||
while (v_p < i_end0_p) {
|
||||
|
||||
+200
-196
@@ -48,15 +48,15 @@
|
||||
// TODO: don't hard code this in base-header.h.
|
||||
#define PUFFS_VERSION (0x00001)
|
||||
|
||||
// puffs_base_slice_u8 is a 1-dimensional buffer (a pointer and length).
|
||||
// puffs_base__slice_u8 is a 1-dimensional buffer (a pointer and length).
|
||||
//
|
||||
// A value with all fields NULL or zero is a valid, empty slice.
|
||||
typedef struct {
|
||||
uint8_t* ptr;
|
||||
size_t len;
|
||||
} puffs_base_slice_u8;
|
||||
} puffs_base__slice_u8;
|
||||
|
||||
// puffs_base_buf1 is a 1-dimensional buffer (a pointer and length), plus
|
||||
// puffs_base__buf1 is a 1-dimensional buffer (a pointer and length), plus
|
||||
// additional indexes into that buffer, plus an opened / closed flag.
|
||||
//
|
||||
// A value with all fields NULL or zero is a valid, empty buffer.
|
||||
@@ -66,28 +66,28 @@ typedef struct {
|
||||
size_t wi; // Write index. Invariant: wi <= len.
|
||||
size_t ri; // Read index. Invariant: ri <= wi.
|
||||
bool closed; // No further writes are expected.
|
||||
} puffs_base_buf1;
|
||||
} puffs_base__buf1;
|
||||
|
||||
// puffs_base_limit1 provides a limited view of a 1-dimensional byte stream:
|
||||
// puffs_base__limit1 provides a limited view of a 1-dimensional byte stream:
|
||||
// its first N bytes. That N can be greater than a buffer's current read or
|
||||
// write capacity. N decreases naturally over time as bytes are read from or
|
||||
// written to the stream.
|
||||
//
|
||||
// A value with all fields NULL or zero is a valid, unlimited view.
|
||||
typedef struct puffs_base_limit1 {
|
||||
uint64_t* ptr_to_len; // Pointer to N.
|
||||
struct puffs_base_limit1* next; // Linked list of limits.
|
||||
} puffs_base_limit1;
|
||||
typedef struct puffs_base__limit1 {
|
||||
uint64_t* ptr_to_len; // Pointer to N.
|
||||
struct puffs_base__limit1* next; // Linked list of limits.
|
||||
} puffs_base__limit1;
|
||||
|
||||
typedef struct {
|
||||
puffs_base_buf1* buf;
|
||||
puffs_base_limit1 limit;
|
||||
} puffs_base_reader1;
|
||||
puffs_base__buf1* buf;
|
||||
puffs_base__limit1 limit;
|
||||
} puffs_base__reader1;
|
||||
|
||||
typedef struct {
|
||||
puffs_base_buf1* buf;
|
||||
puffs_base_limit1 limit;
|
||||
} puffs_base_writer1;
|
||||
puffs_base__buf1* buf;
|
||||
puffs_base__limit1 limit;
|
||||
} puffs_base__writer1;
|
||||
|
||||
#endif // PUFFS_BASE_HEADER_H
|
||||
|
||||
@@ -217,7 +217,7 @@ typedef struct {
|
||||
uint8_t v_lw;
|
||||
uint8_t v_block_size;
|
||||
uint64_t l_lzw_src;
|
||||
puffs_base_reader1 v_lzw_src;
|
||||
puffs_base__reader1 v_lzw_src;
|
||||
} c_decode_id[1];
|
||||
} private_impl;
|
||||
} puffs_gif__decoder;
|
||||
@@ -245,15 +245,15 @@ void puffs_gif__decoder__initialize(puffs_gif__decoder* self,
|
||||
// ---------------- Public Function Prototypes
|
||||
|
||||
puffs_gif__status puffs_gif__decoder__decode(puffs_gif__decoder* self,
|
||||
puffs_base_writer1 a_dst,
|
||||
puffs_base_reader1 a_src);
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src);
|
||||
|
||||
void puffs_gif__lzw_decoder__set_literal_width(puffs_gif__lzw_decoder* self,
|
||||
uint32_t a_lw);
|
||||
|
||||
puffs_gif__status puffs_gif__lzw_decoder__decode(puffs_gif__lzw_decoder* self,
|
||||
puffs_base_writer1 a_dst,
|
||||
puffs_base_reader1 a_src);
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
@@ -280,51 +280,51 @@ puffs_gif__status puffs_gif__lzw_decoder__decode(puffs_gif__lzw_decoder* self,
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#define PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(x) (void)(x)
|
||||
#define PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(x) (void)(x)
|
||||
|
||||
// PUFFS_MAGIC is a magic number to check that initializers are called. It's
|
||||
// not foolproof, given C doesn't automatically zero memory before use, but it
|
||||
// should catch 99.99% of cases.
|
||||
// PUFFS_BASE__MAGIC is a magic number to check that initializers are called.
|
||||
// It's not foolproof, given C doesn't automatically zero memory before use,
|
||||
// but it should catch 99.99% of cases.
|
||||
//
|
||||
// Its (non-zero) value is arbitrary, based on md5sum("puffs").
|
||||
#define PUFFS_MAGIC (0xCB3699CCU)
|
||||
#define PUFFS_BASE__MAGIC (0xCB3699CCU)
|
||||
|
||||
// PUFFS_ALREADY_ZEROED is passed from a container struct's initializer to a
|
||||
// containee struct's initializer when the container has already zeroed the
|
||||
// containee's memory.
|
||||
// PUFFS_BASE__ALREADY_ZEROED is passed from a container struct's initializer
|
||||
// to a containee struct's initializer when the container has already zeroed
|
||||
// the containee's memory.
|
||||
//
|
||||
// Its (non-zero) value is arbitrary, based on md5sum("zeroed").
|
||||
#define PUFFS_ALREADY_ZEROED (0x68602EF1U)
|
||||
#define PUFFS_BASE__ALREADY_ZEROED (0x68602EF1U)
|
||||
|
||||
// Use switch cases for coroutine suspension points, similar to the technique
|
||||
// in https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
|
||||
//
|
||||
// We use a trivial macro instead of an explicit assignment and case statement
|
||||
// so that clang-format doesn't get confused by the unusual "case"s.
|
||||
#define PUFFS_COROUTINE_SUSPENSION_POINT(n) \
|
||||
coro_susp_point = n; \
|
||||
#define PUFFS_BASE__COROUTINE_SUSPENSION_POINT(n) \
|
||||
coro_susp_point = n; \
|
||||
case n:;
|
||||
|
||||
#define PUFFS_COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \
|
||||
if (status < 0) { \
|
||||
goto exit; \
|
||||
} else if (status == 0) { \
|
||||
goto ok; \
|
||||
} \
|
||||
coro_susp_point = n; \
|
||||
goto suspend; \
|
||||
#define PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \
|
||||
if (status < 0) { \
|
||||
goto exit; \
|
||||
} else if (status == 0) { \
|
||||
goto ok; \
|
||||
} \
|
||||
coro_susp_point = n; \
|
||||
goto suspend; \
|
||||
case n:;
|
||||
|
||||
// Clang also defines "__GNUC__".
|
||||
#if defined(__GNUC__)
|
||||
#define PUFFS_LIKELY(expr) (__builtin_expect(!!(expr), 1))
|
||||
#define PUFFS_UNLIKELY(expr) (__builtin_expect(!!(expr), 0))
|
||||
#define PUFFS_BASE__LIKELY(expr) (__builtin_expect(!!(expr), 1))
|
||||
#define PUFFS_BASE__UNLIKELY(expr) (__builtin_expect(!!(expr), 0))
|
||||
// Declare the printf prototype. The generated code shouldn't need this at all,
|
||||
// but it's useful for manual printf debugging.
|
||||
extern int printf(const char* __restrict __format, ...);
|
||||
#else
|
||||
#define PUFFS_LIKELY(expr) (expr)
|
||||
#define PUFFS_UNLIKELY(expr) (expr)
|
||||
#define PUFFS_BASE__LIKELY(expr) (expr)
|
||||
#define PUFFS_BASE__UNLIKELY(expr) (expr)
|
||||
#endif
|
||||
|
||||
// ---------------- Static Inline Functions
|
||||
@@ -345,59 +345,61 @@ extern int printf(const char* __restrict __format, ...);
|
||||
// inline attribute to guide optimizations such as inlining, to avoid the
|
||||
// -Wunused-function warning, and we like to compile with -Wall -Werror.
|
||||
|
||||
static inline uint16_t puffs_base_load_u16be(uint8_t* p) {
|
||||
static inline uint16_t puffs_base__load_u16be(uint8_t* p) {
|
||||
return ((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0);
|
||||
}
|
||||
|
||||
static inline uint16_t puffs_base_load_u16le(uint8_t* p) {
|
||||
static inline uint16_t puffs_base__load_u16le(uint8_t* p) {
|
||||
return ((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8);
|
||||
}
|
||||
|
||||
static inline uint32_t puffs_base_load_u32be(uint8_t* p) {
|
||||
static inline uint32_t puffs_base__load_u32be(uint8_t* p) {
|
||||
return ((uint32_t)(p[0]) << 24) | ((uint32_t)(p[1]) << 16) |
|
||||
((uint32_t)(p[2]) << 8) | ((uint32_t)(p[3]) << 0);
|
||||
}
|
||||
|
||||
static inline uint32_t puffs_base_load_u32le(uint8_t* p) {
|
||||
static inline uint32_t puffs_base__load_u32le(uint8_t* p) {
|
||||
return ((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) |
|
||||
((uint32_t)(p[2]) << 16) | ((uint32_t)(p[3]) << 24);
|
||||
}
|
||||
|
||||
static inline puffs_base_slice_u8 puffs_base_slice_u8_subslice_i(
|
||||
puffs_base_slice_u8 s,
|
||||
static inline puffs_base__slice_u8 puffs_base__slice_u8__subslice_i(
|
||||
puffs_base__slice_u8 s,
|
||||
uint64_t i) {
|
||||
if ((i <= SIZE_MAX) && (i <= s.len)) {
|
||||
return ((puffs_base_slice_u8){
|
||||
return ((puffs_base__slice_u8){
|
||||
.ptr = s.ptr + i,
|
||||
.len = s.len - i,
|
||||
});
|
||||
}
|
||||
return ((puffs_base_slice_u8){});
|
||||
return ((puffs_base__slice_u8){});
|
||||
}
|
||||
|
||||
static inline puffs_base_slice_u8 puffs_base_slice_u8_subslice_j(
|
||||
puffs_base_slice_u8 s,
|
||||
static inline puffs_base__slice_u8 puffs_base__slice_u8__subslice_j(
|
||||
puffs_base__slice_u8 s,
|
||||
uint64_t j) {
|
||||
if ((j <= SIZE_MAX) && (j <= s.len)) {
|
||||
return ((puffs_base_slice_u8){.ptr = s.ptr, .len = j});
|
||||
return ((puffs_base__slice_u8){.ptr = s.ptr, .len = j});
|
||||
}
|
||||
return ((puffs_base_slice_u8){});
|
||||
return ((puffs_base__slice_u8){});
|
||||
}
|
||||
|
||||
static inline puffs_base_slice_u8
|
||||
puffs_base_slice_u8_subslice_ij(puffs_base_slice_u8 s, uint64_t i, uint64_t j) {
|
||||
static inline puffs_base__slice_u8 puffs_base__slice_u8__subslice_ij(
|
||||
puffs_base__slice_u8 s,
|
||||
uint64_t i,
|
||||
uint64_t j) {
|
||||
if ((i <= j) && (j <= SIZE_MAX) && (j <= s.len)) {
|
||||
return ((puffs_base_slice_u8){
|
||||
return ((puffs_base__slice_u8){
|
||||
.ptr = s.ptr + i,
|
||||
.len = j - i,
|
||||
});
|
||||
}
|
||||
return ((puffs_base_slice_u8){});
|
||||
return ((puffs_base__slice_u8){});
|
||||
}
|
||||
|
||||
// puffs_base_slice_u8_prefix returns up to the first up_to bytes of s.
|
||||
static inline puffs_base_slice_u8 puffs_base_slice_u8_prefix(
|
||||
puffs_base_slice_u8 s,
|
||||
// puffs_base__slice_u8__prefix returns up to the first up_to bytes of s.
|
||||
static inline puffs_base__slice_u8 puffs_base__slice_u8__prefix(
|
||||
puffs_base__slice_u8 s,
|
||||
uint64_t up_to) {
|
||||
if ((uint64_t)(s.len) > up_to) {
|
||||
s.len = up_to;
|
||||
@@ -405,9 +407,9 @@ static inline puffs_base_slice_u8 puffs_base_slice_u8_prefix(
|
||||
return s;
|
||||
}
|
||||
|
||||
// puffs_base_slice_u8_suffix returns up to the last up_to bytes of s.
|
||||
static inline puffs_base_slice_u8 puffs_base_slice_u8_suffix(
|
||||
puffs_base_slice_u8 s,
|
||||
// puffs_base__slice_u8__suffix returns up to the last up_to bytes of s.
|
||||
static inline puffs_base__slice_u8 puffs_base__slice_u8_suffix(
|
||||
puffs_base__slice_u8 s,
|
||||
uint64_t up_to) {
|
||||
if ((uint64_t)(s.len) > up_to) {
|
||||
s.ptr += (uint64_t)(s.len) - up_to;
|
||||
@@ -416,14 +418,14 @@ static inline puffs_base_slice_u8 puffs_base_slice_u8_suffix(
|
||||
return s;
|
||||
}
|
||||
|
||||
// puffs_base_slice_u8_copy_from_slice calls memmove(dst.ptr, src.ptr, length)
|
||||
// where length is the minimum of dst.len and src.len.
|
||||
// puffs_base__slice_u8__copy_from_slice calls memmove(dst.ptr, src.ptr,
|
||||
// length) where length is the minimum of dst.len and src.len.
|
||||
//
|
||||
// Passing a puffs_base_slice_u8 with all fields NULL or zero (a valid, empty
|
||||
// Passing a puffs_base__slice_u8 with all fields NULL or zero (a valid, empty
|
||||
// slice) is valid and results in a no-op.
|
||||
static inline uint64_t puffs_base_slice_u8_copy_from_slice(
|
||||
puffs_base_slice_u8 dst,
|
||||
puffs_base_slice_u8 src) {
|
||||
static inline uint64_t puffs_base__slice_u8__copy_from_slice(
|
||||
puffs_base__slice_u8 dst,
|
||||
puffs_base__slice_u8 src) {
|
||||
size_t length = dst.len < src.len ? dst.len : src.len;
|
||||
if (length > 0) {
|
||||
memmove(dst.ptr, src.ptr, length);
|
||||
@@ -431,11 +433,12 @@ static inline uint64_t puffs_base_slice_u8_copy_from_slice(
|
||||
return length;
|
||||
}
|
||||
|
||||
static inline uint32_t puffs_base_writer1_copy_from_history32(uint8_t** ptr_ptr,
|
||||
uint8_t* start,
|
||||
uint8_t* end,
|
||||
uint32_t distance,
|
||||
uint32_t length) {
|
||||
static inline uint32_t puffs_base__writer1__copy_from_history32(
|
||||
uint8_t** ptr_ptr,
|
||||
uint8_t* start,
|
||||
uint8_t* end,
|
||||
uint32_t distance,
|
||||
uint32_t length) {
|
||||
uint8_t* ptr = *ptr_ptr;
|
||||
size_t d = ptr - start;
|
||||
if ((d == 0) || (d < (size_t)(distance))) {
|
||||
@@ -466,11 +469,12 @@ static inline uint32_t puffs_base_writer1_copy_from_history32(uint8_t** ptr_ptr,
|
||||
return length;
|
||||
}
|
||||
|
||||
static inline uint32_t puffs_base_writer1_copy_from_reader32(uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
uint8_t** ptr_rptr,
|
||||
uint8_t* rend,
|
||||
uint32_t length) {
|
||||
static inline uint32_t puffs_base__writer1__copy_from_reader32(
|
||||
uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
uint8_t** ptr_rptr,
|
||||
uint8_t* rend,
|
||||
uint32_t length) {
|
||||
uint8_t* wptr = *ptr_wptr;
|
||||
size_t n = length;
|
||||
if (n > wend - wptr) {
|
||||
@@ -488,10 +492,10 @@ static inline uint32_t puffs_base_writer1_copy_from_reader32(uint8_t** ptr_wptr,
|
||||
return n;
|
||||
}
|
||||
|
||||
static inline uint64_t puffs_base_writer1_copy_from_slice(
|
||||
static inline uint64_t puffs_base__writer1__copy_from_slice(
|
||||
uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
puffs_base_slice_u8 src) {
|
||||
puffs_base__slice_u8 src) {
|
||||
uint8_t* wptr = *ptr_wptr;
|
||||
size_t n = src.len;
|
||||
if (n > wend - wptr) {
|
||||
@@ -504,10 +508,10 @@ static inline uint64_t puffs_base_writer1_copy_from_slice(
|
||||
return n;
|
||||
}
|
||||
|
||||
static inline uint32_t puffs_base_writer1_copy_from_slice32(
|
||||
static inline uint32_t puffs_base__writer1__copy_from_slice32(
|
||||
uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
puffs_base_slice_u8 src,
|
||||
puffs_base__slice_u8 src,
|
||||
uint32_t length) {
|
||||
uint8_t* wptr = *ptr_wptr;
|
||||
size_t n = src.len;
|
||||
@@ -578,18 +582,18 @@ const char* puffs_gif__status__string(puffs_gif__status s) {
|
||||
// ---------------- Private Function Prototypes
|
||||
|
||||
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 puffs_gif__decoder__decode_lsd(puffs_gif__decoder* self,
|
||||
puffs_base_reader1 a_src);
|
||||
puffs_base__reader1 a_src);
|
||||
|
||||
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 puffs_gif__decoder__decode_id(puffs_gif__decoder* self,
|
||||
puffs_base_writer1 a_dst,
|
||||
puffs_base_reader1 a_src);
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src);
|
||||
|
||||
// ---------------- Initializer Implementations
|
||||
|
||||
@@ -603,10 +607,10 @@ void puffs_gif__lzw_decoder__initialize(puffs_gif__lzw_decoder* self,
|
||||
self->private_impl.status = PUFFS_GIF__ERROR_BAD_PUFFS_VERSION;
|
||||
return;
|
||||
}
|
||||
if (for_internal_use_only != PUFFS_ALREADY_ZEROED) {
|
||||
if (for_internal_use_only != PUFFS_BASE__ALREADY_ZEROED) {
|
||||
memset(self, 0, sizeof(*self));
|
||||
}
|
||||
self->private_impl.magic = PUFFS_MAGIC;
|
||||
self->private_impl.magic = PUFFS_BASE__MAGIC;
|
||||
self->private_impl.f_literal_width = 8;
|
||||
}
|
||||
|
||||
@@ -620,23 +624,23 @@ void puffs_gif__decoder__initialize(puffs_gif__decoder* self,
|
||||
self->private_impl.status = PUFFS_GIF__ERROR_BAD_PUFFS_VERSION;
|
||||
return;
|
||||
}
|
||||
if (for_internal_use_only != PUFFS_ALREADY_ZEROED) {
|
||||
if (for_internal_use_only != PUFFS_BASE__ALREADY_ZEROED) {
|
||||
memset(self, 0, sizeof(*self));
|
||||
}
|
||||
self->private_impl.magic = PUFFS_MAGIC;
|
||||
self->private_impl.magic = PUFFS_BASE__MAGIC;
|
||||
puffs_gif__lzw_decoder__initialize(&self->private_impl.f_lzw, PUFFS_VERSION,
|
||||
PUFFS_ALREADY_ZEROED);
|
||||
PUFFS_BASE__ALREADY_ZEROED);
|
||||
}
|
||||
|
||||
// ---------------- Function Implementations
|
||||
|
||||
puffs_gif__status puffs_gif__decoder__decode(puffs_gif__decoder* self,
|
||||
puffs_base_writer1 a_dst,
|
||||
puffs_base_reader1 a_src) {
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src) {
|
||||
if (!self) {
|
||||
return PUFFS_GIF__ERROR_BAD_RECEIVER;
|
||||
}
|
||||
if (self->private_impl.magic != PUFFS_MAGIC) {
|
||||
if (self->private_impl.magic != PUFFS_BASE__MAGIC) {
|
||||
self->private_impl.status = PUFFS_GIF__ERROR_INITIALIZER_NOT_CALLED;
|
||||
}
|
||||
if (self->private_impl.status < 0) {
|
||||
@@ -653,7 +657,7 @@ puffs_gif__status puffs_gif__decoder__decode(puffs_gif__decoder* self,
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
b_rstart_src = b_rptr_src;
|
||||
size_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -667,13 +671,13 @@ puffs_gif__status puffs_gif__decoder__decode(puffs_gif__decoder* self,
|
||||
v_c = self->private_impl.c_decode[0].v_c;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(0);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(0);
|
||||
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(1);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (a_src.buf) {
|
||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||
a_src.buf->ri += n;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
@@ -684,7 +688,7 @@ puffs_gif__status puffs_gif__decoder__decode(puffs_gif__decoder* self,
|
||||
if (a_src.buf) {
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
size_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -695,11 +699,11 @@ puffs_gif__status puffs_gif__decoder__decode(puffs_gif__decoder* self,
|
||||
if (status) {
|
||||
goto suspend;
|
||||
}
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(2);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (a_src.buf) {
|
||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||
a_src.buf->ri += n;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
@@ -710,7 +714,7 @@ puffs_gif__status puffs_gif__decoder__decode(puffs_gif__decoder* self,
|
||||
if (a_src.buf) {
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
size_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -722,18 +726,18 @@ puffs_gif__status puffs_gif__decoder__decode(puffs_gif__decoder* self,
|
||||
goto suspend;
|
||||
}
|
||||
while (true) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(3);
|
||||
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_0 = *b_rptr_src++;
|
||||
v_c = t_0;
|
||||
if (v_c == 33) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(4);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
if (a_src.buf) {
|
||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||
a_src.buf->ri += n;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
@@ -744,7 +748,7 @@ puffs_gif__status puffs_gif__decoder__decode(puffs_gif__decoder* self,
|
||||
if (a_src.buf) {
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
size_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -756,11 +760,11 @@ puffs_gif__status puffs_gif__decoder__decode(puffs_gif__decoder* self,
|
||||
goto suspend;
|
||||
}
|
||||
} else if (v_c == 44) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(5);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
if (a_src.buf) {
|
||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||
a_src.buf->ri += n;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
@@ -771,7 +775,7 @@ puffs_gif__status puffs_gif__decoder__decode(puffs_gif__decoder* self,
|
||||
if (a_src.buf) {
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
size_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -806,14 +810,14 @@ exit:
|
||||
if (a_src.buf) {
|
||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||
a_src.buf->ri += n;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
}
|
||||
|
||||
self->private_impl.status = status;
|
||||
@@ -829,7 +833,7 @@ short_read_src:
|
||||
}
|
||||
|
||||
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 = PUFFS_GIF__STATUS_OK;
|
||||
|
||||
uint8_t v_c[6];
|
||||
@@ -842,7 +846,7 @@ puffs_gif__status puffs_gif__decoder__decode_header(puffs_gif__decoder* self,
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
b_rstart_src = b_rptr_src;
|
||||
size_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -858,13 +862,13 @@ puffs_gif__status puffs_gif__decoder__decode_header(puffs_gif__decoder* self,
|
||||
v_i = self->private_impl.c_decode_header[0].v_i;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(0);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(0);
|
||||
|
||||
memset(v_c, 0, sizeof(v_c));
|
||||
v_i = 0;
|
||||
while (v_i < 6) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(1);
|
||||
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_0 = *b_rptr_src++;
|
||||
@@ -893,14 +897,14 @@ exit:
|
||||
if (a_src.buf) {
|
||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||
a_src.buf->ri += n;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -915,7 +919,7 @@ short_read_src:
|
||||
}
|
||||
|
||||
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 = PUFFS_GIF__STATUS_OK;
|
||||
|
||||
uint8_t v_c[7];
|
||||
@@ -929,7 +933,7 @@ puffs_gif__status puffs_gif__decoder__decode_lsd(puffs_gif__decoder* self,
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
b_rstart_src = b_rptr_src;
|
||||
size_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -945,13 +949,13 @@ puffs_gif__status puffs_gif__decoder__decode_lsd(puffs_gif__decoder* self,
|
||||
v_gct_size = self->private_impl.c_decode_lsd[0].v_gct_size;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(0);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(0);
|
||||
|
||||
memset(v_c, 0, sizeof(v_c));
|
||||
v_i = 0;
|
||||
while (v_i < 7) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(1);
|
||||
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_0 = *b_rptr_src++;
|
||||
@@ -967,20 +971,20 @@ puffs_gif__status puffs_gif__decoder__decode_lsd(puffs_gif__decoder* self,
|
||||
v_gct_size = (((uint32_t)(1)) << (1 + (v_c[4] & 7)));
|
||||
v_i = 0;
|
||||
while (v_i < v_gct_size) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(2);
|
||||
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_1 = *b_rptr_src++;
|
||||
self->private_impl.f_gct[(3 * v_i) + 0] = t_1;
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(3);
|
||||
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_2 = *b_rptr_src++;
|
||||
self->private_impl.f_gct[(3 * v_i) + 1] = t_2;
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(4);
|
||||
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_3 = *b_rptr_src++;
|
||||
@@ -1006,14 +1010,14 @@ exit:
|
||||
if (a_src.buf) {
|
||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||
a_src.buf->ri += n;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -1029,7 +1033,7 @@ short_read_src:
|
||||
|
||||
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 = PUFFS_GIF__STATUS_OK;
|
||||
|
||||
uint8_t v_label;
|
||||
@@ -1042,7 +1046,7 @@ puffs_gif__status puffs_gif__decoder__decode_extension(
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
b_rstart_src = b_rptr_src;
|
||||
size_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -1058,10 +1062,10 @@ puffs_gif__status puffs_gif__decoder__decode_extension(
|
||||
v_block_size = self->private_impl.c_decode_extension[0].v_block_size;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(0);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(0);
|
||||
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(1);
|
||||
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_0 = *b_rptr_src++;
|
||||
@@ -1075,8 +1079,8 @@ puffs_gif__status puffs_gif__decoder__decode_extension(
|
||||
goto exit;
|
||||
}
|
||||
while (true) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(2);
|
||||
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_1 = *b_rptr_src++;
|
||||
@@ -1084,10 +1088,10 @@ puffs_gif__status puffs_gif__decoder__decode_extension(
|
||||
if (v_block_size == 0) {
|
||||
goto label_0_break;
|
||||
}
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(3);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
self->private_impl.c_decode_extension[0].scratch =
|
||||
((uint32_t)(v_block_size));
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(4);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
if (self->private_impl.c_decode_extension[0].scratch >
|
||||
b_rend_src - b_rptr_src) {
|
||||
self->private_impl.c_decode_extension[0].scratch -=
|
||||
@@ -1115,14 +1119,14 @@ exit:
|
||||
if (a_src.buf) {
|
||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||
a_src.buf->ri += n;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -1137,8 +1141,8 @@ 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_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src) {
|
||||
puffs_gif__status status = PUFFS_GIF__STATUS_OK;
|
||||
|
||||
uint8_t v_c[9];
|
||||
@@ -1147,7 +1151,7 @@ puffs_gif__status puffs_gif__decoder__decode_id(puffs_gif__decoder* self,
|
||||
uint8_t v_lw;
|
||||
uint8_t v_block_size;
|
||||
uint64_t l_lzw_src;
|
||||
puffs_base_reader1 v_lzw_src;
|
||||
puffs_base__reader1 v_lzw_src;
|
||||
|
||||
uint8_t* b_rptr_src = NULL;
|
||||
uint8_t* b_rstart_src = NULL;
|
||||
@@ -1156,7 +1160,7 @@ puffs_gif__status puffs_gif__decoder__decode_id(puffs_gif__decoder* self,
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
b_rstart_src = b_rptr_src;
|
||||
size_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -1176,13 +1180,13 @@ puffs_gif__status puffs_gif__decoder__decode_id(puffs_gif__decoder* self,
|
||||
v_lzw_src = self->private_impl.c_decode_id[0].v_lzw_src;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(0);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(0);
|
||||
|
||||
memset(v_c, 0, sizeof(v_c));
|
||||
v_i = 0;
|
||||
while (v_i < 9) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(1);
|
||||
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_0 = *b_rptr_src++;
|
||||
@@ -1196,8 +1200,8 @@ puffs_gif__status puffs_gif__decoder__decode_id(puffs_gif__decoder* self,
|
||||
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)) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_1 = *b_rptr_src++;
|
||||
@@ -1209,8 +1213,8 @@ puffs_gif__status puffs_gif__decoder__decode_id(puffs_gif__decoder* self,
|
||||
puffs_gif__lzw_decoder__set_literal_width(&self->private_impl.f_lzw,
|
||||
((uint32_t)(v_lw)));
|
||||
while (true) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(3);
|
||||
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_2 = *b_rptr_src++;
|
||||
@@ -1219,16 +1223,16 @@ puffs_gif__status puffs_gif__decoder__decode_id(puffs_gif__decoder* self,
|
||||
goto label_0_break;
|
||||
}
|
||||
l_lzw_src = ((uint64_t)(v_block_size));
|
||||
v_lzw_src = (puffs_base_reader1){.buf = a_src.buf,
|
||||
.limit = (puffs_base_limit1){
|
||||
.ptr_to_len = &l_lzw_src,
|
||||
.next = &a_src.limit,
|
||||
}};
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(4);
|
||||
v_lzw_src = (puffs_base__reader1){.buf = a_src.buf,
|
||||
.limit = (puffs_base__limit1){
|
||||
.ptr_to_len = &l_lzw_src,
|
||||
.next = &a_src.limit,
|
||||
}};
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
if (a_src.buf) {
|
||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||
a_src.buf->ri += n;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
@@ -1240,7 +1244,7 @@ puffs_gif__status puffs_gif__decoder__decode_id(puffs_gif__decoder* self,
|
||||
if (a_src.buf) {
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
size_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -1275,14 +1279,14 @@ exit:
|
||||
if (a_src.buf) {
|
||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||
a_src.buf->ri += n;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -1301,7 +1305,7 @@ void puffs_gif__lzw_decoder__set_literal_width(puffs_gif__lzw_decoder* self,
|
||||
if (!self) {
|
||||
return;
|
||||
}
|
||||
if (self->private_impl.magic != PUFFS_MAGIC) {
|
||||
if (self->private_impl.magic != PUFFS_BASE__MAGIC) {
|
||||
self->private_impl.status = PUFFS_GIF__ERROR_INITIALIZER_NOT_CALLED;
|
||||
}
|
||||
if (self->private_impl.status < 0) {
|
||||
@@ -1316,12 +1320,12 @@ 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_base_writer1 a_dst,
|
||||
puffs_base_reader1 a_src) {
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src) {
|
||||
if (!self) {
|
||||
return PUFFS_GIF__ERROR_BAD_RECEIVER;
|
||||
}
|
||||
if (self->private_impl.magic != PUFFS_MAGIC) {
|
||||
if (self->private_impl.magic != PUFFS_BASE__MAGIC) {
|
||||
self->private_impl.status = PUFFS_GIF__ERROR_INITIALIZER_NOT_CALLED;
|
||||
}
|
||||
if (self->private_impl.status < 0) {
|
||||
@@ -1339,7 +1343,7 @@ puffs_gif__status puffs_gif__lzw_decoder__decode(puffs_gif__lzw_decoder* self,
|
||||
uint32_t v_code;
|
||||
uint32_t v_s;
|
||||
uint32_t v_c;
|
||||
puffs_base_slice_u8 v_expansion;
|
||||
puffs_base__slice_u8 v_expansion;
|
||||
uint64_t v_n_copied;
|
||||
|
||||
uint8_t* b_wptr_dst = NULL;
|
||||
@@ -1351,7 +1355,7 @@ puffs_gif__status puffs_gif__lzw_decoder__decode(puffs_gif__lzw_decoder* self,
|
||||
b_wend_dst = b_wptr_dst;
|
||||
if (!a_dst.buf->closed) {
|
||||
size_t len = a_dst.buf->len - a_dst.buf->wi;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_dst.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -1367,7 +1371,7 @@ puffs_gif__status puffs_gif__lzw_decoder__decode(puffs_gif__lzw_decoder* self,
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
b_rstart_src = b_rptr_src;
|
||||
size_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -1388,11 +1392,11 @@ puffs_gif__status puffs_gif__lzw_decoder__decode(puffs_gif__lzw_decoder* self,
|
||||
v_code = self->private_impl.c_decode[0].v_code;
|
||||
v_s = self->private_impl.c_decode[0].v_s;
|
||||
v_c = self->private_impl.c_decode[0].v_c;
|
||||
v_expansion = ((puffs_base_slice_u8){});
|
||||
v_expansion = ((puffs_base__slice_u8){});
|
||||
v_n_copied = self->private_impl.c_decode[0].v_n_copied;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(0);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(0);
|
||||
|
||||
v_clear_code = (((uint32_t)(1)) << self->private_impl.f_literal_width);
|
||||
v_end_code = (v_clear_code + 1);
|
||||
@@ -1404,8 +1408,8 @@ puffs_gif__status puffs_gif__lzw_decoder__decode(puffs_gif__lzw_decoder* self,
|
||||
label_0_continue:;
|
||||
while (true) {
|
||||
while (v_n_bits < v_width) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(1);
|
||||
if (PUFFS_UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_0 = *b_rptr_src++;
|
||||
@@ -1416,7 +1420,7 @@ puffs_gif__status puffs_gif__lzw_decoder__decode(puffs_gif__lzw_decoder* self,
|
||||
v_bits >>= v_width;
|
||||
v_n_bits -= v_width;
|
||||
if (v_code < v_clear_code) {
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT(2);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (b_wptr_dst == b_wend_dst) {
|
||||
status = PUFFS_GIF__SUSPENSION_SHORT_WRITE;
|
||||
goto suspend;
|
||||
@@ -1456,18 +1460,18 @@ puffs_gif__status puffs_gif__lzw_decoder__decode(puffs_gif__lzw_decoder* self,
|
||||
self->private_impl.f_stack[4095] = ((uint8_t)(v_c));
|
||||
}
|
||||
while (true) {
|
||||
v_expansion = puffs_base_slice_u8_subslice_i(
|
||||
((puffs_base_slice_u8){.ptr = self->private_impl.f_stack,
|
||||
.len = 4096}),
|
||||
v_expansion = puffs_base__slice_u8__subslice_i(
|
||||
((puffs_base__slice_u8){.ptr = self->private_impl.f_stack,
|
||||
.len = 4096}),
|
||||
v_s);
|
||||
v_n_copied = puffs_base_writer1_copy_from_slice(
|
||||
v_n_copied = puffs_base__writer1__copy_from_slice(
|
||||
&b_wptr_dst, b_wend_dst, v_expansion);
|
||||
if (v_n_copied == ((uint64_t)(v_expansion.len))) {
|
||||
goto label_1_break;
|
||||
}
|
||||
v_s = ((v_s + ((uint32_t)((v_n_copied & 4095)))) & 4095);
|
||||
status = PUFFS_GIF__SUSPENSION_SHORT_WRITE;
|
||||
PUFFS_COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
}
|
||||
label_1_break:;
|
||||
if (v_save_code <= 4095) {
|
||||
@@ -1513,26 +1517,26 @@ exit:
|
||||
if (a_dst.buf) {
|
||||
size_t n = b_wptr_dst - (a_dst.buf->ptr + a_dst.buf->wi);
|
||||
a_dst.buf->wi += n;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_dst.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wstart_dst);
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wend_dst);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wstart_dst);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wend_dst);
|
||||
}
|
||||
if (a_src.buf) {
|
||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||
a_src.buf->ri += n;
|
||||
puffs_base_limit1* lim;
|
||||
puffs_base__limit1* lim;
|
||||
for (lim = &a_src.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
}
|
||||
|
||||
self->private_impl.status = status;
|
||||
|
||||
+19
-19
@@ -48,15 +48,15 @@
|
||||
// TODO: don't hard code this in base-header.h.
|
||||
#define PUFFS_VERSION (0x00001)
|
||||
|
||||
// puffs_base_slice_u8 is a 1-dimensional buffer (a pointer and length).
|
||||
// puffs_base__slice_u8 is a 1-dimensional buffer (a pointer and length).
|
||||
//
|
||||
// A value with all fields NULL or zero is a valid, empty slice.
|
||||
typedef struct {
|
||||
uint8_t* ptr;
|
||||
size_t len;
|
||||
} puffs_base_slice_u8;
|
||||
} puffs_base__slice_u8;
|
||||
|
||||
// puffs_base_buf1 is a 1-dimensional buffer (a pointer and length), plus
|
||||
// puffs_base__buf1 is a 1-dimensional buffer (a pointer and length), plus
|
||||
// additional indexes into that buffer, plus an opened / closed flag.
|
||||
//
|
||||
// A value with all fields NULL or zero is a valid, empty buffer.
|
||||
@@ -66,28 +66,28 @@ typedef struct {
|
||||
size_t wi; // Write index. Invariant: wi <= len.
|
||||
size_t ri; // Read index. Invariant: ri <= wi.
|
||||
bool closed; // No further writes are expected.
|
||||
} puffs_base_buf1;
|
||||
} puffs_base__buf1;
|
||||
|
||||
// puffs_base_limit1 provides a limited view of a 1-dimensional byte stream:
|
||||
// puffs_base__limit1 provides a limited view of a 1-dimensional byte stream:
|
||||
// its first N bytes. That N can be greater than a buffer's current read or
|
||||
// write capacity. N decreases naturally over time as bytes are read from or
|
||||
// written to the stream.
|
||||
//
|
||||
// A value with all fields NULL or zero is a valid, unlimited view.
|
||||
typedef struct puffs_base_limit1 {
|
||||
uint64_t* ptr_to_len; // Pointer to N.
|
||||
struct puffs_base_limit1* next; // Linked list of limits.
|
||||
} puffs_base_limit1;
|
||||
typedef struct puffs_base__limit1 {
|
||||
uint64_t* ptr_to_len; // Pointer to N.
|
||||
struct puffs_base__limit1* next; // Linked list of limits.
|
||||
} puffs_base__limit1;
|
||||
|
||||
typedef struct {
|
||||
puffs_base_buf1* buf;
|
||||
puffs_base_limit1 limit;
|
||||
} puffs_base_reader1;
|
||||
puffs_base__buf1* buf;
|
||||
puffs_base__limit1 limit;
|
||||
} puffs_base__reader1;
|
||||
|
||||
typedef struct {
|
||||
puffs_base_buf1* buf;
|
||||
puffs_base_limit1 limit;
|
||||
} puffs_base_writer1;
|
||||
puffs_base__buf1* buf;
|
||||
puffs_base__limit1 limit;
|
||||
} puffs_base__writer1;
|
||||
|
||||
#endif // PUFFS_BASE_HEADER_H
|
||||
|
||||
@@ -301,13 +301,13 @@ void puffs_flate__zlib_decoder__initialize(puffs_flate__zlib_decoder* self,
|
||||
|
||||
puffs_flate__status puffs_flate__flate_decoder__decode(
|
||||
puffs_flate__flate_decoder* self,
|
||||
puffs_base_writer1 a_dst,
|
||||
puffs_base_reader1 a_src);
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src);
|
||||
|
||||
puffs_flate__status puffs_flate__zlib_decoder__decode(
|
||||
puffs_flate__zlib_decoder* self,
|
||||
puffs_base_writer1 a_dst,
|
||||
puffs_base_reader1 a_src);
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
||||
+20
-20
@@ -48,15 +48,15 @@
|
||||
// TODO: don't hard code this in base-header.h.
|
||||
#define PUFFS_VERSION (0x00001)
|
||||
|
||||
// puffs_base_slice_u8 is a 1-dimensional buffer (a pointer and length).
|
||||
// puffs_base__slice_u8 is a 1-dimensional buffer (a pointer and length).
|
||||
//
|
||||
// A value with all fields NULL or zero is a valid, empty slice.
|
||||
typedef struct {
|
||||
uint8_t* ptr;
|
||||
size_t len;
|
||||
} puffs_base_slice_u8;
|
||||
} puffs_base__slice_u8;
|
||||
|
||||
// puffs_base_buf1 is a 1-dimensional buffer (a pointer and length), plus
|
||||
// puffs_base__buf1 is a 1-dimensional buffer (a pointer and length), plus
|
||||
// additional indexes into that buffer, plus an opened / closed flag.
|
||||
//
|
||||
// A value with all fields NULL or zero is a valid, empty buffer.
|
||||
@@ -66,28 +66,28 @@ typedef struct {
|
||||
size_t wi; // Write index. Invariant: wi <= len.
|
||||
size_t ri; // Read index. Invariant: ri <= wi.
|
||||
bool closed; // No further writes are expected.
|
||||
} puffs_base_buf1;
|
||||
} puffs_base__buf1;
|
||||
|
||||
// puffs_base_limit1 provides a limited view of a 1-dimensional byte stream:
|
||||
// puffs_base__limit1 provides a limited view of a 1-dimensional byte stream:
|
||||
// its first N bytes. That N can be greater than a buffer's current read or
|
||||
// write capacity. N decreases naturally over time as bytes are read from or
|
||||
// written to the stream.
|
||||
//
|
||||
// A value with all fields NULL or zero is a valid, unlimited view.
|
||||
typedef struct puffs_base_limit1 {
|
||||
uint64_t* ptr_to_len; // Pointer to N.
|
||||
struct puffs_base_limit1* next; // Linked list of limits.
|
||||
} puffs_base_limit1;
|
||||
typedef struct puffs_base__limit1 {
|
||||
uint64_t* ptr_to_len; // Pointer to N.
|
||||
struct puffs_base__limit1* next; // Linked list of limits.
|
||||
} puffs_base__limit1;
|
||||
|
||||
typedef struct {
|
||||
puffs_base_buf1* buf;
|
||||
puffs_base_limit1 limit;
|
||||
} puffs_base_reader1;
|
||||
puffs_base__buf1* buf;
|
||||
puffs_base__limit1 limit;
|
||||
} puffs_base__reader1;
|
||||
|
||||
typedef struct {
|
||||
puffs_base_buf1* buf;
|
||||
puffs_base_limit1 limit;
|
||||
} puffs_base_writer1;
|
||||
puffs_base__buf1* buf;
|
||||
puffs_base__limit1 limit;
|
||||
} puffs_base__writer1;
|
||||
|
||||
#endif // PUFFS_BASE_HEADER_H
|
||||
|
||||
@@ -217,7 +217,7 @@ typedef struct {
|
||||
uint8_t v_lw;
|
||||
uint8_t v_block_size;
|
||||
uint64_t l_lzw_src;
|
||||
puffs_base_reader1 v_lzw_src;
|
||||
puffs_base__reader1 v_lzw_src;
|
||||
} c_decode_id[1];
|
||||
} private_impl;
|
||||
} puffs_gif__decoder;
|
||||
@@ -245,15 +245,15 @@ void puffs_gif__decoder__initialize(puffs_gif__decoder* self,
|
||||
// ---------------- Public Function Prototypes
|
||||
|
||||
puffs_gif__status puffs_gif__decoder__decode(puffs_gif__decoder* self,
|
||||
puffs_base_writer1 a_dst,
|
||||
puffs_base_reader1 a_src);
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src);
|
||||
|
||||
void puffs_gif__lzw_decoder__set_literal_width(puffs_gif__lzw_decoder* self,
|
||||
uint32_t a_lw);
|
||||
|
||||
puffs_gif__status puffs_gif__lzw_decoder__decode(puffs_gif__lzw_decoder* self,
|
||||
puffs_base_writer1 a_dst,
|
||||
puffs_base_reader1 a_src);
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
||||
+14
-14
@@ -16,8 +16,8 @@
|
||||
|
||||
uint32_t global_mimiclib_flate_unused_u32;
|
||||
|
||||
const char* mimic_bench_adler32(puffs_base_buf1* dst,
|
||||
puffs_base_buf1* src,
|
||||
const char* mimic_bench_adler32(puffs_base__buf1* dst,
|
||||
puffs_base__buf1* src,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
// TODO: don't ignore wlimit and rlimit.
|
||||
@@ -31,8 +31,8 @@ const char* mimic_bench_adler32(puffs_base_buf1* dst,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* mimic_bench_crc32(puffs_base_buf1* dst,
|
||||
puffs_base_buf1* src,
|
||||
const char* mimic_bench_crc32(puffs_base__buf1* dst,
|
||||
puffs_base__buf1* src,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
// TODO: don't ignore wlimit and rlimit.
|
||||
@@ -47,13 +47,13 @@ const char* mimic_bench_crc32(puffs_base_buf1* dst,
|
||||
}
|
||||
|
||||
unsigned int mimic_flate_read_func(void* ctx, unsigned char** buf) {
|
||||
puffs_base_buf1* src = (puffs_base_buf1*)(ctx);
|
||||
puffs_base__buf1* src = (puffs_base__buf1*)(ctx);
|
||||
*buf = src->ptr + src->ri;
|
||||
return src->wi - src->ri;
|
||||
}
|
||||
|
||||
int mimic_flate_write_func(void* ctx, unsigned char* ptr, unsigned int len) {
|
||||
puffs_base_buf1* dst = (puffs_base_buf1*)(ctx);
|
||||
puffs_base__buf1* dst = (puffs_base__buf1*)(ctx);
|
||||
size_t n = len;
|
||||
if (n > dst->len - dst->wi) {
|
||||
return 1;
|
||||
@@ -63,8 +63,8 @@ int mimic_flate_write_func(void* ctx, unsigned char* ptr, unsigned int len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char* mimic_flate_decode(puffs_base_buf1* dst,
|
||||
puffs_base_buf1* src,
|
||||
const char* mimic_flate_decode(puffs_base__buf1* dst,
|
||||
puffs_base__buf1* src,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
// TODO: don't ignore wlimit and rlimit.
|
||||
@@ -104,8 +104,8 @@ cleanup0:;
|
||||
return ret;
|
||||
}
|
||||
|
||||
const char* mimic_gzip_zlib_decode(puffs_base_buf1* dst,
|
||||
puffs_base_buf1* src,
|
||||
const char* mimic_gzip_zlib_decode(puffs_base__buf1* dst,
|
||||
puffs_base__buf1* src,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit,
|
||||
bool gzip_instead_of_zlib) {
|
||||
@@ -162,15 +162,15 @@ cleanup0:;
|
||||
return ret;
|
||||
}
|
||||
|
||||
const char* mimic_gzip_decode(puffs_base_buf1* dst,
|
||||
puffs_base_buf1* src,
|
||||
const char* mimic_gzip_decode(puffs_base__buf1* dst,
|
||||
puffs_base__buf1* src,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
return mimic_gzip_zlib_decode(dst, src, wlimit, rlimit, true);
|
||||
}
|
||||
|
||||
const char* mimic_zlib_decode(puffs_base_buf1* dst,
|
||||
puffs_base_buf1* src,
|
||||
const char* mimic_zlib_decode(puffs_base__buf1* dst,
|
||||
puffs_base__buf1* src,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
return mimic_gzip_zlib_decode(dst, src, wlimit, rlimit, false);
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "gif_lib.h"
|
||||
|
||||
int mimic_gif_read_func(GifFileType* f, GifByteType* ptr, int len) {
|
||||
puffs_base_buf1* src = (puffs_base_buf1*)(f->UserData);
|
||||
puffs_base__buf1* src = (puffs_base__buf1*)(f->UserData);
|
||||
if (len < 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -29,7 +29,7 @@ int mimic_gif_read_func(GifFileType* f, GifByteType* ptr, int len) {
|
||||
return n;
|
||||
}
|
||||
|
||||
const char* mimic_gif_decode(puffs_base_buf1* dst, puffs_base_buf1* src) {
|
||||
const char* mimic_gif_decode(puffs_base__buf1* dst, puffs_base__buf1* src) {
|
||||
const char* ret = NULL;
|
||||
|
||||
// TODO: #ifdef API calls for libgif version 4 vs version 5? Note that:
|
||||
|
||||
+33
-33
@@ -153,14 +153,14 @@ void test_puffs_adler32() {
|
||||
|
||||
int i;
|
||||
for (i = 0; i < PUFFS_TESTLIB_ARRAY_SIZE(test_cases); i++) {
|
||||
puffs_base_buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
if (!read_file(&src, test_cases[i].filename)) {
|
||||
return;
|
||||
}
|
||||
puffs_flate__adler32 checksum;
|
||||
puffs_flate__adler32__initialize(&checksum, PUFFS_VERSION, 0);
|
||||
uint32_t got =
|
||||
puffs_flate__adler32__update(&checksum, ((puffs_base_slice_u8){
|
||||
puffs_flate__adler32__update(&checksum, ((puffs_base__slice_u8){
|
||||
.ptr = src.ptr + src.ri,
|
||||
.len = src.wi - src.ri,
|
||||
}));
|
||||
@@ -174,14 +174,14 @@ void test_puffs_adler32() {
|
||||
|
||||
// ---------------- Flate Tests
|
||||
|
||||
const char* puffs_flate_decode(puffs_base_buf1* dst,
|
||||
puffs_base_buf1* src,
|
||||
const char* puffs_flate_decode(puffs_base__buf1* dst,
|
||||
puffs_base__buf1* src,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
puffs_flate__flate_decoder dec;
|
||||
puffs_flate__flate_decoder__initialize(&dec, PUFFS_VERSION, 0);
|
||||
puffs_base_writer1 dst_writer = {.buf = dst};
|
||||
puffs_base_reader1 src_reader = {.buf = src};
|
||||
puffs_base__writer1 dst_writer = {.buf = dst};
|
||||
puffs_base__reader1 src_reader = {.buf = src};
|
||||
while (true) {
|
||||
uint64_t wlim = wlimit;
|
||||
if (wlimit) {
|
||||
@@ -206,14 +206,14 @@ const char* puffs_flate_decode(puffs_base_buf1* dst,
|
||||
}
|
||||
}
|
||||
|
||||
const char* puffs_zlib_decode(puffs_base_buf1* dst,
|
||||
puffs_base_buf1* src,
|
||||
const char* puffs_zlib_decode(puffs_base__buf1* dst,
|
||||
puffs_base__buf1* src,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
puffs_flate__zlib_decoder dec;
|
||||
puffs_flate__zlib_decoder__initialize(&dec, PUFFS_VERSION, 0);
|
||||
puffs_base_writer1 dst_writer = {.buf = dst};
|
||||
puffs_base_reader1 src_reader = {.buf = src};
|
||||
puffs_base__writer1 dst_writer = {.buf = dst};
|
||||
puffs_base__reader1 src_reader = {.buf = src};
|
||||
|
||||
while (true) {
|
||||
uint64_t wlim = wlimit;
|
||||
@@ -282,9 +282,9 @@ void test_puffs_flate_decode_romeo_fixed() {
|
||||
void test_puffs_flate_decode_split_src() {
|
||||
proc_funcname = __func__;
|
||||
|
||||
puffs_base_buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base_buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base_buf1 want = {.ptr = global_want_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 want = {.ptr = global_want_buffer, .len = BUFFER_SIZE};
|
||||
|
||||
golden_test* gt = &flate_256_bytes_gt;
|
||||
if (!read_file(&src, gt->src_filename)) {
|
||||
@@ -295,8 +295,8 @@ void test_puffs_flate_decode_split_src() {
|
||||
}
|
||||
|
||||
puffs_flate__flate_decoder dec;
|
||||
puffs_base_writer1 dst_writer = {.buf = &got};
|
||||
puffs_base_reader1 src_reader = {.buf = &src};
|
||||
puffs_base__writer1 dst_writer = {.buf = &got};
|
||||
puffs_base__reader1 src_reader = {.buf = &src};
|
||||
|
||||
int i;
|
||||
for (i = 1; i < 32; i++) {
|
||||
@@ -345,8 +345,8 @@ void test_puffs_flate_decode_split_src() {
|
||||
|
||||
bool do_test_puffs_flate_history(int i,
|
||||
golden_test* gt,
|
||||
puffs_base_buf1* src,
|
||||
puffs_base_buf1* got,
|
||||
puffs_base__buf1* src,
|
||||
puffs_base__buf1* got,
|
||||
puffs_flate__flate_decoder* dec,
|
||||
uint32_t starting_history_index,
|
||||
uint64_t limit,
|
||||
@@ -357,8 +357,8 @@ bool do_test_puffs_flate_history(int i,
|
||||
got->wi = 0;
|
||||
|
||||
puffs_flate__flate_decoder__initialize(dec, PUFFS_VERSION, 0);
|
||||
puffs_base_writer1 dst_writer = {.buf = got};
|
||||
puffs_base_reader1 src_reader = {.buf = src};
|
||||
puffs_base__writer1 dst_writer = {.buf = got};
|
||||
puffs_base__reader1 src_reader = {.buf = src};
|
||||
|
||||
dec->private_impl.f_history_index = starting_history_index;
|
||||
|
||||
@@ -379,9 +379,9 @@ bool do_test_puffs_flate_history(int i,
|
||||
void test_puffs_flate_history_full() {
|
||||
proc_funcname = __func__;
|
||||
|
||||
puffs_base_buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base_buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base_buf1 want = {.ptr = global_want_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 want = {.ptr = global_want_buffer, .len = BUFFER_SIZE};
|
||||
|
||||
golden_test* gt = &flate_pi_gt;
|
||||
if (!read_file(&src, gt->src_filename)) {
|
||||
@@ -412,7 +412,7 @@ void test_puffs_flate_history_full() {
|
||||
continue;
|
||||
}
|
||||
|
||||
puffs_base_buf1 history_got = {
|
||||
puffs_base__buf1 history_got = {
|
||||
.ptr = dec.private_impl.f_history,
|
||||
.len = full_history_size,
|
||||
.wi = full_history_size,
|
||||
@@ -421,7 +421,7 @@ void test_puffs_flate_history_full() {
|
||||
FAIL("i=%d: want file is too short", i);
|
||||
return;
|
||||
}
|
||||
puffs_base_buf1 history_want = {
|
||||
puffs_base__buf1 history_want = {
|
||||
.ptr = global_want_buffer + want.wi - (full_history_size - i),
|
||||
.len = full_history_size,
|
||||
.wi = full_history_size,
|
||||
@@ -435,8 +435,8 @@ void test_puffs_flate_history_full() {
|
||||
void test_puffs_flate_history_partial() {
|
||||
proc_funcname = __func__;
|
||||
|
||||
puffs_base_buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base_buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
|
||||
golden_test* gt = &flate_pi_gt;
|
||||
if (!read_file(&src, gt->src_filename)) {
|
||||
@@ -626,8 +626,8 @@ void test_puffs_flate_table_redirect() {
|
||||
void test_puffs_zlib_checksum_mismatch() {
|
||||
proc_funcname = __func__;
|
||||
|
||||
puffs_base_buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base_buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
|
||||
if (!read_file(&src, zlib_midsummer_gt.src_filename)) {
|
||||
return;
|
||||
@@ -641,8 +641,8 @@ void test_puffs_zlib_checksum_mismatch() {
|
||||
|
||||
puffs_flate__zlib_decoder dec;
|
||||
puffs_flate__zlib_decoder__initialize(&dec, PUFFS_VERSION, 0);
|
||||
puffs_base_writer1 got_writer = {.buf = &got};
|
||||
puffs_base_reader1 src_reader = {.buf = &src};
|
||||
puffs_base__writer1 got_writer = {.buf = &got};
|
||||
puffs_base__reader1 src_reader = {.buf = &src};
|
||||
|
||||
puffs_flate__status status =
|
||||
puffs_flate__zlib_decoder__decode(&dec, got_writer, src_reader);
|
||||
@@ -722,15 +722,15 @@ void test_mimic_zlib_decode_pi() {
|
||||
|
||||
uint32_t global_puffs_flate_unused_u32;
|
||||
|
||||
const char* puffs_bench_adler32(puffs_base_buf1* dst,
|
||||
puffs_base_buf1* src,
|
||||
const char* puffs_bench_adler32(puffs_base__buf1* dst,
|
||||
puffs_base__buf1* src,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
// TODO: don't ignore wlimit and rlimit.
|
||||
puffs_flate__adler32 checksum;
|
||||
puffs_flate__adler32__initialize(&checksum, PUFFS_VERSION, 0);
|
||||
global_puffs_flate_unused_u32 =
|
||||
puffs_flate__adler32__update(&checksum, ((puffs_base_slice_u8){
|
||||
puffs_flate__adler32__update(&checksum, ((puffs_base__slice_u8){
|
||||
.ptr = src->ptr + src->ri,
|
||||
.len = src->wi - src->ri,
|
||||
}));
|
||||
|
||||
+41
-40
@@ -73,8 +73,8 @@ void test_basic_bad_argument_out_of_range() {
|
||||
|
||||
void test_basic_bad_receiver() {
|
||||
proc_funcname = __func__;
|
||||
puffs_base_writer1 dst = {0};
|
||||
puffs_base_reader1 src = {0};
|
||||
puffs_base__writer1 dst = {0};
|
||||
puffs_base__reader1 src = {0};
|
||||
puffs_gif__status status = puffs_gif__lzw_decoder__decode(NULL, dst, src);
|
||||
if (status != PUFFS_GIF__ERROR_BAD_RECEIVER) {
|
||||
FAIL("status: got %d, want %d", status, PUFFS_GIF__ERROR_BAD_RECEIVER);
|
||||
@@ -84,8 +84,8 @@ void test_basic_bad_receiver() {
|
||||
void test_basic_initializer_not_called() {
|
||||
proc_funcname = __func__;
|
||||
puffs_gif__lzw_decoder dec = {{0}};
|
||||
puffs_base_writer1 dst = {0};
|
||||
puffs_base_reader1 src = {0};
|
||||
puffs_base__writer1 dst = {0};
|
||||
puffs_base__reader1 src = {0};
|
||||
puffs_gif__status status = puffs_gif__lzw_decoder__decode(&dec, dst, src);
|
||||
if (status != PUFFS_GIF__ERROR_INITIALIZER_NOT_CALLED) {
|
||||
FAIL("status: got %d, want %d", status,
|
||||
@@ -108,8 +108,8 @@ void test_basic_puffs_version_good() {
|
||||
proc_funcname = __func__;
|
||||
puffs_gif__lzw_decoder dec;
|
||||
puffs_gif__lzw_decoder__initialize(&dec, PUFFS_VERSION, 0);
|
||||
if (dec.private_impl.magic != PUFFS_MAGIC) {
|
||||
FAIL("magic: got %u, want %u", dec.private_impl.magic, PUFFS_MAGIC);
|
||||
if (dec.private_impl.magic != PUFFS_BASE__MAGIC) {
|
||||
FAIL("magic: got %u, want %u", dec.private_impl.magic, PUFFS_BASE__MAGIC);
|
||||
return;
|
||||
}
|
||||
if (dec.private_impl.f_literal_width != 8) {
|
||||
@@ -179,13 +179,14 @@ void test_basic_sub_struct_initializer() {
|
||||
proc_funcname = __func__;
|
||||
puffs_gif__decoder dec;
|
||||
puffs_gif__decoder__initialize(&dec, PUFFS_VERSION, 0);
|
||||
if (dec.private_impl.magic != PUFFS_MAGIC) {
|
||||
FAIL("outer magic: got %u, want %u", dec.private_impl.magic, PUFFS_MAGIC);
|
||||
if (dec.private_impl.magic != PUFFS_BASE__MAGIC) {
|
||||
FAIL("outer magic: got %u, want %u", dec.private_impl.magic,
|
||||
PUFFS_BASE__MAGIC);
|
||||
return;
|
||||
}
|
||||
if (dec.private_impl.f_lzw.private_impl.magic != PUFFS_MAGIC) {
|
||||
if (dec.private_impl.f_lzw.private_impl.magic != PUFFS_BASE__MAGIC) {
|
||||
FAIL("inner magic: got %u, want %u",
|
||||
dec.private_impl.f_lzw.private_impl.magic, PUFFS_MAGIC);
|
||||
dec.private_impl.f_lzw.private_impl.magic, PUFFS_BASE__MAGIC);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -198,9 +199,9 @@ bool do_test_puffs_gif_lzw_decode(const char* src_filename,
|
||||
uint64_t want_size,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
puffs_base_buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base_buf1 want = {.ptr = global_want_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base_buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 want = {.ptr = global_want_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
|
||||
if (!read_file(&src, src_filename)) {
|
||||
return false;
|
||||
@@ -228,8 +229,8 @@ bool do_test_puffs_gif_lzw_decode(const char* src_filename,
|
||||
puffs_gif__lzw_decoder dec;
|
||||
puffs_gif__lzw_decoder__initialize(&dec, PUFFS_VERSION, 0);
|
||||
puffs_gif__lzw_decoder__set_literal_width(&dec, literal_width);
|
||||
puffs_base_writer1 got_writer = {.buf = &got};
|
||||
puffs_base_reader1 src_reader = {.buf = &src};
|
||||
puffs_base__writer1 got_writer = {.buf = &got};
|
||||
puffs_base__reader1 src_reader = {.buf = &src};
|
||||
int num_iters = 0;
|
||||
while (true) {
|
||||
num_iters++;
|
||||
@@ -331,10 +332,10 @@ void test_puffs_gif_lzw_decode_pi() {
|
||||
// ---------------- LZW Benches
|
||||
|
||||
bool do_bench_puffs_gif_lzw_decode(const char* filename, uint64_t reps) {
|
||||
puffs_base_buf1 dst = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base_buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base_writer1 dst_writer = {.buf = &dst};
|
||||
puffs_base_reader1 src_reader = {.buf = &src};
|
||||
puffs_base__buf1 dst = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__writer1 dst_writer = {.buf = &dst};
|
||||
puffs_base__reader1 src_reader = {.buf = &src};
|
||||
|
||||
if (!read_file(&src, filename)) {
|
||||
return false;
|
||||
@@ -382,11 +383,11 @@ void bench_puffs_gif_lzw_decode_100k() {
|
||||
|
||||
// ---------------- GIF Tests
|
||||
|
||||
const char* puffs_gif_decode(puffs_base_buf1* dst, puffs_base_buf1* src) {
|
||||
const char* puffs_gif_decode(puffs_base__buf1* dst, puffs_base__buf1* src) {
|
||||
puffs_gif__decoder dec;
|
||||
puffs_gif__decoder__initialize(&dec, PUFFS_VERSION, 0);
|
||||
puffs_base_writer1 dst_writer = {.buf = dst};
|
||||
puffs_base_reader1 src_reader = {.buf = src};
|
||||
puffs_base__writer1 dst_writer = {.buf = dst};
|
||||
puffs_base__reader1 src_reader = {.buf = src};
|
||||
puffs_gif__status s =
|
||||
puffs_gif__decoder__decode(&dec, dst_writer, src_reader);
|
||||
if (s) {
|
||||
@@ -400,8 +401,8 @@ bool do_test_puffs_gif_decode(const char* filename,
|
||||
const char* indexes_filename,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
puffs_base_buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base_buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
|
||||
if (!read_file(&src, filename)) {
|
||||
return false;
|
||||
@@ -409,8 +410,8 @@ bool do_test_puffs_gif_decode(const char* filename,
|
||||
|
||||
puffs_gif__decoder dec;
|
||||
puffs_gif__decoder__initialize(&dec, PUFFS_VERSION, 0);
|
||||
puffs_base_writer1 got_writer = {.buf = &got};
|
||||
puffs_base_reader1 src_reader = {.buf = &src};
|
||||
puffs_base__writer1 got_writer = {.buf = &got};
|
||||
puffs_base__reader1 src_reader = {.buf = &src};
|
||||
int num_iters = 0;
|
||||
while (true) {
|
||||
num_iters++;
|
||||
@@ -483,8 +484,8 @@ bool do_test_puffs_gif_decode(const char* filename,
|
||||
}
|
||||
|
||||
// TODO: provide a public API for getting the palette.
|
||||
puffs_base_buf1 pal_got = {.ptr = dec.private_impl.f_gct, .len = 3 * 256};
|
||||
puffs_base_buf1 pal_want = {.ptr = global_palette_buffer, .len = 3 * 256};
|
||||
puffs_base__buf1 pal_got = {.ptr = dec.private_impl.f_gct, .len = 3 * 256};
|
||||
puffs_base__buf1 pal_want = {.ptr = global_palette_buffer, .len = 3 * 256};
|
||||
pal_got.wi = 3 * 256;
|
||||
if (!read_file(&pal_want, palette_filename)) {
|
||||
return false;
|
||||
@@ -493,7 +494,7 @@ bool do_test_puffs_gif_decode(const char* filename,
|
||||
return false;
|
||||
}
|
||||
|
||||
puffs_base_buf1 ind_want = {.ptr = global_want_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 ind_want = {.ptr = global_want_buffer, .len = BUFFER_SIZE};
|
||||
if (!read_file(&ind_want, indexes_filename)) {
|
||||
return false;
|
||||
}
|
||||
@@ -533,8 +534,8 @@ void test_puffs_gif_decode_input_is_a_gif_many_small_writes_reads() {
|
||||
void test_puffs_gif_decode_input_is_a_png() {
|
||||
proc_funcname = __func__;
|
||||
|
||||
puffs_base_buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base_buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
|
||||
if (!read_file(&src, "../../testdata/bricks-dither.png")) {
|
||||
return;
|
||||
@@ -542,8 +543,8 @@ void test_puffs_gif_decode_input_is_a_png() {
|
||||
|
||||
puffs_gif__decoder dec;
|
||||
puffs_gif__decoder__initialize(&dec, PUFFS_VERSION, 0);
|
||||
puffs_base_writer1 got_writer = {.buf = &got};
|
||||
puffs_base_reader1 src_reader = {.buf = &src};
|
||||
puffs_base__writer1 got_writer = {.buf = &got};
|
||||
puffs_base__reader1 src_reader = {.buf = &src};
|
||||
|
||||
puffs_gif__status status =
|
||||
puffs_gif__decoder__decode(&dec, got_writer, src_reader);
|
||||
@@ -562,13 +563,13 @@ void test_puffs_gif_decode_input_is_a_png() {
|
||||
#include "../mimiclib/gif.c"
|
||||
|
||||
bool do_test_mimic_gif_decode(const char* filename) {
|
||||
puffs_base_buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
if (!read_file(&src, filename)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
src.ri = 0;
|
||||
puffs_base_buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
const char* got_msg = puffs_gif_decode(&got, &src);
|
||||
if (got_msg) {
|
||||
FAIL("%s", got_msg);
|
||||
@@ -576,7 +577,7 @@ bool do_test_mimic_gif_decode(const char* filename) {
|
||||
}
|
||||
|
||||
src.ri = 0;
|
||||
puffs_base_buf1 want = {.ptr = global_want_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 want = {.ptr = global_want_buffer, .len = BUFFER_SIZE};
|
||||
const char* want_msg = mimic_gif_decode(&want, &src);
|
||||
if (want_msg) {
|
||||
FAIL("%s", want_msg);
|
||||
@@ -631,12 +632,12 @@ void test_mimic_gif_decode_pjw_thumbnail() {
|
||||
|
||||
// ---------------- GIF Benches
|
||||
|
||||
bool do_bench_gif_decode(const char* (*decode_func)(puffs_base_buf1*,
|
||||
puffs_base_buf1*),
|
||||
bool do_bench_gif_decode(const char* (*decode_func)(puffs_base__buf1*,
|
||||
puffs_base__buf1*),
|
||||
const char* filename,
|
||||
uint64_t reps) {
|
||||
puffs_base_buf1 dst = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base_buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 dst = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
|
||||
if (!read_file(&src, filename)) {
|
||||
return false;
|
||||
|
||||
+14
-14
@@ -181,10 +181,10 @@ int main(int argc, char** argv) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// PUFFS_BASE_HEADER_H is where puffs_base_buf1 is defined.
|
||||
// PUFFS_BASE_HEADER_H is where puffs_base__buf1 is defined.
|
||||
#ifdef PUFFS_BASE_HEADER_H
|
||||
|
||||
bool read_file(puffs_base_buf1* dst, const char* path) {
|
||||
bool read_file(puffs_base__buf1* dst, const char* path) {
|
||||
if (!dst || !path) {
|
||||
FAIL("read_file: NULL argument");
|
||||
return false;
|
||||
@@ -239,7 +239,7 @@ bool read_file(puffs_base_buf1* dst, const char* path) {
|
||||
return true;
|
||||
}
|
||||
|
||||
char* hex_dump(char* msg, puffs_base_buf1* buf, size_t i) {
|
||||
char* hex_dump(char* msg, puffs_base__buf1* buf, size_t i) {
|
||||
if (!msg || !buf) {
|
||||
FAIL("hex_dump: NULL argument");
|
||||
return false;
|
||||
@@ -290,8 +290,8 @@ char* hex_dump(char* msg, puffs_base_buf1* buf, size_t i) {
|
||||
}
|
||||
|
||||
bool buf1s_equal(const char* prefix,
|
||||
puffs_base_buf1* got,
|
||||
puffs_base_buf1* want) {
|
||||
puffs_base__buf1* got,
|
||||
puffs_base__buf1* want) {
|
||||
if (!got || !want) {
|
||||
FAIL("%sbuf1s_equal: NULL argument", prefix);
|
||||
return false;
|
||||
@@ -328,8 +328,8 @@ typedef enum {
|
||||
tc_src = 2,
|
||||
} throughput_counter;
|
||||
|
||||
bool proc_buf1_buf1(const char* (*codec_func)(puffs_base_buf1*,
|
||||
puffs_base_buf1*,
|
||||
bool proc_buf1_buf1(const char* (*codec_func)(puffs_base__buf1*,
|
||||
puffs_base__buf1*,
|
||||
uint64_t,
|
||||
uint64_t),
|
||||
throughput_counter tc,
|
||||
@@ -347,9 +347,9 @@ bool proc_buf1_buf1(const char* (*codec_func)(puffs_base_buf1*,
|
||||
return false;
|
||||
}
|
||||
|
||||
puffs_base_buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base_buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base_buf1 want = {.ptr = global_want_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 want = {.ptr = global_want_buffer, .len = BUFFER_SIZE};
|
||||
|
||||
if (!gt->src_filename) {
|
||||
src.closed = true;
|
||||
@@ -409,8 +409,8 @@ bool proc_buf1_buf1(const char* (*codec_func)(puffs_base_buf1*,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool do_bench_buf1_buf1(const char* (*codec_func)(puffs_base_buf1*,
|
||||
puffs_base_buf1*,
|
||||
bool do_bench_buf1_buf1(const char* (*codec_func)(puffs_base__buf1*,
|
||||
puffs_base__buf1*,
|
||||
uint64_t,
|
||||
uint64_t),
|
||||
throughput_counter tc,
|
||||
@@ -421,8 +421,8 @@ bool do_bench_buf1_buf1(const char* (*codec_func)(puffs_base_buf1*,
|
||||
return proc_buf1_buf1(codec_func, tc, gt, wlimit, rlimit, reps, true);
|
||||
}
|
||||
|
||||
bool do_test_buf1_buf1(const char* (*codec_func)(puffs_base_buf1*,
|
||||
puffs_base_buf1*,
|
||||
bool do_test_buf1_buf1(const char* (*codec_func)(puffs_base__buf1*,
|
||||
puffs_base__buf1*,
|
||||
uint64_t,
|
||||
uint64_t),
|
||||
golden_test* gt,
|
||||
|
||||
Reference in new issue
Block a user