mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
Rename PUFFS to WUFFS, part 7 of N
This commit is contained in:
1 parent
eda3130628
commit
3c708dfe59
23 files changed
+1610
-1610
No files matched your search
@@ -1,7 +1,7 @@
|
||||
// After editing this file, run "go generate" in this directory.
|
||||
|
||||
#ifndef PUFFS_BASE_HEADER_H
|
||||
#define PUFFS_BASE_HEADER_H
|
||||
#ifndef WUFFS_BASE_HEADER_H
|
||||
#define WUFFS_BASE_HEADER_H
|
||||
|
||||
// Copyright 2017 The Wuffs Authors.
|
||||
//
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
// Puffs requires a word size of at least 32 bits because it assumes that
|
||||
// Wuffs requires a word size of at least 32 bits because it assumes that
|
||||
// converting a u32 to usize will never overflow. For example, the size of a
|
||||
// decoded image is often represented, explicitly or implicitly in an image
|
||||
// file, as a u32, and it is convenient to compare that to a buffer size.
|
||||
@@ -29,12 +29,12 @@
|
||||
// Similarly, the word size is at most 64 bits because it assumes that
|
||||
// converting a usize to u64 will never overflow.
|
||||
#if __WORDSIZE < 32
|
||||
#error "Puffs requires a word size of at least 32 bits"
|
||||
#error "Wuffs requires a word size of at least 32 bits"
|
||||
#elif __WORDSIZE > 64
|
||||
#error "Puffs requires a word size of at most 64 bits"
|
||||
#error "Wuffs requires a word size of at most 64 bits"
|
||||
#endif
|
||||
|
||||
// PUFFS_VERSION is the major.minor version number as a uint32. The major
|
||||
// WUFFS_VERSION is the major.minor version number as a uint32. The major
|
||||
// number is the high 16 bits. The minor number is the low 16 bits.
|
||||
//
|
||||
// The intention is to bump the version number at least on every API / ABI
|
||||
@@ -43,17 +43,17 @@
|
||||
// For now, the API and ABI are simply unstable and can change at any time.
|
||||
//
|
||||
// TODO: don't hard code this in base-header.h.
|
||||
#define PUFFS_VERSION (0x00001)
|
||||
#define WUFFS_VERSION (0x00001)
|
||||
|
||||
// puffs_base__slice_u8 is a 1-dimensional buffer (a pointer and length).
|
||||
// wuffs_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;
|
||||
} wuffs_base__slice_u8;
|
||||
|
||||
// puffs_base__buf1 is a 1-dimensional buffer (a pointer and length), plus
|
||||
// wuffs_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,43 +63,43 @@ 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;
|
||||
} wuffs_base__buf1;
|
||||
|
||||
// puffs_base__limit1 provides a limited view of a 1-dimensional byte stream:
|
||||
// wuffs_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 {
|
||||
typedef struct wuffs_base__limit1 {
|
||||
uint64_t* ptr_to_len; // Pointer to N.
|
||||
struct puffs_base__limit1* next; // Linked list of limits.
|
||||
} puffs_base__limit1;
|
||||
struct wuffs_base__limit1* next; // Linked list of limits.
|
||||
} wuffs_base__limit1;
|
||||
|
||||
typedef struct {
|
||||
// TODO: move buf into private_impl? As it is, it looks like users can modify
|
||||
// the buf field to point to a different buffer, which can turn the limit and
|
||||
// mark fields into dangling pointers.
|
||||
puffs_base__buf1* buf;
|
||||
wuffs_base__buf1* buf;
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
// compatibility or safety guarantee if you do so.
|
||||
struct {
|
||||
puffs_base__limit1 limit;
|
||||
wuffs_base__limit1 limit;
|
||||
uint8_t* mark;
|
||||
} private_impl;
|
||||
} puffs_base__reader1;
|
||||
} wuffs_base__reader1;
|
||||
|
||||
typedef struct {
|
||||
// TODO: move buf into private_impl? As it is, it looks like users can modify
|
||||
// the buf field to point to a different buffer, which can turn the limit and
|
||||
// mark fields into dangling pointers.
|
||||
puffs_base__buf1* buf;
|
||||
wuffs_base__buf1* buf;
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
// compatibility or safety guarantee if you do so.
|
||||
struct {
|
||||
puffs_base__limit1 limit;
|
||||
wuffs_base__limit1 limit;
|
||||
uint8_t* mark;
|
||||
} private_impl;
|
||||
} puffs_base__writer1;
|
||||
} wuffs_base__writer1;
|
||||
|
||||
#endif // PUFFS_BASE_HEADER_H
|
||||
#endif // WUFFS_BASE_HEADER_H
|
||||
@@ -1,7 +1,7 @@
|
||||
// After editing this file, run "go generate" in this directory.
|
||||
|
||||
#ifndef PUFFS_BASE_IMPL_H
|
||||
#define PUFFS_BASE_IMPL_H
|
||||
#ifndef WUFFS_BASE_IMPL_H
|
||||
#define WUFFS_BASE_IMPL_H
|
||||
|
||||
// Copyright 2017 The Wuffs Authors.
|
||||
//
|
||||
@@ -17,39 +17,39 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// puffs_base__empty_struct is used when a Puffs function returns an empty
|
||||
// wuffs_base__empty_struct is used when a Wuffs function returns an empty
|
||||
// struct. In C, if a function f returns void, you can't say "x = f()", but in
|
||||
// Puffs, if a function g returns empty, you can say "y = g()".
|
||||
// Wuffs, if a function g returns empty, you can say "y = g()".
|
||||
typedef struct {
|
||||
} puffs_base__empty_struct;
|
||||
} wuffs_base__empty_struct;
|
||||
|
||||
#define PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(x) (void)(x)
|
||||
#define WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(x) (void)(x)
|
||||
|
||||
// PUFFS_BASE__MAGIC is a magic number to check that initializers are called.
|
||||
// WUFFS_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_BASE__MAGIC (0xCB3699CCU)
|
||||
#define WUFFS_BASE__MAGIC (0xCB3699CCU)
|
||||
|
||||
// PUFFS_BASE__ALREADY_ZEROED is passed from a container struct's initializer
|
||||
// WUFFS_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_BASE__ALREADY_ZEROED (0x68602EF1U)
|
||||
#define WUFFS_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 trivial macros instead of an explicit assignment and case statement
|
||||
// so that clang-format doesn't get confused by the unusual "case"s.
|
||||
#define PUFFS_BASE__COROUTINE_SUSPENSION_POINT_0 case 0:;
|
||||
#define PUFFS_BASE__COROUTINE_SUSPENSION_POINT(n) \
|
||||
#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0 case 0:;
|
||||
#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT(n) \
|
||||
coro_susp_point = n; \
|
||||
case n:;
|
||||
|
||||
#define PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \
|
||||
#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \
|
||||
if (status < 0) { \
|
||||
goto exit; \
|
||||
} else if (status == 0) { \
|
||||
@@ -61,11 +61,11 @@ typedef struct {
|
||||
|
||||
// Clang also defines "__GNUC__".
|
||||
#if defined(__GNUC__)
|
||||
#define PUFFS_BASE__LIKELY(expr) (__builtin_expect(!!(expr), 1))
|
||||
#define PUFFS_BASE__UNLIKELY(expr) (__builtin_expect(!!(expr), 0))
|
||||
#define WUFFS_BASE__LIKELY(expr) (__builtin_expect(!!(expr), 1))
|
||||
#define WUFFS_BASE__UNLIKELY(expr) (__builtin_expect(!!(expr), 0))
|
||||
#else
|
||||
#define PUFFS_BASE__LIKELY(expr) (expr)
|
||||
#define PUFFS_BASE__UNLIKELY(expr) (expr)
|
||||
#define WUFFS_BASE__LIKELY(expr) (expr)
|
||||
#define WUFFS_BASE__UNLIKELY(expr) (expr)
|
||||
#endif
|
||||
|
||||
// Uncomment this #include for printf-debugging.
|
||||
@@ -82,68 +82,68 @@ typedef struct {
|
||||
// "gif.c", without having to additionally include or otherwise build and link
|
||||
// a "base.c" file.
|
||||
//
|
||||
// They are static, so that linking multiple puffs .o files won't complain about
|
||||
// They are static, so that linking multiple wuffs .o files won't complain about
|
||||
// duplicate function definitions.
|
||||
//
|
||||
// They are explicitly marked inline, even if modern compilers don't use the
|
||||
// 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 wuffs_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 wuffs_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 wuffs_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 wuffs_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 wuffs_base__slice_u8 wuffs_base__slice_u8__subslice_i(
|
||||
wuffs_base__slice_u8 s,
|
||||
uint64_t i) {
|
||||
if ((i <= SIZE_MAX) && (i <= s.len)) {
|
||||
return ((puffs_base__slice_u8){
|
||||
return ((wuffs_base__slice_u8){
|
||||
.ptr = s.ptr + i,
|
||||
.len = s.len - i,
|
||||
});
|
||||
}
|
||||
return ((puffs_base__slice_u8){});
|
||||
return ((wuffs_base__slice_u8){});
|
||||
}
|
||||
|
||||
static inline puffs_base__slice_u8 puffs_base__slice_u8__subslice_j(
|
||||
puffs_base__slice_u8 s,
|
||||
static inline wuffs_base__slice_u8 wuffs_base__slice_u8__subslice_j(
|
||||
wuffs_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 ((wuffs_base__slice_u8){.ptr = s.ptr, .len = j});
|
||||
}
|
||||
return ((puffs_base__slice_u8){});
|
||||
return ((wuffs_base__slice_u8){});
|
||||
}
|
||||
|
||||
static inline puffs_base__slice_u8 puffs_base__slice_u8__subslice_ij(
|
||||
puffs_base__slice_u8 s,
|
||||
static inline wuffs_base__slice_u8 wuffs_base__slice_u8__subslice_ij(
|
||||
wuffs_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 ((wuffs_base__slice_u8){
|
||||
.ptr = s.ptr + i,
|
||||
.len = j - i,
|
||||
});
|
||||
}
|
||||
return ((puffs_base__slice_u8){});
|
||||
return ((wuffs_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,
|
||||
// wuffs_base__slice_u8__prefix returns up to the first up_to bytes of s.
|
||||
static inline wuffs_base__slice_u8 wuffs_base__slice_u8__prefix(
|
||||
wuffs_base__slice_u8 s,
|
||||
uint64_t up_to) {
|
||||
if ((uint64_t)(s.len) > up_to) {
|
||||
s.len = up_to;
|
||||
@@ -151,9 +151,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,
|
||||
// wuffs_base__slice_u8__suffix returns up to the last up_to bytes of s.
|
||||
static inline wuffs_base__slice_u8 wuffs_base__slice_u8_suffix(
|
||||
wuffs_base__slice_u8 s,
|
||||
uint64_t up_to) {
|
||||
if ((uint64_t)(s.len) > up_to) {
|
||||
s.ptr += (uint64_t)(s.len) - up_to;
|
||||
@@ -162,14 +162,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,
|
||||
// wuffs_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 wuffs_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 wuffs_base__slice_u8__copy_from_slice(
|
||||
wuffs_base__slice_u8 dst,
|
||||
wuffs_base__slice_u8 src) {
|
||||
size_t length = dst.len < src.len ? dst.len : src.len;
|
||||
if (length > 0) {
|
||||
memmove(dst.ptr, src.ptr, length);
|
||||
@@ -177,7 +177,7 @@ static inline uint64_t puffs_base__slice_u8__copy_from_slice(
|
||||
return length;
|
||||
}
|
||||
|
||||
static inline uint32_t puffs_base__writer1__copy_from_history32(
|
||||
static inline uint32_t wuffs_base__writer1__copy_from_history32(
|
||||
uint8_t** ptr_ptr,
|
||||
uint8_t* start, // May be NULL, meaning an unmarked writer1.
|
||||
uint8_t* end,
|
||||
@@ -200,10 +200,10 @@ static inline uint32_t puffs_base__writer1__copy_from_history32(
|
||||
// TODO: unrolling by 3 seems best for the std/flate benchmarks, but that is
|
||||
// mostly because 3 is the minimum length for the flate format. This function
|
||||
// implementation shouldn't overfit to that one format. Perhaps the
|
||||
// copy_from_history32 Puffs method should also take an unroll hint argument,
|
||||
// copy_from_history32 Wuffs method should also take an unroll hint argument,
|
||||
// and the cgen can look if that argument is the constant expression '3'.
|
||||
//
|
||||
// See also puffs_base__writer1__copy_from_history32__bco below.
|
||||
// See also wuffs_base__writer1__copy_from_history32__bco below.
|
||||
//
|
||||
// Alternatively, or additionally, have a sloppy_copy_from_history32 method
|
||||
// that copies 8 bytes at a time, possibly writing more than length bytes?
|
||||
@@ -219,14 +219,14 @@ static inline uint32_t puffs_base__writer1__copy_from_history32(
|
||||
return length;
|
||||
}
|
||||
|
||||
// puffs_base__writer1__copy_from_history32__bco is a Bounds Check Optimized
|
||||
// version of the puffs_base__writer1__copy_from_history32 function above. The
|
||||
// wuffs_base__writer1__copy_from_history32__bco is a Bounds Check Optimized
|
||||
// version of the wuffs_base__writer1__copy_from_history32 function above. The
|
||||
// caller needs to prove that:
|
||||
// - start != NULL
|
||||
// - distance != 0
|
||||
// - distance <= (*ptr_ptr - start)
|
||||
// - length <= (end - *ptr_ptr)
|
||||
static inline uint32_t puffs_base__writer1__copy_from_history32__bco(
|
||||
static inline uint32_t wuffs_base__writer1__copy_from_history32__bco(
|
||||
uint8_t** ptr_ptr,
|
||||
uint8_t* start,
|
||||
uint8_t* end,
|
||||
@@ -247,7 +247,7 @@ static inline uint32_t puffs_base__writer1__copy_from_history32__bco(
|
||||
return length;
|
||||
}
|
||||
|
||||
static inline uint32_t puffs_base__writer1__copy_from_reader32(
|
||||
static inline uint32_t wuffs_base__writer1__copy_from_reader32(
|
||||
uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
uint8_t** ptr_rptr,
|
||||
@@ -270,10 +270,10 @@ static inline uint32_t puffs_base__writer1__copy_from_reader32(
|
||||
return n;
|
||||
}
|
||||
|
||||
static inline uint64_t puffs_base__writer1__copy_from_slice(
|
||||
static inline uint64_t wuffs_base__writer1__copy_from_slice(
|
||||
uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
puffs_base__slice_u8 src) {
|
||||
wuffs_base__slice_u8 src) {
|
||||
uint8_t* wptr = *ptr_wptr;
|
||||
size_t n = src.len;
|
||||
if (n > wend - wptr) {
|
||||
@@ -286,10 +286,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 wuffs_base__writer1__copy_from_slice32(
|
||||
uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
puffs_base__slice_u8 src,
|
||||
wuffs_base__slice_u8 src,
|
||||
uint32_t length) {
|
||||
uint8_t* wptr = *ptr_wptr;
|
||||
size_t n = src.len;
|
||||
@@ -308,39 +308,39 @@ static inline uint32_t puffs_base__writer1__copy_from_slice32(
|
||||
|
||||
// Note that the *__limit and *__mark methods are private (in base-impl.h) not
|
||||
// public (in base-header.h). We assume that, at the boundary between user code
|
||||
// and Puffs code, the reader1 and writer1's private_impl fields (including
|
||||
// and Wuffs code, the reader1 and writer1's private_impl fields (including
|
||||
// limit and mark) are NULL. Otherwise, some internal assumptions break down.
|
||||
// For example, limits could be represented as pointers, even though
|
||||
// conceptually they are counts, but that pointer-to-count correspondence
|
||||
// becomes invalid if a buffer is re-used (e.g. on resuming a coroutine).
|
||||
//
|
||||
// Admittedly, some of the Puffs test code calls these methods, but that test
|
||||
// code is still Puffs code, not user code. Other Puffs test code modifies
|
||||
// Admittedly, some of the Wuffs test code calls these methods, but that test
|
||||
// code is still Wuffs code, not user code. Other Wuffs test code modifies
|
||||
// private_impl fields directly.
|
||||
|
||||
static inline puffs_base__reader1 puffs_base__reader1__limit(
|
||||
puffs_base__reader1* o,
|
||||
static inline wuffs_base__reader1 wuffs_base__reader1__limit(
|
||||
wuffs_base__reader1* o,
|
||||
uint64_t* ptr_to_len) {
|
||||
puffs_base__reader1 ret = *o;
|
||||
wuffs_base__reader1 ret = *o;
|
||||
ret.private_impl.limit.ptr_to_len = ptr_to_len;
|
||||
ret.private_impl.limit.next = &o->private_impl.limit;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline puffs_base__empty_struct puffs_base__reader1__mark(
|
||||
puffs_base__reader1* o,
|
||||
static inline wuffs_base__empty_struct wuffs_base__reader1__mark(
|
||||
wuffs_base__reader1* o,
|
||||
uint8_t* mark) {
|
||||
o->private_impl.mark = mark;
|
||||
return ((puffs_base__empty_struct){});
|
||||
return ((wuffs_base__empty_struct){});
|
||||
}
|
||||
|
||||
// TODO: static inline puffs_base__writer1 puffs_base__writer1__limit()
|
||||
// TODO: static inline wuffs_base__writer1 wuffs_base__writer1__limit()
|
||||
|
||||
static inline puffs_base__empty_struct puffs_base__writer1__mark(
|
||||
puffs_base__writer1* o,
|
||||
static inline wuffs_base__empty_struct wuffs_base__writer1__mark(
|
||||
wuffs_base__writer1* o,
|
||||
uint8_t* mark) {
|
||||
o->private_impl.mark = mark;
|
||||
return ((puffs_base__empty_struct){});
|
||||
return ((wuffs_base__empty_struct){});
|
||||
}
|
||||
|
||||
#endif // PUFFS_BASE_IMPL_H
|
||||
#endif // WUFFS_BASE_IMPL_H
|
||||
@@ -39,7 +39,7 @@ var (
|
||||
)
|
||||
|
||||
// Prefixes are prepended to names to form a namespace and to avoid e.g.
|
||||
// "double" being a valid Puffs variable name but not a valid C one.
|
||||
// "double" being a valid Wuffs variable name but not a valid C one.
|
||||
const (
|
||||
aPrefix = "a_" // Function argument.
|
||||
bPrefix = "b_" // Derived from a function argument.
|
||||
@@ -50,17 +50,17 @@ const (
|
||||
vPrefix = "v_" // Local variable.
|
||||
)
|
||||
|
||||
// Do transpiles a Puffs program to a C program.
|
||||
// Do transpiles a Wuffs program to a C program.
|
||||
//
|
||||
// The arguments list the source Puffs files. If no arguments are given, it
|
||||
// The arguments list the source Wuffs files. If no arguments are given, it
|
||||
// reads from stdin.
|
||||
//
|
||||
// The generated program is written to stdout.
|
||||
func Do(args []string) error {
|
||||
return generate.Do(args, func(pkgName string, tm *t.Map, c *check.Checker, files []*a.File) ([]byte, error) {
|
||||
g := &gen{
|
||||
PKGPREFIX: "PUFFS_" + strings.ToUpper(pkgName) + "__",
|
||||
pkgPrefix: "puffs_" + pkgName + "__",
|
||||
PKGPREFIX: "WUFFS_" + strings.ToUpper(pkgName) + "__",
|
||||
pkgPrefix: "wuffs_" + pkgName + "__",
|
||||
pkgName: pkgName,
|
||||
tm: tm,
|
||||
checker: c,
|
||||
@@ -153,8 +153,8 @@ func (b *buffer) writes(s string) { *b = append(*b, s.
|
||||
func (b *buffer) writex(s []byte) { *b = append(*b, s...) }
|
||||
|
||||
type gen struct {
|
||||
PKGPREFIX string // e.g. "PUFFS_JPEG__"
|
||||
pkgPrefix string // e.g. "puffs_jpeg__"
|
||||
PKGPREFIX string // e.g. "WUFFS_JPEG__"
|
||||
pkgPrefix string // e.g. "wuffs_jpeg__"
|
||||
pkgName string // e.g. "jpeg"
|
||||
|
||||
tm *t.Map
|
||||
@@ -211,7 +211,7 @@ func (g *gen) generate() ([]byte, error) {
|
||||
}
|
||||
|
||||
func (g *gen) genHeader(b *buffer) error {
|
||||
includeGuard := "PUFFS_" + strings.ToUpper(g.pkgName) + "_H"
|
||||
includeGuard := "WUFFS_" + strings.ToUpper(g.pkgName) + "_H"
|
||||
b.printf("#ifndef %s\n#define %s\n\n", includeGuard, includeGuard)
|
||||
|
||||
b.printf("// Code generated by wuffs-c. DO NOT EDIT.\n\n")
|
||||
@@ -492,7 +492,7 @@ func (g *gen) writeConstList(b *buffer, n *a.Expr) error {
|
||||
func (g *gen) writeStruct(b *buffer, n *a.Struct) error {
|
||||
// For API/ABI compatibility, the very first field in the struct's
|
||||
// private_impl must be the status code. This lets the initializer callee
|
||||
// set "self->private_impl.status = PUFFS_ETC__ERROR_BAD_PUFFS_VERSION;"
|
||||
// set "self->private_impl.status = WUFFS_ETC__ERROR_BAD_WUFFS_VERSION;"
|
||||
// regardless of the sizeof(*self) struct reserved by the caller and even
|
||||
// if the caller and callee were built with different versions.
|
||||
structName := n.Name().String(g.tm)
|
||||
@@ -563,10 +563,10 @@ func (g *gen) writeInitializerSignature(b *buffer, n *a.Struct, public bool) err
|
||||
b.printf("// It should be called before any other %s%s__* function.\n",
|
||||
g.pkgPrefix, structName)
|
||||
b.printf("//\n")
|
||||
b.printf("// Pass PUFFS_VERSION and 0 for puffs_version and for_internal_use_only.\n")
|
||||
b.printf("// Pass WUFFS_VERSION and 0 for wuffs_version and for_internal_use_only.\n")
|
||||
}
|
||||
b.printf("void %s%s__initialize(%s%s *self", g.pkgPrefix, structName, g.pkgPrefix, structName)
|
||||
b.printf(", uint32_t puffs_version, uint32_t for_internal_use_only")
|
||||
b.printf(", uint32_t wuffs_version, uint32_t for_internal_use_only")
|
||||
b.printf(")")
|
||||
return nil
|
||||
}
|
||||
@@ -592,14 +592,14 @@ func (g *gen) writeInitializerImpl(b *buffer, n *a.Struct) error {
|
||||
b.printf("{\n")
|
||||
b.printf("if (!self) { return; }\n")
|
||||
|
||||
b.printf("if (puffs_version != PUFFS_VERSION) {\n")
|
||||
b.printf("self->private_impl.status = %sERROR_BAD_PUFFS_VERSION;\n", g.PKGPREFIX)
|
||||
b.printf("if (wuffs_version != WUFFS_VERSION) {\n")
|
||||
b.printf("self->private_impl.status = %sERROR_BAD_WUFFS_VERSION;\n", g.PKGPREFIX)
|
||||
b.printf("return;\n")
|
||||
b.printf("}\n")
|
||||
|
||||
b.writes("if (for_internal_use_only != PUFFS_BASE__ALREADY_ZEROED) {" +
|
||||
b.writes("if (for_internal_use_only != WUFFS_BASE__ALREADY_ZEROED) {" +
|
||||
"memset(self, 0, sizeof(*self)); }\n")
|
||||
b.writes("self->private_impl.magic = PUFFS_BASE__MAGIC;\n")
|
||||
b.writes("self->private_impl.magic = WUFFS_BASE__MAGIC;\n")
|
||||
|
||||
for _, f := range n.Fields() {
|
||||
f := f.Field()
|
||||
@@ -621,7 +621,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_BASE__ALREADY_ZEROED);\n",
|
||||
"WUFFS_VERSION, WUFFS_BASE__ALREADY_ZEROED);\n",
|
||||
g.pkgPrefix, x.Name().String(g.tm), fPrefix, f.Name().String(g.tm))
|
||||
}
|
||||
|
||||
|
||||
@@ -17,24 +17,24 @@
|
||||
package cgen
|
||||
|
||||
const baseHeader = "" +
|
||||
"#ifndef PUFFS_BASE_HEADER_H\n#define PUFFS_BASE_HEADER_H\n\n// Copyright 2017 The Wuffs 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, 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 // TODO: move buf into private_impl? As it is, it looks like users can modify\n // the buf field to point to a different buffer, which can turn the l" +
|
||||
"imit and\n // mark fields into dangling pointers.\n puffs_base__buf1* buf;\n // Do not access the private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n puffs_base__limit1 limit;\n uint8_t* mark;\n } private_impl;\n} puffs_base__reader1;\n\ntypedef struct {\n // TODO: move buf into private_impl? As it is, it looks like users can modify\n // the buf field to point to a different buffer, which can turn the limit and\n // mark fields into dangling pointers.\n puffs_base__buf1* buf;\n // Do not access the private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n puffs_base__limit1 limit;\n uint8_t* mark;\n } private_impl;\n} puffs_base__writer1;\n\n#endif // PUFFS_BASE_HEADER_H\n" +
|
||||
"#ifndef WUFFS_BASE_HEADER_H\n#define WUFFS_BASE_HEADER_H\n\n// Copyright 2017 The Wuffs 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// Wuffs 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 \"Wuffs requires a word size of at least 32 bits\"\n#elif __WORDSIZE > 64\n#error \"Wuffs requires a word size of at most 64 bits\"\n#endif\n\n// WUFFS_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 WUFFS_VERSION (0x00001)\n\n// wuffs_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} wuffs_base__slice_u8;\n\n// wuffs_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} wuffs_base__buf1;\n\n// wuffs_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 wuffs_base__limit1 {\n uint64_t* ptr_to_len; // Pointer to N.\n struct wuffs_base__limit1* next; // Linked list of limits.\n} wuffs_base__limit1;\n\ntypedef struct {\n // TODO: move buf into private_impl? As it is, it looks like users can modify\n // the buf field to point to a different buffer, which can turn the l" +
|
||||
"imit and\n // mark fields into dangling pointers.\n wuffs_base__buf1* buf;\n // Do not access the private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n wuffs_base__limit1 limit;\n uint8_t* mark;\n } private_impl;\n} wuffs_base__reader1;\n\ntypedef struct {\n // TODO: move buf into private_impl? As it is, it looks like users can modify\n // the buf field to point to a different buffer, which can turn the limit and\n // mark fields into dangling pointers.\n wuffs_base__buf1* buf;\n // Do not access the private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n wuffs_base__limit1 limit;\n uint8_t* mark;\n } private_impl;\n} wuffs_base__writer1;\n\n#endif // WUFFS_BASE_HEADER_H\n" +
|
||||
""
|
||||
|
||||
const baseImpl = "" +
|
||||
"#ifndef PUFFS_BASE_IMPL_H\n#define PUFFS_BASE_IMPL_H\n\n// Copyright 2017 The Wuffs 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// puffs_base__empty_struct is used when a Puffs function returns an empty\n// struct. In C, if a function f returns void, you can't say \"x = f()\", but in\n// Puffs, if a function g returns empty, you can say \"y = g()\".\ntypedef struct {\n} puffs_base__empty_struct;\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 trivial macros 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_0 case 0:;\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#else\n#define PUFFS_BASE__LIKELY(expr) (expr)\n#define PUFFS_BASE__UNLIKELY(expr) (expr)\n#endif\n\n// Uncomment this #include for printf-debugging.\n// #include <stdio.h>\n\n// ---------------- Static Inline Functions\n//\n// The helpers below are functions, instead of macros, because their argume" +
|
||||
"nts\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\", 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 puf" +
|
||||
"fs_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 puffs_base__slice_u8__subslice_ij(\n puffs_base__slice_u8 s,\n uint64_t i,\n uin" +
|
||||
"t64_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.\ns" +
|
||||
"tatic 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(\n uint8_t** ptr_ptr,\n uint8_t* start, // May be NULL, meaning an unmarked writer1.\n uint8_t* end,\n uint32_t distance,\n uint32_t length) {\n if (!start || !distance) {\n return 0;\n }\n uint8_t* ptr = *ptr_ptr;\n if ((size_t)(ptr - start) < (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: unrolling by 3 seems best for the std/flate benchmarks, but that is\n // mostly because 3 is the minimum length for the flate format. This function\n // implementation shouldn't overfit to that one format. Perhaps the\n // copy_from_history32 Puffs method shoul" +
|
||||
"d also take an unroll hint argument,\n // and the cgen can look if that argument is the constant expression '3'.\n //\n // See also puffs_base__writer1__copy_from_history32__bco below.\n //\n // Alternatively, or additionally, have a sloppy_copy_from_history32 method\n // that copies 8 bytes at a time, possibly writing more than length bytes?\n for (; n >= 3; n -= 3) {\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\n// puffs_base__writer1__copy_from_history32__bco is a Bounds Check Optimized\n// version of the puffs_base__writer1__copy_from_history32 function above. The\n// caller needs to prove that:\n// - start != NULL\n// - distance != 0\n// - distance <= (*ptr_ptr - start)\n// - length <= (end - *ptr_ptr)\nstatic inline uint32_t puffs_base__writer1__copy_from_history32__bco(\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 start = ptr - distance;\n uint32_t n = length;\n for (; n >= 3; n -= 3) {\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 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 = *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// Note that the *__limit and *__mark methods are private (in base-impl.h) not\n// public (in base-header.h). We assume that, at the boundary between user code\n// and Puffs code, the reader1 and writer1's private_impl fields (including\n// limit and mark) are NULL. Otherwise, some internal assumptions break down.\n// For example, limits could be represented as pointers, even though\n// conceptually they are counts, but that pointer-to-count correspondence\n// becomes invalid if a buffer is re-used (e.g. on resuming a coroutine).\n//\n// Admittedly, some of the Puffs test code calls these methods, but that test\n// code is still Puffs code" +
|
||||
", not user code. Other Puffs test code modifies\n// private_impl fields directly.\n\nstatic inline puffs_base__reader1 puffs_base__reader1__limit(\n puffs_base__reader1* o,\n uint64_t* ptr_to_len) {\n puffs_base__reader1 ret = *o;\n ret.private_impl.limit.ptr_to_len = ptr_to_len;\n ret.private_impl.limit.next = &o->private_impl.limit;\n return ret;\n}\n\nstatic inline puffs_base__empty_struct puffs_base__reader1__mark(\n puffs_base__reader1* o,\n uint8_t* mark) {\n o->private_impl.mark = mark;\n return ((puffs_base__empty_struct){});\n}\n\n// TODO: static inline puffs_base__writer1 puffs_base__writer1__limit()\n\nstatic inline puffs_base__empty_struct puffs_base__writer1__mark(\n puffs_base__writer1* o,\n uint8_t* mark) {\n o->private_impl.mark = mark;\n return ((puffs_base__empty_struct){});\n}\n\n#endif // PUFFS_BASE_IMPL_H\n" +
|
||||
"#ifndef WUFFS_BASE_IMPL_H\n#define WUFFS_BASE_IMPL_H\n\n// Copyright 2017 The Wuffs 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// wuffs_base__empty_struct is used when a Wuffs function returns an empty\n// struct. In C, if a function f returns void, you can't say \"x = f()\", but in\n// Wuffs, if a function g returns empty, you can say \"y = g()\".\ntypedef struct {\n} wuffs_base__empty_struct;\n\n#define WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(x) (void)(x)\n\n// WUFFS_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 WUFFS_BASE__MAGIC (0xCB3699CCU)\n\n// WUFFS_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 WUFFS_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 trivial macros instead of an explicit assignment and case statement\n// so that clang-format doesn't get confused by the unusual \"case\"s.\n#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0 case 0:;\n#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT(n) \\\n coro_susp_point = n; \\\n case" +
|
||||
" n:;\n\n#define WUFFS_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 WUFFS_BASE__LIKELY(expr) (__builtin_expect(!!(expr), 1))\n#define WUFFS_BASE__UNLIKELY(expr) (__builtin_expect(!!(expr), 0))\n#else\n#define WUFFS_BASE__LIKELY(expr) (expr)\n#define WUFFS_BASE__UNLIKELY(expr) (expr)\n#endif\n\n// Uncomment this #include for printf-debugging.\n// #include <stdio.h>\n\n// ---------------- Static Inline Functions\n//\n// The helpers below are functions, instead of macros, because their argume" +
|
||||
"nts\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\", without having to additionally include or otherwise build and link\n// a \"base.c\" file.\n//\n// They are static, so that linking multiple wuffs .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 wuffs_base__load_u16be(uint8_t* p) {\n return ((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0);\n}\n\nstatic inline uint16_t wuffs_base__load_u16le(uint8_t* p) {\n return ((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8);\n}\n\nstatic inline uint32_t wuf" +
|
||||
"fs_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 wuffs_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 wuffs_base__slice_u8 wuffs_base__slice_u8__subslice_i(\n wuffs_base__slice_u8 s,\n uint64_t i) {\n if ((i <= SIZE_MAX) && (i <= s.len)) {\n return ((wuffs_base__slice_u8){\n .ptr = s.ptr + i,\n .len = s.len - i,\n });\n }\n return ((wuffs_base__slice_u8){});\n}\n\nstatic inline wuffs_base__slice_u8 wuffs_base__slice_u8__subslice_j(\n wuffs_base__slice_u8 s,\n uint64_t j) {\n if ((j <= SIZE_MAX) && (j <= s.len)) {\n return ((wuffs_base__slice_u8){.ptr = s.ptr, .len = j});\n }\n return ((wuffs_base__slice_u8){});\n}\n\nstatic inline wuffs_base__slice_u8 wuffs_base__slice_u8__subslice_ij(\n wuffs_base__slice_u8 s,\n uint64_t i,\n uin" +
|
||||
"t64_t j) {\n if ((i <= j) && (j <= SIZE_MAX) && (j <= s.len)) {\n return ((wuffs_base__slice_u8){\n .ptr = s.ptr + i,\n .len = j - i,\n });\n }\n return ((wuffs_base__slice_u8){});\n}\n\n// wuffs_base__slice_u8__prefix returns up to the first up_to bytes of s.\nstatic inline wuffs_base__slice_u8 wuffs_base__slice_u8__prefix(\n wuffs_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// wuffs_base__slice_u8__suffix returns up to the last up_to bytes of s.\nstatic inline wuffs_base__slice_u8 wuffs_base__slice_u8_suffix(\n wuffs_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// wuffs_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 wuffs_base__slice_u8 with all fields NULL or zero (a valid, empty\n// slice) is valid and results in a no-op.\ns" +
|
||||
"tatic inline uint64_t wuffs_base__slice_u8__copy_from_slice(\n wuffs_base__slice_u8 dst,\n wuffs_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 wuffs_base__writer1__copy_from_history32(\n uint8_t** ptr_ptr,\n uint8_t* start, // May be NULL, meaning an unmarked writer1.\n uint8_t* end,\n uint32_t distance,\n uint32_t length) {\n if (!start || !distance) {\n return 0;\n }\n uint8_t* ptr = *ptr_ptr;\n if ((size_t)(ptr - start) < (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: unrolling by 3 seems best for the std/flate benchmarks, but that is\n // mostly because 3 is the minimum length for the flate format. This function\n // implementation shouldn't overfit to that one format. Perhaps the\n // copy_from_history32 Wuffs method shoul" +
|
||||
"d also take an unroll hint argument,\n // and the cgen can look if that argument is the constant expression '3'.\n //\n // See also wuffs_base__writer1__copy_from_history32__bco below.\n //\n // Alternatively, or additionally, have a sloppy_copy_from_history32 method\n // that copies 8 bytes at a time, possibly writing more than length bytes?\n for (; n >= 3; n -= 3) {\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\n// wuffs_base__writer1__copy_from_history32__bco is a Bounds Check Optimized\n// version of the wuffs_base__writer1__copy_from_history32 function above. The\n// caller needs to prove that:\n// - start != NULL\n// - distance != 0\n// - distance <= (*ptr_ptr - start)\n// - length <= (end - *ptr_ptr)\nstatic inline uint32_t wuffs_base__writer1__copy_from_history32__bco(\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 start = ptr - distance;\n uint32_t n = length;\n for (; n >= 3; n -= 3) {\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 wuffs_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 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 wuffs_base__writer1__copy_from_slice(\n uint8_t** ptr_wptr,\n uint8_t* wend,\n wuffs_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 wuffs_base__writer1__copy_from_slice32(\n uint8_t** ptr_wptr,\n uint8_t* wend,\n wuffs_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// Note that the *__limit and *__mark methods are private (in base-impl.h) not\n// public (in base-header.h). We assume that, at the boundary between user code\n// and Wuffs code, the reader1 and writer1's private_impl fields (including\n// limit and mark) are NULL. Otherwise, some internal assumptions break down.\n// For example, limits could be represented as pointers, even though\n// conceptually they are counts, but that pointer-to-count correspondence\n// becomes invalid if a buffer is re-used (e.g. on resuming a coroutine).\n//\n// Admittedly, some of the Wuffs test code calls these methods, but that test\n// code is still Wuffs code" +
|
||||
", not user code. Other Wuffs test code modifies\n// private_impl fields directly.\n\nstatic inline wuffs_base__reader1 wuffs_base__reader1__limit(\n wuffs_base__reader1* o,\n uint64_t* ptr_to_len) {\n wuffs_base__reader1 ret = *o;\n ret.private_impl.limit.ptr_to_len = ptr_to_len;\n ret.private_impl.limit.next = &o->private_impl.limit;\n return ret;\n}\n\nstatic inline wuffs_base__empty_struct wuffs_base__reader1__mark(\n wuffs_base__reader1* o,\n uint8_t* mark) {\n o->private_impl.mark = mark;\n return ((wuffs_base__empty_struct){});\n}\n\n// TODO: static inline wuffs_base__writer1 wuffs_base__writer1__limit()\n\nstatic inline wuffs_base__empty_struct wuffs_base__writer1__mark(\n wuffs_base__writer1* o,\n uint8_t* mark) {\n o->private_impl.mark = mark;\n return ((wuffs_base__empty_struct){});\n}\n\n#endif // WUFFS_BASE_IMPL_H\n" +
|
||||
""
|
||||
|
||||
type template_args_short_read struct {
|
||||
|
||||
@@ -159,7 +159,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("wuffs_base__slice_u8_suffix(")
|
||||
x := n.LHS().Expr().LHS().Expr()
|
||||
if err := g.writeExpr(b, x, rp, parenthesesOptional, depth); err != nil {
|
||||
return err
|
||||
@@ -175,11 +175,11 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
return fmt.Errorf(`TODO: cgen an "in.src.limit" expression`)
|
||||
}
|
||||
if isInSrc(g.tm, n, t.KeyMark, 0) {
|
||||
b.printf("puffs_base__reader1__mark(&%ssrc, %srptr_src)", aPrefix, bPrefix)
|
||||
b.printf("wuffs_base__reader1__mark(&%ssrc, %srptr_src)", aPrefix, bPrefix)
|
||||
return nil
|
||||
}
|
||||
if isInSrc(g.tm, n, t.KeySinceMark, 0) {
|
||||
b.printf("((puffs_base__slice_u8){ "+
|
||||
b.printf("((wuffs_base__slice_u8){ "+
|
||||
".ptr = %ssrc.private_impl.mark, "+
|
||||
".len = %ssrc.private_impl.mark ? (size_t)(%srptr_src - %ssrc.private_impl.mark) : 0, })",
|
||||
aPrefix, aPrefix, bPrefix, aPrefix)
|
||||
@@ -194,7 +194,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
// the function is passed a (ptr writer1) instead of a (writer1)?
|
||||
// Do we still want to have that mark live outside of the function
|
||||
// scope?
|
||||
b.printf("puffs_base__writer1__mark(&%sdst, %swptr_dst)", aPrefix, bPrefix)
|
||||
b.printf("wuffs_base__writer1__mark(&%sdst, %swptr_dst)", aPrefix, bPrefix)
|
||||
return nil
|
||||
}
|
||||
if isInDst(g.tm, n, t.KeySinceMark, 0) {
|
||||
@@ -207,7 +207,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
len0 = aPrefix + "dst.private_impl.mark ?"
|
||||
len1 = ": 0"
|
||||
}
|
||||
b.printf("((puffs_base__slice_u8){ "+
|
||||
b.printf("((wuffs_base__slice_u8){ "+
|
||||
".ptr = %sdst.private_impl.mark, "+
|
||||
".len = %s (size_t)(%swptr_dst - %sdst.private_impl.mark) %s, })",
|
||||
aPrefix, len0, bPrefix, aPrefix, len1)
|
||||
@@ -224,7 +224,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
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("wuffs_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()
|
||||
@@ -239,7 +239,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
if n.BoundsCheckOptimized() {
|
||||
bco = "__bco"
|
||||
}
|
||||
b.printf("puffs_base__writer1__copy_from_history32%s(&%swptr_dst, %sdst.private_impl.mark , %swend_dst",
|
||||
b.printf("wuffs_base__writer1__copy_from_history32%s(&%swptr_dst, %sdst.private_impl.mark , %swend_dst",
|
||||
bco, bPrefix, aPrefix, bPrefix)
|
||||
for _, o := range n.Args() {
|
||||
b.writeb(',')
|
||||
@@ -251,7 +251,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("wuffs_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 {
|
||||
@@ -262,7 +262,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("wuffs_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
|
||||
@@ -271,7 +271,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("wuffs_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
|
||||
@@ -348,12 +348,12 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
}
|
||||
if isThatMethod(g.tm, n, t.KeyMark, 0) {
|
||||
// TODO: don't hard-code v_r or b_rptr_src.
|
||||
b.printf("puffs_base__reader1__mark(&v_r, b_rptr_src)")
|
||||
b.printf("wuffs_base__reader1__mark(&v_r, b_rptr_src)")
|
||||
return nil
|
||||
}
|
||||
if isThatMethod(g.tm, n, t.KeySinceMark, 0) {
|
||||
// TODO: don't hard-code v_r or b_rptr_src.
|
||||
b.printf("((puffs_base__slice_u8){ " +
|
||||
b.printf("((wuffs_base__slice_u8){ " +
|
||||
".ptr = v_r.private_impl.mark, " +
|
||||
".len = v_r.private_impl.mark ? (size_t)(b_rptr_src - v_r.private_impl.mark) : 0, })")
|
||||
return nil
|
||||
@@ -383,17 +383,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("wuffs_base__slice_u8__subslice_i(")
|
||||
case mhs == nil && rhs != nil:
|
||||
b.writes("puffs_base__slice_u8__subslice_j(")
|
||||
b.writes("wuffs_base__slice_u8__subslice_j(")
|
||||
case mhs != nil && rhs != nil:
|
||||
b.writes("puffs_base__slice_u8__subslice_ij(")
|
||||
b.writes("wuffs_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("((wuffs_base__slice_u8){.ptr=")
|
||||
}
|
||||
if err := g.writeExpr(b, lhs, rp, parenthesesOptional, depth); err != nil {
|
||||
return err
|
||||
@@ -524,13 +524,13 @@ 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("wuffs_base__slice_u8")
|
||||
b.writeb(' ')
|
||||
b.writes(varNamePrefix)
|
||||
b.writes(varName)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("cannot convert Puffs type %q to C", n.String(g.tm))
|
||||
return fmt.Errorf("cannot convert Wuffs type %q to C", n.String(g.tm))
|
||||
}
|
||||
|
||||
// maxNumPointers is an arbitrary implementation restriction.
|
||||
@@ -545,13 +545,13 @@ func (g *gen) writeCTypeName(b *buffer, n *a.TypeExpr, varNamePrefix string, var
|
||||
// TODO: "nptr T", not just "ptr T".
|
||||
if p := innermost.Decorator().Key(); p == t.KeyPtr {
|
||||
if numPointers == maxNumPointers {
|
||||
return fmt.Errorf("cannot convert Puffs type %q to C: too many ptr's", n.String(g.tm))
|
||||
return fmt.Errorf("cannot convert Wuffs type %q to C: too many ptr's", n.String(g.tm))
|
||||
}
|
||||
numPointers++
|
||||
continue
|
||||
}
|
||||
// TODO: fix this.
|
||||
return fmt.Errorf("cannot convert Puffs type %q to C", n.String(g.tm))
|
||||
return fmt.Errorf("cannot convert Wuffs type %q to C", n.String(g.tm))
|
||||
}
|
||||
|
||||
fallback := true
|
||||
@@ -594,10 +594,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: "wuffs_base__buf1",
|
||||
t.KeyReader1: "wuffs_base__reader1",
|
||||
t.KeyWriter1: "wuffs_base__writer1",
|
||||
t.KeyBuf2: "wuffs_base__buf2",
|
||||
}
|
||||
|
||||
var cOpNames = [256]string{
|
||||
|
||||
@@ -176,7 +176,7 @@ func (g *gen) writeFuncImplHeader(b *buffer) error {
|
||||
}
|
||||
b.writes("}")
|
||||
|
||||
b.printf("if (self->private_impl.magic != PUFFS_BASE__MAGIC) {"+
|
||||
b.printf("if (self->private_impl.magic != WUFFS_BASE__MAGIC) {"+
|
||||
"self->private_impl.status = %sERROR_INITIALIZER_NOT_CALLED; }", g.PKGPREFIX)
|
||||
|
||||
b.writes("if (self->private_impl.status < 0) {")
|
||||
@@ -234,7 +234,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_BASE__COROUTINE_SUSPENSION_POINT_0;\n\n")
|
||||
b.writes("switch (coro_susp_point) {\nWUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;\n\n")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -23,10 +23,10 @@ import (
|
||||
t "github.com/google/wuffs/lang/token"
|
||||
)
|
||||
|
||||
// genFilenameLineComments is whether to print "// foo.puffs:123\n" comments in
|
||||
// genFilenameLineComments is whether to print "// foo.wuffs:123\n" comments in
|
||||
// the generated code. This can be useful for debugging, although it is not
|
||||
// enabled by default as it can lead to many spurious changes in the generated
|
||||
// C code (due to line numbers changing) when editing Puffs code.
|
||||
// C code (due to line numbers changing) when editing Wuffs code.
|
||||
const genFilenameLineComments = false
|
||||
|
||||
func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
|
||||
@@ -168,7 +168,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("wuffs_base__slice_u8 %sslice_%s =", iPrefix, name)
|
||||
if err := g.writeExpr(b, v.Value(), replaceCallSuspendibles, parenthesesOptional, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -292,7 +292,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("((wuffs_base__slice_u8){})")
|
||||
} else {
|
||||
b.writeb('0')
|
||||
}
|
||||
@@ -346,7 +346,7 @@ func (g *gen) writeCoroSuspPoint(b *buffer, maybeSuspend bool) error {
|
||||
if maybeSuspend {
|
||||
macro = "_MAYBE_SUSPEND"
|
||||
}
|
||||
b.printf("PUFFS_BASE__COROUTINE_SUSPENSION_POINT%s(%d);\n", macro, g.currFunk.coroSuspPoint)
|
||||
b.printf("WUFFS_BASE__COROUTINE_SUSPENSION_POINT%s(%d);\n", macro, g.currFunk.coroSuspPoint)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -447,7 +447,7 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
|
||||
g.currFunk.tempW++
|
||||
|
||||
if !n.ProvenNotToSuspend() {
|
||||
b.printf("if (PUFFS_BASE__UNLIKELY(%srptr_src == %srend_src)) { goto short_read_src; }",
|
||||
b.printf("if (WUFFS_BASE__UNLIKELY(%srptr_src == %srend_src)) { goto short_read_src; }",
|
||||
bPrefix, bPrefix)
|
||||
g.currFunk.shortReads = append(g.currFunk.shortReads, "src")
|
||||
}
|
||||
@@ -658,7 +658,7 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
|
||||
// TODO: don't hard-code a_dst or v_r or l_rlimit or v_block_size.
|
||||
b.writes("uint64_t l_rlimit0 = v_block_size;\n")
|
||||
b.printf("%sstatus %s%d = %slzw_decoder__decode(&self->private_impl.f_lzw, %sdst,"+
|
||||
"puffs_base__reader1__limit(&%sr, &l_rlimit0));\n",
|
||||
"wuffs_base__reader1__limit(&%sr, &l_rlimit0));\n",
|
||||
g.pkgPrefix, tPrefix, temp,
|
||||
g.pkgPrefix, aPrefix, vPrefix)
|
||||
if err := g.writeLoadExprDerivedVars(b, n); err != nil {
|
||||
@@ -667,14 +667,14 @@ func (g *gen) writeCallSuspendibles(b *buffer, n *a.Expr, depth uint32) error {
|
||||
// TODO: check if tPrefix_temp is an error, and return?
|
||||
|
||||
default:
|
||||
return fmt.Errorf("cannot convert Puffs call %q to C", n.String(g.tm))
|
||||
return fmt.Errorf("cannot convert Wuffs call %q to C", n.String(g.tm))
|
||||
}
|
||||
|
||||
} else {
|
||||
// TODO: fix this.
|
||||
//
|
||||
// This might involve calling g.writeExpr with replaceNothing??
|
||||
return fmt.Errorf("cannot convert Puffs call %q to C", n.String(g.tm))
|
||||
return fmt.Errorf("cannot convert Wuffs call %q to C", n.String(g.tm))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -708,8 +708,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_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("if (WUFFS_BASE__LIKELY(%srend_src - %srptr_src >= %d)) {", bPrefix, bPrefix, size/8)
|
||||
b.printf("%s%d = wuffs_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)
|
||||
@@ -718,7 +718,7 @@ func (g *gen) writeReadUXX(b *buffer, n *a.Expr, name string, size uint32, endia
|
||||
}
|
||||
b.printf("while (true) {")
|
||||
|
||||
b.printf("if (PUFFS_BASE__UNLIKELY(%srptr_%s == %srend_%s)) { goto short_read_%s; }",
|
||||
b.printf("if (WUFFS_BASE__UNLIKELY(%srptr_%s == %srend_%s)) { goto short_read_%s; }",
|
||||
bPrefix, name, bPrefix, name, name)
|
||||
g.currFunk.shortReads = append(g.currFunk.shortReads, name)
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ func (g *gen) writeLoadDerivedVar(b *buffer, name t.ID, typ *a.TypeExpr, header
|
||||
|
||||
b.printf("uint64_t len = %s%s.buf->wi - %s%s.buf->ri;", aPrefix, nameStr, aPrefix, nameStr)
|
||||
|
||||
b.printf("puffs_base__limit1* lim;\n")
|
||||
b.printf("wuffs_base__limit1* lim;\n")
|
||||
b.printf("for (lim = &%s%s.private_impl.limit; lim; lim = lim->next) {\n", aPrefix, nameStr)
|
||||
b.printf("if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {\n")
|
||||
b.printf("len = *lim->ptr_to_len;\n")
|
||||
@@ -137,7 +137,7 @@ func (g *gen) writeLoadDerivedVar(b *buffer, name t.ID, typ *a.TypeExpr, header
|
||||
b.printf("if (!%s%s.buf->closed) {", aPrefix, nameStr)
|
||||
b.printf("uint64_t len = %s%s.buf->len - %s%s.buf->wi;", aPrefix, nameStr, aPrefix, nameStr)
|
||||
|
||||
b.printf("puffs_base__limit1* lim;\n")
|
||||
b.printf("wuffs_base__limit1* lim;\n")
|
||||
b.printf("for (lim = &%s%s.private_impl.limit; lim; lim = lim->next) {\n", aPrefix, nameStr)
|
||||
b.printf("if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {\n")
|
||||
b.printf("len = *lim->ptr_to_len;\n")
|
||||
@@ -175,7 +175,7 @@ func (g *gen) writeSaveDerivedVar(b *buffer, name t.ID, typ *a.TypeExpr, footer
|
||||
bPrefix, nameStr, aPrefix, nameStr, aPrefix, nameStr)
|
||||
b.printf("%s%s.buf->ri += n;", aPrefix, nameStr)
|
||||
|
||||
b.printf("puffs_base__limit1* lim;\n")
|
||||
b.printf("wuffs_base__limit1* lim;\n")
|
||||
b.printf("for (lim = &%s%s.private_impl.limit; lim; lim = lim->next) {\n", aPrefix, nameStr)
|
||||
b.printf("if (lim->ptr_to_len) {\n")
|
||||
b.printf("*lim->ptr_to_len -= n;\n")
|
||||
@@ -183,8 +183,8 @@ func (g *gen) writeSaveDerivedVar(b *buffer, name t.ID, typ *a.TypeExpr, footer
|
||||
b.printf("}\n")
|
||||
|
||||
if footer {
|
||||
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("WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(%srstart_%s);", bPrefix, nameStr)
|
||||
b.printf("WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(%srend_%s);", bPrefix, nameStr)
|
||||
}
|
||||
|
||||
b.printf("}\n")
|
||||
@@ -196,7 +196,7 @@ func (g *gen) writeSaveDerivedVar(b *buffer, name t.ID, typ *a.TypeExpr, footer
|
||||
bPrefix, nameStr, aPrefix, nameStr, aPrefix, nameStr)
|
||||
b.printf("%s%s.buf->wi += n;", aPrefix, nameStr)
|
||||
|
||||
b.printf("puffs_base__limit1* lim;\n")
|
||||
b.printf("wuffs_base__limit1* lim;\n")
|
||||
b.printf("for (lim = &%s%s.private_impl.limit; lim; lim = lim->next) {\n", aPrefix, nameStr)
|
||||
b.printf("if (lim->ptr_to_len) {\n")
|
||||
b.printf("*lim->ptr_to_len -= n;\n")
|
||||
@@ -204,8 +204,8 @@ func (g *gen) writeSaveDerivedVar(b *buffer, name t.ID, typ *a.TypeExpr, footer
|
||||
b.printf("}\n")
|
||||
|
||||
if footer {
|
||||
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("WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(%swstart_%s);", bPrefix, nameStr)
|
||||
b.printf("WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(%swend_%s);", bPrefix, nameStr)
|
||||
}
|
||||
|
||||
b.printf("}\n")
|
||||
@@ -309,7 +309,7 @@ func (g *gen) writeResumeSuspend1(b *buffer, n *a.Var, suspend bool) error {
|
||||
}
|
||||
case t.KeyColon:
|
||||
// TODO: don't assume that the slice is a slice of u8.
|
||||
rhs = "puffs_base__slice_u8"
|
||||
rhs = "wuffs_base__slice_u8"
|
||||
}
|
||||
if rhs != "" {
|
||||
b.printf("%s = ((%s){});\n", local, rhs)
|
||||
|
||||
+1
-1
@@ -142,7 +142,7 @@ func findPuffsMimicCflags(filename string) ([]string, error) {
|
||||
s := bufio.NewScanner(f)
|
||||
for s.Scan() {
|
||||
t := s.Text()
|
||||
const prefix = "// !! puffs mimic cflags:"
|
||||
const prefix = "// !! wuffs mimic cflags:"
|
||||
if strings.HasPrefix(t, prefix) {
|
||||
t = strings.TrimSpace(t[len(prefix):])
|
||||
return strings.Split(t, " "), nil
|
||||
|
||||
+536
-536
@@ -1,10 +1,10 @@
|
||||
#ifndef PUFFS_FLATE_H
|
||||
#define PUFFS_FLATE_H
|
||||
#ifndef WUFFS_FLATE_H
|
||||
#define WUFFS_FLATE_H
|
||||
|
||||
// Code generated by wuffs-c. DO NOT EDIT.
|
||||
|
||||
#ifndef PUFFS_BASE_HEADER_H
|
||||
#define PUFFS_BASE_HEADER_H
|
||||
#ifndef WUFFS_BASE_HEADER_H
|
||||
#define WUFFS_BASE_HEADER_H
|
||||
|
||||
// Copyright 2017 The Wuffs Authors.
|
||||
//
|
||||
@@ -24,7 +24,7 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
// Puffs requires a word size of at least 32 bits because it assumes that
|
||||
// Wuffs requires a word size of at least 32 bits because it assumes that
|
||||
// converting a u32 to usize will never overflow. For example, the size of a
|
||||
// decoded image is often represented, explicitly or implicitly in an image
|
||||
// file, as a u32, and it is convenient to compare that to a buffer size.
|
||||
@@ -32,12 +32,12 @@
|
||||
// Similarly, the word size is at most 64 bits because it assumes that
|
||||
// converting a usize to u64 will never overflow.
|
||||
#if __WORDSIZE < 32
|
||||
#error "Puffs requires a word size of at least 32 bits"
|
||||
#error "Wuffs requires a word size of at least 32 bits"
|
||||
#elif __WORDSIZE > 64
|
||||
#error "Puffs requires a word size of at most 64 bits"
|
||||
#error "Wuffs requires a word size of at most 64 bits"
|
||||
#endif
|
||||
|
||||
// PUFFS_VERSION is the major.minor version number as a uint32. The major
|
||||
// WUFFS_VERSION is the major.minor version number as a uint32. The major
|
||||
// number is the high 16 bits. The minor number is the low 16 bits.
|
||||
//
|
||||
// The intention is to bump the version number at least on every API / ABI
|
||||
@@ -46,17 +46,17 @@
|
||||
// For now, the API and ABI are simply unstable and can change at any time.
|
||||
//
|
||||
// TODO: don't hard code this in base-header.h.
|
||||
#define PUFFS_VERSION (0x00001)
|
||||
#define WUFFS_VERSION (0x00001)
|
||||
|
||||
// puffs_base__slice_u8 is a 1-dimensional buffer (a pointer and length).
|
||||
// wuffs_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;
|
||||
} wuffs_base__slice_u8;
|
||||
|
||||
// puffs_base__buf1 is a 1-dimensional buffer (a pointer and length), plus
|
||||
// wuffs_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,46 +66,46 @@ 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;
|
||||
} wuffs_base__buf1;
|
||||
|
||||
// puffs_base__limit1 provides a limited view of a 1-dimensional byte stream:
|
||||
// wuffs_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 {
|
||||
typedef struct wuffs_base__limit1 {
|
||||
uint64_t* ptr_to_len; // Pointer to N.
|
||||
struct puffs_base__limit1* next; // Linked list of limits.
|
||||
} puffs_base__limit1;
|
||||
struct wuffs_base__limit1* next; // Linked list of limits.
|
||||
} wuffs_base__limit1;
|
||||
|
||||
typedef struct {
|
||||
// TODO: move buf into private_impl? As it is, it looks like users can modify
|
||||
// the buf field to point to a different buffer, which can turn the limit and
|
||||
// mark fields into dangling pointers.
|
||||
puffs_base__buf1* buf;
|
||||
wuffs_base__buf1* buf;
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
// compatibility or safety guarantee if you do so.
|
||||
struct {
|
||||
puffs_base__limit1 limit;
|
||||
wuffs_base__limit1 limit;
|
||||
uint8_t* mark;
|
||||
} private_impl;
|
||||
} puffs_base__reader1;
|
||||
} wuffs_base__reader1;
|
||||
|
||||
typedef struct {
|
||||
// TODO: move buf into private_impl? As it is, it looks like users can modify
|
||||
// the buf field to point to a different buffer, which can turn the limit and
|
||||
// mark fields into dangling pointers.
|
||||
puffs_base__buf1* buf;
|
||||
wuffs_base__buf1* buf;
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
// compatibility or safety guarantee if you do so.
|
||||
struct {
|
||||
puffs_base__limit1 limit;
|
||||
wuffs_base__limit1 limit;
|
||||
uint8_t* mark;
|
||||
} private_impl;
|
||||
} puffs_base__writer1;
|
||||
} wuffs_base__writer1;
|
||||
|
||||
#endif // PUFFS_BASE_HEADER_H
|
||||
#endif // WUFFS_BASE_HEADER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -120,62 +120,62 @@ extern "C" {
|
||||
// - bits 0-7 are a package-namespaced numeric code
|
||||
//
|
||||
// Do not manipulate these bits directly. Use the API functions such as
|
||||
// puffs_flate__status__is_error instead.
|
||||
typedef int32_t puffs_flate__status;
|
||||
// wuffs_flate__status__is_error instead.
|
||||
typedef int32_t wuffs_flate__status;
|
||||
|
||||
#define puffs_flate__packageid 967230 // 0x000ec23e
|
||||
#define wuffs_flate__packageid 967230 // 0x000ec23e
|
||||
|
||||
#define PUFFS_FLATE__STATUS_OK 0 // 0x00000000
|
||||
#define PUFFS_FLATE__ERROR_BAD_PUFFS_VERSION -2147483647 // 0x80000001
|
||||
#define PUFFS_FLATE__ERROR_BAD_RECEIVER -2147483646 // 0x80000002
|
||||
#define PUFFS_FLATE__ERROR_BAD_ARGUMENT -2147483645 // 0x80000003
|
||||
#define PUFFS_FLATE__ERROR_INITIALIZER_NOT_CALLED -2147483644 // 0x80000004
|
||||
#define PUFFS_FLATE__ERROR_INVALID_I_O_OPERATION -2147483643 // 0x80000005
|
||||
#define PUFFS_FLATE__ERROR_CLOSED_FOR_WRITES -2147483642 // 0x80000006
|
||||
#define PUFFS_FLATE__ERROR_UNEXPECTED_EOF -2147483641 // 0x80000007
|
||||
#define PUFFS_FLATE__SUSPENSION_SHORT_READ 8 // 0x00000008
|
||||
#define PUFFS_FLATE__SUSPENSION_SHORT_WRITE 9 // 0x00000009
|
||||
#define WUFFS_FLATE__STATUS_OK 0 // 0x00000000
|
||||
#define WUFFS_FLATE__ERROR_BAD_WUFFS_VERSION -2147483647 // 0x80000001
|
||||
#define WUFFS_FLATE__ERROR_BAD_RECEIVER -2147483646 // 0x80000002
|
||||
#define WUFFS_FLATE__ERROR_BAD_ARGUMENT -2147483645 // 0x80000003
|
||||
#define WUFFS_FLATE__ERROR_INITIALIZER_NOT_CALLED -2147483644 // 0x80000004
|
||||
#define WUFFS_FLATE__ERROR_INVALID_I_O_OPERATION -2147483643 // 0x80000005
|
||||
#define WUFFS_FLATE__ERROR_CLOSED_FOR_WRITES -2147483642 // 0x80000006
|
||||
#define WUFFS_FLATE__ERROR_UNEXPECTED_EOF -2147483641 // 0x80000007
|
||||
#define WUFFS_FLATE__SUSPENSION_SHORT_READ 8 // 0x00000008
|
||||
#define WUFFS_FLATE__SUSPENSION_SHORT_WRITE 9 // 0x00000009
|
||||
|
||||
#define PUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_OVER_SUBSCRIBED \
|
||||
#define WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_OVER_SUBSCRIBED \
|
||||
-1157040128 // 0xbb08f800
|
||||
#define PUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_UNDER_SUBSCRIBED \
|
||||
#define WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_UNDER_SUBSCRIBED \
|
||||
-1157040127 // 0xbb08f801
|
||||
#define PUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_LENGTH_COUNT \
|
||||
#define WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_LENGTH_COUNT \
|
||||
-1157040126 // 0xbb08f802
|
||||
#define PUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_LENGTH_REPETITION \
|
||||
#define WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_LENGTH_REPETITION \
|
||||
-1157040125 // 0xbb08f803
|
||||
#define PUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE -1157040124 // 0xbb08f804
|
||||
#define PUFFS_FLATE__ERROR_BAD_HUFFMAN_MINIMUM_CODE_LENGTH \
|
||||
#define WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE -1157040124 // 0xbb08f804
|
||||
#define WUFFS_FLATE__ERROR_BAD_HUFFMAN_MINIMUM_CODE_LENGTH \
|
||||
-1157040123 // 0xbb08f805
|
||||
#define PUFFS_FLATE__ERROR_BAD_DISTANCE -1157040122 // 0xbb08f806
|
||||
#define PUFFS_FLATE__ERROR_BAD_DISTANCE_CODE_COUNT -1157040121 // 0xbb08f807
|
||||
#define PUFFS_FLATE__ERROR_BAD_FLATE_BLOCK -1157040120 // 0xbb08f808
|
||||
#define PUFFS_FLATE__ERROR_BAD_LITERAL_LENGTH_CODE_COUNT \
|
||||
#define WUFFS_FLATE__ERROR_BAD_DISTANCE -1157040122 // 0xbb08f806
|
||||
#define WUFFS_FLATE__ERROR_BAD_DISTANCE_CODE_COUNT -1157040121 // 0xbb08f807
|
||||
#define WUFFS_FLATE__ERROR_BAD_FLATE_BLOCK -1157040120 // 0xbb08f808
|
||||
#define WUFFS_FLATE__ERROR_BAD_LITERAL_LENGTH_CODE_COUNT \
|
||||
-1157040119 // 0xbb08f809
|
||||
#define PUFFS_FLATE__ERROR_CHECKSUM_MISMATCH -1157040118 // 0xbb08f80a
|
||||
#define PUFFS_FLATE__ERROR_INCONSISTENT_STORED_BLOCK_LENGTH \
|
||||
#define WUFFS_FLATE__ERROR_CHECKSUM_MISMATCH -1157040118 // 0xbb08f80a
|
||||
#define WUFFS_FLATE__ERROR_INCONSISTENT_STORED_BLOCK_LENGTH \
|
||||
-1157040117 // 0xbb08f80b
|
||||
#define PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE \
|
||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE \
|
||||
-1157040116 // 0xbb08f80c
|
||||
#define PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_END_OF_BLOCK \
|
||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_END_OF_BLOCK \
|
||||
-1157040115 // 0xbb08f80d
|
||||
#define PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_DISTANCE \
|
||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_DISTANCE \
|
||||
-1157040114 // 0xbb08f80e
|
||||
#define PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS \
|
||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS \
|
||||
-1157040113 // 0xbb08f80f
|
||||
#define PUFFS_FLATE__ERROR_MISSING_END_OF_BLOCK_CODE -1157040112 // 0xbb08f810
|
||||
#define PUFFS_FLATE__ERROR_NO_HUFFMAN_CODES -1157040111 // 0xbb08f811
|
||||
#define PUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_METHOD \
|
||||
#define WUFFS_FLATE__ERROR_MISSING_END_OF_BLOCK_CODE -1157040112 // 0xbb08f810
|
||||
#define WUFFS_FLATE__ERROR_NO_HUFFMAN_CODES -1157040111 // 0xbb08f811
|
||||
#define WUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_METHOD \
|
||||
-1157040110 // 0xbb08f812
|
||||
#define PUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_WINDOW_SIZE \
|
||||
#define WUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_WINDOW_SIZE \
|
||||
-1157040109 // 0xbb08f813
|
||||
#define PUFFS_FLATE__ERROR_INVALID_ZLIB_PARITY_CHECK -1157040108 // 0xbb08f814
|
||||
#define PUFFS_FLATE__ERROR_TODO_UNSUPPORTED_ZLIB_PRESET_DICTIONARY \
|
||||
#define WUFFS_FLATE__ERROR_INVALID_ZLIB_PARITY_CHECK -1157040108 // 0xbb08f814
|
||||
#define WUFFS_FLATE__ERROR_TODO_UNSUPPORTED_ZLIB_PRESET_DICTIONARY \
|
||||
-1157040107 // 0xbb08f815
|
||||
|
||||
bool puffs_flate__status__is_error(puffs_flate__status s);
|
||||
bool wuffs_flate__status__is_error(wuffs_flate__status s);
|
||||
|
||||
const char* puffs_flate__status__string(puffs_flate__status s);
|
||||
const char* wuffs_flate__status__string(wuffs_flate__status s);
|
||||
|
||||
// ---------------- Public Consts
|
||||
|
||||
@@ -184,13 +184,13 @@ const char* puffs_flate__status__string(puffs_flate__status s);
|
||||
typedef struct {
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
// compatibility or safety guarantee if you do so. Instead, use the
|
||||
// puffs_flate__flate_decoder__etc functions.
|
||||
// wuffs_flate__flate_decoder__etc functions.
|
||||
//
|
||||
// In C++, these fields would be "private", but C does not support that.
|
||||
//
|
||||
// It is a struct, not a struct*, so that it can be stack allocated.
|
||||
struct {
|
||||
puffs_flate__status status;
|
||||
wuffs_flate__status status;
|
||||
uint32_t magic;
|
||||
|
||||
uint32_t f_bits;
|
||||
@@ -204,7 +204,7 @@ typedef struct {
|
||||
|
||||
struct {
|
||||
uint32_t coro_susp_point;
|
||||
puffs_flate__status v_z;
|
||||
wuffs_flate__status v_z;
|
||||
uint64_t v_n_copied;
|
||||
uint32_t v_already_full;
|
||||
} c_decode[1];
|
||||
@@ -255,92 +255,92 @@ typedef struct {
|
||||
uint32_t v_hdist;
|
||||
} c_decode_huffman_slow[1];
|
||||
} private_impl;
|
||||
} puffs_flate__flate_decoder;
|
||||
} wuffs_flate__flate_decoder;
|
||||
|
||||
typedef struct {
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
// compatibility or safety guarantee if you do so. Instead, use the
|
||||
// puffs_flate__adler32__etc functions.
|
||||
// wuffs_flate__adler32__etc functions.
|
||||
//
|
||||
// In C++, these fields would be "private", but C does not support that.
|
||||
//
|
||||
// It is a struct, not a struct*, so that it can be stack allocated.
|
||||
struct {
|
||||
puffs_flate__status status;
|
||||
wuffs_flate__status status;
|
||||
uint32_t magic;
|
||||
|
||||
uint32_t f_state;
|
||||
|
||||
} private_impl;
|
||||
} puffs_flate__adler32;
|
||||
} wuffs_flate__adler32;
|
||||
|
||||
typedef struct {
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
// compatibility or safety guarantee if you do so. Instead, use the
|
||||
// puffs_flate__zlib_decoder__etc functions.
|
||||
// wuffs_flate__zlib_decoder__etc functions.
|
||||
//
|
||||
// In C++, these fields would be "private", but C does not support that.
|
||||
//
|
||||
// It is a struct, not a struct*, so that it can be stack allocated.
|
||||
struct {
|
||||
puffs_flate__status status;
|
||||
wuffs_flate__status status;
|
||||
uint32_t magic;
|
||||
|
||||
puffs_flate__flate_decoder f_flate;
|
||||
puffs_flate__adler32 f_adler;
|
||||
wuffs_flate__flate_decoder f_flate;
|
||||
wuffs_flate__adler32 f_adler;
|
||||
|
||||
struct {
|
||||
uint32_t coro_susp_point;
|
||||
uint16_t v_x;
|
||||
uint32_t v_checksum;
|
||||
puffs_flate__status v_z;
|
||||
wuffs_flate__status v_z;
|
||||
uint64_t scratch;
|
||||
} c_decode[1];
|
||||
} private_impl;
|
||||
} puffs_flate__zlib_decoder;
|
||||
} wuffs_flate__zlib_decoder;
|
||||
|
||||
// ---------------- Public Initializer Prototypes
|
||||
|
||||
// puffs_flate__flate_decoder__initialize is an initializer function.
|
||||
// wuffs_flate__flate_decoder__initialize is an initializer function.
|
||||
//
|
||||
// It should be called before any other puffs_flate__flate_decoder__* function.
|
||||
// It should be called before any other wuffs_flate__flate_decoder__* function.
|
||||
//
|
||||
// Pass PUFFS_VERSION and 0 for puffs_version and for_internal_use_only.
|
||||
void puffs_flate__flate_decoder__initialize(puffs_flate__flate_decoder* self,
|
||||
uint32_t puffs_version,
|
||||
// Pass WUFFS_VERSION and 0 for wuffs_version and for_internal_use_only.
|
||||
void wuffs_flate__flate_decoder__initialize(wuffs_flate__flate_decoder* self,
|
||||
uint32_t wuffs_version,
|
||||
uint32_t for_internal_use_only);
|
||||
|
||||
// puffs_flate__zlib_decoder__initialize is an initializer function.
|
||||
// wuffs_flate__zlib_decoder__initialize is an initializer function.
|
||||
//
|
||||
// It should be called before any other puffs_flate__zlib_decoder__* function.
|
||||
// It should be called before any other wuffs_flate__zlib_decoder__* function.
|
||||
//
|
||||
// Pass PUFFS_VERSION and 0 for puffs_version and for_internal_use_only.
|
||||
void puffs_flate__zlib_decoder__initialize(puffs_flate__zlib_decoder* self,
|
||||
uint32_t puffs_version,
|
||||
// Pass WUFFS_VERSION and 0 for wuffs_version and for_internal_use_only.
|
||||
void wuffs_flate__zlib_decoder__initialize(wuffs_flate__zlib_decoder* self,
|
||||
uint32_t wuffs_version,
|
||||
uint32_t for_internal_use_only);
|
||||
|
||||
// ---------------- Public Function Prototypes
|
||||
|
||||
puffs_flate__status puffs_flate__flate_decoder__decode(
|
||||
puffs_flate__flate_decoder* self,
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src);
|
||||
wuffs_flate__status wuffs_flate__flate_decoder__decode(
|
||||
wuffs_flate__flate_decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_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);
|
||||
wuffs_flate__status wuffs_flate__zlib_decoder__decode(
|
||||
wuffs_flate__zlib_decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // PUFFS_FLATE_H
|
||||
#endif // WUFFS_FLATE_H
|
||||
|
||||
// C HEADER ENDS HERE.
|
||||
|
||||
#ifndef PUFFS_BASE_IMPL_H
|
||||
#define PUFFS_BASE_IMPL_H
|
||||
#ifndef WUFFS_BASE_IMPL_H
|
||||
#define WUFFS_BASE_IMPL_H
|
||||
|
||||
// Copyright 2017 The Wuffs Authors.
|
||||
//
|
||||
@@ -356,39 +356,39 @@ puffs_flate__status puffs_flate__zlib_decoder__decode(
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// puffs_base__empty_struct is used when a Puffs function returns an empty
|
||||
// wuffs_base__empty_struct is used when a Wuffs function returns an empty
|
||||
// struct. In C, if a function f returns void, you can't say "x = f()", but in
|
||||
// Puffs, if a function g returns empty, you can say "y = g()".
|
||||
// Wuffs, if a function g returns empty, you can say "y = g()".
|
||||
typedef struct {
|
||||
} puffs_base__empty_struct;
|
||||
} wuffs_base__empty_struct;
|
||||
|
||||
#define PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(x) (void)(x)
|
||||
#define WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(x) (void)(x)
|
||||
|
||||
// PUFFS_BASE__MAGIC is a magic number to check that initializers are called.
|
||||
// WUFFS_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_BASE__MAGIC (0xCB3699CCU)
|
||||
#define WUFFS_BASE__MAGIC (0xCB3699CCU)
|
||||
|
||||
// PUFFS_BASE__ALREADY_ZEROED is passed from a container struct's initializer
|
||||
// WUFFS_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_BASE__ALREADY_ZEROED (0x68602EF1U)
|
||||
#define WUFFS_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 trivial macros instead of an explicit assignment and case statement
|
||||
// so that clang-format doesn't get confused by the unusual "case"s.
|
||||
#define PUFFS_BASE__COROUTINE_SUSPENSION_POINT_0 case 0:;
|
||||
#define PUFFS_BASE__COROUTINE_SUSPENSION_POINT(n) \
|
||||
#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0 case 0:;
|
||||
#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT(n) \
|
||||
coro_susp_point = n; \
|
||||
case n:;
|
||||
|
||||
#define PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \
|
||||
#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \
|
||||
if (status < 0) { \
|
||||
goto exit; \
|
||||
} else if (status == 0) { \
|
||||
@@ -400,11 +400,11 @@ typedef struct {
|
||||
|
||||
// Clang also defines "__GNUC__".
|
||||
#if defined(__GNUC__)
|
||||
#define PUFFS_BASE__LIKELY(expr) (__builtin_expect(!!(expr), 1))
|
||||
#define PUFFS_BASE__UNLIKELY(expr) (__builtin_expect(!!(expr), 0))
|
||||
#define WUFFS_BASE__LIKELY(expr) (__builtin_expect(!!(expr), 1))
|
||||
#define WUFFS_BASE__UNLIKELY(expr) (__builtin_expect(!!(expr), 0))
|
||||
#else
|
||||
#define PUFFS_BASE__LIKELY(expr) (expr)
|
||||
#define PUFFS_BASE__UNLIKELY(expr) (expr)
|
||||
#define WUFFS_BASE__LIKELY(expr) (expr)
|
||||
#define WUFFS_BASE__UNLIKELY(expr) (expr)
|
||||
#endif
|
||||
|
||||
// Uncomment this #include for printf-debugging.
|
||||
@@ -421,68 +421,68 @@ typedef struct {
|
||||
// "gif.c", without having to additionally include or otherwise build and link
|
||||
// a "base.c" file.
|
||||
//
|
||||
// They are static, so that linking multiple puffs .o files won't complain about
|
||||
// They are static, so that linking multiple wuffs .o files won't complain about
|
||||
// duplicate function definitions.
|
||||
//
|
||||
// They are explicitly marked inline, even if modern compilers don't use the
|
||||
// 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 wuffs_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 wuffs_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 wuffs_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 wuffs_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 wuffs_base__slice_u8 wuffs_base__slice_u8__subslice_i(
|
||||
wuffs_base__slice_u8 s,
|
||||
uint64_t i) {
|
||||
if ((i <= SIZE_MAX) && (i <= s.len)) {
|
||||
return ((puffs_base__slice_u8){
|
||||
return ((wuffs_base__slice_u8){
|
||||
.ptr = s.ptr + i,
|
||||
.len = s.len - i,
|
||||
});
|
||||
}
|
||||
return ((puffs_base__slice_u8){});
|
||||
return ((wuffs_base__slice_u8){});
|
||||
}
|
||||
|
||||
static inline puffs_base__slice_u8 puffs_base__slice_u8__subslice_j(
|
||||
puffs_base__slice_u8 s,
|
||||
static inline wuffs_base__slice_u8 wuffs_base__slice_u8__subslice_j(
|
||||
wuffs_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 ((wuffs_base__slice_u8){.ptr = s.ptr, .len = j});
|
||||
}
|
||||
return ((puffs_base__slice_u8){});
|
||||
return ((wuffs_base__slice_u8){});
|
||||
}
|
||||
|
||||
static inline puffs_base__slice_u8 puffs_base__slice_u8__subslice_ij(
|
||||
puffs_base__slice_u8 s,
|
||||
static inline wuffs_base__slice_u8 wuffs_base__slice_u8__subslice_ij(
|
||||
wuffs_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 ((wuffs_base__slice_u8){
|
||||
.ptr = s.ptr + i,
|
||||
.len = j - i,
|
||||
});
|
||||
}
|
||||
return ((puffs_base__slice_u8){});
|
||||
return ((wuffs_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,
|
||||
// wuffs_base__slice_u8__prefix returns up to the first up_to bytes of s.
|
||||
static inline wuffs_base__slice_u8 wuffs_base__slice_u8__prefix(
|
||||
wuffs_base__slice_u8 s,
|
||||
uint64_t up_to) {
|
||||
if ((uint64_t)(s.len) > up_to) {
|
||||
s.len = up_to;
|
||||
@@ -490,9 +490,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,
|
||||
// wuffs_base__slice_u8__suffix returns up to the last up_to bytes of s.
|
||||
static inline wuffs_base__slice_u8 wuffs_base__slice_u8_suffix(
|
||||
wuffs_base__slice_u8 s,
|
||||
uint64_t up_to) {
|
||||
if ((uint64_t)(s.len) > up_to) {
|
||||
s.ptr += (uint64_t)(s.len) - up_to;
|
||||
@@ -501,14 +501,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,
|
||||
// wuffs_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 wuffs_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 wuffs_base__slice_u8__copy_from_slice(
|
||||
wuffs_base__slice_u8 dst,
|
||||
wuffs_base__slice_u8 src) {
|
||||
size_t length = dst.len < src.len ? dst.len : src.len;
|
||||
if (length > 0) {
|
||||
memmove(dst.ptr, src.ptr, length);
|
||||
@@ -516,7 +516,7 @@ static inline uint64_t puffs_base__slice_u8__copy_from_slice(
|
||||
return length;
|
||||
}
|
||||
|
||||
static inline uint32_t puffs_base__writer1__copy_from_history32(
|
||||
static inline uint32_t wuffs_base__writer1__copy_from_history32(
|
||||
uint8_t** ptr_ptr,
|
||||
uint8_t* start, // May be NULL, meaning an unmarked writer1.
|
||||
uint8_t* end,
|
||||
@@ -539,10 +539,10 @@ static inline uint32_t puffs_base__writer1__copy_from_history32(
|
||||
// TODO: unrolling by 3 seems best for the std/flate benchmarks, but that is
|
||||
// mostly because 3 is the minimum length for the flate format. This function
|
||||
// implementation shouldn't overfit to that one format. Perhaps the
|
||||
// copy_from_history32 Puffs method should also take an unroll hint argument,
|
||||
// copy_from_history32 Wuffs method should also take an unroll hint argument,
|
||||
// and the cgen can look if that argument is the constant expression '3'.
|
||||
//
|
||||
// See also puffs_base__writer1__copy_from_history32__bco below.
|
||||
// See also wuffs_base__writer1__copy_from_history32__bco below.
|
||||
//
|
||||
// Alternatively, or additionally, have a sloppy_copy_from_history32 method
|
||||
// that copies 8 bytes at a time, possibly writing more than length bytes?
|
||||
@@ -558,14 +558,14 @@ static inline uint32_t puffs_base__writer1__copy_from_history32(
|
||||
return length;
|
||||
}
|
||||
|
||||
// puffs_base__writer1__copy_from_history32__bco is a Bounds Check Optimized
|
||||
// version of the puffs_base__writer1__copy_from_history32 function above. The
|
||||
// wuffs_base__writer1__copy_from_history32__bco is a Bounds Check Optimized
|
||||
// version of the wuffs_base__writer1__copy_from_history32 function above. The
|
||||
// caller needs to prove that:
|
||||
// - start != NULL
|
||||
// - distance != 0
|
||||
// - distance <= (*ptr_ptr - start)
|
||||
// - length <= (end - *ptr_ptr)
|
||||
static inline uint32_t puffs_base__writer1__copy_from_history32__bco(
|
||||
static inline uint32_t wuffs_base__writer1__copy_from_history32__bco(
|
||||
uint8_t** ptr_ptr,
|
||||
uint8_t* start,
|
||||
uint8_t* end,
|
||||
@@ -586,7 +586,7 @@ static inline uint32_t puffs_base__writer1__copy_from_history32__bco(
|
||||
return length;
|
||||
}
|
||||
|
||||
static inline uint32_t puffs_base__writer1__copy_from_reader32(
|
||||
static inline uint32_t wuffs_base__writer1__copy_from_reader32(
|
||||
uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
uint8_t** ptr_rptr,
|
||||
@@ -609,10 +609,10 @@ static inline uint32_t puffs_base__writer1__copy_from_reader32(
|
||||
return n;
|
||||
}
|
||||
|
||||
static inline uint64_t puffs_base__writer1__copy_from_slice(
|
||||
static inline uint64_t wuffs_base__writer1__copy_from_slice(
|
||||
uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
puffs_base__slice_u8 src) {
|
||||
wuffs_base__slice_u8 src) {
|
||||
uint8_t* wptr = *ptr_wptr;
|
||||
size_t n = src.len;
|
||||
if (n > wend - wptr) {
|
||||
@@ -625,10 +625,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 wuffs_base__writer1__copy_from_slice32(
|
||||
uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
puffs_base__slice_u8 src,
|
||||
wuffs_base__slice_u8 src,
|
||||
uint32_t length) {
|
||||
uint8_t* wptr = *ptr_wptr;
|
||||
size_t n = src.len;
|
||||
@@ -647,52 +647,52 @@ static inline uint32_t puffs_base__writer1__copy_from_slice32(
|
||||
|
||||
// Note that the *__limit and *__mark methods are private (in base-impl.h) not
|
||||
// public (in base-header.h). We assume that, at the boundary between user code
|
||||
// and Puffs code, the reader1 and writer1's private_impl fields (including
|
||||
// and Wuffs code, the reader1 and writer1's private_impl fields (including
|
||||
// limit and mark) are NULL. Otherwise, some internal assumptions break down.
|
||||
// For example, limits could be represented as pointers, even though
|
||||
// conceptually they are counts, but that pointer-to-count correspondence
|
||||
// becomes invalid if a buffer is re-used (e.g. on resuming a coroutine).
|
||||
//
|
||||
// Admittedly, some of the Puffs test code calls these methods, but that test
|
||||
// code is still Puffs code, not user code. Other Puffs test code modifies
|
||||
// Admittedly, some of the Wuffs test code calls these methods, but that test
|
||||
// code is still Wuffs code, not user code. Other Wuffs test code modifies
|
||||
// private_impl fields directly.
|
||||
|
||||
static inline puffs_base__reader1 puffs_base__reader1__limit(
|
||||
puffs_base__reader1* o,
|
||||
static inline wuffs_base__reader1 wuffs_base__reader1__limit(
|
||||
wuffs_base__reader1* o,
|
||||
uint64_t* ptr_to_len) {
|
||||
puffs_base__reader1 ret = *o;
|
||||
wuffs_base__reader1 ret = *o;
|
||||
ret.private_impl.limit.ptr_to_len = ptr_to_len;
|
||||
ret.private_impl.limit.next = &o->private_impl.limit;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline puffs_base__empty_struct puffs_base__reader1__mark(
|
||||
puffs_base__reader1* o,
|
||||
static inline wuffs_base__empty_struct wuffs_base__reader1__mark(
|
||||
wuffs_base__reader1* o,
|
||||
uint8_t* mark) {
|
||||
o->private_impl.mark = mark;
|
||||
return ((puffs_base__empty_struct){});
|
||||
return ((wuffs_base__empty_struct){});
|
||||
}
|
||||
|
||||
// TODO: static inline puffs_base__writer1 puffs_base__writer1__limit()
|
||||
// TODO: static inline wuffs_base__writer1 wuffs_base__writer1__limit()
|
||||
|
||||
static inline puffs_base__empty_struct puffs_base__writer1__mark(
|
||||
puffs_base__writer1* o,
|
||||
static inline wuffs_base__empty_struct wuffs_base__writer1__mark(
|
||||
wuffs_base__writer1* o,
|
||||
uint8_t* mark) {
|
||||
o->private_impl.mark = mark;
|
||||
return ((puffs_base__empty_struct){});
|
||||
return ((wuffs_base__empty_struct){});
|
||||
}
|
||||
|
||||
#endif // PUFFS_BASE_IMPL_H
|
||||
#endif // WUFFS_BASE_IMPL_H
|
||||
|
||||
// ---------------- Status Codes Implementations
|
||||
|
||||
bool puffs_flate__status__is_error(puffs_flate__status s) {
|
||||
bool wuffs_flate__status__is_error(wuffs_flate__status s) {
|
||||
return s < 0;
|
||||
}
|
||||
|
||||
const char* puffs_flate__status__strings0[10] = {
|
||||
const char* wuffs_flate__status__strings0[10] = {
|
||||
"flate: ok",
|
||||
"flate: bad puffs version",
|
||||
"flate: bad wuffs version",
|
||||
"flate: bad receiver",
|
||||
"flate: bad argument",
|
||||
"flate: initializer not called",
|
||||
@@ -703,7 +703,7 @@ const char* puffs_flate__status__strings0[10] = {
|
||||
"flate: short write",
|
||||
};
|
||||
|
||||
const char* puffs_flate__status__strings1[22] = {
|
||||
const char* wuffs_flate__status__strings1[22] = {
|
||||
"flate: bad Huffman code (over-subscribed)",
|
||||
"flate: bad Huffman code (under-subscribed)",
|
||||
"flate: bad Huffman code length count",
|
||||
@@ -728,16 +728,16 @@ const char* puffs_flate__status__strings1[22] = {
|
||||
"flate: TODO: unsupported zlib preset dictionary",
|
||||
};
|
||||
|
||||
const char* puffs_flate__status__string(puffs_flate__status s) {
|
||||
const char* wuffs_flate__status__string(wuffs_flate__status s) {
|
||||
const char** a = NULL;
|
||||
uint32_t n = 0;
|
||||
switch ((s >> 10) & 0x1fffff) {
|
||||
case 0:
|
||||
a = puffs_flate__status__strings0;
|
||||
a = wuffs_flate__status__strings0;
|
||||
n = 10;
|
||||
break;
|
||||
case puffs_flate__packageid:
|
||||
a = puffs_flate__status__strings1;
|
||||
case wuffs_flate__packageid:
|
||||
a = wuffs_flate__status__strings1;
|
||||
n = 22;
|
||||
break;
|
||||
}
|
||||
@@ -747,11 +747,11 @@ const char* puffs_flate__status__string(puffs_flate__status s) {
|
||||
|
||||
// ---------------- Private Consts
|
||||
|
||||
static const uint8_t puffs_flate__code_order[19] = {
|
||||
static const uint8_t wuffs_flate__code_order[19] = {
|
||||
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15,
|
||||
};
|
||||
|
||||
static const uint8_t puffs_flate__reverse8[256] = {
|
||||
static const uint8_t wuffs_flate__reverse8[256] = {
|
||||
0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240,
|
||||
8, 136, 72, 200, 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248,
|
||||
4, 132, 68, 196, 36, 164, 100, 228, 20, 148, 84, 212, 52, 180, 116, 244,
|
||||
@@ -770,7 +770,7 @@ static const uint8_t puffs_flate__reverse8[256] = {
|
||||
15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255,
|
||||
};
|
||||
|
||||
static const uint32_t puffs_flate__lcode_magic_numbers[32] = {
|
||||
static const uint32_t wuffs_flate__lcode_magic_numbers[32] = {
|
||||
1073742592, 1073742848, 1073743104, 1073743360, 1073743616, 1073743872,
|
||||
1073744128, 1073744384, 1073744656, 1073745168, 1073745680, 1073746192,
|
||||
1073746720, 1073747744, 1073748768, 1073749792, 1073750832, 1073752880,
|
||||
@@ -779,7 +779,7 @@ static const uint32_t puffs_flate__lcode_magic_numbers[32] = {
|
||||
134217728, 134217728,
|
||||
};
|
||||
|
||||
static const uint32_t puffs_flate__dcode_magic_numbers[32] = {
|
||||
static const uint32_t wuffs_flate__dcode_magic_numbers[32] = {
|
||||
1073742080, 1073742336, 1073742592, 1073742848, 1073743120, 1073743632,
|
||||
1073744160, 1073745184, 1073746224, 1073748272, 1073750336, 1073754432,
|
||||
1073758544, 1073766736, 1073774944, 1073791328, 1073807728, 1073840496,
|
||||
@@ -790,123 +790,123 @@ static const uint32_t puffs_flate__dcode_magic_numbers[32] = {
|
||||
|
||||
// ---------------- Private Initializer Prototypes
|
||||
|
||||
void puffs_flate__adler32__initialize(puffs_flate__adler32* self,
|
||||
uint32_t puffs_version,
|
||||
void wuffs_flate__adler32__initialize(wuffs_flate__adler32* self,
|
||||
uint32_t wuffs_version,
|
||||
uint32_t for_internal_use_only);
|
||||
|
||||
// ---------------- Private Function Prototypes
|
||||
|
||||
static puffs_flate__status puffs_flate__flate_decoder__decode_blocks(
|
||||
puffs_flate__flate_decoder* self,
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src);
|
||||
static wuffs_flate__status wuffs_flate__flate_decoder__decode_blocks(
|
||||
wuffs_flate__flate_decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src);
|
||||
|
||||
static puffs_flate__status puffs_flate__flate_decoder__decode_uncompressed(
|
||||
puffs_flate__flate_decoder* self,
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src);
|
||||
static wuffs_flate__status wuffs_flate__flate_decoder__decode_uncompressed(
|
||||
wuffs_flate__flate_decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src);
|
||||
|
||||
static puffs_flate__status puffs_flate__flate_decoder__init_fixed_huffman(
|
||||
puffs_flate__flate_decoder* self);
|
||||
static wuffs_flate__status wuffs_flate__flate_decoder__init_fixed_huffman(
|
||||
wuffs_flate__flate_decoder* self);
|
||||
|
||||
static puffs_flate__status puffs_flate__flate_decoder__init_dynamic_huffman(
|
||||
puffs_flate__flate_decoder* self,
|
||||
puffs_base__reader1 a_src);
|
||||
static wuffs_flate__status wuffs_flate__flate_decoder__init_dynamic_huffman(
|
||||
wuffs_flate__flate_decoder* self,
|
||||
wuffs_base__reader1 a_src);
|
||||
|
||||
static puffs_flate__status puffs_flate__flate_decoder__init_huff(
|
||||
puffs_flate__flate_decoder* self,
|
||||
static wuffs_flate__status wuffs_flate__flate_decoder__init_huff(
|
||||
wuffs_flate__flate_decoder* self,
|
||||
uint32_t a_which,
|
||||
uint32_t a_n_codes0,
|
||||
uint32_t a_n_codes1,
|
||||
uint32_t a_base_symbol);
|
||||
|
||||
static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_fast(
|
||||
puffs_flate__flate_decoder* self,
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src);
|
||||
static wuffs_flate__status wuffs_flate__flate_decoder__decode_huffman_fast(
|
||||
wuffs_flate__flate_decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src);
|
||||
|
||||
static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_slow(
|
||||
puffs_flate__flate_decoder* self,
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src);
|
||||
static wuffs_flate__status wuffs_flate__flate_decoder__decode_huffman_slow(
|
||||
wuffs_flate__flate_decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src);
|
||||
|
||||
static uint32_t puffs_flate__adler32__update(puffs_flate__adler32* self,
|
||||
puffs_base__slice_u8 a_x);
|
||||
static uint32_t wuffs_flate__adler32__update(wuffs_flate__adler32* self,
|
||||
wuffs_base__slice_u8 a_x);
|
||||
|
||||
// ---------------- Initializer Implementations
|
||||
|
||||
void puffs_flate__flate_decoder__initialize(puffs_flate__flate_decoder* self,
|
||||
uint32_t puffs_version,
|
||||
void wuffs_flate__flate_decoder__initialize(wuffs_flate__flate_decoder* self,
|
||||
uint32_t wuffs_version,
|
||||
uint32_t for_internal_use_only) {
|
||||
if (!self) {
|
||||
return;
|
||||
}
|
||||
if (puffs_version != PUFFS_VERSION) {
|
||||
self->private_impl.status = PUFFS_FLATE__ERROR_BAD_PUFFS_VERSION;
|
||||
if (wuffs_version != WUFFS_VERSION) {
|
||||
self->private_impl.status = WUFFS_FLATE__ERROR_BAD_WUFFS_VERSION;
|
||||
return;
|
||||
}
|
||||
if (for_internal_use_only != PUFFS_BASE__ALREADY_ZEROED) {
|
||||
if (for_internal_use_only != WUFFS_BASE__ALREADY_ZEROED) {
|
||||
memset(self, 0, sizeof(*self));
|
||||
}
|
||||
self->private_impl.magic = PUFFS_BASE__MAGIC;
|
||||
self->private_impl.magic = WUFFS_BASE__MAGIC;
|
||||
}
|
||||
|
||||
void puffs_flate__adler32__initialize(puffs_flate__adler32* self,
|
||||
uint32_t puffs_version,
|
||||
void wuffs_flate__adler32__initialize(wuffs_flate__adler32* self,
|
||||
uint32_t wuffs_version,
|
||||
uint32_t for_internal_use_only) {
|
||||
if (!self) {
|
||||
return;
|
||||
}
|
||||
if (puffs_version != PUFFS_VERSION) {
|
||||
self->private_impl.status = PUFFS_FLATE__ERROR_BAD_PUFFS_VERSION;
|
||||
if (wuffs_version != WUFFS_VERSION) {
|
||||
self->private_impl.status = WUFFS_FLATE__ERROR_BAD_WUFFS_VERSION;
|
||||
return;
|
||||
}
|
||||
if (for_internal_use_only != PUFFS_BASE__ALREADY_ZEROED) {
|
||||
if (for_internal_use_only != WUFFS_BASE__ALREADY_ZEROED) {
|
||||
memset(self, 0, sizeof(*self));
|
||||
}
|
||||
self->private_impl.magic = PUFFS_BASE__MAGIC;
|
||||
self->private_impl.magic = WUFFS_BASE__MAGIC;
|
||||
self->private_impl.f_state = 1;
|
||||
}
|
||||
|
||||
void puffs_flate__zlib_decoder__initialize(puffs_flate__zlib_decoder* self,
|
||||
uint32_t puffs_version,
|
||||
void wuffs_flate__zlib_decoder__initialize(wuffs_flate__zlib_decoder* self,
|
||||
uint32_t wuffs_version,
|
||||
uint32_t for_internal_use_only) {
|
||||
if (!self) {
|
||||
return;
|
||||
}
|
||||
if (puffs_version != PUFFS_VERSION) {
|
||||
self->private_impl.status = PUFFS_FLATE__ERROR_BAD_PUFFS_VERSION;
|
||||
if (wuffs_version != WUFFS_VERSION) {
|
||||
self->private_impl.status = WUFFS_FLATE__ERROR_BAD_WUFFS_VERSION;
|
||||
return;
|
||||
}
|
||||
if (for_internal_use_only != PUFFS_BASE__ALREADY_ZEROED) {
|
||||
if (for_internal_use_only != WUFFS_BASE__ALREADY_ZEROED) {
|
||||
memset(self, 0, sizeof(*self));
|
||||
}
|
||||
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_BASE__ALREADY_ZEROED);
|
||||
self->private_impl.magic = WUFFS_BASE__MAGIC;
|
||||
wuffs_flate__flate_decoder__initialize(
|
||||
&self->private_impl.f_flate, WUFFS_VERSION, WUFFS_BASE__ALREADY_ZEROED);
|
||||
wuffs_flate__adler32__initialize(&self->private_impl.f_adler, WUFFS_VERSION,
|
||||
WUFFS_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) {
|
||||
wuffs_flate__status wuffs_flate__flate_decoder__decode(
|
||||
wuffs_flate__flate_decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src) {
|
||||
if (!self) {
|
||||
return PUFFS_FLATE__ERROR_BAD_RECEIVER;
|
||||
return WUFFS_FLATE__ERROR_BAD_RECEIVER;
|
||||
}
|
||||
if (self->private_impl.magic != PUFFS_BASE__MAGIC) {
|
||||
self->private_impl.status = PUFFS_FLATE__ERROR_INITIALIZER_NOT_CALLED;
|
||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
self->private_impl.status = WUFFS_FLATE__ERROR_INITIALIZER_NOT_CALLED;
|
||||
}
|
||||
if (self->private_impl.status < 0) {
|
||||
return self->private_impl.status;
|
||||
}
|
||||
puffs_flate__status status = PUFFS_FLATE__STATUS_OK;
|
||||
wuffs_flate__status status = WUFFS_FLATE__STATUS_OK;
|
||||
|
||||
puffs_flate__status v_z;
|
||||
puffs_base__slice_u8 v_written;
|
||||
wuffs_flate__status v_z;
|
||||
wuffs_base__slice_u8 v_written;
|
||||
uint64_t v_n_copied;
|
||||
uint32_t v_already_full;
|
||||
|
||||
@@ -919,7 +919,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode(
|
||||
b_wend_dst = b_wptr_dst;
|
||||
if (!a_dst.buf->closed) {
|
||||
uint64_t len = a_dst.buf->len - a_dst.buf->wi;
|
||||
puffs_base__limit1* lim;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_dst.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -932,29 +932,29 @@ 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 = ((wuffs_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_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
while (true) {
|
||||
puffs_base__writer1__mark(&a_dst, b_wptr_dst);
|
||||
wuffs_base__writer1__mark(&a_dst, b_wptr_dst);
|
||||
{
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
WUFFS_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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_dst.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
}
|
||||
puffs_flate__status t_0 =
|
||||
puffs_flate__flate_decoder__decode_blocks(self, a_dst, a_src);
|
||||
wuffs_flate__status t_0 =
|
||||
wuffs_flate__flate_decoder__decode_blocks(self, a_dst, a_src);
|
||||
if (a_dst.buf) {
|
||||
b_wptr_dst = a_dst.buf->ptr + a_dst.buf->wi;
|
||||
}
|
||||
@@ -962,32 +962,32 @@ puffs_flate__status puffs_flate__flate_decoder__decode(
|
||||
}
|
||||
if (!(v_z > 0)) {
|
||||
status = v_z;
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(2);
|
||||
}
|
||||
v_written = ((puffs_base__slice_u8){
|
||||
v_written = ((wuffs_base__slice_u8){
|
||||
.ptr = a_dst.private_impl.mark,
|
||||
.len = a_dst.private_impl.mark
|
||||
? (size_t)(b_wptr_dst - a_dst.private_impl.mark)
|
||||
: 0,
|
||||
});
|
||||
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,
|
||||
v_written = wuffs_base__slice_u8_suffix(v_written, 32768);
|
||||
wuffs_base__slice_u8__copy_from_slice(
|
||||
((wuffs_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,
|
||||
v_n_copied = wuffs_base__slice_u8__copy_from_slice(
|
||||
wuffs_base__slice_u8__subslice_i(
|
||||
((wuffs_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,
|
||||
v_written = wuffs_base__slice_u8__subslice_i(v_written, v_n_copied);
|
||||
v_n_copied = wuffs_base__slice_u8__copy_from_slice(
|
||||
((wuffs_base__slice_u8){.ptr = self->private_impl.f_history,
|
||||
.len = 32768}),
|
||||
v_written);
|
||||
self->private_impl.f_history_index =
|
||||
@@ -1003,7 +1003,7 @@ puffs_flate__status puffs_flate__flate_decoder__decode(
|
||||
}
|
||||
}
|
||||
status = v_z;
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
}
|
||||
|
||||
goto ok;
|
||||
@@ -1023,25 +1023,25 @@ 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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_dst.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wstart_dst);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wend_dst);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wstart_dst);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wend_dst);
|
||||
}
|
||||
|
||||
self->private_impl.status = status;
|
||||
return status;
|
||||
}
|
||||
|
||||
static 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_flate__status status = PUFFS_FLATE__STATUS_OK;
|
||||
static wuffs_flate__status wuffs_flate__flate_decoder__decode_blocks(
|
||||
wuffs_flate__flate_decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src) {
|
||||
wuffs_flate__status status = WUFFS_FLATE__STATUS_OK;
|
||||
|
||||
uint32_t v_final;
|
||||
uint32_t v_type;
|
||||
@@ -1053,7 +1053,7 @@ static 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;
|
||||
uint64_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base__limit1* lim;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -1069,15 +1069,15 @@ static 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_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
v_final = 0;
|
||||
label_0_continue:;
|
||||
while (v_final == 0) {
|
||||
while (self->private_impl.f_n_bits < 3) {
|
||||
{
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (WUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_0 = *b_rptr_src++;
|
||||
@@ -1091,11 +1091,11 @@ static 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_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
WUFFS_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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
@@ -1103,7 +1103,7 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_blocks(
|
||||
}
|
||||
}
|
||||
status =
|
||||
puffs_flate__flate_decoder__decode_uncompressed(self, a_dst, a_src);
|
||||
wuffs_flate__flate_decoder__decode_uncompressed(self, a_dst, a_src);
|
||||
if (a_src.buf) {
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
}
|
||||
@@ -1112,24 +1112,24 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_blocks(
|
||||
}
|
||||
goto label_0_continue;
|
||||
} else if (v_type == 1) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
status = puffs_flate__flate_decoder__init_fixed_huffman(self);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
status = wuffs_flate__flate_decoder__init_fixed_huffman(self);
|
||||
if (status) {
|
||||
goto suspend;
|
||||
}
|
||||
} else if (v_type == 2) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
WUFFS_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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
}
|
||||
status = puffs_flate__flate_decoder__init_dynamic_huffman(self, a_src);
|
||||
status = wuffs_flate__flate_decoder__init_dynamic_huffman(self, a_src);
|
||||
if (a_src.buf) {
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
}
|
||||
@@ -1137,15 +1137,15 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_blocks(
|
||||
goto suspend;
|
||||
}
|
||||
} else {
|
||||
status = PUFFS_FLATE__ERROR_BAD_FLATE_BLOCK;
|
||||
status = WUFFS_FLATE__ERROR_BAD_FLATE_BLOCK;
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_end_of_block = false;
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
WUFFS_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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
@@ -1153,7 +1153,7 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_blocks(
|
||||
}
|
||||
}
|
||||
status =
|
||||
puffs_flate__flate_decoder__decode_huffman_fast(self, a_dst, a_src);
|
||||
wuffs_flate__flate_decoder__decode_huffman_fast(self, a_dst, a_src);
|
||||
if (a_src.buf) {
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
}
|
||||
@@ -1163,11 +1163,11 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_blocks(
|
||||
if (self->private_impl.f_end_of_block) {
|
||||
goto label_0_continue;
|
||||
}
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
@@ -1175,7 +1175,7 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_blocks(
|
||||
}
|
||||
}
|
||||
status =
|
||||
puffs_flate__flate_decoder__decode_huffman_slow(self, a_dst, a_src);
|
||||
wuffs_flate__flate_decoder__decode_huffman_slow(self, a_dst, a_src);
|
||||
if (a_src.buf) {
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
}
|
||||
@@ -1186,7 +1186,7 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_blocks(
|
||||
goto label_0_continue;
|
||||
}
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_END_OF_BLOCK;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_END_OF_BLOCK;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@@ -1206,32 +1206,32 @@ 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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
short_read_src:
|
||||
if (a_src.buf && a_src.buf->closed && !a_src.private_impl.limit.ptr_to_len) {
|
||||
status = PUFFS_FLATE__ERROR_UNEXPECTED_EOF;
|
||||
status = WUFFS_FLATE__ERROR_UNEXPECTED_EOF;
|
||||
goto exit;
|
||||
}
|
||||
status = PUFFS_FLATE__SUSPENSION_SHORT_READ;
|
||||
status = WUFFS_FLATE__SUSPENSION_SHORT_READ;
|
||||
goto suspend;
|
||||
}
|
||||
|
||||
static 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_flate__status status = PUFFS_FLATE__STATUS_OK;
|
||||
static wuffs_flate__status wuffs_flate__flate_decoder__decode_uncompressed(
|
||||
wuffs_flate__flate_decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src) {
|
||||
wuffs_flate__status status = WUFFS_FLATE__STATUS_OK;
|
||||
|
||||
uint32_t v_length;
|
||||
uint32_t v_n_copied;
|
||||
@@ -1245,7 +1245,7 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_uncompressed(
|
||||
b_wend_dst = b_wptr_dst;
|
||||
if (!a_dst.buf->closed) {
|
||||
uint64_t len = a_dst.buf->len - a_dst.buf->wi;
|
||||
puffs_base__limit1* lim;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_dst.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -1261,7 +1261,7 @@ static 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;
|
||||
uint64_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base__limit1* lim;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -1277,26 +1277,26 @@ static 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_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if ((self->private_impl.f_n_bits >= 8) ||
|
||||
((self->private_impl.f_bits >> self->private_impl.f_n_bits) != 0)) {
|
||||
status = PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS;
|
||||
status = WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS;
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_n_bits = 0;
|
||||
self->private_impl.f_bits = 0;
|
||||
{
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
uint32_t t_1;
|
||||
if (PUFFS_BASE__LIKELY(b_rend_src - b_rptr_src >= 4)) {
|
||||
t_1 = puffs_base__load_u32le(b_rptr_src);
|
||||
if (WUFFS_BASE__LIKELY(b_rend_src - b_rptr_src >= 4)) {
|
||||
t_1 = wuffs_base__load_u32le(b_rptr_src);
|
||||
b_rptr_src += 4;
|
||||
} else {
|
||||
self->private_impl.c_decode_uncompressed[0].scratch = 0;
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
while (true) {
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
if (WUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint32_t t_0 =
|
||||
@@ -1318,12 +1318,12 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_uncompressed(
|
||||
}
|
||||
if ((((v_length) & ((1 << (16)) - 1)) + ((v_length) >> (32 - (16)))) !=
|
||||
65535) {
|
||||
status = PUFFS_FLATE__ERROR_INCONSISTENT_STORED_BLOCK_LENGTH;
|
||||
status = WUFFS_FLATE__ERROR_INCONSISTENT_STORED_BLOCK_LENGTH;
|
||||
goto exit;
|
||||
}
|
||||
v_length = ((v_length) & ((1 << (16)) - 1));
|
||||
while (true) {
|
||||
v_n_copied = puffs_base__writer1__copy_from_reader32(
|
||||
v_n_copied = wuffs_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;
|
||||
@@ -1331,11 +1331,11 @@ static 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_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
status = WUFFS_FLATE__SUSPENSION_SHORT_WRITE;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
} else {
|
||||
status = PUFFS_FLATE__SUSPENSION_SHORT_READ;
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
||||
status = WUFFS_FLATE__SUSPENSION_SHORT_READ;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
||||
}
|
||||
}
|
||||
label_0_break:;
|
||||
@@ -1356,42 +1356,42 @@ 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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_dst.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wstart_dst);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wend_dst);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wstart_dst);
|
||||
WUFFS_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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
short_read_src:
|
||||
if (a_src.buf && a_src.buf->closed && !a_src.private_impl.limit.ptr_to_len) {
|
||||
status = PUFFS_FLATE__ERROR_UNEXPECTED_EOF;
|
||||
status = WUFFS_FLATE__ERROR_UNEXPECTED_EOF;
|
||||
goto exit;
|
||||
}
|
||||
status = PUFFS_FLATE__SUSPENSION_SHORT_READ;
|
||||
status = WUFFS_FLATE__SUSPENSION_SHORT_READ;
|
||||
goto suspend;
|
||||
}
|
||||
|
||||
static puffs_flate__status puffs_flate__flate_decoder__init_fixed_huffman(
|
||||
puffs_flate__flate_decoder* self) {
|
||||
puffs_flate__status status = PUFFS_FLATE__STATUS_OK;
|
||||
static wuffs_flate__status wuffs_flate__flate_decoder__init_fixed_huffman(
|
||||
wuffs_flate__flate_decoder* self) {
|
||||
wuffs_flate__status status = WUFFS_FLATE__STATUS_OK;
|
||||
|
||||
uint32_t v_i;
|
||||
|
||||
@@ -1401,7 +1401,7 @@ static 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_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
v_i = 0;
|
||||
while (v_i < 144) {
|
||||
@@ -1424,13 +1424,13 @@ static puffs_flate__status puffs_flate__flate_decoder__init_fixed_huffman(
|
||||
self->private_impl.f_code_lengths[v_i] = 5;
|
||||
v_i += 1;
|
||||
}
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
status = puffs_flate__flate_decoder__init_huff(self, 0, 0, 288, 257);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
status = wuffs_flate__flate_decoder__init_huff(self, 0, 0, 288, 257);
|
||||
if (status) {
|
||||
goto suspend;
|
||||
}
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
status = puffs_flate__flate_decoder__init_huff(self, 1, 288, 320, 0);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
status = wuffs_flate__flate_decoder__init_huff(self, 1, 288, 320, 0);
|
||||
if (status) {
|
||||
goto suspend;
|
||||
}
|
||||
@@ -1450,10 +1450,10 @@ exit:
|
||||
return status;
|
||||
}
|
||||
|
||||
static puffs_flate__status puffs_flate__flate_decoder__init_dynamic_huffman(
|
||||
puffs_flate__flate_decoder* self,
|
||||
puffs_base__reader1 a_src) {
|
||||
puffs_flate__status status = PUFFS_FLATE__STATUS_OK;
|
||||
static wuffs_flate__status wuffs_flate__flate_decoder__init_dynamic_huffman(
|
||||
wuffs_flate__flate_decoder* self,
|
||||
wuffs_base__reader1 a_src) {
|
||||
wuffs_flate__status status = WUFFS_FLATE__STATUS_OK;
|
||||
|
||||
uint32_t v_bits;
|
||||
uint32_t v_n_bits;
|
||||
@@ -1475,7 +1475,7 @@ static 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;
|
||||
uint64_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base__limit1* lim;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -1503,14 +1503,14 @@ static 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_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
WUFFS_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_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (WUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_0 = *b_rptr_src++;
|
||||
@@ -1520,13 +1520,13 @@ static puffs_flate__status puffs_flate__flate_decoder__init_dynamic_huffman(
|
||||
}
|
||||
v_n_lit = (((v_bits) & ((1 << (5)) - 1)) + 257);
|
||||
if (v_n_lit > 286) {
|
||||
status = PUFFS_FLATE__ERROR_BAD_LITERAL_LENGTH_CODE_COUNT;
|
||||
status = WUFFS_FLATE__ERROR_BAD_LITERAL_LENGTH_CODE_COUNT;
|
||||
goto exit;
|
||||
}
|
||||
v_bits >>= 5;
|
||||
v_n_dist = (((v_bits) & ((1 << (5)) - 1)) + 1);
|
||||
if (v_n_dist > 30) {
|
||||
status = PUFFS_FLATE__ERROR_BAD_DISTANCE_CODE_COUNT;
|
||||
status = WUFFS_FLATE__ERROR_BAD_DISTANCE_CODE_COUNT;
|
||||
goto exit;
|
||||
}
|
||||
v_bits >>= 5;
|
||||
@@ -1537,8 +1537,8 @@ static puffs_flate__status puffs_flate__flate_decoder__init_dynamic_huffman(
|
||||
while (v_i < v_n_clen) {
|
||||
while (v_n_bits < 3) {
|
||||
{
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (WUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_1 = *b_rptr_src++;
|
||||
@@ -1546,18 +1546,18 @@ static puffs_flate__status puffs_flate__flate_decoder__init_dynamic_huffman(
|
||||
}
|
||||
v_n_bits += 8;
|
||||
}
|
||||
self->private_impl.f_code_lengths[puffs_flate__code_order[v_i]] =
|
||||
self->private_impl.f_code_lengths[wuffs_flate__code_order[v_i]] =
|
||||
((uint8_t)((v_bits & 7)));
|
||||
v_bits >>= 3;
|
||||
v_n_bits -= 3;
|
||||
v_i += 1;
|
||||
}
|
||||
while (v_i < 19) {
|
||||
self->private_impl.f_code_lengths[puffs_flate__code_order[v_i]] = 0;
|
||||
self->private_impl.f_code_lengths[wuffs_flate__code_order[v_i]] = 0;
|
||||
v_i += 1;
|
||||
}
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
status = puffs_flate__flate_decoder__init_huff(self, 0, 0, 19, 4095);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
status = wuffs_flate__flate_decoder__init_huff(self, 0, 0, 19, 4095);
|
||||
if (status) {
|
||||
goto suspend;
|
||||
}
|
||||
@@ -1575,8 +1575,8 @@ static puffs_flate__status puffs_flate__flate_decoder__init_dynamic_huffman(
|
||||
goto label_1_break;
|
||||
}
|
||||
{
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
if (WUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_2 = *b_rptr_src++;
|
||||
@@ -1587,7 +1587,7 @@ static puffs_flate__status puffs_flate__flate_decoder__init_dynamic_huffman(
|
||||
label_1_break:;
|
||||
if ((v_table_entry >> 24) != 128) {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
v_table_entry = ((v_table_entry >> 8) & 255);
|
||||
@@ -1602,7 +1602,7 @@ static puffs_flate__status puffs_flate__flate_decoder__init_dynamic_huffman(
|
||||
if (v_table_entry == 16) {
|
||||
v_n_extra_bits = 2;
|
||||
if (v_i <= 0) {
|
||||
status = PUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_LENGTH_REPETITION;
|
||||
status = WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_LENGTH_REPETITION;
|
||||
goto exit;
|
||||
}
|
||||
v_rep_symbol = self->private_impl.f_code_lengths[v_i - 1];
|
||||
@@ -1617,13 +1617,13 @@ static puffs_flate__status puffs_flate__flate_decoder__init_dynamic_huffman(
|
||||
v_rep_count = 11;
|
||||
} else {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
while (v_n_bits < v_n_extra_bits) {
|
||||
{
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
if (WUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_3 = *b_rptr_src++;
|
||||
@@ -1636,7 +1636,7 @@ static puffs_flate__status puffs_flate__flate_decoder__init_dynamic_huffman(
|
||||
v_n_bits -= v_n_extra_bits;
|
||||
while (v_rep_count > 0) {
|
||||
if (v_i >= (v_n_lit + v_n_dist)) {
|
||||
status = PUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_LENGTH_COUNT;
|
||||
status = WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_LENGTH_COUNT;
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_code_lengths[v_i] = v_rep_symbol;
|
||||
@@ -1645,20 +1645,20 @@ static puffs_flate__status puffs_flate__flate_decoder__init_dynamic_huffman(
|
||||
}
|
||||
}
|
||||
if (v_i != (v_n_lit + v_n_dist)) {
|
||||
status = PUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_LENGTH_COUNT;
|
||||
status = WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_LENGTH_COUNT;
|
||||
goto exit;
|
||||
}
|
||||
if (self->private_impl.f_code_lengths[256] == 0) {
|
||||
status = PUFFS_FLATE__ERROR_MISSING_END_OF_BLOCK_CODE;
|
||||
status = WUFFS_FLATE__ERROR_MISSING_END_OF_BLOCK_CODE;
|
||||
goto exit;
|
||||
}
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
status = puffs_flate__flate_decoder__init_huff(self, 0, 0, v_n_lit, 257);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
status = wuffs_flate__flate_decoder__init_huff(self, 0, 0, v_n_lit, 257);
|
||||
if (status) {
|
||||
goto suspend;
|
||||
}
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
status = puffs_flate__flate_decoder__init_huff(self, 1, v_n_lit,
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
status = wuffs_flate__flate_decoder__init_huff(self, 1, v_n_lit,
|
||||
(v_n_lit + v_n_dist), 0);
|
||||
if (status) {
|
||||
goto suspend;
|
||||
@@ -1694,34 +1694,34 @@ 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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
short_read_src:
|
||||
if (a_src.buf && a_src.buf->closed && !a_src.private_impl.limit.ptr_to_len) {
|
||||
status = PUFFS_FLATE__ERROR_UNEXPECTED_EOF;
|
||||
status = WUFFS_FLATE__ERROR_UNEXPECTED_EOF;
|
||||
goto exit;
|
||||
}
|
||||
status = PUFFS_FLATE__SUSPENSION_SHORT_READ;
|
||||
status = WUFFS_FLATE__SUSPENSION_SHORT_READ;
|
||||
goto suspend;
|
||||
}
|
||||
|
||||
static puffs_flate__status puffs_flate__flate_decoder__init_huff(
|
||||
puffs_flate__flate_decoder* self,
|
||||
static wuffs_flate__status wuffs_flate__flate_decoder__init_huff(
|
||||
wuffs_flate__flate_decoder* self,
|
||||
uint32_t a_which,
|
||||
uint32_t a_n_codes0,
|
||||
uint32_t a_n_codes1,
|
||||
uint32_t a_base_symbol) {
|
||||
puffs_flate__status status = PUFFS_FLATE__STATUS_OK;
|
||||
wuffs_flate__status status = WUFFS_FLATE__STATUS_OK;
|
||||
|
||||
uint16_t v_counts[16];
|
||||
uint32_t v_i;
|
||||
@@ -1754,14 +1754,14 @@ static puffs_flate__status puffs_flate__flate_decoder__init_huff(
|
||||
while (v_i < a_n_codes1) {
|
||||
if (v_counts[self->private_impl.f_code_lengths[v_i]] >= 320) {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
v_counts[self->private_impl.f_code_lengths[v_i]] += 1;
|
||||
v_i += 1;
|
||||
}
|
||||
if ((((uint32_t)(v_counts[0])) + a_n_codes0) == a_n_codes1) {
|
||||
status = PUFFS_FLATE__ERROR_NO_HUFFMAN_CODES;
|
||||
status = WUFFS_FLATE__ERROR_NO_HUFFMAN_CODES;
|
||||
goto exit;
|
||||
}
|
||||
v_remaining = 1;
|
||||
@@ -1769,19 +1769,19 @@ static puffs_flate__status puffs_flate__flate_decoder__init_huff(
|
||||
while (v_i <= 15) {
|
||||
if (v_remaining > 1073741824) {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
v_remaining <<= 1;
|
||||
if (v_remaining < ((uint32_t)(v_counts[v_i]))) {
|
||||
status = PUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_OVER_SUBSCRIBED;
|
||||
status = WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_OVER_SUBSCRIBED;
|
||||
goto exit;
|
||||
}
|
||||
v_remaining -= ((uint32_t)(v_counts[v_i]));
|
||||
v_i += 1;
|
||||
}
|
||||
if (v_remaining != 0) {
|
||||
status = PUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_UNDER_SUBSCRIBED;
|
||||
status = WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_UNDER_SUBSCRIBED;
|
||||
goto exit;
|
||||
}
|
||||
memset(v_offsets, 0, sizeof(v_offsets));
|
||||
@@ -1792,7 +1792,7 @@ static puffs_flate__status puffs_flate__flate_decoder__init_huff(
|
||||
v_count = ((uint32_t)(v_counts[v_i]));
|
||||
if (v_n_symbols > (320 - v_count)) {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
v_n_symbols = (v_n_symbols + v_count);
|
||||
@@ -1800,7 +1800,7 @@ static puffs_flate__status puffs_flate__flate_decoder__init_huff(
|
||||
}
|
||||
if (v_n_symbols > 288) {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
memset(v_symbols, 0, sizeof(v_symbols));
|
||||
@@ -1808,13 +1808,13 @@ static puffs_flate__status puffs_flate__flate_decoder__init_huff(
|
||||
while (v_i < a_n_codes1) {
|
||||
if (v_i < a_n_codes0) {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
if (self->private_impl.f_code_lengths[v_i] != 0) {
|
||||
if (v_offsets[self->private_impl.f_code_lengths[v_i]] >= 320) {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
v_symbols[v_offsets[self->private_impl.f_code_lengths[v_i]]] =
|
||||
@@ -1829,7 +1829,7 @@ static puffs_flate__status puffs_flate__flate_decoder__init_huff(
|
||||
goto label_0_break;
|
||||
}
|
||||
if (v_min_cl >= 9) {
|
||||
status = PUFFS_FLATE__ERROR_BAD_HUFFMAN_MINIMUM_CODE_LENGTH;
|
||||
status = WUFFS_FLATE__ERROR_BAD_HUFFMAN_MINIMUM_CODE_LENGTH;
|
||||
goto exit;
|
||||
}
|
||||
v_min_cl += 1;
|
||||
@@ -1841,7 +1841,7 @@ label_0_break:;
|
||||
goto label_1_break;
|
||||
}
|
||||
if (v_max_cl <= 1) {
|
||||
status = PUFFS_FLATE__ERROR_NO_HUFFMAN_CODES;
|
||||
status = WUFFS_FLATE__ERROR_NO_HUFFMAN_CODES;
|
||||
goto exit;
|
||||
}
|
||||
v_max_cl -= 1;
|
||||
@@ -1856,12 +1856,12 @@ label_1_break:;
|
||||
if ((v_n_symbols != ((uint32_t)(v_offsets[v_max_cl]))) ||
|
||||
(v_n_symbols != ((uint32_t)(v_offsets[15])))) {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
if ((a_n_codes0 + ((uint32_t)(v_symbols[0]))) >= 320) {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
v_initial_high_bits = 512;
|
||||
@@ -1880,7 +1880,7 @@ label_1_break:;
|
||||
while (true) {
|
||||
if ((a_n_codes0 + ((uint32_t)(v_symbols[v_i]))) >= 320) {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
v_cl = ((uint32_t)(
|
||||
@@ -1890,7 +1890,7 @@ label_1_break:;
|
||||
v_code <<= (v_cl - v_prev_cl);
|
||||
if (v_code >= 32768) {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
@@ -1912,7 +1912,7 @@ label_1_break:;
|
||||
v_remaining -= ((uint32_t)(v_counts[v_j]));
|
||||
if (v_remaining > 1073741824) {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
v_remaining <<= 1;
|
||||
@@ -1921,7 +1921,7 @@ label_1_break:;
|
||||
label_2_break:;
|
||||
if ((v_j <= 9) || (15 < v_j)) {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
v_tmp = (v_j - 9);
|
||||
@@ -1929,12 +1929,12 @@ label_1_break:;
|
||||
v_top = v_next_top;
|
||||
if ((v_top + (((uint32_t)(1)) << v_tmp)) > 1234) {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
v_next_top = (v_top + (((uint32_t)(1)) << v_tmp));
|
||||
v_redirect_key =
|
||||
(((uint32_t)(puffs_flate__reverse8[v_redirect_key >> 1])) |
|
||||
(((uint32_t)(wuffs_flate__reverse8[v_redirect_key >> 1])) |
|
||||
((v_redirect_key & 1) << 8));
|
||||
self->private_impl.f_huffs[a_which][v_redirect_key] =
|
||||
(268435465 | (v_top << 8) | (v_tmp << 4));
|
||||
@@ -1942,12 +1942,12 @@ label_1_break:;
|
||||
}
|
||||
if ((v_key >= 512) || (v_counts[v_prev_cl] <= 0)) {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
v_counts[v_prev_cl] -= 1;
|
||||
v_reversed_key =
|
||||
(((uint32_t)(puffs_flate__reverse8[v_key >> 1])) | ((v_key & 1) << 8));
|
||||
(((uint32_t)(wuffs_flate__reverse8[v_key >> 1])) | ((v_key & 1) << 8));
|
||||
v_reversed_key >>= (9 - v_cl);
|
||||
v_symbol = ((uint32_t)(v_symbols[v_i]));
|
||||
if (v_symbol == 256) {
|
||||
@@ -1957,13 +1957,13 @@ label_1_break:;
|
||||
} else if (v_symbol >= a_base_symbol) {
|
||||
v_symbol -= a_base_symbol;
|
||||
if (a_which == 0) {
|
||||
v_value = (puffs_flate__lcode_magic_numbers[v_symbol & 31] | v_cl);
|
||||
v_value = (wuffs_flate__lcode_magic_numbers[v_symbol & 31] | v_cl);
|
||||
} else {
|
||||
v_value = (puffs_flate__dcode_magic_numbers[v_symbol & 31] | v_cl);
|
||||
v_value = (wuffs_flate__dcode_magic_numbers[v_symbol & 31] | v_cl);
|
||||
}
|
||||
} else {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
v_high_bits = v_initial_high_bits;
|
||||
@@ -1972,7 +1972,7 @@ label_1_break:;
|
||||
v_high_bits -= v_delta;
|
||||
if ((v_top + ((v_high_bits | v_reversed_key) & 511)) >= 1234) {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl
|
||||
@@ -1986,7 +1986,7 @@ label_1_break:;
|
||||
v_code += 1;
|
||||
if (v_code >= 32768) {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
@@ -1995,11 +1995,11 @@ exit:
|
||||
return status;
|
||||
}
|
||||
|
||||
static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_fast(
|
||||
puffs_flate__flate_decoder* self,
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src) {
|
||||
puffs_flate__status status = PUFFS_FLATE__STATUS_OK;
|
||||
static wuffs_flate__status wuffs_flate__flate_decoder__decode_huffman_fast(
|
||||
wuffs_flate__flate_decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src) {
|
||||
wuffs_flate__status status = WUFFS_FLATE__STATUS_OK;
|
||||
|
||||
uint32_t v_bits;
|
||||
uint32_t v_n_bits;
|
||||
@@ -2024,7 +2024,7 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_fast(
|
||||
b_wend_dst = b_wptr_dst;
|
||||
if (!a_dst.buf->closed) {
|
||||
uint64_t len = a_dst.buf->len - a_dst.buf->wi;
|
||||
puffs_base__limit1* lim;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_dst.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -2040,7 +2040,7 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_fast(
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
b_rstart_src = b_rptr_src;
|
||||
uint64_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base__limit1* lim;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -2050,12 +2050,12 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_fast(
|
||||
}
|
||||
|
||||
if (!(a_dst.private_impl.mark != NULL)) {
|
||||
status = PUFFS_FLATE__ERROR_BAD_ARGUMENT;
|
||||
status = WUFFS_FLATE__ERROR_BAD_ARGUMENT;
|
||||
goto exit;
|
||||
}
|
||||
if ((self->private_impl.f_n_bits >= 8) ||
|
||||
((self->private_impl.f_bits >> self->private_impl.f_n_bits) != 0)) {
|
||||
status = PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS;
|
||||
status = WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS;
|
||||
goto exit;
|
||||
}
|
||||
v_bits = self->private_impl.f_bits;
|
||||
@@ -2109,7 +2109,7 @@ label_0_continue:;
|
||||
v_redir_mask = ((((uint32_t)(1)) << ((v_table_entry >> 4) & 15)) - 1);
|
||||
if ((v_redir_top + (v_bits & v_redir_mask)) >= 1234) {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
v_table_entry =
|
||||
@@ -2126,22 +2126,22 @@ label_0_continue:;
|
||||
goto label_0_break;
|
||||
} else if ((v_table_entry >> 28) != 0) {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
} else if ((v_table_entry >> 27) != 0) {
|
||||
status = PUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE;
|
||||
status = WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE;
|
||||
goto exit;
|
||||
} else {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
} else if ((v_table_entry >> 27) != 0) {
|
||||
status = PUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE;
|
||||
status = WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE;
|
||||
goto exit;
|
||||
} else {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
v_length = ((v_table_entry >> 8) & 32767);
|
||||
@@ -2169,7 +2169,7 @@ label_0_continue:;
|
||||
}
|
||||
if (v_length > 258) {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
if (v_n_bits < 15) {
|
||||
@@ -2207,7 +2207,7 @@ label_0_continue:;
|
||||
v_redir_mask = ((((uint32_t)(1)) << ((v_table_entry >> 4) & 15)) - 1);
|
||||
if ((v_redir_top + (v_bits & v_redir_mask)) >= 1234) {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
v_table_entry =
|
||||
@@ -2219,11 +2219,11 @@ label_0_continue:;
|
||||
}
|
||||
if ((v_table_entry >> 24) != 64) {
|
||||
if ((v_table_entry >> 24) == 8) {
|
||||
status = PUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE;
|
||||
status = WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE;
|
||||
goto exit;
|
||||
}
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
v_distance = ((v_table_entry >> 8) & 32767);
|
||||
@@ -2249,14 +2249,14 @@ label_0_continue:;
|
||||
}
|
||||
if (v_distance <= 0) {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
v_n_copied = 0;
|
||||
while (true) {
|
||||
if (((uint64_t)(v_distance)) >
|
||||
((uint64_t)(
|
||||
((puffs_base__slice_u8){
|
||||
((wuffs_base__slice_u8){
|
||||
.ptr = a_dst.private_impl.mark,
|
||||
.len = a_dst.private_impl.mark
|
||||
? (size_t)(b_wptr_dst - a_dst.private_impl.mark)
|
||||
@@ -2267,7 +2267,7 @@ label_0_continue:;
|
||||
v_hdist = ((uint32_t)((
|
||||
((uint64_t)(v_distance)) -
|
||||
((uint64_t)(
|
||||
((puffs_base__slice_u8){
|
||||
((wuffs_base__slice_u8){
|
||||
.ptr = a_dst.private_impl.mark,
|
||||
.len = a_dst.private_impl.mark
|
||||
? (size_t)(b_wptr_dst - a_dst.private_impl.mark)
|
||||
@@ -2279,7 +2279,7 @@ label_0_continue:;
|
||||
v_hlen = v_hdist;
|
||||
if (v_length > 258) {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
} else {
|
||||
@@ -2287,15 +2287,15 @@ label_0_continue:;
|
||||
v_length = 0;
|
||||
}
|
||||
if (self->private_impl.f_history_index < v_hdist) {
|
||||
status = PUFFS_FLATE__ERROR_BAD_DISTANCE;
|
||||
status = WUFFS_FLATE__ERROR_BAD_DISTANCE;
|
||||
goto exit;
|
||||
}
|
||||
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 = wuffs_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,
|
||||
wuffs_base__slice_u8__subslice_i(
|
||||
((wuffs_base__slice_u8){.ptr = self->private_impl.f_history,
|
||||
.len = 32768}),
|
||||
v_hdist),
|
||||
v_hlen);
|
||||
@@ -2303,9 +2303,9 @@ label_0_continue:;
|
||||
goto label_1_break;
|
||||
}
|
||||
v_hlen -= v_n_copied;
|
||||
puffs_base__writer1__copy_from_slice32(
|
||||
wuffs_base__writer1__copy_from_slice32(
|
||||
&b_wptr_dst, b_wend_dst,
|
||||
((puffs_base__slice_u8){.ptr = self->private_impl.f_history,
|
||||
((wuffs_base__slice_u8){.ptr = self->private_impl.f_history,
|
||||
.len = 32768}),
|
||||
v_hlen);
|
||||
goto label_1_break;
|
||||
@@ -2316,18 +2316,18 @@ label_0_continue:;
|
||||
}
|
||||
if (((uint64_t)(v_distance)) >
|
||||
((uint64_t)(
|
||||
((puffs_base__slice_u8){
|
||||
((wuffs_base__slice_u8){
|
||||
.ptr = a_dst.private_impl.mark,
|
||||
.len = a_dst.private_impl.mark
|
||||
? (size_t)(b_wptr_dst - a_dst.private_impl.mark)
|
||||
: 0,
|
||||
})
|
||||
.len))) {
|
||||
status = PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_DISTANCE;
|
||||
status = WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_DISTANCE;
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
puffs_base__writer1__copy_from_history32__bco(
|
||||
wuffs_base__writer1__copy_from_history32__bco(
|
||||
&b_wptr_dst, a_dst.private_impl.mark, b_wend_dst, v_distance,
|
||||
v_length);
|
||||
goto label_2_break;
|
||||
@@ -2338,7 +2338,7 @@ label_0_break:;
|
||||
while (v_n_bits >= 8) {
|
||||
v_n_bits -= 8;
|
||||
if (b_rptr_src == b_rstart_src) {
|
||||
status = PUFFS_FLATE__ERROR_INVALID_I_O_OPERATION;
|
||||
status = WUFFS_FLATE__ERROR_INVALID_I_O_OPERATION;
|
||||
goto exit;
|
||||
}
|
||||
b_rptr_src--;
|
||||
@@ -2347,43 +2347,43 @@ label_0_break:;
|
||||
self->private_impl.f_n_bits = v_n_bits;
|
||||
if ((self->private_impl.f_n_bits >= 8) ||
|
||||
((self->private_impl.f_bits >> self->private_impl.f_n_bits) != 0)) {
|
||||
status = PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS;
|
||||
status = WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS;
|
||||
goto exit;
|
||||
}
|
||||
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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_dst.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wstart_dst);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wend_dst);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wstart_dst);
|
||||
WUFFS_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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_slow(
|
||||
puffs_flate__flate_decoder* self,
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src) {
|
||||
puffs_flate__status status = PUFFS_FLATE__STATUS_OK;
|
||||
static wuffs_flate__status wuffs_flate__flate_decoder__decode_huffman_slow(
|
||||
wuffs_flate__flate_decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src) {
|
||||
wuffs_flate__status status = WUFFS_FLATE__STATUS_OK;
|
||||
|
||||
uint32_t v_bits;
|
||||
uint32_t v_n_bits;
|
||||
@@ -2408,7 +2408,7 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_slow(
|
||||
b_wend_dst = b_wptr_dst;
|
||||
if (!a_dst.buf->closed) {
|
||||
uint64_t len = a_dst.buf->len - a_dst.buf->wi;
|
||||
puffs_base__limit1* lim;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_dst.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -2424,7 +2424,7 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_slow(
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
b_rstart_src = b_rptr_src;
|
||||
uint64_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base__limit1* lim;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -2452,11 +2452,11 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_slow(
|
||||
v_hdist = self->private_impl.c_decode_huffman_slow[0].v_hdist;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
if ((self->private_impl.f_n_bits >= 8) ||
|
||||
((self->private_impl.f_bits >> self->private_impl.f_n_bits) != 0)) {
|
||||
status = PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS;
|
||||
status = WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS;
|
||||
goto exit;
|
||||
}
|
||||
v_bits = self->private_impl.f_bits;
|
||||
@@ -2476,8 +2476,8 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_slow(
|
||||
goto label_1_break;
|
||||
}
|
||||
{
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (WUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_0 = *b_rptr_src++;
|
||||
@@ -2487,9 +2487,9 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_slow(
|
||||
}
|
||||
label_1_break:;
|
||||
if ((v_table_entry >> 31) != 0) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (b_wptr_dst == b_wend_dst) {
|
||||
status = PUFFS_FLATE__SUSPENSION_SHORT_WRITE;
|
||||
status = WUFFS_FLATE__SUSPENSION_SHORT_WRITE;
|
||||
goto suspend;
|
||||
}
|
||||
*b_wptr_dst++ = ((v_table_entry >> 8) & 255);
|
||||
@@ -2504,7 +2504,7 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_slow(
|
||||
while (true) {
|
||||
if ((v_redir_top + (v_bits & v_redir_mask)) >= 1234) {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
v_table_entry =
|
||||
@@ -2517,8 +2517,8 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_slow(
|
||||
goto label_2_break;
|
||||
}
|
||||
{
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
if (WUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_1 = *b_rptr_src++;
|
||||
@@ -2528,9 +2528,9 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_slow(
|
||||
}
|
||||
label_2_break:;
|
||||
if ((v_table_entry >> 31) != 0) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
if (b_wptr_dst == b_wend_dst) {
|
||||
status = PUFFS_FLATE__SUSPENSION_SHORT_WRITE;
|
||||
status = WUFFS_FLATE__SUSPENSION_SHORT_WRITE;
|
||||
goto suspend;
|
||||
}
|
||||
*b_wptr_dst++ = ((v_table_entry >> 8) & 255);
|
||||
@@ -2541,22 +2541,22 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_slow(
|
||||
goto label_0_break;
|
||||
} else if ((v_table_entry >> 28) != 0) {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
} else if ((v_table_entry >> 27) != 0) {
|
||||
status = PUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE;
|
||||
status = WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE;
|
||||
goto exit;
|
||||
} else {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
} else if ((v_table_entry >> 27) != 0) {
|
||||
status = PUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE;
|
||||
status = WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE;
|
||||
goto exit;
|
||||
} else {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
v_length = ((v_table_entry >> 8) & 32767);
|
||||
@@ -2564,8 +2564,8 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_slow(
|
||||
if (v_table_entry_n_bits > 0) {
|
||||
while (v_n_bits < v_table_entry_n_bits) {
|
||||
{
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
if (WUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_2 = *b_rptr_src++;
|
||||
@@ -2588,8 +2588,8 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_slow(
|
||||
goto label_3_break;
|
||||
}
|
||||
{
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
if (WUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_3 = *b_rptr_src++;
|
||||
@@ -2604,7 +2604,7 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_slow(
|
||||
while (true) {
|
||||
if ((v_redir_top + (v_bits & v_redir_mask)) >= 1234) {
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
v_table_entry =
|
||||
@@ -2617,8 +2617,8 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_slow(
|
||||
goto label_4_break;
|
||||
}
|
||||
{
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
|
||||
if (WUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_4 = *b_rptr_src++;
|
||||
@@ -2630,11 +2630,11 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_slow(
|
||||
}
|
||||
if ((v_table_entry >> 24) != 64) {
|
||||
if ((v_table_entry >> 24) == 8) {
|
||||
status = PUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE;
|
||||
status = WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE;
|
||||
goto exit;
|
||||
}
|
||||
status =
|
||||
PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE;
|
||||
goto exit;
|
||||
}
|
||||
v_distance = ((v_table_entry >> 8) & 32767);
|
||||
@@ -2642,8 +2642,8 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_slow(
|
||||
if (v_table_entry_n_bits > 0) {
|
||||
while (v_n_bits < v_table_entry_n_bits) {
|
||||
{
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
|
||||
if (WUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_5 = *b_rptr_src++;
|
||||
@@ -2661,7 +2661,7 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_slow(
|
||||
while (true) {
|
||||
if (((uint64_t)(v_distance)) >
|
||||
((uint64_t)(
|
||||
((puffs_base__slice_u8){
|
||||
((wuffs_base__slice_u8){
|
||||
.ptr = a_dst.private_impl.mark,
|
||||
.len = a_dst.private_impl.mark
|
||||
? (size_t)(b_wptr_dst - a_dst.private_impl.mark)
|
||||
@@ -2671,7 +2671,7 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_slow(
|
||||
v_hlen = 0;
|
||||
v_hdist = ((uint32_t)(
|
||||
(((uint64_t)(v_distance)) -
|
||||
((uint64_t)(((puffs_base__slice_u8){
|
||||
((uint64_t)(((wuffs_base__slice_u8){
|
||||
.ptr = a_dst.private_impl.mark,
|
||||
.len = a_dst.private_impl.mark
|
||||
? (size_t)(b_wptr_dst -
|
||||
@@ -2687,15 +2687,15 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_slow(
|
||||
v_length = 0;
|
||||
}
|
||||
if (self->private_impl.f_history_index < v_hdist) {
|
||||
status = PUFFS_FLATE__ERROR_BAD_DISTANCE;
|
||||
status = WUFFS_FLATE__ERROR_BAD_DISTANCE;
|
||||
goto exit;
|
||||
}
|
||||
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 = wuffs_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,
|
||||
wuffs_base__slice_u8__subslice_i(
|
||||
((wuffs_base__slice_u8){.ptr = self->private_impl.f_history,
|
||||
.len = 32768}),
|
||||
v_hdist),
|
||||
v_hlen);
|
||||
@@ -2710,16 +2710,16 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_slow(
|
||||
goto label_5_break;
|
||||
}
|
||||
}
|
||||
status = PUFFS_FLATE__SUSPENSION_SHORT_WRITE;
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
|
||||
status = WUFFS_FLATE__SUSPENSION_SHORT_WRITE;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(9);
|
||||
}
|
||||
label_5_break:;
|
||||
if (v_hlen > 0) {
|
||||
while (true) {
|
||||
v_n_copied = puffs_base__writer1__copy_from_slice32(
|
||||
v_n_copied = wuffs_base__writer1__copy_from_slice32(
|
||||
&b_wptr_dst, b_wend_dst,
|
||||
puffs_base__slice_u8__subslice_i(
|
||||
((puffs_base__slice_u8){
|
||||
wuffs_base__slice_u8__subslice_i(
|
||||
((wuffs_base__slice_u8){
|
||||
.ptr = self->private_impl.f_history, .len = 32768}),
|
||||
v_hdist),
|
||||
v_hlen);
|
||||
@@ -2729,8 +2729,8 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_slow(
|
||||
}
|
||||
v_hlen -= v_n_copied;
|
||||
v_hdist = ((v_hdist + (v_n_copied & 32767)) & 32767);
|
||||
status = PUFFS_FLATE__SUSPENSION_SHORT_WRITE;
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
status = WUFFS_FLATE__SUSPENSION_SHORT_WRITE;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(10);
|
||||
}
|
||||
label_6_break:;
|
||||
}
|
||||
@@ -2738,7 +2738,7 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_slow(
|
||||
goto label_0_continue;
|
||||
}
|
||||
}
|
||||
v_n_copied = puffs_base__writer1__copy_from_history32(
|
||||
v_n_copied = wuffs_base__writer1__copy_from_history32(
|
||||
&b_wptr_dst, a_dst.private_impl.mark, b_wend_dst, v_distance,
|
||||
v_length);
|
||||
if (v_length <= v_n_copied) {
|
||||
@@ -2746,8 +2746,8 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_slow(
|
||||
goto label_7_break;
|
||||
}
|
||||
v_length -= v_n_copied;
|
||||
status = PUFFS_FLATE__SUSPENSION_SHORT_WRITE;
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11);
|
||||
status = WUFFS_FLATE__SUSPENSION_SHORT_WRITE;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(11);
|
||||
}
|
||||
label_7_break:;
|
||||
}
|
||||
@@ -2756,7 +2756,7 @@ static puffs_flate__status puffs_flate__flate_decoder__decode_huffman_slow(
|
||||
self->private_impl.f_n_bits = v_n_bits;
|
||||
if ((self->private_impl.f_n_bits >= 8) ||
|
||||
((self->private_impl.f_bits >> self->private_impl.f_n_bits) != 0)) {
|
||||
status = PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS;
|
||||
status = WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@@ -2788,57 +2788,57 @@ 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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_dst.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wstart_dst);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wend_dst);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wstart_dst);
|
||||
WUFFS_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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
short_read_src:
|
||||
if (a_src.buf && a_src.buf->closed && !a_src.private_impl.limit.ptr_to_len) {
|
||||
status = PUFFS_FLATE__ERROR_UNEXPECTED_EOF;
|
||||
status = WUFFS_FLATE__ERROR_UNEXPECTED_EOF;
|
||||
goto exit;
|
||||
}
|
||||
status = PUFFS_FLATE__SUSPENSION_SHORT_READ;
|
||||
status = WUFFS_FLATE__SUSPENSION_SHORT_READ;
|
||||
goto suspend;
|
||||
}
|
||||
|
||||
puffs_flate__status puffs_flate__zlib_decoder__decode(
|
||||
puffs_flate__zlib_decoder* self,
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src) {
|
||||
wuffs_flate__status wuffs_flate__zlib_decoder__decode(
|
||||
wuffs_flate__zlib_decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src) {
|
||||
if (!self) {
|
||||
return PUFFS_FLATE__ERROR_BAD_RECEIVER;
|
||||
return WUFFS_FLATE__ERROR_BAD_RECEIVER;
|
||||
}
|
||||
if (self->private_impl.magic != PUFFS_BASE__MAGIC) {
|
||||
self->private_impl.status = PUFFS_FLATE__ERROR_INITIALIZER_NOT_CALLED;
|
||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
self->private_impl.status = WUFFS_FLATE__ERROR_INITIALIZER_NOT_CALLED;
|
||||
}
|
||||
if (self->private_impl.status < 0) {
|
||||
return self->private_impl.status;
|
||||
}
|
||||
puffs_flate__status status = PUFFS_FLATE__STATUS_OK;
|
||||
wuffs_flate__status status = WUFFS_FLATE__STATUS_OK;
|
||||
|
||||
uint16_t v_x;
|
||||
uint32_t v_checksum;
|
||||
puffs_flate__status v_z;
|
||||
wuffs_flate__status v_z;
|
||||
|
||||
uint8_t* b_wptr_dst = NULL;
|
||||
uint8_t* b_wstart_dst = NULL;
|
||||
@@ -2849,7 +2849,7 @@ puffs_flate__status puffs_flate__zlib_decoder__decode(
|
||||
b_wend_dst = b_wptr_dst;
|
||||
if (!a_dst.buf->closed) {
|
||||
uint64_t len = a_dst.buf->len - a_dst.buf->wi;
|
||||
puffs_base__limit1* lim;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_dst.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -2865,7 +2865,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;
|
||||
uint64_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base__limit1* lim;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -2881,19 +2881,19 @@ puffs_flate__status puffs_flate__zlib_decoder__decode(
|
||||
v_z = self->private_impl.c_decode[0].v_z;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
{
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
uint16_t t_1;
|
||||
if (PUFFS_BASE__LIKELY(b_rend_src - b_rptr_src >= 2)) {
|
||||
t_1 = puffs_base__load_u16be(b_rptr_src);
|
||||
if (WUFFS_BASE__LIKELY(b_rend_src - b_rptr_src >= 2)) {
|
||||
t_1 = wuffs_base__load_u16be(b_rptr_src);
|
||||
b_rptr_src += 2;
|
||||
} else {
|
||||
self->private_impl.c_decode[0].scratch = 0;
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
while (true) {
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
if (WUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint32_t t_0 = self->private_impl.c_decode[0].scratch & 0xFF;
|
||||
@@ -2912,30 +2912,30 @@ puffs_flate__status puffs_flate__zlib_decoder__decode(
|
||||
v_x = t_1;
|
||||
}
|
||||
if (((v_x >> 8) & 15) != 8) {
|
||||
status = PUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_METHOD;
|
||||
status = WUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_METHOD;
|
||||
goto exit;
|
||||
}
|
||||
if ((v_x >> 12) > 7) {
|
||||
status = PUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_WINDOW_SIZE;
|
||||
status = WUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_WINDOW_SIZE;
|
||||
goto exit;
|
||||
}
|
||||
if ((v_x & 32) != 0) {
|
||||
status = PUFFS_FLATE__ERROR_TODO_UNSUPPORTED_ZLIB_PRESET_DICTIONARY;
|
||||
status = WUFFS_FLATE__ERROR_TODO_UNSUPPORTED_ZLIB_PRESET_DICTIONARY;
|
||||
goto exit;
|
||||
}
|
||||
if ((v_x % 31) != 0) {
|
||||
status = PUFFS_FLATE__ERROR_INVALID_ZLIB_PARITY_CHECK;
|
||||
status = WUFFS_FLATE__ERROR_INVALID_ZLIB_PARITY_CHECK;
|
||||
goto exit;
|
||||
}
|
||||
v_checksum = 0;
|
||||
while (true) {
|
||||
puffs_base__writer1__mark(&a_dst, b_wptr_dst);
|
||||
wuffs_base__writer1__mark(&a_dst, b_wptr_dst);
|
||||
{
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
WUFFS_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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_dst.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
@@ -2945,14 +2945,14 @@ 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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
}
|
||||
puffs_flate__status t_2 = puffs_flate__flate_decoder__decode(
|
||||
wuffs_flate__status t_2 = wuffs_flate__flate_decoder__decode(
|
||||
&self->private_impl.f_flate, a_dst, a_src);
|
||||
if (a_dst.buf) {
|
||||
b_wptr_dst = a_dst.buf->ptr + a_dst.buf->wi;
|
||||
@@ -2962,9 +2962,9 @@ puffs_flate__status puffs_flate__zlib_decoder__decode(
|
||||
}
|
||||
v_z = t_2;
|
||||
}
|
||||
v_checksum = puffs_flate__adler32__update(
|
||||
v_checksum = wuffs_flate__adler32__update(
|
||||
&self->private_impl.f_adler,
|
||||
((puffs_base__slice_u8){
|
||||
((wuffs_base__slice_u8){
|
||||
.ptr = a_dst.private_impl.mark,
|
||||
.len = a_dst.private_impl.mark
|
||||
? (size_t)(b_wptr_dst - a_dst.private_impl.mark)
|
||||
@@ -2974,19 +2974,19 @@ puffs_flate__status puffs_flate__zlib_decoder__decode(
|
||||
goto label_0_break;
|
||||
}
|
||||
status = v_z;
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(4);
|
||||
}
|
||||
label_0_break:;
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
uint32_t t_4;
|
||||
if (PUFFS_BASE__LIKELY(b_rend_src - b_rptr_src >= 4)) {
|
||||
t_4 = puffs_base__load_u32be(b_rptr_src);
|
||||
if (WUFFS_BASE__LIKELY(b_rend_src - b_rptr_src >= 4)) {
|
||||
t_4 = wuffs_base__load_u32be(b_rptr_src);
|
||||
b_rptr_src += 4;
|
||||
} else {
|
||||
self->private_impl.c_decode[0].scratch = 0;
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
while (true) {
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
if (WUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint32_t t_3 = self->private_impl.c_decode[0].scratch & 0xFF;
|
||||
@@ -3003,7 +3003,7 @@ puffs_flate__status puffs_flate__zlib_decoder__decode(
|
||||
}
|
||||
}
|
||||
if (v_checksum != t_4) {
|
||||
status = PUFFS_FLATE__ERROR_CHECKSUM_MISMATCH;
|
||||
status = WUFFS_FLATE__ERROR_CHECKSUM_MISMATCH;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@@ -3024,26 +3024,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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_dst.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wstart_dst);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wend_dst);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wstart_dst);
|
||||
WUFFS_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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
}
|
||||
|
||||
self->private_impl.status = status;
|
||||
@@ -3051,29 +3051,29 @@ exit:
|
||||
|
||||
short_read_src:
|
||||
if (a_src.buf && a_src.buf->closed && !a_src.private_impl.limit.ptr_to_len) {
|
||||
status = PUFFS_FLATE__ERROR_UNEXPECTED_EOF;
|
||||
status = WUFFS_FLATE__ERROR_UNEXPECTED_EOF;
|
||||
goto exit;
|
||||
}
|
||||
status = PUFFS_FLATE__SUSPENSION_SHORT_READ;
|
||||
status = WUFFS_FLATE__SUSPENSION_SHORT_READ;
|
||||
goto suspend;
|
||||
}
|
||||
|
||||
static uint32_t puffs_flate__adler32__update(puffs_flate__adler32* self,
|
||||
puffs_base__slice_u8 a_x) {
|
||||
static uint32_t wuffs_flate__adler32__update(wuffs_flate__adler32* self,
|
||||
wuffs_base__slice_u8 a_x) {
|
||||
uint32_t v_s1;
|
||||
uint32_t v_s2;
|
||||
puffs_base__slice_u8 v_remaining;
|
||||
wuffs_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 = ((wuffs_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 = wuffs_base__slice_u8__subslice_i(a_x, 5552);
|
||||
a_x = wuffs_base__slice_u8__subslice_j(a_x, 5552);
|
||||
}
|
||||
{
|
||||
puffs_base__slice_u8 i_slice_p = a_x;
|
||||
wuffs_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) {
|
||||
|
||||
+329
-329
@@ -1,10 +1,10 @@
|
||||
#ifndef PUFFS_GIF_H
|
||||
#define PUFFS_GIF_H
|
||||
#ifndef WUFFS_GIF_H
|
||||
#define WUFFS_GIF_H
|
||||
|
||||
// Code generated by wuffs-c. DO NOT EDIT.
|
||||
|
||||
#ifndef PUFFS_BASE_HEADER_H
|
||||
#define PUFFS_BASE_HEADER_H
|
||||
#ifndef WUFFS_BASE_HEADER_H
|
||||
#define WUFFS_BASE_HEADER_H
|
||||
|
||||
// Copyright 2017 The Wuffs Authors.
|
||||
//
|
||||
@@ -24,7 +24,7 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
// Puffs requires a word size of at least 32 bits because it assumes that
|
||||
// Wuffs requires a word size of at least 32 bits because it assumes that
|
||||
// converting a u32 to usize will never overflow. For example, the size of a
|
||||
// decoded image is often represented, explicitly or implicitly in an image
|
||||
// file, as a u32, and it is convenient to compare that to a buffer size.
|
||||
@@ -32,12 +32,12 @@
|
||||
// Similarly, the word size is at most 64 bits because it assumes that
|
||||
// converting a usize to u64 will never overflow.
|
||||
#if __WORDSIZE < 32
|
||||
#error "Puffs requires a word size of at least 32 bits"
|
||||
#error "Wuffs requires a word size of at least 32 bits"
|
||||
#elif __WORDSIZE > 64
|
||||
#error "Puffs requires a word size of at most 64 bits"
|
||||
#error "Wuffs requires a word size of at most 64 bits"
|
||||
#endif
|
||||
|
||||
// PUFFS_VERSION is the major.minor version number as a uint32. The major
|
||||
// WUFFS_VERSION is the major.minor version number as a uint32. The major
|
||||
// number is the high 16 bits. The minor number is the low 16 bits.
|
||||
//
|
||||
// The intention is to bump the version number at least on every API / ABI
|
||||
@@ -46,17 +46,17 @@
|
||||
// For now, the API and ABI are simply unstable and can change at any time.
|
||||
//
|
||||
// TODO: don't hard code this in base-header.h.
|
||||
#define PUFFS_VERSION (0x00001)
|
||||
#define WUFFS_VERSION (0x00001)
|
||||
|
||||
// puffs_base__slice_u8 is a 1-dimensional buffer (a pointer and length).
|
||||
// wuffs_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;
|
||||
} wuffs_base__slice_u8;
|
||||
|
||||
// puffs_base__buf1 is a 1-dimensional buffer (a pointer and length), plus
|
||||
// wuffs_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,46 +66,46 @@ 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;
|
||||
} wuffs_base__buf1;
|
||||
|
||||
// puffs_base__limit1 provides a limited view of a 1-dimensional byte stream:
|
||||
// wuffs_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 {
|
||||
typedef struct wuffs_base__limit1 {
|
||||
uint64_t* ptr_to_len; // Pointer to N.
|
||||
struct puffs_base__limit1* next; // Linked list of limits.
|
||||
} puffs_base__limit1;
|
||||
struct wuffs_base__limit1* next; // Linked list of limits.
|
||||
} wuffs_base__limit1;
|
||||
|
||||
typedef struct {
|
||||
// TODO: move buf into private_impl? As it is, it looks like users can modify
|
||||
// the buf field to point to a different buffer, which can turn the limit and
|
||||
// mark fields into dangling pointers.
|
||||
puffs_base__buf1* buf;
|
||||
wuffs_base__buf1* buf;
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
// compatibility or safety guarantee if you do so.
|
||||
struct {
|
||||
puffs_base__limit1 limit;
|
||||
wuffs_base__limit1 limit;
|
||||
uint8_t* mark;
|
||||
} private_impl;
|
||||
} puffs_base__reader1;
|
||||
} wuffs_base__reader1;
|
||||
|
||||
typedef struct {
|
||||
// TODO: move buf into private_impl? As it is, it looks like users can modify
|
||||
// the buf field to point to a different buffer, which can turn the limit and
|
||||
// mark fields into dangling pointers.
|
||||
puffs_base__buf1* buf;
|
||||
wuffs_base__buf1* buf;
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
// compatibility or safety guarantee if you do so.
|
||||
struct {
|
||||
puffs_base__limit1 limit;
|
||||
wuffs_base__limit1 limit;
|
||||
uint8_t* mark;
|
||||
} private_impl;
|
||||
} puffs_base__writer1;
|
||||
} wuffs_base__writer1;
|
||||
|
||||
#endif // PUFFS_BASE_HEADER_H
|
||||
#endif // WUFFS_BASE_HEADER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -120,36 +120,36 @@ extern "C" {
|
||||
// - bits 0-7 are a package-namespaced numeric code
|
||||
//
|
||||
// Do not manipulate these bits directly. Use the API functions such as
|
||||
// puffs_gif__status__is_error instead.
|
||||
typedef int32_t puffs_gif__status;
|
||||
// wuffs_gif__status__is_error instead.
|
||||
typedef int32_t wuffs_gif__status;
|
||||
|
||||
#define puffs_gif__packageid 1017222 // 0x000f8586
|
||||
#define wuffs_gif__packageid 1017222 // 0x000f8586
|
||||
|
||||
#define PUFFS_GIF__STATUS_OK 0 // 0x00000000
|
||||
#define PUFFS_GIF__ERROR_BAD_PUFFS_VERSION -2147483647 // 0x80000001
|
||||
#define PUFFS_GIF__ERROR_BAD_RECEIVER -2147483646 // 0x80000002
|
||||
#define PUFFS_GIF__ERROR_BAD_ARGUMENT -2147483645 // 0x80000003
|
||||
#define PUFFS_GIF__ERROR_INITIALIZER_NOT_CALLED -2147483644 // 0x80000004
|
||||
#define PUFFS_GIF__ERROR_INVALID_I_O_OPERATION -2147483643 // 0x80000005
|
||||
#define PUFFS_GIF__ERROR_CLOSED_FOR_WRITES -2147483642 // 0x80000006
|
||||
#define PUFFS_GIF__ERROR_UNEXPECTED_EOF -2147483641 // 0x80000007
|
||||
#define PUFFS_GIF__SUSPENSION_SHORT_READ 8 // 0x00000008
|
||||
#define PUFFS_GIF__SUSPENSION_SHORT_WRITE 9 // 0x00000009
|
||||
#define WUFFS_GIF__STATUS_OK 0 // 0x00000000
|
||||
#define WUFFS_GIF__ERROR_BAD_WUFFS_VERSION -2147483647 // 0x80000001
|
||||
#define WUFFS_GIF__ERROR_BAD_RECEIVER -2147483646 // 0x80000002
|
||||
#define WUFFS_GIF__ERROR_BAD_ARGUMENT -2147483645 // 0x80000003
|
||||
#define WUFFS_GIF__ERROR_INITIALIZER_NOT_CALLED -2147483644 // 0x80000004
|
||||
#define WUFFS_GIF__ERROR_INVALID_I_O_OPERATION -2147483643 // 0x80000005
|
||||
#define WUFFS_GIF__ERROR_CLOSED_FOR_WRITES -2147483642 // 0x80000006
|
||||
#define WUFFS_GIF__ERROR_UNEXPECTED_EOF -2147483641 // 0x80000007
|
||||
#define WUFFS_GIF__SUSPENSION_SHORT_READ 8 // 0x00000008
|
||||
#define WUFFS_GIF__SUSPENSION_SHORT_WRITE 9 // 0x00000009
|
||||
|
||||
#define PUFFS_GIF__ERROR_BAD_GIF_BLOCK -1105848320 // 0xbe161800
|
||||
#define PUFFS_GIF__ERROR_BAD_GIF_EXTENSION_LABEL -1105848319 // 0xbe161801
|
||||
#define PUFFS_GIF__ERROR_BAD_GIF_HEADER -1105848318 // 0xbe161802
|
||||
#define PUFFS_GIF__ERROR_BAD_LZW_LITERAL_WIDTH -1105848317 // 0xbe161803
|
||||
#define PUFFS_GIF__ERROR_INTERNAL_ERROR_INCONSISTENT_LIMITED_READ \
|
||||
#define WUFFS_GIF__ERROR_BAD_GIF_BLOCK -1105848320 // 0xbe161800
|
||||
#define WUFFS_GIF__ERROR_BAD_GIF_EXTENSION_LABEL -1105848319 // 0xbe161801
|
||||
#define WUFFS_GIF__ERROR_BAD_GIF_HEADER -1105848318 // 0xbe161802
|
||||
#define WUFFS_GIF__ERROR_BAD_LZW_LITERAL_WIDTH -1105848317 // 0xbe161803
|
||||
#define WUFFS_GIF__ERROR_INTERNAL_ERROR_INCONSISTENT_LIMITED_READ \
|
||||
-1105848316 // 0xbe161804
|
||||
#define PUFFS_GIF__ERROR_TODO_UNSUPPORTED_LOCAL_COLOR_TABLE \
|
||||
#define WUFFS_GIF__ERROR_TODO_UNSUPPORTED_LOCAL_COLOR_TABLE \
|
||||
-1105848315 // 0xbe161805
|
||||
#define PUFFS_GIF__ERROR_LZW_CODE_IS_OUT_OF_RANGE -1105848314 // 0xbe161806
|
||||
#define PUFFS_GIF__ERROR_LZW_PREFIX_CHAIN_IS_CYCLICAL -1105848313 // 0xbe161807
|
||||
#define WUFFS_GIF__ERROR_LZW_CODE_IS_OUT_OF_RANGE -1105848314 // 0xbe161806
|
||||
#define WUFFS_GIF__ERROR_LZW_PREFIX_CHAIN_IS_CYCLICAL -1105848313 // 0xbe161807
|
||||
|
||||
bool puffs_gif__status__is_error(puffs_gif__status s);
|
||||
bool wuffs_gif__status__is_error(wuffs_gif__status s);
|
||||
|
||||
const char* puffs_gif__status__string(puffs_gif__status s);
|
||||
const char* wuffs_gif__status__string(wuffs_gif__status s);
|
||||
|
||||
// ---------------- Public Consts
|
||||
|
||||
@@ -158,13 +158,13 @@ const char* puffs_gif__status__string(puffs_gif__status s);
|
||||
typedef struct {
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
// compatibility or safety guarantee if you do so. Instead, use the
|
||||
// puffs_gif__lzw_decoder__etc functions.
|
||||
// wuffs_gif__lzw_decoder__etc functions.
|
||||
//
|
||||
// In C++, these fields would be "private", but C does not support that.
|
||||
//
|
||||
// It is a struct, not a struct*, so that it can be stack allocated.
|
||||
struct {
|
||||
puffs_gif__status status;
|
||||
wuffs_gif__status status;
|
||||
uint32_t magic;
|
||||
|
||||
uint32_t f_literal_width;
|
||||
@@ -187,25 +187,25 @@ typedef struct {
|
||||
uint64_t v_n_copied;
|
||||
} c_decode[1];
|
||||
} private_impl;
|
||||
} puffs_gif__lzw_decoder;
|
||||
} wuffs_gif__lzw_decoder;
|
||||
|
||||
typedef struct {
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
// compatibility or safety guarantee if you do so. Instead, use the
|
||||
// puffs_gif__decoder__etc functions.
|
||||
// wuffs_gif__decoder__etc functions.
|
||||
//
|
||||
// In C++, these fields would be "private", but C does not support that.
|
||||
//
|
||||
// It is a struct, not a struct*, so that it can be stack allocated.
|
||||
struct {
|
||||
puffs_gif__status status;
|
||||
wuffs_gif__status status;
|
||||
uint32_t magic;
|
||||
|
||||
uint32_t f_width;
|
||||
uint32_t f_height;
|
||||
uint8_t f_background_color_index;
|
||||
uint8_t f_gct[768];
|
||||
puffs_gif__lzw_decoder f_lzw;
|
||||
wuffs_gif__lzw_decoder f_lzw;
|
||||
|
||||
struct {
|
||||
uint32_t coro_susp_point;
|
||||
@@ -235,54 +235,54 @@ typedef struct {
|
||||
bool v_interlace;
|
||||
uint8_t v_lw;
|
||||
uint64_t v_block_size;
|
||||
puffs_gif__status v_z;
|
||||
wuffs_gif__status v_z;
|
||||
} c_decode_id[1];
|
||||
} private_impl;
|
||||
} puffs_gif__decoder;
|
||||
} wuffs_gif__decoder;
|
||||
|
||||
// ---------------- Public Initializer Prototypes
|
||||
|
||||
// puffs_gif__lzw_decoder__initialize is an initializer function.
|
||||
// wuffs_gif__lzw_decoder__initialize is an initializer function.
|
||||
//
|
||||
// It should be called before any other puffs_gif__lzw_decoder__* function.
|
||||
// It should be called before any other wuffs_gif__lzw_decoder__* function.
|
||||
//
|
||||
// Pass PUFFS_VERSION and 0 for puffs_version and for_internal_use_only.
|
||||
void puffs_gif__lzw_decoder__initialize(puffs_gif__lzw_decoder* self,
|
||||
uint32_t puffs_version,
|
||||
// Pass WUFFS_VERSION and 0 for wuffs_version and for_internal_use_only.
|
||||
void wuffs_gif__lzw_decoder__initialize(wuffs_gif__lzw_decoder* self,
|
||||
uint32_t wuffs_version,
|
||||
uint32_t for_internal_use_only);
|
||||
|
||||
// puffs_gif__decoder__initialize is an initializer function.
|
||||
// wuffs_gif__decoder__initialize is an initializer function.
|
||||
//
|
||||
// It should be called before any other puffs_gif__decoder__* function.
|
||||
// It should be called before any other wuffs_gif__decoder__* function.
|
||||
//
|
||||
// Pass PUFFS_VERSION and 0 for puffs_version and for_internal_use_only.
|
||||
void puffs_gif__decoder__initialize(puffs_gif__decoder* self,
|
||||
uint32_t puffs_version,
|
||||
// Pass WUFFS_VERSION and 0 for wuffs_version and for_internal_use_only.
|
||||
void wuffs_gif__decoder__initialize(wuffs_gif__decoder* self,
|
||||
uint32_t wuffs_version,
|
||||
uint32_t for_internal_use_only);
|
||||
|
||||
// ---------------- Public Function Prototypes
|
||||
|
||||
puffs_gif__status puffs_gif__decoder__decode(puffs_gif__decoder* self,
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src);
|
||||
wuffs_gif__status wuffs_gif__decoder__decode(wuffs_gif__decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src);
|
||||
|
||||
void puffs_gif__lzw_decoder__set_literal_width(puffs_gif__lzw_decoder* self,
|
||||
void wuffs_gif__lzw_decoder__set_literal_width(wuffs_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);
|
||||
wuffs_gif__status wuffs_gif__lzw_decoder__decode(wuffs_gif__lzw_decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // PUFFS_GIF_H
|
||||
#endif // WUFFS_GIF_H
|
||||
|
||||
// C HEADER ENDS HERE.
|
||||
|
||||
#ifndef PUFFS_BASE_IMPL_H
|
||||
#define PUFFS_BASE_IMPL_H
|
||||
#ifndef WUFFS_BASE_IMPL_H
|
||||
#define WUFFS_BASE_IMPL_H
|
||||
|
||||
// Copyright 2017 The Wuffs Authors.
|
||||
//
|
||||
@@ -298,39 +298,39 @@ 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.
|
||||
|
||||
// puffs_base__empty_struct is used when a Puffs function returns an empty
|
||||
// wuffs_base__empty_struct is used when a Wuffs function returns an empty
|
||||
// struct. In C, if a function f returns void, you can't say "x = f()", but in
|
||||
// Puffs, if a function g returns empty, you can say "y = g()".
|
||||
// Wuffs, if a function g returns empty, you can say "y = g()".
|
||||
typedef struct {
|
||||
} puffs_base__empty_struct;
|
||||
} wuffs_base__empty_struct;
|
||||
|
||||
#define PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(x) (void)(x)
|
||||
#define WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(x) (void)(x)
|
||||
|
||||
// PUFFS_BASE__MAGIC is a magic number to check that initializers are called.
|
||||
// WUFFS_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_BASE__MAGIC (0xCB3699CCU)
|
||||
#define WUFFS_BASE__MAGIC (0xCB3699CCU)
|
||||
|
||||
// PUFFS_BASE__ALREADY_ZEROED is passed from a container struct's initializer
|
||||
// WUFFS_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_BASE__ALREADY_ZEROED (0x68602EF1U)
|
||||
#define WUFFS_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 trivial macros instead of an explicit assignment and case statement
|
||||
// so that clang-format doesn't get confused by the unusual "case"s.
|
||||
#define PUFFS_BASE__COROUTINE_SUSPENSION_POINT_0 case 0:;
|
||||
#define PUFFS_BASE__COROUTINE_SUSPENSION_POINT(n) \
|
||||
#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0 case 0:;
|
||||
#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT(n) \
|
||||
coro_susp_point = n; \
|
||||
case n:;
|
||||
|
||||
#define PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \
|
||||
#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \
|
||||
if (status < 0) { \
|
||||
goto exit; \
|
||||
} else if (status == 0) { \
|
||||
@@ -342,11 +342,11 @@ typedef struct {
|
||||
|
||||
// Clang also defines "__GNUC__".
|
||||
#if defined(__GNUC__)
|
||||
#define PUFFS_BASE__LIKELY(expr) (__builtin_expect(!!(expr), 1))
|
||||
#define PUFFS_BASE__UNLIKELY(expr) (__builtin_expect(!!(expr), 0))
|
||||
#define WUFFS_BASE__LIKELY(expr) (__builtin_expect(!!(expr), 1))
|
||||
#define WUFFS_BASE__UNLIKELY(expr) (__builtin_expect(!!(expr), 0))
|
||||
#else
|
||||
#define PUFFS_BASE__LIKELY(expr) (expr)
|
||||
#define PUFFS_BASE__UNLIKELY(expr) (expr)
|
||||
#define WUFFS_BASE__LIKELY(expr) (expr)
|
||||
#define WUFFS_BASE__UNLIKELY(expr) (expr)
|
||||
#endif
|
||||
|
||||
// Uncomment this #include for printf-debugging.
|
||||
@@ -363,68 +363,68 @@ typedef struct {
|
||||
// "gif.c", without having to additionally include or otherwise build and link
|
||||
// a "base.c" file.
|
||||
//
|
||||
// They are static, so that linking multiple puffs .o files won't complain about
|
||||
// They are static, so that linking multiple wuffs .o files won't complain about
|
||||
// duplicate function definitions.
|
||||
//
|
||||
// They are explicitly marked inline, even if modern compilers don't use the
|
||||
// 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 wuffs_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 wuffs_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 wuffs_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 wuffs_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 wuffs_base__slice_u8 wuffs_base__slice_u8__subslice_i(
|
||||
wuffs_base__slice_u8 s,
|
||||
uint64_t i) {
|
||||
if ((i <= SIZE_MAX) && (i <= s.len)) {
|
||||
return ((puffs_base__slice_u8){
|
||||
return ((wuffs_base__slice_u8){
|
||||
.ptr = s.ptr + i,
|
||||
.len = s.len - i,
|
||||
});
|
||||
}
|
||||
return ((puffs_base__slice_u8){});
|
||||
return ((wuffs_base__slice_u8){});
|
||||
}
|
||||
|
||||
static inline puffs_base__slice_u8 puffs_base__slice_u8__subslice_j(
|
||||
puffs_base__slice_u8 s,
|
||||
static inline wuffs_base__slice_u8 wuffs_base__slice_u8__subslice_j(
|
||||
wuffs_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 ((wuffs_base__slice_u8){.ptr = s.ptr, .len = j});
|
||||
}
|
||||
return ((puffs_base__slice_u8){});
|
||||
return ((wuffs_base__slice_u8){});
|
||||
}
|
||||
|
||||
static inline puffs_base__slice_u8 puffs_base__slice_u8__subslice_ij(
|
||||
puffs_base__slice_u8 s,
|
||||
static inline wuffs_base__slice_u8 wuffs_base__slice_u8__subslice_ij(
|
||||
wuffs_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 ((wuffs_base__slice_u8){
|
||||
.ptr = s.ptr + i,
|
||||
.len = j - i,
|
||||
});
|
||||
}
|
||||
return ((puffs_base__slice_u8){});
|
||||
return ((wuffs_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,
|
||||
// wuffs_base__slice_u8__prefix returns up to the first up_to bytes of s.
|
||||
static inline wuffs_base__slice_u8 wuffs_base__slice_u8__prefix(
|
||||
wuffs_base__slice_u8 s,
|
||||
uint64_t up_to) {
|
||||
if ((uint64_t)(s.len) > up_to) {
|
||||
s.len = up_to;
|
||||
@@ -432,9 +432,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,
|
||||
// wuffs_base__slice_u8__suffix returns up to the last up_to bytes of s.
|
||||
static inline wuffs_base__slice_u8 wuffs_base__slice_u8_suffix(
|
||||
wuffs_base__slice_u8 s,
|
||||
uint64_t up_to) {
|
||||
if ((uint64_t)(s.len) > up_to) {
|
||||
s.ptr += (uint64_t)(s.len) - up_to;
|
||||
@@ -443,14 +443,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,
|
||||
// wuffs_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 wuffs_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 wuffs_base__slice_u8__copy_from_slice(
|
||||
wuffs_base__slice_u8 dst,
|
||||
wuffs_base__slice_u8 src) {
|
||||
size_t length = dst.len < src.len ? dst.len : src.len;
|
||||
if (length > 0) {
|
||||
memmove(dst.ptr, src.ptr, length);
|
||||
@@ -458,7 +458,7 @@ static inline uint64_t puffs_base__slice_u8__copy_from_slice(
|
||||
return length;
|
||||
}
|
||||
|
||||
static inline uint32_t puffs_base__writer1__copy_from_history32(
|
||||
static inline uint32_t wuffs_base__writer1__copy_from_history32(
|
||||
uint8_t** ptr_ptr,
|
||||
uint8_t* start, // May be NULL, meaning an unmarked writer1.
|
||||
uint8_t* end,
|
||||
@@ -481,10 +481,10 @@ static inline uint32_t puffs_base__writer1__copy_from_history32(
|
||||
// TODO: unrolling by 3 seems best for the std/flate benchmarks, but that is
|
||||
// mostly because 3 is the minimum length for the flate format. This function
|
||||
// implementation shouldn't overfit to that one format. Perhaps the
|
||||
// copy_from_history32 Puffs method should also take an unroll hint argument,
|
||||
// copy_from_history32 Wuffs method should also take an unroll hint argument,
|
||||
// and the cgen can look if that argument is the constant expression '3'.
|
||||
//
|
||||
// See also puffs_base__writer1__copy_from_history32__bco below.
|
||||
// See also wuffs_base__writer1__copy_from_history32__bco below.
|
||||
//
|
||||
// Alternatively, or additionally, have a sloppy_copy_from_history32 method
|
||||
// that copies 8 bytes at a time, possibly writing more than length bytes?
|
||||
@@ -500,14 +500,14 @@ static inline uint32_t puffs_base__writer1__copy_from_history32(
|
||||
return length;
|
||||
}
|
||||
|
||||
// puffs_base__writer1__copy_from_history32__bco is a Bounds Check Optimized
|
||||
// version of the puffs_base__writer1__copy_from_history32 function above. The
|
||||
// wuffs_base__writer1__copy_from_history32__bco is a Bounds Check Optimized
|
||||
// version of the wuffs_base__writer1__copy_from_history32 function above. The
|
||||
// caller needs to prove that:
|
||||
// - start != NULL
|
||||
// - distance != 0
|
||||
// - distance <= (*ptr_ptr - start)
|
||||
// - length <= (end - *ptr_ptr)
|
||||
static inline uint32_t puffs_base__writer1__copy_from_history32__bco(
|
||||
static inline uint32_t wuffs_base__writer1__copy_from_history32__bco(
|
||||
uint8_t** ptr_ptr,
|
||||
uint8_t* start,
|
||||
uint8_t* end,
|
||||
@@ -528,7 +528,7 @@ static inline uint32_t puffs_base__writer1__copy_from_history32__bco(
|
||||
return length;
|
||||
}
|
||||
|
||||
static inline uint32_t puffs_base__writer1__copy_from_reader32(
|
||||
static inline uint32_t wuffs_base__writer1__copy_from_reader32(
|
||||
uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
uint8_t** ptr_rptr,
|
||||
@@ -551,10 +551,10 @@ static inline uint32_t puffs_base__writer1__copy_from_reader32(
|
||||
return n;
|
||||
}
|
||||
|
||||
static inline uint64_t puffs_base__writer1__copy_from_slice(
|
||||
static inline uint64_t wuffs_base__writer1__copy_from_slice(
|
||||
uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
puffs_base__slice_u8 src) {
|
||||
wuffs_base__slice_u8 src) {
|
||||
uint8_t* wptr = *ptr_wptr;
|
||||
size_t n = src.len;
|
||||
if (n > wend - wptr) {
|
||||
@@ -567,10 +567,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 wuffs_base__writer1__copy_from_slice32(
|
||||
uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
puffs_base__slice_u8 src,
|
||||
wuffs_base__slice_u8 src,
|
||||
uint32_t length) {
|
||||
uint8_t* wptr = *ptr_wptr;
|
||||
size_t n = src.len;
|
||||
@@ -589,52 +589,52 @@ static inline uint32_t puffs_base__writer1__copy_from_slice32(
|
||||
|
||||
// Note that the *__limit and *__mark methods are private (in base-impl.h) not
|
||||
// public (in base-header.h). We assume that, at the boundary between user code
|
||||
// and Puffs code, the reader1 and writer1's private_impl fields (including
|
||||
// and Wuffs code, the reader1 and writer1's private_impl fields (including
|
||||
// limit and mark) are NULL. Otherwise, some internal assumptions break down.
|
||||
// For example, limits could be represented as pointers, even though
|
||||
// conceptually they are counts, but that pointer-to-count correspondence
|
||||
// becomes invalid if a buffer is re-used (e.g. on resuming a coroutine).
|
||||
//
|
||||
// Admittedly, some of the Puffs test code calls these methods, but that test
|
||||
// code is still Puffs code, not user code. Other Puffs test code modifies
|
||||
// Admittedly, some of the Wuffs test code calls these methods, but that test
|
||||
// code is still Wuffs code, not user code. Other Wuffs test code modifies
|
||||
// private_impl fields directly.
|
||||
|
||||
static inline puffs_base__reader1 puffs_base__reader1__limit(
|
||||
puffs_base__reader1* o,
|
||||
static inline wuffs_base__reader1 wuffs_base__reader1__limit(
|
||||
wuffs_base__reader1* o,
|
||||
uint64_t* ptr_to_len) {
|
||||
puffs_base__reader1 ret = *o;
|
||||
wuffs_base__reader1 ret = *o;
|
||||
ret.private_impl.limit.ptr_to_len = ptr_to_len;
|
||||
ret.private_impl.limit.next = &o->private_impl.limit;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline puffs_base__empty_struct puffs_base__reader1__mark(
|
||||
puffs_base__reader1* o,
|
||||
static inline wuffs_base__empty_struct wuffs_base__reader1__mark(
|
||||
wuffs_base__reader1* o,
|
||||
uint8_t* mark) {
|
||||
o->private_impl.mark = mark;
|
||||
return ((puffs_base__empty_struct){});
|
||||
return ((wuffs_base__empty_struct){});
|
||||
}
|
||||
|
||||
// TODO: static inline puffs_base__writer1 puffs_base__writer1__limit()
|
||||
// TODO: static inline wuffs_base__writer1 wuffs_base__writer1__limit()
|
||||
|
||||
static inline puffs_base__empty_struct puffs_base__writer1__mark(
|
||||
puffs_base__writer1* o,
|
||||
static inline wuffs_base__empty_struct wuffs_base__writer1__mark(
|
||||
wuffs_base__writer1* o,
|
||||
uint8_t* mark) {
|
||||
o->private_impl.mark = mark;
|
||||
return ((puffs_base__empty_struct){});
|
||||
return ((wuffs_base__empty_struct){});
|
||||
}
|
||||
|
||||
#endif // PUFFS_BASE_IMPL_H
|
||||
#endif // WUFFS_BASE_IMPL_H
|
||||
|
||||
// ---------------- Status Codes Implementations
|
||||
|
||||
bool puffs_gif__status__is_error(puffs_gif__status s) {
|
||||
bool wuffs_gif__status__is_error(wuffs_gif__status s) {
|
||||
return s < 0;
|
||||
}
|
||||
|
||||
const char* puffs_gif__status__strings0[10] = {
|
||||
const char* wuffs_gif__status__strings0[10] = {
|
||||
"gif: ok",
|
||||
"gif: bad puffs version",
|
||||
"gif: bad wuffs version",
|
||||
"gif: bad receiver",
|
||||
"gif: bad argument",
|
||||
"gif: initializer not called",
|
||||
@@ -645,7 +645,7 @@ const char* puffs_gif__status__strings0[10] = {
|
||||
"gif: short write",
|
||||
};
|
||||
|
||||
const char* puffs_gif__status__strings1[8] = {
|
||||
const char* wuffs_gif__status__strings1[8] = {
|
||||
"gif: bad GIF block",
|
||||
"gif: bad GIF extension label",
|
||||
"gif: bad GIF header",
|
||||
@@ -656,16 +656,16 @@ const char* puffs_gif__status__strings1[8] = {
|
||||
"gif: LZW prefix chain is cyclical",
|
||||
};
|
||||
|
||||
const char* puffs_gif__status__string(puffs_gif__status s) {
|
||||
const char* wuffs_gif__status__string(wuffs_gif__status s) {
|
||||
const char** a = NULL;
|
||||
uint32_t n = 0;
|
||||
switch ((s >> 10) & 0x1fffff) {
|
||||
case 0:
|
||||
a = puffs_gif__status__strings0;
|
||||
a = wuffs_gif__status__strings0;
|
||||
n = 10;
|
||||
break;
|
||||
case puffs_gif__packageid:
|
||||
a = puffs_gif__status__strings1;
|
||||
case wuffs_gif__packageid:
|
||||
a = wuffs_gif__status__strings1;
|
||||
n = 8;
|
||||
break;
|
||||
}
|
||||
@@ -679,75 +679,75 @@ const char* puffs_gif__status__string(puffs_gif__status s) {
|
||||
|
||||
// ---------------- Private Function Prototypes
|
||||
|
||||
static puffs_gif__status puffs_gif__decoder__decode_header(
|
||||
puffs_gif__decoder* self,
|
||||
puffs_base__reader1 a_src);
|
||||
static wuffs_gif__status wuffs_gif__decoder__decode_header(
|
||||
wuffs_gif__decoder* self,
|
||||
wuffs_base__reader1 a_src);
|
||||
|
||||
static puffs_gif__status puffs_gif__decoder__decode_lsd(
|
||||
puffs_gif__decoder* self,
|
||||
puffs_base__reader1 a_src);
|
||||
static wuffs_gif__status wuffs_gif__decoder__decode_lsd(
|
||||
wuffs_gif__decoder* self,
|
||||
wuffs_base__reader1 a_src);
|
||||
|
||||
static puffs_gif__status puffs_gif__decoder__decode_extension(
|
||||
puffs_gif__decoder* self,
|
||||
puffs_base__reader1 a_src);
|
||||
static wuffs_gif__status wuffs_gif__decoder__decode_extension(
|
||||
wuffs_gif__decoder* self,
|
||||
wuffs_base__reader1 a_src);
|
||||
|
||||
static puffs_gif__status puffs_gif__decoder__decode_id(
|
||||
puffs_gif__decoder* self,
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src);
|
||||
static wuffs_gif__status wuffs_gif__decoder__decode_id(
|
||||
wuffs_gif__decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src);
|
||||
|
||||
// ---------------- Initializer Implementations
|
||||
|
||||
void puffs_gif__lzw_decoder__initialize(puffs_gif__lzw_decoder* self,
|
||||
uint32_t puffs_version,
|
||||
void wuffs_gif__lzw_decoder__initialize(wuffs_gif__lzw_decoder* self,
|
||||
uint32_t wuffs_version,
|
||||
uint32_t for_internal_use_only) {
|
||||
if (!self) {
|
||||
return;
|
||||
}
|
||||
if (puffs_version != PUFFS_VERSION) {
|
||||
self->private_impl.status = PUFFS_GIF__ERROR_BAD_PUFFS_VERSION;
|
||||
if (wuffs_version != WUFFS_VERSION) {
|
||||
self->private_impl.status = WUFFS_GIF__ERROR_BAD_WUFFS_VERSION;
|
||||
return;
|
||||
}
|
||||
if (for_internal_use_only != PUFFS_BASE__ALREADY_ZEROED) {
|
||||
if (for_internal_use_only != WUFFS_BASE__ALREADY_ZEROED) {
|
||||
memset(self, 0, sizeof(*self));
|
||||
}
|
||||
self->private_impl.magic = PUFFS_BASE__MAGIC;
|
||||
self->private_impl.magic = WUFFS_BASE__MAGIC;
|
||||
self->private_impl.f_literal_width = 8;
|
||||
}
|
||||
|
||||
void puffs_gif__decoder__initialize(puffs_gif__decoder* self,
|
||||
uint32_t puffs_version,
|
||||
void wuffs_gif__decoder__initialize(wuffs_gif__decoder* self,
|
||||
uint32_t wuffs_version,
|
||||
uint32_t for_internal_use_only) {
|
||||
if (!self) {
|
||||
return;
|
||||
}
|
||||
if (puffs_version != PUFFS_VERSION) {
|
||||
self->private_impl.status = PUFFS_GIF__ERROR_BAD_PUFFS_VERSION;
|
||||
if (wuffs_version != WUFFS_VERSION) {
|
||||
self->private_impl.status = WUFFS_GIF__ERROR_BAD_WUFFS_VERSION;
|
||||
return;
|
||||
}
|
||||
if (for_internal_use_only != PUFFS_BASE__ALREADY_ZEROED) {
|
||||
if (for_internal_use_only != WUFFS_BASE__ALREADY_ZEROED) {
|
||||
memset(self, 0, sizeof(*self));
|
||||
}
|
||||
self->private_impl.magic = PUFFS_BASE__MAGIC;
|
||||
puffs_gif__lzw_decoder__initialize(&self->private_impl.f_lzw, PUFFS_VERSION,
|
||||
PUFFS_BASE__ALREADY_ZEROED);
|
||||
self->private_impl.magic = WUFFS_BASE__MAGIC;
|
||||
wuffs_gif__lzw_decoder__initialize(&self->private_impl.f_lzw, WUFFS_VERSION,
|
||||
WUFFS_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) {
|
||||
wuffs_gif__status wuffs_gif__decoder__decode(wuffs_gif__decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src) {
|
||||
if (!self) {
|
||||
return PUFFS_GIF__ERROR_BAD_RECEIVER;
|
||||
return WUFFS_GIF__ERROR_BAD_RECEIVER;
|
||||
}
|
||||
if (self->private_impl.magic != PUFFS_BASE__MAGIC) {
|
||||
self->private_impl.status = PUFFS_GIF__ERROR_INITIALIZER_NOT_CALLED;
|
||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
self->private_impl.status = WUFFS_GIF__ERROR_INITIALIZER_NOT_CALLED;
|
||||
}
|
||||
if (self->private_impl.status < 0) {
|
||||
return self->private_impl.status;
|
||||
}
|
||||
puffs_gif__status status = PUFFS_GIF__STATUS_OK;
|
||||
wuffs_gif__status status = WUFFS_GIF__STATUS_OK;
|
||||
|
||||
uint8_t v_c;
|
||||
|
||||
@@ -758,7 +758,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;
|
||||
uint64_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base__limit1* lim;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -772,38 +772,38 @@ 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_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
WUFFS_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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
}
|
||||
status = puffs_gif__decoder__decode_header(self, a_src);
|
||||
status = wuffs_gif__decoder__decode_header(self, a_src);
|
||||
if (a_src.buf) {
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
}
|
||||
if (status) {
|
||||
goto suspend;
|
||||
}
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
WUFFS_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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
}
|
||||
status = puffs_gif__decoder__decode_lsd(self, a_src);
|
||||
status = wuffs_gif__decoder__decode_lsd(self, a_src);
|
||||
if (a_src.buf) {
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
}
|
||||
@@ -812,26 +812,26 @@ puffs_gif__status puffs_gif__decoder__decode(puffs_gif__decoder* self,
|
||||
}
|
||||
while (true) {
|
||||
{
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
if (WUFFS_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_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
WUFFS_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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
}
|
||||
status = puffs_gif__decoder__decode_extension(self, a_src);
|
||||
status = wuffs_gif__decoder__decode_extension(self, a_src);
|
||||
if (a_src.buf) {
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
}
|
||||
@@ -839,18 +839,18 @@ puffs_gif__status puffs_gif__decoder__decode(puffs_gif__decoder* self,
|
||||
goto suspend;
|
||||
}
|
||||
} else if (v_c == 44) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
|
||||
WUFFS_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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
}
|
||||
status = puffs_gif__decoder__decode_id(self, a_dst, a_src);
|
||||
status = wuffs_gif__decoder__decode_id(self, a_dst, a_src);
|
||||
if (a_src.buf) {
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
}
|
||||
@@ -858,10 +858,10 @@ puffs_gif__status puffs_gif__decoder__decode(puffs_gif__decoder* self,
|
||||
goto suspend;
|
||||
}
|
||||
} else if (v_c == 59) {
|
||||
status = PUFFS_GIF__STATUS_OK;
|
||||
status = WUFFS_GIF__STATUS_OK;
|
||||
goto ok;
|
||||
} else {
|
||||
status = PUFFS_GIF__ERROR_BAD_GIF_BLOCK;
|
||||
status = WUFFS_GIF__ERROR_BAD_GIF_BLOCK;
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
@@ -881,14 +881,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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
}
|
||||
|
||||
self->private_impl.status = status;
|
||||
@@ -896,17 +896,17 @@ exit:
|
||||
|
||||
short_read_src:
|
||||
if (a_src.buf && a_src.buf->closed && !a_src.private_impl.limit.ptr_to_len) {
|
||||
status = PUFFS_GIF__ERROR_UNEXPECTED_EOF;
|
||||
status = WUFFS_GIF__ERROR_UNEXPECTED_EOF;
|
||||
goto exit;
|
||||
}
|
||||
status = PUFFS_GIF__SUSPENSION_SHORT_READ;
|
||||
status = WUFFS_GIF__SUSPENSION_SHORT_READ;
|
||||
goto suspend;
|
||||
}
|
||||
|
||||
static puffs_gif__status puffs_gif__decoder__decode_header(
|
||||
puffs_gif__decoder* self,
|
||||
puffs_base__reader1 a_src) {
|
||||
puffs_gif__status status = PUFFS_GIF__STATUS_OK;
|
||||
static wuffs_gif__status wuffs_gif__decoder__decode_header(
|
||||
wuffs_gif__decoder* self,
|
||||
wuffs_base__reader1 a_src) {
|
||||
wuffs_gif__status status = WUFFS_GIF__STATUS_OK;
|
||||
|
||||
uint8_t v_c[6];
|
||||
uint32_t v_i;
|
||||
@@ -918,7 +918,7 @@ static puffs_gif__status puffs_gif__decoder__decode_header(
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
b_rstart_src = b_rptr_src;
|
||||
uint64_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base__limit1* lim;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -934,14 +934,14 @@ static puffs_gif__status puffs_gif__decoder__decode_header(
|
||||
v_i = self->private_impl.c_decode_header[0].v_i;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
memset(v_c, 0, sizeof(v_c));
|
||||
v_i = 0;
|
||||
while (v_i < 6) {
|
||||
{
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (WUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_0 = *b_rptr_src++;
|
||||
@@ -951,7 +951,7 @@ static puffs_gif__status puffs_gif__decoder__decode_header(
|
||||
}
|
||||
if ((v_c[0] != 71) || (v_c[1] != 73) || (v_c[2] != 70) || (v_c[3] != 56) ||
|
||||
((v_c[4] != 55) && (v_c[4] != 57)) || (v_c[5] != 97)) {
|
||||
status = PUFFS_GIF__ERROR_BAD_GIF_HEADER;
|
||||
status = WUFFS_GIF__ERROR_BAD_GIF_HEADER;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@@ -971,31 +971,31 @@ 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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
short_read_src:
|
||||
if (a_src.buf && a_src.buf->closed && !a_src.private_impl.limit.ptr_to_len) {
|
||||
status = PUFFS_GIF__ERROR_UNEXPECTED_EOF;
|
||||
status = WUFFS_GIF__ERROR_UNEXPECTED_EOF;
|
||||
goto exit;
|
||||
}
|
||||
status = PUFFS_GIF__SUSPENSION_SHORT_READ;
|
||||
status = WUFFS_GIF__SUSPENSION_SHORT_READ;
|
||||
goto suspend;
|
||||
}
|
||||
|
||||
static puffs_gif__status puffs_gif__decoder__decode_lsd(
|
||||
puffs_gif__decoder* self,
|
||||
puffs_base__reader1 a_src) {
|
||||
puffs_gif__status status = PUFFS_GIF__STATUS_OK;
|
||||
static wuffs_gif__status wuffs_gif__decoder__decode_lsd(
|
||||
wuffs_gif__decoder* self,
|
||||
wuffs_base__reader1 a_src) {
|
||||
wuffs_gif__status status = WUFFS_GIF__STATUS_OK;
|
||||
|
||||
uint8_t v_c[7];
|
||||
uint32_t v_i;
|
||||
@@ -1008,7 +1008,7 @@ static puffs_gif__status puffs_gif__decoder__decode_lsd(
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
b_rstart_src = b_rptr_src;
|
||||
uint64_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base__limit1* lim;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -1024,14 +1024,14 @@ static puffs_gif__status puffs_gif__decoder__decode_lsd(
|
||||
v_gct_size = self->private_impl.c_decode_lsd[0].v_gct_size;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
memset(v_c, 0, sizeof(v_c));
|
||||
v_i = 0;
|
||||
while (v_i < 7) {
|
||||
{
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (WUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_0 = *b_rptr_src++;
|
||||
@@ -1049,24 +1049,24 @@ static puffs_gif__status puffs_gif__decoder__decode_lsd(
|
||||
v_i = 0;
|
||||
while (v_i < v_gct_size) {
|
||||
{
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (WUFFS_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_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
if (WUFFS_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_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
if (WUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_3 = *b_rptr_src++;
|
||||
@@ -1093,31 +1093,31 @@ 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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
short_read_src:
|
||||
if (a_src.buf && a_src.buf->closed && !a_src.private_impl.limit.ptr_to_len) {
|
||||
status = PUFFS_GIF__ERROR_UNEXPECTED_EOF;
|
||||
status = WUFFS_GIF__ERROR_UNEXPECTED_EOF;
|
||||
goto exit;
|
||||
}
|
||||
status = PUFFS_GIF__SUSPENSION_SHORT_READ;
|
||||
status = WUFFS_GIF__SUSPENSION_SHORT_READ;
|
||||
goto suspend;
|
||||
}
|
||||
|
||||
static puffs_gif__status puffs_gif__decoder__decode_extension(
|
||||
puffs_gif__decoder* self,
|
||||
puffs_base__reader1 a_src) {
|
||||
puffs_gif__status status = PUFFS_GIF__STATUS_OK;
|
||||
static wuffs_gif__status wuffs_gif__decoder__decode_extension(
|
||||
wuffs_gif__decoder* self,
|
||||
wuffs_base__reader1 a_src) {
|
||||
wuffs_gif__status status = WUFFS_GIF__STATUS_OK;
|
||||
|
||||
uint8_t v_label;
|
||||
uint8_t v_block_size;
|
||||
@@ -1129,7 +1129,7 @@ static 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;
|
||||
uint64_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base__limit1* lim;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -1145,11 +1145,11 @@ static 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_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
{
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (WUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_0 = *b_rptr_src++;
|
||||
@@ -1160,13 +1160,13 @@ static puffs_gif__status puffs_gif__decoder__decode_extension(
|
||||
} else if (v_label == 254) {
|
||||
} else if (v_label == 255) {
|
||||
} else {
|
||||
status = PUFFS_GIF__ERROR_BAD_GIF_EXTENSION_LABEL;
|
||||
status = WUFFS_GIF__ERROR_BAD_GIF_EXTENSION_LABEL;
|
||||
goto exit;
|
||||
}
|
||||
while (true) {
|
||||
{
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (WUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_1 = *b_rptr_src++;
|
||||
@@ -1175,10 +1175,10 @@ static puffs_gif__status puffs_gif__decoder__decode_extension(
|
||||
if (v_block_size == 0) {
|
||||
goto label_0_break;
|
||||
}
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
self->private_impl.c_decode_extension[0].scratch =
|
||||
((uint32_t)(v_block_size));
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
WUFFS_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 -=
|
||||
@@ -1206,40 +1206,40 @@ 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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
short_read_src:
|
||||
if (a_src.buf && a_src.buf->closed && !a_src.private_impl.limit.ptr_to_len) {
|
||||
status = PUFFS_GIF__ERROR_UNEXPECTED_EOF;
|
||||
status = WUFFS_GIF__ERROR_UNEXPECTED_EOF;
|
||||
goto exit;
|
||||
}
|
||||
status = PUFFS_GIF__SUSPENSION_SHORT_READ;
|
||||
status = WUFFS_GIF__SUSPENSION_SHORT_READ;
|
||||
goto suspend;
|
||||
}
|
||||
|
||||
static puffs_gif__status puffs_gif__decoder__decode_id(
|
||||
puffs_gif__decoder* self,
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src) {
|
||||
puffs_gif__status status = PUFFS_GIF__STATUS_OK;
|
||||
static wuffs_gif__status wuffs_gif__decoder__decode_id(
|
||||
wuffs_gif__decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src) {
|
||||
wuffs_gif__status status = WUFFS_GIF__STATUS_OK;
|
||||
|
||||
uint8_t v_c[9];
|
||||
uint32_t v_i;
|
||||
bool v_interlace;
|
||||
uint8_t v_lw;
|
||||
uint64_t v_block_size;
|
||||
puffs_base__reader1 v_r;
|
||||
puffs_gif__status v_z;
|
||||
wuffs_base__reader1 v_r;
|
||||
wuffs_gif__status v_z;
|
||||
|
||||
uint8_t* b_rptr_src = NULL;
|
||||
uint8_t* b_rstart_src = NULL;
|
||||
@@ -1248,7 +1248,7 @@ static puffs_gif__status puffs_gif__decoder__decode_id(
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
b_rstart_src = b_rptr_src;
|
||||
uint64_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base__limit1* lim;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -1264,18 +1264,18 @@ static puffs_gif__status puffs_gif__decoder__decode_id(
|
||||
v_interlace = self->private_impl.c_decode_id[0].v_interlace;
|
||||
v_lw = self->private_impl.c_decode_id[0].v_lw;
|
||||
v_block_size = self->private_impl.c_decode_id[0].v_block_size;
|
||||
v_r = ((puffs_base__reader1){});
|
||||
v_r = ((wuffs_base__reader1){});
|
||||
v_z = self->private_impl.c_decode_id[0].v_z;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
memset(v_c, 0, sizeof(v_c));
|
||||
v_i = 0;
|
||||
while (v_i < 9) {
|
||||
{
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (WUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_0 = *b_rptr_src++;
|
||||
@@ -1287,27 +1287,27 @@ static puffs_gif__status puffs_gif__decoder__decode_id(
|
||||
if (v_interlace) {
|
||||
}
|
||||
if ((v_c[8] & 128) != 0) {
|
||||
status = PUFFS_GIF__ERROR_TODO_UNSUPPORTED_LOCAL_COLOR_TABLE;
|
||||
status = WUFFS_GIF__ERROR_TODO_UNSUPPORTED_LOCAL_COLOR_TABLE;
|
||||
goto exit;
|
||||
}
|
||||
{
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (WUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_1 = *b_rptr_src++;
|
||||
v_lw = t_1;
|
||||
}
|
||||
if ((v_lw < 2) || (8 < v_lw)) {
|
||||
status = PUFFS_GIF__ERROR_BAD_LZW_LITERAL_WIDTH;
|
||||
status = WUFFS_GIF__ERROR_BAD_LZW_LITERAL_WIDTH;
|
||||
goto exit;
|
||||
}
|
||||
puffs_gif__lzw_decoder__set_literal_width(&self->private_impl.f_lzw,
|
||||
wuffs_gif__lzw_decoder__set_literal_width(&self->private_impl.f_lzw,
|
||||
((uint32_t)(v_lw)));
|
||||
while (true) {
|
||||
{
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
if (WUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_2 = *b_rptr_src++;
|
||||
@@ -1318,13 +1318,13 @@ static puffs_gif__status puffs_gif__decoder__decode_id(
|
||||
}
|
||||
while (true) {
|
||||
v_r = a_src;
|
||||
puffs_base__reader1__mark(&v_r, b_rptr_src);
|
||||
wuffs_base__reader1__mark(&v_r, b_rptr_src);
|
||||
{
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
|
||||
WUFFS_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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
@@ -1332,9 +1332,9 @@ static puffs_gif__status puffs_gif__decoder__decode_id(
|
||||
}
|
||||
}
|
||||
uint64_t l_rlimit0 = v_block_size;
|
||||
puffs_gif__status t_3 = puffs_gif__lzw_decoder__decode(
|
||||
wuffs_gif__status t_3 = wuffs_gif__lzw_decoder__decode(
|
||||
&self->private_impl.f_lzw, a_dst,
|
||||
puffs_base__reader1__limit(&v_r, &l_rlimit0));
|
||||
wuffs_base__reader1__limit(&v_r, &l_rlimit0));
|
||||
if (a_src.buf) {
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
}
|
||||
@@ -1345,29 +1345,29 @@ static puffs_gif__status puffs_gif__decoder__decode_id(
|
||||
}
|
||||
if (v_block_size <
|
||||
((uint64_t)(
|
||||
((puffs_base__slice_u8){
|
||||
((wuffs_base__slice_u8){
|
||||
.ptr = v_r.private_impl.mark,
|
||||
.len = v_r.private_impl.mark
|
||||
? (size_t)(b_rptr_src - v_r.private_impl.mark)
|
||||
: 0,
|
||||
})
|
||||
.len))) {
|
||||
status = PUFFS_GIF__ERROR_INTERNAL_ERROR_INCONSISTENT_LIMITED_READ;
|
||||
status = WUFFS_GIF__ERROR_INTERNAL_ERROR_INCONSISTENT_LIMITED_READ;
|
||||
goto exit;
|
||||
}
|
||||
v_block_size -= ((uint64_t)(
|
||||
((puffs_base__slice_u8){
|
||||
((wuffs_base__slice_u8){
|
||||
.ptr = v_r.private_impl.mark,
|
||||
.len = v_r.private_impl.mark
|
||||
? (size_t)(b_rptr_src - v_r.private_impl.mark)
|
||||
: 0,
|
||||
})
|
||||
.len));
|
||||
if ((v_block_size == 0) && (v_z == PUFFS_GIF__SUSPENSION_SHORT_READ)) {
|
||||
if ((v_block_size == 0) && (v_z == WUFFS_GIF__SUSPENSION_SHORT_READ)) {
|
||||
goto label_1_break;
|
||||
}
|
||||
status = v_z;
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(5);
|
||||
}
|
||||
label_1_break:;
|
||||
}
|
||||
@@ -1393,59 +1393,59 @@ 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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
short_read_src:
|
||||
if (a_src.buf && a_src.buf->closed && !a_src.private_impl.limit.ptr_to_len) {
|
||||
status = PUFFS_GIF__ERROR_UNEXPECTED_EOF;
|
||||
status = WUFFS_GIF__ERROR_UNEXPECTED_EOF;
|
||||
goto exit;
|
||||
}
|
||||
status = PUFFS_GIF__SUSPENSION_SHORT_READ;
|
||||
status = WUFFS_GIF__SUSPENSION_SHORT_READ;
|
||||
goto suspend;
|
||||
}
|
||||
|
||||
void puffs_gif__lzw_decoder__set_literal_width(puffs_gif__lzw_decoder* self,
|
||||
void wuffs_gif__lzw_decoder__set_literal_width(wuffs_gif__lzw_decoder* self,
|
||||
uint32_t a_lw) {
|
||||
if (!self) {
|
||||
return;
|
||||
}
|
||||
if (self->private_impl.magic != PUFFS_BASE__MAGIC) {
|
||||
self->private_impl.status = PUFFS_GIF__ERROR_INITIALIZER_NOT_CALLED;
|
||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
self->private_impl.status = WUFFS_GIF__ERROR_INITIALIZER_NOT_CALLED;
|
||||
}
|
||||
if (self->private_impl.status < 0) {
|
||||
return;
|
||||
}
|
||||
if (a_lw < 2 || a_lw > 8) {
|
||||
self->private_impl.status = PUFFS_GIF__ERROR_BAD_ARGUMENT;
|
||||
self->private_impl.status = WUFFS_GIF__ERROR_BAD_ARGUMENT;
|
||||
return;
|
||||
}
|
||||
|
||||
self->private_impl.f_literal_width = 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) {
|
||||
wuffs_gif__status wuffs_gif__lzw_decoder__decode(wuffs_gif__lzw_decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src) {
|
||||
if (!self) {
|
||||
return PUFFS_GIF__ERROR_BAD_RECEIVER;
|
||||
return WUFFS_GIF__ERROR_BAD_RECEIVER;
|
||||
}
|
||||
if (self->private_impl.magic != PUFFS_BASE__MAGIC) {
|
||||
self->private_impl.status = PUFFS_GIF__ERROR_INITIALIZER_NOT_CALLED;
|
||||
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
self->private_impl.status = WUFFS_GIF__ERROR_INITIALIZER_NOT_CALLED;
|
||||
}
|
||||
if (self->private_impl.status < 0) {
|
||||
return self->private_impl.status;
|
||||
}
|
||||
puffs_gif__status status = PUFFS_GIF__STATUS_OK;
|
||||
wuffs_gif__status status = WUFFS_GIF__STATUS_OK;
|
||||
|
||||
uint32_t v_clear_code;
|
||||
uint32_t v_end_code;
|
||||
@@ -1457,7 +1457,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;
|
||||
wuffs_base__slice_u8 v_expansion;
|
||||
uint64_t v_n_copied;
|
||||
|
||||
uint8_t* b_wptr_dst = NULL;
|
||||
@@ -1469,7 +1469,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) {
|
||||
uint64_t len = a_dst.buf->len - a_dst.buf->wi;
|
||||
puffs_base__limit1* lim;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_dst.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -1485,7 +1485,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;
|
||||
uint64_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
puffs_base__limit1* lim;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -1506,11 +1506,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 = ((wuffs_base__slice_u8){});
|
||||
v_n_copied = self->private_impl.c_decode[0].v_n_copied;
|
||||
}
|
||||
switch (coro_susp_point) {
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
v_clear_code = (((uint32_t)(1)) << self->private_impl.f_literal_width);
|
||||
v_end_code = (v_clear_code + 1);
|
||||
@@ -1523,8 +1523,8 @@ puffs_gif__status puffs_gif__lzw_decoder__decode(puffs_gif__lzw_decoder* self,
|
||||
while (true) {
|
||||
while (v_n_bits < v_width) {
|
||||
{
|
||||
PUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (PUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
|
||||
if (WUFFS_BASE__UNLIKELY(b_rptr_src == b_rend_src)) {
|
||||
goto short_read_src;
|
||||
}
|
||||
uint8_t t_0 = *b_rptr_src++;
|
||||
@@ -1536,9 +1536,9 @@ 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_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
|
||||
if (b_wptr_dst == b_wend_dst) {
|
||||
status = PUFFS_GIF__SUSPENSION_SHORT_WRITE;
|
||||
status = WUFFS_GIF__SUSPENSION_SHORT_WRITE;
|
||||
goto suspend;
|
||||
}
|
||||
*b_wptr_dst++ = ((uint8_t)(v_code));
|
||||
@@ -1553,7 +1553,7 @@ puffs_gif__status puffs_gif__lzw_decoder__decode(puffs_gif__lzw_decoder* self,
|
||||
v_width = (self->private_impl.f_literal_width + 1);
|
||||
goto label_0_continue;
|
||||
} else if (v_code == v_end_code) {
|
||||
status = PUFFS_GIF__STATUS_OK;
|
||||
status = WUFFS_GIF__STATUS_OK;
|
||||
goto ok;
|
||||
} else if (v_code <= v_save_code) {
|
||||
v_s = 4095;
|
||||
@@ -1565,7 +1565,7 @@ puffs_gif__status puffs_gif__lzw_decoder__decode(puffs_gif__lzw_decoder* self,
|
||||
while (v_c >= v_clear_code) {
|
||||
self->private_impl.f_stack[v_s] = self->private_impl.f_suffixes[v_c];
|
||||
if (v_s == 0) {
|
||||
status = PUFFS_GIF__ERROR_LZW_PREFIX_CHAIN_IS_CYCLICAL;
|
||||
status = WUFFS_GIF__ERROR_LZW_PREFIX_CHAIN_IS_CYCLICAL;
|
||||
goto exit;
|
||||
}
|
||||
v_s -= 1;
|
||||
@@ -1576,18 +1576,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,
|
||||
v_expansion = wuffs_base__slice_u8__subslice_i(
|
||||
((wuffs_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 = wuffs_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_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
status = WUFFS_GIF__SUSPENSION_SHORT_WRITE;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3);
|
||||
}
|
||||
label_1_break:;
|
||||
if (v_save_code <= 4095) {
|
||||
@@ -1596,7 +1596,7 @@ puffs_gif__status puffs_gif__lzw_decoder__decode(puffs_gif__lzw_decoder* self,
|
||||
((uint16_t)(v_prev_code));
|
||||
}
|
||||
} else {
|
||||
status = PUFFS_GIF__ERROR_LZW_CODE_IS_OUT_OF_RANGE;
|
||||
status = WUFFS_GIF__ERROR_LZW_CODE_IS_OUT_OF_RANGE;
|
||||
goto exit;
|
||||
}
|
||||
if (v_save_code <= 4095) {
|
||||
@@ -1633,26 +1633,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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_dst.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wstart_dst);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wend_dst);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_wstart_dst);
|
||||
WUFFS_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;
|
||||
wuffs_base__limit1* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
}
|
||||
}
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
PUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rstart_src);
|
||||
WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(b_rend_src);
|
||||
}
|
||||
|
||||
self->private_impl.status = status;
|
||||
@@ -1660,9 +1660,9 @@ exit:
|
||||
|
||||
short_read_src:
|
||||
if (a_src.buf && a_src.buf->closed && !a_src.private_impl.limit.ptr_to_len) {
|
||||
status = PUFFS_GIF__ERROR_UNEXPECTED_EOF;
|
||||
status = WUFFS_GIF__ERROR_UNEXPECTED_EOF;
|
||||
goto exit;
|
||||
}
|
||||
status = PUFFS_GIF__SUSPENSION_SHORT_READ;
|
||||
status = WUFFS_GIF__SUSPENSION_SHORT_READ;
|
||||
goto suspend;
|
||||
}
|
||||
+93
-93
@@ -1,10 +1,10 @@
|
||||
#ifndef PUFFS_FLATE_H
|
||||
#define PUFFS_FLATE_H
|
||||
#ifndef WUFFS_FLATE_H
|
||||
#define WUFFS_FLATE_H
|
||||
|
||||
// Code generated by wuffs-c. DO NOT EDIT.
|
||||
|
||||
#ifndef PUFFS_BASE_HEADER_H
|
||||
#define PUFFS_BASE_HEADER_H
|
||||
#ifndef WUFFS_BASE_HEADER_H
|
||||
#define WUFFS_BASE_HEADER_H
|
||||
|
||||
// Copyright 2017 The Wuffs Authors.
|
||||
//
|
||||
@@ -24,7 +24,7 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
// Puffs requires a word size of at least 32 bits because it assumes that
|
||||
// Wuffs requires a word size of at least 32 bits because it assumes that
|
||||
// converting a u32 to usize will never overflow. For example, the size of a
|
||||
// decoded image is often represented, explicitly or implicitly in an image
|
||||
// file, as a u32, and it is convenient to compare that to a buffer size.
|
||||
@@ -32,12 +32,12 @@
|
||||
// Similarly, the word size is at most 64 bits because it assumes that
|
||||
// converting a usize to u64 will never overflow.
|
||||
#if __WORDSIZE < 32
|
||||
#error "Puffs requires a word size of at least 32 bits"
|
||||
#error "Wuffs requires a word size of at least 32 bits"
|
||||
#elif __WORDSIZE > 64
|
||||
#error "Puffs requires a word size of at most 64 bits"
|
||||
#error "Wuffs requires a word size of at most 64 bits"
|
||||
#endif
|
||||
|
||||
// PUFFS_VERSION is the major.minor version number as a uint32. The major
|
||||
// WUFFS_VERSION is the major.minor version number as a uint32. The major
|
||||
// number is the high 16 bits. The minor number is the low 16 bits.
|
||||
//
|
||||
// The intention is to bump the version number at least on every API / ABI
|
||||
@@ -46,17 +46,17 @@
|
||||
// For now, the API and ABI are simply unstable and can change at any time.
|
||||
//
|
||||
// TODO: don't hard code this in base-header.h.
|
||||
#define PUFFS_VERSION (0x00001)
|
||||
#define WUFFS_VERSION (0x00001)
|
||||
|
||||
// puffs_base__slice_u8 is a 1-dimensional buffer (a pointer and length).
|
||||
// wuffs_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;
|
||||
} wuffs_base__slice_u8;
|
||||
|
||||
// puffs_base__buf1 is a 1-dimensional buffer (a pointer and length), plus
|
||||
// wuffs_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,46 +66,46 @@ 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;
|
||||
} wuffs_base__buf1;
|
||||
|
||||
// puffs_base__limit1 provides a limited view of a 1-dimensional byte stream:
|
||||
// wuffs_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 {
|
||||
typedef struct wuffs_base__limit1 {
|
||||
uint64_t* ptr_to_len; // Pointer to N.
|
||||
struct puffs_base__limit1* next; // Linked list of limits.
|
||||
} puffs_base__limit1;
|
||||
struct wuffs_base__limit1* next; // Linked list of limits.
|
||||
} wuffs_base__limit1;
|
||||
|
||||
typedef struct {
|
||||
// TODO: move buf into private_impl? As it is, it looks like users can modify
|
||||
// the buf field to point to a different buffer, which can turn the limit and
|
||||
// mark fields into dangling pointers.
|
||||
puffs_base__buf1* buf;
|
||||
wuffs_base__buf1* buf;
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
// compatibility or safety guarantee if you do so.
|
||||
struct {
|
||||
puffs_base__limit1 limit;
|
||||
wuffs_base__limit1 limit;
|
||||
uint8_t* mark;
|
||||
} private_impl;
|
||||
} puffs_base__reader1;
|
||||
} wuffs_base__reader1;
|
||||
|
||||
typedef struct {
|
||||
// TODO: move buf into private_impl? As it is, it looks like users can modify
|
||||
// the buf field to point to a different buffer, which can turn the limit and
|
||||
// mark fields into dangling pointers.
|
||||
puffs_base__buf1* buf;
|
||||
wuffs_base__buf1* buf;
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
// compatibility or safety guarantee if you do so.
|
||||
struct {
|
||||
puffs_base__limit1 limit;
|
||||
wuffs_base__limit1 limit;
|
||||
uint8_t* mark;
|
||||
} private_impl;
|
||||
} puffs_base__writer1;
|
||||
} wuffs_base__writer1;
|
||||
|
||||
#endif // PUFFS_BASE_HEADER_H
|
||||
#endif // WUFFS_BASE_HEADER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -120,62 +120,62 @@ extern "C" {
|
||||
// - bits 0-7 are a package-namespaced numeric code
|
||||
//
|
||||
// Do not manipulate these bits directly. Use the API functions such as
|
||||
// puffs_flate__status__is_error instead.
|
||||
typedef int32_t puffs_flate__status;
|
||||
// wuffs_flate__status__is_error instead.
|
||||
typedef int32_t wuffs_flate__status;
|
||||
|
||||
#define puffs_flate__packageid 967230 // 0x000ec23e
|
||||
#define wuffs_flate__packageid 967230 // 0x000ec23e
|
||||
|
||||
#define PUFFS_FLATE__STATUS_OK 0 // 0x00000000
|
||||
#define PUFFS_FLATE__ERROR_BAD_PUFFS_VERSION -2147483647 // 0x80000001
|
||||
#define PUFFS_FLATE__ERROR_BAD_RECEIVER -2147483646 // 0x80000002
|
||||
#define PUFFS_FLATE__ERROR_BAD_ARGUMENT -2147483645 // 0x80000003
|
||||
#define PUFFS_FLATE__ERROR_INITIALIZER_NOT_CALLED -2147483644 // 0x80000004
|
||||
#define PUFFS_FLATE__ERROR_INVALID_I_O_OPERATION -2147483643 // 0x80000005
|
||||
#define PUFFS_FLATE__ERROR_CLOSED_FOR_WRITES -2147483642 // 0x80000006
|
||||
#define PUFFS_FLATE__ERROR_UNEXPECTED_EOF -2147483641 // 0x80000007
|
||||
#define PUFFS_FLATE__SUSPENSION_SHORT_READ 8 // 0x00000008
|
||||
#define PUFFS_FLATE__SUSPENSION_SHORT_WRITE 9 // 0x00000009
|
||||
#define WUFFS_FLATE__STATUS_OK 0 // 0x00000000
|
||||
#define WUFFS_FLATE__ERROR_BAD_WUFFS_VERSION -2147483647 // 0x80000001
|
||||
#define WUFFS_FLATE__ERROR_BAD_RECEIVER -2147483646 // 0x80000002
|
||||
#define WUFFS_FLATE__ERROR_BAD_ARGUMENT -2147483645 // 0x80000003
|
||||
#define WUFFS_FLATE__ERROR_INITIALIZER_NOT_CALLED -2147483644 // 0x80000004
|
||||
#define WUFFS_FLATE__ERROR_INVALID_I_O_OPERATION -2147483643 // 0x80000005
|
||||
#define WUFFS_FLATE__ERROR_CLOSED_FOR_WRITES -2147483642 // 0x80000006
|
||||
#define WUFFS_FLATE__ERROR_UNEXPECTED_EOF -2147483641 // 0x80000007
|
||||
#define WUFFS_FLATE__SUSPENSION_SHORT_READ 8 // 0x00000008
|
||||
#define WUFFS_FLATE__SUSPENSION_SHORT_WRITE 9 // 0x00000009
|
||||
|
||||
#define PUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_OVER_SUBSCRIBED \
|
||||
#define WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_OVER_SUBSCRIBED \
|
||||
-1157040128 // 0xbb08f800
|
||||
#define PUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_UNDER_SUBSCRIBED \
|
||||
#define WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_UNDER_SUBSCRIBED \
|
||||
-1157040127 // 0xbb08f801
|
||||
#define PUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_LENGTH_COUNT \
|
||||
#define WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_LENGTH_COUNT \
|
||||
-1157040126 // 0xbb08f802
|
||||
#define PUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_LENGTH_REPETITION \
|
||||
#define WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE_LENGTH_REPETITION \
|
||||
-1157040125 // 0xbb08f803
|
||||
#define PUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE -1157040124 // 0xbb08f804
|
||||
#define PUFFS_FLATE__ERROR_BAD_HUFFMAN_MINIMUM_CODE_LENGTH \
|
||||
#define WUFFS_FLATE__ERROR_BAD_HUFFMAN_CODE -1157040124 // 0xbb08f804
|
||||
#define WUFFS_FLATE__ERROR_BAD_HUFFMAN_MINIMUM_CODE_LENGTH \
|
||||
-1157040123 // 0xbb08f805
|
||||
#define PUFFS_FLATE__ERROR_BAD_DISTANCE -1157040122 // 0xbb08f806
|
||||
#define PUFFS_FLATE__ERROR_BAD_DISTANCE_CODE_COUNT -1157040121 // 0xbb08f807
|
||||
#define PUFFS_FLATE__ERROR_BAD_FLATE_BLOCK -1157040120 // 0xbb08f808
|
||||
#define PUFFS_FLATE__ERROR_BAD_LITERAL_LENGTH_CODE_COUNT \
|
||||
#define WUFFS_FLATE__ERROR_BAD_DISTANCE -1157040122 // 0xbb08f806
|
||||
#define WUFFS_FLATE__ERROR_BAD_DISTANCE_CODE_COUNT -1157040121 // 0xbb08f807
|
||||
#define WUFFS_FLATE__ERROR_BAD_FLATE_BLOCK -1157040120 // 0xbb08f808
|
||||
#define WUFFS_FLATE__ERROR_BAD_LITERAL_LENGTH_CODE_COUNT \
|
||||
-1157040119 // 0xbb08f809
|
||||
#define PUFFS_FLATE__ERROR_CHECKSUM_MISMATCH -1157040118 // 0xbb08f80a
|
||||
#define PUFFS_FLATE__ERROR_INCONSISTENT_STORED_BLOCK_LENGTH \
|
||||
#define WUFFS_FLATE__ERROR_CHECKSUM_MISMATCH -1157040118 // 0xbb08f80a
|
||||
#define WUFFS_FLATE__ERROR_INCONSISTENT_STORED_BLOCK_LENGTH \
|
||||
-1157040117 // 0xbb08f80b
|
||||
#define PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE \
|
||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_DECODER_STATE \
|
||||
-1157040116 // 0xbb08f80c
|
||||
#define PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_END_OF_BLOCK \
|
||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_HUFFMAN_END_OF_BLOCK \
|
||||
-1157040115 // 0xbb08f80d
|
||||
#define PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_DISTANCE \
|
||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_DISTANCE \
|
||||
-1157040114 // 0xbb08f80e
|
||||
#define PUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS \
|
||||
#define WUFFS_FLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_N_BITS \
|
||||
-1157040113 // 0xbb08f80f
|
||||
#define PUFFS_FLATE__ERROR_MISSING_END_OF_BLOCK_CODE -1157040112 // 0xbb08f810
|
||||
#define PUFFS_FLATE__ERROR_NO_HUFFMAN_CODES -1157040111 // 0xbb08f811
|
||||
#define PUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_METHOD \
|
||||
#define WUFFS_FLATE__ERROR_MISSING_END_OF_BLOCK_CODE -1157040112 // 0xbb08f810
|
||||
#define WUFFS_FLATE__ERROR_NO_HUFFMAN_CODES -1157040111 // 0xbb08f811
|
||||
#define WUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_METHOD \
|
||||
-1157040110 // 0xbb08f812
|
||||
#define PUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_WINDOW_SIZE \
|
||||
#define WUFFS_FLATE__ERROR_INVALID_ZLIB_COMPRESSION_WINDOW_SIZE \
|
||||
-1157040109 // 0xbb08f813
|
||||
#define PUFFS_FLATE__ERROR_INVALID_ZLIB_PARITY_CHECK -1157040108 // 0xbb08f814
|
||||
#define PUFFS_FLATE__ERROR_TODO_UNSUPPORTED_ZLIB_PRESET_DICTIONARY \
|
||||
#define WUFFS_FLATE__ERROR_INVALID_ZLIB_PARITY_CHECK -1157040108 // 0xbb08f814
|
||||
#define WUFFS_FLATE__ERROR_TODO_UNSUPPORTED_ZLIB_PRESET_DICTIONARY \
|
||||
-1157040107 // 0xbb08f815
|
||||
|
||||
bool puffs_flate__status__is_error(puffs_flate__status s);
|
||||
bool wuffs_flate__status__is_error(wuffs_flate__status s);
|
||||
|
||||
const char* puffs_flate__status__string(puffs_flate__status s);
|
||||
const char* wuffs_flate__status__string(wuffs_flate__status s);
|
||||
|
||||
// ---------------- Public Consts
|
||||
|
||||
@@ -184,13 +184,13 @@ const char* puffs_flate__status__string(puffs_flate__status s);
|
||||
typedef struct {
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
// compatibility or safety guarantee if you do so. Instead, use the
|
||||
// puffs_flate__flate_decoder__etc functions.
|
||||
// wuffs_flate__flate_decoder__etc functions.
|
||||
//
|
||||
// In C++, these fields would be "private", but C does not support that.
|
||||
//
|
||||
// It is a struct, not a struct*, so that it can be stack allocated.
|
||||
struct {
|
||||
puffs_flate__status status;
|
||||
wuffs_flate__status status;
|
||||
uint32_t magic;
|
||||
|
||||
uint32_t f_bits;
|
||||
@@ -204,7 +204,7 @@ typedef struct {
|
||||
|
||||
struct {
|
||||
uint32_t coro_susp_point;
|
||||
puffs_flate__status v_z;
|
||||
wuffs_flate__status v_z;
|
||||
uint64_t v_n_copied;
|
||||
uint32_t v_already_full;
|
||||
} c_decode[1];
|
||||
@@ -255,84 +255,84 @@ typedef struct {
|
||||
uint32_t v_hdist;
|
||||
} c_decode_huffman_slow[1];
|
||||
} private_impl;
|
||||
} puffs_flate__flate_decoder;
|
||||
} wuffs_flate__flate_decoder;
|
||||
|
||||
typedef struct {
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
// compatibility or safety guarantee if you do so. Instead, use the
|
||||
// puffs_flate__adler32__etc functions.
|
||||
// wuffs_flate__adler32__etc functions.
|
||||
//
|
||||
// In C++, these fields would be "private", but C does not support that.
|
||||
//
|
||||
// It is a struct, not a struct*, so that it can be stack allocated.
|
||||
struct {
|
||||
puffs_flate__status status;
|
||||
wuffs_flate__status status;
|
||||
uint32_t magic;
|
||||
|
||||
uint32_t f_state;
|
||||
|
||||
} private_impl;
|
||||
} puffs_flate__adler32;
|
||||
} wuffs_flate__adler32;
|
||||
|
||||
typedef struct {
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
// compatibility or safety guarantee if you do so. Instead, use the
|
||||
// puffs_flate__zlib_decoder__etc functions.
|
||||
// wuffs_flate__zlib_decoder__etc functions.
|
||||
//
|
||||
// In C++, these fields would be "private", but C does not support that.
|
||||
//
|
||||
// It is a struct, not a struct*, so that it can be stack allocated.
|
||||
struct {
|
||||
puffs_flate__status status;
|
||||
wuffs_flate__status status;
|
||||
uint32_t magic;
|
||||
|
||||
puffs_flate__flate_decoder f_flate;
|
||||
puffs_flate__adler32 f_adler;
|
||||
wuffs_flate__flate_decoder f_flate;
|
||||
wuffs_flate__adler32 f_adler;
|
||||
|
||||
struct {
|
||||
uint32_t coro_susp_point;
|
||||
uint16_t v_x;
|
||||
uint32_t v_checksum;
|
||||
puffs_flate__status v_z;
|
||||
wuffs_flate__status v_z;
|
||||
uint64_t scratch;
|
||||
} c_decode[1];
|
||||
} private_impl;
|
||||
} puffs_flate__zlib_decoder;
|
||||
} wuffs_flate__zlib_decoder;
|
||||
|
||||
// ---------------- Public Initializer Prototypes
|
||||
|
||||
// puffs_flate__flate_decoder__initialize is an initializer function.
|
||||
// wuffs_flate__flate_decoder__initialize is an initializer function.
|
||||
//
|
||||
// It should be called before any other puffs_flate__flate_decoder__* function.
|
||||
// It should be called before any other wuffs_flate__flate_decoder__* function.
|
||||
//
|
||||
// Pass PUFFS_VERSION and 0 for puffs_version and for_internal_use_only.
|
||||
void puffs_flate__flate_decoder__initialize(puffs_flate__flate_decoder* self,
|
||||
uint32_t puffs_version,
|
||||
// Pass WUFFS_VERSION and 0 for wuffs_version and for_internal_use_only.
|
||||
void wuffs_flate__flate_decoder__initialize(wuffs_flate__flate_decoder* self,
|
||||
uint32_t wuffs_version,
|
||||
uint32_t for_internal_use_only);
|
||||
|
||||
// puffs_flate__zlib_decoder__initialize is an initializer function.
|
||||
// wuffs_flate__zlib_decoder__initialize is an initializer function.
|
||||
//
|
||||
// It should be called before any other puffs_flate__zlib_decoder__* function.
|
||||
// It should be called before any other wuffs_flate__zlib_decoder__* function.
|
||||
//
|
||||
// Pass PUFFS_VERSION and 0 for puffs_version and for_internal_use_only.
|
||||
void puffs_flate__zlib_decoder__initialize(puffs_flate__zlib_decoder* self,
|
||||
uint32_t puffs_version,
|
||||
// Pass WUFFS_VERSION and 0 for wuffs_version and for_internal_use_only.
|
||||
void wuffs_flate__zlib_decoder__initialize(wuffs_flate__zlib_decoder* self,
|
||||
uint32_t wuffs_version,
|
||||
uint32_t for_internal_use_only);
|
||||
|
||||
// ---------------- Public Function Prototypes
|
||||
|
||||
puffs_flate__status puffs_flate__flate_decoder__decode(
|
||||
puffs_flate__flate_decoder* self,
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src);
|
||||
wuffs_flate__status wuffs_flate__flate_decoder__decode(
|
||||
wuffs_flate__flate_decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_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);
|
||||
wuffs_flate__status wuffs_flate__zlib_decoder__decode(
|
||||
wuffs_flate__zlib_decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // PUFFS_FLATE_H
|
||||
#endif // WUFFS_FLATE_H
|
||||
+73
-73
@@ -1,10 +1,10 @@
|
||||
#ifndef PUFFS_GIF_H
|
||||
#define PUFFS_GIF_H
|
||||
#ifndef WUFFS_GIF_H
|
||||
#define WUFFS_GIF_H
|
||||
|
||||
// Code generated by wuffs-c. DO NOT EDIT.
|
||||
|
||||
#ifndef PUFFS_BASE_HEADER_H
|
||||
#define PUFFS_BASE_HEADER_H
|
||||
#ifndef WUFFS_BASE_HEADER_H
|
||||
#define WUFFS_BASE_HEADER_H
|
||||
|
||||
// Copyright 2017 The Wuffs Authors.
|
||||
//
|
||||
@@ -24,7 +24,7 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
// Puffs requires a word size of at least 32 bits because it assumes that
|
||||
// Wuffs requires a word size of at least 32 bits because it assumes that
|
||||
// converting a u32 to usize will never overflow. For example, the size of a
|
||||
// decoded image is often represented, explicitly or implicitly in an image
|
||||
// file, as a u32, and it is convenient to compare that to a buffer size.
|
||||
@@ -32,12 +32,12 @@
|
||||
// Similarly, the word size is at most 64 bits because it assumes that
|
||||
// converting a usize to u64 will never overflow.
|
||||
#if __WORDSIZE < 32
|
||||
#error "Puffs requires a word size of at least 32 bits"
|
||||
#error "Wuffs requires a word size of at least 32 bits"
|
||||
#elif __WORDSIZE > 64
|
||||
#error "Puffs requires a word size of at most 64 bits"
|
||||
#error "Wuffs requires a word size of at most 64 bits"
|
||||
#endif
|
||||
|
||||
// PUFFS_VERSION is the major.minor version number as a uint32. The major
|
||||
// WUFFS_VERSION is the major.minor version number as a uint32. The major
|
||||
// number is the high 16 bits. The minor number is the low 16 bits.
|
||||
//
|
||||
// The intention is to bump the version number at least on every API / ABI
|
||||
@@ -46,17 +46,17 @@
|
||||
// For now, the API and ABI are simply unstable and can change at any time.
|
||||
//
|
||||
// TODO: don't hard code this in base-header.h.
|
||||
#define PUFFS_VERSION (0x00001)
|
||||
#define WUFFS_VERSION (0x00001)
|
||||
|
||||
// puffs_base__slice_u8 is a 1-dimensional buffer (a pointer and length).
|
||||
// wuffs_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;
|
||||
} wuffs_base__slice_u8;
|
||||
|
||||
// puffs_base__buf1 is a 1-dimensional buffer (a pointer and length), plus
|
||||
// wuffs_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,46 +66,46 @@ 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;
|
||||
} wuffs_base__buf1;
|
||||
|
||||
// puffs_base__limit1 provides a limited view of a 1-dimensional byte stream:
|
||||
// wuffs_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 {
|
||||
typedef struct wuffs_base__limit1 {
|
||||
uint64_t* ptr_to_len; // Pointer to N.
|
||||
struct puffs_base__limit1* next; // Linked list of limits.
|
||||
} puffs_base__limit1;
|
||||
struct wuffs_base__limit1* next; // Linked list of limits.
|
||||
} wuffs_base__limit1;
|
||||
|
||||
typedef struct {
|
||||
// TODO: move buf into private_impl? As it is, it looks like users can modify
|
||||
// the buf field to point to a different buffer, which can turn the limit and
|
||||
// mark fields into dangling pointers.
|
||||
puffs_base__buf1* buf;
|
||||
wuffs_base__buf1* buf;
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
// compatibility or safety guarantee if you do so.
|
||||
struct {
|
||||
puffs_base__limit1 limit;
|
||||
wuffs_base__limit1 limit;
|
||||
uint8_t* mark;
|
||||
} private_impl;
|
||||
} puffs_base__reader1;
|
||||
} wuffs_base__reader1;
|
||||
|
||||
typedef struct {
|
||||
// TODO: move buf into private_impl? As it is, it looks like users can modify
|
||||
// the buf field to point to a different buffer, which can turn the limit and
|
||||
// mark fields into dangling pointers.
|
||||
puffs_base__buf1* buf;
|
||||
wuffs_base__buf1* buf;
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
// compatibility or safety guarantee if you do so.
|
||||
struct {
|
||||
puffs_base__limit1 limit;
|
||||
wuffs_base__limit1 limit;
|
||||
uint8_t* mark;
|
||||
} private_impl;
|
||||
} puffs_base__writer1;
|
||||
} wuffs_base__writer1;
|
||||
|
||||
#endif // PUFFS_BASE_HEADER_H
|
||||
#endif // WUFFS_BASE_HEADER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -120,36 +120,36 @@ extern "C" {
|
||||
// - bits 0-7 are a package-namespaced numeric code
|
||||
//
|
||||
// Do not manipulate these bits directly. Use the API functions such as
|
||||
// puffs_gif__status__is_error instead.
|
||||
typedef int32_t puffs_gif__status;
|
||||
// wuffs_gif__status__is_error instead.
|
||||
typedef int32_t wuffs_gif__status;
|
||||
|
||||
#define puffs_gif__packageid 1017222 // 0x000f8586
|
||||
#define wuffs_gif__packageid 1017222 // 0x000f8586
|
||||
|
||||
#define PUFFS_GIF__STATUS_OK 0 // 0x00000000
|
||||
#define PUFFS_GIF__ERROR_BAD_PUFFS_VERSION -2147483647 // 0x80000001
|
||||
#define PUFFS_GIF__ERROR_BAD_RECEIVER -2147483646 // 0x80000002
|
||||
#define PUFFS_GIF__ERROR_BAD_ARGUMENT -2147483645 // 0x80000003
|
||||
#define PUFFS_GIF__ERROR_INITIALIZER_NOT_CALLED -2147483644 // 0x80000004
|
||||
#define PUFFS_GIF__ERROR_INVALID_I_O_OPERATION -2147483643 // 0x80000005
|
||||
#define PUFFS_GIF__ERROR_CLOSED_FOR_WRITES -2147483642 // 0x80000006
|
||||
#define PUFFS_GIF__ERROR_UNEXPECTED_EOF -2147483641 // 0x80000007
|
||||
#define PUFFS_GIF__SUSPENSION_SHORT_READ 8 // 0x00000008
|
||||
#define PUFFS_GIF__SUSPENSION_SHORT_WRITE 9 // 0x00000009
|
||||
#define WUFFS_GIF__STATUS_OK 0 // 0x00000000
|
||||
#define WUFFS_GIF__ERROR_BAD_WUFFS_VERSION -2147483647 // 0x80000001
|
||||
#define WUFFS_GIF__ERROR_BAD_RECEIVER -2147483646 // 0x80000002
|
||||
#define WUFFS_GIF__ERROR_BAD_ARGUMENT -2147483645 // 0x80000003
|
||||
#define WUFFS_GIF__ERROR_INITIALIZER_NOT_CALLED -2147483644 // 0x80000004
|
||||
#define WUFFS_GIF__ERROR_INVALID_I_O_OPERATION -2147483643 // 0x80000005
|
||||
#define WUFFS_GIF__ERROR_CLOSED_FOR_WRITES -2147483642 // 0x80000006
|
||||
#define WUFFS_GIF__ERROR_UNEXPECTED_EOF -2147483641 // 0x80000007
|
||||
#define WUFFS_GIF__SUSPENSION_SHORT_READ 8 // 0x00000008
|
||||
#define WUFFS_GIF__SUSPENSION_SHORT_WRITE 9 // 0x00000009
|
||||
|
||||
#define PUFFS_GIF__ERROR_BAD_GIF_BLOCK -1105848320 // 0xbe161800
|
||||
#define PUFFS_GIF__ERROR_BAD_GIF_EXTENSION_LABEL -1105848319 // 0xbe161801
|
||||
#define PUFFS_GIF__ERROR_BAD_GIF_HEADER -1105848318 // 0xbe161802
|
||||
#define PUFFS_GIF__ERROR_BAD_LZW_LITERAL_WIDTH -1105848317 // 0xbe161803
|
||||
#define PUFFS_GIF__ERROR_INTERNAL_ERROR_INCONSISTENT_LIMITED_READ \
|
||||
#define WUFFS_GIF__ERROR_BAD_GIF_BLOCK -1105848320 // 0xbe161800
|
||||
#define WUFFS_GIF__ERROR_BAD_GIF_EXTENSION_LABEL -1105848319 // 0xbe161801
|
||||
#define WUFFS_GIF__ERROR_BAD_GIF_HEADER -1105848318 // 0xbe161802
|
||||
#define WUFFS_GIF__ERROR_BAD_LZW_LITERAL_WIDTH -1105848317 // 0xbe161803
|
||||
#define WUFFS_GIF__ERROR_INTERNAL_ERROR_INCONSISTENT_LIMITED_READ \
|
||||
-1105848316 // 0xbe161804
|
||||
#define PUFFS_GIF__ERROR_TODO_UNSUPPORTED_LOCAL_COLOR_TABLE \
|
||||
#define WUFFS_GIF__ERROR_TODO_UNSUPPORTED_LOCAL_COLOR_TABLE \
|
||||
-1105848315 // 0xbe161805
|
||||
#define PUFFS_GIF__ERROR_LZW_CODE_IS_OUT_OF_RANGE -1105848314 // 0xbe161806
|
||||
#define PUFFS_GIF__ERROR_LZW_PREFIX_CHAIN_IS_CYCLICAL -1105848313 // 0xbe161807
|
||||
#define WUFFS_GIF__ERROR_LZW_CODE_IS_OUT_OF_RANGE -1105848314 // 0xbe161806
|
||||
#define WUFFS_GIF__ERROR_LZW_PREFIX_CHAIN_IS_CYCLICAL -1105848313 // 0xbe161807
|
||||
|
||||
bool puffs_gif__status__is_error(puffs_gif__status s);
|
||||
bool wuffs_gif__status__is_error(wuffs_gif__status s);
|
||||
|
||||
const char* puffs_gif__status__string(puffs_gif__status s);
|
||||
const char* wuffs_gif__status__string(wuffs_gif__status s);
|
||||
|
||||
// ---------------- Public Consts
|
||||
|
||||
@@ -158,13 +158,13 @@ const char* puffs_gif__status__string(puffs_gif__status s);
|
||||
typedef struct {
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
// compatibility or safety guarantee if you do so. Instead, use the
|
||||
// puffs_gif__lzw_decoder__etc functions.
|
||||
// wuffs_gif__lzw_decoder__etc functions.
|
||||
//
|
||||
// In C++, these fields would be "private", but C does not support that.
|
||||
//
|
||||
// It is a struct, not a struct*, so that it can be stack allocated.
|
||||
struct {
|
||||
puffs_gif__status status;
|
||||
wuffs_gif__status status;
|
||||
uint32_t magic;
|
||||
|
||||
uint32_t f_literal_width;
|
||||
@@ -187,25 +187,25 @@ typedef struct {
|
||||
uint64_t v_n_copied;
|
||||
} c_decode[1];
|
||||
} private_impl;
|
||||
} puffs_gif__lzw_decoder;
|
||||
} wuffs_gif__lzw_decoder;
|
||||
|
||||
typedef struct {
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
// compatibility or safety guarantee if you do so. Instead, use the
|
||||
// puffs_gif__decoder__etc functions.
|
||||
// wuffs_gif__decoder__etc functions.
|
||||
//
|
||||
// In C++, these fields would be "private", but C does not support that.
|
||||
//
|
||||
// It is a struct, not a struct*, so that it can be stack allocated.
|
||||
struct {
|
||||
puffs_gif__status status;
|
||||
wuffs_gif__status status;
|
||||
uint32_t magic;
|
||||
|
||||
uint32_t f_width;
|
||||
uint32_t f_height;
|
||||
uint8_t f_background_color_index;
|
||||
uint8_t f_gct[768];
|
||||
puffs_gif__lzw_decoder f_lzw;
|
||||
wuffs_gif__lzw_decoder f_lzw;
|
||||
|
||||
struct {
|
||||
uint32_t coro_susp_point;
|
||||
@@ -235,46 +235,46 @@ typedef struct {
|
||||
bool v_interlace;
|
||||
uint8_t v_lw;
|
||||
uint64_t v_block_size;
|
||||
puffs_gif__status v_z;
|
||||
wuffs_gif__status v_z;
|
||||
} c_decode_id[1];
|
||||
} private_impl;
|
||||
} puffs_gif__decoder;
|
||||
} wuffs_gif__decoder;
|
||||
|
||||
// ---------------- Public Initializer Prototypes
|
||||
|
||||
// puffs_gif__lzw_decoder__initialize is an initializer function.
|
||||
// wuffs_gif__lzw_decoder__initialize is an initializer function.
|
||||
//
|
||||
// It should be called before any other puffs_gif__lzw_decoder__* function.
|
||||
// It should be called before any other wuffs_gif__lzw_decoder__* function.
|
||||
//
|
||||
// Pass PUFFS_VERSION and 0 for puffs_version and for_internal_use_only.
|
||||
void puffs_gif__lzw_decoder__initialize(puffs_gif__lzw_decoder* self,
|
||||
uint32_t puffs_version,
|
||||
// Pass WUFFS_VERSION and 0 for wuffs_version and for_internal_use_only.
|
||||
void wuffs_gif__lzw_decoder__initialize(wuffs_gif__lzw_decoder* self,
|
||||
uint32_t wuffs_version,
|
||||
uint32_t for_internal_use_only);
|
||||
|
||||
// puffs_gif__decoder__initialize is an initializer function.
|
||||
// wuffs_gif__decoder__initialize is an initializer function.
|
||||
//
|
||||
// It should be called before any other puffs_gif__decoder__* function.
|
||||
// It should be called before any other wuffs_gif__decoder__* function.
|
||||
//
|
||||
// Pass PUFFS_VERSION and 0 for puffs_version and for_internal_use_only.
|
||||
void puffs_gif__decoder__initialize(puffs_gif__decoder* self,
|
||||
uint32_t puffs_version,
|
||||
// Pass WUFFS_VERSION and 0 for wuffs_version and for_internal_use_only.
|
||||
void wuffs_gif__decoder__initialize(wuffs_gif__decoder* self,
|
||||
uint32_t wuffs_version,
|
||||
uint32_t for_internal_use_only);
|
||||
|
||||
// ---------------- Public Function Prototypes
|
||||
|
||||
puffs_gif__status puffs_gif__decoder__decode(puffs_gif__decoder* self,
|
||||
puffs_base__writer1 a_dst,
|
||||
puffs_base__reader1 a_src);
|
||||
wuffs_gif__status wuffs_gif__decoder__decode(wuffs_gif__decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src);
|
||||
|
||||
void puffs_gif__lzw_decoder__set_literal_width(puffs_gif__lzw_decoder* self,
|
||||
void wuffs_gif__lzw_decoder__set_literal_width(wuffs_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);
|
||||
wuffs_gif__status wuffs_gif__lzw_decoder__decode(wuffs_gif__lzw_decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // PUFFS_GIF_H
|
||||
#endif // WUFFS_GIF_H
|
||||
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Package builtin lists Puffs' built-in concepts such as status codes.
|
||||
// Package builtin lists Wuffs' built-in concepts such as status codes.
|
||||
package builtin
|
||||
|
||||
import (
|
||||
@@ -37,7 +37,7 @@ func (z Status) String() string {
|
||||
|
||||
var StatusList = [...]Status{
|
||||
{0, "ok"},
|
||||
{t.IDError, "bad puffs version"},
|
||||
{t.IDError, "bad wuffs version"},
|
||||
{t.IDError, "bad receiver"},
|
||||
{t.IDError, "bad argument"},
|
||||
{t.IDError, "initializer not called"},
|
||||
|
||||
@@ -421,7 +421,7 @@ pri func flate_decoder.init_dynamic_huffman?(src reader1)() {
|
||||
|
||||
// TODO: make named constants for 15, 19, 319, etc.
|
||||
|
||||
// TODO: skip generating PUFFS_COROUTINE_SUSPENSION_POINTs for *callers* of
|
||||
// TODO: skip generating WUFFS_COROUTINE_SUSPENSION_POINTs for *callers* of
|
||||
// this function, as it can only return errors, not suspensions.
|
||||
|
||||
pri func flate_decoder.init_huff?(which u32[..1], n_codes0 u32[..320], n_codes1 u32[..320], base_symbol u32)() {
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
pri func flate_decoder.decode_huffman_fast?(dst writer1, src reader1)() {
|
||||
// When editing this function, consider making the equivalent change to the
|
||||
// decode_huffman_slow function. Keep the diff between the two
|
||||
// decode_huffman_*.puffs files as small as possible, while retaining both
|
||||
// decode_huffman_*.wuffs files as small as possible, while retaining both
|
||||
// correctness and performance.
|
||||
|
||||
// TODO: make this a func pre-condition.
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
pri func flate_decoder.decode_huffman_slow?(dst writer1, src reader1)() {
|
||||
// When editing this function, consider making the equivalent change to the
|
||||
// decode_huffman_fast function. Keep the diff between the two
|
||||
// decode_huffman_*.puffs files as small as possible, while retaining both
|
||||
// decode_huffman_*.wuffs files as small as possible, while retaining both
|
||||
// correctness and performance.
|
||||
|
||||
if (this.n_bits >= 8) or ((this.bits >> this.n_bits) != 0) {
|
||||
|
||||
@@ -21,7 +21,7 @@ pub error "TODO: unsupported zlib preset dictionary"
|
||||
// TODO: move this file from std/flate to std/zlib? In doing so, we could
|
||||
// rename both of "struct flate_decoder" and "struct zlib_decoder" to just
|
||||
// "struct decoder", to avoid stutter in the fully qualified C name such as
|
||||
// "puffs_flate__flate_decoder".
|
||||
// "wuffs_flate__flate_decoder".
|
||||
//
|
||||
// Would we then need to somehow share code between test/c/std/{flate,gzip}.c?
|
||||
|
||||
@@ -61,7 +61,7 @@ pub func zlib_decoder.decode?(dst writer1, src reader1)() {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: drop the '?' but still generate puffs_flate_adler_initialize?
|
||||
// TODO: drop the '?' but still generate wuffs_flate_adler_initialize?
|
||||
pri struct adler32?(
|
||||
state u32 = 1,
|
||||
)
|
||||
|
||||
+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(wuffs_base__buf1* dst,
|
||||
wuffs_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(wuffs_base__buf1* dst,
|
||||
wuffs_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);
|
||||
wuffs_base__buf1* src = (wuffs_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);
|
||||
wuffs_base__buf1* dst = (wuffs_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(wuffs_base__buf1* dst,
|
||||
wuffs_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(wuffs_base__buf1* dst,
|
||||
wuffs_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(wuffs_base__buf1* dst,
|
||||
wuffs_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(wuffs_base__buf1* dst,
|
||||
wuffs_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);
|
||||
wuffs_base__buf1* src = (wuffs_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(wuffs_base__buf1* dst, wuffs_base__buf1* src) {
|
||||
const char* ret = NULL;
|
||||
|
||||
// http://giflib.sourceforge.net/gif_lib.html#compatibility says that "A few
|
||||
@@ -54,7 +54,7 @@ const char* mimic_gif_decode(puffs_base__buf1* dst, puffs_base__buf1* src) {
|
||||
goto cleanup1;
|
||||
}
|
||||
|
||||
// TODO: have Puffs accept multi-frame (animated) GIFs.
|
||||
// TODO: have Wuffs accept multi-frame (animated) GIFs.
|
||||
if (f->ImageCount != 1) {
|
||||
ret = "GIF image has more than one frame";
|
||||
goto cleanup1;
|
||||
|
||||
+176
-176
@@ -13,9 +13,9 @@
|
||||
// limitations under the License.
|
||||
|
||||
/*
|
||||
This test program is typically run indirectly, by the "puffs test" or "puffs
|
||||
This test program is typically run indirectly, by the "wuffs test" or "wuffs
|
||||
bench" commands. These commands take an optional "-mimic" flag to check that
|
||||
Puffs' output mimics (i.e. exactly matches) other libraries' output, such as
|
||||
Wuffs' output mimics (i.e. exactly matches) other libraries' output, such as
|
||||
giflib for GIF, libpng for PNG, etc.
|
||||
|
||||
To manually run this test:
|
||||
@@ -27,15 +27,15 @@ done
|
||||
|
||||
Each edition should print "PASS", amongst other information, and exit(0).
|
||||
|
||||
Add the "puffs mimic cflags" (everything after the colon below) to the C
|
||||
Add the "wuffs mimic cflags" (everything after the colon below) to the C
|
||||
compiler flags (after the .c file) to run the mimic tests.
|
||||
|
||||
To manually run the benchmarks, replace "-Wall -Werror" with "-O3" and replace
|
||||
the first "./a.out" with "./a.out -bench". Combine these changes with the
|
||||
"puffs mimic cflags" to run the mimic benchmarks.
|
||||
"wuffs mimic cflags" to run the mimic benchmarks.
|
||||
*/
|
||||
|
||||
// !! puffs mimic cflags: -DPUFFS_MIMIC -lz
|
||||
// !! wuffs mimic cflags: -DWUFFS_MIMIC -lz
|
||||
|
||||
#include "../../../gen/c/std/flate.c"
|
||||
#include "../testlib/testlib.c"
|
||||
@@ -120,7 +120,7 @@ golden_test zlib_pi_gt = {
|
||||
|
||||
// ---------------- Checksum Tests
|
||||
|
||||
void test_puffs_adler32() {
|
||||
void test_wuffs_adler32() {
|
||||
CHECK_FOCUS(__func__);
|
||||
|
||||
struct {
|
||||
@@ -159,15 +159,15 @@ 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};
|
||||
for (i = 0; i < WUFFS_TESTLIB_ARRAY_SIZE(test_cases); i++) {
|
||||
wuffs_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);
|
||||
wuffs_flate__adler32 checksum;
|
||||
wuffs_flate__adler32__initialize(&checksum, WUFFS_VERSION, 0);
|
||||
uint32_t got =
|
||||
puffs_flate__adler32__update(&checksum, ((puffs_base__slice_u8){
|
||||
wuffs_flate__adler32__update(&checksum, ((wuffs_base__slice_u8){
|
||||
.ptr = src.ptr + src.ri,
|
||||
.len = src.wi - src.ri,
|
||||
}));
|
||||
@@ -181,127 +181,127 @@ void test_puffs_adler32() {
|
||||
|
||||
// ---------------- Flate Tests
|
||||
|
||||
const char* puffs_flate_decode(puffs_base__buf1* dst,
|
||||
puffs_base__buf1* src,
|
||||
const char* wuffs_flate_decode(wuffs_base__buf1* dst,
|
||||
wuffs_base__buf1* src,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
puffs_flate__flate_decoder dec;
|
||||
puffs_flate__flate_decoder__initialize(&dec, PUFFS_VERSION, 0);
|
||||
wuffs_flate__flate_decoder dec;
|
||||
wuffs_flate__flate_decoder__initialize(&dec, WUFFS_VERSION, 0);
|
||||
uint64_t wlim = 0;
|
||||
uint64_t rlim = 0;
|
||||
while (true) {
|
||||
puffs_base__writer1 dst_writer = {.buf = dst};
|
||||
wuffs_base__writer1 dst_writer = {.buf = dst};
|
||||
if (wlimit) {
|
||||
wlim = wlimit;
|
||||
dst_writer.private_impl.limit.ptr_to_len = &wlim;
|
||||
}
|
||||
puffs_base__reader1 src_reader = {.buf = src};
|
||||
wuffs_base__reader1 src_reader = {.buf = src};
|
||||
if (rlimit) {
|
||||
rlim = rlimit;
|
||||
src_reader.private_impl.limit.ptr_to_len = &rlim;
|
||||
}
|
||||
|
||||
puffs_flate__status s =
|
||||
puffs_flate__flate_decoder__decode(&dec, dst_writer, src_reader);
|
||||
wuffs_flate__status s =
|
||||
wuffs_flate__flate_decoder__decode(&dec, dst_writer, src_reader);
|
||||
|
||||
if (s == PUFFS_FLATE__STATUS_OK) {
|
||||
if (s == WUFFS_FLATE__STATUS_OK) {
|
||||
return NULL;
|
||||
}
|
||||
if ((wlimit && (s == PUFFS_FLATE__SUSPENSION_SHORT_WRITE)) ||
|
||||
(rlimit && (s == PUFFS_FLATE__SUSPENSION_SHORT_READ))) {
|
||||
if ((wlimit && (s == WUFFS_FLATE__SUSPENSION_SHORT_WRITE)) ||
|
||||
(rlimit && (s == WUFFS_FLATE__SUSPENSION_SHORT_READ))) {
|
||||
continue;
|
||||
}
|
||||
return puffs_flate__status__string(s);
|
||||
return wuffs_flate__status__string(s);
|
||||
}
|
||||
}
|
||||
|
||||
const char* puffs_zlib_decode(puffs_base__buf1* dst,
|
||||
puffs_base__buf1* src,
|
||||
const char* wuffs_zlib_decode(wuffs_base__buf1* dst,
|
||||
wuffs_base__buf1* src,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
puffs_flate__zlib_decoder dec;
|
||||
puffs_flate__zlib_decoder__initialize(&dec, PUFFS_VERSION, 0);
|
||||
wuffs_flate__zlib_decoder dec;
|
||||
wuffs_flate__zlib_decoder__initialize(&dec, WUFFS_VERSION, 0);
|
||||
|
||||
uint64_t wlim = 0;
|
||||
uint64_t rlim = 0;
|
||||
while (true) {
|
||||
puffs_base__writer1 dst_writer = {.buf = dst};
|
||||
wuffs_base__writer1 dst_writer = {.buf = dst};
|
||||
if (wlimit) {
|
||||
wlim = wlimit;
|
||||
dst_writer.private_impl.limit.ptr_to_len = &wlim;
|
||||
}
|
||||
puffs_base__reader1 src_reader = {.buf = src};
|
||||
wuffs_base__reader1 src_reader = {.buf = src};
|
||||
if (rlimit) {
|
||||
rlim = rlimit;
|
||||
src_reader.private_impl.limit.ptr_to_len = &rlim;
|
||||
}
|
||||
|
||||
puffs_flate__status s =
|
||||
puffs_flate__zlib_decoder__decode(&dec, dst_writer, src_reader);
|
||||
wuffs_flate__status s =
|
||||
wuffs_flate__zlib_decoder__decode(&dec, dst_writer, src_reader);
|
||||
|
||||
if (s == PUFFS_FLATE__STATUS_OK) {
|
||||
if (s == WUFFS_FLATE__STATUS_OK) {
|
||||
return NULL;
|
||||
}
|
||||
if ((wlimit && (s == PUFFS_FLATE__SUSPENSION_SHORT_WRITE)) ||
|
||||
(rlimit && (s == PUFFS_FLATE__SUSPENSION_SHORT_READ))) {
|
||||
if ((wlimit && (s == WUFFS_FLATE__SUSPENSION_SHORT_WRITE)) ||
|
||||
(rlimit && (s == WUFFS_FLATE__SUSPENSION_SHORT_READ))) {
|
||||
continue;
|
||||
}
|
||||
return puffs_flate__status__string(s);
|
||||
return wuffs_flate__status__string(s);
|
||||
}
|
||||
}
|
||||
|
||||
void test_puffs_flate_decode_256_bytes() {
|
||||
void test_wuffs_flate_decode_256_bytes() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_256_bytes_gt, 0, 0);
|
||||
do_test_buf1_buf1(wuffs_flate_decode, &flate_256_bytes_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_puffs_flate_decode_flate_backref_crosses_blocks() {
|
||||
void test_wuffs_flate_decode_flate_backref_crosses_blocks() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_flate_backref_crosses_blocks_gt,
|
||||
do_test_buf1_buf1(wuffs_flate_decode, &flate_flate_backref_crosses_blocks_gt,
|
||||
0, 0);
|
||||
}
|
||||
|
||||
void test_puffs_flate_decode_midsummer() {
|
||||
void test_wuffs_flate_decode_midsummer() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_midsummer_gt, 0, 0);
|
||||
do_test_buf1_buf1(wuffs_flate_decode, &flate_midsummer_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_puffs_flate_decode_pi() {
|
||||
void test_wuffs_flate_decode_pi() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_pi_gt, 0, 0);
|
||||
do_test_buf1_buf1(wuffs_flate_decode, &flate_pi_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_puffs_flate_decode_pi_many_big_reads() {
|
||||
void test_wuffs_flate_decode_pi_many_big_reads() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_pi_gt, 0, 4096);
|
||||
do_test_buf1_buf1(wuffs_flate_decode, &flate_pi_gt, 0, 4096);
|
||||
}
|
||||
|
||||
void test_puffs_flate_decode_pi_many_medium_reads() {
|
||||
void test_wuffs_flate_decode_pi_many_medium_reads() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_pi_gt, 0, 599);
|
||||
do_test_buf1_buf1(wuffs_flate_decode, &flate_pi_gt, 0, 599);
|
||||
}
|
||||
|
||||
void test_puffs_flate_decode_pi_many_small_writes_reads() {
|
||||
void test_wuffs_flate_decode_pi_many_small_writes_reads() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_pi_gt, 59, 61);
|
||||
do_test_buf1_buf1(wuffs_flate_decode, &flate_pi_gt, 59, 61);
|
||||
}
|
||||
|
||||
void test_puffs_flate_decode_romeo() {
|
||||
void test_wuffs_flate_decode_romeo() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_romeo_gt, 0, 0);
|
||||
do_test_buf1_buf1(wuffs_flate_decode, &flate_romeo_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_puffs_flate_decode_romeo_fixed() {
|
||||
void test_wuffs_flate_decode_romeo_fixed() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(puffs_flate_decode, &flate_romeo_fixed_gt, 0, 0);
|
||||
do_test_buf1_buf1(wuffs_flate_decode, &flate_romeo_fixed_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_puffs_flate_decode_split_src() {
|
||||
void test_wuffs_flate_decode_split_src() {
|
||||
CHECK_FOCUS(__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};
|
||||
wuffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
wuffs_base__buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
wuffs_base__buf1 want = {.ptr = global_want_buffer, .len = BUFFER_SIZE};
|
||||
|
||||
golden_test* gt = &flate_256_bytes_gt;
|
||||
if (!read_file(&src, gt->src_filename)) {
|
||||
@@ -311,9 +311,9 @@ void test_puffs_flate_decode_split_src() {
|
||||
return;
|
||||
}
|
||||
|
||||
puffs_flate__flate_decoder dec;
|
||||
puffs_base__writer1 dst_writer = {.buf = &got};
|
||||
puffs_base__reader1 src_reader = {.buf = &src};
|
||||
wuffs_flate__flate_decoder dec;
|
||||
wuffs_base__writer1 dst_writer = {.buf = &got};
|
||||
wuffs_base__reader1 src_reader = {.buf = &src};
|
||||
|
||||
int i;
|
||||
for (i = 1; i < 32; i++) {
|
||||
@@ -324,31 +324,31 @@ void test_puffs_flate_decode_split_src() {
|
||||
}
|
||||
got.wi = 0;
|
||||
|
||||
puffs_flate__flate_decoder__initialize(&dec, PUFFS_VERSION, 0);
|
||||
wuffs_flate__flate_decoder__initialize(&dec, WUFFS_VERSION, 0);
|
||||
|
||||
src.closed = false;
|
||||
src.ri = gt->src_offset0;
|
||||
src.wi = split;
|
||||
puffs_flate__status s0 =
|
||||
puffs_flate__flate_decoder__decode(&dec, dst_writer, src_reader);
|
||||
wuffs_flate__status s0 =
|
||||
wuffs_flate__flate_decoder__decode(&dec, dst_writer, src_reader);
|
||||
|
||||
src.closed = true;
|
||||
src.ri = split;
|
||||
src.wi = gt->src_offset1;
|
||||
puffs_flate__status s1 =
|
||||
puffs_flate__flate_decoder__decode(&dec, dst_writer, src_reader);
|
||||
wuffs_flate__status s1 =
|
||||
wuffs_flate__flate_decoder__decode(&dec, dst_writer, src_reader);
|
||||
|
||||
if (s0 != PUFFS_FLATE__SUSPENSION_SHORT_READ) {
|
||||
if (s0 != WUFFS_FLATE__SUSPENSION_SHORT_READ) {
|
||||
FAIL("i=%d: s0: got %" PRIi32 " (%s), want %" PRIi32 " (%s)", i, s0,
|
||||
puffs_flate__status__string(s0), PUFFS_FLATE__SUSPENSION_SHORT_READ,
|
||||
puffs_flate__status__string(PUFFS_FLATE__SUSPENSION_SHORT_READ));
|
||||
wuffs_flate__status__string(s0), WUFFS_FLATE__SUSPENSION_SHORT_READ,
|
||||
wuffs_flate__status__string(WUFFS_FLATE__SUSPENSION_SHORT_READ));
|
||||
return;
|
||||
}
|
||||
|
||||
if (s1 != PUFFS_FLATE__STATUS_OK) {
|
||||
if (s1 != WUFFS_FLATE__STATUS_OK) {
|
||||
FAIL("i=%d: s1: got %" PRIi32 " (%s), want %" PRIi32 " (%s)", i, s1,
|
||||
puffs_flate__status__string(s1), PUFFS_FLATE__STATUS_OK,
|
||||
puffs_flate__status__string(PUFFS_FLATE__STATUS_OK));
|
||||
wuffs_flate__status__string(s1), WUFFS_FLATE__STATUS_OK,
|
||||
wuffs_flate__status__string(WUFFS_FLATE__STATUS_OK));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -360,45 +360,45 @@ void test_puffs_flate_decode_split_src() {
|
||||
}
|
||||
}
|
||||
|
||||
bool do_test_puffs_flate_history(int i,
|
||||
bool do_test_wuffs_flate_history(int i,
|
||||
golden_test* gt,
|
||||
puffs_base__buf1* src,
|
||||
puffs_base__buf1* got,
|
||||
puffs_flate__flate_decoder* dec,
|
||||
wuffs_base__buf1* src,
|
||||
wuffs_base__buf1* got,
|
||||
wuffs_flate__flate_decoder* dec,
|
||||
uint32_t starting_history_index,
|
||||
uint64_t limit,
|
||||
puffs_flate__status want_s) {
|
||||
wuffs_flate__status want_s) {
|
||||
src->ri = gt->src_offset0;
|
||||
src->wi = gt->src_offset1;
|
||||
got->ri = 0;
|
||||
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};
|
||||
wuffs_flate__flate_decoder__initialize(dec, WUFFS_VERSION, 0);
|
||||
wuffs_base__writer1 dst_writer = {.buf = got};
|
||||
wuffs_base__reader1 src_reader = {.buf = src};
|
||||
|
||||
dec->private_impl.f_history_index = starting_history_index;
|
||||
|
||||
dst_writer.private_impl.limit.ptr_to_len = &limit;
|
||||
|
||||
puffs_flate__status got_s =
|
||||
puffs_flate__flate_decoder__decode(dec, dst_writer, src_reader);
|
||||
wuffs_flate__status got_s =
|
||||
wuffs_flate__flate_decoder__decode(dec, dst_writer, src_reader);
|
||||
if (got_s != want_s) {
|
||||
FAIL("i=%d: starting_history_index=0x%04" PRIX32
|
||||
": decode status: got %" PRIi32 " (%s), want %" PRIi32 " (%s)",
|
||||
i, starting_history_index, got_s, puffs_flate__status__string(got_s),
|
||||
want_s, puffs_flate__status__string(want_s));
|
||||
i, starting_history_index, got_s, wuffs_flate__status__string(got_s),
|
||||
want_s, wuffs_flate__status__string(want_s));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void test_puffs_flate_history_full() {
|
||||
void test_wuffs_flate_history_full() {
|
||||
CHECK_FOCUS(__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};
|
||||
wuffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
wuffs_base__buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
wuffs_base__buf1 want = {.ptr = global_want_buffer, .len = BUFFER_SIZE};
|
||||
|
||||
golden_test* gt = &flate_pi_gt;
|
||||
if (!read_file(&src, gt->src_filename)) {
|
||||
@@ -411,11 +411,11 @@ void test_puffs_flate_history_full() {
|
||||
const int full_history_size = 0x8000;
|
||||
int i;
|
||||
for (i = -2; i <= +2; i++) {
|
||||
puffs_flate__flate_decoder dec;
|
||||
if (!do_test_puffs_flate_history(
|
||||
wuffs_flate__flate_decoder dec;
|
||||
if (!do_test_wuffs_flate_history(
|
||||
i, gt, &src, &got, &dec, 0, want.wi + i,
|
||||
i >= 0 ? PUFFS_FLATE__STATUS_OK
|
||||
: PUFFS_FLATE__SUSPENSION_SHORT_WRITE)) {
|
||||
i >= 0 ? WUFFS_FLATE__STATUS_OK
|
||||
: WUFFS_FLATE__SUSPENSION_SHORT_WRITE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -429,7 +429,7 @@ void test_puffs_flate_history_full() {
|
||||
continue;
|
||||
}
|
||||
|
||||
puffs_base__buf1 history_got = {
|
||||
wuffs_base__buf1 history_got = {
|
||||
.ptr = dec.private_impl.f_history,
|
||||
.len = full_history_size,
|
||||
.wi = full_history_size,
|
||||
@@ -438,7 +438,7 @@ void test_puffs_flate_history_full() {
|
||||
FAIL("i=%d: want file is too short", i);
|
||||
return;
|
||||
}
|
||||
puffs_base__buf1 history_want = {
|
||||
wuffs_base__buf1 history_want = {
|
||||
.ptr = global_want_buffer + want.wi - (full_history_size - i),
|
||||
.len = full_history_size,
|
||||
.wi = full_history_size,
|
||||
@@ -449,11 +449,11 @@ void test_puffs_flate_history_full() {
|
||||
}
|
||||
}
|
||||
|
||||
void test_puffs_flate_history_partial() {
|
||||
void test_wuffs_flate_history_partial() {
|
||||
CHECK_FOCUS(__func__);
|
||||
|
||||
puffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
wuffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
wuffs_base__buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
|
||||
golden_test* gt = &flate_pi_gt;
|
||||
if (!read_file(&src, gt->src_filename)) {
|
||||
@@ -466,17 +466,17 @@ void test_puffs_flate_history_partial() {
|
||||
};
|
||||
|
||||
int i;
|
||||
for (i = 0; i < PUFFS_TESTLIB_ARRAY_SIZE(starting_history_indexes); i++) {
|
||||
for (i = 0; i < WUFFS_TESTLIB_ARRAY_SIZE(starting_history_indexes); i++) {
|
||||
uint32_t starting_history_index = starting_history_indexes[i];
|
||||
|
||||
// The flate_pi_gt golden test file decodes to the digits of pi.
|
||||
const char* fragment = "3.14";
|
||||
const uint32_t fragment_length = 4;
|
||||
|
||||
puffs_flate__flate_decoder dec;
|
||||
if (!do_test_puffs_flate_history(i, gt, &src, &got, &dec,
|
||||
wuffs_flate__flate_decoder dec;
|
||||
if (!do_test_wuffs_flate_history(i, gt, &src, &got, &dec,
|
||||
starting_history_index, fragment_length,
|
||||
PUFFS_FLATE__SUSPENSION_SHORT_WRITE)) {
|
||||
WUFFS_FLATE__SUSPENSION_SHORT_WRITE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -508,7 +508,7 @@ void test_puffs_flate_history_partial() {
|
||||
}
|
||||
}
|
||||
|
||||
void test_puffs_flate_table_redirect() {
|
||||
void test_wuffs_flate_table_redirect() {
|
||||
CHECK_FOCUS(__func__);
|
||||
|
||||
// Call init_huff with a Huffman code that looks like:
|
||||
@@ -554,8 +554,8 @@ void test_puffs_flate_table_redirect() {
|
||||
// 1st is the key in the first level table (9 bits).
|
||||
// 2nd is the key in the second level table (variable bits).
|
||||
|
||||
puffs_flate__flate_decoder dec;
|
||||
puffs_flate__flate_decoder__initialize(&dec, PUFFS_VERSION, 0);
|
||||
wuffs_flate__flate_decoder dec;
|
||||
wuffs_flate__flate_decoder__initialize(&dec, WUFFS_VERSION, 0);
|
||||
|
||||
// The initializer should zero out dec's fields, but to be paranoid, we zero
|
||||
// it out explicitly.
|
||||
@@ -578,10 +578,10 @@ void test_puffs_flate_table_redirect() {
|
||||
dec.private_impl.f_code_lengths[n++] = 13;
|
||||
dec.private_impl.f_code_lengths[n++] = 13;
|
||||
|
||||
puffs_flate__status s =
|
||||
puffs_flate__flate_decoder__init_huff(&dec, 0, 0, n, 257);
|
||||
wuffs_flate__status s =
|
||||
wuffs_flate__flate_decoder__init_huff(&dec, 0, 0, n, 257);
|
||||
if (s) {
|
||||
FAIL("%s", puffs_flate__status__string(s));
|
||||
FAIL("%s", wuffs_flate__status__string(s));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -640,11 +640,11 @@ void test_puffs_flate_table_redirect() {
|
||||
}
|
||||
}
|
||||
|
||||
void test_puffs_zlib_checksum_mismatch() {
|
||||
void test_wuffs_zlib_checksum_mismatch() {
|
||||
CHECK_FOCUS(__func__);
|
||||
|
||||
puffs_base__buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
wuffs_base__buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
wuffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
|
||||
if (!read_file(&src, zlib_midsummer_gt.src_filename)) {
|
||||
return;
|
||||
@@ -656,35 +656,35 @@ void test_puffs_zlib_checksum_mismatch() {
|
||||
// Flip a bit in the zlib checksum, which comes at the end of the file.
|
||||
src.ptr[src.wi - 1] ^= 1;
|
||||
|
||||
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};
|
||||
wuffs_flate__zlib_decoder dec;
|
||||
wuffs_flate__zlib_decoder__initialize(&dec, WUFFS_VERSION, 0);
|
||||
wuffs_base__writer1 got_writer = {.buf = &got};
|
||||
wuffs_base__reader1 src_reader = {.buf = &src};
|
||||
|
||||
puffs_flate__status status =
|
||||
puffs_flate__zlib_decoder__decode(&dec, got_writer, src_reader);
|
||||
if (status != PUFFS_FLATE__ERROR_CHECKSUM_MISMATCH) {
|
||||
wuffs_flate__status status =
|
||||
wuffs_flate__zlib_decoder__decode(&dec, got_writer, src_reader);
|
||||
if (status != WUFFS_FLATE__ERROR_CHECKSUM_MISMATCH) {
|
||||
FAIL("status: got %" PRIi32 " (%s), want %" PRIi32 " (%s)", status,
|
||||
puffs_flate__status__string(status),
|
||||
PUFFS_FLATE__ERROR_CHECKSUM_MISMATCH,
|
||||
puffs_flate__status__string(PUFFS_FLATE__ERROR_CHECKSUM_MISMATCH));
|
||||
wuffs_flate__status__string(status),
|
||||
WUFFS_FLATE__ERROR_CHECKSUM_MISMATCH,
|
||||
wuffs_flate__status__string(WUFFS_FLATE__ERROR_CHECKSUM_MISMATCH));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void test_puffs_zlib_decode_midsummer() {
|
||||
void test_wuffs_zlib_decode_midsummer() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(puffs_zlib_decode, &zlib_midsummer_gt, 0, 0);
|
||||
do_test_buf1_buf1(wuffs_zlib_decode, &zlib_midsummer_gt, 0, 0);
|
||||
}
|
||||
|
||||
void test_puffs_zlib_decode_pi() {
|
||||
void test_wuffs_zlib_decode_pi() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_buf1_buf1(puffs_zlib_decode, &zlib_pi_gt, 0, 0);
|
||||
do_test_buf1_buf1(wuffs_zlib_decode, &zlib_pi_gt, 0, 0);
|
||||
}
|
||||
|
||||
// ---------------- Mimic Tests
|
||||
|
||||
#ifdef PUFFS_MIMIC
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
#include "../mimiclib/flate.c"
|
||||
|
||||
@@ -739,21 +739,21 @@ void test_mimic_zlib_decode_pi() {
|
||||
do_test_buf1_buf1(mimic_zlib_decode, &zlib_pi_gt, 0, 0);
|
||||
}
|
||||
|
||||
#endif // PUFFS_MIMIC
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- Checksum Benches
|
||||
|
||||
uint32_t global_puffs_flate_unused_u32;
|
||||
uint32_t global_wuffs_flate_unused_u32;
|
||||
|
||||
const char* puffs_bench_adler32(puffs_base__buf1* dst,
|
||||
puffs_base__buf1* src,
|
||||
const char* wuffs_bench_adler32(wuffs_base__buf1* dst,
|
||||
wuffs_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){
|
||||
wuffs_flate__adler32 checksum;
|
||||
wuffs_flate__adler32__initialize(&checksum, WUFFS_VERSION, 0);
|
||||
global_wuffs_flate_unused_u32 =
|
||||
wuffs_flate__adler32__update(&checksum, ((wuffs_base__slice_u8){
|
||||
.ptr = src->ptr + src->ri,
|
||||
.len = src->wi - src->ri,
|
||||
}));
|
||||
@@ -761,49 +761,49 @@ const char* puffs_bench_adler32(puffs_base__buf1* dst,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void bench_puffs_adler32_10k() {
|
||||
void bench_wuffs_adler32_10k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_buf1_buf1(puffs_bench_adler32, tc_src, &checksum_midsummer_gt, 0, 0,
|
||||
do_bench_buf1_buf1(wuffs_bench_adler32, tc_src, &checksum_midsummer_gt, 0, 0,
|
||||
150000);
|
||||
}
|
||||
|
||||
void bench_puffs_adler32_100k() {
|
||||
void bench_wuffs_adler32_100k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_buf1_buf1(puffs_bench_adler32, tc_src, &checksum_pi_gt, 0, 0, 15000);
|
||||
do_bench_buf1_buf1(wuffs_bench_adler32, tc_src, &checksum_pi_gt, 0, 0, 15000);
|
||||
}
|
||||
|
||||
// ---------------- Flate Benches
|
||||
|
||||
void bench_puffs_flate_decode_1k() {
|
||||
void bench_wuffs_flate_decode_1k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_buf1_buf1(puffs_flate_decode, tc_dst, &flate_romeo_gt, 0, 0, 200000);
|
||||
do_bench_buf1_buf1(wuffs_flate_decode, tc_dst, &flate_romeo_gt, 0, 0, 200000);
|
||||
}
|
||||
|
||||
void bench_puffs_flate_decode_10k() {
|
||||
void bench_wuffs_flate_decode_10k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_buf1_buf1(puffs_flate_decode, tc_dst, &flate_midsummer_gt, 0, 0,
|
||||
do_bench_buf1_buf1(wuffs_flate_decode, tc_dst, &flate_midsummer_gt, 0, 0,
|
||||
30000);
|
||||
}
|
||||
|
||||
void bench_puffs_flate_decode_100k() {
|
||||
void bench_wuffs_flate_decode_100k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_buf1_buf1(puffs_flate_decode, tc_dst, &flate_pi_gt, 0, 0, 3000);
|
||||
do_bench_buf1_buf1(wuffs_flate_decode, tc_dst, &flate_pi_gt, 0, 0, 3000);
|
||||
}
|
||||
|
||||
void bench_puffs_zlib_decode_10k() {
|
||||
void bench_wuffs_zlib_decode_10k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_buf1_buf1(puffs_zlib_decode, tc_dst, &zlib_midsummer_gt, 0, 0,
|
||||
do_bench_buf1_buf1(wuffs_zlib_decode, tc_dst, &zlib_midsummer_gt, 0, 0,
|
||||
30000);
|
||||
}
|
||||
|
||||
void bench_puffs_zlib_decode_100k() {
|
||||
void bench_wuffs_zlib_decode_100k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_buf1_buf1(puffs_zlib_decode, tc_dst, &zlib_pi_gt, 0, 0, 3000);
|
||||
do_bench_buf1_buf1(wuffs_zlib_decode, tc_dst, &zlib_pi_gt, 0, 0, 3000);
|
||||
}
|
||||
|
||||
// ---------------- Mimic Benches
|
||||
|
||||
#ifdef PUFFS_MIMIC
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
void bench_mimic_adler32_10k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
@@ -865,32 +865,32 @@ void bench_mimic_zlib_decode_100k() {
|
||||
do_bench_buf1_buf1(mimic_zlib_decode, tc_dst, &zlib_pi_gt, 0, 0, 3000);
|
||||
}
|
||||
|
||||
#endif // PUFFS_MIMIC
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- Manifest
|
||||
|
||||
// The empty comments forces clang-format to place one element per line.
|
||||
proc tests[] = {
|
||||
// Flate Tests
|
||||
test_puffs_adler32, //
|
||||
test_puffs_flate_decode_256_bytes, //
|
||||
test_puffs_flate_decode_flate_backref_crosses_blocks, //
|
||||
test_puffs_flate_decode_midsummer, //
|
||||
test_puffs_flate_decode_pi, //
|
||||
test_puffs_flate_decode_pi_many_big_reads, //
|
||||
test_puffs_flate_decode_pi_many_medium_reads, //
|
||||
test_puffs_flate_decode_pi_many_small_writes_reads, //
|
||||
test_puffs_flate_decode_romeo, //
|
||||
test_puffs_flate_decode_romeo_fixed, //
|
||||
test_puffs_flate_decode_split_src, //
|
||||
test_puffs_flate_history_full, //
|
||||
test_puffs_flate_history_partial, //
|
||||
test_puffs_flate_table_redirect, //
|
||||
test_puffs_zlib_checksum_mismatch, //
|
||||
test_puffs_zlib_decode_midsummer, //
|
||||
test_puffs_zlib_decode_pi, //
|
||||
test_wuffs_adler32, //
|
||||
test_wuffs_flate_decode_256_bytes, //
|
||||
test_wuffs_flate_decode_flate_backref_crosses_blocks, //
|
||||
test_wuffs_flate_decode_midsummer, //
|
||||
test_wuffs_flate_decode_pi, //
|
||||
test_wuffs_flate_decode_pi_many_big_reads, //
|
||||
test_wuffs_flate_decode_pi_many_medium_reads, //
|
||||
test_wuffs_flate_decode_pi_many_small_writes_reads, //
|
||||
test_wuffs_flate_decode_romeo, //
|
||||
test_wuffs_flate_decode_romeo_fixed, //
|
||||
test_wuffs_flate_decode_split_src, //
|
||||
test_wuffs_flate_history_full, //
|
||||
test_wuffs_flate_history_partial, //
|
||||
test_wuffs_flate_table_redirect, //
|
||||
test_wuffs_zlib_checksum_mismatch, //
|
||||
test_wuffs_zlib_decode_midsummer, //
|
||||
test_wuffs_zlib_decode_pi, //
|
||||
|
||||
#ifdef PUFFS_MIMIC
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
// Mimic Tests
|
||||
test_mimic_flate_decode_256_bytes, //
|
||||
@@ -904,7 +904,7 @@ proc tests[] = {
|
||||
test_mimic_zlib_decode_midsummer, //
|
||||
test_mimic_zlib_decode_pi, //
|
||||
|
||||
#endif // PUFFS_MIMIC
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
@@ -912,15 +912,15 @@ proc tests[] = {
|
||||
// The empty comments forces clang-format to place one element per line.
|
||||
proc benches[] = {
|
||||
// Flate Benches
|
||||
bench_puffs_adler32_10k, //
|
||||
bench_puffs_adler32_100k, //
|
||||
bench_puffs_flate_decode_1k, //
|
||||
bench_puffs_flate_decode_10k, //
|
||||
bench_puffs_flate_decode_100k, //
|
||||
bench_puffs_zlib_decode_10k, //
|
||||
bench_puffs_zlib_decode_100k, //
|
||||
bench_wuffs_adler32_10k, //
|
||||
bench_wuffs_adler32_100k, //
|
||||
bench_wuffs_flate_decode_1k, //
|
||||
bench_wuffs_flate_decode_10k, //
|
||||
bench_wuffs_flate_decode_100k, //
|
||||
bench_wuffs_zlib_decode_10k, //
|
||||
bench_wuffs_zlib_decode_100k, //
|
||||
|
||||
#ifdef PUFFS_MIMIC
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
// Mimic Benches
|
||||
bench_mimic_adler32_10k, //
|
||||
@@ -935,7 +935,7 @@ proc benches[] = {
|
||||
bench_mimic_zlib_decode_10k, //
|
||||
bench_mimic_zlib_decode_100k, //
|
||||
|
||||
#endif // PUFFS_MIMIC
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
||||
+187
-187
@@ -13,9 +13,9 @@
|
||||
// limitations under the License.
|
||||
|
||||
/*
|
||||
This test program is typically run indirectly, by the "puffs test" or "puffs
|
||||
This test program is typically run indirectly, by the "wuffs test" or "wuffs
|
||||
bench" commands. These commands take an optional "-mimic" flag to check that
|
||||
Puffs' output mimics (i.e. exactly matches) other libraries' output, such as
|
||||
Wuffs' output mimics (i.e. exactly matches) other libraries' output, such as
|
||||
giflib for GIF, libpng for PNG, etc.
|
||||
|
||||
To manually run this test:
|
||||
@@ -27,15 +27,15 @@ done
|
||||
|
||||
Each edition should print "PASS", amongst other information, and exit(0).
|
||||
|
||||
Add the "puffs mimic cflags" (everything after the colon below) to the C
|
||||
Add the "wuffs mimic cflags" (everything after the colon below) to the C
|
||||
compiler flags (after the .c file) to run the mimic tests.
|
||||
|
||||
To manually run the benchmarks, replace "-Wall -Werror" with "-O3" and replace
|
||||
the first "./a.out" with "./a.out -bench". Combine these changes with the
|
||||
"puffs mimic cflags" to run the mimic benchmarks.
|
||||
"wuffs mimic cflags" to run the mimic benchmarks.
|
||||
*/
|
||||
|
||||
// !! puffs mimic cflags: -DPUFFS_MIMIC -lgif
|
||||
// !! wuffs mimic cflags: -DWUFFS_MIMIC -lgif
|
||||
|
||||
#include "../../../gen/c/std/gif.c"
|
||||
#include "../testlib/testlib.c"
|
||||
@@ -44,70 +44,70 @@ the first "./a.out" with "./a.out -bench". Combine these changes with the
|
||||
|
||||
void test_basic_bad_argument_out_of_range() {
|
||||
CHECK_FOCUS(__func__);
|
||||
puffs_gif__lzw_decoder dec;
|
||||
puffs_gif__lzw_decoder__initialize(&dec, PUFFS_VERSION, 0);
|
||||
wuffs_gif__lzw_decoder dec;
|
||||
wuffs_gif__lzw_decoder__initialize(&dec, WUFFS_VERSION, 0);
|
||||
|
||||
// Setting to 8 is in the [2..8] range.
|
||||
puffs_gif__lzw_decoder__set_literal_width(&dec, 8);
|
||||
if (dec.private_impl.status != PUFFS_GIF__STATUS_OK) {
|
||||
wuffs_gif__lzw_decoder__set_literal_width(&dec, 8);
|
||||
if (dec.private_impl.status != WUFFS_GIF__STATUS_OK) {
|
||||
FAIL("status: got %d, want %d", dec.private_impl.status,
|
||||
PUFFS_GIF__STATUS_OK);
|
||||
WUFFS_GIF__STATUS_OK);
|
||||
}
|
||||
|
||||
// Setting to 999 is out of range.
|
||||
puffs_gif__lzw_decoder__set_literal_width(&dec, 999);
|
||||
if (dec.private_impl.status != PUFFS_GIF__ERROR_BAD_ARGUMENT) {
|
||||
wuffs_gif__lzw_decoder__set_literal_width(&dec, 999);
|
||||
if (dec.private_impl.status != WUFFS_GIF__ERROR_BAD_ARGUMENT) {
|
||||
FAIL("status: got %d, want %d", dec.private_impl.status,
|
||||
PUFFS_GIF__ERROR_BAD_ARGUMENT);
|
||||
WUFFS_GIF__ERROR_BAD_ARGUMENT);
|
||||
}
|
||||
|
||||
// That error status code should be sticky.
|
||||
puffs_gif__lzw_decoder__set_literal_width(&dec, 8);
|
||||
if (dec.private_impl.status != PUFFS_GIF__ERROR_BAD_ARGUMENT) {
|
||||
wuffs_gif__lzw_decoder__set_literal_width(&dec, 8);
|
||||
if (dec.private_impl.status != WUFFS_GIF__ERROR_BAD_ARGUMENT) {
|
||||
FAIL("status: got %d, want %d", dec.private_impl.status,
|
||||
PUFFS_GIF__ERROR_BAD_ARGUMENT);
|
||||
WUFFS_GIF__ERROR_BAD_ARGUMENT);
|
||||
}
|
||||
}
|
||||
|
||||
void test_basic_bad_receiver() {
|
||||
CHECK_FOCUS(__func__);
|
||||
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);
|
||||
wuffs_base__writer1 dst = {0};
|
||||
wuffs_base__reader1 src = {0};
|
||||
wuffs_gif__status status = wuffs_gif__lzw_decoder__decode(NULL, dst, src);
|
||||
if (status != WUFFS_GIF__ERROR_BAD_RECEIVER) {
|
||||
FAIL("status: got %d, want %d", status, WUFFS_GIF__ERROR_BAD_RECEIVER);
|
||||
}
|
||||
}
|
||||
|
||||
void test_basic_initializer_not_called() {
|
||||
CHECK_FOCUS(__func__);
|
||||
puffs_gif__lzw_decoder dec = {{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) {
|
||||
wuffs_gif__lzw_decoder dec = {{0}};
|
||||
wuffs_base__writer1 dst = {0};
|
||||
wuffs_base__reader1 src = {0};
|
||||
wuffs_gif__status status = wuffs_gif__lzw_decoder__decode(&dec, dst, src);
|
||||
if (status != WUFFS_GIF__ERROR_INITIALIZER_NOT_CALLED) {
|
||||
FAIL("status: got %d, want %d", status,
|
||||
PUFFS_GIF__ERROR_INITIALIZER_NOT_CALLED);
|
||||
WUFFS_GIF__ERROR_INITIALIZER_NOT_CALLED);
|
||||
}
|
||||
}
|
||||
|
||||
void test_basic_puffs_version_bad() {
|
||||
void test_basic_wuffs_version_bad() {
|
||||
CHECK_FOCUS(__func__);
|
||||
puffs_gif__lzw_decoder dec;
|
||||
puffs_gif__lzw_decoder__initialize(&dec, 0, 0); // 0 is not PUFFS_VERSION.
|
||||
if (dec.private_impl.status != PUFFS_GIF__ERROR_BAD_PUFFS_VERSION) {
|
||||
wuffs_gif__lzw_decoder dec;
|
||||
wuffs_gif__lzw_decoder__initialize(&dec, 0, 0); // 0 is not WUFFS_VERSION.
|
||||
if (dec.private_impl.status != WUFFS_GIF__ERROR_BAD_WUFFS_VERSION) {
|
||||
FAIL("status: got %d, want %d", dec.private_impl.status,
|
||||
PUFFS_GIF__ERROR_BAD_PUFFS_VERSION);
|
||||
WUFFS_GIF__ERROR_BAD_WUFFS_VERSION);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void test_basic_puffs_version_good() {
|
||||
void test_basic_wuffs_version_good() {
|
||||
CHECK_FOCUS(__func__);
|
||||
puffs_gif__lzw_decoder dec;
|
||||
puffs_gif__lzw_decoder__initialize(&dec, PUFFS_VERSION, 0);
|
||||
if (dec.private_impl.magic != PUFFS_BASE__MAGIC) {
|
||||
FAIL("magic: got %u, want %u", dec.private_impl.magic, PUFFS_BASE__MAGIC);
|
||||
wuffs_gif__lzw_decoder dec;
|
||||
wuffs_gif__lzw_decoder__initialize(&dec, WUFFS_VERSION, 0);
|
||||
if (dec.private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
FAIL("magic: got %u, want %u", dec.private_impl.magic, WUFFS_BASE__MAGIC);
|
||||
return;
|
||||
}
|
||||
if (dec.private_impl.f_literal_width != 8) {
|
||||
@@ -119,19 +119,19 @@ void test_basic_puffs_version_good() {
|
||||
|
||||
void test_basic_status_is_error() {
|
||||
CHECK_FOCUS(__func__);
|
||||
if (puffs_gif__status__is_error(PUFFS_GIF__STATUS_OK)) {
|
||||
if (wuffs_gif__status__is_error(WUFFS_GIF__STATUS_OK)) {
|
||||
FAIL("is_error(OK) returned true");
|
||||
return;
|
||||
}
|
||||
if (!puffs_gif__status__is_error(PUFFS_GIF__ERROR_BAD_PUFFS_VERSION)) {
|
||||
FAIL("is_error(BAD_PUFFS_VERSION) returned false");
|
||||
if (!wuffs_gif__status__is_error(WUFFS_GIF__ERROR_BAD_WUFFS_VERSION)) {
|
||||
FAIL("is_error(BAD_WUFFS_VERSION) returned false");
|
||||
return;
|
||||
}
|
||||
if (puffs_gif__status__is_error(PUFFS_GIF__SUSPENSION_SHORT_WRITE)) {
|
||||
if (wuffs_gif__status__is_error(WUFFS_GIF__SUSPENSION_SHORT_WRITE)) {
|
||||
FAIL("is_error(SHORT_WRITE) returned true");
|
||||
return;
|
||||
}
|
||||
if (!puffs_gif__status__is_error(PUFFS_GIF__ERROR_LZW_CODE_IS_OUT_OF_RANGE)) {
|
||||
if (!wuffs_gif__status__is_error(WUFFS_GIF__ERROR_LZW_CODE_IS_OUT_OF_RANGE)) {
|
||||
FAIL("is_error(LZW_CODE_IS_OUT_OF_RANGE) returned false");
|
||||
return;
|
||||
}
|
||||
@@ -139,33 +139,33 @@ void test_basic_status_is_error() {
|
||||
|
||||
void test_basic_status_strings() {
|
||||
CHECK_FOCUS(__func__);
|
||||
const char* s0 = puffs_gif__status__string(PUFFS_GIF__STATUS_OK);
|
||||
const char* s0 = wuffs_gif__status__string(WUFFS_GIF__STATUS_OK);
|
||||
const char* t0 = "gif: ok";
|
||||
if (strcmp(s0, t0)) {
|
||||
FAIL("got \"%s\", want \"%s\"", s0, t0);
|
||||
return;
|
||||
}
|
||||
const char* s1 =
|
||||
puffs_gif__status__string(PUFFS_GIF__ERROR_BAD_PUFFS_VERSION);
|
||||
const char* t1 = "gif: bad puffs version";
|
||||
wuffs_gif__status__string(WUFFS_GIF__ERROR_BAD_WUFFS_VERSION);
|
||||
const char* t1 = "gif: bad wuffs version";
|
||||
if (strcmp(s1, t1)) {
|
||||
FAIL("got \"%s\", want \"%s\"", s1, t1);
|
||||
return;
|
||||
}
|
||||
const char* s2 = puffs_gif__status__string(PUFFS_GIF__SUSPENSION_SHORT_WRITE);
|
||||
const char* s2 = wuffs_gif__status__string(WUFFS_GIF__SUSPENSION_SHORT_WRITE);
|
||||
const char* t2 = "gif: short write";
|
||||
if (strcmp(s2, t2)) {
|
||||
FAIL("got \"%s\", want \"%s\"", s2, t2);
|
||||
return;
|
||||
}
|
||||
const char* s3 =
|
||||
puffs_gif__status__string(PUFFS_GIF__ERROR_LZW_CODE_IS_OUT_OF_RANGE);
|
||||
wuffs_gif__status__string(WUFFS_GIF__ERROR_LZW_CODE_IS_OUT_OF_RANGE);
|
||||
const char* t3 = "gif: LZW code is out of range";
|
||||
if (strcmp(s3, t3)) {
|
||||
FAIL("got \"%s\", want \"%s\"", s3, t3);
|
||||
return;
|
||||
}
|
||||
const char* s4 = puffs_gif__status__string(-254);
|
||||
const char* s4 = wuffs_gif__status__string(-254);
|
||||
const char* t4 = "gif: unknown status";
|
||||
if (strcmp(s4, t4)) {
|
||||
FAIL("got \"%s\", want \"%s\"", s4, t4);
|
||||
@@ -175,31 +175,31 @@ void test_basic_status_strings() {
|
||||
|
||||
void test_basic_sub_struct_initializer() {
|
||||
CHECK_FOCUS(__func__);
|
||||
puffs_gif__decoder dec;
|
||||
puffs_gif__decoder__initialize(&dec, PUFFS_VERSION, 0);
|
||||
if (dec.private_impl.magic != PUFFS_BASE__MAGIC) {
|
||||
wuffs_gif__decoder dec;
|
||||
wuffs_gif__decoder__initialize(&dec, WUFFS_VERSION, 0);
|
||||
if (dec.private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
FAIL("outer magic: got %u, want %u", dec.private_impl.magic,
|
||||
PUFFS_BASE__MAGIC);
|
||||
WUFFS_BASE__MAGIC);
|
||||
return;
|
||||
}
|
||||
if (dec.private_impl.f_lzw.private_impl.magic != PUFFS_BASE__MAGIC) {
|
||||
if (dec.private_impl.f_lzw.private_impl.magic != WUFFS_BASE__MAGIC) {
|
||||
FAIL("inner magic: got %u, want %u",
|
||||
dec.private_impl.f_lzw.private_impl.magic, PUFFS_BASE__MAGIC);
|
||||
dec.private_impl.f_lzw.private_impl.magic, WUFFS_BASE__MAGIC);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------- LZW Tests
|
||||
|
||||
bool do_test_puffs_gif_lzw_decode(const char* src_filename,
|
||||
bool do_test_wuffs_gif_lzw_decode(const char* src_filename,
|
||||
uint64_t src_size,
|
||||
const char* want_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};
|
||||
wuffs_base__buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
wuffs_base__buf1 want = {.ptr = global_want_buffer, .len = BUFFER_SIZE};
|
||||
wuffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
|
||||
if (!read_file(&src, src_filename)) {
|
||||
return false;
|
||||
@@ -224,20 +224,20 @@ bool do_test_puffs_gif_lzw_decode(const char* src_filename,
|
||||
return false;
|
||||
}
|
||||
|
||||
puffs_gif__lzw_decoder dec;
|
||||
puffs_gif__lzw_decoder__initialize(&dec, PUFFS_VERSION, 0);
|
||||
puffs_gif__lzw_decoder__set_literal_width(&dec, literal_width);
|
||||
wuffs_gif__lzw_decoder dec;
|
||||
wuffs_gif__lzw_decoder__initialize(&dec, WUFFS_VERSION, 0);
|
||||
wuffs_gif__lzw_decoder__set_literal_width(&dec, literal_width);
|
||||
int num_iters = 0;
|
||||
uint64_t wlim = 0;
|
||||
uint64_t rlim = 0;
|
||||
while (true) {
|
||||
num_iters++;
|
||||
puffs_base__writer1 got_writer = {.buf = &got};
|
||||
wuffs_base__writer1 got_writer = {.buf = &got};
|
||||
if (wlimit) {
|
||||
wlim = wlimit;
|
||||
got_writer.private_impl.limit.ptr_to_len = &wlim;
|
||||
}
|
||||
puffs_base__reader1 src_reader = {.buf = &src};
|
||||
wuffs_base__reader1 src_reader = {.buf = &src};
|
||||
if (rlimit) {
|
||||
rlim = rlimit;
|
||||
src_reader.private_impl.limit.ptr_to_len = &rlim;
|
||||
@@ -245,24 +245,24 @@ bool do_test_puffs_gif_lzw_decode(const char* src_filename,
|
||||
size_t old_wi = got.wi;
|
||||
size_t old_ri = src.ri;
|
||||
|
||||
puffs_gif__status status =
|
||||
puffs_gif__lzw_decoder__decode(&dec, got_writer, src_reader);
|
||||
if (status == PUFFS_GIF__STATUS_OK) {
|
||||
wuffs_gif__status status =
|
||||
wuffs_gif__lzw_decoder__decode(&dec, got_writer, src_reader);
|
||||
if (status == WUFFS_GIF__STATUS_OK) {
|
||||
if (src.ri != src.wi) {
|
||||
FAIL("decode returned ok but src was not exhausted");
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ((status != PUFFS_GIF__SUSPENSION_SHORT_READ) &&
|
||||
(status != PUFFS_GIF__SUSPENSION_SHORT_WRITE)) {
|
||||
if ((status != WUFFS_GIF__SUSPENSION_SHORT_READ) &&
|
||||
(status != WUFFS_GIF__SUSPENSION_SHORT_WRITE)) {
|
||||
FAIL("status: got %" PRIi32 " (%s), want %" PRIi32 " (%s) or %" PRIi32
|
||||
" (%s)",
|
||||
status, puffs_gif__status__string(status),
|
||||
PUFFS_GIF__SUSPENSION_SHORT_READ,
|
||||
puffs_gif__status__string(PUFFS_GIF__SUSPENSION_SHORT_READ),
|
||||
PUFFS_GIF__SUSPENSION_SHORT_WRITE,
|
||||
puffs_gif__status__string(PUFFS_GIF__SUSPENSION_SHORT_WRITE));
|
||||
status, wuffs_gif__status__string(status),
|
||||
WUFFS_GIF__SUSPENSION_SHORT_READ,
|
||||
wuffs_gif__status__string(WUFFS_GIF__SUSPENSION_SHORT_READ),
|
||||
WUFFS_GIF__SUSPENSION_SHORT_WRITE,
|
||||
wuffs_gif__status__string(WUFFS_GIF__SUSPENSION_SHORT_WRITE));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -295,47 +295,47 @@ bool do_test_puffs_gif_lzw_decode(const char* src_filename,
|
||||
return buf1s_equal("", &got, &want);
|
||||
}
|
||||
|
||||
void test_puffs_gif_lzw_decode_many_big_reads() {
|
||||
void test_wuffs_gif_lzw_decode_many_big_reads() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_puffs_gif_lzw_decode("../../testdata/bricks-gray.indexes.giflzw",
|
||||
do_test_wuffs_gif_lzw_decode("../../testdata/bricks-gray.indexes.giflzw",
|
||||
14731, "../../testdata/bricks-gray.indexes",
|
||||
19200, 0, 4096);
|
||||
}
|
||||
|
||||
void test_puffs_gif_lzw_decode_many_small_writes_reads() {
|
||||
void test_wuffs_gif_lzw_decode_many_small_writes_reads() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_puffs_gif_lzw_decode("../../testdata/bricks-gray.indexes.giflzw",
|
||||
do_test_wuffs_gif_lzw_decode("../../testdata/bricks-gray.indexes.giflzw",
|
||||
14731, "../../testdata/bricks-gray.indexes",
|
||||
19200, 41, 43);
|
||||
}
|
||||
|
||||
void test_puffs_gif_lzw_decode_bricks_dither() {
|
||||
void test_wuffs_gif_lzw_decode_bricks_dither() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_puffs_gif_lzw_decode("../../testdata/bricks-dither.indexes.giflzw",
|
||||
do_test_wuffs_gif_lzw_decode("../../testdata/bricks-dither.indexes.giflzw",
|
||||
14923, "../../testdata/bricks-dither.indexes",
|
||||
19200, 0, 0);
|
||||
}
|
||||
|
||||
void test_puffs_gif_lzw_decode_bricks_nodither() {
|
||||
void test_wuffs_gif_lzw_decode_bricks_nodither() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_puffs_gif_lzw_decode("../../testdata/bricks-nodither.indexes.giflzw",
|
||||
do_test_wuffs_gif_lzw_decode("../../testdata/bricks-nodither.indexes.giflzw",
|
||||
13382, "../../testdata/bricks-nodither.indexes",
|
||||
19200, 0, 0);
|
||||
}
|
||||
|
||||
void test_puffs_gif_lzw_decode_pi() {
|
||||
void test_wuffs_gif_lzw_decode_pi() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_puffs_gif_lzw_decode("../../testdata/pi.txt.giflzw", 50550,
|
||||
do_test_wuffs_gif_lzw_decode("../../testdata/pi.txt.giflzw", 50550,
|
||||
"../../testdata/pi.txt", 100003, 0, 0);
|
||||
}
|
||||
|
||||
// ---------------- 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};
|
||||
bool do_bench_wuffs_gif_lzw_decode(const char* filename, uint64_t reps) {
|
||||
wuffs_base__buf1 dst = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
wuffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
wuffs_base__writer1 dst_writer = {.buf = &dst};
|
||||
wuffs_base__reader1 src_reader = {.buf = &src};
|
||||
|
||||
if (!read_file(&src, filename)) {
|
||||
return false;
|
||||
@@ -356,12 +356,12 @@ bool do_bench_puffs_gif_lzw_decode(const char* filename, uint64_t reps) {
|
||||
for (i = 0; i < reps; i++) {
|
||||
dst.wi = 0;
|
||||
src.ri = 1; // Skip the literal width.
|
||||
puffs_gif__lzw_decoder dec;
|
||||
puffs_gif__lzw_decoder__initialize(&dec, PUFFS_VERSION, 0);
|
||||
puffs_gif__status s =
|
||||
puffs_gif__lzw_decoder__decode(&dec, dst_writer, src_reader);
|
||||
wuffs_gif__lzw_decoder dec;
|
||||
wuffs_gif__lzw_decoder__initialize(&dec, WUFFS_VERSION, 0);
|
||||
wuffs_gif__status s =
|
||||
wuffs_gif__lzw_decoder__decode(&dec, dst_writer, src_reader);
|
||||
if (s) {
|
||||
FAIL("decode: %" PRIi32 " (%s)", s, puffs_gif__status__string(s));
|
||||
FAIL("decode: %" PRIi32 " (%s)", s, wuffs_gif__status__string(s));
|
||||
return false;
|
||||
}
|
||||
n_bytes += dst.wi;
|
||||
@@ -370,57 +370,57 @@ bool do_bench_puffs_gif_lzw_decode(const char* filename, uint64_t reps) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void bench_puffs_gif_lzw_decode_20k() {
|
||||
void bench_wuffs_gif_lzw_decode_20k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_puffs_gif_lzw_decode("../../testdata/bricks-gray.indexes.giflzw",
|
||||
do_bench_wuffs_gif_lzw_decode("../../testdata/bricks-gray.indexes.giflzw",
|
||||
5000);
|
||||
}
|
||||
|
||||
void bench_puffs_gif_lzw_decode_100k() {
|
||||
void bench_wuffs_gif_lzw_decode_100k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_puffs_gif_lzw_decode("../../testdata/pi.txt.giflzw", 1000);
|
||||
do_bench_wuffs_gif_lzw_decode("../../testdata/pi.txt.giflzw", 1000);
|
||||
}
|
||||
|
||||
// ---------------- GIF Tests
|
||||
|
||||
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_gif__status s =
|
||||
puffs_gif__decoder__decode(&dec, dst_writer, src_reader);
|
||||
const char* wuffs_gif_decode(wuffs_base__buf1* dst, wuffs_base__buf1* src) {
|
||||
wuffs_gif__decoder dec;
|
||||
wuffs_gif__decoder__initialize(&dec, WUFFS_VERSION, 0);
|
||||
wuffs_base__writer1 dst_writer = {.buf = dst};
|
||||
wuffs_base__reader1 src_reader = {.buf = src};
|
||||
wuffs_gif__status s =
|
||||
wuffs_gif__decoder__decode(&dec, dst_writer, src_reader);
|
||||
if (s) {
|
||||
return puffs_gif__status__string(s);
|
||||
return wuffs_gif__status__string(s);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool do_test_puffs_gif_decode(const char* filename,
|
||||
bool do_test_wuffs_gif_decode(const char* filename,
|
||||
const char* palette_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};
|
||||
wuffs_base__buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
wuffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
|
||||
if (!read_file(&src, filename)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
puffs_gif__decoder dec;
|
||||
puffs_gif__decoder__initialize(&dec, PUFFS_VERSION, 0);
|
||||
wuffs_gif__decoder dec;
|
||||
wuffs_gif__decoder__initialize(&dec, WUFFS_VERSION, 0);
|
||||
int num_iters = 0;
|
||||
uint64_t wlim = 0;
|
||||
uint64_t rlim = 0;
|
||||
while (true) {
|
||||
num_iters++;
|
||||
puffs_base__writer1 got_writer = {.buf = &got};
|
||||
wuffs_base__writer1 got_writer = {.buf = &got};
|
||||
if (wlimit) {
|
||||
wlim = wlimit;
|
||||
got_writer.private_impl.limit.ptr_to_len = &wlim;
|
||||
}
|
||||
puffs_base__reader1 src_reader = {.buf = &src};
|
||||
wuffs_base__reader1 src_reader = {.buf = &src};
|
||||
if (rlimit) {
|
||||
rlim = rlimit;
|
||||
src_reader.private_impl.limit.ptr_to_len = &rlim;
|
||||
@@ -428,24 +428,24 @@ bool do_test_puffs_gif_decode(const char* filename,
|
||||
size_t old_wi = got.wi;
|
||||
size_t old_ri = src.ri;
|
||||
|
||||
puffs_gif__status status =
|
||||
puffs_gif__decoder__decode(&dec, got_writer, src_reader);
|
||||
if (status == PUFFS_GIF__STATUS_OK) {
|
||||
wuffs_gif__status status =
|
||||
wuffs_gif__decoder__decode(&dec, got_writer, src_reader);
|
||||
if (status == WUFFS_GIF__STATUS_OK) {
|
||||
if (src.ri != src.wi) {
|
||||
FAIL("decode returned ok but src was not exhausted");
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ((status != PUFFS_GIF__SUSPENSION_SHORT_READ) &&
|
||||
(status != PUFFS_GIF__SUSPENSION_SHORT_WRITE)) {
|
||||
if ((status != WUFFS_GIF__SUSPENSION_SHORT_READ) &&
|
||||
(status != WUFFS_GIF__SUSPENSION_SHORT_WRITE)) {
|
||||
FAIL("status: got %" PRIi32 " (%s), want %" PRIi32 " (%s) or %" PRIi32
|
||||
" (%s)",
|
||||
status, puffs_gif__status__string(status),
|
||||
PUFFS_GIF__SUSPENSION_SHORT_READ,
|
||||
puffs_gif__status__string(PUFFS_GIF__SUSPENSION_SHORT_READ),
|
||||
PUFFS_GIF__SUSPENSION_SHORT_WRITE,
|
||||
puffs_gif__status__string(PUFFS_GIF__SUSPENSION_SHORT_WRITE));
|
||||
status, wuffs_gif__status__string(status),
|
||||
WUFFS_GIF__SUSPENSION_SHORT_READ,
|
||||
wuffs_gif__status__string(WUFFS_GIF__SUSPENSION_SHORT_READ),
|
||||
WUFFS_GIF__SUSPENSION_SHORT_WRITE,
|
||||
wuffs_gif__status__string(WUFFS_GIF__SUSPENSION_SHORT_WRITE));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -486,8 +486,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};
|
||||
wuffs_base__buf1 pal_got = {.ptr = dec.private_impl.f_gct, .len = 3 * 256};
|
||||
wuffs_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;
|
||||
@@ -496,90 +496,90 @@ bool do_test_puffs_gif_decode(const char* filename,
|
||||
return false;
|
||||
}
|
||||
|
||||
puffs_base__buf1 ind_want = {.ptr = global_want_buffer, .len = BUFFER_SIZE};
|
||||
wuffs_base__buf1 ind_want = {.ptr = global_want_buffer, .len = BUFFER_SIZE};
|
||||
if (!read_file(&ind_want, indexes_filename)) {
|
||||
return false;
|
||||
}
|
||||
return buf1s_equal("indexes ", &got, &ind_want);
|
||||
}
|
||||
|
||||
void test_puffs_gif_decode_input_is_a_gif() {
|
||||
void test_wuffs_gif_decode_input_is_a_gif() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_puffs_gif_decode("../../testdata/bricks-dither.gif",
|
||||
do_test_wuffs_gif_decode("../../testdata/bricks-dither.gif",
|
||||
"../../testdata/bricks-dither.palette",
|
||||
"../../testdata/bricks-dither.indexes", 0, 0);
|
||||
}
|
||||
|
||||
void test_puffs_gif_decode_input_is_a_gif_many_big_reads() {
|
||||
void test_wuffs_gif_decode_input_is_a_gif_many_big_reads() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_puffs_gif_decode("../../testdata/bricks-dither.gif",
|
||||
do_test_wuffs_gif_decode("../../testdata/bricks-dither.gif",
|
||||
"../../testdata/bricks-dither.palette",
|
||||
"../../testdata/bricks-dither.indexes", 0, 4096);
|
||||
}
|
||||
|
||||
void test_puffs_gif_decode_input_is_a_gif_many_medium_reads() {
|
||||
void test_wuffs_gif_decode_input_is_a_gif_many_medium_reads() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_puffs_gif_decode("../../testdata/bricks-dither.gif",
|
||||
do_test_wuffs_gif_decode("../../testdata/bricks-dither.gif",
|
||||
"../../testdata/bricks-dither.palette",
|
||||
"../../testdata/bricks-dither.indexes", 0,
|
||||
787); // 787 tickles being in the middle of a
|
||||
// decode_extension skip32 call.
|
||||
}
|
||||
|
||||
void test_puffs_gif_decode_input_is_a_gif_many_small_writes_reads() {
|
||||
void test_wuffs_gif_decode_input_is_a_gif_many_small_writes_reads() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_test_puffs_gif_decode("../../testdata/bricks-dither.gif",
|
||||
do_test_wuffs_gif_decode("../../testdata/bricks-dither.gif",
|
||||
"../../testdata/bricks-dither.palette",
|
||||
"../../testdata/bricks-dither.indexes", 11, 13);
|
||||
}
|
||||
|
||||
void test_puffs_gif_decode_input_is_a_png() {
|
||||
void test_wuffs_gif_decode_input_is_a_png() {
|
||||
CHECK_FOCUS(__func__);
|
||||
|
||||
puffs_base__buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
puffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
wuffs_base__buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
wuffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
|
||||
if (!read_file(&src, "../../testdata/bricks-dither.png")) {
|
||||
return;
|
||||
}
|
||||
|
||||
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};
|
||||
wuffs_gif__decoder dec;
|
||||
wuffs_gif__decoder__initialize(&dec, WUFFS_VERSION, 0);
|
||||
wuffs_base__writer1 got_writer = {.buf = &got};
|
||||
wuffs_base__reader1 src_reader = {.buf = &src};
|
||||
|
||||
puffs_gif__status status =
|
||||
puffs_gif__decoder__decode(&dec, got_writer, src_reader);
|
||||
if (status != PUFFS_GIF__ERROR_BAD_GIF_HEADER) {
|
||||
wuffs_gif__status status =
|
||||
wuffs_gif__decoder__decode(&dec, got_writer, src_reader);
|
||||
if (status != WUFFS_GIF__ERROR_BAD_GIF_HEADER) {
|
||||
FAIL("status: got %" PRIi32 " (%s), want %" PRIi32 " (%s)", status,
|
||||
puffs_gif__status__string(status), PUFFS_GIF__ERROR_BAD_GIF_HEADER,
|
||||
puffs_gif__status__string(PUFFS_GIF__ERROR_BAD_GIF_HEADER));
|
||||
wuffs_gif__status__string(status), WUFFS_GIF__ERROR_BAD_GIF_HEADER,
|
||||
wuffs_gif__status__string(WUFFS_GIF__ERROR_BAD_GIF_HEADER));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------- Mimic Tests
|
||||
|
||||
#ifdef PUFFS_MIMIC
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
#include "../mimiclib/gif.c"
|
||||
|
||||
bool do_test_mimic_gif_decode(const char* filename) {
|
||||
puffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
wuffs_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};
|
||||
const char* got_msg = puffs_gif_decode(&got, &src);
|
||||
wuffs_base__buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
const char* got_msg = wuffs_gif_decode(&got, &src);
|
||||
if (got_msg) {
|
||||
FAIL("%s", got_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
src.ri = 0;
|
||||
puffs_base__buf1 want = {.ptr = global_want_buffer, .len = BUFFER_SIZE};
|
||||
wuffs_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);
|
||||
@@ -630,16 +630,16 @@ void test_mimic_gif_decode_pjw_thumbnail() {
|
||||
do_test_mimic_gif_decode("../../testdata/pjw-thumbnail.gif");
|
||||
}
|
||||
|
||||
#endif // PUFFS_MIMIC
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- 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)(wuffs_base__buf1*,
|
||||
wuffs_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};
|
||||
wuffs_base__buf1 dst = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
wuffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
|
||||
if (!read_file(&src, filename)) {
|
||||
return false;
|
||||
@@ -662,30 +662,30 @@ bool do_bench_gif_decode(const char* (*decode_func)(puffs_base__buf1*,
|
||||
return true;
|
||||
}
|
||||
|
||||
void bench_puffs_gif_decode_1k() {
|
||||
void bench_wuffs_gif_decode_1k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_gif_decode(puffs_gif_decode, "../../testdata/pjw-thumbnail.gif",
|
||||
do_bench_gif_decode(wuffs_gif_decode, "../../testdata/pjw-thumbnail.gif",
|
||||
200000);
|
||||
}
|
||||
|
||||
void bench_puffs_gif_decode_10k() {
|
||||
void bench_wuffs_gif_decode_10k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_gif_decode(puffs_gif_decode, "../../testdata/hat.gif", 10000);
|
||||
do_bench_gif_decode(wuffs_gif_decode, "../../testdata/hat.gif", 10000);
|
||||
}
|
||||
|
||||
void bench_puffs_gif_decode_100k() {
|
||||
void bench_wuffs_gif_decode_100k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_gif_decode(puffs_gif_decode, "../../testdata/hibiscus.gif", 1000);
|
||||
do_bench_gif_decode(wuffs_gif_decode, "../../testdata/hibiscus.gif", 1000);
|
||||
}
|
||||
|
||||
void bench_puffs_gif_decode_1000k() {
|
||||
void bench_wuffs_gif_decode_1000k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
do_bench_gif_decode(puffs_gif_decode, "../../testdata/harvesters.gif", 100);
|
||||
do_bench_gif_decode(wuffs_gif_decode, "../../testdata/harvesters.gif", 100);
|
||||
}
|
||||
|
||||
// ---------------- Mimic Benches
|
||||
|
||||
#ifdef PUFFS_MIMIC
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
void bench_mimic_gif_decode_1k() {
|
||||
CHECK_FOCUS(__func__);
|
||||
@@ -708,7 +708,7 @@ void bench_mimic_gif_decode_1000k() {
|
||||
do_bench_gif_decode(mimic_gif_decode, "../../testdata/harvesters.gif", 100);
|
||||
}
|
||||
|
||||
#endif // PUFFS_MIMIC
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
// ---------------- Manifest
|
||||
|
||||
@@ -718,27 +718,27 @@ proc tests[] = {
|
||||
test_basic_bad_argument_out_of_range, //
|
||||
test_basic_bad_receiver, //
|
||||
test_basic_initializer_not_called, //
|
||||
test_basic_puffs_version_bad, //
|
||||
test_basic_puffs_version_good, //
|
||||
test_basic_wuffs_version_bad, //
|
||||
test_basic_wuffs_version_good, //
|
||||
test_basic_status_is_error, //
|
||||
test_basic_status_strings, //
|
||||
test_basic_sub_struct_initializer, //
|
||||
|
||||
// LZW Tests
|
||||
test_puffs_gif_lzw_decode_many_big_reads, //
|
||||
test_puffs_gif_lzw_decode_many_small_writes_reads, //
|
||||
test_puffs_gif_lzw_decode_bricks_dither, //
|
||||
test_puffs_gif_lzw_decode_bricks_nodither, //
|
||||
test_puffs_gif_lzw_decode_pi, //
|
||||
test_wuffs_gif_lzw_decode_many_big_reads, //
|
||||
test_wuffs_gif_lzw_decode_many_small_writes_reads, //
|
||||
test_wuffs_gif_lzw_decode_bricks_dither, //
|
||||
test_wuffs_gif_lzw_decode_bricks_nodither, //
|
||||
test_wuffs_gif_lzw_decode_pi, //
|
||||
|
||||
// GIF Tests
|
||||
test_puffs_gif_decode_input_is_a_gif, //
|
||||
test_puffs_gif_decode_input_is_a_gif_many_big_reads, //
|
||||
test_puffs_gif_decode_input_is_a_gif_many_medium_reads, //
|
||||
test_puffs_gif_decode_input_is_a_gif_many_small_writes_reads, //
|
||||
test_puffs_gif_decode_input_is_a_png, //
|
||||
test_wuffs_gif_decode_input_is_a_gif, //
|
||||
test_wuffs_gif_decode_input_is_a_gif_many_big_reads, //
|
||||
test_wuffs_gif_decode_input_is_a_gif_many_medium_reads, //
|
||||
test_wuffs_gif_decode_input_is_a_gif_many_small_writes_reads, //
|
||||
test_wuffs_gif_decode_input_is_a_png, //
|
||||
|
||||
#ifdef PUFFS_MIMIC
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
// Mimic Tests
|
||||
test_mimic_gif_decode_bricks_dither, //
|
||||
@@ -749,7 +749,7 @@ proc tests[] = {
|
||||
test_mimic_gif_decode_hibiscus, //
|
||||
test_mimic_gif_decode_pjw_thumbnail, //
|
||||
|
||||
#endif // PUFFS_MIMIC
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
@@ -757,16 +757,16 @@ proc tests[] = {
|
||||
// The empty comments forces clang-format to place one element per line.
|
||||
proc benches[] = {
|
||||
// LZW Benches
|
||||
bench_puffs_gif_lzw_decode_20k, //
|
||||
bench_puffs_gif_lzw_decode_100k, //
|
||||
bench_wuffs_gif_lzw_decode_20k, //
|
||||
bench_wuffs_gif_lzw_decode_100k, //
|
||||
|
||||
// GIF Benches
|
||||
bench_puffs_gif_decode_1k, //
|
||||
bench_puffs_gif_decode_10k, //
|
||||
bench_puffs_gif_decode_100k, //
|
||||
bench_puffs_gif_decode_1000k, //
|
||||
bench_wuffs_gif_decode_1k, //
|
||||
bench_wuffs_gif_decode_10k, //
|
||||
bench_wuffs_gif_decode_100k, //
|
||||
bench_wuffs_gif_decode_1000k, //
|
||||
|
||||
#ifdef PUFFS_MIMIC
|
||||
#ifdef WUFFS_MIMIC
|
||||
|
||||
// Mimic Benches
|
||||
bench_mimic_gif_decode_1k, //
|
||||
@@ -774,7 +774,7 @@ proc benches[] = {
|
||||
bench_mimic_gif_decode_100k, //
|
||||
bench_mimic_gif_decode_1000k, //
|
||||
|
||||
#endif // PUFFS_MIMIC
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
||||
+21
-21
@@ -22,7 +22,7 @@
|
||||
#define BUFFER_SIZE (64 * 1024 * 1024)
|
||||
#define PALETTE_BUFFER_SIZE (4 * 245)
|
||||
|
||||
#define PUFFS_TESTLIB_ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
|
||||
#define WUFFS_TESTLIB_ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
|
||||
|
||||
uint8_t global_got_buffer[BUFFER_SIZE];
|
||||
uint8_t global_want_buffer[BUFFER_SIZE];
|
||||
@@ -82,10 +82,10 @@ bool check_focus() {
|
||||
// copy/paste a string with a trailing comma.
|
||||
} else {
|
||||
// Strip a leading "Benchmark", if present, from the [p, q) string.
|
||||
// Idiomatic C function names look like "test_puffs_gif_lzw_decode_pi"
|
||||
// Idiomatic C function names look like "test_wuffs_gif_lzw_decode_pi"
|
||||
// and won't start with "Benchmark". Stripping lets us conveniently
|
||||
// copy/paste a string like "Benchmarkpuffs_gif_decode_10k/gcc" from the
|
||||
// "puffs bench std/gif" output.
|
||||
// copy/paste a string like "Benchmarkwuffs_gif_decode_10k/gcc" from the
|
||||
// "wuffs bench std/gif" output.
|
||||
if ((q - p >= 9) && !strncmp(p, "Benchmark", 9)) {
|
||||
p += 9;
|
||||
}
|
||||
@@ -175,7 +175,7 @@ void bench_finish(uint64_t reps, uint64_t n_bytes) {
|
||||
name, cc, reps, nanos / reps, //
|
||||
(int)(kb_per_s / 1000), (int)(kb_per_s % 1000));
|
||||
}
|
||||
// Flush stdout so that "puffs bench | tee etc" still prints its numbers as
|
||||
// Flush stdout so that "wuffs bench | tee etc" still prints its numbers as
|
||||
// soon as they are available.
|
||||
fflush(stdout);
|
||||
}
|
||||
@@ -264,10 +264,10 @@ int test_main(int argc, char** argv, proc* tests, proc* benches) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// PUFFS_BASE_HEADER_H is where puffs_base__buf1 is defined.
|
||||
#ifdef PUFFS_BASE_HEADER_H
|
||||
// WUFFS_BASE_HEADER_H is where wuffs_base__buf1 is defined.
|
||||
#ifdef WUFFS_BASE_HEADER_H
|
||||
|
||||
bool read_file(puffs_base__buf1* dst, const char* path) {
|
||||
bool read_file(wuffs_base__buf1* dst, const char* path) {
|
||||
if (!dst || !path) {
|
||||
FAIL("read_file: NULL argument");
|
||||
return false;
|
||||
@@ -322,7 +322,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, wuffs_base__buf1* buf, size_t i) {
|
||||
if (!msg || !buf) {
|
||||
FAIL("hex_dump: NULL argument");
|
||||
return NULL;
|
||||
@@ -373,8 +373,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) {
|
||||
wuffs_base__buf1* got,
|
||||
wuffs_base__buf1* want) {
|
||||
if (!got || !want) {
|
||||
FAIL("%sbuf1s_equal: NULL argument", prefix);
|
||||
return false;
|
||||
@@ -411,8 +411,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)(wuffs_base__buf1*,
|
||||
wuffs_base__buf1*,
|
||||
uint64_t,
|
||||
uint64_t),
|
||||
throughput_counter tc,
|
||||
@@ -430,9 +430,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};
|
||||
wuffs_base__buf1 src = {.ptr = global_src_buffer, .len = BUFFER_SIZE};
|
||||
wuffs_base__buf1 got = {.ptr = global_got_buffer, .len = BUFFER_SIZE};
|
||||
wuffs_base__buf1 want = {.ptr = global_want_buffer, .len = BUFFER_SIZE};
|
||||
|
||||
if (!gt->src_filename) {
|
||||
src.closed = true;
|
||||
@@ -492,8 +492,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)(wuffs_base__buf1*,
|
||||
wuffs_base__buf1*,
|
||||
uint64_t,
|
||||
uint64_t),
|
||||
throughput_counter tc,
|
||||
@@ -504,8 +504,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)(wuffs_base__buf1*,
|
||||
wuffs_base__buf1*,
|
||||
uint64_t,
|
||||
uint64_t),
|
||||
golden_test* gt,
|
||||
@@ -514,4 +514,4 @@ bool do_test_buf1_buf1(const char* (*codec_func)(puffs_base__buf1*,
|
||||
return proc_buf1_buf1(codec_func, tc_neither, gt, wlimit, rlimit, 1, false);
|
||||
}
|
||||
|
||||
#endif // PUFFS_BASE_HEADER_H
|
||||
#endif // WUFFS_BASE_HEADER_H
|
||||
Reference in new issue
Block a user