Update wuffs to match the version used by Skia
Change-Id: I3cd6abafb5f5565842beaae48139e5bdb89a5093
diff --git a/README.md b/README.md
index dbbc98b..5dd3443 100644
--- a/README.md
+++ b/README.md
@@ -285,6 +285,8 @@
mentioned above, Wuffs transpiles to C code, and Go is not necessarily
involved if all you want is to use the C edition of Wuffs.
- `lib` holds other Go libraries, not specific to the Wuffs language per se.
+- `internal` holds internal implementation details, as per Go's [internal
+ packages](https://golang.org/s/go14internal) convention.
- `cmd` holds Wuffs' command line tools, also written in Go.
- `std` holds the Wuffs standard library's code. The initial focus is on
popular image codecs: BMP, GIF, JPEG, PNG, TIFF and WEBP.
diff --git a/build-all.sh b/build-all.sh
index 56ef78d..7255654 100755
--- a/build-all.sh
+++ b/build-all.sh
@@ -49,16 +49,20 @@
go test github.com/google/wuffs/...
wuffs gen
+# Compiler warning flags are discussed at
+# http://fastcompression.blogspot.com/2019/01/compiler-warnings.html
+WARNING_FLAGS="-Wall -Werror -Wpedantic -Wcast-qual -Wcast-align -Wpointer-arith -Wfloat-equal -Wundef -Wvla -Wconversion"
+
echo "Checking snapshot compiles cleanly (as C)"
-$CC -c -Wall -Werror -std=c99 \
+$CC -c $WARNING_FLAGS -std=c99 -Wc++-compat \
release/c/wuffs-unsupported-snapshot.c -o /dev/null
-$CC -c -Wall -Werror -DWUFFS_IMPLEMENTATION -std=c99 \
+$CC -c $WARNING_FLAGS -DWUFFS_IMPLEMENTATION -std=c99 -Wc++-compat \
release/c/wuffs-unsupported-snapshot.c -o /dev/null
echo "Checking snapshot compiles cleanly (as C++)"
-$CXX -c -Wall -Werror -std=c++11 \
+$CXX -c $WARNING_FLAGS -std=c++11 -x c++ \
release/c/wuffs-unsupported-snapshot.c -o /dev/null
-$CXX -c -Wall -Werror -DWUFFS_IMPLEMENTATION -std=c++11 \
+$CXX -c $WARNING_FLAGS -DWUFFS_IMPLEMENTATION -std=c++11 -x c++ \
release/c/wuffs-unsupported-snapshot.c -o /dev/null
wuffs genlib -skipgen
@@ -67,3 +71,7 @@
./build-example.sh
./build-fuzz.sh
+for f in gen/bin/fuzz-*; do
+ echo "Running $f"
+ $f test/data > /dev/null
+done
diff --git a/cmd/wuffs-c/internal/cgen/base/range-private.h b/cmd/wuffs-c/internal/cgen/base/range-private.h
deleted file mode 100644
index e37a3ae..0000000
--- a/cmd/wuffs-c/internal/cgen/base/range-private.h
+++ /dev/null
@@ -1,127 +0,0 @@
-// After editing this file, run "go generate" in the parent directory.
-
-// Copyright 2017 The Wuffs Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// https://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-// ---------------- Ranges and Rects
-
-static inline uint32_t //
-wuffs_base__range_ii_u32__get_min_incl(const wuffs_base__range_ii_u32* r) {
- return r->min_incl;
-}
-
-static inline uint32_t //
-wuffs_base__range_ii_u32__get_max_incl(const wuffs_base__range_ii_u32* r) {
- return r->max_incl;
-}
-
-static inline uint32_t //
-wuffs_base__range_ie_u32__get_min_incl(const wuffs_base__range_ie_u32* r) {
- return r->min_incl;
-}
-
-static inline uint32_t //
-wuffs_base__range_ie_u32__get_max_excl(const wuffs_base__range_ie_u32* r) {
- return r->max_excl;
-}
-
-static inline uint64_t //
-wuffs_base__range_ii_u64__get_min_incl(const wuffs_base__range_ii_u64* r) {
- return r->min_incl;
-}
-
-static inline uint64_t //
-wuffs_base__range_ii_u64__get_max_incl(const wuffs_base__range_ii_u64* r) {
- return r->max_incl;
-}
-
-static inline uint64_t //
-wuffs_base__range_ie_u64__get_min_incl(const wuffs_base__range_ie_u64* r) {
- return r->min_incl;
-}
-
-static inline uint64_t //
-wuffs_base__range_ie_u64__get_max_excl(const wuffs_base__range_ie_u64* r) {
- return r->max_excl;
-}
-
-// ---------------- Ranges and Rects (Utility)
-
-static inline wuffs_base__range_ii_u32 //
-wuffs_base__utility__make_range_ii_u32(const wuffs_base__utility* ignored,
- uint32_t min_incl,
- uint32_t max_incl) {
- return ((wuffs_base__range_ii_u32){
- .min_incl = min_incl,
- .max_incl = max_incl,
- });
-}
-
-static inline wuffs_base__range_ie_u32 //
-wuffs_base__utility__make_range_ie_u32(const wuffs_base__utility* ignored,
- uint32_t min_incl,
- uint32_t max_excl) {
- return ((wuffs_base__range_ie_u32){
- .min_incl = min_incl,
- .max_excl = max_excl,
- });
-}
-
-static inline wuffs_base__range_ii_u64 //
-wuffs_base__utility__make_range_ii_u64(const wuffs_base__utility* ignored,
- uint64_t min_incl,
- uint64_t max_incl) {
- return ((wuffs_base__range_ii_u64){
- .min_incl = min_incl,
- .max_incl = max_incl,
- });
-}
-
-static inline wuffs_base__range_ie_u64 //
-wuffs_base__utility__make_range_ie_u64(const wuffs_base__utility* ignored,
- uint64_t min_incl,
- uint64_t max_excl) {
- return ((wuffs_base__range_ie_u64){
- .min_incl = min_incl,
- .max_excl = max_excl,
- });
-}
-
-static inline wuffs_base__rect_ii_u32 //
-wuffs_base__utility__make_rect_ii_u32(const wuffs_base__utility* ignored,
- uint32_t min_incl_x,
- uint32_t min_incl_y,
- uint32_t max_incl_x,
- uint32_t max_incl_y) {
- return ((wuffs_base__rect_ii_u32){
- .min_incl_x = min_incl_x,
- .min_incl_y = min_incl_y,
- .max_incl_x = max_incl_x,
- .max_incl_y = max_incl_y,
- });
-}
-
-static inline wuffs_base__rect_ie_u32 //
-wuffs_base__utility__make_rect_ie_u32(const wuffs_base__utility* ignored,
- uint32_t min_incl_x,
- uint32_t min_incl_y,
- uint32_t max_excl_x,
- uint32_t max_excl_y) {
- return ((wuffs_base__rect_ie_u32){
- .min_incl_x = min_incl_x,
- .min_incl_y = min_incl_y,
- .max_excl_x = max_excl_x,
- .max_excl_y = max_excl_y,
- });
-}
diff --git a/cmd/wuffs-c/internal/cgen/data.go b/cmd/wuffs-c/internal/cgen/data.go
deleted file mode 100644
index 0d03d8c..0000000
--- a/cmd/wuffs-c/internal/cgen/data.go
+++ /dev/null
@@ -1,211 +0,0 @@
-// Code generated by running "go generate". DO NOT EDIT.
-
-// Copyright 2017 The Wuffs Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// https://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package cgen
-
-const baseAllImplC = "" +
- "#ifndef WUFFS_INCLUDE_GUARD__BASE\n#define WUFFS_INCLUDE_GUARD__BASE\n\n#if defined(WUFFS_IMPLEMENTATION) && !defined(WUFFS_CONFIG__MODULES)\n#define WUFFS_CONFIG__MODULES\n#define WUFFS_CONFIG__MODULE__BASE\n#endif\n\n// !! WUFFS MONOLITHIC RELEASE DISCARDS EVERYTHING ABOVE.\n\n// !! INSERT base/copyright\n\n#include <stdbool.h>\n#include <stdint.h>\n#include <string.h>\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n// !! INSERT base/all-public.h.\n\n#ifdef __cplusplus\n} // extern \"C\"\n#endif\n\n// WUFFS C HEADER ENDS HERE.\n#ifdef WUFFS_IMPLEMENTATION\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n// !! INSERT base/all-private.h.\n\n#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BASE)\n\nconst uint8_t wuffs_base__low_bits_mask__u8[9] = {\n 0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF,\n};\n\nconst uint16_t wuffs_base__low_bits_mask__u16[17] = {\n 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF,\n 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF,\n};\n\nconst uint32_t wuffs_ba" +
- "se__low_bits_mask__u32[33] = {\n 0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000F, 0x0000001F,\n 0x0000003F, 0x0000007F, 0x000000FF, 0x000001FF, 0x000003FF, 0x000007FF,\n 0x00000FFF, 0x00001FFF, 0x00003FFF, 0x00007FFF, 0x0000FFFF, 0x0001FFFF,\n 0x0003FFFF, 0x0007FFFF, 0x000FFFFF, 0x001FFFFF, 0x003FFFFF, 0x007FFFFF,\n 0x00FFFFFF, 0x01FFFFFF, 0x03FFFFFF, 0x07FFFFFF, 0x0FFFFFFF, 0x1FFFFFFF,\n 0x3FFFFFFF, 0x7FFFFFFF, 0xFFFFFFFF,\n};\n\nconst uint64_t wuffs_base__low_bits_mask__u64[65] = {\n 0x0000000000000000, 0x0000000000000001, 0x0000000000000003,\n 0x0000000000000007, 0x000000000000000F, 0x000000000000001F,\n 0x000000000000003F, 0x000000000000007F, 0x00000000000000FF,\n 0x00000000000001FF, 0x00000000000003FF, 0x00000000000007FF,\n 0x0000000000000FFF, 0x0000000000001FFF, 0x0000000000003FFF,\n 0x0000000000007FFF, 0x000000000000FFFF, 0x000000000001FFFF,\n 0x000000000003FFFF, 0x000000000007FFFF, 0x00000000000FFFFF,\n 0x00000000001FFFFF, 0x00000000003FFFFF, 0x00000000007FFFFF,\n " +
- " 0x0000000000FFFFFF, 0x0000000001FFFFFF, 0x0000000003FFFFFF,\n 0x0000000007FFFFFF, 0x000000000FFFFFFF, 0x000000001FFFFFFF,\n 0x000000003FFFFFFF, 0x000000007FFFFFFF, 0x00000000FFFFFFFF,\n 0x00000001FFFFFFFF, 0x00000003FFFFFFFF, 0x00000007FFFFFFFF,\n 0x0000000FFFFFFFFF, 0x0000001FFFFFFFFF, 0x0000003FFFFFFFFF,\n 0x0000007FFFFFFFFF, 0x000000FFFFFFFFFF, 0x000001FFFFFFFFFF,\n 0x000003FFFFFFFFFF, 0x000007FFFFFFFFFF, 0x00000FFFFFFFFFFF,\n 0x00001FFFFFFFFFFF, 0x00003FFFFFFFFFFF, 0x00007FFFFFFFFFFF,\n 0x0000FFFFFFFFFFFF, 0x0001FFFFFFFFFFFF, 0x0003FFFFFFFFFFFF,\n 0x0007FFFFFFFFFFFF, 0x000FFFFFFFFFFFFF, 0x001FFFFFFFFFFFFF,\n 0x003FFFFFFFFFFFFF, 0x007FFFFFFFFFFFFF, 0x00FFFFFFFFFFFFFF,\n 0x01FFFFFFFFFFFFFF, 0x03FFFFFFFFFFFFFF, 0x07FFFFFFFFFFFFFF,\n 0x0FFFFFFFFFFFFFFF, 0x1FFFFFFFFFFFFFFF, 0x3FFFFFFFFFFFFFFF,\n 0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF,\n};\n\n// !! INSERT wuffs_base__status strings.\n\n// !! INSERT base/image-impl.c.\n\n#endif // !defined(WUFFS_CONFIG__MODULES) ||\n // defined(WUFFS_C" +
- "ONFIG__MODULE__BASE)\n\n#ifdef __cplusplus\n} // extern \"C\"\n#endif\n\n#endif // WUFFS_IMPLEMENTATION\n\n// !! WUFFS MONOLITHIC RELEASE DISCARDS EVERYTHING BELOW.\n\n#endif // WUFFS_INCLUDE_GUARD__BASE\n" +
- ""
-
-const baseImageImplC = "" +
- "// ---------------- Images\n\nconst uint32_t wuffs_base__pixel_format__bits_per_channel[16] = {\n 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,\n 0x08, 0x0A, 0x0C, 0x10, 0x18, 0x20, 0x30, 0x40,\n};\n\nstatic uint64_t //\nwuffs_base__pixel_swizzler__copy_1_1(wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src) {\n return wuffs_base__slice_u8__copy_from_slice(dst, src);\n}\n\nstatic uint64_t //\nwuffs_base__pixel_swizzler__copy_4_1(wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src) {\n if (dst_palette.len != 1024) {\n return 0;\n }\n size_t dst_len4 = dst.len / 4;\n size_t len = dst_len4 < src.len ? dst_len4 : src.len;\n uint8_t* d = dst.ptr;\n uint8_t* s = src.ptr;\n\n size_t n = len;\n const int N = 4;\n\n while (n >= N) {\n wuffs_base__store_u32le(\n d + (0 * 4),\n wuffs_base__load_u3" +
- "2le(dst_palette.ptr + ((uint32_t)(s[0]) * 4)));\n wuffs_base__store_u32le(\n d + (1 * 4),\n wuffs_base__load_u32le(dst_palette.ptr + ((uint32_t)(s[1]) * 4)));\n wuffs_base__store_u32le(\n d + (2 * 4),\n wuffs_base__load_u32le(dst_palette.ptr + ((uint32_t)(s[2]) * 4)));\n wuffs_base__store_u32le(\n d + (3 * 4),\n wuffs_base__load_u32le(dst_palette.ptr + ((uint32_t)(s[3]) * 4)));\n\n s += 1 * N;\n d += 4 * N;\n n -= 1 * N;\n }\n\n while (n >= 1) {\n wuffs_base__store_u32le(\n d + (0 * 4),\n wuffs_base__load_u32le(dst_palette.ptr + ((uint32_t)(s[0]) * 4)));\n\n s += 1 * 1;\n d += 4 * 1;\n n -= 1 * 1;\n }\n\n return len;\n}\n\nstatic uint64_t //\nwuffs_base__pixel_swizzler__swap_rgbx_bgrx(wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 src) {\n size_t len4 = (dst.len < src.len ? dst.len : src.len) / 4;\n uint8_t* d = dst.ptr;\n uint8_t* s = src.ptr;\n\n size_t n = len4;\n while (n--) {\n uint8_t b0 = s[0];\n " +
- "uint8_t b1 = s[1];\n uint8_t b2 = s[2];\n uint8_t b3 = s[3];\n d[0] = b2;\n d[1] = b1;\n d[2] = b0;\n d[3] = b3;\n s += 4;\n d += 4;\n }\n return len4 * 4;\n}\n\nvoid //\nwuffs_base__pixel_swizzler__prepare(wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_format,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__pixel_format src_format,\n wuffs_base__slice_u8 src_palette) {\n if (!p) {\n return;\n }\n\n // TODO: support many more formats.\n\n uint64_t (*func)(wuffs_base__slice_u8 dst, wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src) = NULL;\n\n switch (src_format) {\n case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY:\n switch (dst_format) {\n case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BG" +
- "RA_BINARY:\n if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=\n 1024) {\n break;\n }\n func = wuffs_base__pixel_swizzler__copy_1_1;\n break;\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:\n if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=\n 1024) {\n break;\n }\n func = wuffs_base__pixel_swizzler__copy_4_1;\n break;\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:\n if (wuffs_base__pixel_swizzler__swap_rgbx_bgrx(dst_palette,\n src_palette) != 1024) {\n break;\n }\n func = wuffs_base__pixel_swizzler__copy_4_1;\n break;\n default:\n br" +
- "eak;\n }\n break;\n\n default:\n break;\n }\n\n p->private_impl.func = func;\n}\n\nuint64_t //\nwuffs_base__pixel_swizzler__swizzle_packed(wuffs_base__pixel_swizzler* p,\n wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src) {\n if (p && p->private_impl.func) {\n return (*(p->private_impl.func))(dst, dst_palette, src);\n }\n return 0;\n}\n" +
- ""
-
-const baseCorePrivateH = "" +
- "#define WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(x) (void)(x)\n\nstatic inline void wuffs_base__ignore_check_wuffs_version_status(\n wuffs_base__status z) {}\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(\"wuffs\").\n#define WUFFS_BASE__MAGIC ((uint32_t)0x3CCB6C71)\n\n// WUFFS_BASE__DISABLED is a magic number to indicate that a non-recoverable\n// error was previously encountered.\n//\n// Its (non-zero) value is arbitrary, based on md5sum(\"disabled\").\n#define WUFFS_BASE__DISABLED ((uint32_t)0x075AE3D2)\n\n// Denote intentional fallthroughs for -Wimplicit-fallthrough.\n//\n// The order matters here. Clang also defines \"__GNUC__\".\n#if defined(__clang__) && __cplusplus >= 201103L\n#define WUFFS_BASE__FALLTHROUGH [[clang::fallthrough]]\n#elif !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 7)\n#define WUFFS_BA" +
- "SE__FALLTHROUGH __attribute__((fallthrough))\n#else\n#define WUFFS_BASE__FALLTHROUGH\n#endif\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 WUFFS_BASE__FALLTHROUGH; \\\n case n:;\n\n#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \\\n if (!status) { \\\n goto ok; \\\n } else if (*status != '$') { \\\n goto exit; \\\n } \\\n coro_susp_poin" +
- "t = 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// The helpers below are functions, instead of macros, because their arguments\n// can be an expression that we shouldn't evaluate more than once.\n//\n// They are 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 wuffs_base__empty_struct //\nwuffs_base__return_empty_struct() {\n return ((wuffs_base__empty_struct){});" +
- "\n}\n\n" +
- "" +
- "// ---------------- Numeric Types\n\nstatic inline uint8_t //\nwuffs_base__load_u8be(uint8_t* p) {\n return p[0];\n}\n\nstatic inline uint16_t //\nwuffs_base__load_u16be(uint8_t* p) {\n return ((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0);\n}\n\nstatic inline uint16_t //\nwuffs_base__load_u16le(uint8_t* p) {\n return ((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8);\n}\n\nstatic inline uint32_t //\nwuffs_base__load_u24be(uint8_t* p) {\n return ((uint32_t)(p[0]) << 16) | ((uint32_t)(p[1]) << 8) |\n ((uint32_t)(p[2]) << 0);\n}\n\nstatic inline uint32_t //\nwuffs_base__load_u24le(uint8_t* p) {\n return ((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) |\n ((uint32_t)(p[2]) << 16);\n}\n\nstatic inline uint32_t //\nwuffs_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 //\nwuffs_base__load_u32le(uint8_t* p) {\n return ((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) |\n ((uin" +
- "t32_t)(p[2]) << 16) | ((uint32_t)(p[3]) << 24);\n}\n\nstatic inline uint64_t //\nwuffs_base__load_u40be(uint8_t* p) {\n return ((uint64_t)(p[0]) << 32) | ((uint64_t)(p[1]) << 24) |\n ((uint64_t)(p[2]) << 16) | ((uint64_t)(p[3]) << 8) |\n ((uint64_t)(p[4]) << 0);\n}\n\nstatic inline uint64_t //\nwuffs_base__load_u40le(uint8_t* p) {\n return ((uint64_t)(p[0]) << 0) | ((uint64_t)(p[1]) << 8) |\n ((uint64_t)(p[2]) << 16) | ((uint64_t)(p[3]) << 24) |\n ((uint64_t)(p[4]) << 32);\n}\n\nstatic inline uint64_t //\nwuffs_base__load_u48be(uint8_t* p) {\n return ((uint64_t)(p[0]) << 40) | ((uint64_t)(p[1]) << 32) |\n ((uint64_t)(p[2]) << 24) | ((uint64_t)(p[3]) << 16) |\n ((uint64_t)(p[4]) << 8) | ((uint64_t)(p[5]) << 0);\n}\n\nstatic inline uint64_t //\nwuffs_base__load_u48le(uint8_t* p) {\n return ((uint64_t)(p[0]) << 0) | ((uint64_t)(p[1]) << 8) |\n ((uint64_t)(p[2]) << 16) | ((uint64_t)(p[3]) << 24) |\n ((uint64_t)(p[4]) << 32) | ((uint64_t)(p[5]) << 40);\n}\n\nstatic inline u" +
- "int64_t //\nwuffs_base__load_u56be(uint8_t* p) {\n return ((uint64_t)(p[0]) << 48) | ((uint64_t)(p[1]) << 40) |\n ((uint64_t)(p[2]) << 32) | ((uint64_t)(p[3]) << 24) |\n ((uint64_t)(p[4]) << 16) | ((uint64_t)(p[5]) << 8) |\n ((uint64_t)(p[6]) << 0);\n}\n\nstatic inline uint64_t //\nwuffs_base__load_u56le(uint8_t* p) {\n return ((uint64_t)(p[0]) << 0) | ((uint64_t)(p[1]) << 8) |\n ((uint64_t)(p[2]) << 16) | ((uint64_t)(p[3]) << 24) |\n ((uint64_t)(p[4]) << 32) | ((uint64_t)(p[5]) << 40) |\n ((uint64_t)(p[6]) << 48);\n}\n\nstatic inline uint64_t //\nwuffs_base__load_u64be(uint8_t* p) {\n return ((uint64_t)(p[0]) << 56) | ((uint64_t)(p[1]) << 48) |\n ((uint64_t)(p[2]) << 40) | ((uint64_t)(p[3]) << 32) |\n ((uint64_t)(p[4]) << 24) | ((uint64_t)(p[5]) << 16) |\n ((uint64_t)(p[6]) << 8) | ((uint64_t)(p[7]) << 0);\n}\n\nstatic inline uint64_t //\nwuffs_base__load_u64le(uint8_t* p) {\n return ((uint64_t)(p[0]) << 0) | ((uint64_t)(p[1]) << 8) |\n ((uint64_t)" +
- "(p[2]) << 16) | ((uint64_t)(p[3]) << 24) |\n ((uint64_t)(p[4]) << 32) | ((uint64_t)(p[5]) << 40) |\n ((uint64_t)(p[6]) << 48) | ((uint64_t)(p[7]) << 56);\n}\n\n" +
- "" +
- "// --------\n\nstatic inline void //\nwuffs_base__store_u8be(uint8_t* p, uint8_t x) {\n p[0] = x;\n}\n\nstatic inline void //\nwuffs_base__store_u16be(uint8_t* p, uint16_t x) {\n p[0] = x >> 8;\n p[1] = x >> 0;\n}\n\nstatic inline void //\nwuffs_base__store_u16le(uint8_t* p, uint16_t x) {\n p[0] = x >> 0;\n p[1] = x >> 8;\n}\n\nstatic inline void //\nwuffs_base__store_u24be(uint8_t* p, uint32_t x) {\n p[0] = x >> 16;\n p[1] = x >> 8;\n p[2] = x >> 0;\n}\n\nstatic inline void //\nwuffs_base__store_u24le(uint8_t* p, uint32_t x) {\n p[0] = x >> 0;\n p[1] = x >> 8;\n p[2] = x >> 16;\n}\n\nstatic inline void //\nwuffs_base__store_u32be(uint8_t* p, uint32_t x) {\n p[0] = x >> 24;\n p[1] = x >> 16;\n p[2] = x >> 8;\n p[3] = x >> 0;\n}\n\nstatic inline void //\nwuffs_base__store_u32le(uint8_t* p, uint32_t x) {\n p[0] = x >> 0;\n p[1] = x >> 8;\n p[2] = x >> 16;\n p[3] = x >> 24;\n}\n\nstatic inline void //\nwuffs_base__store_u40be(uint8_t* p, uint64_t x) {\n p[0] = x >> 32;\n p[1] = x >> 24;\n p[2] = x >> 16;\n p[3] = x >> 8;\n p[4] = x >>" +
- " 0;\n}\n\nstatic inline void //\nwuffs_base__store_u40le(uint8_t* p, uint64_t x) {\n p[0] = x >> 0;\n p[1] = x >> 8;\n p[2] = x >> 16;\n p[3] = x >> 24;\n p[4] = x >> 32;\n}\n\nstatic inline void //\nwuffs_base__store_u48be(uint8_t* p, uint64_t x) {\n p[0] = x >> 40;\n p[1] = x >> 32;\n p[2] = x >> 24;\n p[3] = x >> 16;\n p[4] = x >> 8;\n p[5] = x >> 0;\n}\n\nstatic inline void //\nwuffs_base__store_u48le(uint8_t* p, uint64_t x) {\n p[0] = x >> 0;\n p[1] = x >> 8;\n p[2] = x >> 16;\n p[3] = x >> 24;\n p[4] = x >> 32;\n p[5] = x >> 40;\n}\n\nstatic inline void //\nwuffs_base__store_u56be(uint8_t* p, uint64_t x) {\n p[0] = x >> 48;\n p[1] = x >> 40;\n p[2] = x >> 32;\n p[3] = x >> 24;\n p[4] = x >> 16;\n p[5] = x >> 8;\n p[6] = x >> 0;\n}\n\nstatic inline void //\nwuffs_base__store_u56le(uint8_t* p, uint64_t x) {\n p[0] = x >> 0;\n p[1] = x >> 8;\n p[2] = x >> 16;\n p[3] = x >> 24;\n p[4] = x >> 32;\n p[5] = x >> 40;\n p[6] = x >> 48;\n}\n\nstatic inline void //\nwuffs_base__store_u64be(uint8_t* p, uint64_t x) {\n p[0] = x >> 56" +
- ";\n p[1] = x >> 48;\n p[2] = x >> 40;\n p[3] = x >> 32;\n p[4] = x >> 24;\n p[5] = x >> 16;\n p[6] = x >> 8;\n p[7] = x >> 0;\n}\n\nstatic inline void //\nwuffs_base__store_u64le(uint8_t* p, uint64_t x) {\n p[0] = x >> 0;\n p[1] = x >> 8;\n p[2] = x >> 16;\n p[3] = x >> 24;\n p[4] = x >> 32;\n p[5] = x >> 40;\n p[6] = x >> 48;\n p[7] = x >> 56;\n}\n\n" +
- "" +
- "// --------\n\nextern const uint8_t wuffs_base__low_bits_mask__u8[9];\nextern const uint16_t wuffs_base__low_bits_mask__u16[17];\nextern const uint32_t wuffs_base__low_bits_mask__u32[33];\nextern const uint64_t wuffs_base__low_bits_mask__u64[65];\n\n#define WUFFS_BASE__LOW_BITS_MASK__U8(n) (wuffs_base__low_bits_mask__u8[n])\n#define WUFFS_BASE__LOW_BITS_MASK__U16(n) (wuffs_base__low_bits_mask__u16[n])\n#define WUFFS_BASE__LOW_BITS_MASK__U32(n) (wuffs_base__low_bits_mask__u32[n])\n#define WUFFS_BASE__LOW_BITS_MASK__U64(n) (wuffs_base__low_bits_mask__u64[n])\n\n" +
- "" +
- "// --------\n\nstatic inline void //\nwuffs_base__u8__sat_add_indirect(uint8_t* x, uint8_t y) {\n *x = wuffs_base__u8__sat_add(*x, y);\n}\n\nstatic inline void //\nwuffs_base__u8__sat_sub_indirect(uint8_t* x, uint8_t y) {\n *x = wuffs_base__u8__sat_sub(*x, y);\n}\n\nstatic inline void //\nwuffs_base__u16__sat_add_indirect(uint16_t* x, uint16_t y) {\n *x = wuffs_base__u16__sat_add(*x, y);\n}\n\nstatic inline void //\nwuffs_base__u16__sat_sub_indirect(uint16_t* x, uint16_t y) {\n *x = wuffs_base__u16__sat_sub(*x, y);\n}\n\nstatic inline void //\nwuffs_base__u32__sat_add_indirect(uint32_t* x, uint32_t y) {\n *x = wuffs_base__u32__sat_add(*x, y);\n}\n\nstatic inline void //\nwuffs_base__u32__sat_sub_indirect(uint32_t* x, uint32_t y) {\n *x = wuffs_base__u32__sat_sub(*x, y);\n}\n\nstatic inline void //\nwuffs_base__u64__sat_add_indirect(uint64_t* x, uint64_t y) {\n *x = wuffs_base__u64__sat_add(*x, y);\n}\n\nstatic inline void //\nwuffs_base__u64__sat_sub_indirect(uint64_t* x, uint64_t y) {\n *x = wuffs_base__u64__sat_sub(*x, y);\n}\n\n" +
- "" +
- "// ---------------- Slices and Tables\n\n// wuffs_base__slice_u8__prefix returns up to the first up_to bytes of s.\nstatic inline wuffs_base__slice_u8 //\nwuffs_base__slice_u8__prefix(wuffs_base__slice_u8 s, 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 //\nwuffs_base__slice_u8__suffix(wuffs_base__slice_u8 s, 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, len)\n// where len 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.\nstatic inline uint64_t //\nwuffs_base__slice_u8__copy_from_slice(wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 src) {\n size_t len = dst.l" +
- "en < src.len ? dst.len : src.len;\n if (len > 0) {\n memmove(dst.ptr, src.ptr, len);\n }\n return len;\n}\n\n" +
- "" +
- "// --------\n\nstatic inline wuffs_base__slice_u8 //\nwuffs_base__table_u8__row(wuffs_base__table_u8 t, uint32_t y) {\n if (y < t.height) {\n return ((wuffs_base__slice_u8){\n .ptr = t.ptr + (t.stride * y),\n .len = t.width,\n });\n }\n return ((wuffs_base__slice_u8){});\n}\n" +
- ""
-
-const baseCorePublicH = "" +
- "// Wuffs assumes that:\n// - converting a uint32_t to a size_t will never overflow.\n// - converting a size_t to a uint64_t will never overflow.\n#ifdef __WORDSIZE\n#if (__WORDSIZE != 32) && (__WORDSIZE != 64)\n#error \"Wuffs requires a word size of either 32 or 64 bits\"\n#endif\n#endif\n\n// WUFFS_VERSION is the major.minor.patch version, as per https://semver.org/,\n// as a uint64_t. The major number is the high 32 bits. The minor number is the\n// middle 16 bits. The patch number is the low 16 bits. The pre-release label\n// and build metadata are part of the string representation (such as\n// \"1.2.3-beta+456.20181231\") but not the uint64_t representation.\n//\n// WUFFS_VERSION_PRE_RELEASE_LABEL (such as \"\", \"beta\" or \"rc.1\") being\n// non-empty denotes a developer preview, not a release version, and has no\n// backwards or forwards compatibility guarantees.\n//\n// WUFFS_VERSION_BUILD_METADATA_XXX, if non-zero, are the number of commits and\n// the last commit date in the repository used to build this library. Within\n// eac" +
- "h major.minor branch, the commit count should increase monotonically.\n//\n// !! Some code generation programs can override WUFFS_VERSION.\n#define WUFFS_VERSION ((uint64_t)0)\n#define WUFFS_VERSION_MAJOR ((uint64_t)0)\n#define WUFFS_VERSION_MINOR ((uint64_t)0)\n#define WUFFS_VERSION_PATCH ((uint64_t)0)\n#define WUFFS_VERSION_PRE_RELEASE_LABEL \"work.in.progress\"\n#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 0\n#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 0\n#define WUFFS_VERSION_STRING \"0.0.0+0.00000000\"\n\n// Define WUFFS_CONFIG__STATIC_FUNCTIONS to make all of Wuffs' functions have\n// static storage. The motivation is discussed in the \"ALLOW STATIC\n// IMPLEMENTATION\" section of\n// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt\n#ifdef WUFFS_CONFIG__STATIC_FUNCTIONS\n#define WUFFS_BASE__MAYBE_STATIC static\n#else\n#define WUFFS_BASE__MAYBE_STATIC\n#endif\n\n// Clang also defines \"__GNUC__\".\n#if defined(__GNUC__)\n#define WUFFS_BASE__WARN_UNUSED_RESULT __attribute__((warn_unused_result))\n#else\n" +
- "#define WUFFS_BASE__WARN_UNUSED_RESULT\n#endif\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 // private_impl is a placeholder field. It isn't explicitly used, except that\n // without it, the sizeof a struct with no fields can differ across C/C++\n // compilers, and it is undefined behavior in C99. For example, gcc says that\n // the sizeof an empty struct is 0, and g++ says that it is 1. This leads to\n // ABI incompatibility if a Wuffs .c file is processed by one compiler and\n // its .h file with another compiler.\n //\n // Instead, we explicitly insert an otherwise unused field, so that the\n // sizeof this struct is always 1.\n uint8_t private_impl;\n} wuffs_base__empty_struct;\n\n// wuffs_base__utility is a placeholder receiver type. It enables what Java\n// calls static methods, as opposed to regular methods.\ntypedef s" +
- "truct {\n // private_impl is a placeholder field. It isn't explicitly used, except that\n // without it, the sizeof a struct with no fields can differ across C/C++\n // compilers, and it is undefined behavior in C99. For example, gcc says that\n // the sizeof an empty struct is 0, and g++ says that it is 1. This leads to\n // ABI incompatibility if a Wuffs .c file is processed by one compiler and\n // its .h file with another compiler.\n //\n // Instead, we explicitly insert an otherwise unused field, so that the\n // sizeof this struct is always 1.\n uint8_t private_impl;\n} wuffs_base__utility;\n\n" +
- "" +
- "// --------\n\n// A status is either NULL (meaning OK) or a string message. That message is\n// human-readable, for programmers, but it is not for end users. It is not\n// localized, and does not contain additional contextual information such as a\n// source filename.\n//\n// Status strings are statically allocated and should never be free'd. They can\n// be compared by the == operator and not just by strcmp.\n//\n// Statuses come in four categories:\n// - OK: the request was completed, successfully.\n// - Warnings: the request was completed, unsuccessfully.\n// - Suspensions: the request was not completed, but can be re-tried.\n// - Errors: the request was not completed, permanently.\n//\n// When a function returns an incomplete status, a suspension means that that\n// function should be called again within a new context, such as after flushing\n// or re-filling an I/O buffer. An error means that an irrecoverable failure\n// state was reached.\ntypedef const char* wuffs_base__status;\n\n// !! INSERT wuffs_bas" +
- "e__status names.\n\nstatic inline bool //\nwuffs_base__status__is_complete(wuffs_base__status z) {\n return (z == NULL) || ((*z != '$') && (*z != '?'));\n}\n\nstatic inline bool //\nwuffs_base__status__is_error(wuffs_base__status z) {\n return z && (*z == '?');\n}\n\nstatic inline bool //\nwuffs_base__status__is_ok(wuffs_base__status z) {\n return z == NULL;\n}\n\nstatic inline bool //\nwuffs_base__status__is_suspension(wuffs_base__status z) {\n return z && (*z == '$');\n}\n\nstatic inline bool //\nwuffs_base__status__is_warning(wuffs_base__status z) {\n return z && (*z != '$') && (*z != '?');\n}\n\n" +
- "" +
- "// --------\n\n// Flicks are a unit of time. One flick (frame-tick) is 1 / 705_600_000 of a\n// second. See https://github.com/OculusVR/Flicks\ntypedef int64_t wuffs_base__flicks;\n\n#define WUFFS_BASE__FLICKS_PER_SECOND ((uint64_t)705600000)\n#define WUFFS_BASE__FLICKS_PER_MILLISECOND ((uint64_t)705600)\n\n" +
- "" +
- "// ---------------- Numeric Types\n\nstatic inline uint8_t //\nwuffs_base__u8__min(uint8_t x, uint8_t y) {\n return x < y ? x : y;\n}\n\nstatic inline uint8_t //\nwuffs_base__u8__max(uint8_t x, uint8_t y) {\n return x > y ? x : y;\n}\n\nstatic inline uint16_t //\nwuffs_base__u16__min(uint16_t x, uint16_t y) {\n return x < y ? x : y;\n}\n\nstatic inline uint16_t //\nwuffs_base__u16__max(uint16_t x, uint16_t y) {\n return x > y ? x : y;\n}\n\nstatic inline uint32_t //\nwuffs_base__u32__min(uint32_t x, uint32_t y) {\n return x < y ? x : y;\n}\n\nstatic inline uint32_t //\nwuffs_base__u32__max(uint32_t x, uint32_t y) {\n return x > y ? x : y;\n}\n\nstatic inline uint64_t //\nwuffs_base__u64__min(uint64_t x, uint64_t y) {\n return x < y ? x : y;\n}\n\nstatic inline uint64_t //\nwuffs_base__u64__max(uint64_t x, uint64_t y) {\n return x > y ? x : y;\n}\n\n" +
- "" +
- "// --------\n\n// Saturating arithmetic (sat_add, sat_sub) branchless bit-twiddling algorithms\n// are per https://locklessinc.com/articles/sat_arithmetic/\n//\n// It is important that the underlying types are unsigned integers, as signed\n// integer arithmetic overflow is undefined behavior in C.\n\nstatic inline uint8_t //\nwuffs_base__u8__sat_add(uint8_t x, uint8_t y) {\n uint8_t res = x + y;\n res |= -(res < x);\n return res;\n}\n\nstatic inline uint8_t //\nwuffs_base__u8__sat_sub(uint8_t x, uint8_t y) {\n uint8_t res = x - y;\n res &= -(res <= x);\n return res;\n}\n\nstatic inline uint16_t //\nwuffs_base__u16__sat_add(uint16_t x, uint16_t y) {\n uint16_t res = x + y;\n res |= -(res < x);\n return res;\n}\n\nstatic inline uint16_t //\nwuffs_base__u16__sat_sub(uint16_t x, uint16_t y) {\n uint16_t res = x - y;\n res &= -(res <= x);\n return res;\n}\n\nstatic inline uint32_t //\nwuffs_base__u32__sat_add(uint32_t x, uint32_t y) {\n uint32_t res = x + y;\n res |= -(res < x);\n return res;\n}\n\nstatic inline uint32_t //\nwuffs_base_" +
- "_u32__sat_sub(uint32_t x, uint32_t y) {\n uint32_t res = x - y;\n res &= -(res <= x);\n return res;\n}\n\nstatic inline uint64_t //\nwuffs_base__u64__sat_add(uint64_t x, uint64_t y) {\n uint64_t res = x + y;\n res |= -(res < x);\n return res;\n}\n\nstatic inline uint64_t //\nwuffs_base__u64__sat_sub(uint64_t x, uint64_t y) {\n uint64_t res = x - y;\n res &= -(res <= x);\n return res;\n}\n\n" +
- "" +
- "// ---------------- Slices and Tables\n\n// WUFFS_BASE__SLICE is a 1-dimensional buffer.\n//\n// len measures a number of elements, not necessarily a size in bytes.\n//\n// A value with all fields NULL or zero is a valid, empty slice.\n#define WUFFS_BASE__SLICE(T) \\\n struct { \\\n T* ptr; \\\n size_t len; \\\n }\n\n// WUFFS_BASE__TABLE is a 2-dimensional buffer.\n//\n// width height, and stride measure a number of elements, not necessarily a\n// size in bytes.\n//\n// A value with all fields NULL or zero is a valid, empty table.\n#define WUFFS_BASE__TABLE(T) \\\n struct { \\\n T* ptr; \\\n size_t width; \\\n size_t height; \\\n size_t stride; \\\n }\n\ntypedef WUFFS_BASE__SLICE(uint8_t) wuffs_base__slice_u8;\ntypedef WUFFS_BASE__SLICE(uint16_t) wuffs_base__slice_u16;\ntypedef WUFFS_BASE__SLICE(uint32_t) wuffs_base__slice_u32;\ntypedef WUFFS_BASE__SLICE(uint64_t) wuffs_base__slice_u64;\n\ntypedef WUFFS_BASE__TABLE(u" +
- "int8_t) wuffs_base__table_u8;\ntypedef WUFFS_BASE__TABLE(uint16_t) wuffs_base__table_u16;\ntypedef WUFFS_BASE__TABLE(uint32_t) wuffs_base__table_u32;\ntypedef WUFFS_BASE__TABLE(uint64_t) wuffs_base__table_u64;\n\n// wuffs_base__slice_u8__subslice_i returns s[i:].\n//\n// It returns an empty slice if i is out of bounds.\nstatic inline wuffs_base__slice_u8 //\nwuffs_base__slice_u8__subslice_i(wuffs_base__slice_u8 s, 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\n// wuffs_base__slice_u8__subslice_j returns s[:j].\n//\n// It returns an empty slice if j is out of bounds.\nstatic inline wuffs_base__slice_u8 //\nwuffs_base__slice_u8__subslice_j(wuffs_base__slice_u8 s, uint64_t j) {\n if ((j <= SIZE_MAX) && (j <= s.len)) {\n return ((wuffs_base__slice_u8){\n .ptr = s.ptr,\n .len = j,\n });\n }\n return ((wuffs_base__slice_u8){});\n}\n\n// wuffs_base__slice_u8__subslice_" +
- "ij returns s[i:j].\n//\n// It returns an empty slice if i or j is out of bounds.\nstatic inline wuffs_base__slice_u8 //\nwuffs_base__slice_u8__subslice_ij(wuffs_base__slice_u8 s,\n uint64_t i,\n uint64_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" +
- ""
-
-const baseMemoryPrivateH = "" +
- "// ---------------- Memory Allocation\n" +
- ""
-
-const baseMemoryPublicH = "" +
- "// ---------------- Memory Allocation\n\n// The memory allocation related functions in this section aren't used by Wuffs\n// per se, but they may be helpful to the code that uses Wuffs.\n\n// wuffs_base__malloc_slice_uxx wraps calling a malloc-like function, except\n// that it takes a uint64_t number of elements instead of a size_t size in\n// bytes, and it returns a slice (a pointer and a length) instead of just a\n// pointer.\n//\n// You can pass the C stdlib's malloc as the malloc_func.\n//\n// It returns an empty slice (containing a NULL ptr field) if (num_uxx *\n// sizeof(uintxx_t)) would overflow SIZE_MAX.\n\nstatic inline wuffs_base__slice_u8 //\nwuffs_base__malloc_slice_u8(void* (*malloc_func)(size_t), uint64_t num_u8) {\n if (malloc_func && (num_u8 <= (SIZE_MAX / sizeof(uint8_t)))) {\n void* p = (*malloc_func)(num_u8 * sizeof(uint8_t));\n if (p) {\n return ((wuffs_base__slice_u8){\n .ptr = (uint8_t*)(p),\n .len = num_u8,\n });\n }\n }\n return ((wuffs_base__slice_u8){});\n}\n\nstatic inli" +
- "ne wuffs_base__slice_u16 //\nwuffs_base__malloc_slice_u16(void* (*malloc_func)(size_t), uint64_t num_u16) {\n if (malloc_func && (num_u16 <= (SIZE_MAX / sizeof(uint16_t)))) {\n void* p = (*malloc_func)(num_u16 * sizeof(uint16_t));\n if (p) {\n return ((wuffs_base__slice_u16){\n .ptr = (uint16_t*)(p),\n .len = num_u16,\n });\n }\n }\n return ((wuffs_base__slice_u16){});\n}\n\nstatic inline wuffs_base__slice_u32 //\nwuffs_base__malloc_slice_u32(void* (*malloc_func)(size_t), uint64_t num_u32) {\n if (malloc_func && (num_u32 <= (SIZE_MAX / sizeof(uint32_t)))) {\n void* p = (*malloc_func)(num_u32 * sizeof(uint32_t));\n if (p) {\n return ((wuffs_base__slice_u32){\n .ptr = (uint32_t*)(p),\n .len = num_u32,\n });\n }\n }\n return ((wuffs_base__slice_u32){});\n}\n\nstatic inline wuffs_base__slice_u64 //\nwuffs_base__malloc_slice_u64(void* (*malloc_func)(size_t), uint64_t num_u64) {\n if (malloc_func && (num_u64 <= (SIZE_MAX / sizeof(uint64_t)))) {\n void* p = (*m" +
- "alloc_func)(num_u64 * sizeof(uint64_t));\n if (p) {\n return ((wuffs_base__slice_u64){\n .ptr = (uint64_t*)(p),\n .len = num_u64,\n });\n }\n }\n return ((wuffs_base__slice_u64){});\n}\n" +
- ""
-
-const baseImagePrivateH = "" +
- "// ---------------- Images\n" +
- ""
-
-const baseImagePublicH = "" +
- "// ---------------- Images\n\n// wuffs_base__color_u32_argb_premul is an 8 bit per channel premultiplied\n// Alpha, Red, Green, Blue color, as a uint32_t value. It is in word order, not\n// byte order: its value is always 0xAARRGGBB, regardless of endianness.\ntypedef uint32_t wuffs_base__color_u32_argb_premul;\n\n" +
- "" +
- "// --------\n\n// wuffs_base__pixel_format encodes the format of the bytes that constitute an\n// image frame's pixel data. Its bits:\n// - bit 31 is reserved.\n// - bits 30 .. 28 encodes color (and channel order, in terms of memory).\n// - bit 27 is reserved.\n// - bits 26 .. 24 encodes transparency.\n// - bits 23 .. 21 are reserved.\n// - bit 20 indicates big-endian/MSB-first (as opposed to little/LSB).\n// - bit 19 indicates floating point (as opposed to integer).\n// - bit 18 indicates palette-indexed. The number-of-planes (the next\n// field) will be zero, as the format is considered packed,\n// but the 8-bit N-BGRA color data is stored in plane 3.\n// - bits 17 .. 16 are the number of planes, minus 1. Zero means packed.\n// - bits 15 .. 12 encodes the number of bits (depth) in the 3rd channel.\n// - bits 11 .. 8 encodes the number of bits (depth) in the 2nd channel.\n// - bits 7 .. 4 encodes the number of bits (depth) in the 1st channe" +
- "l.\n// - bits 3 .. 0 encodes the number of bits (depth) in the 0th channel.\n//\n// The bit fields of a wuffs_base__pixel_format are not independent. For\n// example, the number of planes should not be greater than the number of\n// channels. Similarly, bits 15..4 are unused (and should be zero) if bits\n// 31..24 (color and transparency) together imply only 1 channel (gray, no\n// alpha) and floating point samples should mean a bit depth of 16, 32 or 64.\n//\n// Formats hold between 1 and 4 channels. For example: Y (1 channel: gray), YA\n// (2 channels: gray and alpha), BGR (3 channels: blue, green, red) or CMYK (4\n// channels: cyan, magenta, yellow, black).\n//\n// For direct formats with N > 1 channels, those channels can be laid out in\n// either 1 (packed) or N (planar) planes. For example, RGBA data is usually\n// packed, but YCbCr data is usually planar, due to chroma subsampling (for\n// details, see the wuffs_base__pixel_subsampling type).\n//\n// For indexed formats, the palette (always 256 × 4 bytes) holds 8 bi" +
- "ts per\n// channel non-alpha-premultiplied BGRA color data. There is only 1 plane (for\n// the index), as the format is considered packed. Plane 0 holds the per-pixel\n// indices. Plane 3 is re-purposed to hold the per-index colors.\n//\n// The color field is encoded in 3 bits:\n// - 0 means A (Alpha).\n// - 1 means Y or YA (Gray, Alpha).\n// - 2 means YCbCr or YCbCrA (Luma, Chroma-blue, Chroma-red, Alpha).\n// - 3 means YCoCg or YCoCgA (Luma, Chroma-orange, Chroma-green, Alpha).\n// - 4 means BGR, BGRX or BGRA (Blue, Green, Red, X-padding or Alpha).\n// - 5 means RGB, RGBX or RGBA (Red, Green, Blue, X-padding or Alpha).\n// - 6 means CMY or CMYK (Cyan, Magenta, Yellow, Black).\n// - all other values are reserved.\n//\n// In Wuffs, channels are given in memory order (also known as byte order),\n// regardless of endianness, since the C type for the pixel data is an array of\n// bytes, not an array of uint32_t. For example, packed BGRA with 8 bits per\n// channel means th" +
- "at the bytes in memory are always Blue, Green, Red then\n// Alpha. On big-endian systems, that is the uint32_t 0xBBGGRRAA. On\n// little-endian, 0xAARRGGBB.\n//\n// When the color field (3 bits) encodes multiple options, the transparency\n// field (3 bits) distinguishes them:\n// - 0 means fully opaque, no extra channels\n// - 1 means fully opaque, one extra channel (X or K, padding or black).\n// - 5 means one extra alpha channel, other channels are non-premultiplied.\n// - 6 means one extra alpha channel, other channels are premultiplied.\n// - 7 means one extra alpha channel, binary alpha.\n// - all other values are reserved.\n//\n// Binary alpha means that if a color is not completely opaque, it is\n// completely transparent black. As a source pixel format, it can therefore be\n// treated as either non-premultiplied or premultiplied.\n//\n// The zero wuffs_base__pixel_format value is an invalid pixel format, as it is\n// invalid to combine the zero color (alpha only) with the zero transparency.\n//\n// Bit depth is" +
- " encoded in 4 bits:\n// - 0 means the channel or index is unused.\n// - x means a bit depth of x, for x in the range 1..8.\n// - 9 means a bit depth of 10.\n// - 10 means a bit depth of 12.\n// - 11 means a bit depth of 16.\n// - 12 means a bit depth of 24.\n// - 13 means a bit depth of 32.\n// - 14 means a bit depth of 48.\n// - 15 means a bit depth of 64.\n//\n// For example, wuffs_base__pixel_format 0x5510BBBB is a natural format for\n// decoding a PNG image - network byte order (also known as big-endian),\n// packed, non-premultiplied alpha - that happens to be 16-bit-depth truecolor\n// with alpha (RGBA). In memory order:\n//\n// ptr+0 ptr+1 ptr+2 ptr+3 ptr+4 ptr+5 ptr+6 ptr+7\n// Rhi Rlo Ghi Glo Bhi Blo Ahi Alo\n//\n// For example, the value wuffs_base__pixel_format 0x40000565 means BGR with no\n// alpha or padding, 5/6/5 bits for blue/green/red, packed 2 bytes per pixel,\n// laid out LSB-first in memory order:\n//\n// ptr+0........... ptr+1...........\n// MSB LSB MSB " +
- " LSB\n// G₂G₁G₀B₄B₃B₂B₁B₀ R₄R₃R₂R₁R₀G₅G₄G₃\n//\n// On little-endian systems (but not big-endian), this Wuffs pixel format value\n// (0x40000565) corresponds to the Cairo library's CAIRO_FORMAT_RGB16_565, the\n// SDL2 (Simple DirectMedia Layer 2) library's SDL_PIXELFORMAT_RGB565 and the\n// Skia library's kRGB_565_SkColorType. Note BGR in Wuffs versus RGB in the\n// other libraries.\n//\n// Regardless of endianness, this Wuffs pixel format value (0x40000565)\n// corresponds to the V4L2 (Video For Linux 2) library's V4L2_PIX_FMT_RGB565\n// and the Wayland-DRM library's WL_DRM_FORMAT_RGB565.\n//\n// Different software libraries name their pixel formats (and especially their\n// channel order) either according to memory layout or as bits of a native\n// integer type like uint32_t. The two conventions differ because of a system's\n// endianness. As mentioned earlier, Wuffs pixel formats are always in memory\n// order. More detail of other software libraries' naming conventions is in the\n// Pi" +
- "xel Format Guide at https://afrantzis.github.io/pixel-format-guide/\n//\n// Do not manipulate these bits directly; they are private implementation\n// details. Use methods such as wuffs_base__pixel_format__num_planes instead.\ntypedef uint32_t wuffs_base__pixel_format;\n\n// Common 8-bit-depth pixel formats. This list is not exhaustive; not all valid\n// wuffs_base__pixel_format values are present.\n\n#define WUFFS_BASE__PIXEL_FORMAT__INVALID ((wuffs_base__pixel_format)0x00000000)\n\n#define WUFFS_BASE__PIXEL_FORMAT__A ((wuffs_base__pixel_format)0x02000008)\n\n#define WUFFS_BASE__PIXEL_FORMAT__Y ((wuffs_base__pixel_format)0x10000008)\n#define WUFFS_BASE__PIXEL_FORMAT__YA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x15000008)\n#define WUFFS_BASE__PIXEL_FORMAT__YA_PREMUL \\\n ((wuffs_base__pixel_format)0x16000008)\n\n#define WUFFS_BASE__PIXEL_FORMAT__YCBCR ((wuffs_base__pixel_format)0x20020888)\n#define WUFFS_BASE__PIXEL_FORMAT__YCBCRK ((wuffs_base__pixel_format)0x21038888)\n#define WUFFS_BASE__PIXEL_FORMAT__YCBCRA_NONPREMUL \\\n ((w" +
- "uffs_base__pixel_format)0x25038888)\n\n#define WUFFS_BASE__PIXEL_FORMAT__YCOCG ((wuffs_base__pixel_format)0x30020888)\n#define WUFFS_BASE__PIXEL_FORMAT__YCOCGK ((wuffs_base__pixel_format)0x31038888)\n#define WUFFS_BASE__PIXEL_FORMAT__YCOCGA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x35038888)\n\n#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x45040008)\n#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_PREMUL \\\n ((wuffs_base__pixel_format)0x46040008)\n#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY \\\n ((wuffs_base__pixel_format)0x47040008)\n\n#define WUFFS_BASE__PIXEL_FORMAT__BGR ((wuffs_base__pixel_format)0x40000888)\n#define WUFFS_BASE__PIXEL_FORMAT__BGRX ((wuffs_base__pixel_format)0x41008888)\n#define WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x45008888)\n#define WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL \\\n ((wuffs_base__pixel_format)0x46008888)\n#define WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY \\\n ((wuffs_base__pixel_format)0x47008888)\n\n#define W" +
- "UFFS_BASE__PIXEL_FORMAT__RGB ((wuffs_base__pixel_format)0x50000888)\n#define WUFFS_BASE__PIXEL_FORMAT__RGBX ((wuffs_base__pixel_format)0x51008888)\n#define WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x55008888)\n#define WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL \\\n ((wuffs_base__pixel_format)0x56008888)\n#define WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY \\\n ((wuffs_base__pixel_format)0x57008888)\n\n#define WUFFS_BASE__PIXEL_FORMAT__CMY ((wuffs_base__pixel_format)0x60020888)\n#define WUFFS_BASE__PIXEL_FORMAT__CMYK ((wuffs_base__pixel_format)0x61038888)\n\nextern const uint32_t wuffs_base__pixel_format__bits_per_channel[16];\n\nstatic inline bool //\nwuffs_base__pixel_format__is_valid(wuffs_base__pixel_format f) {\n return f != 0;\n}\n\n// wuffs_base__pixel_format__bits_per_pixel returns, for packed pixel formats,\n// the number of bits per pixel. It returns 0 for planar pixel formats.\nstatic inline uint32_t //\nwuffs_base__pixel_format__bits_per_pixel(wuffs_base__pixel_format f) {\n if (((f >> 16) & 0x03" +
- ") != 0) {\n return 0;\n }\n return wuffs_base__pixel_format__bits_per_channel[0x0F & (f >> 0)] +\n wuffs_base__pixel_format__bits_per_channel[0x0F & (f >> 4)] +\n wuffs_base__pixel_format__bits_per_channel[0x0F & (f >> 8)] +\n wuffs_base__pixel_format__bits_per_channel[0x0F & (f >> 12)];\n}\n\nstatic inline bool //\nwuffs_base__pixel_format__is_indexed(wuffs_base__pixel_format f) {\n return (f >> 18) & 0x01;\n}\n\nstatic inline bool //\nwuffs_base__pixel_format__is_packed(wuffs_base__pixel_format f) {\n return ((f >> 16) & 0x03) == 0;\n}\n\nstatic inline bool //\nwuffs_base__pixel_format__is_planar(wuffs_base__pixel_format f) {\n return ((f >> 16) & 0x03) != 0;\n}\n\nstatic inline uint32_t //\nwuffs_base__pixel_format__num_planes(wuffs_base__pixel_format f) {\n return ((f >> 16) & 0x03) + 1;\n}\n\n#define WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX 4\n\n#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__INDEX_PLANE 0\n#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__COLOR_PLANE 3\n\n" +
- "" +
- "// --------\n\n// wuffs_base__pixel_subsampling encodes the mapping of pixel space coordinates\n// (x, y) to pixel buffer indices (i, j). That mapping can differ for each\n// plane p. For a depth of 8 bits (1 byte), the p'th plane's sample starts at\n// (planes[p].ptr + (j * planes[p].stride) + i).\n//\n// For packed pixel formats, the mapping is trivial: i = x and j = y. For\n// planar pixel formats, the mapping can differ due to chroma subsampling. For\n// example, consider a three plane YCbCr pixel format with 4:2:2 subsampling.\n// For the luma (Y) channel, there is one sample for every pixel, but for the\n// chroma (Cb, Cr) channels, there is one sample for every two pixels: pairs of\n// horizontally adjacent pixels form one macropixel, i = x / 2 and j == y. In\n// general, for a given p:\n// - i = (x + bias_x) >> shift_x.\n// - j = (y + bias_y) >> shift_y.\n// where biases and shifts are in the range 0..3 and 0..2 respectively.\n//\n// In general, the biases will be zero after decoding an image. However, making\n// a su" +
- "b-image may change the bias, since the (x, y) coordinates are relative\n// to the sub-image's top-left origin, but the backing pixel buffers were\n// created relative to the original image's origin.\n//\n// For each plane p, each of those four numbers (biases and shifts) are encoded\n// in two bits, which combine to form an 8 bit unsigned integer:\n//\n// e_p = (bias_x << 6) | (shift_x << 4) | (bias_y << 2) | (shift_y << 0)\n//\n// Those e_p values (e_0 for the first plane, e_1 for the second plane, etc)\n// combine to form a wuffs_base__pixel_subsampling value:\n//\n// pixsub = (e_3 << 24) | (e_2 << 16) | (e_1 << 8) | (e_0 << 0)\n//\n// Do not manipulate these bits directly; they are private implementation\n// details. Use methods such as wuffs_base__pixel_subsampling__bias_x instead.\ntypedef uint32_t wuffs_base__pixel_subsampling;\n\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__NONE ((wuffs_base__pixel_subsampling)0)\n\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__444 \\\n ((wuffs_base__pixel_subsampling)0x000000)\n#define WUFFS_BASE__PI" +
- "XEL_SUBSAMPLING__440 \\\n ((wuffs_base__pixel_subsampling)0x010100)\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__422 \\\n ((wuffs_base__pixel_subsampling)0x101000)\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__420 \\\n ((wuffs_base__pixel_subsampling)0x111100)\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__411 \\\n ((wuffs_base__pixel_subsampling)0x202000)\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__410 \\\n ((wuffs_base__pixel_subsampling)0x212100)\n\nstatic inline uint32_t //\nwuffs_base__pixel_subsampling__bias_x(wuffs_base__pixel_subsampling s,\n uint32_t plane) {\n uint32_t shift = ((plane & 0x03) * 8) + 6;\n return (s >> shift) & 0x03;\n}\n\nstatic inline uint32_t //\nwuffs_base__pixel_subsampling__shift_x(wuffs_base__pixel_subsampling s,\n uint32_t plane) {\n uint32_t shift = ((plane & 0x03) * 8) + 4;\n return (s >> shift) & 0x03;\n}\n\nstatic inline uint32_t //\nwuffs_base__pixel_subsampling__bias_y(wuffs_base__pixel_subsampling s,\n " +
- " uint32_t plane) {\n uint32_t shift = ((plane & 0x03) * 8) + 2;\n return (s >> shift) & 0x03;\n}\n\nstatic inline uint32_t //\nwuffs_base__pixel_subsampling__shift_y(wuffs_base__pixel_subsampling s,\n uint32_t plane) {\n uint32_t shift = ((plane & 0x03) * 8) + 0;\n return (s >> shift) & 0x03;\n}\n\n" +
- "" +
- "// --------\n\ntypedef struct {\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__pixel_format pixfmt;\n wuffs_base__pixel_subsampling pixsub;\n uint32_t width;\n uint32_t height;\n } private_impl;\n\n#ifdef __cplusplus\n inline void set(wuffs_base__pixel_format pixfmt,\n wuffs_base__pixel_subsampling pixsub,\n uint32_t width,\n uint32_t height);\n inline void invalidate();\n inline bool is_valid();\n inline wuffs_base__pixel_format pixel_format();\n inline wuffs_base__pixel_subsampling pixel_subsampling();\n inline wuffs_base__rect_ie_u32 bounds();\n inline uint32_t width();\n inline uint32_t height();\n inline uint64_t pixbuf_len();\n#endif // __cplusplus\n\n} wuffs_base__pixel_config;\n\n// TODO: Should this function return bool? An error type?\nstatic inline void //\nwuffs_base__pixel_config__set(wuffs_base__pixel_config* c,\n wuf" +
- "fs_base__pixel_format pixfmt,\n wuffs_base__pixel_subsampling pixsub,\n uint32_t width,\n uint32_t height) {\n if (!c) {\n return;\n }\n if (pixfmt) {\n uint64_t wh = ((uint64_t)width) * ((uint64_t)height);\n // TODO: handle things other than 1 byte per pixel.\n if (wh <= ((uint64_t)SIZE_MAX)) {\n c->private_impl.pixfmt = pixfmt;\n c->private_impl.pixsub = pixsub;\n c->private_impl.width = width;\n c->private_impl.height = height;\n return;\n }\n }\n *c = ((wuffs_base__pixel_config){});\n}\n\nstatic inline void //\nwuffs_base__pixel_config__invalidate(wuffs_base__pixel_config* c) {\n if (c) {\n *c = ((wuffs_base__pixel_config){});\n }\n}\n\nstatic inline bool //\nwuffs_base__pixel_config__is_valid(wuffs_base__pixel_config* c) {\n return c && c->private_impl.pixfmt;\n}\n\nstatic inline wuffs_base__pixel_format //\nwuffs_base__pixel_config__pixel_format(wuffs_base__pixel_config* c) {\n return c ? c->privat" +
- "e_impl.pixfmt : 0;\n}\n\nstatic inline wuffs_base__pixel_subsampling //\nwuffs_base__pixel_config__pixel_subsampling(wuffs_base__pixel_config* c) {\n return c ? c->private_impl.pixsub : 0;\n}\n\nstatic inline wuffs_base__rect_ie_u32 //\nwuffs_base__pixel_config__bounds(wuffs_base__pixel_config* c) {\n return c ? ((wuffs_base__rect_ie_u32){\n .min_incl_x = 0,\n .min_incl_y = 0,\n .max_excl_x = c->private_impl.width,\n .max_excl_y = c->private_impl.height,\n })\n : ((wuffs_base__rect_ie_u32){});\n}\n\nstatic inline uint32_t //\nwuffs_base__pixel_config__width(wuffs_base__pixel_config* c) {\n return c ? c->private_impl.width : 0;\n}\n\nstatic inline uint32_t //\nwuffs_base__pixel_config__height(wuffs_base__pixel_config* c) {\n return c ? c->private_impl.height : 0;\n}\n\n// TODO: this is the right API for planar (not packed) pixbufs? Should it allow\n// decoding into a color model different from the format's intrinsic one? For\n// example, decoding a" +
- " JPEG image straight to RGBA instead of to YCbCr?\nstatic inline uint64_t //\nwuffs_base__pixel_config__pixbuf_len(wuffs_base__pixel_config* c) {\n if (!c) {\n return 0;\n }\n if (wuffs_base__pixel_format__is_planar(c->private_impl.pixfmt)) {\n // TODO: support planar pixel formats, concious of pixel subsampling.\n return 0;\n }\n uint32_t bits_per_pixel =\n wuffs_base__pixel_format__bits_per_pixel(c->private_impl.pixfmt);\n if ((bits_per_pixel == 0) || ((bits_per_pixel % 8) != 0)) {\n // TODO: support fraction-of-byte pixels, e.g. 1 bit per pixel?\n return 0;\n }\n uint64_t bytes_per_pixel = bits_per_pixel / 8;\n\n uint64_t n =\n ((uint64_t)c->private_impl.width) * ((uint64_t)c->private_impl.height);\n if (n > (UINT64_MAX / bytes_per_pixel)) {\n return 0;\n }\n n *= bytes_per_pixel;\n\n if (wuffs_base__pixel_format__is_indexed(c->private_impl.pixfmt)) {\n if (n > (UINT64_MAX - 1024)) {\n return 0;\n }\n n += 1024;\n }\n\n return n;\n}\n\n#ifdef __cplusplus\n\ninline void //\nwuffs_base__" +
- "pixel_config::set(wuffs_base__pixel_format pixfmt,\n wuffs_base__pixel_subsampling pixsub,\n uint32_t width,\n uint32_t height) {\n wuffs_base__pixel_config__set(this, pixfmt, pixsub, width, height);\n}\n\ninline void //\nwuffs_base__pixel_config::invalidate() {\n wuffs_base__pixel_config__invalidate(this);\n}\n\ninline bool //\nwuffs_base__pixel_config::is_valid() {\n return wuffs_base__pixel_config__is_valid(this);\n}\n\ninline wuffs_base__pixel_format //\nwuffs_base__pixel_config::pixel_format() {\n return wuffs_base__pixel_config__pixel_format(this);\n}\n\ninline wuffs_base__pixel_subsampling //\nwuffs_base__pixel_config::pixel_subsampling() {\n return wuffs_base__pixel_config__pixel_subsampling(this);\n}\n\ninline wuffs_base__rect_ie_u32 //\nwuffs_base__pixel_config::bounds() {\n return wuffs_base__pixel_config__bounds(this);\n}\n\ninline uint32_t //\nwuffs_base__pixel_config::width() {\n return wuffs_base__pixel_config__width(this);\n}\n\nin" +
- "line uint32_t //\nwuffs_base__pixel_config::height() {\n return wuffs_base__pixel_config__height(this);\n}\n\ninline uint64_t //\nwuffs_base__pixel_config::pixbuf_len() {\n return wuffs_base__pixel_config__pixbuf_len(this);\n}\n\n#endif // __cplusplus\n\n" +
- "" +
- "// --------\n\ntypedef struct {\n wuffs_base__pixel_config pixcfg;\n\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 uint64_t first_frame_io_position;\n bool first_frame_is_opaque;\n } private_impl;\n\n#ifdef __cplusplus\n inline void set(wuffs_base__pixel_format pixfmt,\n wuffs_base__pixel_subsampling pixsub,\n uint32_t width,\n uint32_t height,\n uint64_t first_frame_io_position,\n bool first_frame_is_opaque);\n inline void invalidate();\n inline bool is_valid();\n inline uint64_t first_frame_io_position();\n inline bool first_frame_is_opaque();\n#endif // __cplusplus\n\n} wuffs_base__image_config;\n\n// TODO: Should this function return bool? An error type?\nstatic inline void //\nwuffs_base__image_config__set(wuffs_base__image_config* c,\n wuffs_base__pixel_format pixfmt,\n wuffs_base__" +
- "pixel_subsampling pixsub,\n uint32_t width,\n uint32_t height,\n uint64_t first_frame_io_position,\n bool first_frame_is_opaque) {\n if (!c) {\n return;\n }\n if (wuffs_base__pixel_format__is_valid(pixfmt)) {\n c->pixcfg.private_impl.pixfmt = pixfmt;\n c->pixcfg.private_impl.pixsub = pixsub;\n c->pixcfg.private_impl.width = width;\n c->pixcfg.private_impl.height = height;\n c->private_impl.first_frame_io_position = first_frame_io_position;\n c->private_impl.first_frame_is_opaque = first_frame_is_opaque;\n return;\n }\n *c = ((wuffs_base__image_config){});\n}\n\nstatic inline void //\nwuffs_base__image_config__invalidate(wuffs_base__image_config* c) {\n if (c) {\n *c = ((wuffs_base__image_config){});\n }\n}\n\nstatic inline bool //\nwuffs_base__image_config__is_valid(wuffs_base__image_config* c) {\n return c && wuffs_base__pixel_config__is_valid(&(c->pixcfg));\n}\n\nstatic inline uint64_t /" +
- "/\nwuffs_base__image_config__first_frame_io_position(wuffs_base__image_config* c) {\n return c ? c->private_impl.first_frame_io_position : 0;\n}\n\nstatic inline bool //\nwuffs_base__image_config__first_frame_is_opaque(wuffs_base__image_config* c) {\n return c ? c->private_impl.first_frame_is_opaque : false;\n}\n\n#ifdef __cplusplus\n\ninline void //\nwuffs_base__image_config::set(wuffs_base__pixel_format pixfmt,\n wuffs_base__pixel_subsampling pixsub,\n uint32_t width,\n uint32_t height,\n uint64_t first_frame_io_position,\n bool first_frame_is_opaque) {\n wuffs_base__image_config__set(this, pixfmt, pixsub, width, height,\n first_frame_io_position, first_frame_is_opaque);\n}\n\ninline void //\nwuffs_base__image_config::invalidate() {\n wuffs_base__image_config__invalidate(this);\n}\n\ninline bool //\nwuffs_base__image_config::is_valid() {\n return wuffs_ba" +
- "se__image_config__is_valid(this);\n}\n\ninline uint64_t //\nwuffs_base__image_config::first_frame_io_position() {\n return wuffs_base__image_config__first_frame_io_position(this);\n}\n\ninline bool //\nwuffs_base__image_config::first_frame_is_opaque() {\n return wuffs_base__image_config__first_frame_is_opaque(this);\n}\n\n#endif // __cplusplus\n\n" +
- "" +
- "// --------\n\n// wuffs_base__animation_blend encodes, for an animated image, how to blend the\n// transparent pixels of this frame with the existing canvas. In Porter-Duff\n// compositing operator terminology:\n// - 0 means the frame may be transparent, and should be blended \"src over\n// dst\", also known as just \"over\".\n// - 1 means the frame may be transparent, and should be blended \"src\".\n// - 2 means the frame is completely opaque, so that \"src over dst\" and \"src\"\n// are equivalent.\n//\n// These semantics are conservative. It is valid for a completely opaque frame\n// to have a blend value other than 2.\ntypedef uint8_t wuffs_base__animation_blend;\n\n#define WUFFS_BASE__ANIMATION_BLEND__SRC_OVER_DST \\\n ((wuffs_base__animation_blend)0)\n#define WUFFS_BASE__ANIMATION_BLEND__SRC ((wuffs_base__animation_blend)1)\n#define WUFFS_BASE__ANIMATION_BLEND__OPAQUE ((wuffs_base__animation_blend)2)\n\n" +
- "" +
- "// --------\n\n// wuffs_base__animation_disposal encodes, for an animated image, how to\n// dispose of a frame after displaying it:\n// - None means to draw the next frame on top of this one.\n// - Restore Background means to clear the frame's dirty rectangle to \"the\n// background color\" (in practice, this means transparent black) before\n// drawing the next frame.\n// - Restore Previous means to undo the current frame, so that the next frame\n// is drawn on top of the previous one.\ntypedef uint8_t wuffs_base__animation_disposal;\n\n#define WUFFS_BASE__ANIMATION_DISPOSAL__NONE ((wuffs_base__animation_disposal)0)\n#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_BACKGROUND \\\n ((wuffs_base__animation_disposal)1)\n#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_PREVIOUS \\\n ((wuffs_base__animation_disposal)2)\n\n" +
- "" +
- "// --------\n\ntypedef struct {\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__rect_ie_u32 bounds;\n wuffs_base__flicks duration;\n uint64_t index;\n uint64_t io_position;\n wuffs_base__animation_blend blend;\n wuffs_base__animation_disposal disposal;\n } private_impl;\n\n#ifdef __cplusplus\n inline void update(wuffs_base__rect_ie_u32 bounds,\n wuffs_base__flicks duration,\n uint64_t index,\n uint64_t io_position,\n wuffs_base__animation_blend blend,\n wuffs_base__animation_disposal disposal);\n inline wuffs_base__rect_ie_u32 bounds();\n inline uint32_t width();\n inline uint32_t height();\n inline wuffs_base__flicks duration();\n inline uint64_t index();\n inline uint64_t io_position();\n inline wuffs_base__animation_blend blend();\n inline wuffs_base__animation_disposal disposal();\n#endif // __cpluspl" +
- "us\n\n} wuffs_base__frame_config;\n\nstatic inline void //\nwuffs_base__frame_config__update(wuffs_base__frame_config* c,\n wuffs_base__rect_ie_u32 bounds,\n wuffs_base__flicks duration,\n uint64_t index,\n uint64_t io_position,\n wuffs_base__animation_blend blend,\n wuffs_base__animation_disposal disposal) {\n if (!c) {\n return;\n }\n\n c->private_impl.bounds = bounds;\n c->private_impl.duration = duration;\n c->private_impl.index = index;\n c->private_impl.io_position = io_position;\n c->private_impl.blend = blend;\n c->private_impl.disposal = disposal;\n}\n\nstatic inline wuffs_base__rect_ie_u32 //\nwuffs_base__frame_config__bounds(wuffs_base__frame_config* c) {\n return c ? c->private_impl.bounds : ((wuffs_base__rect_ie_u32){});\n}\n\nstatic inline uint32_t //\nwuffs_base__frame_config__width(wuffs_base__frame_config* c) {\n retur" +
- "n c ? wuffs_base__rect_ie_u32__width(&c->private_impl.bounds) : 0;\n}\n\nstatic inline uint32_t //\nwuffs_base__frame_config__height(wuffs_base__frame_config* c) {\n return c ? wuffs_base__rect_ie_u32__height(&c->private_impl.bounds) : 0;\n}\n\n// wuffs_base__frame_config__duration returns the amount of time to display\n// this frame. Zero means to display forever - a still (non-animated) image.\nstatic inline wuffs_base__flicks //\nwuffs_base__frame_config__duration(wuffs_base__frame_config* c) {\n return c ? c->private_impl.duration : 0;\n}\n\n// wuffs_base__frame_config__index returns the index of this frame. The first\n// frame in an image has index 0, the second frame has index 1, and so on.\nstatic inline uint64_t //\nwuffs_base__frame_config__index(wuffs_base__frame_config* c) {\n return c ? c->private_impl.index : 0;\n}\n\n// wuffs_base__frame_config__io_position returns the I/O stream position before\n// the frame config.\nstatic inline uint64_t //\nwuffs_base__frame_config__io_position(wuffs_base__frame_config* c) {\n" +
- " return c ? c->private_impl.io_position : 0;\n}\n\n// wuffs_base__frame_config__blend returns, for an animated image, how to blend\n// the transparent pixels of this frame with the existing canvas.\nstatic inline wuffs_base__animation_blend //\nwuffs_base__frame_config__blend(wuffs_base__frame_config* c) {\n return c ? c->private_impl.blend : 0;\n}\n\n// wuffs_base__frame_config__disposal returns, for an animated image, how to\n// dispose of this frame after displaying it.\nstatic inline wuffs_base__animation_disposal //\nwuffs_base__frame_config__disposal(wuffs_base__frame_config* c) {\n return c ? c->private_impl.disposal : 0;\n}\n\n#ifdef __cplusplus\n\ninline void //\nwuffs_base__frame_config::update(wuffs_base__rect_ie_u32 bounds,\n wuffs_base__flicks duration,\n uint64_t index,\n uint64_t io_position,\n wuffs_base__animation_blend blend,\n wuffs_base__animation_dis" +
- "posal disposal) {\n wuffs_base__frame_config__update(this, bounds, duration, index, io_position,\n blend, disposal);\n}\n\ninline wuffs_base__rect_ie_u32 //\nwuffs_base__frame_config::bounds() {\n return wuffs_base__frame_config__bounds(this);\n}\n\ninline uint32_t //\nwuffs_base__frame_config::width() {\n return wuffs_base__frame_config__width(this);\n}\n\ninline uint32_t //\nwuffs_base__frame_config::height() {\n return wuffs_base__frame_config__height(this);\n}\n\ninline wuffs_base__flicks //\nwuffs_base__frame_config::duration() {\n return wuffs_base__frame_config__duration(this);\n}\n\ninline uint64_t //\nwuffs_base__frame_config::index() {\n return wuffs_base__frame_config__index(this);\n}\n\ninline uint64_t //\nwuffs_base__frame_config::io_position() {\n return wuffs_base__frame_config__io_position(this);\n}\n\ninline wuffs_base__animation_blend //\nwuffs_base__frame_config::blend() {\n return wuffs_base__frame_config__blend(this);\n}\n\ninline wuffs_base__animation_disposal //\nwuffs_base__fr" +
- "ame_config::disposal() {\n return wuffs_base__frame_config__disposal(this);\n}\n\n#endif // __cplusplus\n\n" +
- "" +
- "// --------\n\ntypedef struct {\n wuffs_base__pixel_config pixcfg;\n\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__table_u8 planes[WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX];\n // TODO: color spaces.\n } private_impl;\n\n#ifdef __cplusplus\n inline wuffs_base__status set_from_slice(wuffs_base__pixel_config* pixcfg,\n wuffs_base__slice_u8 pixbuf_memory);\n inline wuffs_base__slice_u8 palette();\n inline wuffs_base__pixel_format pixel_format();\n inline wuffs_base__table_u8 plane(uint32_t p);\n#endif // __cplusplus\n\n} wuffs_base__pixel_buffer;\n\nstatic inline wuffs_base__status //\nwuffs_base__pixel_buffer__set_from_slice(wuffs_base__pixel_buffer* b,\n wuffs_base__pixel_config* pixcfg,\n wuffs_base__slice_u8 pixbuf_memory) {\n if (!b) {\n return wuffs_base__error__bad_receiver;\n }\n *b = (" +
- "(wuffs_base__pixel_buffer){});\n if (!pixcfg) {\n return wuffs_base__error__bad_argument;\n }\n if (wuffs_base__pixel_format__is_planar(pixcfg->private_impl.pixfmt)) {\n // TODO: support planar pixel formats, concious of pixel subsampling.\n return wuffs_base__error__bad_argument;\n }\n uint32_t bits_per_pixel =\n wuffs_base__pixel_format__bits_per_pixel(pixcfg->private_impl.pixfmt);\n if ((bits_per_pixel == 0) || ((bits_per_pixel % 8) != 0)) {\n return wuffs_base__error__bad_argument;\n }\n uint64_t bytes_per_pixel = bits_per_pixel / 8;\n\n uint8_t* ptr = pixbuf_memory.ptr;\n uint64_t len = pixbuf_memory.len;\n if (wuffs_base__pixel_format__is_indexed(pixcfg->private_impl.pixfmt)) {\n // Split a 1024 byte chunk (256 palette entries × 4 bytes per entry) from\n // the start of pixbuf_memory. We split from the start, not the end, so\n // that the both chunks' pointers have the same alignment as the original\n // pointer, up to an alignment of 1024.\n if (len < 1024) {\n return wuffs_ba" +
- "se__error__bad_argument_length_too_short;\n }\n wuffs_base__table_u8* tab =\n &b->private_impl.planes[WUFFS_BASE__PIXEL_FORMAT__INDEXED__COLOR_PLANE];\n tab->ptr = ptr;\n tab->width = 1024;\n tab->height = 1;\n tab->stride = 1024;\n ptr += 1024;\n len -= 1024;\n }\n\n uint64_t wh = ((uint64_t)pixcfg->private_impl.width) *\n ((uint64_t)pixcfg->private_impl.height);\n size_t width = (size_t)(pixcfg->private_impl.width);\n if ((wh > (UINT64_MAX / bytes_per_pixel)) ||\n (width > (SIZE_MAX / bytes_per_pixel))) {\n return wuffs_base__error__bad_argument;\n }\n wh *= bytes_per_pixel;\n width *= bytes_per_pixel;\n if (wh > len) {\n return wuffs_base__error__bad_argument_length_too_short;\n }\n\n b->pixcfg = *pixcfg;\n wuffs_base__table_u8* tab = &b->private_impl.planes[0];\n tab->ptr = ptr;\n tab->width = width;\n tab->height = pixcfg->private_impl.height;\n tab->stride = width;\n return NULL;\n}\n\n// wuffs_base__pixel_buffer__palette returns the palette color data. If\n// non-e" +
- "mpty, it will have length 1024.\nstatic inline wuffs_base__slice_u8 //\nwuffs_base__pixel_buffer__palette(wuffs_base__pixel_buffer* b) {\n if (b &&\n wuffs_base__pixel_format__is_indexed(b->pixcfg.private_impl.pixfmt)) {\n wuffs_base__table_u8* tab =\n &b->private_impl.planes[WUFFS_BASE__PIXEL_FORMAT__INDEXED__COLOR_PLANE];\n if ((tab->width == 1024) && (tab->height == 1)) {\n return ((wuffs_base__slice_u8){\n .ptr = tab->ptr,\n .len = 1024,\n });\n }\n }\n return ((wuffs_base__slice_u8){});\n}\n\nstatic inline wuffs_base__pixel_format //\nwuffs_base__pixel_buffer__pixel_format(wuffs_base__pixel_buffer* b) {\n if (b) {\n return b->pixcfg.private_impl.pixfmt;\n }\n return WUFFS_BASE__PIXEL_FORMAT__INVALID;\n}\n\nstatic inline wuffs_base__table_u8 //\nwuffs_base__pixel_buffer__plane(wuffs_base__pixel_buffer* b, uint32_t p) {\n return (b && (p < WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX))\n ? b->private_impl.planes[p]\n : ((wuffs_base__table_u8){});\n}\n\n#ifd" +
- "ef __cplusplus\n\ninline wuffs_base__status //\nwuffs_base__pixel_buffer::set_from_slice(wuffs_base__pixel_config* pixcfg,\n wuffs_base__slice_u8 pixbuf_memory) {\n return wuffs_base__pixel_buffer__set_from_slice(this, pixcfg, pixbuf_memory);\n}\n\ninline wuffs_base__slice_u8 //\nwuffs_base__pixel_buffer::palette() {\n return wuffs_base__pixel_buffer__palette(this);\n}\n\ninline wuffs_base__pixel_format //\nwuffs_base__pixel_buffer::pixel_format() {\n return wuffs_base__pixel_buffer__pixel_format(this);\n}\n\ninline wuffs_base__table_u8 //\nwuffs_base__pixel_buffer::plane(uint32_t p) {\n return wuffs_base__pixel_buffer__plane(this, p);\n}\n\n#endif // __cplusplus\n\n" +
- "" +
- "// --------\n\ntypedef struct {\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 uint8_t TODO;\n } private_impl;\n\n#ifdef __cplusplus\n#endif // __cplusplus\n\n} wuffs_base__decode_frame_options;\n\n#ifdef __cplusplus\n\n#endif // __cplusplus\n\n" +
- "" +
- "// --------\n\ntypedef struct {\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 // TODO: should the func type take restrict pointers?\n uint64_t (*func)(wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src);\n } private_impl;\n\n#ifdef __cplusplus\n inline void prepare(wuffs_base__pixel_format dst_format,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__pixel_format src_format,\n wuffs_base__slice_u8 src_palette);\n inline uint64_t swizzle_packed(wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src);\n#endif // __cplusplus\n\n} wuffs_base__pixel_swizzler;\n\n// TODO: should prepare (both the C and C++ methods) return a status?\n\nvoid //\nwuffs_base__pixel_swizzler__prepare(wuffs_base__pixel_swi" +
- "zzler* p,\n wuffs_base__pixel_format dst_format,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__pixel_format src_format,\n wuffs_base__slice_u8 src_palette);\n\nuint64_t //\nwuffs_base__pixel_swizzler__swizzle_packed(wuffs_base__pixel_swizzler* p,\n wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src);\n\n#ifdef __cplusplus\n\ninline void //\nwuffs_base__pixel_swizzler::prepare(wuffs_base__pixel_format dst_format,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__pixel_format src_format,\n wuffs_base__slice_u8 src_palette) {\n wuffs_base__pixel_swizzler__prepare(this, dst_format, dst_palette, src_format,\n " +
- " src_palette);\n}\n\nuint64_t //\nwuffs_base__pixel_swizzler::swizzle_packed(wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src) {\n return wuffs_base__pixel_swizzler__swizzle_packed(this, dst, dst_palette,\n src);\n}\n\n#endif // __cplusplus\n" +
- ""
-
-const baseIOPrivateH = "" +
- "// ---------------- I/O\n\nstatic inline bool //\nwuffs_base__io_buffer__is_valid(wuffs_base__io_buffer buf) {\n return (buf.data.ptr || (buf.data.len == 0)) &&\n (buf.data.len >= buf.meta.wi) && (buf.meta.wi >= buf.meta.ri);\n}\n\n// TODO: wuffs_base__io_reader__is_eof is no longer used by Wuffs per se, but\n// it might be handy to programs that use Wuffs. Either delete it, or promote\n// it to the public API.\n//\n// If making this function public (i.e. moving it to base-header.h), it also\n// needs to allow NULL (i.e. implicit, callee-calculated) mark/limit.\n\nstatic inline bool //\nwuffs_base__io_reader__is_eof(wuffs_base__io_reader o) {\n wuffs_base__io_buffer* buf = o.private_impl.buf;\n return buf && buf->meta.closed &&\n (buf->data.ptr + buf->meta.wi == o.private_impl.limit);\n}\n\nstatic inline bool //\nwuffs_base__io_reader__is_valid(wuffs_base__io_reader o) {\n wuffs_base__io_buffer* buf = o.private_impl.buf;\n // Note: if making this function public (i.e. moving it to base-header.h), it\n // also " +
- "needs to allow NULL (i.e. implicit, callee-calculated) mark/limit.\n return buf ? ((buf->data.ptr <= o.private_impl.mark) &&\n (o.private_impl.mark <= o.private_impl.limit) &&\n (o.private_impl.limit <= buf->data.ptr + buf->data.len))\n : ((o.private_impl.mark == NULL) &&\n (o.private_impl.limit == NULL));\n}\n\nstatic inline bool //\nwuffs_base__io_writer__is_valid(wuffs_base__io_writer o) {\n wuffs_base__io_buffer* buf = o.private_impl.buf;\n // Note: if making this function public (i.e. moving it to base-header.h), it\n // also needs to allow NULL (i.e. implicit, callee-calculated) mark/limit.\n return buf ? ((buf->data.ptr <= o.private_impl.mark) &&\n (o.private_impl.mark <= o.private_impl.limit) &&\n (o.private_impl.limit <= buf->data.ptr + buf->data.len))\n : ((o.private_impl.mark == NULL) &&\n (o.private_impl.limit == NULL));\n}\n\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n_from_history(uin" +
- "t8_t** ptr_iop_w,\n uint8_t* io0_w,\n uint8_t* io1_w,\n uint32_t length,\n uint32_t distance) {\n if (!distance) {\n return 0;\n }\n uint8_t* p = *ptr_iop_w;\n if ((size_t)(p - io0_w) < (size_t)(distance)) {\n return 0;\n }\n uint8_t* q = p - distance;\n size_t n = io1_w - p;\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/deflate benchmarks, but that\n // is mostly because 3 is the minimum length for the deflate format. This\n // function implementation shouldn't overfit to that one format. Perhaps the\n // copy_n_from_history Wuffs method should 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__io_writer__copy_n_from_history_fast below.\n //\n // Alternatively, or additionall" +
- "y, have a sloppy_copy_n_from_history method\n // that copies 8 bytes at a time, possibly writing more than length bytes?\n for (; n >= 3; n -= 3) {\n *p++ = *q++;\n *p++ = *q++;\n *p++ = *q++;\n }\n for (; n; n--) {\n *p++ = *q++;\n }\n *ptr_iop_w = p;\n return length;\n}\n\n// wuffs_base__io_writer__copy_n_from_history_fast is like the\n// wuffs_base__io_writer__copy_n_from_history function above, but has stronger\n// pre-conditions. The caller needs to prove that:\n// - distance > 0\n// - distance <= (*ptr_iop_w - io0_w)\n// - length <= (io1_w - *ptr_iop_w)\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n_from_history_fast(uint8_t** ptr_iop_w,\n uint8_t* io0_w,\n uint8_t* io1_w,\n uint32_t length,\n uint32_t distance) {\n uint8_t* p = *ptr_iop_w;\n uint8_t* q = p - distance;\n uint32_t n = length;\n for (; n" +
- " >= 3; n -= 3) {\n *p++ = *q++;\n *p++ = *q++;\n *p++ = *q++;\n }\n for (; n; n--) {\n *p++ = *q++;\n }\n *ptr_iop_w = p;\n return length;\n}\n\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n_from_reader(uint8_t** ptr_iop_w,\n uint8_t* io1_w,\n uint32_t length,\n uint8_t** ptr_iop_r,\n uint8_t* io1_r) {\n uint8_t* iop_w = *ptr_iop_w;\n size_t n = length;\n if (n > ((size_t)(io1_w - iop_w))) {\n n = io1_w - iop_w;\n }\n uint8_t* iop_r = *ptr_iop_r;\n if (n > ((size_t)(io1_r - iop_r))) {\n n = io1_r - iop_r;\n }\n if (n > 0) {\n memmove(iop_w, iop_r, n);\n *ptr_iop_w += n;\n *ptr_iop_r += n;\n }\n return n;\n}\n\nstatic inline uint64_t //\nwuffs_base__io_writer__copy_from_slice(uint8_t** ptr_iop_w,\n uint8_t* io1_w,\n wuffs_base__slice_u8 src) {\n uint8_t* iop" +
- "_w = *ptr_iop_w;\n size_t n = src.len;\n if (n > ((size_t)(io1_w - iop_w))) {\n n = io1_w - iop_w;\n }\n if (n > 0) {\n memmove(iop_w, src.ptr, n);\n *ptr_iop_w += n;\n }\n return n;\n}\n\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n_from_slice(uint8_t** ptr_iop_w,\n uint8_t* io1_w,\n uint32_t length,\n wuffs_base__slice_u8 src) {\n uint8_t* iop_w = *ptr_iop_w;\n size_t n = src.len;\n if (n > length) {\n n = length;\n }\n if (n > ((size_t)(io1_w - iop_w))) {\n n = io1_w - iop_w;\n }\n if (n > 0) {\n memmove(iop_w, src.ptr, n);\n *ptr_iop_w += n;\n }\n return n;\n}\n\nstatic inline wuffs_base__empty_struct //\nwuffs_base__io_reader__set(wuffs_base__io_reader* o,\n wuffs_base__io_buffer* b,\n uint8_t** ptr_iop_r,\n uint8_t** ptr_io1_r,\n wuffs_base__slice_u8 data) {\n b->data = " +
- "data;\n b->meta.wi = data.len;\n b->meta.ri = 0;\n b->meta.pos = 0;\n b->meta.closed = false;\n\n o->private_impl.buf = b;\n o->private_impl.mark = data.ptr;\n o->private_impl.limit = data.ptr + data.len;\n *ptr_iop_r = data.ptr;\n *ptr_io1_r = data.ptr + data.len;\n return ((wuffs_base__empty_struct){});\n}\n\nstatic inline wuffs_base__empty_struct //\nwuffs_base__io_reader__set_limit(wuffs_base__io_reader* o,\n uint8_t* iop_r,\n uint64_t limit) {\n if (o && (((size_t)(o->private_impl.limit - iop_r)) > limit)) {\n o->private_impl.limit = iop_r + limit;\n }\n return ((wuffs_base__empty_struct){});\n}\n\nstatic inline wuffs_base__empty_struct //\nwuffs_base__io_reader__set_mark(wuffs_base__io_reader* o, uint8_t* mark) {\n o->private_impl.mark = mark;\n return ((wuffs_base__empty_struct){});\n}\n\nstatic inline wuffs_base__slice_u8 //\nwuffs_base__io_reader__take(uint8_t** ptr_iop_r, uint8_t* io1_r, uint64_t n) {\n if (n <= ((size_t)(io1_r - *ptr_iop_r))) {\n" +
- " uint8_t* p = *ptr_iop_r;\n *ptr_iop_r += n;\n return ((wuffs_base__slice_u8){\n .ptr = p,\n .len = n,\n });\n }\n return ((wuffs_base__slice_u8){});\n}\n\nstatic inline wuffs_base__empty_struct //\nwuffs_base__io_writer__set(wuffs_base__io_writer* o,\n wuffs_base__io_buffer* b,\n uint8_t** ptr_iop_w,\n uint8_t** ptr_io1_w,\n wuffs_base__slice_u8 data) {\n b->data = data;\n b->meta.wi = 0;\n b->meta.ri = 0;\n b->meta.pos = 0;\n b->meta.closed = false;\n\n o->private_impl.buf = b;\n o->private_impl.mark = data.ptr;\n o->private_impl.limit = data.ptr + data.len;\n *ptr_iop_w = data.ptr;\n *ptr_io1_w = data.ptr + data.len;\n return ((wuffs_base__empty_struct){});\n}\n\nstatic inline wuffs_base__empty_struct //\nwuffs_base__io_writer__set_mark(wuffs_base__io_writer* o, uint8_t* mark) {\n o->private_impl.mark = mark;\n return ((wuffs_base__empty_struct){});\n}\n\n" +
- "" +
- "// ---------------- I/O (Utility)\n\nstatic inline wuffs_base__io_reader //\nwuffs_base__utility__null_io_reader(const wuffs_base__utility* ignored) {\n return ((wuffs_base__io_reader){});\n}\n\nstatic inline wuffs_base__io_writer //\nwuffs_base__utility__null_io_writer(const wuffs_base__utility* ignored) {\n return ((wuffs_base__io_writer){});\n}\n" +
- ""
-
-const baseIOPublicH = "" +
- "// ---------------- I/O\n\nstruct wuffs_base__io_buffer__struct;\n\ntypedef struct {\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 struct wuffs_base__io_buffer__struct* buf;\n // The bounds values are typically NULL, when created by the Wuffs public\n // API. NULL means that the callee substitutes the implicit bounds derived\n // from buf.\n uint8_t* mark;\n uint8_t* limit;\n } private_impl;\n} wuffs_base__io_reader;\n\ntypedef struct {\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 struct wuffs_base__io_buffer__struct* buf;\n // The bounds values are typically NULL, when created by the Wuffs public\n // API. NULL means that the callee substitutes the implicit bounds derived\n // from buf.\n uint8_t* mark;\n uint8_t* limit;\n } private_impl;\n} wuffs_base__io_writer;\n\n// wuffs_base__io_buffer_meta is the met" +
- "adata for a wuffs_base__io_buffer's\n// data.\ntypedef struct {\n size_t wi; // Write index. Invariant: wi <= len.\n size_t ri; // Read index. Invariant: ri <= wi.\n uint64_t pos; // Position of the buffer start relative to the stream start.\n bool closed; // No further writes are expected.\n} wuffs_base__io_buffer_meta;\n\n// wuffs_base__io_buffer is a 1-dimensional buffer (a pointer and length) plus\n// additional metadata.\n//\n// A value with all fields zero is a valid, empty buffer.\ntypedef struct wuffs_base__io_buffer__struct {\n wuffs_base__slice_u8 data;\n wuffs_base__io_buffer_meta meta;\n\n#ifdef __cplusplus\n inline void compact();\n inline wuffs_base__io_reader reader();\n inline wuffs_base__io_writer writer();\n inline uint64_t reader_io_position();\n inline uint64_t writer_io_position();\n#endif // __cplusplus\n\n} wuffs_base__io_buffer;\n\n// wuffs_base__io_buffer__compact moves any written but unread bytes to the\n// start of the buffer.\nstatic inline void //\nwuffs_base__io_buffer__compact(wuffs" +
- "_base__io_buffer* buf) {\n if (!buf || (buf->meta.ri == 0)) {\n return;\n }\n buf->meta.pos = wuffs_base__u64__sat_add(buf->meta.pos, buf->meta.ri);\n size_t n = buf->meta.wi - buf->meta.ri;\n if (n != 0) {\n memmove(buf->data.ptr, buf->data.ptr + buf->meta.ri, n);\n }\n buf->meta.wi = n;\n buf->meta.ri = 0;\n}\n\nstatic inline wuffs_base__io_reader //\nwuffs_base__io_buffer__reader(wuffs_base__io_buffer* buf) {\n wuffs_base__io_reader ret = ((wuffs_base__io_reader){});\n ret.private_impl.buf = buf;\n return ret;\n}\n\nstatic inline wuffs_base__io_writer //\nwuffs_base__io_buffer__writer(wuffs_base__io_buffer* buf) {\n wuffs_base__io_writer ret = ((wuffs_base__io_writer){});\n ret.private_impl.buf = buf;\n return ret;\n}\n\nstatic inline uint64_t //\nwuffs_base__io_buffer__reader_io_position(wuffs_base__io_buffer* buf) {\n return buf ? wuffs_base__u64__sat_add(buf->meta.pos, buf->meta.ri) : 0;\n}\n\nstatic inline uint64_t //\nwuffs_base__io_buffer__writer_io_position(wuffs_base__io_buffer* buf) {\n return buf ? wuffs" +
- "_base__u64__sat_add(buf->meta.pos, buf->meta.wi) : 0;\n}\n\n#ifdef __cplusplus\n\ninline void //\nwuffs_base__io_buffer__struct::compact() {\n wuffs_base__io_buffer__compact(this);\n}\n\ninline wuffs_base__io_reader //\nwuffs_base__io_buffer__struct::reader() {\n return wuffs_base__io_buffer__reader(this);\n}\n\ninline wuffs_base__io_writer //\nwuffs_base__io_buffer__struct::writer() {\n return wuffs_base__io_buffer__writer(this);\n}\n\ninline uint64_t //\nwuffs_base__io_buffer__struct::reader_io_position() {\n return wuffs_base__io_buffer__reader_io_position(this);\n}\n\ninline uint64_t //\nwuffs_base__io_buffer__struct::writer_io_position() {\n return wuffs_base__io_buffer__writer_io_position(this);\n}\n\n#endif // __cplusplus\n" +
- ""
-
-const baseRangePrivateH = "" +
- "// ---------------- Ranges and Rects\n\nstatic inline uint32_t //\nwuffs_base__range_ii_u32__get_min_incl(const wuffs_base__range_ii_u32* r) {\n return r->min_incl;\n}\n\nstatic inline uint32_t //\nwuffs_base__range_ii_u32__get_max_incl(const wuffs_base__range_ii_u32* r) {\n return r->max_incl;\n}\n\nstatic inline uint32_t //\nwuffs_base__range_ie_u32__get_min_incl(const wuffs_base__range_ie_u32* r) {\n return r->min_incl;\n}\n\nstatic inline uint32_t //\nwuffs_base__range_ie_u32__get_max_excl(const wuffs_base__range_ie_u32* r) {\n return r->max_excl;\n}\n\nstatic inline uint64_t //\nwuffs_base__range_ii_u64__get_min_incl(const wuffs_base__range_ii_u64* r) {\n return r->min_incl;\n}\n\nstatic inline uint64_t //\nwuffs_base__range_ii_u64__get_max_incl(const wuffs_base__range_ii_u64* r) {\n return r->max_incl;\n}\n\nstatic inline uint64_t //\nwuffs_base__range_ie_u64__get_min_incl(const wuffs_base__range_ie_u64* r) {\n return r->min_incl;\n}\n\nstatic inline uint64_t //\nwuffs_base__range_ie_u64__get_max_excl(const wuffs_base__range_" +
- "ie_u64* r) {\n return r->max_excl;\n}\n\n" +
- "" +
- "// ---------------- Ranges and Rects (Utility)\n\nstatic inline wuffs_base__range_ii_u32 //\nwuffs_base__utility__make_range_ii_u32(const wuffs_base__utility* ignored,\n uint32_t min_incl,\n uint32_t max_incl) {\n return ((wuffs_base__range_ii_u32){\n .min_incl = min_incl,\n .max_incl = max_incl,\n });\n}\n\nstatic inline wuffs_base__range_ie_u32 //\nwuffs_base__utility__make_range_ie_u32(const wuffs_base__utility* ignored,\n uint32_t min_incl,\n uint32_t max_excl) {\n return ((wuffs_base__range_ie_u32){\n .min_incl = min_incl,\n .max_excl = max_excl,\n });\n}\n\nstatic inline wuffs_base__range_ii_u64 //\nwuffs_base__utility__make_range_ii_u64(const wuffs_base__utility* ignored,\n uint64_t min_incl,\n uint64_t max_incl) {\n return ((wuffs_base__range_ii_u64){\n .min_incl = min_in" +
- "cl,\n .max_incl = max_incl,\n });\n}\n\nstatic inline wuffs_base__range_ie_u64 //\nwuffs_base__utility__make_range_ie_u64(const wuffs_base__utility* ignored,\n uint64_t min_incl,\n uint64_t max_excl) {\n return ((wuffs_base__range_ie_u64){\n .min_incl = min_incl,\n .max_excl = max_excl,\n });\n}\n\nstatic inline wuffs_base__rect_ii_u32 //\nwuffs_base__utility__make_rect_ii_u32(const wuffs_base__utility* ignored,\n uint32_t min_incl_x,\n uint32_t min_incl_y,\n uint32_t max_incl_x,\n uint32_t max_incl_y) {\n return ((wuffs_base__rect_ii_u32){\n .min_incl_x = min_incl_x,\n .min_incl_y = min_incl_y,\n .max_incl_x = max_incl_x,\n .max_incl_y = max_incl_y,\n });\n}\n\nstatic inline wuffs_base__rect_ie_u32 //\nwuffs_base__utility__make_rect_ie_u32(const wuffs_base__utility* ignored,\n" +
- " uint32_t min_incl_x,\n uint32_t min_incl_y,\n uint32_t max_excl_x,\n uint32_t max_excl_y) {\n return ((wuffs_base__rect_ie_u32){\n .min_incl_x = min_incl_x,\n .min_incl_y = min_incl_y,\n .max_excl_x = max_excl_x,\n .max_excl_y = max_excl_y,\n });\n}\n" +
- ""
-
-const baseRangePublicH = "" +
- "// ---------------- Ranges and Rects\n\n// Ranges are either inclusive (\"range_ii\") or exclusive (\"range_ie\") on the\n// high end. Both the \"ii\" and \"ie\" flavors are useful in practice.\n//\n// The \"ei\" and \"ee\" flavors also exist in theory, but aren't widely used. In\n// Wuffs, the low end is always inclusive.\n//\n// The \"ii\" (closed interval) flavor is useful when refining e.g. \"the set of\n// all uint32_t values\" to a contiguous subset: \"uint32_t values in the closed\n// interval [M, N]\", for uint32_t values M and N. An unrefined type (in other\n// words, the set of all uint32_t values) is not representable in the \"ie\"\n// flavor because if N equals ((1<<32) - 1) then (N + 1) will overflow.\n//\n// On the other hand, the \"ie\" (half-open interval) flavor is recommended by\n// Dijkstra's \"Why numbering should start at zero\" at\n// http://www.cs.utexas.edu/users/EWD/ewd08xx/EWD831.PDF and a further\n// discussion of motivating rationale is at\n// https://www.quora.com/Why-are-Python-ranges-half-open-exclusive-instead-of-close" +
- "d-inclusive\n//\n// For example, with \"ie\", the number of elements in \"uint32_t values in the\n// half-open interval [M, N)\" is equal to max(0, N-M). Furthermore, that number\n// of elements (in one dimension, a length, in two dimensions, a width or\n// height) is itself representable as a uint32_t without overflow, again for\n// uint32_t values M and N. In the contrasting \"ii\" flavor, the length of the\n// closed interval [0, (1<<32) - 1] is 1<<32, which cannot be represented as a\n// uint32_t. In Wuffs, because of this potential overflow, the \"ie\" flavor has\n// length / width / height methods, but the \"ii\" flavor does not.\n//\n// It is valid for min > max (for range_ii) or for min >= max (for range_ie),\n// in which case the range is empty. There are multiple representations of an\n// empty range.\n\ntypedef struct wuffs_base__range_ii_u32__struct {\n uint32_t min_incl;\n uint32_t max_incl;\n\n#ifdef __cplusplus\n inline bool is_empty();\n inline bool equals(wuffs_base__range_ii_u32__struct s);\n inline bool contains(uint" +
- "32_t x);\n inline wuffs_base__range_ii_u32__struct intersect(\n wuffs_base__range_ii_u32__struct s);\n inline wuffs_base__range_ii_u32__struct unite(\n wuffs_base__range_ii_u32__struct s);\n#endif // __cplusplus\n\n} wuffs_base__range_ii_u32;\n\nstatic inline bool //\nwuffs_base__range_ii_u32__is_empty(wuffs_base__range_ii_u32* r) {\n return r->min_incl > r->max_incl;\n}\n\nstatic inline bool //\nwuffs_base__range_ii_u32__equals(wuffs_base__range_ii_u32* r,\n wuffs_base__range_ii_u32 s) {\n return (r->min_incl == s.min_incl && r->max_incl == s.max_incl) ||\n (wuffs_base__range_ii_u32__is_empty(r) &&\n wuffs_base__range_ii_u32__is_empty(&s));\n}\n\nstatic inline bool //\nwuffs_base__range_ii_u32__contains(wuffs_base__range_ii_u32* r, uint32_t x) {\n return (r->min_incl <= x) && (x <= r->max_incl);\n}\n\nstatic inline //\n wuffs_base__range_ii_u32\n wuffs_base__range_ii_u32__intersect(wuffs_base__range_ii_u32* r,\n wuffs_base__r" +
- "ange_ii_u32 s) {\n wuffs_base__range_ii_u32 t;\n t.min_incl = wuffs_base__u32__max(r->min_incl, s.min_incl);\n t.max_incl = wuffs_base__u32__min(r->max_incl, s.max_incl);\n return t;\n}\n\nstatic inline //\n wuffs_base__range_ii_u32\n wuffs_base__range_ii_u32__unite(wuffs_base__range_ii_u32* r,\n wuffs_base__range_ii_u32 s) {\n if (wuffs_base__range_ii_u32__is_empty(r)) {\n return s;\n }\n if (wuffs_base__range_ii_u32__is_empty(&s)) {\n return *r;\n }\n wuffs_base__range_ii_u32 t;\n t.min_incl = wuffs_base__u32__min(r->min_incl, s.min_incl);\n t.max_incl = wuffs_base__u32__max(r->max_incl, s.max_incl);\n return t;\n}\n\n#ifdef __cplusplus\n\ninline bool //\nwuffs_base__range_ii_u32::is_empty() {\n return wuffs_base__range_ii_u32__is_empty(this);\n}\n\ninline bool //\nwuffs_base__range_ii_u32::equals(wuffs_base__range_ii_u32 s) {\n return wuffs_base__range_ii_u32__equals(this, s);\n}\n\ninline bool //\nwuffs_base__range_ii_u32::contains(uint32_t x) {\n return wuffs_base__range_ii_u" +
- "32__contains(this, x);\n}\n\ninline wuffs_base__range_ii_u32 //\nwuffs_base__range_ii_u32::intersect(wuffs_base__range_ii_u32 s) {\n return wuffs_base__range_ii_u32__intersect(this, s);\n}\n\ninline wuffs_base__range_ii_u32 //\nwuffs_base__range_ii_u32::unite(wuffs_base__range_ii_u32 s) {\n return wuffs_base__range_ii_u32__unite(this, s);\n}\n\n#endif // __cplusplus\n\n" +
- "" +
- "// --------\n\ntypedef struct wuffs_base__range_ie_u32__struct {\n uint32_t min_incl;\n uint32_t max_excl;\n\n#ifdef __cplusplus\n inline bool is_empty();\n inline bool equals(wuffs_base__range_ie_u32__struct s);\n inline bool contains(uint32_t x);\n inline wuffs_base__range_ie_u32__struct intersect(\n wuffs_base__range_ie_u32__struct s);\n inline wuffs_base__range_ie_u32__struct unite(\n wuffs_base__range_ie_u32__struct s);\n inline uint32_t length();\n#endif // __cplusplus\n\n} wuffs_base__range_ie_u32;\n\nstatic inline bool //\nwuffs_base__range_ie_u32__is_empty(wuffs_base__range_ie_u32* r) {\n return r->min_incl >= r->max_excl;\n}\n\nstatic inline bool //\nwuffs_base__range_ie_u32__equals(wuffs_base__range_ie_u32* r,\n wuffs_base__range_ie_u32 s) {\n return (r->min_incl == s.min_incl && r->max_excl == s.max_excl) ||\n (wuffs_base__range_ie_u32__is_empty(r) &&\n wuffs_base__range_ie_u32__is_empty(&s));\n}\n\nstatic inline bool //\nwuffs_base__range_ie_u32__contains(w" +
- "uffs_base__range_ie_u32* r, uint32_t x) {\n return (r->min_incl <= x) && (x < r->max_excl);\n}\n\nstatic inline wuffs_base__range_ie_u32 //\nwuffs_base__range_ie_u32__intersect(wuffs_base__range_ie_u32* r,\n wuffs_base__range_ie_u32 s) {\n wuffs_base__range_ie_u32 t;\n t.min_incl = wuffs_base__u32__max(r->min_incl, s.min_incl);\n t.max_excl = wuffs_base__u32__min(r->max_excl, s.max_excl);\n return t;\n}\n\nstatic inline wuffs_base__range_ie_u32 //\nwuffs_base__range_ie_u32__unite(wuffs_base__range_ie_u32* r,\n wuffs_base__range_ie_u32 s) {\n if (wuffs_base__range_ie_u32__is_empty(r)) {\n return s;\n }\n if (wuffs_base__range_ie_u32__is_empty(&s)) {\n return *r;\n }\n wuffs_base__range_ie_u32 t;\n t.min_incl = wuffs_base__u32__min(r->min_incl, s.min_incl);\n t.max_excl = wuffs_base__u32__max(r->max_excl, s.max_excl);\n return t;\n}\n\nstatic inline uint32_t //\nwuffs_base__range_ie_u32__length(wuffs_base__range_ie_u32* r) {\n return wuffs_base__u32__sa" +
- "t_sub(r->max_excl, r->min_incl);\n}\n\n#ifdef __cplusplus\n\ninline bool //\nwuffs_base__range_ie_u32::is_empty() {\n return wuffs_base__range_ie_u32__is_empty(this);\n}\n\ninline bool //\nwuffs_base__range_ie_u32::equals(wuffs_base__range_ie_u32 s) {\n return wuffs_base__range_ie_u32__equals(this, s);\n}\n\ninline bool //\nwuffs_base__range_ie_u32::contains(uint32_t x) {\n return wuffs_base__range_ie_u32__contains(this, x);\n}\n\ninline wuffs_base__range_ie_u32 //\nwuffs_base__range_ie_u32::intersect(wuffs_base__range_ie_u32 s) {\n return wuffs_base__range_ie_u32__intersect(this, s);\n}\n\ninline wuffs_base__range_ie_u32 //\nwuffs_base__range_ie_u32::unite(wuffs_base__range_ie_u32 s) {\n return wuffs_base__range_ie_u32__unite(this, s);\n}\n\ninline uint32_t //\nwuffs_base__range_ie_u32::length() {\n return wuffs_base__range_ie_u32__length(this);\n}\n\n#endif // __cplusplus\n\n" +
- "" +
- "// --------\n\ntypedef struct wuffs_base__range_ii_u64__struct {\n uint64_t min_incl;\n uint64_t max_incl;\n\n#ifdef __cplusplus\n inline bool is_empty();\n inline bool equals(wuffs_base__range_ii_u64__struct s);\n inline bool contains(uint64_t x);\n inline wuffs_base__range_ii_u64__struct intersect(\n wuffs_base__range_ii_u64__struct s);\n inline wuffs_base__range_ii_u64__struct unite(\n wuffs_base__range_ii_u64__struct s);\n#endif // __cplusplus\n\n} wuffs_base__range_ii_u64;\n\nstatic inline bool //\nwuffs_base__range_ii_u64__is_empty(wuffs_base__range_ii_u64* r) {\n return r->min_incl > r->max_incl;\n}\n\nstatic inline bool //\nwuffs_base__range_ii_u64__equals(wuffs_base__range_ii_u64* r,\n wuffs_base__range_ii_u64 s) {\n return (r->min_incl == s.min_incl && r->max_incl == s.max_incl) ||\n (wuffs_base__range_ii_u64__is_empty(r) &&\n wuffs_base__range_ii_u64__is_empty(&s));\n}\n\nstatic inline bool //\nwuffs_base__range_ii_u64__contains(wuffs_base__range_ii_u64* r, u" +
- "int64_t x) {\n return (r->min_incl <= x) && (x <= r->max_incl);\n}\n\nstatic inline wuffs_base__range_ii_u64 //\nwuffs_base__range_ii_u64__intersect(wuffs_base__range_ii_u64* r,\n wuffs_base__range_ii_u64 s) {\n wuffs_base__range_ii_u64 t;\n t.min_incl = wuffs_base__u64__max(r->min_incl, s.min_incl);\n t.max_incl = wuffs_base__u64__min(r->max_incl, s.max_incl);\n return t;\n}\n\nstatic inline wuffs_base__range_ii_u64 //\nwuffs_base__range_ii_u64__unite(wuffs_base__range_ii_u64* r,\n wuffs_base__range_ii_u64 s) {\n if (wuffs_base__range_ii_u64__is_empty(r)) {\n return s;\n }\n if (wuffs_base__range_ii_u64__is_empty(&s)) {\n return *r;\n }\n wuffs_base__range_ii_u64 t;\n t.min_incl = wuffs_base__u64__min(r->min_incl, s.min_incl);\n t.max_incl = wuffs_base__u64__max(r->max_incl, s.max_incl);\n return t;\n}\n\n#ifdef __cplusplus\n\ninline bool //\nwuffs_base__range_ii_u64::is_empty() {\n return wuffs_base__range_ii_u64__is_empty(this);\n}\n\ninline bool //\nwu" +
- "ffs_base__range_ii_u64::equals(wuffs_base__range_ii_u64 s) {\n return wuffs_base__range_ii_u64__equals(this, s);\n}\n\ninline bool //\nwuffs_base__range_ii_u64::contains(uint64_t x) {\n return wuffs_base__range_ii_u64__contains(this, x);\n}\n\ninline wuffs_base__range_ii_u64 //\nwuffs_base__range_ii_u64::intersect(wuffs_base__range_ii_u64 s) {\n return wuffs_base__range_ii_u64__intersect(this, s);\n}\n\ninline wuffs_base__range_ii_u64 //\nwuffs_base__range_ii_u64::unite(wuffs_base__range_ii_u64 s) {\n return wuffs_base__range_ii_u64__unite(this, s);\n}\n\n#endif // __cplusplus\n\n" +
- "" +
- "// --------\n\ntypedef struct wuffs_base__range_ie_u64__struct {\n uint64_t min_incl;\n uint64_t max_excl;\n\n#ifdef __cplusplus\n inline bool is_empty();\n inline bool equals(wuffs_base__range_ie_u64__struct s);\n inline bool contains(uint64_t x);\n inline wuffs_base__range_ie_u64__struct intersect(\n wuffs_base__range_ie_u64__struct s);\n inline wuffs_base__range_ie_u64__struct unite(\n wuffs_base__range_ie_u64__struct s);\n inline uint64_t length();\n#endif // __cplusplus\n\n} wuffs_base__range_ie_u64;\n\nstatic inline bool //\nwuffs_base__range_ie_u64__is_empty(wuffs_base__range_ie_u64* r) {\n return r->min_incl >= r->max_excl;\n}\n\nstatic inline bool //\nwuffs_base__range_ie_u64__equals(wuffs_base__range_ie_u64* r,\n wuffs_base__range_ie_u64 s) {\n return (r->min_incl == s.min_incl && r->max_excl == s.max_excl) ||\n (wuffs_base__range_ie_u64__is_empty(r) &&\n wuffs_base__range_ie_u64__is_empty(&s));\n}\n\nstatic inline bool //\nwuffs_base__range_ie_u64__contains(w" +
- "uffs_base__range_ie_u64* r, uint64_t x) {\n return (r->min_incl <= x) && (x < r->max_excl);\n}\n\nstatic inline wuffs_base__range_ie_u64 //\nwuffs_base__range_ie_u64__intersect(wuffs_base__range_ie_u64* r,\n wuffs_base__range_ie_u64 s) {\n wuffs_base__range_ie_u64 t;\n t.min_incl = wuffs_base__u64__max(r->min_incl, s.min_incl);\n t.max_excl = wuffs_base__u64__min(r->max_excl, s.max_excl);\n return t;\n}\n\nstatic inline wuffs_base__range_ie_u64 //\nwuffs_base__range_ie_u64__unite(wuffs_base__range_ie_u64* r,\n wuffs_base__range_ie_u64 s) {\n if (wuffs_base__range_ie_u64__is_empty(r)) {\n return s;\n }\n if (wuffs_base__range_ie_u64__is_empty(&s)) {\n return *r;\n }\n wuffs_base__range_ie_u64 t;\n t.min_incl = wuffs_base__u64__min(r->min_incl, s.min_incl);\n t.max_excl = wuffs_base__u64__max(r->max_excl, s.max_excl);\n return t;\n}\n\nstatic inline uint64_t //\nwuffs_base__range_ie_u64__length(wuffs_base__range_ie_u64* r) {\n return wuffs_base__u64__sa" +
- "t_sub(r->max_excl, r->min_incl);\n}\n\n#ifdef __cplusplus\n\ninline bool //\nwuffs_base__range_ie_u64::is_empty() {\n return wuffs_base__range_ie_u64__is_empty(this);\n}\n\ninline bool //\nwuffs_base__range_ie_u64::equals(wuffs_base__range_ie_u64 s) {\n return wuffs_base__range_ie_u64__equals(this, s);\n}\n\ninline bool //\nwuffs_base__range_ie_u64::contains(uint64_t x) {\n return wuffs_base__range_ie_u64__contains(this, x);\n}\n\ninline wuffs_base__range_ie_u64 //\nwuffs_base__range_ie_u64::intersect(wuffs_base__range_ie_u64 s) {\n return wuffs_base__range_ie_u64__intersect(this, s);\n}\n\ninline wuffs_base__range_ie_u64 //\nwuffs_base__range_ie_u64::unite(wuffs_base__range_ie_u64 s) {\n return wuffs_base__range_ie_u64__unite(this, s);\n}\n\ninline uint64_t //\nwuffs_base__range_ie_u64::length() {\n return wuffs_base__range_ie_u64__length(this);\n}\n\n#endif // __cplusplus\n\n" +
- "" +
- "// --------\n\n// wuffs_base__rect_ii_u32 is a rectangle (a 2-dimensional range) on the\n// integer grid. The \"ii\" means that the bounds are inclusive on the low end\n// and inclusive on the high end. It contains all points (x, y) such that\n// ((min_incl_x <= x) && (x <= max_incl_x)) and likewise for y.\n//\n// It is valid for min > max, in which case the rectangle is empty. There are\n// multiple representations of an empty rectangle.\n//\n// The X and Y axes increase right and down.\ntypedef struct wuffs_base__rect_ii_u32__struct {\n uint32_t min_incl_x;\n uint32_t min_incl_y;\n uint32_t max_incl_x;\n uint32_t max_incl_y;\n\n#ifdef __cplusplus\n inline bool is_empty();\n inline bool equals(wuffs_base__rect_ii_u32__struct s);\n inline bool contains(uint32_t x, uint32_t y);\n inline wuffs_base__rect_ii_u32__struct intersect(\n wuffs_base__rect_ii_u32__struct s);\n inline wuffs_base__rect_ii_u32__struct unite(\n wuffs_base__rect_ii_u32__struct s);\n#endif // __cplusplus\n\n} wuffs_base__rect_ii_u32;\n\nstatic inline b" +
- "ool //\nwuffs_base__rect_ii_u32__is_empty(wuffs_base__rect_ii_u32* r) {\n return (r->min_incl_x > r->max_incl_x) || (r->min_incl_y > r->max_incl_y);\n}\n\nstatic inline bool //\nwuffs_base__rect_ii_u32__equals(wuffs_base__rect_ii_u32* r,\n wuffs_base__rect_ii_u32 s) {\n return (r->min_incl_x == s.min_incl_x && r->min_incl_y == s.min_incl_y &&\n r->max_incl_x == s.max_incl_x && r->max_incl_y == s.max_incl_y) ||\n (wuffs_base__rect_ii_u32__is_empty(r) &&\n wuffs_base__rect_ii_u32__is_empty(&s));\n}\n\nstatic inline bool //\nwuffs_base__rect_ii_u32__contains(wuffs_base__rect_ii_u32* r,\n uint32_t x,\n uint32_t y) {\n return (r->min_incl_x <= x) && (x <= r->max_incl_x) && (r->min_incl_y <= y) &&\n (y <= r->max_incl_y);\n}\n\nstatic inline wuffs_base__rect_ii_u32 //\nwuffs_base__rect_ii_u32__intersect(wuffs_base__rect_ii_u32* r,\n wuffs_base__rect_ii_u32 s) {\n wuffs_b" +
- "ase__rect_ii_u32 t;\n t.min_incl_x = wuffs_base__u32__max(r->min_incl_x, s.min_incl_x);\n t.min_incl_y = wuffs_base__u32__max(r->min_incl_y, s.min_incl_y);\n t.max_incl_x = wuffs_base__u32__min(r->max_incl_x, s.max_incl_x);\n t.max_incl_y = wuffs_base__u32__min(r->max_incl_y, s.max_incl_y);\n return t;\n}\n\nstatic inline wuffs_base__rect_ii_u32 //\nwuffs_base__rect_ii_u32__unite(wuffs_base__rect_ii_u32* r,\n wuffs_base__rect_ii_u32 s) {\n if (wuffs_base__rect_ii_u32__is_empty(r)) {\n return s;\n }\n if (wuffs_base__rect_ii_u32__is_empty(&s)) {\n return *r;\n }\n wuffs_base__rect_ii_u32 t;\n t.min_incl_x = wuffs_base__u32__min(r->min_incl_x, s.min_incl_x);\n t.min_incl_y = wuffs_base__u32__min(r->min_incl_y, s.min_incl_y);\n t.max_incl_x = wuffs_base__u32__max(r->max_incl_x, s.max_incl_x);\n t.max_incl_y = wuffs_base__u32__max(r->max_incl_y, s.max_incl_y);\n return t;\n}\n\n#ifdef __cplusplus\n\ninline bool //\nwuffs_base__rect_ii_u32::is_empty() {\n return wuffs_base__rect_ii_u32__is" +
- "_empty(this);\n}\n\ninline bool //\nwuffs_base__rect_ii_u32::equals(wuffs_base__rect_ii_u32 s) {\n return wuffs_base__rect_ii_u32__equals(this, s);\n}\n\ninline bool //\nwuffs_base__rect_ii_u32::contains(uint32_t x, uint32_t y) {\n return wuffs_base__rect_ii_u32__contains(this, x, y);\n}\n\ninline wuffs_base__rect_ii_u32 //\nwuffs_base__rect_ii_u32::intersect(wuffs_base__rect_ii_u32 s) {\n return wuffs_base__rect_ii_u32__intersect(this, s);\n}\n\ninline wuffs_base__rect_ii_u32 //\nwuffs_base__rect_ii_u32::unite(wuffs_base__rect_ii_u32 s) {\n return wuffs_base__rect_ii_u32__unite(this, s);\n}\n\n#endif // __cplusplus\n\n" +
- "" +
- "// --------\n\n// wuffs_base__rect_ie_u32 is a rectangle (a 2-dimensional range) on the\n// integer grid. The \"ie\" means that the bounds are inclusive on the low end\n// and exclusive on the high end. It contains all points (x, y) such that\n// ((min_incl_x <= x) && (x < max_excl_x)) and likewise for y.\n//\n// It is valid for min >= max, in which case the rectangle is empty. There are\n// multiple representations of an empty rectangle, including a value with all\n// fields zero.\n//\n// The X and Y axes increase right and down.\ntypedef struct wuffs_base__rect_ie_u32__struct {\n uint32_t min_incl_x;\n uint32_t min_incl_y;\n uint32_t max_excl_x;\n uint32_t max_excl_y;\n\n#ifdef __cplusplus\n inline bool is_empty();\n inline bool equals(wuffs_base__rect_ie_u32__struct s);\n inline bool contains(uint32_t x, uint32_t y);\n inline wuffs_base__rect_ie_u32__struct intersect(\n wuffs_base__rect_ie_u32__struct s);\n inline wuffs_base__rect_ie_u32__struct unite(\n wuffs_base__rect_ie_u32__struct s);\n inline uint32_t width(" +
- ");\n inline uint32_t height();\n#endif // __cplusplus\n\n} wuffs_base__rect_ie_u32;\n\nstatic inline bool //\nwuffs_base__rect_ie_u32__is_empty(wuffs_base__rect_ie_u32* r) {\n return (r->min_incl_x >= r->max_excl_x) || (r->min_incl_y >= r->max_excl_y);\n}\n\nstatic inline bool //\nwuffs_base__rect_ie_u32__equals(wuffs_base__rect_ie_u32* r,\n wuffs_base__rect_ie_u32 s) {\n return (r->min_incl_x == s.min_incl_x && r->min_incl_y == s.min_incl_y &&\n r->max_excl_x == s.max_excl_x && r->max_excl_y == s.max_excl_y) ||\n (wuffs_base__rect_ie_u32__is_empty(r) &&\n wuffs_base__rect_ie_u32__is_empty(&s));\n}\n\nstatic inline bool //\nwuffs_base__rect_ie_u32__contains(wuffs_base__rect_ie_u32* r,\n uint32_t x,\n uint32_t y) {\n return (r->min_incl_x <= x) && (x < r->max_excl_x) && (r->min_incl_y <= y) &&\n (y < r->max_excl_y);\n}\n\nstatic inline wuffs_base__rect_ie_u32 //\nwuffs_base__rect_ie_u32__intersect(wuf" +
- "fs_base__rect_ie_u32* r,\n wuffs_base__rect_ie_u32 s) {\n wuffs_base__rect_ie_u32 t;\n t.min_incl_x = wuffs_base__u32__max(r->min_incl_x, s.min_incl_x);\n t.min_incl_y = wuffs_base__u32__max(r->min_incl_y, s.min_incl_y);\n t.max_excl_x = wuffs_base__u32__min(r->max_excl_x, s.max_excl_x);\n t.max_excl_y = wuffs_base__u32__min(r->max_excl_y, s.max_excl_y);\n return t;\n}\n\nstatic inline wuffs_base__rect_ie_u32 //\nwuffs_base__rect_ie_u32__unite(wuffs_base__rect_ie_u32* r,\n wuffs_base__rect_ie_u32 s) {\n if (wuffs_base__rect_ie_u32__is_empty(r)) {\n return s;\n }\n if (wuffs_base__rect_ie_u32__is_empty(&s)) {\n return *r;\n }\n wuffs_base__rect_ie_u32 t;\n t.min_incl_x = wuffs_base__u32__min(r->min_incl_x, s.min_incl_x);\n t.min_incl_y = wuffs_base__u32__min(r->min_incl_y, s.min_incl_y);\n t.max_excl_x = wuffs_base__u32__max(r->max_excl_x, s.max_excl_x);\n t.max_excl_y = wuffs_base__u32__max(r->max_excl_y, s.max_excl_y);\n return t;\n}\n\nstatic inlin" +
- "e uint32_t //\nwuffs_base__rect_ie_u32__width(wuffs_base__rect_ie_u32* r) {\n return wuffs_base__u32__sat_sub(r->max_excl_x, r->min_incl_x);\n}\n\nstatic inline uint32_t //\nwuffs_base__rect_ie_u32__height(wuffs_base__rect_ie_u32* r) {\n return wuffs_base__u32__sat_sub(r->max_excl_y, r->min_incl_y);\n}\n\n#ifdef __cplusplus\n\ninline bool //\nwuffs_base__rect_ie_u32::is_empty() {\n return wuffs_base__rect_ie_u32__is_empty(this);\n}\n\ninline bool //\nwuffs_base__rect_ie_u32::equals(wuffs_base__rect_ie_u32 s) {\n return wuffs_base__rect_ie_u32__equals(this, s);\n}\n\ninline bool //\nwuffs_base__rect_ie_u32::contains(uint32_t x, uint32_t y) {\n return wuffs_base__rect_ie_u32__contains(this, x, y);\n}\n\ninline wuffs_base__rect_ie_u32 //\nwuffs_base__rect_ie_u32::intersect(wuffs_base__rect_ie_u32 s) {\n return wuffs_base__rect_ie_u32__intersect(this, s);\n}\n\ninline wuffs_base__rect_ie_u32 //\nwuffs_base__rect_ie_u32::unite(wuffs_base__rect_ie_u32 s) {\n return wuffs_base__rect_ie_u32__unite(this, s);\n}\n\ninline uint32_t //\nwuffs_" +
- "base__rect_ie_u32::width() {\n return wuffs_base__rect_ie_u32__width(this);\n}\n\ninline uint32_t //\nwuffs_base__rect_ie_u32::height() {\n return wuffs_base__rect_ie_u32__height(this);\n}\n\n#endif // __cplusplus\n" +
- ""
-
-const baseCopyright = "" +
- "// 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" +
- ""
diff --git a/cmd/wuffs-c/main.go b/cmd/wuffs-c/main.go
index 1494674..0fd731a 100644
--- a/cmd/wuffs-c/main.go
+++ b/cmd/wuffs-c/main.go
@@ -19,7 +19,7 @@
"fmt"
"os"
- "github.com/google/wuffs/cmd/wuffs-c/internal/cgen"
+ "github.com/google/wuffs/internal/cgen"
)
func main() {
diff --git a/cmd/wuffs/gen.go b/cmd/wuffs/gen.go
index f43c29a..10f9822 100644
--- a/cmd/wuffs/gen.go
+++ b/cmd/wuffs/gen.go
@@ -264,7 +264,8 @@
if !n.Public() {
continue
}
- return fmt.Errorf("TODO: genWuffs for consts")
+ fmt.Fprintf(out, "pub const %s %s = %v\n",
+ n.QID().Str(&h.tm), n.XType().Str(&h.tm), n.Value().Str(&h.tm))
case a.KFunc:
n := n.AsFunc()
diff --git a/doc/changelog.md b/doc/changelog.md
index 24b0fee..205ad84 100644
--- a/doc/changelog.md
+++ b/doc/changelog.md
@@ -21,6 +21,7 @@
- Spun `std/zlib` out of `std/flate`.
- Let the `std/zlib` decoder ignore checksums.
- Renamed `std/flate` to `std/deflate`.
+- Renamed `!=` to `<>`; `!` is now only for impure functions.
- Renamed `~+` to `~mod+`; added `~mod-`, `~sat+` and `~sat-`.
- Removed `&^`.
- Renamed `$(etc)` to `[etc]`.
@@ -37,12 +38,13 @@
- Added `peek_uxx`, `skip_fast` and `write_fast_uxx` methods.
- Renamed some `read_uxx` methods as `read_uxx_as_uyy`.
- Added I/O positions.
+- Added extra fields (uninitialized internal buffers) to structs.
- Tweaked how marks and limits work.
- Supported animated (not just single frame) and interlaced GIFs.
- Marked some internal status codes as private.
- Removed closed-for-read/write built-in status codes.
- Changed the string messages for built-in status codes.
-- Changed `error "foo"` to `"?foo"` or `base."?bar"`.
+- Changed `error "foo"` to `"#foo"` or `base."#bar"`.
- Added warnings as another status code category.
- Made the status type a `const char *`, not an `int32_t`.
- Disallowed `__double_underscore` prefixed names.
@@ -66,4 +68,4 @@
---
-Updated on December 2018.
+Updated on March 2019.
diff --git a/doc/spec/README.md b/doc/spec/README.md
new file mode 100644
index 0000000..518d6e9
--- /dev/null
+++ b/doc/spec/README.md
@@ -0,0 +1,5 @@
+This directory contains various specifications, whether intrinsically related to
+Wuffs or stand-alone formats that were invented alongside Wuffs' development.
+
+ - [Naïve Image Formats: NIE, NII, NIA](./nie-spec.md)
+ - [Random Access Compression: RAC](./rac-spec.md)
diff --git a/lib/nie/README.md b/doc/spec/nie-spec.md
similarity index 87%
rename from lib/nie/README.md
rename to doc/spec/nie-spec.md
index e8b7d06..dac4108 100644
--- a/lib/nie/README.md
+++ b/doc/spec/nie-spec.md
@@ -12,17 +12,17 @@
- 4 bytes of version-and-configuration: \[0xFF, 0x62 or 0x72, 0x6E or 0x70,
0x34 or 0x38\].
- The first byte denotes the overall NIE/NII/NIA format version. 0xFF (which
- is not valid UTF-8) denotes version 1. There are no other valid versions at
- this time.
+ is not valid UTF-8) denotes version 1. There are no other valid versions at
+ this time.
- The second byte, either an ASCII 'b' or an ASCII 'r', denotes whether the
- pixel's data is in BGRA or RGBA order (in memory order, independent of CPU
- endianness).
+ pixel's data is in BGRA or RGBA order (in memory order, independent of CPU
+ endianness).
- The third byte, either an ASCII 'n' or an ASCII 'p', denotes whether the
- payload contains non-premultiplied or premultiplied alpha.
+ payload contains non-premultiplied or premultiplied alpha.
- The fourth byte, either an ASCII '4' or an ASCII '8', denotes whether there
- are 4 or 8 bytes per pixel.
+ are 4 or 8 bytes per pixel.
- Future format versions may allow other byte values, but in version 1, it
- must be '\xFF', then 'b' or 'r', then 'n' or 'p', then '4' or '8'.
+ must be '\xFF', then 'b' or 'r', then 'n' or 'p', then '4' or '8'.
- 4 bytes little-endian `uint32` width.
- 4 bytes little-endian `uint32` height.
@@ -34,6 +34,18 @@
bytes are \[B₀, B₁, G₀, G₁, R₀, R₁, A₀, A₁\]. The ₀ and ₁ subscripts denote
the low and high bytes of the `uint16`.
+That's it.
+
+
+### Example NIE File
+
+This still image is 3 pixels wide and 2 pixels high. It is a crude
+approximation to the French flag, being three columns: blue, white and red.
+
+ 00000000: 6ec3 af45 ff62 6e34 0300 0000 0200 0000 n..E.bn4........
+ 00000010: ff00 00ff ffff ffff 0000 ffff ff00 00ff ................
+ 00000020: ffff ffff 0000 ffff ........
+
## NII: Animated Images, Timing Index Only, Out-of-Band Frames
@@ -129,6 +141,19 @@
years, are not representable in the NII format.
+### Example NII File
+
+This animated image is 3 pixels wide and 2 pixels high. It consists of 20
+frames, being 10 loops of 2 frames. The total animation time of a single loop
+is 3 seconds, so the 10 loops will take 30 seconds. The first frame is shown
+for 1 second. The next frame is shown for (3 - 1) seconds (i.e., 2 seconds).
+The actual pixel data per frame is stored elsewhere.
+
+ 00000000: 6ec3 af49 ffff ffff 0300 0000 0200 0000 n..I............
+ 00000010: 0a00 0000 0200 0000 ff31 d481 ffff ffff .........1......
+ 00000020: 009a 0e2a 0000 0000 ff31 d481 ffff ffff ...*.....1......
+
+
## NIA: Animated Images, In-band Frames
NIA is like an NII file where the per-frame still images are NIE files
@@ -153,6 +178,25 @@
- 8 bytes little-endian int64 TValue, the same meaning and constraints as NII.
+### Example NIA File
+
+This animated image is 3 pixels wide and 2 pixels high. It consists of 20
+frames, being 10 loops of 2 frames. The total animation time of a single loop
+is 3 seconds, so the 10 loops will take 30 seconds. The first frame is a crude
+approximation to the French flag (blue, white and red) and is shown for 1
+second. The next frame is a crude approximation to the Italian flag (green,
+white and red) and is shown for (3 - 1) seconds (i.e., 2 seconds).
+
+ 00000000: 6ec3 af41 ff62 6e34 0300 0000 0200 0000 n..A.bn4........
+ 00000010: 0a00 0000 0200 0000 ff31 d481 ffff ffff .........1......
+ 00000020: 6ec3 af45 ff62 6e34 0300 0000 0200 0000 n..E.bn4........
+ 00000030: ff00 00ff ffff ffff 0000 ffff ff00 00ff ................
+ 00000040: ffff ffff 0000 ffff 009a 0e2a 0000 0000 ...........*....
+ 00000050: 6ec3 af45 ff62 6e34 0300 0000 0200 0000 n..E.bn4........
+ 00000060: 00ff 00ff ffff ffff 0000 ffff 00ff 00ff ................
+ 00000070: ffff ffff 0000 ffff ff31 d481 ffff ffff .........1......
+
+
# Commentary
@@ -391,4 +435,4 @@
---
-Updated on December 2018.
+Updated on February 2019.
diff --git a/doc/spec/rac-spec.md b/doc/spec/rac-spec.md
new file mode 100644
index 0000000..fbd45f9
--- /dev/null
+++ b/doc/spec/rac-spec.md
@@ -0,0 +1,550 @@
+# Random Access Compression: RAC
+
+Status: Draft (as of March 2019). There is no compatibility guarantee yet.
+
+
+## Overview
+
+The goal of the RAC file format is to compress a source file (the "decompressed
+file") such that, starting from the compressed file, it is possible to
+reconstruct the half-open byte range `[di .. dj)` of the decompressed file
+without always having to first decompress all of `[0 .. di)`.
+
+Conceptually, the decompressed file is partitioned into non-overlapping chunks.
+Each compressed chunk can be decompressed independently (although possibly
+sharing additional context, such as a LZ77 prefix dictionary). A RAC file also
+contains a hierarchical index of those chunks.
+
+RAC is a container format, and while it supports common compression codecs like
+Zlib, Brotli and Zstandard, it is not tied to any particular compression codec.
+
+Non-goals for version 1 include:
+
+ - Filesystem metadata like file names, file sizes and modification times.
+ - Multiple source files.
+
+There is the capability (see reserved `TTag`s, below) but no promise to address
+these in a future RAC version. There might not be a need to, as other designs
+such as EROFS ([Extendable Read-Only File
+System](https://lkml.org/lkml/2018/5/31/306)) already exist.
+
+Non-goals in general include:
+
+ - Encryption.
+ - Streaming decompression.
+
+
+### Related Work
+
+In general, RAC differs from most other archive or compression formats in a
+number of ways. This doesn't mean that RAC is necessarily better or worse than
+these other designs, just that different designs make different trade-offs. For
+example, supporting shared dictionaries means giving up streaming (one pass)
+decoding.
+
+ - RAC files must start with a magic sequence, but RAC still supports
+ append-only modifications.
+ - RAC seek points are identified by numbers (i.e. `DOffset`s), not strings
+ (i.e. file names). Some other formats' seek points are positioned only at
+ source file boundaries. They cannot seek to a relative offset (in what RAC
+ calls `DSpace`) within a source file.
+ - RAC supports [shared compression
+ dictionaries](http://fastcompression.blogspot.com/2018/02/when-to-use-dictionary-compression.html)
+ embedded within an archive.
+
+These points apply to established archive formats like
+[Tar](https://en.wikipedia.org/wiki/Tar_%28computing%29) and
+[Zip](https://en.wikipedia.org/wiki/Zip_%28file_format%29), and newer archive
+formats like [Śiva](https://blog.sourced.tech/post/siva/).
+
+[Riegeli](https://github.com/google/riegeli) is a sequence-of-records format. A
+RAC file arguably contains what Riegeli calls records (which are not files, as
+they don't have names) and both formats support numerical seek points, and
+multiple compression codecs, but Riegeli seeks to a point in what RAC calls
+`CSpace`, whereas RAC seeks to a point in `DSpace`.
+
+[XFLATE](https://github.com/dsnet/compress/blob/master/doc/xflate-format.pdf)
+supports random access like RAC, but is tied to the DEFLATE family of
+compression codecs.
+
+[XZ](https://tukaani.org/xz/format.html) supports random access like RAC, but
+as one of its explicit goals is to support streaming decoding, it does not
+support shared dictionaries. Also, unlike RAC, finding the record that contains
+any given `DOffset` requires a linear scan of all previous records, even if
+those records don't need decompressing.
+
+[QCOW](https://github.com/qemu/qemu/blob/master/docs/interop/qcow2.txt)
+supports random access like RAC, but compression does not seem to be the
+foremost concern. That specification mentions compression but does not give any
+particular codec. A [separate
+document](https://people.gnome.org/~markmc/qcow-image-format.html) suggests
+that the codec is Zlib (with no other option), and that it does not support
+shared dictionaries.
+
+The
+[`examples/zran.c`](https://github.com/madler/zlib/blob/master/examples/zran.c)
+program in the zlib-the-library source code repository builds an in-memory
+index, not a persistent (disk-backed) one, and building the index involves
+first decompressing the whole file. It also requires storing (in memory) the
+entire state of the decompressor, including 32 KiB of history, per seek point.
+For coarse grained seek points (e.g. once every 1 MiB), that overhead can be
+acceptable, but for fine grained seek points (e.g. once every 16 KiB), that
+overhead is prohibitive.
+
+RAC differs from the [LevelDB
+Table](https://github.com/google/leveldb/blob/master/doc/table_format.md)
+format, even if the LevelDB Table string keys are re-purposed to encode both
+numerical `DOffset` seek points and identifiers for shared compression
+dictionaries. A LevelDB Table index is flat, unlike RAC's hierarchical index.
+In both cases, a maliciously written index could contain multiple entries for
+the same key, and different decoders could therefore produce different output
+for the same source file - a potential security vulnerability. For LevelDB
+Tables, verifying an index key's uniqueness requires scanning every key in the
+file, which can be relatively expensive, and is therefore not done in practice.
+In comparison, RAC's "Branch Node Validation" process (see below) ensures that
+exactly one `Leaf Node` contains any given byte offset `di` in the decompressed
+file, and the RAC index's hierarchical nature places a scalable upper bound on
+the scanning cost of verifying that, based on that portion of the index tree
+visited for any given request `[di .. dj)`.
+
+
+### Glossary
+
+ - `CBias` is the delta added to a `CPointer` to produce a `COffset`.
+ - `DBias` is the delta added to a `DPointer` to produce a `DOffset`.
+ - `CFile` is the compressed file.
+ - `DFile` is the decompressed file.
+ - `CFileSize` is the size of the `CFile`.
+ - `DFileSize` is the size of the `DFile`.
+ - `COffset` is a byte offset in `CSpace`.
+ - `DOffset` is a byte offset in `DSpace`.
+ - `CPointer` is a relative `COffset`, prior to bias-correction.
+ - `DPointer` is a relative `DOffset`, prior to bias-correction.
+ - `CRange` is a `Range` in `CSpace`.
+ - `DRange` is a `Range` in `DSpace`.
+ - `CSpace` means that byte offsets refer to the `CFile`.
+ - `DSpace` means that byte offsets refer to the `DFile`.
+
+`Range` is a pair of byte offsets `[i .. j)`, in either `CSpace` or `DSpace`.
+It is half-open, containing every byte offset `x` such that `(i <= x)` and `(x
+< j)`. It is invalid to have `(i > j)`. The size of a `Range` equals `(j - i)`.
+
+All bytes are 8 bits and unless explicitly specified otherwise, all fixed-size
+unsigned integers (e.g. `uint32_t`, `uint64_t`) are encoded little-endian.
+Within those unsigned integers, bit 0 is the least significant bit and e.g. bit
+31 is the most significant bit of a `uint32_t`.
+
+The maximum supported `CFileSize` and the maximum supported `DFileSize` are the
+same number: `0x0000_FFFF_FFFF_FFFF`, which is `((1 << 48) - 1)`.
+
+
+## File Structure
+
+A RAC file (the `CFile`) must be at least 4 bytes long, and start with the 3
+byte `Magic` (see below), so that no valid RAC file can also be e.g. a valid
+JPEG file. The fourth byte is examined in the process described by the "Root
+Node at the CFile Start" section, below.
+
+The `CFile` contains a tree of `Node`s. Each `Node` is either a `Branch Node`
+(pointing to between 1 and 255 child `Node`s) or a `Leaf Node`. There must be
+at least one `Branch Node`, called the `Root Node`. Parsing a `CFile` requires
+knowing the `CFileSize` in order to identify the `Root Node`, which is either
+at the start or the end of the `CFile`.
+
+Each `Node` has a `DRange`. An empty `DRange` means that the `Node` contains
+metadata or other decompression context such as a shared dictionary.
+
+Each `Leaf Node` also has 3 `CRange`s (`Primary`, `Secondary` and `Tertiary`),
+any or all of which may be empty. The contents of the `CFile`, within those
+`CRange`s, are decompressed according to the `Codec` (see below) to reconstruct
+that part of the `DFile` within the `Leaf Node`'s `DRange`.
+
+
+## Branch Nodes
+
+A `Branch Node`'s encoding in the `CFile` has a variable byte size, between 32
+and 4096 inclusive, depending on its number of children. Specifically, it
+occupies `((Arity * 16) + 16)` bytes, grouped into 8 byte segments (but not
+necessarily 8 byte aligned), starting at a `COffset` called its `Branch
+COffset`:
+
+ +-+-+-+-+-+-+-+-+
+ |0|1|2|3|4|5|6|7|
+ +-+-+-+-+-+-+-+-+
+ |Magic|A|Che|0|T| Magic, Arity, Checksum, Reserved (0), TTag[0]
+ | DPtr[1] |0|T| DPtr[1], Reserved (0), TTag[1]
+ | DPtr[2] |0|T| DPtr[2], Reserved (0), TTag[2]
+ | ... |0|.| ..., Reserved (0), ...
+ | DPtr[A-2] |0|T| DPtr[Arity-2], Reserved (0), TTag[Arity-2]
+ | DPtr[A-1] |0|T| DPtr[Arity-1], Reserved (0), TTag[Arity-1]
+ | DPtr[A] |0|C| DPtr[Arity] a.k.a. DPtrMax, Reserved (0), Codec
+ | CPtr[0] |L|S| CPtr[0], CLen[0], STag[0]
+ | CPtr[1] |L|S| CPtr[1], CLen[1], STag[1]
+ | CPtr[2] |L|S| CPtr[2], CLen[2], STag[2]
+ | ... |L|.| ..., ..., ...
+ | CPtr[A-2] |L|S| CPtr[Arity-2], CLen[Arity-2], STag[Arity-2]
+ | CPtr[A-1] |L|S| CPtr[Arity-1], CLen[Arity-2], STag[Arity-1]
+ | CPtr[A] |V|A| CPtr[Arity] a.k.a. CPtrMax, Version, Arity
+ +-+-+-+-+-+-+-+-+
+
+For the `(XPtr | Other6 | Other7)` 8 byte fields, the `XPtr` occupies the low
+48 bits (as a little-endian `uint64_t`) and the `Other` fields occupy the high
+16 bits.
+
+The `CPtr` and `DPtr` values are what is explicitly written in the `CFile`'s
+bytes. These are added to a `Branch Node`'s implicit `Branch CBias` and `Branch
+DBias` values to give the implicit `COff` and `DOff` values: `COff[i]` and
+`DOff[i]` are defined to be `(Branch_CBias + CPtr[i])` and `(Branch_DBias +
+DPtr[i])`.
+
+`CPtrMax` is another name for `CPtr[Arity]`, and `COffMax` is defined to be
+`(Branch_CBias + CPtrMax)`. Likewise for `DPtrMax` and `DOffMax`.
+
+The `DPtr[0]` value is implicit, and always equals zero, so that `DOff[0]`
+always equals the `Branch DBias`.
+
+ - For the `Root Node`, the `DPtrMax` also sets the `DFileSize`. The `Branch
+ CBias` and `Branch DBias` are both zero. The `Branch COffset` is determined
+ by the "Root Node" section below.
+ - For a child `Branch Node`, the `Branch COffset`, `Branch CBias` and `Branch
+ DBias` are given by the parent `Branch Node`. See the "Search Within a
+ Branch Node" section below.
+
+
+### Magic
+
+`Magic` is the three bytes `"\x72\xC3\x63"`, which is invalid UTF-8 but is
+`"rÃc"` in ISO 8859-1. The tilde isn't particularly meaningful, other than
+`"rÃc"` being a nonsensical word (with nonsensical capitalization) that is
+unlikely to appear in other files.
+
+Every `Branch Node` must start with these `Magic` bytes, not just a `Branch
+Node` positioned at the start of the `CFile`.
+
+
+### Arity
+
+`Arity` is the `Branch Node`'s number of children. Zero is invalid.
+
+The `Arity` byte is given twice: the fourth byte and the final byte of the
+`Branch Node`. The two values must match.
+
+The repetition lets a RAC reader determine the size of the `Branch Node` data
+(as the size depends on the `Arity`), given either its start or its end offset
+in `CSpace`. For almost all `Branch Node`s, we will know its start offset (its
+`Branch COffset`), but for a `Root Node` at the end of a `CFile`, we will only
+know its end offset.
+
+
+### Checksum
+
+`Checksum` is a checksum of the `Branch Node`'s bytes. It is not a checksum of
+the `CFile` or `DFile` contents pointed to by a `Branch Node`. Content
+checksums are a `Codec`-specific consideration.
+
+The little-endian `uint16_t` `Checksum` value is the low 16 bits XOR'ed with
+the high 16 bits of the `uint32_t` CRC-32 IEEE checksum of the `((Arity * 16) +
+10)` bytes immediately after the `Checksum`. The 4 bytes immediately before the
+`Checksum` are not considered: the `Magic` bytes have only one valid value and
+the `Arity` byte near the start is replicated by the `Arity` byte at the end.
+
+
+### Reserved (0)
+
+The `Reserved (0)` bytes must have the value `0x00`.
+
+
+### COffs and DOffs, STags and TTags
+
+For every `a` in the half-open range `[0 .. Arity)`, the `a`'th child `Node`
+has two tags, `STag[a]` and `TTag[a]`, and a `DRange` of `[DOff[a] ..
+DOff[a+1])`. The `DOff` values must be non-decreasing: see the "Branch Node
+Validation" section below.
+
+A `TTag[a]` of `0xFE` means that child is a `Branch Node`. A `TTag[a]` in the
+half-open range `[0xC0 .. 0xFE)` is reserved. Otherwise, the child is a `Leaf
+Node`.
+
+A child `Branch Node`'s `SubBranch COffset` is defined to be `COff[a]`. Its
+`SubBranch DBias` and `SubBranch DOffMax` are defined to be `DOff[a]` and
+`DOff[a+1].
+
+ - When `(STag[a] < Arity)`, it is a `CBiasing Branch Node`. The `SubBranch
+ CBias` is defined to be `(Branch_CBias + CPtr[STag[a]])`. This expression
+ is equivalent to `COff[STag[a]]`.
+ - When `(STag[a] >= Arity)`, it is a `CNeutral Branch Node`. The `SubBranch
+ CBias` is defined to be `(Branch_CBias)`.
+
+A child `Leaf Node`'s `STag[a]` and `TTag[a]` values are also called its `Leaf
+STag` and `Leaf TTag`. It also has:
+
+ - A `Primary CRange`, equal to `MakeCRange(a)`.
+ - A `Secondary CRange`, equal to `MakeCRange(STag[a])`.
+ - A `Tertiary CRange`, equal to `MakeCRange(TTag[a])`.
+
+The `MakeCRange(i)` function defines a `CRange`. If `(i >= Arity)` then that
+`CRange` is the empty range `[COffMax .. COffMax)`. Otherwise, the lower bound
+is `COff[i]` and the upper bound is:
+
+ - `COffMax` when `CLen[i]` is zero.
+ - The minimum of `COffMax` and `(COff[i] + (CLen[i] * 1024))` when `CLen[i]`
+ is non-zero.
+
+In other words, the `COffMax` value clamps the `CRange` upper bound. The `CLen`
+value, if non-zero, combines with the `COff` value to apply another clamp. The
+`CLen` is given in units of 1024 bytes, but the `(COff[i] + (CLen[i] * 1024))`
+value is not necessarily quantized to 1024 byte boundaries.
+
+Note that, since `Arity` is at most 255, an `STag[a]` of `0xFF` always results
+in a `CNeutral Branch Node` or an empty `Secondary CRange`. Likewise, a
+`TTag[a]` of `0xFF` always results in an empty `Tertiary CRange`.
+
+
+### COffMax
+
+`COffMax` is an inclusive upper bound on every `COff` in a `Branch Node` and in
+its descendent `Branch Node`s. A child `Branch Node` must not have a larger
+`COffMax` than the parent `Branch Node`'s `COffMax`, and the `Root Node`'s
+`COffMax` must equal the `CFileSize`. See the "Branch Node Validation" section
+below.
+
+A RAC file can therefore be incrementally modified, if the RAC writer only
+appends new `CFile` bytes and does not re-write existing `CFile` bytes, so that
+the `CFileSize` increases. Even if the old (smaller) RAC file's `Root Node` was
+at the `CFile` start, the new (larger) `CFileSize` means that those starting
+bytes are an obsolete `Root Node` (but still a valid `Branch Node`). The new
+`Root Node` is therefore located at the end of the new RAC file.
+
+Concatenating RAC files (concatenating in `DSpace`) involves concatenating the
+RAC files in `CSpace` and then appending a new `Root Node` with `CBiasing
+Branch Node`s pointing to each source RAC file's `Root Node`.
+
+
+### Version
+
+`Version` must have the value `0x01`, indicating version 1 of the RAC format.
+
+
+### Codec
+
+`Codec`s define specializations of RAC, such as "RAC + Zlib" or "RAC + Brotli".
+It is valid for a "RAC + Zstandard" only decoder to reject a "RAC + Brotli"
+file, even if it is a valid RAC file. Recall that RAC is just a container, and
+not tied to any particular compression codec. For the `Codec` byte in a `Branch
+Node`:
+
+ - `0x00` is reserved.
+ - `0x01` means "RAC + Zlib".
+ - `0x02` means "RAC + Brotli".
+ - `0x04` means "RAC + ZStandard".
+ - Any other value less than 0x08 means that all of this `Branch Node`'s
+ children must be `Branch Node`s and not `Leaf Node`s and that no child's
+ `Codec` byte can have a bit set that is not set in this `Codec` byte.
+ - All other values, 0x08 or greater, are reserved.
+
+
+### Branch Node Validation
+
+The first time that a RAC reader visits any particular `Branch Node`, it must
+check that the `Magic` matches, the two `Arity` values match and are non-zero,
+the computed checksum matches the listed `Checksum` and that the RAC reader
+accepts the `Version` and the `Codec`.
+
+It must also check that all of its `DOff` values are sorted: `(DOff[a] <=
+DOff[a+1])` for every `a` in the half-open range `[0 .. Arity)`. By induction,
+this means that all of its `DOff` values do not exceed `DOffMax`, and again by
+induction, therefore do not exceed `DFileSize`.
+
+It must also check that all of its `COff` values do not exceed `COffMax` (and
+again by induction, therefore do not exceed `CFileSize`). Other than that,
+`COff` values do not have to be sorted: successive `Node`s (in `DSpace`) can be
+out of order (in `CSpace`), allowing for incrementally modified RAC files.
+
+For the `Root Node`, its `COffMax` must equal the `CFileSize`. Recall that
+parsing a `CFile` requires knowing the `CFileSize`, and also that a `Root
+Node`'s `Branch CBias` is zero, so its `COffMax` equals its `CPtrMax`.
+
+For a child `Branch Node`, its `Codec` bits must be a subset of its parent's
+`Codec` bits, its `COffMax` must be less than or equal to its parent's
+`COffMax`, and its `DOffMax` must equal its parent's `SubBranch DOffMax`. The
+`DOffMax` condition is equivalent to checking that the parent and child agree
+on the child's size in `DSpace`. The parent states that it is its `(DPtr[a+1] -
+DPtr[a])` and the child states that it is its `DPtrMax`.
+
+One conservative way to check `Branch Node`s' validity on first visit is to
+check them on every visit, as validating any particular `Branch Node` is
+idempotent, but other ways are acceptable.
+
+
+## Root Node
+
+The `Root Node` might be at the start of the `CFile`, as this might optimize
+alignment of `Branch Node`s and of `CRange`s. All `Branch Node`s' sizes are
+multiples of 16 bytes, and a maximal `Branch Node` is exactly 4096 bytes.
+
+The `Root Node` might be at the end of the `CFile`, as this allows one-pass
+(streaming) encoding of a RAC file. It also allows appending to, concatenating
+or incrementally modifying existing RAC files relatively cheaply.
+
+To find the `Root Node`, first look for a valid `Root Node` at the `CFile`
+start. If and only if that fails, look at the `CFile` end. If that also fails,
+it is not a valid RAC file.
+
+
+### Root Node at the CFile Start
+
+The fourth byte of the `CFile` gives the `Arity`, assuming the `Root Node` is
+at the `CFile` start. If it is zero, fail over to the `CFile` end. A RAC writer
+that does not want to place the `Root Node` at the `CFile` start should
+intentionally write a zero to the fourth byte.
+
+Otherwise, that `Arity` defines the size in bytes of any starting `Root Node`:
+`((Arity * 16) + 16)`. If the `CFileSize` is less than this size, fail over to
+the `CFile` end.
+
+If those starting bytes form a valid `Root Node` (as per the "Branch Node
+Validation" section), including having a `CPtrMax` equal to the `CFileSize`,
+then we have indeed found our `Root Node`: its `Branch COffset` is zero.
+Otherwise, fail over to the `CFile` end.
+
+
+### Root Node at the CFile End
+
+If there is no valid `Root Node` at the `CFile` start then the last byte of the
+`CFile` gives the `Root Node`'s `Arity`. This does not necessarily need to
+match the fourth byte of the `CFile`.
+
+As before, that `Arity` defines the size in bytes of any ending `Root Node`:
+`((Arity * 16) + 16)`. If the `CFileSize` is less than this size, it is not a
+valid RAC file.
+
+If those ending bytes form a valid `Root Node` (as per the "Branch Node
+Validation" section), including having a `CPtrMax` equal to the `CFileSize`,
+then we have indeed found our `Root Node`: its `Branch COffset` is the
+`CFileSize` minus the size implied by the `Arity`. Otherwise, it is not a valid
+RAC file.
+
+
+## DRange Reconstruction
+
+To reconstruct the `DRange` `[di .. dj)`, if that `DRange` is empty then the
+request is trivially satisfied.
+
+Otherwise, if `(dj > DFileSize)` then reject the request.
+
+Otherwise, start at the `Root Node` and continue to the next section to find
+the `Leaf Node` containing the `DOffset` `di`.
+
+
+### Search Within a Branch Node
+
+Load (and validate) the `Branch Node` given its `Branch COffset`, `Branch
+CBias` and `Branch DBias`.
+
+Find the largest child index `a` such that `(a < Arity)` and `(DOff[a] <= di)`
+and `(DOff[a+1] > di)`, then examine `TTag[a]` to see if the child is a `Leaf
+Node`. If so, skip to the next section.
+
+For a `Branch Node` child, let `CRemaining` equal this `Branch Node`'s (the
+parents') `COffMax` minus the `SubBranch COffset`. It invalid for `CRemaining`
+to be less than 4, or to be less than the child's size implied by the child's
+`Arity` byte at a `COffset` equal to `(SubBranch_COffset + 3)`.
+
+The `SubBranch COffset`, `SubBranch CBias` and `SubBranch DBias` from the
+parent `Branch Node` become the `Branch COffset`, `Branch CBias` and `Branch
+DBias` of the child `Branch Node`. In order to rule out infinite loops, at
+least one of these two conditions must hold:
+
+ - The child's `Branch COffset` is less than the parent's `Branch COffset`.
+ - The child's `DPtrMax` is less than the parent's `DPtrMax`.
+
+It is valid for one of those conditions to hold between a parent-child pair and
+the other condition to hold between the next parent-child pair.
+
+Repeat this "Search Within a Branch Node" section with the child `Branch Node`.
+
+
+### Decompressing a Leaf Node
+
+If a `Leaf Node`'s `DRange` is empty, decompression is a no-op and skip the
+rest of this section.
+
+Otherwise, decompression combines the `Primary CRange`, `Secondary CRange` and
+`Tertiary CRange` slices of the `CFile`, and the `Leaf STag` and `Leaf TTag`
+values, in a `Codec`-specific way to produce decompressed data.
+
+There are two general principles, although specific `Codec`s can overrule:
+
+ - The `Codec` may produce fewer bytes than the `DRange` size. In that case,
+ the remaining bytes (in `DSpace`) are set to NUL (`memset` to zero).
+ - The `Codec` may consume fewer bytes than each `CRange` size, and the
+ compressed data typically contains an explicit "end of data" marker. In
+ that case, the remaining bytes (in `CSpace`) are ignored. Padding allows
+ `COff` values to optionally be aligned.
+
+It is invalid to produce more bytes than the `DRange` size or to consume more
+bytes than each `CRange` size.
+
+
+### Continuing the Reconstruction
+
+If decompressing that `Leaf Node` did not fully reconstruct `[di .. dj)`,
+advance through the `Node` tree in depth first search order, decompressing
+every `Leaf Node` along the way, until we have gone up to or beyond `dj`.
+
+During that traversal, `Node`s with an empty `DRange` should be skipped, even
+if they are `Branch Node`s.
+
+
+# Specific Codecs
+
+
+## RAC + Zlib
+
+The `CFile` data in the `Leaf Node`'s `Primary CRange` is decompressed as Zlib
+(RFC 1950), possibly referencing a LZ77 prefix dictionary (what the RFC calls a
+"preset dictionary").
+
+If a `Leaf Node`'s `Secondary CRange` is empty then there is no dictionary.
+Otherwise, the `Secondary CRange` must be at least 6 bytes long:
+
+ - 2 byte little-endian `uint16_t` `Dictionary Length`.
+ - `Dictionary Length` bytes `Dictionary`.
+ - 4 byte big-endian `uint32_t` `Dictionary Checksum`.
+ - Padding (ignored).
+
+The `Dictionary Checksum` is Zlib's Adler32 checksum over the `Dictionary`'s
+bytes (excluding the initial 2 bytes for the `Dictionary Length`). The checksum
+is stored big-endian, like Zlib's other checksums, and its 4 byte value must
+match the `DICTID` (in RFC 1950 terminology) given in the `Primary CRange`'s
+Zlib-formatted data.
+
+The `Leaf TTag` must be `0xFF`. All other `Leaf TTag` values (below `0xC0`) are
+reserved. The empty `Tertiary CRange` is ignored. The `Leaf STag` value is also
+ignored, other than deriving the `Secondary CRange`.
+
+
+## RAC + Brotli
+
+TODO.
+
+
+## RAC + Zstandard
+
+TODO.
+
+
+# Examples
+
+TODO (zlib).
+
+
+# Acknowledgements
+
+I (Nigel Tao) thank Robert Obryk, Sanjay Ghemawat and Sean Klein for their
+review.
+
+
+---
+
+Updated on April 2019.
diff --git a/example/crc32/crc32.cc b/example/crc32/crc32.cc
index e9e1796..97b5cc3 100644
--- a/example/crc32/crc32.cc
+++ b/example/crc32/crc32.cc
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// ----------------
+
/*
crc32 prints the CRC-32 checksum (using the IEEE polynomial) of stdin. It is
similar to the standard /usr/bin/crc32 program, except that this example
@@ -28,7 +30,6 @@
#include <errno.h>
#include <inttypes.h>
#include <stdio.h>
-#include <unistd.h>
// Wuffs ships as a "single file C library" or "header file library" as per
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
@@ -56,32 +57,22 @@
uint8_t src_buffer[SRC_BUFFER_SIZE];
int main(int argc, char** argv) {
- wuffs_crc32__ieee_hasher h = ((wuffs_crc32__ieee_hasher){});
- const char* status = h.check_wuffs_version(sizeof h, WUFFS_VERSION);
+ wuffs_crc32__ieee_hasher h;
+ const char* status = h.initialize(sizeof h, WUFFS_VERSION, 0);
if (status) {
fprintf(stderr, "%s\n", status);
return 1;
}
while (true) {
- const int stdin_fd = 0;
- ssize_t n = read(stdin_fd, src_buffer, SRC_BUFFER_SIZE);
- if (n < 0) {
- if (errno != EINTR) {
- fprintf(stderr, "%s\n", strerror(errno));
- return 1;
- }
- continue;
- }
-
- uint32_t checksum = h.update((wuffs_base__slice_u8){
- .ptr = src_buffer,
- .len = static_cast<size_t>(n),
- });
-
- if (n == 0) {
+ size_t n = fread(src_buffer, sizeof(uint8_t), SRC_BUFFER_SIZE, stdin);
+ uint32_t checksum = h.update(wuffs_base__make_slice_u8(src_buffer, n));
+ if (feof(stdin)) {
printf("%08" PRIx32 "\n", checksum);
return 0;
+ } else if (ferror(stdin)) {
+ fprintf(stderr, "read error\n");
+ return 1;
}
}
}
diff --git a/example/gifplayer/gifplayer.c b/example/gifplayer/gifplayer.c
index 42ab767..74ff1be 100644
--- a/example/gifplayer/gifplayer.c
+++ b/example/gifplayer/gifplayer.c
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// ----------------
+
/*
gifplayer prints an ASCII representation of the GIF image read from stdin. To
play Eadweard Muybridge's iconic galloping horse animation, run:
@@ -30,17 +32,19 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
-#ifndef _POSIX_TIMERS
-#error "TODO: timers on non-POSIX systems"
-#else
+// ----------------
+
+#if defined(__unix__) || defined(__MACH__)
+
#include <time.h>
+#include <unistd.h>
+#define WUFFS_EXAMPLE_USE_TIMERS
bool started = false;
-struct timespec start_time;
+struct timespec start_time = {0};
-uint64_t micros_since_start(struct timespec* now) {
+int64_t micros_since_start(struct timespec* now) {
if (!started) {
return 0;
}
@@ -51,8 +55,13 @@
}
return nanos / 1000;
}
+
+#else
+#warning "TODO: timers on non-POSIX systems"
#endif
+// ----------------
+
// Wuffs ships as a "single file C library" or "header file library" as per
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
//
@@ -86,31 +95,25 @@
wuffs_base__color_u32_argb_premul* prev_dst_buffer = NULL;
size_t dst_len; // Length in bytes.
-wuffs_base__slice_u8 pixbuf = ((wuffs_base__slice_u8){});
-wuffs_base__slice_u8 workbuf = ((wuffs_base__slice_u8){});
-wuffs_base__slice_u8 printbuf = ((wuffs_base__slice_u8){});
+wuffs_base__slice_u8 pixbuf = {0};
+wuffs_base__slice_u8 workbuf = {0};
+wuffs_base__slice_u8 printbuf = {0};
bool first_play = true;
uint32_t num_loops_remaining = 0;
-wuffs_base__pixel_buffer pb = ((wuffs_base__pixel_buffer){});
+wuffs_base__pixel_buffer pb = {0};
wuffs_base__flicks cumulative_delay_micros = 0;
-// ignore_return_value suppresses errors from -Wall -Werror.
-static void ignore_return_value(int ignored) {}
-
const char* read_stdin() {
while (src_len < SRC_BUFFER_SIZE) {
- const int stdin_fd = 0;
- ssize_t n = read(stdin_fd, src_buffer + src_len, SRC_BUFFER_SIZE - src_len);
- if (n > 0) {
- src_len += n;
- } else if (n == 0) {
+ size_t n = fread(src_buffer + src_len, sizeof(uint8_t),
+ SRC_BUFFER_SIZE - src_len, stdin);
+ src_len += n;
+ if (feof(stdin)) {
return NULL;
- } else if (errno == EINTR) {
- // No-op.
- } else {
- return strerror(errno);
+ } else if (ferror(stdin)) {
+ return "read error";
}
}
return "input is too large";
@@ -271,11 +274,11 @@
const char* status = try_allocate(dec, ic);
if (status) {
free(printbuf.ptr);
- printbuf = ((wuffs_base__slice_u8){});
+ printbuf = wuffs_base__make_slice_u8(NULL, 0);
free(workbuf.ptr);
- workbuf = ((wuffs_base__slice_u8){});
+ workbuf = wuffs_base__make_slice_u8(NULL, 0);
free(pixbuf.ptr);
- pixbuf = ((wuffs_base__slice_u8){});
+ pixbuf = wuffs_base__make_slice_u8(NULL, 0);
free(prev_dst_buffer);
prev_dst_buffer = NULL;
free(curr_dst_buffer);
@@ -286,29 +289,24 @@
}
const char* play() {
- wuffs_gif__decoder dec = ((wuffs_gif__decoder){});
+ wuffs_gif__decoder dec;
wuffs_base__status status =
- wuffs_gif__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION);
+ wuffs_gif__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
if (status) {
return status;
}
- wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
- .data = ((wuffs_base__slice_u8){
- .ptr = src_buffer,
- .len = src_len,
- }),
- .meta = ((wuffs_base__io_buffer_meta){
- .wi = src_len,
- .ri = 0,
- .pos = 0,
- .closed = true,
- }),
- });
+ wuffs_base__io_buffer src;
+ src.data.ptr = src_buffer;
+ src.data.len = src_len;
+ src.meta.wi = src_len;
+ src.meta.ri = 0;
+ src.meta.pos = 0;
+ src.meta.closed = true;
wuffs_base__io_reader src_reader = wuffs_base__io_buffer__reader(&src);
if (first_play) {
- wuffs_base__image_config ic = ((wuffs_base__image_config){});
+ wuffs_base__image_config ic = {0};
status = wuffs_gif__decoder__decode_image_config(&dec, &ic, src_reader);
if (status) {
return status;
@@ -340,7 +338,7 @@
}
while (1) {
- wuffs_base__frame_config fc = ((wuffs_base__frame_config){});
+ wuffs_base__frame_config fc = {0};
wuffs_base__status status =
wuffs_gif__decoder__decode_frame_config(&dec, &fc, src_reader);
if (status) {
@@ -383,13 +381,13 @@
}
}
-#ifdef _POSIX_TIMERS
+#if defined(WUFFS_EXAMPLE_USE_TIMERS)
if (started) {
struct timespec now;
if (clock_gettime(CLOCK_MONOTONIC, &now)) {
return strerror(errno);
}
- uint64_t elapsed_micros = micros_since_start(&now);
+ int64_t elapsed_micros = micros_since_start(&now);
if (cumulative_delay_micros > elapsed_micros) {
usleep(cumulative_delay_micros - elapsed_micros);
}
@@ -402,7 +400,7 @@
}
#endif
- ignore_return_value(write(stdout_fd, printbuf.ptr, n));
+ fwrite(printbuf.ptr, sizeof(uint8_t), n, stdout);
cumulative_delay_micros +=
(1000 * wuffs_base__frame_config__duration(&fc)) /
@@ -419,13 +417,6 @@
return NULL;
}
-int fail(const char* msg) {
- const int stderr_fd = 2;
- ignore_return_value(write(stderr_fd, msg, strnlen(msg, 4095)));
- ignore_return_value(write(stderr_fd, "\n", 1));
- return 1;
-}
-
int main(int argc, char** argv) {
int i;
for (i = 1; i < argc; i++) {
@@ -434,14 +425,17 @@
}
}
- const char* msg = read_stdin();
- if (msg) {
- return fail(msg);
+ const char* status = read_stdin();
+ if (status) {
+ fprintf(stderr, "%s\n", status);
+ return 1;
}
+
while (true) {
- msg = play();
- if (msg) {
- return fail(msg);
+ status = play();
+ if (status) {
+ fprintf(stderr, "%s\n", status);
+ return 1;
}
if (num_loops_remaining == 0) {
continue;
diff --git a/example/library/library.c b/example/library/library.c
index 29fbd26..8726ca3 100644
--- a/example/library/library.c
+++ b/example/library/library.c
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// ----------------
+
/*
library exercises the software libraries built by `wuffs genlib`.
@@ -30,81 +32,99 @@
for a C compiler $CC, such as clang or gcc.
*/
+#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
// Wuffs ships as a "single file C library" or "header file library" as per
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
//
// By #include'ing it "as is" without #define'ing WUFFS_IMPLEMENTATION, we use
// it as a "foo.h"-like header, instead of a "foo.c"-like implementation.
+#if defined(WUFFS_IMPLEMENTATION)
+#error "example/library should not #define WUFFS_IMPLEMENTATION"
+#endif
#include "wuffs/release/c/wuffs-unsupported-snapshot.c"
#ifndef DST_BUFFER_SIZE
-#define DST_BUFFER_SIZE (1024 * 1024)
+#define DST_BUFFER_SIZE 1024
+#endif
+uint8_t dst_buffer[DST_BUFFER_SIZE];
+
+// src_ptr and src_len hold a gzip-encoded "Hello Wuffs."
+//
+// $ echo "Hello Wuffs." | gzip --no-name | xxd
+// 00000000: 1f8b 0800 0000 0000 0003 f348 cdc9 c957 ...........H...W
+// 00000010: 082f 4d4b 2bd6 e302 003c 8475 bb0d 0000 ./MK+....<.u....
+// 00000020: 00 .
+//
+// Passing --no-name to the gzip command line also means to skip the timestamp,
+// which means that its output is deterministic.
+uint8_t src_ptr[] = {
+ 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, // 00..07
+ 0x00, 0x03, 0xf3, 0x48, 0xcd, 0xc9, 0xc9, 0x57, // 08..0F
+ 0x08, 0x2f, 0x4d, 0x4b, 0x2b, 0xd6, 0xe3, 0x02, // 10..17
+ 0x00, 0x3c, 0x84, 0x75, 0xbb, 0x0d, 0x00, 0x00, // 18..1F
+ 0x00, // 20..20
+};
+size_t src_len = 0x21;
+
+#define WORK_BUFFER_SIZE WUFFS_GZIP__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE
+#if WORK_BUFFER_SIZE > 0
+uint8_t work_buffer[WORK_BUFFER_SIZE];
+#else
+// Not all C/C++ compilers support 0-length arrays.
+uint8_t work_buffer[1];
#endif
-// lgtm_ptr and lgtm_len hold a deflate-encoded "LGTM" message.
-uint8_t lgtm_ptr[] = {
- 0xf3, 0xc9, 0xcf, 0xcf, 0x2e, 0x56, 0x48, 0xcf, 0xcf, 0x4f,
- 0x51, 0x28, 0xc9, 0x57, 0xc8, 0x4d, 0xd5, 0xe3, 0x02, 0x00,
-};
-size_t lgtm_len = 20;
-
-// ignore_return_value suppresses errors from -Wall -Werror.
-static void ignore_return_value(int ignored) {}
-
static const char* decode() {
- uint8_t dst_buffer[DST_BUFFER_SIZE];
- wuffs_base__io_buffer dst = ((wuffs_base__io_buffer){
- .data = ((wuffs_base__slice_u8){
- .ptr = dst_buffer,
- .len = DST_BUFFER_SIZE,
- }),
- });
- wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
- .data = ((wuffs_base__slice_u8){
- .ptr = lgtm_ptr,
- .len = lgtm_len,
- }),
- .meta = ((wuffs_base__io_buffer_meta){
- .wi = lgtm_len,
- .ri = 0,
- .pos = 0,
- .closed = true,
- }),
- });
+ wuffs_base__io_buffer dst;
+ dst.data.ptr = dst_buffer;
+ dst.data.len = DST_BUFFER_SIZE;
+ dst.meta.wi = 0;
+ dst.meta.ri = 0;
+ dst.meta.pos = 0;
+ dst.meta.closed = false;
+
+ wuffs_base__io_buffer src;
+ src.data.ptr = src_ptr;
+ src.data.len = src_len;
+ src.meta.wi = src_len;
+ src.meta.ri = 0;
+ src.meta.pos = 0;
+ src.meta.closed = true;
+
wuffs_base__io_writer dst_writer = wuffs_base__io_buffer__writer(&dst);
wuffs_base__io_reader src_reader = wuffs_base__io_buffer__reader(&src);
- wuffs_deflate__decoder* dec = calloc(sizeof__wuffs_deflate__decoder(), 1);
+ wuffs_gzip__decoder* dec =
+ (wuffs_gzip__decoder*)(calloc(sizeof__wuffs_gzip__decoder(), 1));
if (!dec) {
return "out of memory";
}
- const char* status = wuffs_deflate__decoder__check_wuffs_version(
- dec, sizeof__wuffs_deflate__decoder(), WUFFS_VERSION);
+ const char* status = wuffs_gzip__decoder__initialize(
+ dec, sizeof__wuffs_gzip__decoder(), WUFFS_VERSION,
+ WUFFS_INITIALIZE__ALREADY_ZEROED);
if (status) {
free(dec);
return status;
}
- status =
- wuffs_deflate__decoder__decode_io_writer(dec, dst_writer, src_reader);
+ status = wuffs_gzip__decoder__decode_io_writer(
+ dec, dst_writer, src_reader,
+ wuffs_base__make_slice_u8(work_buffer, WORK_BUFFER_SIZE));
if (status) {
free(dec);
return status;
}
- ignore_return_value(write(1, dst.data.ptr, dst.meta.wi));
+ fwrite(dst.data.ptr, sizeof(uint8_t), dst.meta.wi, stdout);
free(dec);
return NULL;
}
int main(int argc, char** argv) {
- const char* status_msg = decode();
- int status = 0;
- if (status_msg) {
- status = 1;
- ignore_return_value(write(2, status_msg, strnlen(status_msg, 4095)));
- ignore_return_value(write(2, "\n", 1));
+ const char* status = decode();
+ if (status) {
+ fprintf(stderr, "%s\n", status);
+ return 1;
}
- return status;
+ return 0;
}
diff --git a/example/zcat/zcat.c b/example/zcat/zcat.c
index f8b01a3..c2bf06a 100644
--- a/example/zcat/zcat.c
+++ b/example/zcat/zcat.c
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// ----------------
+
/*
zcat decodes gzip'ed data to stdout. It is similar to the standard /bin/zcat
program, except that this example program only reads from stdin. On Linux, it
@@ -51,7 +53,7 @@
// program to generate a stand-alone C file.
#include "../../release/c/wuffs-unsupported-snapshot.c"
-#ifdef __linux__
+#if defined(__linux__)
#include <linux/prctl.h>
#include <linux/seccomp.h>
#include <sys/prctl.h>
@@ -67,32 +69,43 @@
#define SRC_BUFFER_SIZE (128 * 1024)
#endif
+#define WORK_BUFFER_SIZE WUFFS_GZIP__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE
+
uint8_t dst_buffer[DST_BUFFER_SIZE];
uint8_t src_buffer[SRC_BUFFER_SIZE];
+#if WORK_BUFFER_SIZE > 0
+uint8_t work_buffer[WORK_BUFFER_SIZE];
+#else
+// Not all C/C++ compilers support 0-length arrays.
+uint8_t work_buffer[1];
+#endif
// ignore_return_value suppresses errors from -Wall -Werror.
static void ignore_return_value(int ignored) {}
static const char* decode() {
- wuffs_gzip__decoder dec = ((wuffs_gzip__decoder){});
+ wuffs_gzip__decoder dec;
const char* status =
- wuffs_gzip__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION);
+ wuffs_gzip__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
if (status) {
return status;
}
- wuffs_base__io_buffer dst = ((wuffs_base__io_buffer){
- .data = ((wuffs_base__slice_u8){
- .ptr = dst_buffer,
- .len = DST_BUFFER_SIZE,
- }),
- });
- wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
- .data = ((wuffs_base__slice_u8){
- .ptr = src_buffer,
- .len = SRC_BUFFER_SIZE,
- }),
- });
+ wuffs_base__io_buffer dst;
+ dst.data.ptr = dst_buffer;
+ dst.data.len = DST_BUFFER_SIZE;
+ dst.meta.wi = 0;
+ dst.meta.ri = 0;
+ dst.meta.pos = 0;
+ dst.meta.closed = false;
+
+ wuffs_base__io_buffer src;
+ src.data.ptr = src_buffer;
+ src.data.len = SRC_BUFFER_SIZE;
+ src.meta.wi = 0;
+ src.meta.ri = 0;
+ src.meta.pos = 0;
+ src.meta.closed = false;
while (true) {
const int stdin_fd = 0;
@@ -112,7 +125,8 @@
while (true) {
status = wuffs_gzip__decoder__decode_io_writer(
&dec, wuffs_base__io_buffer__writer(&dst),
- wuffs_base__io_buffer__reader(&src));
+ wuffs_base__io_buffer__reader(&src),
+ wuffs_base__make_slice_u8(work_buffer, WORK_BUFFER_SIZE));
if (dst.meta.wi) {
// TODO: handle EINTR and other write errors; see "man 2 write".
@@ -146,17 +160,17 @@
}
int main(int argc, char** argv) {
-#ifdef WUFFS_EXAMPLE_USE_SECCOMP
+#if defined(WUFFS_EXAMPLE_USE_SECCOMP)
prctl(PR_SET_SECCOMP, SECCOMP_MODE_STRICT);
#endif
- const char* msg = decode();
- int status = msg ? fail(msg) : 0;
+ const char* status = decode();
+ int status_code = status ? fail(status) : 0;
-#ifdef WUFFS_EXAMPLE_USE_SECCOMP
+#if defined(WUFFS_EXAMPLE_USE_SECCOMP)
// Call SYS_exit explicitly instead of SYS_exit_group implicitly.
// SECCOMP_MODE_STRICT allows only the former.
- syscall(SYS_exit, status);
+ syscall(SYS_exit, status_code);
#endif
- return status;
+ return status_code;
}
diff --git a/fuzz/c/fuzzlib/fuzzlib.c b/fuzz/c/fuzzlib/fuzzlib.c
index a74c55c..03050f9 100644
--- a/fuzz/c/fuzzlib/fuzzlib.c
+++ b/fuzz/c/fuzzlib/fuzzlib.c
@@ -15,6 +15,7 @@
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#ifndef WUFFS_INCLUDE_GUARD
#error "Wuffs' .h files need to be included before this file"
@@ -53,7 +54,13 @@
.closed = true,
}),
});
- return fuzz(wuffs_base__io_buffer__reader(&src), hash);
+
+ const char* msg = fuzz(wuffs_base__io_buffer__reader(&src), hash);
+ if (msg && strstr(msg, "internal error:")) {
+ fprintf(stderr, "internal errors shouldn't occur: \"%s\"\n", msg);
+ intentional_segfault();
+ }
+ return msg;
}
#ifdef __cplusplus
@@ -71,58 +78,170 @@
#ifdef WUFFS_CONFIG__FUZZLIB_MAIN
+#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
+#include <stdbool.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
-int main(int argc, char** argv) {
- int i;
- for (i = 1; i < argc; i++) {
- printf("%-50s", argv[i]);
+static int num_files_processed;
- struct stat z;
- int fd = open(argv[i], O_RDONLY, 0);
- if (fd == -1) {
- printf("\n");
- fprintf(stderr, "FAIL: open: %s\n", strerror(errno));
- return 1;
+static struct {
+ char buf[PATH_MAX];
+ size_t len;
+} relative_cwd;
+
+static int visit(char* filename);
+
+static int visit_dir(int fd) {
+ int cwd_fd = open(".", O_RDONLY, 0);
+ if (fchdir(fd)) {
+ printf("failed\n");
+ fprintf(stderr, "FAIL: fchdir: %s\n", strerror(errno));
+ return 1;
+ }
+
+ DIR* d = fdopendir(fd);
+ if (!d) {
+ printf("failed\n");
+ fprintf(stderr, "FAIL: fdopendir: %s\n", strerror(errno));
+ return 1;
+ }
+
+ printf("+dir\n");
+ while (true) {
+ struct dirent* e = readdir(d);
+ if (!e) {
+ break;
}
- if (fstat(fd, &z)) {
- printf("\n");
- fprintf(stderr, "FAIL: fstat: %s\n", strerror(errno));
- return 1;
+ if ((e->d_name[0] == '\x00') || (e->d_name[0] == '.')) {
+ continue;
}
- if ((z.st_size < 0) || (0x7FFFFFFF < z.st_size)) {
- printf("\n");
- fprintf(stderr, "FAIL: file size out of bounds");
- return 1;
+ int v = visit(e->d_name);
+ if (v) {
+ return v;
}
- size_t n = z.st_size;
- void* data = mmap(NULL, n, PROT_READ, MAP_SHARED, fd, 0);
+ }
+
+ if (closedir(d)) {
+ fprintf(stderr, "FAIL: closedir: %s\n", strerror(errno));
+ return 1;
+ }
+ if (fchdir(cwd_fd)) {
+ fprintf(stderr, "FAIL: fchdir: %s\n", strerror(errno));
+ return 1;
+ }
+ if (close(cwd_fd)) {
+ fprintf(stderr, "FAIL: close: %s\n", strerror(errno));
+ return 1;
+ }
+ return 0;
+}
+
+static int visit_reg(int fd, off_t size) {
+ if ((size < 0) || (0x7FFFFFFF < size)) {
+ printf("failed\n");
+ fprintf(stderr, "FAIL: file size out of bounds");
+ return 1;
+ }
+
+ void* data = NULL;
+ if (size > 0) {
+ data = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
if (data == MAP_FAILED) {
- printf("\n");
+ printf("failed\n");
fprintf(stderr, "FAIL: mmap: %s\n", strerror(errno));
return 1;
}
-
- const char* msg = llvmFuzzerTestOneInput((const uint8_t*)(data), n);
- if (!msg) {
- msg = "(null)";
- }
- printf(" %s\n", msg);
-
- if (munmap(data, n)) {
- fprintf(stderr, "FAIL: mmap: %s\n", strerror(errno));
- return 1;
- }
- if (close(fd)) {
- fprintf(stderr, "FAIL: close: %s\n", strerror(errno));
- return 1;
- }
}
- printf("PASS: %d files processed\n", argc > 1 ? argc - 1 : 0);
+
+ const char* msg = llvmFuzzerTestOneInput((const uint8_t*)(data), size);
+ if (!msg) {
+ msg = "+ok";
+ }
+ printf("%s\n", msg);
+
+ if ((size > 0) && munmap(data, size)) {
+ fprintf(stderr, "FAIL: mmap: %s\n", strerror(errno));
+ return 1;
+ }
+ if (close(fd)) {
+ fprintf(stderr, "FAIL: close: %s\n", strerror(errno));
+ return 1;
+ }
+ return 0;
+}
+
+static int visit(char* filename) {
+ num_files_processed++;
+ if (!filename || (filename[0] == '\x00')) {
+ fprintf(stderr, "FAIL: invalid filename\n");
+ return 1;
+ }
+ int n = printf("- %s%s", relative_cwd.buf, filename);
+ printf("%*s", (60 > n) ? (60 - n) : 1, "");
+
+ struct stat z;
+ int fd = open(filename, O_RDONLY, 0);
+ if (fd == -1) {
+ printf("failed\n");
+ fprintf(stderr, "FAIL: open: %s\n", strerror(errno));
+ return 1;
+ }
+ if (fstat(fd, &z)) {
+ printf("failed\n");
+ fprintf(stderr, "FAIL: fstat: %s\n", strerror(errno));
+ return 1;
+ }
+
+ if (S_ISREG(z.st_mode)) {
+ return visit_reg(fd, z.st_size);
+ } else if (!S_ISDIR(z.st_mode)) {
+ printf("skipped\n");
+ return 0;
+ }
+
+ size_t old_len = relative_cwd.len;
+ size_t filename_len = strlen(filename);
+ size_t new_len = old_len + strlen(filename);
+ bool slash = filename[filename_len - 1] != '/';
+ if (slash) {
+ new_len++;
+ }
+ if ((filename_len >= PATH_MAX) || (new_len >= PATH_MAX)) {
+ printf("failed\n");
+ fprintf(stderr, "FAIL: path is too long\n");
+ return 1;
+ }
+ memcpy(relative_cwd.buf + old_len, filename, filename_len);
+
+ if (slash) {
+ relative_cwd.buf[new_len - 1] = '/';
+ }
+ relative_cwd.buf[new_len] = '\x00';
+ relative_cwd.len = new_len;
+
+ int v = visit_dir(fd);
+
+ relative_cwd.buf[old_len] = '\x00';
+ relative_cwd.len = old_len;
+ return v;
+}
+
+int main(int argc, char** argv) {
+ num_files_processed = 0;
+ relative_cwd.len = 0;
+
+ int i;
+ for (i = 1; i < argc; i++) {
+ int v = visit(argv[i]);
+ if (v) {
+ return v;
+ }
+ }
+ printf("PASS: %d files processed\n", num_files_processed);
return 0;
}
diff --git a/fuzz/c/std/gif_fuzzer.c b/fuzz/c/std/gif_fuzzer.c
index e1e7adf..c3ce2fd 100644
--- a/fuzz/c/std/gif_fuzzer.c
+++ b/fuzz/c/std/gif_fuzzer.c
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// ----------------
+
// Silence the nested slash-star warning for the next comment's command line.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wcomment"
@@ -54,9 +56,11 @@
// Use a {} code block so that "goto exit" doesn't trigger "jump bypasses
// variable initialization" warnings.
{
- wuffs_gif__decoder dec = ((wuffs_gif__decoder){});
- const char* status = wuffs_gif__decoder__check_wuffs_version(
- &dec, sizeof dec, WUFFS_VERSION);
+ wuffs_gif__decoder dec;
+ const char* status = wuffs_gif__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION,
+ (hash & 1) ? WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED
+ : 0);
if (status) {
ret = status;
goto exit;
@@ -73,15 +77,19 @@
goto exit;
}
+ // Wuffs allows either statically or dynamically allocated work buffers.
+ // This program exercises dynamic allocation.
uint64_t n = wuffs_gif__decoder__workbuf_len(&dec).max_incl;
if (n > 64 * 1024 * 1024) { // Don't allocate more than 64 MiB.
ret = "image too large";
goto exit;
}
- workbuf = wuffs_base__malloc_slice_u8(malloc, n);
- if (!workbuf.ptr) {
- ret = "out of memory";
- goto exit;
+ if (n > 0) {
+ workbuf = wuffs_base__malloc_slice_u8(malloc, n);
+ if (!workbuf.ptr) {
+ ret = "out of memory";
+ goto exit;
+ }
}
n = wuffs_base__pixel_config__pixbuf_len(&ic.pixcfg);
@@ -89,10 +97,12 @@
ret = "image too large";
goto exit;
}
- pixbuf = wuffs_base__malloc_slice_u8(malloc, n);
- if (!pixbuf.ptr) {
- ret = "out of memory";
- goto exit;
+ if (n > 0) {
+ pixbuf = wuffs_base__malloc_slice_u8(malloc, n);
+ if (!pixbuf.ptr) {
+ ret = "out of memory";
+ goto exit;
+ }
}
wuffs_base__pixel_buffer pb = ((wuffs_base__pixel_buffer){});
@@ -104,8 +114,27 @@
bool seen_ok = false;
while (true) {
+ wuffs_base__frame_config fc = ((wuffs_base__frame_config){});
+ status = wuffs_gif__decoder__decode_frame_config(&dec, &fc, src_reader);
+ if (status) {
+ if ((status != wuffs_base__warning__end_of_data) || !seen_ok) {
+ ret = status;
+ }
+ goto exit;
+ }
+
status = wuffs_gif__decoder__decode_frame(&dec, &pb, src_reader, workbuf,
NULL);
+
+ wuffs_base__rect_ie_u32 frame_rect =
+ wuffs_base__frame_config__bounds(&fc);
+ wuffs_base__rect_ie_u32 dirty_rect =
+ wuffs_gif__decoder__frame_dirty_rect(&dec);
+ if (!wuffs_base__rect_ie_u32__contains_rect(&frame_rect, dirty_rect)) {
+ ret = "internal error: frame_rect does not contain dirty_rect";
+ goto exit;
+ }
+
if (status) {
if ((status != wuffs_base__warning__end_of_data) || !seen_ok) {
ret = status;
@@ -113,6 +142,11 @@
goto exit;
}
seen_ok = true;
+
+ if (!wuffs_base__rect_ie_u32__equals(&frame_rect, dirty_rect)) {
+ ret = "internal error: frame_rect does not equal dirty_rect";
+ goto exit;
+ }
}
}
diff --git a/fuzz/c/std/seed_corpora.txt b/fuzz/c/std/seed_corpora.txt
index 809e9fd..b295144 100644
--- a/fuzz/c/std/seed_corpora.txt
+++ b/fuzz/c/std/seed_corpora.txt
@@ -11,6 +11,6 @@
# This file is not used by Wuffs per se, but it is used by the "projects/wuffs"
# directory in the https://github.com/google/oss-fuzz repository.
-gif: test/data/*.gif
-gzip: test/data/*.gz
+gif: test/data/*.gif test/data/artificial/*.gif
+gzip: test/data/*.gz test/data/artificial/*.gz
zlib: test/data/*.zlib
diff --git a/fuzz/c/std/zlib_fuzzer.c b/fuzz/c/std/zlib_fuzzer.c
index 49f58a1..ffded01 100644
--- a/fuzz/c/std/zlib_fuzzer.c
+++ b/fuzz/c/std/zlib_fuzzer.c
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// ----------------
+
// Silence the nested slash-star warning for the next comment's command line.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wcomment"
@@ -46,10 +48,23 @@
#include "../../../release/c/wuffs-unsupported-snapshot.c"
#include "../fuzzlib/fuzzlib.c"
+#define DST_BUFFER_SIZE 65536
+
+// Wuffs allows either statically or dynamically allocated work buffers. This
+// program exercises static allocation.
+#define WORK_BUFFER_SIZE WUFFS_ZLIB__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE
+#if WORK_BUFFER_SIZE > 0
+uint8_t work_buffer[WORK_BUFFER_SIZE];
+#else
+// Not all C/C++ compilers support 0-length arrays.
+uint8_t work_buffer[1];
+#endif
+
const char* fuzz(wuffs_base__io_reader src_reader, uint32_t hash) {
- wuffs_zlib__decoder dec = ((wuffs_zlib__decoder){});
- const char* status =
- wuffs_zlib__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION);
+ wuffs_zlib__decoder dec;
+ const char* status = wuffs_zlib__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION,
+ (hash & 1) ? WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED : 0);
if (status) {
return status;
}
@@ -57,27 +72,30 @@
// Ignore the checksum for 99.99%-ish of all input. When fuzzers generate
// random input, the checkum is very unlikely to match. Still, it's useful to
// verify that checksumming does not lead to e.g. buffer overflows.
- wuffs_zlib__decoder__set_ignore_checksum(&dec, hash & 0xFFFF);
+ wuffs_zlib__decoder__set_ignore_checksum(&dec, hash & 0xFFFE);
- const size_t dstbuf_size = 65536;
- uint8_t dstbuf[dstbuf_size];
+ uint8_t dst_buffer[DST_BUFFER_SIZE];
wuffs_base__io_buffer dst = ((wuffs_base__io_buffer){
.data = ((wuffs_base__slice_u8){
- .ptr = dstbuf,
- .len = dstbuf_size,
+ .ptr = dst_buffer,
+ .len = DST_BUFFER_SIZE,
}),
});
wuffs_base__io_writer dst_writer = wuffs_base__io_buffer__writer(&dst);
while (true) {
dst.meta.wi = 0;
- status =
- wuffs_zlib__decoder__decode_io_writer(&dec, dst_writer, src_reader);
+ status = wuffs_zlib__decoder__decode_io_writer(&dec, dst_writer, src_reader,
+ ((wuffs_base__slice_u8){
+ .ptr = work_buffer,
+ .len = WORK_BUFFER_SIZE,
+ }));
if (status != wuffs_base__suspension__short_write) {
break;
}
if (dst.meta.wi == 0) {
- fprintf(stderr, "wuffs_zlib__decoder__decode made no progress\n");
+ fprintf(stderr,
+ "wuffs_zlib__decoder__decode_io_writer made no progress\n");
intentional_segfault();
}
}
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..3279328
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,3 @@
+module github.com/google/wuffs
+
+go 1.13
diff --git a/cmd/wuffs-c/internal/cgen/base/all-impl.c b/internal/cgen/base/all-impl.c
similarity index 88%
rename from cmd/wuffs-c/internal/cgen/base/all-impl.c
rename to internal/cgen/base/all-impl.c
index 76d2cbd..8289d71 100644
--- a/cmd/wuffs-c/internal/cgen/base/all-impl.c
+++ b/internal/cgen/base/all-impl.c
@@ -30,6 +30,12 @@
#include <stdint.h>
#include <string.h>
+// GCC does not warn for unused *static inline* functions, but clang does.
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunused-function"
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -40,9 +46,19 @@
} // extern "C"
#endif
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+
// WUFFS C HEADER ENDS HERE.
#ifdef WUFFS_IMPLEMENTATION
+// GCC does not warn for unused *static inline* functions, but clang does.
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunused-function"
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -105,6 +121,10 @@
} // extern "C"
#endif
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+
#endif // WUFFS_IMPLEMENTATION
// !! WUFFS MONOLITHIC RELEASE DISCARDS EVERYTHING BELOW.
diff --git a/cmd/wuffs-c/internal/cgen/base/core-private.h b/internal/cgen/base/core-private.h
similarity index 80%
rename from cmd/wuffs-c/internal/cgen/base/core-private.h
rename to internal/cgen/base/core-private.h
index 3b5e068..6c43af5 100644
--- a/cmd/wuffs-c/internal/cgen/base/core-private.h
+++ b/internal/cgen/base/core-private.h
@@ -14,10 +14,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#define WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(x) (void)(x)
-
-static inline void wuffs_base__ignore_check_wuffs_version_status(
- wuffs_base__status z) {}
+static inline wuffs_base__empty_struct //
+wuffs_base__ignore_status(wuffs_base__status z) {
+ return wuffs_base__make_empty_struct();
+}
// 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,
@@ -35,7 +35,7 @@
// Denote intentional fallthroughs for -Wimplicit-fallthrough.
//
// The order matters here. Clang also defines "__GNUC__".
-#if defined(__clang__) && __cplusplus >= 201103L
+#if defined(__clang__) && defined(__cplusplus) && (__cplusplus >= 201103L)
#define WUFFS_BASE__FALLTHROUGH [[clang::fallthrough]]
#elif !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 7)
#define WUFFS_BASE__FALLTHROUGH __attribute__((fallthrough))
@@ -83,11 +83,6 @@
// inline attribute to guide optimizations such as inlining, to avoid the
// -Wunused-function warning, and we like to compile with -Wall -Werror.
-static inline wuffs_base__empty_struct //
-wuffs_base__return_empty_struct() {
- return ((wuffs_base__empty_struct){});
-}
-
// ---------------- Numeric Types
static inline uint8_t //
@@ -97,12 +92,12 @@
static inline uint16_t //
wuffs_base__load_u16be(uint8_t* p) {
- return ((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0);
+ return (uint16_t)(((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0));
}
static inline uint16_t //
wuffs_base__load_u16le(uint8_t* p) {
- return ((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8);
+ return (uint16_t)(((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8));
}
static inline uint32_t //
@@ -198,128 +193,128 @@
static inline void //
wuffs_base__store_u16be(uint8_t* p, uint16_t x) {
- p[0] = x >> 8;
- p[1] = x >> 0;
+ p[0] = (uint8_t)(x >> 8);
+ p[1] = (uint8_t)(x >> 0);
}
static inline void //
wuffs_base__store_u16le(uint8_t* p, uint16_t x) {
- p[0] = x >> 0;
- p[1] = x >> 8;
+ p[0] = (uint8_t)(x >> 0);
+ p[1] = (uint8_t)(x >> 8);
}
static inline void //
wuffs_base__store_u24be(uint8_t* p, uint32_t x) {
- p[0] = x >> 16;
- p[1] = x >> 8;
- p[2] = x >> 0;
+ p[0] = (uint8_t)(x >> 16);
+ p[1] = (uint8_t)(x >> 8);
+ p[2] = (uint8_t)(x >> 0);
}
static inline void //
wuffs_base__store_u24le(uint8_t* p, uint32_t x) {
- p[0] = x >> 0;
- p[1] = x >> 8;
- p[2] = x >> 16;
+ p[0] = (uint8_t)(x >> 0);
+ p[1] = (uint8_t)(x >> 8);
+ p[2] = (uint8_t)(x >> 16);
}
static inline void //
wuffs_base__store_u32be(uint8_t* p, uint32_t x) {
- p[0] = x >> 24;
- p[1] = x >> 16;
- p[2] = x >> 8;
- p[3] = x >> 0;
+ p[0] = (uint8_t)(x >> 24);
+ p[1] = (uint8_t)(x >> 16);
+ p[2] = (uint8_t)(x >> 8);
+ p[3] = (uint8_t)(x >> 0);
}
static inline void //
wuffs_base__store_u32le(uint8_t* p, uint32_t x) {
- p[0] = x >> 0;
- p[1] = x >> 8;
- p[2] = x >> 16;
- p[3] = x >> 24;
+ p[0] = (uint8_t)(x >> 0);
+ p[1] = (uint8_t)(x >> 8);
+ p[2] = (uint8_t)(x >> 16);
+ p[3] = (uint8_t)(x >> 24);
}
static inline void //
wuffs_base__store_u40be(uint8_t* p, uint64_t x) {
- p[0] = x >> 32;
- p[1] = x >> 24;
- p[2] = x >> 16;
- p[3] = x >> 8;
- p[4] = x >> 0;
+ p[0] = (uint8_t)(x >> 32);
+ p[1] = (uint8_t)(x >> 24);
+ p[2] = (uint8_t)(x >> 16);
+ p[3] = (uint8_t)(x >> 8);
+ p[4] = (uint8_t)(x >> 0);
}
static inline void //
wuffs_base__store_u40le(uint8_t* p, uint64_t x) {
- p[0] = x >> 0;
- p[1] = x >> 8;
- p[2] = x >> 16;
- p[3] = x >> 24;
- p[4] = x >> 32;
+ p[0] = (uint8_t)(x >> 0);
+ p[1] = (uint8_t)(x >> 8);
+ p[2] = (uint8_t)(x >> 16);
+ p[3] = (uint8_t)(x >> 24);
+ p[4] = (uint8_t)(x >> 32);
}
static inline void //
wuffs_base__store_u48be(uint8_t* p, uint64_t x) {
- p[0] = x >> 40;
- p[1] = x >> 32;
- p[2] = x >> 24;
- p[3] = x >> 16;
- p[4] = x >> 8;
- p[5] = x >> 0;
+ p[0] = (uint8_t)(x >> 40);
+ p[1] = (uint8_t)(x >> 32);
+ p[2] = (uint8_t)(x >> 24);
+ p[3] = (uint8_t)(x >> 16);
+ p[4] = (uint8_t)(x >> 8);
+ p[5] = (uint8_t)(x >> 0);
}
static inline void //
wuffs_base__store_u48le(uint8_t* p, uint64_t x) {
- p[0] = x >> 0;
- p[1] = x >> 8;
- p[2] = x >> 16;
- p[3] = x >> 24;
- p[4] = x >> 32;
- p[5] = x >> 40;
+ p[0] = (uint8_t)(x >> 0);
+ p[1] = (uint8_t)(x >> 8);
+ p[2] = (uint8_t)(x >> 16);
+ p[3] = (uint8_t)(x >> 24);
+ p[4] = (uint8_t)(x >> 32);
+ p[5] = (uint8_t)(x >> 40);
}
static inline void //
wuffs_base__store_u56be(uint8_t* p, uint64_t x) {
- p[0] = x >> 48;
- p[1] = x >> 40;
- p[2] = x >> 32;
- p[3] = x >> 24;
- p[4] = x >> 16;
- p[5] = x >> 8;
- p[6] = x >> 0;
+ p[0] = (uint8_t)(x >> 48);
+ p[1] = (uint8_t)(x >> 40);
+ p[2] = (uint8_t)(x >> 32);
+ p[3] = (uint8_t)(x >> 24);
+ p[4] = (uint8_t)(x >> 16);
+ p[5] = (uint8_t)(x >> 8);
+ p[6] = (uint8_t)(x >> 0);
}
static inline void //
wuffs_base__store_u56le(uint8_t* p, uint64_t x) {
- p[0] = x >> 0;
- p[1] = x >> 8;
- p[2] = x >> 16;
- p[3] = x >> 24;
- p[4] = x >> 32;
- p[5] = x >> 40;
- p[6] = x >> 48;
+ p[0] = (uint8_t)(x >> 0);
+ p[1] = (uint8_t)(x >> 8);
+ p[2] = (uint8_t)(x >> 16);
+ p[3] = (uint8_t)(x >> 24);
+ p[4] = (uint8_t)(x >> 32);
+ p[5] = (uint8_t)(x >> 40);
+ p[6] = (uint8_t)(x >> 48);
}
static inline void //
wuffs_base__store_u64be(uint8_t* p, uint64_t x) {
- p[0] = x >> 56;
- p[1] = x >> 48;
- p[2] = x >> 40;
- p[3] = x >> 32;
- p[4] = x >> 24;
- p[5] = x >> 16;
- p[6] = x >> 8;
- p[7] = x >> 0;
+ p[0] = (uint8_t)(x >> 56);
+ p[1] = (uint8_t)(x >> 48);
+ p[2] = (uint8_t)(x >> 40);
+ p[3] = (uint8_t)(x >> 32);
+ p[4] = (uint8_t)(x >> 24);
+ p[5] = (uint8_t)(x >> 16);
+ p[6] = (uint8_t)(x >> 8);
+ p[7] = (uint8_t)(x >> 0);
}
static inline void //
wuffs_base__store_u64le(uint8_t* p, uint64_t x) {
- p[0] = x >> 0;
- p[1] = x >> 8;
- p[2] = x >> 16;
- p[3] = x >> 24;
- p[4] = x >> 32;
- p[5] = x >> 40;
- p[6] = x >> 48;
- p[7] = x >> 56;
+ p[0] = (uint8_t)(x >> 0);
+ p[1] = (uint8_t)(x >> 8);
+ p[2] = (uint8_t)(x >> 16);
+ p[3] = (uint8_t)(x >> 24);
+ p[4] = (uint8_t)(x >> 32);
+ p[5] = (uint8_t)(x >> 40);
+ p[6] = (uint8_t)(x >> 48);
+ p[7] = (uint8_t)(x >> 56);
}
// --------
@@ -417,10 +412,11 @@
static inline wuffs_base__slice_u8 //
wuffs_base__table_u8__row(wuffs_base__table_u8 t, uint32_t y) {
if (y < t.height) {
- return ((wuffs_base__slice_u8){
- .ptr = t.ptr + (t.stride * y),
- .len = t.width,
- });
+ return wuffs_base__make_slice_u8(t.ptr + (t.stride * y), t.width);
}
- return ((wuffs_base__slice_u8){});
+ return wuffs_base__make_slice_u8(NULL, 0);
}
+
+// ---------------- Slices and Tables (Utility)
+
+#define wuffs_base__utility__null_slice_u8 wuffs_base__null_slice_u8
diff --git a/cmd/wuffs-c/internal/cgen/base/core-public.h b/internal/cgen/base/core-public.h
similarity index 70%
rename from cmd/wuffs-c/internal/cgen/base/core-public.h
rename to internal/cgen/base/core-public.h
index c3c2b75..dc7e7fb 100644
--- a/cmd/wuffs-c/internal/cgen/base/core-public.h
+++ b/internal/cgen/base/core-public.h
@@ -57,13 +57,57 @@
#define WUFFS_BASE__MAYBE_STATIC
#endif
+#if defined(__clang__)
+#define WUFFS_BASE__POTENTIALLY_UNUSED_FIELD __attribute__((unused))
+#else
+#define WUFFS_BASE__POTENTIALLY_UNUSED_FIELD
+#endif
+
// Clang also defines "__GNUC__".
#if defined(__GNUC__)
+#define WUFFS_BASE__POTENTIALLY_UNUSED __attribute__((unused))
#define WUFFS_BASE__WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#else
+#define WUFFS_BASE__POTENTIALLY_UNUSED
#define WUFFS_BASE__WARN_UNUSED_RESULT
#endif
+// Flags for wuffs_foo__bar__initialize functions.
+
+#define WUFFS_INITIALIZE__DEFAULT_OPTIONS ((uint32_t)0x00000000)
+
+// WUFFS_INITIALIZE__ALREADY_ZEROED means that the "self" receiver struct value
+// has already been set to all zeroes.
+#define WUFFS_INITIALIZE__ALREADY_ZEROED ((uint32_t)0x00000001)
+
+// WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED means that, absent
+// WUFFS_INITIALIZE__ALREADY_ZEROED, only some of the "self" receiver struct
+// value will be set to all zeroes. Internal buffers, which tend to be a large
+// proportion of the struct's size, will be left uninitialized. Internal means
+// that the buffer is contained by the receiver struct, as opposed to being
+// passed as a separately allocated "work buffer".
+//
+// With or without this bit set, the Wuffs compiler still enforces that no
+// reads or writes will overflow internal buffers' bounds. Even with this bit
+// set, the Wuffs standard library also considers reading from an uninitialized
+// buffer to be a bug, and strives to never do so, but unlike buffer overflows,
+// it is not a bug class that the Wuffs compiler eliminates.
+//
+// For those paranoid about security, leave this bit unset, so that
+// wuffs_foo__bar__initialize will initialize the entire struct value to zeroes
+// (unless WUFFS_INITIALIZE__ALREADY_ZEROED is set).
+//
+// Setting this bit gives a small absolute improvement on micro-benchmarks, but
+// this can be a large relative effect, up to 2x faster, when the actual work
+// to be done is also small, such as decompressing small input. See git commit
+// 438fc105 "Move some struct fields to private_data" for some numbers and a
+// discussion, noting that its commit message was written before this
+// WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED option was defined.
+#define WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED \
+ ((uint32_t)0x00000002)
+
+// --------
+
// 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
// Wuffs, if a function g returns empty, you can say "y = g()".
@@ -80,6 +124,13 @@
uint8_t private_impl;
} wuffs_base__empty_struct;
+static inline wuffs_base__empty_struct //
+wuffs_base__make_empty_struct() {
+ wuffs_base__empty_struct ret;
+ ret.private_impl = 0;
+ return ret;
+}
+
// wuffs_base__utility is a placeholder receiver type. It enables what Java
// calls static methods, as opposed to regular methods.
typedef struct {
@@ -121,12 +172,12 @@
static inline bool //
wuffs_base__status__is_complete(wuffs_base__status z) {
- return (z == NULL) || ((*z != '$') && (*z != '?'));
+ return (z == NULL) || ((*z != '$') && (*z != '#'));
}
static inline bool //
wuffs_base__status__is_error(wuffs_base__status z) {
- return z && (*z == '?');
+ return z && (*z == '#');
}
static inline bool //
@@ -141,7 +192,7 @@
static inline bool //
wuffs_base__status__is_warning(wuffs_base__status z) {
- return z && (*z != '$') && (*z != '?');
+ return z && (*z != '$') && (*z != '#');
}
// --------
@@ -205,57 +256,57 @@
static inline uint8_t //
wuffs_base__u8__sat_add(uint8_t x, uint8_t y) {
- uint8_t res = x + y;
- res |= -(res < x);
+ uint8_t res = (uint8_t)(x + y);
+ res |= (uint8_t)(-(res < x));
return res;
}
static inline uint8_t //
wuffs_base__u8__sat_sub(uint8_t x, uint8_t y) {
- uint8_t res = x - y;
- res &= -(res <= x);
+ uint8_t res = (uint8_t)(x - y);
+ res &= (uint8_t)(-(res <= x));
return res;
}
static inline uint16_t //
wuffs_base__u16__sat_add(uint16_t x, uint16_t y) {
- uint16_t res = x + y;
- res |= -(res < x);
+ uint16_t res = (uint16_t)(x + y);
+ res |= (uint16_t)(-(res < x));
return res;
}
static inline uint16_t //
wuffs_base__u16__sat_sub(uint16_t x, uint16_t y) {
- uint16_t res = x - y;
- res &= -(res <= x);
+ uint16_t res = (uint16_t)(x - y);
+ res &= (uint16_t)(-(res <= x));
return res;
}
static inline uint32_t //
wuffs_base__u32__sat_add(uint32_t x, uint32_t y) {
- uint32_t res = x + y;
- res |= -(res < x);
+ uint32_t res = (uint32_t)(x + y);
+ res |= (uint32_t)(-(res < x));
return res;
}
static inline uint32_t //
wuffs_base__u32__sat_sub(uint32_t x, uint32_t y) {
- uint32_t res = x - y;
- res &= -(res <= x);
+ uint32_t res = (uint32_t)(x - y);
+ res &= (uint32_t)(-(res <= x));
return res;
}
static inline uint64_t //
wuffs_base__u64__sat_add(uint64_t x, uint64_t y) {
- uint64_t res = x + y;
- res |= -(res < x);
+ uint64_t res = (uint64_t)(x + y);
+ res |= (uint64_t)(-(res < x));
return res;
}
static inline uint64_t //
wuffs_base__u64__sat_sub(uint64_t x, uint64_t y) {
- uint64_t res = x - y;
- res &= -(res <= x);
+ uint64_t res = (uint64_t)(x - y);
+ res &= (uint64_t)(-(res <= x));
return res;
}
@@ -296,18 +347,65 @@
typedef WUFFS_BASE__TABLE(uint32_t) wuffs_base__table_u32;
typedef WUFFS_BASE__TABLE(uint64_t) wuffs_base__table_u64;
+static inline wuffs_base__slice_u8 //
+wuffs_base__make_slice_u8(uint8_t* ptr, size_t len) {
+ wuffs_base__slice_u8 ret;
+ ret.ptr = ptr;
+ ret.len = len;
+ return ret;
+}
+
+static inline wuffs_base__slice_u16 //
+wuffs_base__make_slice_u16(uint16_t* ptr, size_t len) {
+ wuffs_base__slice_u16 ret;
+ ret.ptr = ptr;
+ ret.len = len;
+ return ret;
+}
+
+static inline wuffs_base__slice_u32 //
+wuffs_base__make_slice_u32(uint32_t* ptr, size_t len) {
+ wuffs_base__slice_u32 ret;
+ ret.ptr = ptr;
+ ret.len = len;
+ return ret;
+}
+
+static inline wuffs_base__slice_u64 //
+wuffs_base__make_slice_u64(uint64_t* ptr, size_t len) {
+ wuffs_base__slice_u64 ret;
+ ret.ptr = ptr;
+ ret.len = len;
+ return ret;
+}
+
+static inline wuffs_base__slice_u8 //
+wuffs_base__null_slice_u8() {
+ wuffs_base__slice_u8 ret;
+ ret.ptr = NULL;
+ ret.len = 0;
+ return ret;
+}
+
+static inline wuffs_base__table_u8 //
+wuffs_base__null_table_u8() {
+ wuffs_base__table_u8 ret;
+ ret.ptr = NULL;
+ ret.width = 0;
+ ret.height = 0;
+ ret.stride = 0;
+ return ret;
+}
+
// wuffs_base__slice_u8__subslice_i returns s[i:].
//
// It returns an empty slice if i is out of bounds.
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 ((wuffs_base__slice_u8){
- .ptr = s.ptr + i,
- .len = s.len - i,
- });
+ return wuffs_base__make_slice_u8(s.ptr + i, s.len - i);
}
- return ((wuffs_base__slice_u8){});
+ return wuffs_base__make_slice_u8(NULL, 0);
}
// wuffs_base__slice_u8__subslice_j returns s[:j].
@@ -316,12 +414,9 @@
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 ((wuffs_base__slice_u8){
- .ptr = s.ptr,
- .len = j,
- });
+ return wuffs_base__make_slice_u8(s.ptr, j);
}
- return ((wuffs_base__slice_u8){});
+ return wuffs_base__make_slice_u8(NULL, 0);
}
// wuffs_base__slice_u8__subslice_ij returns s[i:j].
@@ -332,10 +427,7 @@
uint64_t i,
uint64_t j) {
if ((i <= j) && (j <= SIZE_MAX) && (j <= s.len)) {
- return ((wuffs_base__slice_u8){
- .ptr = s.ptr + i,
- .len = j - i,
- });
+ return wuffs_base__make_slice_u8(s.ptr + i, j - i);
}
- return ((wuffs_base__slice_u8){});
+ return wuffs_base__make_slice_u8(NULL, 0);
}
diff --git a/cmd/wuffs-c/internal/cgen/base/image-impl.c b/internal/cgen/base/image-impl.c
similarity index 98%
rename from cmd/wuffs-c/internal/cgen/base/image-impl.c
rename to internal/cgen/base/image-impl.c
index c3ce468..6674c4a 100644
--- a/cmd/wuffs-c/internal/cgen/base/image-impl.c
+++ b/internal/cgen/base/image-impl.c
@@ -59,7 +59,7 @@
s += 1 * N;
d += 4 * N;
- n -= 1 * N;
+ n -= (size_t)(1 * N);
}
while (n >= 1) {
@@ -69,7 +69,7 @@
s += 1 * 1;
d += 4 * 1;
- n -= 1 * 1;
+ n -= (size_t)(1 * 1);
}
return len;
diff --git a/cmd/wuffs-c/internal/cgen/base/image-private.h b/internal/cgen/base/image-private.h
similarity index 100%
rename from cmd/wuffs-c/internal/cgen/base/image-private.h
rename to internal/cgen/base/image-private.h
diff --git a/cmd/wuffs-c/internal/cgen/base/image-public.h b/internal/cgen/base/image-public.h
similarity index 92%
rename from cmd/wuffs-c/internal/cgen/base/image-public.h
rename to internal/cgen/base/image-public.h
index 59e1d3f..f452b3b 100644
--- a/cmd/wuffs-c/internal/cgen/base/image-public.h
+++ b/internal/cgen/base/image-public.h
@@ -347,6 +347,16 @@
} wuffs_base__pixel_config;
+static inline wuffs_base__pixel_config //
+wuffs_base__null_pixel_config() {
+ wuffs_base__pixel_config ret;
+ ret.private_impl.pixfmt = 0;
+ ret.private_impl.pixsub = 0;
+ ret.private_impl.width = 0;
+ ret.private_impl.height = 0;
+ return ret;
+}
+
// TODO: Should this function return bool? An error type?
static inline void //
wuffs_base__pixel_config__set(wuffs_base__pixel_config* c,
@@ -368,13 +378,20 @@
return;
}
}
- *c = ((wuffs_base__pixel_config){});
+
+ c->private_impl.pixfmt = 0;
+ c->private_impl.pixsub = 0;
+ c->private_impl.width = 0;
+ c->private_impl.height = 0;
}
static inline void //
wuffs_base__pixel_config__invalidate(wuffs_base__pixel_config* c) {
if (c) {
- *c = ((wuffs_base__pixel_config){});
+ c->private_impl.pixfmt = 0;
+ c->private_impl.pixsub = 0;
+ c->private_impl.width = 0;
+ c->private_impl.height = 0;
}
}
@@ -395,13 +412,21 @@
static inline wuffs_base__rect_ie_u32 //
wuffs_base__pixel_config__bounds(wuffs_base__pixel_config* c) {
- return c ? ((wuffs_base__rect_ie_u32){
- .min_incl_x = 0,
- .min_incl_y = 0,
- .max_excl_x = c->private_impl.width,
- .max_excl_y = c->private_impl.height,
- })
- : ((wuffs_base__rect_ie_u32){});
+ if (c) {
+ wuffs_base__rect_ie_u32 ret;
+ ret.min_incl_x = 0;
+ ret.min_incl_y = 0;
+ ret.max_excl_x = c->private_impl.width;
+ ret.max_excl_y = c->private_impl.height;
+ return ret;
+ }
+
+ wuffs_base__rect_ie_u32 ret;
+ ret.min_incl_x = 0;
+ ret.min_incl_y = 0;
+ ret.max_excl_x = 0;
+ ret.max_excl_y = 0;
+ return ret;
}
static inline uint32_t //
@@ -530,6 +555,15 @@
} wuffs_base__image_config;
+static inline wuffs_base__image_config //
+wuffs_base__null_image_config() {
+ wuffs_base__image_config ret;
+ ret.pixcfg = wuffs_base__null_pixel_config();
+ ret.private_impl.first_frame_io_position = 0;
+ ret.private_impl.first_frame_is_opaque = false;
+ return ret;
+}
+
// TODO: Should this function return bool? An error type?
static inline void //
wuffs_base__image_config__set(wuffs_base__image_config* c,
@@ -551,13 +585,24 @@
c->private_impl.first_frame_is_opaque = first_frame_is_opaque;
return;
}
- *c = ((wuffs_base__image_config){});
+
+ c->pixcfg.private_impl.pixfmt = 0;
+ c->pixcfg.private_impl.pixsub = 0;
+ c->pixcfg.private_impl.width = 0;
+ c->pixcfg.private_impl.height = 0;
+ c->private_impl.first_frame_io_position = 0;
+ c->private_impl.first_frame_is_opaque = 0;
}
static inline void //
wuffs_base__image_config__invalidate(wuffs_base__image_config* c) {
if (c) {
- *c = ((wuffs_base__image_config){});
+ c->pixcfg.private_impl.pixfmt = 0;
+ c->pixcfg.private_impl.pixsub = 0;
+ c->pixcfg.private_impl.width = 0;
+ c->pixcfg.private_impl.height = 0;
+ c->private_impl.first_frame_io_position = 0;
+ c->private_impl.first_frame_is_opaque = 0;
}
}
@@ -682,6 +727,18 @@
} wuffs_base__frame_config;
+static inline wuffs_base__frame_config //
+wuffs_base__null_frame_config() {
+ wuffs_base__frame_config ret;
+ ret.private_impl.bounds = wuffs_base__make_rect_ie_u32(0, 0, 0, 0);
+ ret.private_impl.duration = 0;
+ ret.private_impl.index = 0;
+ ret.private_impl.io_position = 0;
+ ret.private_impl.blend = 0;
+ ret.private_impl.disposal = 0;
+ return ret;
+}
+
static inline void //
wuffs_base__frame_config__update(wuffs_base__frame_config* c,
wuffs_base__rect_ie_u32 bounds,
@@ -704,7 +761,16 @@
static inline wuffs_base__rect_ie_u32 //
wuffs_base__frame_config__bounds(wuffs_base__frame_config* c) {
- return c ? c->private_impl.bounds : ((wuffs_base__rect_ie_u32){});
+ if (c) {
+ return c->private_impl.bounds;
+ }
+
+ wuffs_base__rect_ie_u32 ret;
+ ret.min_incl_x = 0;
+ ret.min_incl_y = 0;
+ ret.max_excl_x = 0;
+ ret.max_excl_y = 0;
+ return ret;
}
static inline uint32_t //
@@ -829,6 +895,17 @@
} wuffs_base__pixel_buffer;
+static inline wuffs_base__pixel_buffer //
+wuffs_base__null_pixel_buffer() {
+ wuffs_base__pixel_buffer ret;
+ ret.pixcfg = wuffs_base__null_pixel_config();
+ ret.private_impl.planes[0] = wuffs_base__null_table_u8();
+ ret.private_impl.planes[1] = wuffs_base__null_table_u8();
+ ret.private_impl.planes[2] = wuffs_base__null_table_u8();
+ ret.private_impl.planes[3] = wuffs_base__null_table_u8();
+ return ret;
+}
+
static inline wuffs_base__status //
wuffs_base__pixel_buffer__set_from_slice(wuffs_base__pixel_buffer* b,
wuffs_base__pixel_config* pixcfg,
@@ -836,7 +913,7 @@
if (!b) {
return wuffs_base__error__bad_receiver;
}
- *b = ((wuffs_base__pixel_buffer){});
+ memset(b, 0, sizeof(*b));
if (!pixcfg) {
return wuffs_base__error__bad_argument;
}
@@ -902,13 +979,10 @@
wuffs_base__table_u8* tab =
&b->private_impl.planes[WUFFS_BASE__PIXEL_FORMAT__INDEXED__COLOR_PLANE];
if ((tab->width == 1024) && (tab->height == 1)) {
- return ((wuffs_base__slice_u8){
- .ptr = tab->ptr,
- .len = 1024,
- });
+ return wuffs_base__make_slice_u8(tab->ptr, 1024);
}
}
- return ((wuffs_base__slice_u8){});
+ return wuffs_base__make_slice_u8(NULL, 0);
}
static inline wuffs_base__pixel_format //
@@ -921,9 +995,16 @@
static inline wuffs_base__table_u8 //
wuffs_base__pixel_buffer__plane(wuffs_base__pixel_buffer* b, uint32_t p) {
- return (b && (p < WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX))
- ? b->private_impl.planes[p]
- : ((wuffs_base__table_u8){});
+ if (b && (p < WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX)) {
+ return b->private_impl.planes[p];
+ }
+
+ wuffs_base__table_u8 ret;
+ ret.ptr = NULL;
+ ret.width = 0;
+ ret.height = 0;
+ ret.stride = 0;
+ return ret;
}
#ifdef __cplusplus
diff --git a/cmd/wuffs-c/internal/cgen/base/io-private.h b/internal/cgen/base/io-private.h
similarity index 90%
rename from cmd/wuffs-c/internal/cgen/base/io-private.h
rename to internal/cgen/base/io-private.h
index 725adf5..088f3ce 100644
--- a/cmd/wuffs-c/internal/cgen/base/io-private.h
+++ b/internal/cgen/base/io-private.h
@@ -74,11 +74,11 @@
return 0;
}
uint8_t* q = p - distance;
- size_t n = io1_w - p;
+ size_t n = (size_t)(io1_w - p);
if ((size_t)(length) > n) {
- length = n;
+ length = (uint32_t)(n);
} else {
- n = length;
+ n = (size_t)(length);
}
// TODO: unrolling by 3 seems best for the std/deflate benchmarks, but that
// is mostly because 3 is the minimum length for the deflate format. This
@@ -138,18 +138,18 @@
uint8_t* iop_w = *ptr_iop_w;
size_t n = length;
if (n > ((size_t)(io1_w - iop_w))) {
- n = io1_w - iop_w;
+ n = (size_t)(io1_w - iop_w);
}
uint8_t* iop_r = *ptr_iop_r;
if (n > ((size_t)(io1_r - iop_r))) {
- n = io1_r - iop_r;
+ n = (size_t)(io1_r - iop_r);
}
if (n > 0) {
memmove(iop_w, iop_r, n);
*ptr_iop_w += n;
*ptr_iop_r += n;
}
- return n;
+ return (uint32_t)(n);
}
static inline uint64_t //
@@ -159,13 +159,13 @@
uint8_t* iop_w = *ptr_iop_w;
size_t n = src.len;
if (n > ((size_t)(io1_w - iop_w))) {
- n = io1_w - iop_w;
+ n = (size_t)(io1_w - iop_w);
}
if (n > 0) {
memmove(iop_w, src.ptr, n);
*ptr_iop_w += n;
}
- return n;
+ return (uint64_t)(n);
}
static inline uint32_t //
@@ -179,13 +179,13 @@
n = length;
}
if (n > ((size_t)(io1_w - iop_w))) {
- n = io1_w - iop_w;
+ n = (size_t)(io1_w - iop_w);
}
if (n > 0) {
memmove(iop_w, src.ptr, n);
*ptr_iop_w += n;
}
- return n;
+ return (uint32_t)(n);
}
static inline wuffs_base__empty_struct //
@@ -205,7 +205,10 @@
o->private_impl.limit = data.ptr + data.len;
*ptr_iop_r = data.ptr;
*ptr_io1_r = data.ptr + data.len;
- return ((wuffs_base__empty_struct){});
+
+ wuffs_base__empty_struct ret;
+ ret.private_impl = 0;
+ return ret;
}
static inline wuffs_base__empty_struct //
@@ -215,13 +218,19 @@
if (o && (((size_t)(o->private_impl.limit - iop_r)) > limit)) {
o->private_impl.limit = iop_r + limit;
}
- return ((wuffs_base__empty_struct){});
+
+ wuffs_base__empty_struct ret;
+ ret.private_impl = 0;
+ return ret;
}
static inline wuffs_base__empty_struct //
wuffs_base__io_reader__set_mark(wuffs_base__io_reader* o, uint8_t* mark) {
o->private_impl.mark = mark;
- return ((wuffs_base__empty_struct){});
+
+ wuffs_base__empty_struct ret;
+ ret.private_impl = 0;
+ return ret;
}
static inline wuffs_base__slice_u8 //
@@ -229,12 +238,9 @@
if (n <= ((size_t)(io1_r - *ptr_iop_r))) {
uint8_t* p = *ptr_iop_r;
*ptr_iop_r += n;
- return ((wuffs_base__slice_u8){
- .ptr = p,
- .len = n,
- });
+ return wuffs_base__make_slice_u8(p, n);
}
- return ((wuffs_base__slice_u8){});
+ return wuffs_base__make_slice_u8(NULL, 0);
}
static inline wuffs_base__empty_struct //
@@ -254,23 +260,22 @@
o->private_impl.limit = data.ptr + data.len;
*ptr_iop_w = data.ptr;
*ptr_io1_w = data.ptr + data.len;
- return ((wuffs_base__empty_struct){});
+
+ wuffs_base__empty_struct ret;
+ ret.private_impl = 0;
+ return ret;
}
static inline wuffs_base__empty_struct //
wuffs_base__io_writer__set_mark(wuffs_base__io_writer* o, uint8_t* mark) {
o->private_impl.mark = mark;
- return ((wuffs_base__empty_struct){});
+
+ wuffs_base__empty_struct ret;
+ ret.private_impl = 0;
+ return ret;
}
// ---------------- I/O (Utility)
-static inline wuffs_base__io_reader //
-wuffs_base__utility__null_io_reader(const wuffs_base__utility* ignored) {
- return ((wuffs_base__io_reader){});
-}
-
-static inline wuffs_base__io_writer //
-wuffs_base__utility__null_io_writer(const wuffs_base__utility* ignored) {
- return ((wuffs_base__io_writer){});
-}
+#define wuffs_base__utility__null_io_reader wuffs_base__null_io_reader
+#define wuffs_base__utility__null_io_writer wuffs_base__null_io_writer
diff --git a/cmd/wuffs-c/internal/cgen/base/io-public.h b/internal/cgen/base/io-public.h
similarity index 72%
rename from cmd/wuffs-c/internal/cgen/base/io-public.h
rename to internal/cgen/base/io-public.h
index a87a7c0..6e9bb58 100644
--- a/cmd/wuffs-c/internal/cgen/base/io-public.h
+++ b/internal/cgen/base/io-public.h
@@ -71,6 +71,68 @@
} wuffs_base__io_buffer;
+static inline wuffs_base__io_buffer //
+wuffs_base__make_io_buffer(wuffs_base__slice_u8 data,
+ wuffs_base__io_buffer_meta meta) {
+ wuffs_base__io_buffer ret;
+ ret.data = data;
+ ret.meta = meta;
+ return ret;
+}
+
+static inline wuffs_base__io_buffer_meta //
+wuffs_base__make_io_buffer_meta(size_t wi,
+ size_t ri,
+ uint64_t pos,
+ bool closed) {
+ wuffs_base__io_buffer_meta ret;
+ ret.wi = wi;
+ ret.ri = ri;
+ ret.pos = pos;
+ ret.closed = closed;
+ return ret;
+}
+
+static inline wuffs_base__io_buffer //
+wuffs_base__null_io_buffer() {
+ wuffs_base__io_buffer ret;
+ ret.data.ptr = NULL;
+ ret.data.len = 0;
+ ret.meta.wi = 0;
+ ret.meta.ri = 0;
+ ret.meta.pos = 0;
+ ret.meta.closed = false;
+ return ret;
+}
+
+static inline wuffs_base__io_buffer_meta //
+wuffs_base__null_io_buffer_meta() {
+ wuffs_base__io_buffer_meta ret;
+ ret.wi = 0;
+ ret.ri = 0;
+ ret.pos = 0;
+ ret.closed = false;
+ return ret;
+}
+
+static inline wuffs_base__io_reader //
+wuffs_base__null_io_reader() {
+ wuffs_base__io_reader ret;
+ ret.private_impl.buf = NULL;
+ ret.private_impl.mark = NULL;
+ ret.private_impl.limit = NULL;
+ return ret;
+}
+
+static inline wuffs_base__io_writer //
+wuffs_base__null_io_writer() {
+ wuffs_base__io_writer ret;
+ ret.private_impl.buf = NULL;
+ ret.private_impl.mark = NULL;
+ ret.private_impl.limit = NULL;
+ return ret;
+}
+
// wuffs_base__io_buffer__compact moves any written but unread bytes to the
// start of the buffer.
static inline void //
@@ -89,15 +151,19 @@
static inline wuffs_base__io_reader //
wuffs_base__io_buffer__reader(wuffs_base__io_buffer* buf) {
- wuffs_base__io_reader ret = ((wuffs_base__io_reader){});
+ wuffs_base__io_reader ret;
ret.private_impl.buf = buf;
+ ret.private_impl.mark = NULL;
+ ret.private_impl.limit = NULL;
return ret;
}
static inline wuffs_base__io_writer //
wuffs_base__io_buffer__writer(wuffs_base__io_buffer* buf) {
- wuffs_base__io_writer ret = ((wuffs_base__io_writer){});
+ wuffs_base__io_writer ret;
ret.private_impl.buf = buf;
+ ret.private_impl.mark = NULL;
+ ret.private_impl.limit = NULL;
return ret;
}
diff --git a/cmd/wuffs-c/internal/cgen/base/memory-private.h b/internal/cgen/base/memory-private.h
similarity index 100%
rename from cmd/wuffs-c/internal/cgen/base/memory-private.h
rename to internal/cgen/base/memory-private.h
diff --git a/cmd/wuffs-c/internal/cgen/base/memory-public.h b/internal/cgen/base/memory-public.h
similarity index 80%
rename from cmd/wuffs-c/internal/cgen/base/memory-public.h
rename to internal/cgen/base/memory-public.h
index fbf0e05..03b73c9 100644
--- a/cmd/wuffs-c/internal/cgen/base/memory-public.h
+++ b/internal/cgen/base/memory-public.h
@@ -34,13 +34,10 @@
if (malloc_func && (num_u8 <= (SIZE_MAX / sizeof(uint8_t)))) {
void* p = (*malloc_func)(num_u8 * sizeof(uint8_t));
if (p) {
- return ((wuffs_base__slice_u8){
- .ptr = (uint8_t*)(p),
- .len = num_u8,
- });
+ return wuffs_base__make_slice_u8((uint8_t*)(p), num_u8);
}
}
- return ((wuffs_base__slice_u8){});
+ return wuffs_base__make_slice_u8(NULL, 0);
}
static inline wuffs_base__slice_u16 //
@@ -48,13 +45,10 @@
if (malloc_func && (num_u16 <= (SIZE_MAX / sizeof(uint16_t)))) {
void* p = (*malloc_func)(num_u16 * sizeof(uint16_t));
if (p) {
- return ((wuffs_base__slice_u16){
- .ptr = (uint16_t*)(p),
- .len = num_u16,
- });
+ return wuffs_base__make_slice_u16((uint16_t*)(p), num_u16);
}
}
- return ((wuffs_base__slice_u16){});
+ return wuffs_base__make_slice_u16(NULL, 0);
}
static inline wuffs_base__slice_u32 //
@@ -62,13 +56,10 @@
if (malloc_func && (num_u32 <= (SIZE_MAX / sizeof(uint32_t)))) {
void* p = (*malloc_func)(num_u32 * sizeof(uint32_t));
if (p) {
- return ((wuffs_base__slice_u32){
- .ptr = (uint32_t*)(p),
- .len = num_u32,
- });
+ return wuffs_base__make_slice_u32((uint32_t*)(p), num_u32);
}
}
- return ((wuffs_base__slice_u32){});
+ return wuffs_base__make_slice_u32(NULL, 0);
}
static inline wuffs_base__slice_u64 //
@@ -76,11 +67,8 @@
if (malloc_func && (num_u64 <= (SIZE_MAX / sizeof(uint64_t)))) {
void* p = (*malloc_func)(num_u64 * sizeof(uint64_t));
if (p) {
- return ((wuffs_base__slice_u64){
- .ptr = (uint64_t*)(p),
- .len = num_u64,
- });
+ return wuffs_base__make_slice_u64((uint64_t*)(p), num_u64);
}
}
- return ((wuffs_base__slice_u64){});
+ return wuffs_base__make_slice_u64(NULL, 0);
}
diff --git a/internal/cgen/base/range-private.h b/internal/cgen/base/range-private.h
new file mode 100644
index 0000000..fc86180
--- /dev/null
+++ b/internal/cgen/base/range-private.h
@@ -0,0 +1,67 @@
+// After editing this file, run "go generate" in the parent directory.
+
+// Copyright 2017 The Wuffs Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// ---------------- Ranges and Rects
+
+static inline uint32_t //
+wuffs_base__range_ii_u32__get_min_incl(const wuffs_base__range_ii_u32* r) {
+ return r->min_incl;
+}
+
+static inline uint32_t //
+wuffs_base__range_ii_u32__get_max_incl(const wuffs_base__range_ii_u32* r) {
+ return r->max_incl;
+}
+
+static inline uint32_t //
+wuffs_base__range_ie_u32__get_min_incl(const wuffs_base__range_ie_u32* r) {
+ return r->min_incl;
+}
+
+static inline uint32_t //
+wuffs_base__range_ie_u32__get_max_excl(const wuffs_base__range_ie_u32* r) {
+ return r->max_excl;
+}
+
+static inline uint64_t //
+wuffs_base__range_ii_u64__get_min_incl(const wuffs_base__range_ii_u64* r) {
+ return r->min_incl;
+}
+
+static inline uint64_t //
+wuffs_base__range_ii_u64__get_max_incl(const wuffs_base__range_ii_u64* r) {
+ return r->max_incl;
+}
+
+static inline uint64_t //
+wuffs_base__range_ie_u64__get_min_incl(const wuffs_base__range_ie_u64* r) {
+ return r->min_incl;
+}
+
+static inline uint64_t //
+wuffs_base__range_ie_u64__get_max_excl(const wuffs_base__range_ie_u64* r) {
+ return r->max_excl;
+}
+
+// ---------------- Ranges and Rects (Utility)
+
+#define wuffs_base__utility__make_range_ii_u32 wuffs_base__make_range_ii_u32
+#define wuffs_base__utility__make_range_ie_u32 wuffs_base__make_range_ie_u32
+#define wuffs_base__utility__make_range_ii_u64 wuffs_base__make_range_ii_u64
+#define wuffs_base__utility__make_range_ie_u64 wuffs_base__make_range_ie_u64
+#define wuffs_base__utility__make_rect_ii_u32 wuffs_base__make_rect_ii_u32
+#define wuffs_base__utility__make_rect_ie_u32 wuffs_base__make_rect_ie_u32
+
diff --git a/cmd/wuffs-c/internal/cgen/base/range-public.h b/internal/cgen/base/range-public.h
similarity index 81%
rename from cmd/wuffs-c/internal/cgen/base/range-public.h
rename to internal/cgen/base/range-public.h
index 2071d9c..69d6ecb 100644
--- a/cmd/wuffs-c/internal/cgen/base/range-public.h
+++ b/internal/cgen/base/range-public.h
@@ -54,15 +54,24 @@
#ifdef __cplusplus
inline bool is_empty();
inline bool equals(wuffs_base__range_ii_u32__struct s);
- inline bool contains(uint32_t x);
inline wuffs_base__range_ii_u32__struct intersect(
wuffs_base__range_ii_u32__struct s);
inline wuffs_base__range_ii_u32__struct unite(
wuffs_base__range_ii_u32__struct s);
+ inline bool contains(uint32_t x);
+ inline bool contains_range(wuffs_base__range_ii_u32__struct s);
#endif // __cplusplus
} wuffs_base__range_ii_u32;
+static inline wuffs_base__range_ii_u32 //
+wuffs_base__make_range_ii_u32(uint32_t min_incl, uint32_t max_incl) {
+ wuffs_base__range_ii_u32 ret;
+ ret.min_incl = min_incl;
+ ret.max_incl = max_incl;
+ return ret;
+}
+
static inline bool //
wuffs_base__range_ii_u32__is_empty(wuffs_base__range_ii_u32* r) {
return r->min_incl > r->max_incl;
@@ -76,25 +85,18 @@
wuffs_base__range_ii_u32__is_empty(&s));
}
-static inline bool //
-wuffs_base__range_ii_u32__contains(wuffs_base__range_ii_u32* r, uint32_t x) {
- return (r->min_incl <= x) && (x <= r->max_incl);
-}
-
-static inline //
- wuffs_base__range_ii_u32
- wuffs_base__range_ii_u32__intersect(wuffs_base__range_ii_u32* r,
- wuffs_base__range_ii_u32 s) {
+static inline wuffs_base__range_ii_u32 //
+wuffs_base__range_ii_u32__intersect(wuffs_base__range_ii_u32* r,
+ wuffs_base__range_ii_u32 s) {
wuffs_base__range_ii_u32 t;
t.min_incl = wuffs_base__u32__max(r->min_incl, s.min_incl);
t.max_incl = wuffs_base__u32__min(r->max_incl, s.max_incl);
return t;
}
-static inline //
- wuffs_base__range_ii_u32
- wuffs_base__range_ii_u32__unite(wuffs_base__range_ii_u32* r,
- wuffs_base__range_ii_u32 s) {
+static inline wuffs_base__range_ii_u32 //
+wuffs_base__range_ii_u32__unite(wuffs_base__range_ii_u32* r,
+ wuffs_base__range_ii_u32 s) {
if (wuffs_base__range_ii_u32__is_empty(r)) {
return s;
}
@@ -107,6 +109,18 @@
return t;
}
+static inline bool //
+wuffs_base__range_ii_u32__contains(wuffs_base__range_ii_u32* r, uint32_t x) {
+ return (r->min_incl <= x) && (x <= r->max_incl);
+}
+
+static inline bool //
+wuffs_base__range_ii_u32__contains_range(wuffs_base__range_ii_u32* r,
+ wuffs_base__range_ii_u32 s) {
+ return wuffs_base__range_ii_u32__equals(
+ &s, wuffs_base__range_ii_u32__intersect(r, s));
+}
+
#ifdef __cplusplus
inline bool //
@@ -119,11 +133,6 @@
return wuffs_base__range_ii_u32__equals(this, s);
}
-inline bool //
-wuffs_base__range_ii_u32::contains(uint32_t x) {
- return wuffs_base__range_ii_u32__contains(this, x);
-}
-
inline wuffs_base__range_ii_u32 //
wuffs_base__range_ii_u32::intersect(wuffs_base__range_ii_u32 s) {
return wuffs_base__range_ii_u32__intersect(this, s);
@@ -134,6 +143,16 @@
return wuffs_base__range_ii_u32__unite(this, s);
}
+inline bool //
+wuffs_base__range_ii_u32::contains(uint32_t x) {
+ return wuffs_base__range_ii_u32__contains(this, x);
+}
+
+inline bool //
+wuffs_base__range_ii_u32::contains_range(wuffs_base__range_ii_u32 s) {
+ return wuffs_base__range_ii_u32__contains_range(this, s);
+}
+
#endif // __cplusplus
// --------
@@ -145,16 +164,25 @@
#ifdef __cplusplus
inline bool is_empty();
inline bool equals(wuffs_base__range_ie_u32__struct s);
- inline bool contains(uint32_t x);
inline wuffs_base__range_ie_u32__struct intersect(
wuffs_base__range_ie_u32__struct s);
inline wuffs_base__range_ie_u32__struct unite(
wuffs_base__range_ie_u32__struct s);
+ inline bool contains(uint32_t x);
+ inline bool contains_range(wuffs_base__range_ie_u32__struct s);
inline uint32_t length();
#endif // __cplusplus
} wuffs_base__range_ie_u32;
+static inline wuffs_base__range_ie_u32 //
+wuffs_base__make_range_ie_u32(uint32_t min_incl, uint32_t max_excl) {
+ wuffs_base__range_ie_u32 ret;
+ ret.min_incl = min_incl;
+ ret.max_excl = max_excl;
+ return ret;
+}
+
static inline bool //
wuffs_base__range_ie_u32__is_empty(wuffs_base__range_ie_u32* r) {
return r->min_incl >= r->max_excl;
@@ -168,11 +196,6 @@
wuffs_base__range_ie_u32__is_empty(&s));
}
-static inline bool //
-wuffs_base__range_ie_u32__contains(wuffs_base__range_ie_u32* r, uint32_t x) {
- return (r->min_incl <= x) && (x < r->max_excl);
-}
-
static inline wuffs_base__range_ie_u32 //
wuffs_base__range_ie_u32__intersect(wuffs_base__range_ie_u32* r,
wuffs_base__range_ie_u32 s) {
@@ -197,6 +220,18 @@
return t;
}
+static inline bool //
+wuffs_base__range_ie_u32__contains(wuffs_base__range_ie_u32* r, uint32_t x) {
+ return (r->min_incl <= x) && (x < r->max_excl);
+}
+
+static inline bool //
+wuffs_base__range_ie_u32__contains_range(wuffs_base__range_ie_u32* r,
+ wuffs_base__range_ie_u32 s) {
+ return wuffs_base__range_ie_u32__equals(
+ &s, wuffs_base__range_ie_u32__intersect(r, s));
+}
+
static inline uint32_t //
wuffs_base__range_ie_u32__length(wuffs_base__range_ie_u32* r) {
return wuffs_base__u32__sat_sub(r->max_excl, r->min_incl);
@@ -214,11 +249,6 @@
return wuffs_base__range_ie_u32__equals(this, s);
}
-inline bool //
-wuffs_base__range_ie_u32::contains(uint32_t x) {
- return wuffs_base__range_ie_u32__contains(this, x);
-}
-
inline wuffs_base__range_ie_u32 //
wuffs_base__range_ie_u32::intersect(wuffs_base__range_ie_u32 s) {
return wuffs_base__range_ie_u32__intersect(this, s);
@@ -229,6 +259,16 @@
return wuffs_base__range_ie_u32__unite(this, s);
}
+inline bool //
+wuffs_base__range_ie_u32::contains(uint32_t x) {
+ return wuffs_base__range_ie_u32__contains(this, x);
+}
+
+inline bool //
+wuffs_base__range_ie_u32::contains_range(wuffs_base__range_ie_u32 s) {
+ return wuffs_base__range_ie_u32__contains_range(this, s);
+}
+
inline uint32_t //
wuffs_base__range_ie_u32::length() {
return wuffs_base__range_ie_u32__length(this);
@@ -245,15 +285,24 @@
#ifdef __cplusplus
inline bool is_empty();
inline bool equals(wuffs_base__range_ii_u64__struct s);
- inline bool contains(uint64_t x);
inline wuffs_base__range_ii_u64__struct intersect(
wuffs_base__range_ii_u64__struct s);
inline wuffs_base__range_ii_u64__struct unite(
wuffs_base__range_ii_u64__struct s);
+ inline bool contains(uint64_t x);
+ inline bool contains_range(wuffs_base__range_ii_u64__struct s);
#endif // __cplusplus
} wuffs_base__range_ii_u64;
+static inline wuffs_base__range_ii_u64 //
+wuffs_base__make_range_ii_u64(uint64_t min_incl, uint64_t max_incl) {
+ wuffs_base__range_ii_u64 ret;
+ ret.min_incl = min_incl;
+ ret.max_incl = max_incl;
+ return ret;
+}
+
static inline bool //
wuffs_base__range_ii_u64__is_empty(wuffs_base__range_ii_u64* r) {
return r->min_incl > r->max_incl;
@@ -267,11 +316,6 @@
wuffs_base__range_ii_u64__is_empty(&s));
}
-static inline bool //
-wuffs_base__range_ii_u64__contains(wuffs_base__range_ii_u64* r, uint64_t x) {
- return (r->min_incl <= x) && (x <= r->max_incl);
-}
-
static inline wuffs_base__range_ii_u64 //
wuffs_base__range_ii_u64__intersect(wuffs_base__range_ii_u64* r,
wuffs_base__range_ii_u64 s) {
@@ -296,6 +340,18 @@
return t;
}
+static inline bool //
+wuffs_base__range_ii_u64__contains(wuffs_base__range_ii_u64* r, uint64_t x) {
+ return (r->min_incl <= x) && (x <= r->max_incl);
+}
+
+static inline bool //
+wuffs_base__range_ii_u64__contains_range(wuffs_base__range_ii_u64* r,
+ wuffs_base__range_ii_u64 s) {
+ return wuffs_base__range_ii_u64__equals(
+ &s, wuffs_base__range_ii_u64__intersect(r, s));
+}
+
#ifdef __cplusplus
inline bool //
@@ -308,11 +364,6 @@
return wuffs_base__range_ii_u64__equals(this, s);
}
-inline bool //
-wuffs_base__range_ii_u64::contains(uint64_t x) {
- return wuffs_base__range_ii_u64__contains(this, x);
-}
-
inline wuffs_base__range_ii_u64 //
wuffs_base__range_ii_u64::intersect(wuffs_base__range_ii_u64 s) {
return wuffs_base__range_ii_u64__intersect(this, s);
@@ -323,6 +374,16 @@
return wuffs_base__range_ii_u64__unite(this, s);
}
+inline bool //
+wuffs_base__range_ii_u64::contains(uint64_t x) {
+ return wuffs_base__range_ii_u64__contains(this, x);
+}
+
+inline bool //
+wuffs_base__range_ii_u64::contains_range(wuffs_base__range_ii_u64 s) {
+ return wuffs_base__range_ii_u64__contains_range(this, s);
+}
+
#endif // __cplusplus
// --------
@@ -334,16 +395,25 @@
#ifdef __cplusplus
inline bool is_empty();
inline bool equals(wuffs_base__range_ie_u64__struct s);
- inline bool contains(uint64_t x);
inline wuffs_base__range_ie_u64__struct intersect(
wuffs_base__range_ie_u64__struct s);
inline wuffs_base__range_ie_u64__struct unite(
wuffs_base__range_ie_u64__struct s);
+ inline bool contains(uint64_t x);
+ inline bool contains_range(wuffs_base__range_ie_u64__struct s);
inline uint64_t length();
#endif // __cplusplus
} wuffs_base__range_ie_u64;
+static inline wuffs_base__range_ie_u64 //
+wuffs_base__make_range_ie_u64(uint64_t min_incl, uint64_t max_excl) {
+ wuffs_base__range_ie_u64 ret;
+ ret.min_incl = min_incl;
+ ret.max_excl = max_excl;
+ return ret;
+}
+
static inline bool //
wuffs_base__range_ie_u64__is_empty(wuffs_base__range_ie_u64* r) {
return r->min_incl >= r->max_excl;
@@ -357,11 +427,6 @@
wuffs_base__range_ie_u64__is_empty(&s));
}
-static inline bool //
-wuffs_base__range_ie_u64__contains(wuffs_base__range_ie_u64* r, uint64_t x) {
- return (r->min_incl <= x) && (x < r->max_excl);
-}
-
static inline wuffs_base__range_ie_u64 //
wuffs_base__range_ie_u64__intersect(wuffs_base__range_ie_u64* r,
wuffs_base__range_ie_u64 s) {
@@ -386,6 +451,18 @@
return t;
}
+static inline bool //
+wuffs_base__range_ie_u64__contains(wuffs_base__range_ie_u64* r, uint64_t x) {
+ return (r->min_incl <= x) && (x < r->max_excl);
+}
+
+static inline bool //
+wuffs_base__range_ie_u64__contains_range(wuffs_base__range_ie_u64* r,
+ wuffs_base__range_ie_u64 s) {
+ return wuffs_base__range_ie_u64__equals(
+ &s, wuffs_base__range_ie_u64__intersect(r, s));
+}
+
static inline uint64_t //
wuffs_base__range_ie_u64__length(wuffs_base__range_ie_u64* r) {
return wuffs_base__u64__sat_sub(r->max_excl, r->min_incl);
@@ -403,11 +480,6 @@
return wuffs_base__range_ie_u64__equals(this, s);
}
-inline bool //
-wuffs_base__range_ie_u64::contains(uint64_t x) {
- return wuffs_base__range_ie_u64__contains(this, x);
-}
-
inline wuffs_base__range_ie_u64 //
wuffs_base__range_ie_u64::intersect(wuffs_base__range_ie_u64 s) {
return wuffs_base__range_ie_u64__intersect(this, s);
@@ -418,6 +490,16 @@
return wuffs_base__range_ie_u64__unite(this, s);
}
+inline bool //
+wuffs_base__range_ie_u64::contains(uint64_t x) {
+ return wuffs_base__range_ie_u64__contains(this, x);
+}
+
+inline bool //
+wuffs_base__range_ie_u64::contains_range(wuffs_base__range_ie_u64 s) {
+ return wuffs_base__range_ie_u64__contains_range(this, s);
+}
+
inline uint64_t //
wuffs_base__range_ie_u64::length() {
return wuffs_base__range_ie_u64__length(this);
@@ -445,15 +527,29 @@
#ifdef __cplusplus
inline bool is_empty();
inline bool equals(wuffs_base__rect_ii_u32__struct s);
- inline bool contains(uint32_t x, uint32_t y);
inline wuffs_base__rect_ii_u32__struct intersect(
wuffs_base__rect_ii_u32__struct s);
inline wuffs_base__rect_ii_u32__struct unite(
wuffs_base__rect_ii_u32__struct s);
+ inline bool contains(uint32_t x, uint32_t y);
+ inline bool contains_rect(wuffs_base__rect_ii_u32__struct s);
#endif // __cplusplus
} wuffs_base__rect_ii_u32;
+static inline wuffs_base__rect_ii_u32 //
+wuffs_base__make_rect_ii_u32(uint32_t min_incl_x,
+ uint32_t min_incl_y,
+ uint32_t max_incl_x,
+ uint32_t max_incl_y) {
+ wuffs_base__rect_ii_u32 ret;
+ ret.min_incl_x = min_incl_x;
+ ret.min_incl_y = min_incl_y;
+ ret.max_incl_x = max_incl_x;
+ ret.max_incl_y = max_incl_y;
+ return ret;
+}
+
static inline bool //
wuffs_base__rect_ii_u32__is_empty(wuffs_base__rect_ii_u32* r) {
return (r->min_incl_x > r->max_incl_x) || (r->min_incl_y > r->max_incl_y);
@@ -468,14 +564,6 @@
wuffs_base__rect_ii_u32__is_empty(&s));
}
-static inline bool //
-wuffs_base__rect_ii_u32__contains(wuffs_base__rect_ii_u32* r,
- uint32_t x,
- uint32_t y) {
- return (r->min_incl_x <= x) && (x <= r->max_incl_x) && (r->min_incl_y <= y) &&
- (y <= r->max_incl_y);
-}
-
static inline wuffs_base__rect_ii_u32 //
wuffs_base__rect_ii_u32__intersect(wuffs_base__rect_ii_u32* r,
wuffs_base__rect_ii_u32 s) {
@@ -504,6 +592,21 @@
return t;
}
+static inline bool //
+wuffs_base__rect_ii_u32__contains(wuffs_base__rect_ii_u32* r,
+ uint32_t x,
+ uint32_t y) {
+ return (r->min_incl_x <= x) && (x <= r->max_incl_x) && (r->min_incl_y <= y) &&
+ (y <= r->max_incl_y);
+}
+
+static inline bool //
+wuffs_base__rect_ii_u32__contains_rect(wuffs_base__rect_ii_u32* r,
+ wuffs_base__rect_ii_u32 s) {
+ return wuffs_base__rect_ii_u32__equals(
+ &s, wuffs_base__rect_ii_u32__intersect(r, s));
+}
+
#ifdef __cplusplus
inline bool //
@@ -516,11 +619,6 @@
return wuffs_base__rect_ii_u32__equals(this, s);
}
-inline bool //
-wuffs_base__rect_ii_u32::contains(uint32_t x, uint32_t y) {
- return wuffs_base__rect_ii_u32__contains(this, x, y);
-}
-
inline wuffs_base__rect_ii_u32 //
wuffs_base__rect_ii_u32::intersect(wuffs_base__rect_ii_u32 s) {
return wuffs_base__rect_ii_u32__intersect(this, s);
@@ -531,6 +629,16 @@
return wuffs_base__rect_ii_u32__unite(this, s);
}
+inline bool //
+wuffs_base__rect_ii_u32::contains(uint32_t x, uint32_t y) {
+ return wuffs_base__rect_ii_u32__contains(this, x, y);
+}
+
+inline bool //
+wuffs_base__rect_ii_u32::contains_rect(wuffs_base__rect_ii_u32 s) {
+ return wuffs_base__rect_ii_u32__contains_rect(this, s);
+}
+
#endif // __cplusplus
// --------
@@ -554,17 +662,31 @@
#ifdef __cplusplus
inline bool is_empty();
inline bool equals(wuffs_base__rect_ie_u32__struct s);
- inline bool contains(uint32_t x, uint32_t y);
inline wuffs_base__rect_ie_u32__struct intersect(
wuffs_base__rect_ie_u32__struct s);
inline wuffs_base__rect_ie_u32__struct unite(
wuffs_base__rect_ie_u32__struct s);
+ inline bool contains(uint32_t x, uint32_t y);
+ inline bool contains_rect(wuffs_base__rect_ie_u32__struct s);
inline uint32_t width();
inline uint32_t height();
#endif // __cplusplus
} wuffs_base__rect_ie_u32;
+static inline wuffs_base__rect_ie_u32 //
+wuffs_base__make_rect_ie_u32(uint32_t min_incl_x,
+ uint32_t min_incl_y,
+ uint32_t max_excl_x,
+ uint32_t max_excl_y) {
+ wuffs_base__rect_ie_u32 ret;
+ ret.min_incl_x = min_incl_x;
+ ret.min_incl_y = min_incl_y;
+ ret.max_excl_x = max_excl_x;
+ ret.max_excl_y = max_excl_y;
+ return ret;
+}
+
static inline bool //
wuffs_base__rect_ie_u32__is_empty(wuffs_base__rect_ie_u32* r) {
return (r->min_incl_x >= r->max_excl_x) || (r->min_incl_y >= r->max_excl_y);
@@ -579,14 +701,6 @@
wuffs_base__rect_ie_u32__is_empty(&s));
}
-static inline bool //
-wuffs_base__rect_ie_u32__contains(wuffs_base__rect_ie_u32* r,
- uint32_t x,
- uint32_t y) {
- return (r->min_incl_x <= x) && (x < r->max_excl_x) && (r->min_incl_y <= y) &&
- (y < r->max_excl_y);
-}
-
static inline wuffs_base__rect_ie_u32 //
wuffs_base__rect_ie_u32__intersect(wuffs_base__rect_ie_u32* r,
wuffs_base__rect_ie_u32 s) {
@@ -615,6 +729,21 @@
return t;
}
+static inline bool //
+wuffs_base__rect_ie_u32__contains(wuffs_base__rect_ie_u32* r,
+ uint32_t x,
+ uint32_t y) {
+ return (r->min_incl_x <= x) && (x < r->max_excl_x) && (r->min_incl_y <= y) &&
+ (y < r->max_excl_y);
+}
+
+static inline bool //
+wuffs_base__rect_ie_u32__contains_rect(wuffs_base__rect_ie_u32* r,
+ wuffs_base__rect_ie_u32 s) {
+ return wuffs_base__rect_ie_u32__equals(
+ &s, wuffs_base__rect_ie_u32__intersect(r, s));
+}
+
static inline uint32_t //
wuffs_base__rect_ie_u32__width(wuffs_base__rect_ie_u32* r) {
return wuffs_base__u32__sat_sub(r->max_excl_x, r->min_incl_x);
@@ -637,11 +766,6 @@
return wuffs_base__rect_ie_u32__equals(this, s);
}
-inline bool //
-wuffs_base__rect_ie_u32::contains(uint32_t x, uint32_t y) {
- return wuffs_base__rect_ie_u32__contains(this, x, y);
-}
-
inline wuffs_base__rect_ie_u32 //
wuffs_base__rect_ie_u32::intersect(wuffs_base__rect_ie_u32 s) {
return wuffs_base__rect_ie_u32__intersect(this, s);
@@ -652,6 +776,16 @@
return wuffs_base__rect_ie_u32__unite(this, s);
}
+inline bool //
+wuffs_base__rect_ie_u32::contains(uint32_t x, uint32_t y) {
+ return wuffs_base__rect_ie_u32__contains(this, x, y);
+}
+
+inline bool //
+wuffs_base__rect_ie_u32::contains_rect(wuffs_base__rect_ie_u32 s) {
+ return wuffs_base__rect_ie_u32__contains_rect(this, s);
+}
+
inline uint32_t //
wuffs_base__rect_ie_u32::width() {
return wuffs_base__rect_ie_u32__width(this);
diff --git a/cmd/wuffs-c/internal/cgen/builtin.go b/internal/cgen/builtin.go
similarity index 91%
rename from cmd/wuffs-c/internal/cgen/builtin.go
rename to internal/cgen/builtin.go
index 23a2477..636637e 100644
--- a/cmd/wuffs-c/internal/cgen/builtin.go
+++ b/internal/cgen/builtin.go
@@ -40,21 +40,39 @@
switch recvTyp.Decorator() {
case 0:
// No-op.
+
case t.IDNptr, t.IDPtr:
- // TODO: don't hard-code set.
- if method.Ident() != t.IDSet {
+ u64ToFlicksIndex := -1
+
+ // TODO: don't hard-code these, or a_dst.
+ switch meth := method.Ident(); {
+ case (meth == t.IDSet) && (recvTyp.Inner().QID() == t.QID{t.IDBase, t.IDImageConfig}):
+ b.writes("wuffs_base__image_config__set(a_dst")
+ case (meth == t.IDUpdate) && (recvTyp.Inner().QID() == t.QID{t.IDBase, t.IDFrameConfig}):
+ b.writes("wuffs_base__frame_config__update(a_dst")
+ u64ToFlicksIndex = 1
+ default:
return errNoSuchBuiltin
}
- // TODO: don't hard-code a_dst.
- b.printf("wuffs_base__image_config__set(a_dst")
- for _, o := range n.Args() {
+
+ for i, o := range n.Args() {
b.writeb(',')
+ if i == u64ToFlicksIndex {
+ if o.AsArg().Name().Str(g.tm) != "duration" {
+ return errors.New("cgen: internal error: inconsistent frame_config.update argument")
+ }
+ b.writes("((wuffs_base__flicks)(")
+ }
if err := g.writeExpr(b, o.AsArg().Value(), depth); err != nil {
return err
}
+ if i == u64ToFlicksIndex {
+ b.writes("))")
+ }
}
- b.printf(")")
+ b.writeb(')')
return nil
+
case t.IDSlice:
return g.writeBuiltinSlice(b, recv, method.Ident(), n.Args(), depth)
case t.IDTable:
@@ -119,7 +137,7 @@
// TODO: don't hard-code the recv being a_src.
switch method {
case t.IDUndoByte:
- b.writes("(iop_a_src--, wuffs_base__return_empty_struct())")
+ b.writes("(iop_a_src--, wuffs_base__make_empty_struct())")
return nil
case t.IDCanUndoByte:
@@ -128,7 +146,7 @@
case t.IDPosition:
b.printf("(a_src.private_impl.buf ? wuffs_base__u64__sat_add(" +
- "a_src.private_impl.buf->meta.pos, iop_a_src - a_src.private_impl.buf->data.ptr) : 0)")
+ "a_src.private_impl.buf->meta.pos, ((uint64_t)(iop_a_src - a_src.private_impl.buf->data.ptr))) : 0)")
return nil
case t.IDSetLimit:
@@ -147,14 +165,11 @@
}
if method == t.IDSinceMark {
- b.printf("((wuffs_base__slice_u8){ "+
- ".ptr = %s%s.private_impl.mark, "+
- ".len = (size_t)(",
- prefix, name)
+ b.printf("wuffs_base__make_slice_u8(%s%s.private_impl.mark, (size_t)(", prefix, name)
}
b.printf("iop_%s%s - %s%s.private_impl.mark", prefix, name, prefix, name)
if method == t.IDSinceMark {
- b.writes("), })")
+ b.writes("))")
}
return nil
@@ -167,7 +182,7 @@
if err := g.writeExpr(b, args[0].AsArg().Value(), depth); err != nil {
return err
}
- b.writes(", wuffs_base__return_empty_struct())")
+ b.writes(", wuffs_base__make_empty_struct())")
return nil
case t.IDTake:
@@ -250,14 +265,11 @@
}
if method == t.IDSinceMark {
- b.printf("((wuffs_base__slice_u8){ "+
- ".ptr = %s%s.private_impl.mark, "+
- ".len = (size_t)(",
- prefix, name)
+ b.printf("wuffs_base__make_slice_u8(%s%s.private_impl.mark, (size_t)(", prefix, name)
}
b.printf("iop_%s%s - %s%s.private_impl.mark", prefix, name, prefix, name)
if method == t.IDSinceMark {
- b.writes("), })")
+ b.writes("))")
}
return nil
}
@@ -274,7 +286,7 @@
if err := g.writeExpr(b, args[0].AsArg().Value(), depth); err != nil {
return err
}
- b.printf("), iop_a_dst += %d, wuffs_base__return_empty_struct())", p.n/8)
+ b.printf("), iop_a_dst += %d, wuffs_base__make_empty_struct())", p.n/8)
return nil
}
}
@@ -443,6 +455,9 @@
if err := g.writeExpr(b, foo, depth); err != nil {
return err
}
+ if foo.MType().IsSliceType() {
+ b.writes(".ptr")
+ }
if fIndex != nil {
b.writes(")+(")
if err := g.writeExpr(b, fIndex, depth); err != nil {
@@ -453,6 +468,9 @@
if err := g.writeExpr(b, bar, depth); err != nil {
return err
}
+ if bar.MType().IsSliceType() {
+ b.writes(".ptr")
+ }
if bIndex != nil {
b.writes(")+(")
if err := g.writeExpr(b, bIndex, depth); err != nil {
@@ -586,8 +604,8 @@
g.currFunk.usesScratch = true
// TODO: don't hard-code [0], and allow recursive coroutines.
- scratchName := fmt.Sprintf("self->private_impl.%s%s[0].scratch",
- cPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
+ scratchName := fmt.Sprintf("self->private_data.%s%s[0].scratch",
+ sPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
b.printf("%s = ", scratchName)
if err := g.writeExpr(b, x, depth); err != nil {
@@ -600,7 +618,7 @@
}
b.printf("if (%s > ((uint64_t)(io1_a_src - iop_a_src))) {\n", scratchName)
- b.printf("%s -= io1_a_src - iop_a_src;\n", scratchName)
+ b.printf("%s -= ((uint64_t)(io1_a_src - iop_a_src));\n", scratchName)
b.printf("iop_a_src = io1_a_src;\n")
b.writes("status = wuffs_base__suspension__short_read; goto suspend; }\n")
@@ -660,8 +678,8 @@
g.currFunk.usesScratch = true
// TODO: don't hard-code [0], and allow recursive coroutines.
- scratchName := fmt.Sprintf("self->private_impl.%s%s[0].scratch",
- cPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
+ scratchName := fmt.Sprintf("self->private_data.%s%s[0].scratch",
+ sPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
b.printf("if (WUFFS_BASE__LIKELY(io1_a_src - iop_a_src >= %d)) {", xx/8)
b.printf("%s%d =", tPrefix, temp)
@@ -686,32 +704,26 @@
preName, preName)
b.printf("uint64_t *scratch = &%s;", scratchName)
- b.printf("uint32_t num_bits_%d = *scratch", temp)
+ b.printf("uint32_t num_bits_%d = ((uint32_t)(*scratch", temp)
switch endianness {
case 'b':
- b.writes("& 0xFF; *scratch >>= 8; *scratch <<= 8;")
+ b.writes("& 0xFF)); *scratch >>= 8; *scratch <<= 8;")
b.printf("*scratch |= ((uint64_t)(*%s%s++)) << (56 - num_bits_%d);",
iopPrefix, preName, temp)
case 'l':
- b.writes(">> 56; *scratch <<= 8; *scratch >>= 8;")
+ b.writes(">> 56)); *scratch <<= 8; *scratch >>= 8;")
b.printf("*scratch |= ((uint64_t)(*%s%s++)) << num_bits_%d;",
iopPrefix, preName, temp)
}
- b.printf("if (num_bits_%d == %d) { %s%d =", temp, xx-8, tPrefix, temp)
- if xx != yy {
- b.printf("((uint%d_t)(", yy)
- }
+ b.printf("if (num_bits_%d == %d) { %s%d = ((uint%d_t)(", temp, xx-8, tPrefix, temp, yy)
switch endianness {
case 'b':
- b.printf("*scratch >> %d", 64-xx)
+ b.printf("*scratch >> %d));", 64-xx)
case 'l':
- b.printf("*scratch")
+ b.printf("*scratch));")
}
- if xx != yy {
- b.writes("))")
- }
- b.printf("; break;")
+ b.printf("break;")
b.printf("}")
b.printf("num_bits_%d += 8;", temp)
diff --git a/cmd/wuffs-c/internal/cgen/cgen.go b/internal/cgen/cgen.go
similarity index 81%
rename from cmd/wuffs-c/internal/cgen/cgen.go
rename to internal/cgen/cgen.go
index 1381f23..52f9b3c 100644
--- a/cmd/wuffs-c/internal/cgen/cgen.go
+++ b/internal/cgen/cgen.go
@@ -44,16 +44,19 @@
sixtyFour = big.NewInt(64)
mibi = big.NewInt(1 << 20)
+
+ typeExprUtility = a.NewTypeExpr(0, t.IDBase, t.IDUtility, nil, nil, nil)
)
// Prefixes are prepended to names to form a namespace and to avoid e.g.
// "double" being a valid Wuffs variable name but not a valid C one.
const (
aPrefix = "a_" // Function argument.
- cPrefix = "c_" // Coroutine state.
fPrefix = "f_" // Struct field.
iPrefix = "i_" // Iterate variable.
oPrefix = "o_" // Temporary io_bind variable.
+ pPrefix = "p_" // Coroutine suspension point (program counter).
+ sPrefix = "s_" // Coroutine stack (saved local variables).
tPrefix = "t_" // Temporary local variable.
uPrefix = "u_" // Derived from a local variable.
vPrefix = "v_" // Local variable.
@@ -125,7 +128,7 @@
pre := "warning"
if msg[0] == '$' {
pre = "suspension"
- } else if msg[0] == '?' {
+ } else if msg[0] == '#' {
pre = "error"
}
b.printf("const char* wuffs_base__%s__%s = \"%sbase: %s\";\n",
@@ -187,7 +190,7 @@
}
func statusMsgIsError(msg string) bool {
- return (len(msg) != 0) && (msg[0] == '?')
+ return (len(msg) != 0) && (msg[0] == '#')
}
func statusMsgIsSuspension(msg string) bool {
@@ -195,7 +198,7 @@
}
func statusMsgIsWarning(msg string) bool {
- return (len(msg) == 0) || (msg[0] != '$' && msg[0] != '?')
+ return (len(msg) == 0) || (msg[0] != '$' && msg[0] != '#')
}
type buffer []byte
@@ -318,10 +321,12 @@
// generated C code (due to line numbers changing) when editing Wuffs code.
genlinenum bool
- statusList []status
- statusMap map[t.QID]status
- structList []*a.Struct
- structMap map[t.QID]*a.Struct
+ privateDataFields map[t.QQID]struct{}
+ scalarConstsMap map[t.QID]*a.Const
+ statusList []status
+ statusMap map[t.QID]status
+ structList []*a.Struct
+ structMap map[t.QID]*a.Struct
currFunk funk
funks map[t.QQID]funk
@@ -350,6 +355,11 @@
}
}
+ g.scalarConstsMap = map[t.QID]*a.Const{}
+ if err := g.forEachConst(b, bothPubPri, (*gen).gatherScalarConsts); err != nil {
+ return nil, err
+ }
+
// Make a topologically sorted list of structs.
unsortedStructs := []*a.Struct(nil)
for _, file := range g.files {
@@ -365,8 +375,16 @@
return nil, fmt.Errorf("cyclical struct definitions")
}
g.structMap = map[t.QID]*a.Struct{}
+ g.privateDataFields = map[t.QQID]struct{}{}
for _, n := range g.structList {
- g.structMap[n.QID()] = n
+ qid := n.QID()
+ g.structMap[qid] = n
+ for _, f := range n.Fields() {
+ f := f.AsField()
+ if f.PrivateData() {
+ g.privateDataFields[t.QQID{qid[0], qid[1], f.Name()}] = struct{}{}
+ }
+ }
}
g.funks = map[t.QQID]funk{}
@@ -461,6 +479,11 @@
}
b.writes("// ---------------- Public Initializer Prototypes\n\n")
+ b.writes("// For any given \"wuffs_foo__bar* self\", \"wuffs_foo__bar__initialize(self,\n")
+ b.writes("// etc)\" should be called before any other \"wuffs_foo__bar__xxx(self, etc)\".\n")
+ b.writes("//\n")
+ b.writes("// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.\n")
+ b.writes("// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for initialize_flags.\n\n")
for _, n := range g.structList {
if n.Public() {
if err := g.writeInitializerPrototype(b, n); err != nil {
@@ -653,7 +676,7 @@
category := "warning__"
if msg[0] == '$' {
category = "suspension__"
- } else if msg[0] == '?' {
+ } else if msg[0] == '#' {
category = "error__"
}
z := status{
@@ -667,17 +690,25 @@
return nil
}
+func (g *gen) gatherScalarConsts(b *buffer, n *a.Const) error {
+ if cv := n.Value().ConstValue(); cv != nil {
+ g.scalarConstsMap[n.QID()] = n
+ }
+ return nil
+}
+
func (g *gen) writeConst(b *buffer, n *a.Const) error {
if n.Public() {
- b.writes("WUFFS_BASE__MAYBE_STATIC ")
- } else {
- b.writes("static ")
+ if cv := n.Value().ConstValue(); cv != nil {
+ b.printf("#define %s %v\n\n", strings.ToUpper(g.pkgPrefix+n.QID()[1].Str(g.tm)), cv)
+ }
}
- b.writes("const ")
- if err := g.writeCTypeName(b, n.XType(), g.pkgPrefix, n.QID()[1].Str(g.tm)); err != nil {
+
+ b.writes("static const ")
+ if err := g.writeCTypeName(b, n.XType(), "//\n"+g.pkgPrefix, n.QID()[1].Str(g.tm)); err != nil {
return err
}
- b.writes(" = ")
+ b.writes("//\n WUFFS_BASE__POTENTIALLY_UNUSED = ")
if err := g.writeConstList(b, n.Value()); err != nil {
return err
}
@@ -704,12 +735,15 @@
}
func (g *gen) writeStructPrivateImpl(b *buffer, n *a.Struct) error {
- b.writes("// Do not access the private_impl's fields directly. There is no API/ABI\n")
- b.writes("// compatibility or safety guarantee if you do so. Instead, use the\n")
- b.writes("// wuffs_foo__bar__baz functions.\n")
+ // TODO: allow max depth > 1 for recursive coroutines.
+ const maxDepth = 1
+
+ b.writes("// Do not access the private_impl's or private_data's fields directly. There\n")
+ b.writes("// is no API/ABI compatibility or safety guarantee if you do so. Instead, use\n")
+ b.writes("// the wuffs_foo__bar__baz functions.\n")
b.writes("//\n")
- b.writes("// It is a struct, not a struct*, so that the outermost wuffs_foo__bar\n")
- b.writes("// struct can be stack allocated when WUFFS_IMPLEMENTATION is defined.\n")
+ b.writes("// It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct\n")
+ b.writes("// can be stack allocated when WUFFS_IMPLEMENTATION is defined.\n\n")
b.writes("struct {\n")
if n.Classy() {
@@ -720,6 +754,9 @@
for _, o := range n.Fields() {
o := o.AsField()
+ if o.PrivateData() || o.XType().Eq(typeExprUtility) {
+ continue
+ }
if err := g.writeCTypeName(b, o.XType(), fPrefix, o.Name().Str(g.tm)); err != nil {
return err
}
@@ -738,14 +775,54 @@
continue
}
k := g.funks[o.QQID()]
+ if k.coroSuspPoint == 0 {
+ continue
+ }
+
+ b.printf("uint32_t %s%s[%d];\n", pPrefix, o.FuncName().Str(g.tm), maxDepth)
+ }
+ }
+
+ }
+ b.writes("} private_impl;\n\n")
+
+ {
+ oldOuterLenB0 := len(*b)
+ b.writes("struct {\n")
+ oldOuterLenB1 := len(*b)
+
+ for _, o := range n.Fields() {
+ o := o.AsField()
+ if !o.PrivateData() || o.XType().Eq(typeExprUtility) {
+ continue
+ }
+ if err := g.writeCTypeName(b, o.XType(), fPrefix, o.Name().Str(g.tm)); err != nil {
+ return err
+ }
+ b.writes(";\n")
+ }
+ if oldOuterLenB1 != len(*b) {
+ b.writeb('\n')
+ }
+
+ for _, file := range g.files {
+ for _, tld := range file.TopLevelDecls() {
+ if tld.Kind() != a.KFunc {
+ continue
+ }
+ o := tld.AsFunc()
+ if o.Receiver() != n.QID() || !o.Effect().Coroutine() {
+ continue
+ }
+ k := g.funks[o.QQID()]
if k.coroSuspPoint == 0 && !k.usesScratch {
continue
}
- // TODO: allow max depth > 1 for recursive coroutines.
- const maxDepth = 1
+
+ oldInnerLenB0 := len(*b)
b.writes("struct {\n")
+ oldInnerLenB1 := len(*b)
if k.coroSuspPoint != 0 {
- b.writes("uint32_t coro_susp_point;\n")
if err := g.writeVars(b, &k, true); err != nil {
return err
}
@@ -753,11 +830,21 @@
if k.usesScratch {
b.writes("uint64_t scratch;\n")
}
- b.printf("} %s%s[%d];\n", cPrefix, o.FuncName().Str(g.tm), maxDepth)
+ if oldInnerLenB1 != len(*b) {
+ b.printf("} %s%s[%d];\n", sPrefix, o.FuncName().Str(g.tm), maxDepth)
+ } else {
+ *b = (*b)[:oldInnerLenB0]
+ }
}
}
+
+ if oldOuterLenB1 != len(*b) {
+ b.writes("} private_data;\n\n")
+ } else {
+ *b = (*b)[:oldOuterLenB0]
+ }
}
- b.writes("} private_impl;\n\n")
+
return nil
}
@@ -786,7 +873,7 @@
b.writes("union {\n")
b.writes("uint32_t align_as_per_magic_field;\n")
b.writes("uint8_t placeholder[1073741824]; // 1 GiB.\n")
- b.writes("} private_impl;\n\n")
+ b.writes("} private_impl WUFFS_BASE__POTENTIALLY_UNUSED_FIELD;\n\n")
b.writes("public:\n")
b.writex(wiEnd)
@@ -808,8 +895,8 @@
// The empty // comment makes clang-format place the function name
// at the start of a line.
b.writes("inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //\n" +
- "check_wuffs_version(size_t sizeof_star_self, uint64_t wuffs_version) {\n")
- b.printf("return %s%s__check_wuffs_version(this, sizeof_star_self, wuffs_version);\n}\n\n",
+ "initialize(size_t sizeof_star_self, uint64_t wuffs_version, uint32_t initialize_flags) {\n")
+ b.printf("return %s%s__initialize(this, sizeof_star_self, wuffs_version, initialize_flags);\n}\n\n",
g.pkgPrefix, structName)
structID := n.QID()[1]
@@ -858,15 +945,8 @@
func (g *gen) writeInitializerSignature(b *buffer, n *a.Struct, public bool) error {
structName := n.QID().Str(g.tm)
- if public {
- b.printf("// %s%s__check_wuffs_version is an initializer function.\n", g.pkgPrefix, structName)
- b.printf("//\n")
- b.printf("// It should be called before any other %s%s__* function.\n", g.pkgPrefix, structName)
- b.printf("//\n")
- b.printf("// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.\n")
- }
b.printf("wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //\n"+
- "%s%s__check_wuffs_version(%s%s *self, size_t sizeof_star_self, uint64_t wuffs_version)",
+ "%s%s__initialize(%s%s *self, size_t sizeof_star_self, uint64_t wuffs_version, uint32_t initialize_flags)",
g.pkgPrefix, structName, g.pkgPrefix, structName)
return nil
}
@@ -884,6 +964,7 @@
return err
}
b.writes(";\n\n")
+
if n.Public() {
if err := g.writeSizeofSignature(b, n); err != nil {
return err
@@ -904,15 +985,36 @@
b.writes("if (!self) { return wuffs_base__error__bad_receiver; }\n")
b.writes("if (sizeof(*self) != sizeof_star_self) {\n")
- b.writes("return wuffs_base__error__bad_sizeof_receiver;\n")
+ b.writes(" return wuffs_base__error__bad_sizeof_receiver;\n")
b.writes("}\n")
b.writes("if (((wuffs_version >> 32) != WUFFS_VERSION_MAJOR) || " +
"(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {\n")
- b.writes("return wuffs_base__error__bad_wuffs_version;\n")
- b.writes("}\n")
- b.writes("if (self->private_impl.magic != 0) {\n")
- b.writes("return wuffs_base__error__check_wuffs_version_not_applicable;\n")
- b.writes("}\n")
+ b.writes(" return wuffs_base__error__bad_wuffs_version;\n")
+ b.writes("}\n\n")
+
+ b.writes("if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {\n")
+ b.writes(" // The whole point of this if-check is to detect an uninitialized *self.\n")
+ b.writes(" // We disable the warning on GCC. Clang-5.0 does not have this warning.\n")
+ b.writes(" #if !defined(__clang__) && defined(__GNUC__)\n")
+ b.writes(" #pragma GCC diagnostic push\n")
+ b.writes(" #pragma GCC diagnostic ignored \"-Wmaybe-uninitialized\"\n")
+ b.writes(" #endif\n")
+ b.writes(" if (self->private_impl.magic != 0) {\n")
+ b.writes(" return wuffs_base__error__initialize_falsely_claimed_already_zeroed;\n")
+ b.writes(" }\n")
+ b.writes(" #if !defined(__clang__) && defined(__GNUC__)\n")
+ b.writes(" #pragma GCC diagnostic pop\n")
+ b.writes(" #endif\n")
+ b.writes("} else {\n")
+ b.writes(" void* p = &(self->private_impl);\n")
+ b.writes(" size_t n = sizeof(self->private_impl);\n")
+ b.writes(" if ((initialize_flags & WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {\n")
+ b.writes(" p = self;\n")
+ b.writes(" n = sizeof(*self);\n")
+ b.writes(" initialize_flags |= WUFFS_INITIALIZE__ALREADY_ZEROED;\n")
+ b.writes(" }\n")
+ b.writes(" memset(p, 0, n);\n")
+ b.writes("}\n\n")
// Call any ctors on sub-structs.
for _, f := range n.Fields() {
@@ -937,8 +1039,8 @@
}
b.printf("{\n")
- b.printf("wuffs_base__status z = %s%s__check_wuffs_version("+
- "&self->private_impl.%s%s, sizeof(self->private_impl.%s%s), WUFFS_VERSION);\n",
+ b.printf("wuffs_base__status z = %s%s__initialize("+
+ "&self->private_data.%s%s, sizeof(self->private_data.%s%s), WUFFS_VERSION, initialize_flags);\n",
prefix, qid[1].Str(g.tm), fPrefix, f.Name().Str(g.tm), fPrefix, f.Name().Str(g.tm))
b.printf("if (z) { return z; }\n")
b.printf("}\n")
@@ -952,7 +1054,7 @@
if err := g.writeSizeofSignature(b, n); err != nil {
return err
}
- b.printf("{ return sizeof((%s%s){}); }\n\n", g.pkgPrefix, n.QID().Str(g.tm))
+ b.printf("{ return sizeof (%s%s); }\n\n", g.pkgPrefix, n.QID().Str(g.tm))
}
return nil
}
diff --git a/internal/cgen/data.go b/internal/cgen/data.go
new file mode 100644
index 0000000..9b91b5e
--- /dev/null
+++ b/internal/cgen/data.go
@@ -0,0 +1,226 @@
+// Code generated by running "go generate". DO NOT EDIT.
+
+// Copyright 2017 The Wuffs Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package cgen
+
+const baseAllImplC = "" +
+ "#ifndef WUFFS_INCLUDE_GUARD__BASE\n#define WUFFS_INCLUDE_GUARD__BASE\n\n#if defined(WUFFS_IMPLEMENTATION) && !defined(WUFFS_CONFIG__MODULES)\n#define WUFFS_CONFIG__MODULES\n#define WUFFS_CONFIG__MODULE__BASE\n#endif\n\n// !! WUFFS MONOLITHIC RELEASE DISCARDS EVERYTHING ABOVE.\n\n// !! INSERT base/copyright\n\n#include <stdbool.h>\n#include <stdint.h>\n#include <string.h>\n\n// GCC does not warn for unused *static inline* functions, but clang does.\n#ifdef __clang__\n#pragma clang diagnostic push\n#pragma clang diagnostic ignored \"-Wunused-function\"\n#endif\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n// !! INSERT base/all-public.h.\n\n#ifdef __cplusplus\n} // extern \"C\"\n#endif\n\n#ifdef __clang__\n#pragma clang diagnostic pop\n#endif\n\n// WUFFS C HEADER ENDS HERE.\n#ifdef WUFFS_IMPLEMENTATION\n\n// GCC does not warn for unused *static inline* functions, but clang does.\n#ifdef __clang__\n#pragma clang diagnostic push\n#pragma clang diagnostic ignored \"-Wunused-function\"\n#endif\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n// !! INSERT base/all-privat" +
+ "e.h.\n\n#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BASE)\n\nconst uint8_t wuffs_base__low_bits_mask__u8[9] = {\n 0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF,\n};\n\nconst uint16_t wuffs_base__low_bits_mask__u16[17] = {\n 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF,\n 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF,\n};\n\nconst uint32_t wuffs_base__low_bits_mask__u32[33] = {\n 0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000F, 0x0000001F,\n 0x0000003F, 0x0000007F, 0x000000FF, 0x000001FF, 0x000003FF, 0x000007FF,\n 0x00000FFF, 0x00001FFF, 0x00003FFF, 0x00007FFF, 0x0000FFFF, 0x0001FFFF,\n 0x0003FFFF, 0x0007FFFF, 0x000FFFFF, 0x001FFFFF, 0x003FFFFF, 0x007FFFFF,\n 0x00FFFFFF, 0x01FFFFFF, 0x03FFFFFF, 0x07FFFFFF, 0x0FFFFFFF, 0x1FFFFFFF,\n 0x3FFFFFFF, 0x7FFFFFFF, 0xFFFFFFFF,\n};\n\nconst uint64_t wuffs_base__low_bits_mask__u64[65] = {\n 0x0000000000000000, 0x0000000000000001, 0x0000000000000003,\n 0x0000000000000007, 0x00000" +
+ "0000000000F, 0x000000000000001F,\n 0x000000000000003F, 0x000000000000007F, 0x00000000000000FF,\n 0x00000000000001FF, 0x00000000000003FF, 0x00000000000007FF,\n 0x0000000000000FFF, 0x0000000000001FFF, 0x0000000000003FFF,\n 0x0000000000007FFF, 0x000000000000FFFF, 0x000000000001FFFF,\n 0x000000000003FFFF, 0x000000000007FFFF, 0x00000000000FFFFF,\n 0x00000000001FFFFF, 0x00000000003FFFFF, 0x00000000007FFFFF,\n 0x0000000000FFFFFF, 0x0000000001FFFFFF, 0x0000000003FFFFFF,\n 0x0000000007FFFFFF, 0x000000000FFFFFFF, 0x000000001FFFFFFF,\n 0x000000003FFFFFFF, 0x000000007FFFFFFF, 0x00000000FFFFFFFF,\n 0x00000001FFFFFFFF, 0x00000003FFFFFFFF, 0x00000007FFFFFFFF,\n 0x0000000FFFFFFFFF, 0x0000001FFFFFFFFF, 0x0000003FFFFFFFFF,\n 0x0000007FFFFFFFFF, 0x000000FFFFFFFFFF, 0x000001FFFFFFFFFF,\n 0x000003FFFFFFFFFF, 0x000007FFFFFFFFFF, 0x00000FFFFFFFFFFF,\n 0x00001FFFFFFFFFFF, 0x00003FFFFFFFFFFF, 0x00007FFFFFFFFFFF,\n 0x0000FFFFFFFFFFFF, 0x0001FFFFFFFFFFFF, 0x0003FFFFFFFFFFFF,\n 0x0007FFFFFFFFFFFF, 0x000FF" +
+ "FFFFFFFFFFF, 0x001FFFFFFFFFFFFF,\n 0x003FFFFFFFFFFFFF, 0x007FFFFFFFFFFFFF, 0x00FFFFFFFFFFFFFF,\n 0x01FFFFFFFFFFFFFF, 0x03FFFFFFFFFFFFFF, 0x07FFFFFFFFFFFFFF,\n 0x0FFFFFFFFFFFFFFF, 0x1FFFFFFFFFFFFFFF, 0x3FFFFFFFFFFFFFFF,\n 0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF,\n};\n\n// !! INSERT wuffs_base__status strings.\n\n// !! INSERT base/image-impl.c.\n\n#endif // !defined(WUFFS_CONFIG__MODULES) ||\n // defined(WUFFS_CONFIG__MODULE__BASE)\n\n#ifdef __cplusplus\n} // extern \"C\"\n#endif\n\n#ifdef __clang__\n#pragma clang diagnostic pop\n#endif\n\n#endif // WUFFS_IMPLEMENTATION\n\n// !! WUFFS MONOLITHIC RELEASE DISCARDS EVERYTHING BELOW.\n\n#endif // WUFFS_INCLUDE_GUARD__BASE\n" +
+ ""
+
+const baseImageImplC = "" +
+ "// ---------------- Images\n\nconst uint32_t wuffs_base__pixel_format__bits_per_channel[16] = {\n 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,\n 0x08, 0x0A, 0x0C, 0x10, 0x18, 0x20, 0x30, 0x40,\n};\n\nstatic uint64_t //\nwuffs_base__pixel_swizzler__copy_1_1(wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src) {\n return wuffs_base__slice_u8__copy_from_slice(dst, src);\n}\n\nstatic uint64_t //\nwuffs_base__pixel_swizzler__copy_4_1(wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src) {\n if (dst_palette.len != 1024) {\n return 0;\n }\n size_t dst_len4 = dst.len / 4;\n size_t len = dst_len4 < src.len ? dst_len4 : src.len;\n uint8_t* d = dst.ptr;\n uint8_t* s = src.ptr;\n\n size_t n = len;\n const int N = 4;\n\n while (n >= N) {\n wuffs_base__store_u32le(\n d + (0 * 4),\n wuffs_base__load_u3" +
+ "2le(dst_palette.ptr + ((uint32_t)(s[0]) * 4)));\n wuffs_base__store_u32le(\n d + (1 * 4),\n wuffs_base__load_u32le(dst_palette.ptr + ((uint32_t)(s[1]) * 4)));\n wuffs_base__store_u32le(\n d + (2 * 4),\n wuffs_base__load_u32le(dst_palette.ptr + ((uint32_t)(s[2]) * 4)));\n wuffs_base__store_u32le(\n d + (3 * 4),\n wuffs_base__load_u32le(dst_palette.ptr + ((uint32_t)(s[3]) * 4)));\n\n s += 1 * N;\n d += 4 * N;\n n -= (size_t)(1 * N);\n }\n\n while (n >= 1) {\n wuffs_base__store_u32le(\n d + (0 * 4),\n wuffs_base__load_u32le(dst_palette.ptr + ((uint32_t)(s[0]) * 4)));\n\n s += 1 * 1;\n d += 4 * 1;\n n -= (size_t)(1 * 1);\n }\n\n return len;\n}\n\nstatic uint64_t //\nwuffs_base__pixel_swizzler__swap_rgbx_bgrx(wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 src) {\n size_t len4 = (dst.len < src.len ? dst.len : src.len) / 4;\n uint8_t* d = dst.ptr;\n uint8_t* s = src.ptr;\n\n size_t n = len4;\n while (n--) {\n uin" +
+ "t8_t b0 = s[0];\n uint8_t b1 = s[1];\n uint8_t b2 = s[2];\n uint8_t b3 = s[3];\n d[0] = b2;\n d[1] = b1;\n d[2] = b0;\n d[3] = b3;\n s += 4;\n d += 4;\n }\n return len4 * 4;\n}\n\nvoid //\nwuffs_base__pixel_swizzler__prepare(wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_format,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__pixel_format src_format,\n wuffs_base__slice_u8 src_palette) {\n if (!p) {\n return;\n }\n\n // TODO: support many more formats.\n\n uint64_t (*func)(wuffs_base__slice_u8 dst, wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src) = NULL;\n\n switch (src_format) {\n case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY:\n switch (dst_format) {\n case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_PREMUL:\n case WUFFS_BASE__PIXEL" +
+ "_FORMAT__INDEXED__BGRA_BINARY:\n if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=\n 1024) {\n break;\n }\n func = wuffs_base__pixel_swizzler__copy_1_1;\n break;\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:\n if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=\n 1024) {\n break;\n }\n func = wuffs_base__pixel_swizzler__copy_4_1;\n break;\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:\n if (wuffs_base__pixel_swizzler__swap_rgbx_bgrx(dst_palette,\n src_palette) != 1024) {\n break;\n }\n func = wuffs_base__pixel_swizzler__copy_4_1;\n break;\n d" +
+ "efault:\n break;\n }\n break;\n\n default:\n break;\n }\n\n p->private_impl.func = func;\n}\n\nuint64_t //\nwuffs_base__pixel_swizzler__swizzle_packed(wuffs_base__pixel_swizzler* p,\n wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src) {\n if (p && p->private_impl.func) {\n return (*(p->private_impl.func))(dst, dst_palette, src);\n }\n return 0;\n}\n" +
+ ""
+
+const baseCorePrivateH = "" +
+ "static inline wuffs_base__empty_struct //\nwuffs_base__ignore_status(wuffs_base__status z) {\n return wuffs_base__make_empty_struct();\n}\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(\"wuffs\").\n#define WUFFS_BASE__MAGIC ((uint32_t)0x3CCB6C71)\n\n// WUFFS_BASE__DISABLED is a magic number to indicate that a non-recoverable\n// error was previously encountered.\n//\n// Its (non-zero) value is arbitrary, based on md5sum(\"disabled\").\n#define WUFFS_BASE__DISABLED ((uint32_t)0x075AE3D2)\n\n// Denote intentional fallthroughs for -Wimplicit-fallthrough.\n//\n// The order matters here. Clang also defines \"__GNUC__\".\n#if defined(__clang__) && defined(__cplusplus) && (__cplusplus >= 201103L)\n#define WUFFS_BASE__FALLTHROUGH [[clang::fallthrough]]\n#elif !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 7)\n#define WUFFS_BAS" +
+ "E__FALLTHROUGH __attribute__((fallthrough))\n#else\n#define WUFFS_BASE__FALLTHROUGH\n#endif\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 WUFFS_BASE__FALLTHROUGH; \\\n case n:;\n\n#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \\\n if (!status) { \\\n goto ok; \\\n } else if (*status != '$') { \\\n goto exit; \\\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// The helpers below are functions, instead of macros, because their arguments\n// can be an expression that we shouldn't evaluate more than once.\n//\n// They are 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\n" +
+ "" +
+ "// ---------------- Numeric Types\n\nstatic inline uint8_t //\nwuffs_base__load_u8be(uint8_t* p) {\n return p[0];\n}\n\nstatic inline uint16_t //\nwuffs_base__load_u16be(uint8_t* p) {\n return (uint16_t)(((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0));\n}\n\nstatic inline uint16_t //\nwuffs_base__load_u16le(uint8_t* p) {\n return (uint16_t)(((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8));\n}\n\nstatic inline uint32_t //\nwuffs_base__load_u24be(uint8_t* p) {\n return ((uint32_t)(p[0]) << 16) | ((uint32_t)(p[1]) << 8) |\n ((uint32_t)(p[2]) << 0);\n}\n\nstatic inline uint32_t //\nwuffs_base__load_u24le(uint8_t* p) {\n return ((uint32_t)(p[0]) << 0) | ((uint32_t)(p[1]) << 8) |\n ((uint32_t)(p[2]) << 16);\n}\n\nstatic inline uint32_t //\nwuffs_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 //\nwuffs_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 uint64_t //\nwuffs_base__load_u40be(uint8_t* p) {\n return ((uint64_t)(p[0]) << 32) | ((uint64_t)(p[1]) << 24) |\n ((uint64_t)(p[2]) << 16) | ((uint64_t)(p[3]) << 8) |\n ((uint64_t)(p[4]) << 0);\n}\n\nstatic inline uint64_t //\nwuffs_base__load_u40le(uint8_t* p) {\n return ((uint64_t)(p[0]) << 0) | ((uint64_t)(p[1]) << 8) |\n ((uint64_t)(p[2]) << 16) | ((uint64_t)(p[3]) << 24) |\n ((uint64_t)(p[4]) << 32);\n}\n\nstatic inline uint64_t //\nwuffs_base__load_u48be(uint8_t* p) {\n return ((uint64_t)(p[0]) << 40) | ((uint64_t)(p[1]) << 32) |\n ((uint64_t)(p[2]) << 24) | ((uint64_t)(p[3]) << 16) |\n ((uint64_t)(p[4]) << 8) | ((uint64_t)(p[5]) << 0);\n}\n\nstatic inline uint64_t //\nwuffs_base__load_u48le(uint8_t* p) {\n return ((uint64_t)(p[0]) << 0) | ((uint64_t)(p[1]) << 8) |\n ((uint64_t)(p[2]) << 16) | ((uint64_t)(p[3]) << 24) |\n ((uint64_t)(p[4]) << 32) | ((uint64_t)(p[5]) <<" +
+ " 40);\n}\n\nstatic inline uint64_t //\nwuffs_base__load_u56be(uint8_t* p) {\n return ((uint64_t)(p[0]) << 48) | ((uint64_t)(p[1]) << 40) |\n ((uint64_t)(p[2]) << 32) | ((uint64_t)(p[3]) << 24) |\n ((uint64_t)(p[4]) << 16) | ((uint64_t)(p[5]) << 8) |\n ((uint64_t)(p[6]) << 0);\n}\n\nstatic inline uint64_t //\nwuffs_base__load_u56le(uint8_t* p) {\n return ((uint64_t)(p[0]) << 0) | ((uint64_t)(p[1]) << 8) |\n ((uint64_t)(p[2]) << 16) | ((uint64_t)(p[3]) << 24) |\n ((uint64_t)(p[4]) << 32) | ((uint64_t)(p[5]) << 40) |\n ((uint64_t)(p[6]) << 48);\n}\n\nstatic inline uint64_t //\nwuffs_base__load_u64be(uint8_t* p) {\n return ((uint64_t)(p[0]) << 56) | ((uint64_t)(p[1]) << 48) |\n ((uint64_t)(p[2]) << 40) | ((uint64_t)(p[3]) << 32) |\n ((uint64_t)(p[4]) << 24) | ((uint64_t)(p[5]) << 16) |\n ((uint64_t)(p[6]) << 8) | ((uint64_t)(p[7]) << 0);\n}\n\nstatic inline uint64_t //\nwuffs_base__load_u64le(uint8_t* p) {\n return ((uint64_t)(p[0]) << 0) | ((uint64_t)(p[1]) << 8" +
+ ") |\n ((uint64_t)(p[2]) << 16) | ((uint64_t)(p[3]) << 24) |\n ((uint64_t)(p[4]) << 32) | ((uint64_t)(p[5]) << 40) |\n ((uint64_t)(p[6]) << 48) | ((uint64_t)(p[7]) << 56);\n}\n\n" +
+ "" +
+ "// --------\n\nstatic inline void //\nwuffs_base__store_u8be(uint8_t* p, uint8_t x) {\n p[0] = x;\n}\n\nstatic inline void //\nwuffs_base__store_u16be(uint8_t* p, uint16_t x) {\n p[0] = (uint8_t)(x >> 8);\n p[1] = (uint8_t)(x >> 0);\n}\n\nstatic inline void //\nwuffs_base__store_u16le(uint8_t* p, uint16_t x) {\n p[0] = (uint8_t)(x >> 0);\n p[1] = (uint8_t)(x >> 8);\n}\n\nstatic inline void //\nwuffs_base__store_u24be(uint8_t* p, uint32_t x) {\n p[0] = (uint8_t)(x >> 16);\n p[1] = (uint8_t)(x >> 8);\n p[2] = (uint8_t)(x >> 0);\n}\n\nstatic inline void //\nwuffs_base__store_u24le(uint8_t* p, uint32_t x) {\n p[0] = (uint8_t)(x >> 0);\n p[1] = (uint8_t)(x >> 8);\n p[2] = (uint8_t)(x >> 16);\n}\n\nstatic inline void //\nwuffs_base__store_u32be(uint8_t* p, uint32_t x) {\n p[0] = (uint8_t)(x >> 24);\n p[1] = (uint8_t)(x >> 16);\n p[2] = (uint8_t)(x >> 8);\n p[3] = (uint8_t)(x >> 0);\n}\n\nstatic inline void //\nwuffs_base__store_u32le(uint8_t* p, uint32_t x) {\n p[0] = (uint8_t)(x >> 0);\n p[1] = (uint8_t)(x >> 8);\n p[2] = (uint8_t)(x" +
+ " >> 16);\n p[3] = (uint8_t)(x >> 24);\n}\n\nstatic inline void //\nwuffs_base__store_u40be(uint8_t* p, uint64_t x) {\n p[0] = (uint8_t)(x >> 32);\n p[1] = (uint8_t)(x >> 24);\n p[2] = (uint8_t)(x >> 16);\n p[3] = (uint8_t)(x >> 8);\n p[4] = (uint8_t)(x >> 0);\n}\n\nstatic inline void //\nwuffs_base__store_u40le(uint8_t* p, uint64_t x) {\n p[0] = (uint8_t)(x >> 0);\n p[1] = (uint8_t)(x >> 8);\n p[2] = (uint8_t)(x >> 16);\n p[3] = (uint8_t)(x >> 24);\n p[4] = (uint8_t)(x >> 32);\n}\n\nstatic inline void //\nwuffs_base__store_u48be(uint8_t* p, uint64_t x) {\n p[0] = (uint8_t)(x >> 40);\n p[1] = (uint8_t)(x >> 32);\n p[2] = (uint8_t)(x >> 24);\n p[3] = (uint8_t)(x >> 16);\n p[4] = (uint8_t)(x >> 8);\n p[5] = (uint8_t)(x >> 0);\n}\n\nstatic inline void //\nwuffs_base__store_u48le(uint8_t* p, uint64_t x) {\n p[0] = (uint8_t)(x >> 0);\n p[1] = (uint8_t)(x >> 8);\n p[2] = (uint8_t)(x >> 16);\n p[3] = (uint8_t)(x >> 24);\n p[4] = (uint8_t)(x >> 32);\n p[5] = (uint8_t)(x >> 40);\n}\n\nstatic inline void //\nwuffs_base__store_u56be(ui" +
+ "nt8_t* p, uint64_t x) {\n p[0] = (uint8_t)(x >> 48);\n p[1] = (uint8_t)(x >> 40);\n p[2] = (uint8_t)(x >> 32);\n p[3] = (uint8_t)(x >> 24);\n p[4] = (uint8_t)(x >> 16);\n p[5] = (uint8_t)(x >> 8);\n p[6] = (uint8_t)(x >> 0);\n}\n\nstatic inline void //\nwuffs_base__store_u56le(uint8_t* p, uint64_t x) {\n p[0] = (uint8_t)(x >> 0);\n p[1] = (uint8_t)(x >> 8);\n p[2] = (uint8_t)(x >> 16);\n p[3] = (uint8_t)(x >> 24);\n p[4] = (uint8_t)(x >> 32);\n p[5] = (uint8_t)(x >> 40);\n p[6] = (uint8_t)(x >> 48);\n}\n\nstatic inline void //\nwuffs_base__store_u64be(uint8_t* p, uint64_t x) {\n p[0] = (uint8_t)(x >> 56);\n p[1] = (uint8_t)(x >> 48);\n p[2] = (uint8_t)(x >> 40);\n p[3] = (uint8_t)(x >> 32);\n p[4] = (uint8_t)(x >> 24);\n p[5] = (uint8_t)(x >> 16);\n p[6] = (uint8_t)(x >> 8);\n p[7] = (uint8_t)(x >> 0);\n}\n\nstatic inline void //\nwuffs_base__store_u64le(uint8_t* p, uint64_t x) {\n p[0] = (uint8_t)(x >> 0);\n p[1] = (uint8_t)(x >> 8);\n p[2] = (uint8_t)(x >> 16);\n p[3] = (uint8_t)(x >> 24);\n p[4] = (uint8_t)(x >> 32" +
+ ");\n p[5] = (uint8_t)(x >> 40);\n p[6] = (uint8_t)(x >> 48);\n p[7] = (uint8_t)(x >> 56);\n}\n\n" +
+ "" +
+ "// --------\n\nextern const uint8_t wuffs_base__low_bits_mask__u8[9];\nextern const uint16_t wuffs_base__low_bits_mask__u16[17];\nextern const uint32_t wuffs_base__low_bits_mask__u32[33];\nextern const uint64_t wuffs_base__low_bits_mask__u64[65];\n\n#define WUFFS_BASE__LOW_BITS_MASK__U8(n) (wuffs_base__low_bits_mask__u8[n])\n#define WUFFS_BASE__LOW_BITS_MASK__U16(n) (wuffs_base__low_bits_mask__u16[n])\n#define WUFFS_BASE__LOW_BITS_MASK__U32(n) (wuffs_base__low_bits_mask__u32[n])\n#define WUFFS_BASE__LOW_BITS_MASK__U64(n) (wuffs_base__low_bits_mask__u64[n])\n\n" +
+ "" +
+ "// --------\n\nstatic inline void //\nwuffs_base__u8__sat_add_indirect(uint8_t* x, uint8_t y) {\n *x = wuffs_base__u8__sat_add(*x, y);\n}\n\nstatic inline void //\nwuffs_base__u8__sat_sub_indirect(uint8_t* x, uint8_t y) {\n *x = wuffs_base__u8__sat_sub(*x, y);\n}\n\nstatic inline void //\nwuffs_base__u16__sat_add_indirect(uint16_t* x, uint16_t y) {\n *x = wuffs_base__u16__sat_add(*x, y);\n}\n\nstatic inline void //\nwuffs_base__u16__sat_sub_indirect(uint16_t* x, uint16_t y) {\n *x = wuffs_base__u16__sat_sub(*x, y);\n}\n\nstatic inline void //\nwuffs_base__u32__sat_add_indirect(uint32_t* x, uint32_t y) {\n *x = wuffs_base__u32__sat_add(*x, y);\n}\n\nstatic inline void //\nwuffs_base__u32__sat_sub_indirect(uint32_t* x, uint32_t y) {\n *x = wuffs_base__u32__sat_sub(*x, y);\n}\n\nstatic inline void //\nwuffs_base__u64__sat_add_indirect(uint64_t* x, uint64_t y) {\n *x = wuffs_base__u64__sat_add(*x, y);\n}\n\nstatic inline void //\nwuffs_base__u64__sat_sub_indirect(uint64_t* x, uint64_t y) {\n *x = wuffs_base__u64__sat_sub(*x, y);\n}\n\n" +
+ "" +
+ "// ---------------- Slices and Tables\n\n// wuffs_base__slice_u8__prefix returns up to the first up_to bytes of s.\nstatic inline wuffs_base__slice_u8 //\nwuffs_base__slice_u8__prefix(wuffs_base__slice_u8 s, 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 //\nwuffs_base__slice_u8__suffix(wuffs_base__slice_u8 s, 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, len)\n// where len 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.\nstatic inline uint64_t //\nwuffs_base__slice_u8__copy_from_slice(wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 src) {\n size_t len = dst.l" +
+ "en < src.len ? dst.len : src.len;\n if (len > 0) {\n memmove(dst.ptr, src.ptr, len);\n }\n return len;\n}\n\n" +
+ "" +
+ "// --------\n\nstatic inline wuffs_base__slice_u8 //\nwuffs_base__table_u8__row(wuffs_base__table_u8 t, uint32_t y) {\n if (y < t.height) {\n return wuffs_base__make_slice_u8(t.ptr + (t.stride * y), t.width);\n }\n return wuffs_base__make_slice_u8(NULL, 0);\n}\n\n" +
+ "" +
+ "// ---------------- Slices and Tables (Utility)\n\n#define wuffs_base__utility__null_slice_u8 wuffs_base__null_slice_u8\n" +
+ ""
+
+const baseCorePublicH = "" +
+ "// Wuffs assumes that:\n// - converting a uint32_t to a size_t will never overflow.\n// - converting a size_t to a uint64_t will never overflow.\n#ifdef __WORDSIZE\n#if (__WORDSIZE != 32) && (__WORDSIZE != 64)\n#error \"Wuffs requires a word size of either 32 or 64 bits\"\n#endif\n#endif\n\n// WUFFS_VERSION is the major.minor.patch version, as per https://semver.org/,\n// as a uint64_t. The major number is the high 32 bits. The minor number is the\n// middle 16 bits. The patch number is the low 16 bits. The pre-release label\n// and build metadata are part of the string representation (such as\n// \"1.2.3-beta+456.20181231\") but not the uint64_t representation.\n//\n// WUFFS_VERSION_PRE_RELEASE_LABEL (such as \"\", \"beta\" or \"rc.1\") being\n// non-empty denotes a developer preview, not a release version, and has no\n// backwards or forwards compatibility guarantees.\n//\n// WUFFS_VERSION_BUILD_METADATA_XXX, if non-zero, are the number of commits and\n// the last commit date in the repository used to build this library. Within\n// eac" +
+ "h major.minor branch, the commit count should increase monotonically.\n//\n// !! Some code generation programs can override WUFFS_VERSION.\n#define WUFFS_VERSION ((uint64_t)0)\n#define WUFFS_VERSION_MAJOR ((uint64_t)0)\n#define WUFFS_VERSION_MINOR ((uint64_t)0)\n#define WUFFS_VERSION_PATCH ((uint64_t)0)\n#define WUFFS_VERSION_PRE_RELEASE_LABEL \"work.in.progress\"\n#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 0\n#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 0\n#define WUFFS_VERSION_STRING \"0.0.0+0.00000000\"\n\n// Define WUFFS_CONFIG__STATIC_FUNCTIONS to make all of Wuffs' functions have\n// static storage. The motivation is discussed in the \"ALLOW STATIC\n// IMPLEMENTATION\" section of\n// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt\n#ifdef WUFFS_CONFIG__STATIC_FUNCTIONS\n#define WUFFS_BASE__MAYBE_STATIC static\n#else\n#define WUFFS_BASE__MAYBE_STATIC\n#endif\n\n#if defined(__clang__)\n#define WUFFS_BASE__POTENTIALLY_UNUSED_FIELD __attribute__((unused))\n#else\n#define WUFFS_BASE__POTENTIALLY_UNUSED_" +
+ "FIELD\n#endif\n\n// Clang also defines \"__GNUC__\".\n#if defined(__GNUC__)\n#define WUFFS_BASE__POTENTIALLY_UNUSED __attribute__((unused))\n#define WUFFS_BASE__WARN_UNUSED_RESULT __attribute__((warn_unused_result))\n#else\n#define WUFFS_BASE__POTENTIALLY_UNUSED\n#define WUFFS_BASE__WARN_UNUSED_RESULT\n#endif\n\n// Flags for wuffs_foo__bar__initialize functions.\n\n#define WUFFS_INITIALIZE__DEFAULT_OPTIONS ((uint32_t)0x00000000)\n\n// WUFFS_INITIALIZE__ALREADY_ZEROED means that the \"self\" receiver struct value\n// has already been set to all zeroes.\n#define WUFFS_INITIALIZE__ALREADY_ZEROED ((uint32_t)0x00000001)\n\n// WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED means that, absent\n// WUFFS_INITIALIZE__ALREADY_ZEROED, only some of the \"self\" receiver struct\n// value will be set to all zeroes. Internal buffers, which tend to be a large\n// proportion of the struct's size, will be left uninitialized. Internal means\n// that the buffer is contained by the receiver struct, as opposed to being\n// passed as a separately allocate" +
+ "d \"work buffer\".\n//\n// With or without this bit set, the Wuffs compiler still enforces that no\n// reads or writes will overflow internal buffers' bounds. Even with this bit\n// set, the Wuffs standard library also considers reading from an uninitialized\n// buffer to be a bug, and strives to never do so, but unlike buffer overflows,\n// it is not a bug class that the Wuffs compiler eliminates.\n//\n// For those paranoid about security, leave this bit unset, so that\n// wuffs_foo__bar__initialize will initialize the entire struct value to zeroes\n// (unless WUFFS_INITIALIZE__ALREADY_ZEROED is set).\n//\n// Setting this bit gives a small absolute improvement on micro-benchmarks, but\n// this can be a large relative effect, up to 2x faster, when the actual work\n// to be done is also small, such as decompressing small input. See git commit\n// 438fc105 \"Move some struct fields to private_data\" for some numbers and a\n// discussion, noting that its commit message was written before this\n// WUFFS_INITIALIZE__LEAVE_INTERNAL_BUF" +
+ "FERS_UNINITIALIZED option was defined.\n#define WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED \\\n ((uint32_t)0x00000002)\n\n" +
+ "" +
+ "// --------\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 // private_impl is a placeholder field. It isn't explicitly used, except that\n // without it, the sizeof a struct with no fields can differ across C/C++\n // compilers, and it is undefined behavior in C99. For example, gcc says that\n // the sizeof an empty struct is 0, and g++ says that it is 1. This leads to\n // ABI incompatibility if a Wuffs .c file is processed by one compiler and\n // its .h file with another compiler.\n //\n // Instead, we explicitly insert an otherwise unused field, so that the\n // sizeof this struct is always 1.\n uint8_t private_impl;\n} wuffs_base__empty_struct;\n\nstatic inline wuffs_base__empty_struct //\nwuffs_base__make_empty_struct() {\n wuffs_base__empty_struct ret;\n ret.private_impl = 0;\n return ret;\n}\n\n// wuffs_base__utility is" +
+ " a placeholder receiver type. It enables what Java\n// calls static methods, as opposed to regular methods.\ntypedef struct {\n // private_impl is a placeholder field. It isn't explicitly used, except that\n // without it, the sizeof a struct with no fields can differ across C/C++\n // compilers, and it is undefined behavior in C99. For example, gcc says that\n // the sizeof an empty struct is 0, and g++ says that it is 1. This leads to\n // ABI incompatibility if a Wuffs .c file is processed by one compiler and\n // its .h file with another compiler.\n //\n // Instead, we explicitly insert an otherwise unused field, so that the\n // sizeof this struct is always 1.\n uint8_t private_impl;\n} wuffs_base__utility;\n\n" +
+ "" +
+ "// --------\n\n// A status is either NULL (meaning OK) or a string message. That message is\n// human-readable, for programmers, but it is not for end users. It is not\n// localized, and does not contain additional contextual information such as a\n// source filename.\n//\n// Status strings are statically allocated and should never be free'd. They can\n// be compared by the == operator and not just by strcmp.\n//\n// Statuses come in four categories:\n// - OK: the request was completed, successfully.\n// - Warnings: the request was completed, unsuccessfully.\n// - Suspensions: the request was not completed, but can be re-tried.\n// - Errors: the request was not completed, permanently.\n//\n// When a function returns an incomplete status, a suspension means that that\n// function should be called again within a new context, such as after flushing\n// or re-filling an I/O buffer. An error means that an irrecoverable failure\n// state was reached.\ntypedef const char* wuffs_base__status;\n\n// !! INSERT wuffs_bas" +
+ "e__status names.\n\nstatic inline bool //\nwuffs_base__status__is_complete(wuffs_base__status z) {\n return (z == NULL) || ((*z != '$') && (*z != '#'));\n}\n\nstatic inline bool //\nwuffs_base__status__is_error(wuffs_base__status z) {\n return z && (*z == '#');\n}\n\nstatic inline bool //\nwuffs_base__status__is_ok(wuffs_base__status z) {\n return z == NULL;\n}\n\nstatic inline bool //\nwuffs_base__status__is_suspension(wuffs_base__status z) {\n return z && (*z == '$');\n}\n\nstatic inline bool //\nwuffs_base__status__is_warning(wuffs_base__status z) {\n return z && (*z != '$') && (*z != '#');\n}\n\n" +
+ "" +
+ "// --------\n\n// Flicks are a unit of time. One flick (frame-tick) is 1 / 705_600_000 of a\n// second. See https://github.com/OculusVR/Flicks\ntypedef int64_t wuffs_base__flicks;\n\n#define WUFFS_BASE__FLICKS_PER_SECOND ((uint64_t)705600000)\n#define WUFFS_BASE__FLICKS_PER_MILLISECOND ((uint64_t)705600)\n\n" +
+ "" +
+ "// ---------------- Numeric Types\n\nstatic inline uint8_t //\nwuffs_base__u8__min(uint8_t x, uint8_t y) {\n return x < y ? x : y;\n}\n\nstatic inline uint8_t //\nwuffs_base__u8__max(uint8_t x, uint8_t y) {\n return x > y ? x : y;\n}\n\nstatic inline uint16_t //\nwuffs_base__u16__min(uint16_t x, uint16_t y) {\n return x < y ? x : y;\n}\n\nstatic inline uint16_t //\nwuffs_base__u16__max(uint16_t x, uint16_t y) {\n return x > y ? x : y;\n}\n\nstatic inline uint32_t //\nwuffs_base__u32__min(uint32_t x, uint32_t y) {\n return x < y ? x : y;\n}\n\nstatic inline uint32_t //\nwuffs_base__u32__max(uint32_t x, uint32_t y) {\n return x > y ? x : y;\n}\n\nstatic inline uint64_t //\nwuffs_base__u64__min(uint64_t x, uint64_t y) {\n return x < y ? x : y;\n}\n\nstatic inline uint64_t //\nwuffs_base__u64__max(uint64_t x, uint64_t y) {\n return x > y ? x : y;\n}\n\n" +
+ "" +
+ "// --------\n\n// Saturating arithmetic (sat_add, sat_sub) branchless bit-twiddling algorithms\n// are per https://locklessinc.com/articles/sat_arithmetic/\n//\n// It is important that the underlying types are unsigned integers, as signed\n// integer arithmetic overflow is undefined behavior in C.\n\nstatic inline uint8_t //\nwuffs_base__u8__sat_add(uint8_t x, uint8_t y) {\n uint8_t res = (uint8_t)(x + y);\n res |= (uint8_t)(-(res < x));\n return res;\n}\n\nstatic inline uint8_t //\nwuffs_base__u8__sat_sub(uint8_t x, uint8_t y) {\n uint8_t res = (uint8_t)(x - y);\n res &= (uint8_t)(-(res <= x));\n return res;\n}\n\nstatic inline uint16_t //\nwuffs_base__u16__sat_add(uint16_t x, uint16_t y) {\n uint16_t res = (uint16_t)(x + y);\n res |= (uint16_t)(-(res < x));\n return res;\n}\n\nstatic inline uint16_t //\nwuffs_base__u16__sat_sub(uint16_t x, uint16_t y) {\n uint16_t res = (uint16_t)(x - y);\n res &= (uint16_t)(-(res <= x));\n return res;\n}\n\nstatic inline uint32_t //\nwuffs_base__u32__sat_add(uint32_t x, uint32_t y) {\n uint32" +
+ "_t res = (uint32_t)(x + y);\n res |= (uint32_t)(-(res < x));\n return res;\n}\n\nstatic inline uint32_t //\nwuffs_base__u32__sat_sub(uint32_t x, uint32_t y) {\n uint32_t res = (uint32_t)(x - y);\n res &= (uint32_t)(-(res <= x));\n return res;\n}\n\nstatic inline uint64_t //\nwuffs_base__u64__sat_add(uint64_t x, uint64_t y) {\n uint64_t res = (uint64_t)(x + y);\n res |= (uint64_t)(-(res < x));\n return res;\n}\n\nstatic inline uint64_t //\nwuffs_base__u64__sat_sub(uint64_t x, uint64_t y) {\n uint64_t res = (uint64_t)(x - y);\n res &= (uint64_t)(-(res <= x));\n return res;\n}\n\n" +
+ "" +
+ "// ---------------- Slices and Tables\n\n// WUFFS_BASE__SLICE is a 1-dimensional buffer.\n//\n// len measures a number of elements, not necessarily a size in bytes.\n//\n// A value with all fields NULL or zero is a valid, empty slice.\n#define WUFFS_BASE__SLICE(T) \\\n struct { \\\n T* ptr; \\\n size_t len; \\\n }\n\n// WUFFS_BASE__TABLE is a 2-dimensional buffer.\n//\n// width height, and stride measure a number of elements, not necessarily a\n// size in bytes.\n//\n// A value with all fields NULL or zero is a valid, empty table.\n#define WUFFS_BASE__TABLE(T) \\\n struct { \\\n T* ptr; \\\n size_t width; \\\n size_t height; \\\n size_t stride; \\\n }\n\ntypedef WUFFS_BASE__SLICE(uint8_t) wuffs_base__slice_u8;\ntypedef WUFFS_BASE__SLICE(uint16_t) wuffs_base__slice_u16;\ntypedef WUFFS_BASE__SLICE(uint32_t) wuffs_base__slice_u32;\ntypedef WUFFS_BASE__SLICE(uint64_t) wuffs_base__slice_u64;\n\ntypedef WUFFS_BASE__TABLE(u" +
+ "int8_t) wuffs_base__table_u8;\ntypedef WUFFS_BASE__TABLE(uint16_t) wuffs_base__table_u16;\ntypedef WUFFS_BASE__TABLE(uint32_t) wuffs_base__table_u32;\ntypedef WUFFS_BASE__TABLE(uint64_t) wuffs_base__table_u64;\n\nstatic inline wuffs_base__slice_u8 //\nwuffs_base__make_slice_u8(uint8_t* ptr, size_t len) {\n wuffs_base__slice_u8 ret;\n ret.ptr = ptr;\n ret.len = len;\n return ret;\n}\n\nstatic inline wuffs_base__slice_u16 //\nwuffs_base__make_slice_u16(uint16_t* ptr, size_t len) {\n wuffs_base__slice_u16 ret;\n ret.ptr = ptr;\n ret.len = len;\n return ret;\n}\n\nstatic inline wuffs_base__slice_u32 //\nwuffs_base__make_slice_u32(uint32_t* ptr, size_t len) {\n wuffs_base__slice_u32 ret;\n ret.ptr = ptr;\n ret.len = len;\n return ret;\n}\n\nstatic inline wuffs_base__slice_u64 //\nwuffs_base__make_slice_u64(uint64_t* ptr, size_t len) {\n wuffs_base__slice_u64 ret;\n ret.ptr = ptr;\n ret.len = len;\n return ret;\n}\n\nstatic inline wuffs_base__slice_u8 //\nwuffs_base__null_slice_u8() {\n wuffs_base__slice_u8 ret;\n ret.ptr = NULL;\n " +
+ " ret.len = 0;\n return ret;\n}\n\nstatic inline wuffs_base__table_u8 //\nwuffs_base__null_table_u8() {\n wuffs_base__table_u8 ret;\n ret.ptr = NULL;\n ret.width = 0;\n ret.height = 0;\n ret.stride = 0;\n return ret;\n}\n\n// wuffs_base__slice_u8__subslice_i returns s[i:].\n//\n// It returns an empty slice if i is out of bounds.\nstatic inline wuffs_base__slice_u8 //\nwuffs_base__slice_u8__subslice_i(wuffs_base__slice_u8 s, uint64_t i) {\n if ((i <= SIZE_MAX) && (i <= s.len)) {\n return wuffs_base__make_slice_u8(s.ptr + i, s.len - i);\n }\n return wuffs_base__make_slice_u8(NULL, 0);\n}\n\n// wuffs_base__slice_u8__subslice_j returns s[:j].\n//\n// It returns an empty slice if j is out of bounds.\nstatic inline wuffs_base__slice_u8 //\nwuffs_base__slice_u8__subslice_j(wuffs_base__slice_u8 s, uint64_t j) {\n if ((j <= SIZE_MAX) && (j <= s.len)) {\n return wuffs_base__make_slice_u8(s.ptr, j);\n }\n return wuffs_base__make_slice_u8(NULL, 0);\n}\n\n// wuffs_base__slice_u8__subslice_ij returns s[i:j].\n//\n// It returns an empty sli" +
+ "ce if i or j is out of bounds.\nstatic inline wuffs_base__slice_u8 //\nwuffs_base__slice_u8__subslice_ij(wuffs_base__slice_u8 s,\n uint64_t i,\n uint64_t j) {\n if ((i <= j) && (j <= SIZE_MAX) && (j <= s.len)) {\n return wuffs_base__make_slice_u8(s.ptr + i, j - i);\n }\n return wuffs_base__make_slice_u8(NULL, 0);\n}\n" +
+ ""
+
+const baseMemoryPrivateH = "" +
+ "// ---------------- Memory Allocation\n" +
+ ""
+
+const baseMemoryPublicH = "" +
+ "// ---------------- Memory Allocation\n\n// The memory allocation related functions in this section aren't used by Wuffs\n// per se, but they may be helpful to the code that uses Wuffs.\n\n// wuffs_base__malloc_slice_uxx wraps calling a malloc-like function, except\n// that it takes a uint64_t number of elements instead of a size_t size in\n// bytes, and it returns a slice (a pointer and a length) instead of just a\n// pointer.\n//\n// You can pass the C stdlib's malloc as the malloc_func.\n//\n// It returns an empty slice (containing a NULL ptr field) if (num_uxx *\n// sizeof(uintxx_t)) would overflow SIZE_MAX.\n\nstatic inline wuffs_base__slice_u8 //\nwuffs_base__malloc_slice_u8(void* (*malloc_func)(size_t), uint64_t num_u8) {\n if (malloc_func && (num_u8 <= (SIZE_MAX / sizeof(uint8_t)))) {\n void* p = (*malloc_func)(num_u8 * sizeof(uint8_t));\n if (p) {\n return wuffs_base__make_slice_u8((uint8_t*)(p), num_u8);\n }\n }\n return wuffs_base__make_slice_u8(NULL, 0);\n}\n\nstatic inline wuffs_base__slice_u16 //\nwuffs" +
+ "_base__malloc_slice_u16(void* (*malloc_func)(size_t), uint64_t num_u16) {\n if (malloc_func && (num_u16 <= (SIZE_MAX / sizeof(uint16_t)))) {\n void* p = (*malloc_func)(num_u16 * sizeof(uint16_t));\n if (p) {\n return wuffs_base__make_slice_u16((uint16_t*)(p), num_u16);\n }\n }\n return wuffs_base__make_slice_u16(NULL, 0);\n}\n\nstatic inline wuffs_base__slice_u32 //\nwuffs_base__malloc_slice_u32(void* (*malloc_func)(size_t), uint64_t num_u32) {\n if (malloc_func && (num_u32 <= (SIZE_MAX / sizeof(uint32_t)))) {\n void* p = (*malloc_func)(num_u32 * sizeof(uint32_t));\n if (p) {\n return wuffs_base__make_slice_u32((uint32_t*)(p), num_u32);\n }\n }\n return wuffs_base__make_slice_u32(NULL, 0);\n}\n\nstatic inline wuffs_base__slice_u64 //\nwuffs_base__malloc_slice_u64(void* (*malloc_func)(size_t), uint64_t num_u64) {\n if (malloc_func && (num_u64 <= (SIZE_MAX / sizeof(uint64_t)))) {\n void* p = (*malloc_func)(num_u64 * sizeof(uint64_t));\n if (p) {\n return wuffs_base__make_slice_u64((uint64_" +
+ "t*)(p), num_u64);\n }\n }\n return wuffs_base__make_slice_u64(NULL, 0);\n}\n" +
+ ""
+
+const baseImagePrivateH = "" +
+ "// ---------------- Images\n" +
+ ""
+
+const baseImagePublicH = "" +
+ "// ---------------- Images\n\n// wuffs_base__color_u32_argb_premul is an 8 bit per channel premultiplied\n// Alpha, Red, Green, Blue color, as a uint32_t value. It is in word order, not\n// byte order: its value is always 0xAARRGGBB, regardless of endianness.\ntypedef uint32_t wuffs_base__color_u32_argb_premul;\n\n" +
+ "" +
+ "// --------\n\n// wuffs_base__pixel_format encodes the format of the bytes that constitute an\n// image frame's pixel data. Its bits:\n// - bit 31 is reserved.\n// - bits 30 .. 28 encodes color (and channel order, in terms of memory).\n// - bit 27 is reserved.\n// - bits 26 .. 24 encodes transparency.\n// - bits 23 .. 21 are reserved.\n// - bit 20 indicates big-endian/MSB-first (as opposed to little/LSB).\n// - bit 19 indicates floating point (as opposed to integer).\n// - bit 18 indicates palette-indexed. The number-of-planes (the next\n// field) will be zero, as the format is considered packed,\n// but the 8-bit N-BGRA color data is stored in plane 3.\n// - bits 17 .. 16 are the number of planes, minus 1. Zero means packed.\n// - bits 15 .. 12 encodes the number of bits (depth) in the 3rd channel.\n// - bits 11 .. 8 encodes the number of bits (depth) in the 2nd channel.\n// - bits 7 .. 4 encodes the number of bits (depth) in the 1st channe" +
+ "l.\n// - bits 3 .. 0 encodes the number of bits (depth) in the 0th channel.\n//\n// The bit fields of a wuffs_base__pixel_format are not independent. For\n// example, the number of planes should not be greater than the number of\n// channels. Similarly, bits 15..4 are unused (and should be zero) if bits\n// 31..24 (color and transparency) together imply only 1 channel (gray, no\n// alpha) and floating point samples should mean a bit depth of 16, 32 or 64.\n//\n// Formats hold between 1 and 4 channels. For example: Y (1 channel: gray), YA\n// (2 channels: gray and alpha), BGR (3 channels: blue, green, red) or CMYK (4\n// channels: cyan, magenta, yellow, black).\n//\n// For direct formats with N > 1 channels, those channels can be laid out in\n// either 1 (packed) or N (planar) planes. For example, RGBA data is usually\n// packed, but YCbCr data is usually planar, due to chroma subsampling (for\n// details, see the wuffs_base__pixel_subsampling type).\n//\n// For indexed formats, the palette (always 256 × 4 bytes) holds 8 bi" +
+ "ts per\n// channel non-alpha-premultiplied BGRA color data. There is only 1 plane (for\n// the index), as the format is considered packed. Plane 0 holds the per-pixel\n// indices. Plane 3 is re-purposed to hold the per-index colors.\n//\n// The color field is encoded in 3 bits:\n// - 0 means A (Alpha).\n// - 1 means Y or YA (Gray, Alpha).\n// - 2 means YCbCr or YCbCrA (Luma, Chroma-blue, Chroma-red, Alpha).\n// - 3 means YCoCg or YCoCgA (Luma, Chroma-orange, Chroma-green, Alpha).\n// - 4 means BGR, BGRX or BGRA (Blue, Green, Red, X-padding or Alpha).\n// - 5 means RGB, RGBX or RGBA (Red, Green, Blue, X-padding or Alpha).\n// - 6 means CMY or CMYK (Cyan, Magenta, Yellow, Black).\n// - all other values are reserved.\n//\n// In Wuffs, channels are given in memory order (also known as byte order),\n// regardless of endianness, since the C type for the pixel data is an array of\n// bytes, not an array of uint32_t. For example, packed BGRA with 8 bits per\n// channel means th" +
+ "at the bytes in memory are always Blue, Green, Red then\n// Alpha. On big-endian systems, that is the uint32_t 0xBBGGRRAA. On\n// little-endian, 0xAARRGGBB.\n//\n// When the color field (3 bits) encodes multiple options, the transparency\n// field (3 bits) distinguishes them:\n// - 0 means fully opaque, no extra channels\n// - 1 means fully opaque, one extra channel (X or K, padding or black).\n// - 5 means one extra alpha channel, other channels are non-premultiplied.\n// - 6 means one extra alpha channel, other channels are premultiplied.\n// - 7 means one extra alpha channel, binary alpha.\n// - all other values are reserved.\n//\n// Binary alpha means that if a color is not completely opaque, it is\n// completely transparent black. As a source pixel format, it can therefore be\n// treated as either non-premultiplied or premultiplied.\n//\n// The zero wuffs_base__pixel_format value is an invalid pixel format, as it is\n// invalid to combine the zero color (alpha only) with the zero transparency.\n//\n// Bit depth is" +
+ " encoded in 4 bits:\n// - 0 means the channel or index is unused.\n// - x means a bit depth of x, for x in the range 1..8.\n// - 9 means a bit depth of 10.\n// - 10 means a bit depth of 12.\n// - 11 means a bit depth of 16.\n// - 12 means a bit depth of 24.\n// - 13 means a bit depth of 32.\n// - 14 means a bit depth of 48.\n// - 15 means a bit depth of 64.\n//\n// For example, wuffs_base__pixel_format 0x5510BBBB is a natural format for\n// decoding a PNG image - network byte order (also known as big-endian),\n// packed, non-premultiplied alpha - that happens to be 16-bit-depth truecolor\n// with alpha (RGBA). In memory order:\n//\n// ptr+0 ptr+1 ptr+2 ptr+3 ptr+4 ptr+5 ptr+6 ptr+7\n// Rhi Rlo Ghi Glo Bhi Blo Ahi Alo\n//\n// For example, the value wuffs_base__pixel_format 0x40000565 means BGR with no\n// alpha or padding, 5/6/5 bits for blue/green/red, packed 2 bytes per pixel,\n// laid out LSB-first in memory order:\n//\n// ptr+0........... ptr+1...........\n// MSB LSB MSB " +
+ " LSB\n// G₂G₁G₀B₄B₃B₂B₁B₀ R₄R₃R₂R₁R₀G₅G₄G₃\n//\n// On little-endian systems (but not big-endian), this Wuffs pixel format value\n// (0x40000565) corresponds to the Cairo library's CAIRO_FORMAT_RGB16_565, the\n// SDL2 (Simple DirectMedia Layer 2) library's SDL_PIXELFORMAT_RGB565 and the\n// Skia library's kRGB_565_SkColorType. Note BGR in Wuffs versus RGB in the\n// other libraries.\n//\n// Regardless of endianness, this Wuffs pixel format value (0x40000565)\n// corresponds to the V4L2 (Video For Linux 2) library's V4L2_PIX_FMT_RGB565\n// and the Wayland-DRM library's WL_DRM_FORMAT_RGB565.\n//\n// Different software libraries name their pixel formats (and especially their\n// channel order) either according to memory layout or as bits of a native\n// integer type like uint32_t. The two conventions differ because of a system's\n// endianness. As mentioned earlier, Wuffs pixel formats are always in memory\n// order. More detail of other software libraries' naming conventions is in the\n// Pi" +
+ "xel Format Guide at https://afrantzis.github.io/pixel-format-guide/\n//\n// Do not manipulate these bits directly; they are private implementation\n// details. Use methods such as wuffs_base__pixel_format__num_planes instead.\ntypedef uint32_t wuffs_base__pixel_format;\n\n// Common 8-bit-depth pixel formats. This list is not exhaustive; not all valid\n// wuffs_base__pixel_format values are present.\n\n#define WUFFS_BASE__PIXEL_FORMAT__INVALID ((wuffs_base__pixel_format)0x00000000)\n\n#define WUFFS_BASE__PIXEL_FORMAT__A ((wuffs_base__pixel_format)0x02000008)\n\n#define WUFFS_BASE__PIXEL_FORMAT__Y ((wuffs_base__pixel_format)0x10000008)\n#define WUFFS_BASE__PIXEL_FORMAT__YA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x15000008)\n#define WUFFS_BASE__PIXEL_FORMAT__YA_PREMUL \\\n ((wuffs_base__pixel_format)0x16000008)\n\n#define WUFFS_BASE__PIXEL_FORMAT__YCBCR ((wuffs_base__pixel_format)0x20020888)\n#define WUFFS_BASE__PIXEL_FORMAT__YCBCRK ((wuffs_base__pixel_format)0x21038888)\n#define WUFFS_BASE__PIXEL_FORMAT__YCBCRA_NONPREMUL \\\n ((w" +
+ "uffs_base__pixel_format)0x25038888)\n\n#define WUFFS_BASE__PIXEL_FORMAT__YCOCG ((wuffs_base__pixel_format)0x30020888)\n#define WUFFS_BASE__PIXEL_FORMAT__YCOCGK ((wuffs_base__pixel_format)0x31038888)\n#define WUFFS_BASE__PIXEL_FORMAT__YCOCGA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x35038888)\n\n#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x45040008)\n#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_PREMUL \\\n ((wuffs_base__pixel_format)0x46040008)\n#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY \\\n ((wuffs_base__pixel_format)0x47040008)\n\n#define WUFFS_BASE__PIXEL_FORMAT__BGR ((wuffs_base__pixel_format)0x40000888)\n#define WUFFS_BASE__PIXEL_FORMAT__BGRX ((wuffs_base__pixel_format)0x41008888)\n#define WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x45008888)\n#define WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL \\\n ((wuffs_base__pixel_format)0x46008888)\n#define WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY \\\n ((wuffs_base__pixel_format)0x47008888)\n\n#define W" +
+ "UFFS_BASE__PIXEL_FORMAT__RGB ((wuffs_base__pixel_format)0x50000888)\n#define WUFFS_BASE__PIXEL_FORMAT__RGBX ((wuffs_base__pixel_format)0x51008888)\n#define WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL \\\n ((wuffs_base__pixel_format)0x55008888)\n#define WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL \\\n ((wuffs_base__pixel_format)0x56008888)\n#define WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY \\\n ((wuffs_base__pixel_format)0x57008888)\n\n#define WUFFS_BASE__PIXEL_FORMAT__CMY ((wuffs_base__pixel_format)0x60020888)\n#define WUFFS_BASE__PIXEL_FORMAT__CMYK ((wuffs_base__pixel_format)0x61038888)\n\nextern const uint32_t wuffs_base__pixel_format__bits_per_channel[16];\n\nstatic inline bool //\nwuffs_base__pixel_format__is_valid(wuffs_base__pixel_format f) {\n return f != 0;\n}\n\n// wuffs_base__pixel_format__bits_per_pixel returns, for packed pixel formats,\n// the number of bits per pixel. It returns 0 for planar pixel formats.\nstatic inline uint32_t //\nwuffs_base__pixel_format__bits_per_pixel(wuffs_base__pixel_format f) {\n if (((f >> 16) & 0x03" +
+ ") != 0) {\n return 0;\n }\n return wuffs_base__pixel_format__bits_per_channel[0x0F & (f >> 0)] +\n wuffs_base__pixel_format__bits_per_channel[0x0F & (f >> 4)] +\n wuffs_base__pixel_format__bits_per_channel[0x0F & (f >> 8)] +\n wuffs_base__pixel_format__bits_per_channel[0x0F & (f >> 12)];\n}\n\nstatic inline bool //\nwuffs_base__pixel_format__is_indexed(wuffs_base__pixel_format f) {\n return (f >> 18) & 0x01;\n}\n\nstatic inline bool //\nwuffs_base__pixel_format__is_packed(wuffs_base__pixel_format f) {\n return ((f >> 16) & 0x03) == 0;\n}\n\nstatic inline bool //\nwuffs_base__pixel_format__is_planar(wuffs_base__pixel_format f) {\n return ((f >> 16) & 0x03) != 0;\n}\n\nstatic inline uint32_t //\nwuffs_base__pixel_format__num_planes(wuffs_base__pixel_format f) {\n return ((f >> 16) & 0x03) + 1;\n}\n\n#define WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX 4\n\n#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__INDEX_PLANE 0\n#define WUFFS_BASE__PIXEL_FORMAT__INDEXED__COLOR_PLANE 3\n\n" +
+ "" +
+ "// --------\n\n// wuffs_base__pixel_subsampling encodes the mapping of pixel space coordinates\n// (x, y) to pixel buffer indices (i, j). That mapping can differ for each\n// plane p. For a depth of 8 bits (1 byte), the p'th plane's sample starts at\n// (planes[p].ptr + (j * planes[p].stride) + i).\n//\n// For packed pixel formats, the mapping is trivial: i = x and j = y. For\n// planar pixel formats, the mapping can differ due to chroma subsampling. For\n// example, consider a three plane YCbCr pixel format with 4:2:2 subsampling.\n// For the luma (Y) channel, there is one sample for every pixel, but for the\n// chroma (Cb, Cr) channels, there is one sample for every two pixels: pairs of\n// horizontally adjacent pixels form one macropixel, i = x / 2 and j == y. In\n// general, for a given p:\n// - i = (x + bias_x) >> shift_x.\n// - j = (y + bias_y) >> shift_y.\n// where biases and shifts are in the range 0..3 and 0..2 respectively.\n//\n// In general, the biases will be zero after decoding an image. However, making\n// a su" +
+ "b-image may change the bias, since the (x, y) coordinates are relative\n// to the sub-image's top-left origin, but the backing pixel buffers were\n// created relative to the original image's origin.\n//\n// For each plane p, each of those four numbers (biases and shifts) are encoded\n// in two bits, which combine to form an 8 bit unsigned integer:\n//\n// e_p = (bias_x << 6) | (shift_x << 4) | (bias_y << 2) | (shift_y << 0)\n//\n// Those e_p values (e_0 for the first plane, e_1 for the second plane, etc)\n// combine to form a wuffs_base__pixel_subsampling value:\n//\n// pixsub = (e_3 << 24) | (e_2 << 16) | (e_1 << 8) | (e_0 << 0)\n//\n// Do not manipulate these bits directly; they are private implementation\n// details. Use methods such as wuffs_base__pixel_subsampling__bias_x instead.\ntypedef uint32_t wuffs_base__pixel_subsampling;\n\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__NONE ((wuffs_base__pixel_subsampling)0)\n\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__444 \\\n ((wuffs_base__pixel_subsampling)0x000000)\n#define WUFFS_BASE__PI" +
+ "XEL_SUBSAMPLING__440 \\\n ((wuffs_base__pixel_subsampling)0x010100)\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__422 \\\n ((wuffs_base__pixel_subsampling)0x101000)\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__420 \\\n ((wuffs_base__pixel_subsampling)0x111100)\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__411 \\\n ((wuffs_base__pixel_subsampling)0x202000)\n#define WUFFS_BASE__PIXEL_SUBSAMPLING__410 \\\n ((wuffs_base__pixel_subsampling)0x212100)\n\nstatic inline uint32_t //\nwuffs_base__pixel_subsampling__bias_x(wuffs_base__pixel_subsampling s,\n uint32_t plane) {\n uint32_t shift = ((plane & 0x03) * 8) + 6;\n return (s >> shift) & 0x03;\n}\n\nstatic inline uint32_t //\nwuffs_base__pixel_subsampling__shift_x(wuffs_base__pixel_subsampling s,\n uint32_t plane) {\n uint32_t shift = ((plane & 0x03) * 8) + 4;\n return (s >> shift) & 0x03;\n}\n\nstatic inline uint32_t //\nwuffs_base__pixel_subsampling__bias_y(wuffs_base__pixel_subsampling s,\n " +
+ " uint32_t plane) {\n uint32_t shift = ((plane & 0x03) * 8) + 2;\n return (s >> shift) & 0x03;\n}\n\nstatic inline uint32_t //\nwuffs_base__pixel_subsampling__shift_y(wuffs_base__pixel_subsampling s,\n uint32_t plane) {\n uint32_t shift = ((plane & 0x03) * 8) + 0;\n return (s >> shift) & 0x03;\n}\n\n" +
+ "" +
+ "// --------\n\ntypedef struct {\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__pixel_format pixfmt;\n wuffs_base__pixel_subsampling pixsub;\n uint32_t width;\n uint32_t height;\n } private_impl;\n\n#ifdef __cplusplus\n inline void set(wuffs_base__pixel_format pixfmt,\n wuffs_base__pixel_subsampling pixsub,\n uint32_t width,\n uint32_t height);\n inline void invalidate();\n inline bool is_valid();\n inline wuffs_base__pixel_format pixel_format();\n inline wuffs_base__pixel_subsampling pixel_subsampling();\n inline wuffs_base__rect_ie_u32 bounds();\n inline uint32_t width();\n inline uint32_t height();\n inline uint64_t pixbuf_len();\n#endif // __cplusplus\n\n} wuffs_base__pixel_config;\n\nstatic inline wuffs_base__pixel_config //\nwuffs_base__null_pixel_config() {\n wuffs_base__pixel_config ret;\n ret.private_impl.pixfmt = 0;\n ret.private_impl.pixsub = 0;\n " +
+ "ret.private_impl.width = 0;\n ret.private_impl.height = 0;\n return ret;\n}\n\n// TODO: Should this function return bool? An error type?\nstatic inline void //\nwuffs_base__pixel_config__set(wuffs_base__pixel_config* c,\n wuffs_base__pixel_format pixfmt,\n wuffs_base__pixel_subsampling pixsub,\n uint32_t width,\n uint32_t height) {\n if (!c) {\n return;\n }\n if (pixfmt) {\n uint64_t wh = ((uint64_t)width) * ((uint64_t)height);\n // TODO: handle things other than 1 byte per pixel.\n if (wh <= ((uint64_t)SIZE_MAX)) {\n c->private_impl.pixfmt = pixfmt;\n c->private_impl.pixsub = pixsub;\n c->private_impl.width = width;\n c->private_impl.height = height;\n return;\n }\n }\n\n c->private_impl.pixfmt = 0;\n c->private_impl.pixsub = 0;\n c->private_impl.width = 0;\n c->private_impl.height = 0;\n}\n\nstatic inline void //\nwuffs_base__pixel_config__invalidate(wuffs_base__pixel_config*" +
+ " c) {\n if (c) {\n c->private_impl.pixfmt = 0;\n c->private_impl.pixsub = 0;\n c->private_impl.width = 0;\n c->private_impl.height = 0;\n }\n}\n\nstatic inline bool //\nwuffs_base__pixel_config__is_valid(wuffs_base__pixel_config* c) {\n return c && c->private_impl.pixfmt;\n}\n\nstatic inline wuffs_base__pixel_format //\nwuffs_base__pixel_config__pixel_format(wuffs_base__pixel_config* c) {\n return c ? c->private_impl.pixfmt : 0;\n}\n\nstatic inline wuffs_base__pixel_subsampling //\nwuffs_base__pixel_config__pixel_subsampling(wuffs_base__pixel_config* c) {\n return c ? c->private_impl.pixsub : 0;\n}\n\nstatic inline wuffs_base__rect_ie_u32 //\nwuffs_base__pixel_config__bounds(wuffs_base__pixel_config* c) {\n if (c) {\n wuffs_base__rect_ie_u32 ret;\n ret.min_incl_x = 0;\n ret.min_incl_y = 0;\n ret.max_excl_x = c->private_impl.width;\n ret.max_excl_y = c->private_impl.height;\n return ret;\n }\n\n wuffs_base__rect_ie_u32 ret;\n ret.min_incl_x = 0;\n ret.min_incl_y = 0;\n ret.max_excl_x = 0;\n ret.max_excl" +
+ "_y = 0;\n return ret;\n}\n\nstatic inline uint32_t //\nwuffs_base__pixel_config__width(wuffs_base__pixel_config* c) {\n return c ? c->private_impl.width : 0;\n}\n\nstatic inline uint32_t //\nwuffs_base__pixel_config__height(wuffs_base__pixel_config* c) {\n return c ? c->private_impl.height : 0;\n}\n\n// TODO: this is the right API for planar (not packed) pixbufs? Should it allow\n// decoding into a color model different from the format's intrinsic one? For\n// example, decoding a JPEG image straight to RGBA instead of to YCbCr?\nstatic inline uint64_t //\nwuffs_base__pixel_config__pixbuf_len(wuffs_base__pixel_config* c) {\n if (!c) {\n return 0;\n }\n if (wuffs_base__pixel_format__is_planar(c->private_impl.pixfmt)) {\n // TODO: support planar pixel formats, concious of pixel subsampling.\n return 0;\n }\n uint32_t bits_per_pixel =\n wuffs_base__pixel_format__bits_per_pixel(c->private_impl.pixfmt);\n if ((bits_per_pixel == 0) || ((bits_per_pixel % 8) != 0)) {\n // TODO: support fraction-of-byte pixels, e.g. 1 " +
+ "bit per pixel?\n return 0;\n }\n uint64_t bytes_per_pixel = bits_per_pixel / 8;\n\n uint64_t n =\n ((uint64_t)c->private_impl.width) * ((uint64_t)c->private_impl.height);\n if (n > (UINT64_MAX / bytes_per_pixel)) {\n return 0;\n }\n n *= bytes_per_pixel;\n\n if (wuffs_base__pixel_format__is_indexed(c->private_impl.pixfmt)) {\n if (n > (UINT64_MAX - 1024)) {\n return 0;\n }\n n += 1024;\n }\n\n return n;\n}\n\n#ifdef __cplusplus\n\ninline void //\nwuffs_base__pixel_config::set(wuffs_base__pixel_format pixfmt,\n wuffs_base__pixel_subsampling pixsub,\n uint32_t width,\n uint32_t height) {\n wuffs_base__pixel_config__set(this, pixfmt, pixsub, width, height);\n}\n\ninline void //\nwuffs_base__pixel_config::invalidate() {\n wuffs_base__pixel_config__invalidate(this);\n}\n\ninline bool //\nwuffs_base__pixel_config::is_valid() {\n return wuffs_base__pixel_config__is_valid(this);\n}\n\ninline wuffs_base__pixel_format //\nwuffs_base__p" +
+ "ixel_config::pixel_format() {\n return wuffs_base__pixel_config__pixel_format(this);\n}\n\ninline wuffs_base__pixel_subsampling //\nwuffs_base__pixel_config::pixel_subsampling() {\n return wuffs_base__pixel_config__pixel_subsampling(this);\n}\n\ninline wuffs_base__rect_ie_u32 //\nwuffs_base__pixel_config::bounds() {\n return wuffs_base__pixel_config__bounds(this);\n}\n\ninline uint32_t //\nwuffs_base__pixel_config::width() {\n return wuffs_base__pixel_config__width(this);\n}\n\ninline uint32_t //\nwuffs_base__pixel_config::height() {\n return wuffs_base__pixel_config__height(this);\n}\n\ninline uint64_t //\nwuffs_base__pixel_config::pixbuf_len() {\n return wuffs_base__pixel_config__pixbuf_len(this);\n}\n\n#endif // __cplusplus\n\n" +
+ "" +
+ "// --------\n\ntypedef struct {\n wuffs_base__pixel_config pixcfg;\n\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 uint64_t first_frame_io_position;\n bool first_frame_is_opaque;\n } private_impl;\n\n#ifdef __cplusplus\n inline void set(wuffs_base__pixel_format pixfmt,\n wuffs_base__pixel_subsampling pixsub,\n uint32_t width,\n uint32_t height,\n uint64_t first_frame_io_position,\n bool first_frame_is_opaque);\n inline void invalidate();\n inline bool is_valid();\n inline uint64_t first_frame_io_position();\n inline bool first_frame_is_opaque();\n#endif // __cplusplus\n\n} wuffs_base__image_config;\n\nstatic inline wuffs_base__image_config //\nwuffs_base__null_image_config() {\n wuffs_base__image_config ret;\n ret.pixcfg = wuffs_base__null_pixel_config();\n ret.private_impl.first_frame_io_position = 0;\n ret.private_impl.first_frame_is_opaque" +
+ " = false;\n return ret;\n}\n\n// TODO: Should this function return bool? An error type?\nstatic inline void //\nwuffs_base__image_config__set(wuffs_base__image_config* c,\n wuffs_base__pixel_format pixfmt,\n wuffs_base__pixel_subsampling pixsub,\n uint32_t width,\n uint32_t height,\n uint64_t first_frame_io_position,\n bool first_frame_is_opaque) {\n if (!c) {\n return;\n }\n if (wuffs_base__pixel_format__is_valid(pixfmt)) {\n c->pixcfg.private_impl.pixfmt = pixfmt;\n c->pixcfg.private_impl.pixsub = pixsub;\n c->pixcfg.private_impl.width = width;\n c->pixcfg.private_impl.height = height;\n c->private_impl.first_frame_io_position = first_frame_io_position;\n c->private_impl.first_frame_is_opaque = first_frame_is_opaque;\n return;\n }\n\n c->pixcfg.private_impl.pixfmt = 0;\n c->pixcfg.private_impl.pixsub = 0;\n c->pixcfg.private_impl.w" +
+ "idth = 0;\n c->pixcfg.private_impl.height = 0;\n c->private_impl.first_frame_io_position = 0;\n c->private_impl.first_frame_is_opaque = 0;\n}\n\nstatic inline void //\nwuffs_base__image_config__invalidate(wuffs_base__image_config* c) {\n if (c) {\n c->pixcfg.private_impl.pixfmt = 0;\n c->pixcfg.private_impl.pixsub = 0;\n c->pixcfg.private_impl.width = 0;\n c->pixcfg.private_impl.height = 0;\n c->private_impl.first_frame_io_position = 0;\n c->private_impl.first_frame_is_opaque = 0;\n }\n}\n\nstatic inline bool //\nwuffs_base__image_config__is_valid(wuffs_base__image_config* c) {\n return c && wuffs_base__pixel_config__is_valid(&(c->pixcfg));\n}\n\nstatic inline uint64_t //\nwuffs_base__image_config__first_frame_io_position(wuffs_base__image_config* c) {\n return c ? c->private_impl.first_frame_io_position : 0;\n}\n\nstatic inline bool //\nwuffs_base__image_config__first_frame_is_opaque(wuffs_base__image_config* c) {\n return c ? c->private_impl.first_frame_is_opaque : false;\n}\n\n#ifdef __cplusplus\n\ninline void " +
+ " //\nwuffs_base__image_config::set(wuffs_base__pixel_format pixfmt,\n wuffs_base__pixel_subsampling pixsub,\n uint32_t width,\n uint32_t height,\n uint64_t first_frame_io_position,\n bool first_frame_is_opaque) {\n wuffs_base__image_config__set(this, pixfmt, pixsub, width, height,\n first_frame_io_position, first_frame_is_opaque);\n}\n\ninline void //\nwuffs_base__image_config::invalidate() {\n wuffs_base__image_config__invalidate(this);\n}\n\ninline bool //\nwuffs_base__image_config::is_valid() {\n return wuffs_base__image_config__is_valid(this);\n}\n\ninline uint64_t //\nwuffs_base__image_config::first_frame_io_position() {\n return wuffs_base__image_config__first_frame_io_position(this);\n}\n\ninline bool //\nwuffs_base__image_config::first_frame_is_opaque() {\n return wuffs_base__image_config__first_frame_is_opaque(this);\n}\n\n#endif // __cplusplus\n\n" +
+ "" +
+ "// --------\n\n// wuffs_base__animation_blend encodes, for an animated image, how to blend the\n// transparent pixels of this frame with the existing canvas. In Porter-Duff\n// compositing operator terminology:\n// - 0 means the frame may be transparent, and should be blended \"src over\n// dst\", also known as just \"over\".\n// - 1 means the frame may be transparent, and should be blended \"src\".\n// - 2 means the frame is completely opaque, so that \"src over dst\" and \"src\"\n// are equivalent.\n//\n// These semantics are conservative. It is valid for a completely opaque frame\n// to have a blend value other than 2.\ntypedef uint8_t wuffs_base__animation_blend;\n\n#define WUFFS_BASE__ANIMATION_BLEND__SRC_OVER_DST \\\n ((wuffs_base__animation_blend)0)\n#define WUFFS_BASE__ANIMATION_BLEND__SRC ((wuffs_base__animation_blend)1)\n#define WUFFS_BASE__ANIMATION_BLEND__OPAQUE ((wuffs_base__animation_blend)2)\n\n" +
+ "" +
+ "// --------\n\n// wuffs_base__animation_disposal encodes, for an animated image, how to\n// dispose of a frame after displaying it:\n// - None means to draw the next frame on top of this one.\n// - Restore Background means to clear the frame's dirty rectangle to \"the\n// background color\" (in practice, this means transparent black) before\n// drawing the next frame.\n// - Restore Previous means to undo the current frame, so that the next frame\n// is drawn on top of the previous one.\ntypedef uint8_t wuffs_base__animation_disposal;\n\n#define WUFFS_BASE__ANIMATION_DISPOSAL__NONE ((wuffs_base__animation_disposal)0)\n#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_BACKGROUND \\\n ((wuffs_base__animation_disposal)1)\n#define WUFFS_BASE__ANIMATION_DISPOSAL__RESTORE_PREVIOUS \\\n ((wuffs_base__animation_disposal)2)\n\n" +
+ "" +
+ "// --------\n\ntypedef struct {\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__rect_ie_u32 bounds;\n wuffs_base__flicks duration;\n uint64_t index;\n uint64_t io_position;\n wuffs_base__animation_blend blend;\n wuffs_base__animation_disposal disposal;\n } private_impl;\n\n#ifdef __cplusplus\n inline void update(wuffs_base__rect_ie_u32 bounds,\n wuffs_base__flicks duration,\n uint64_t index,\n uint64_t io_position,\n wuffs_base__animation_blend blend,\n wuffs_base__animation_disposal disposal);\n inline wuffs_base__rect_ie_u32 bounds();\n inline uint32_t width();\n inline uint32_t height();\n inline wuffs_base__flicks duration();\n inline uint64_t index();\n inline uint64_t io_position();\n inline wuffs_base__animation_blend blend();\n inline wuffs_base__animation_disposal disposal();\n#endif // __cpluspl" +
+ "us\n\n} wuffs_base__frame_config;\n\nstatic inline wuffs_base__frame_config //\nwuffs_base__null_frame_config() {\n wuffs_base__frame_config ret;\n ret.private_impl.bounds = wuffs_base__make_rect_ie_u32(0, 0, 0, 0);\n ret.private_impl.duration = 0;\n ret.private_impl.index = 0;\n ret.private_impl.io_position = 0;\n ret.private_impl.blend = 0;\n ret.private_impl.disposal = 0;\n return ret;\n}\n\nstatic inline void //\nwuffs_base__frame_config__update(wuffs_base__frame_config* c,\n wuffs_base__rect_ie_u32 bounds,\n wuffs_base__flicks duration,\n uint64_t index,\n uint64_t io_position,\n wuffs_base__animation_blend blend,\n wuffs_base__animation_disposal disposal) {\n if (!c) {\n return;\n }\n\n c->private_impl.bounds = bounds;\n c->private_impl.duration = duration;\n c->private_impl.index = index;\n c->private_impl.io_position = io_po" +
+ "sition;\n c->private_impl.blend = blend;\n c->private_impl.disposal = disposal;\n}\n\nstatic inline wuffs_base__rect_ie_u32 //\nwuffs_base__frame_config__bounds(wuffs_base__frame_config* c) {\n if (c) {\n return c->private_impl.bounds;\n }\n\n wuffs_base__rect_ie_u32 ret;\n ret.min_incl_x = 0;\n ret.min_incl_y = 0;\n ret.max_excl_x = 0;\n ret.max_excl_y = 0;\n return ret;\n}\n\nstatic inline uint32_t //\nwuffs_base__frame_config__width(wuffs_base__frame_config* c) {\n return c ? wuffs_base__rect_ie_u32__width(&c->private_impl.bounds) : 0;\n}\n\nstatic inline uint32_t //\nwuffs_base__frame_config__height(wuffs_base__frame_config* c) {\n return c ? wuffs_base__rect_ie_u32__height(&c->private_impl.bounds) : 0;\n}\n\n// wuffs_base__frame_config__duration returns the amount of time to display\n// this frame. Zero means to display forever - a still (non-animated) image.\nstatic inline wuffs_base__flicks //\nwuffs_base__frame_config__duration(wuffs_base__frame_config* c) {\n return c ? c->private_impl.duration : 0;\n}\n\n// wuffs_b" +
+ "ase__frame_config__index returns the index of this frame. The first\n// frame in an image has index 0, the second frame has index 1, and so on.\nstatic inline uint64_t //\nwuffs_base__frame_config__index(wuffs_base__frame_config* c) {\n return c ? c->private_impl.index : 0;\n}\n\n// wuffs_base__frame_config__io_position returns the I/O stream position before\n// the frame config.\nstatic inline uint64_t //\nwuffs_base__frame_config__io_position(wuffs_base__frame_config* c) {\n return c ? c->private_impl.io_position : 0;\n}\n\n// wuffs_base__frame_config__blend returns, for an animated image, how to blend\n// the transparent pixels of this frame with the existing canvas.\nstatic inline wuffs_base__animation_blend //\nwuffs_base__frame_config__blend(wuffs_base__frame_config* c) {\n return c ? c->private_impl.blend : 0;\n}\n\n// wuffs_base__frame_config__disposal returns, for an animated image, how to\n// dispose of this frame after displaying it.\nstatic inline wuffs_base__animation_disposal //\nwuffs_base__frame_config__dispos" +
+ "al(wuffs_base__frame_config* c) {\n return c ? c->private_impl.disposal : 0;\n}\n\n#ifdef __cplusplus\n\ninline void //\nwuffs_base__frame_config::update(wuffs_base__rect_ie_u32 bounds,\n wuffs_base__flicks duration,\n uint64_t index,\n uint64_t io_position,\n wuffs_base__animation_blend blend,\n wuffs_base__animation_disposal disposal) {\n wuffs_base__frame_config__update(this, bounds, duration, index, io_position,\n blend, disposal);\n}\n\ninline wuffs_base__rect_ie_u32 //\nwuffs_base__frame_config::bounds() {\n return wuffs_base__frame_config__bounds(this);\n}\n\ninline uint32_t //\nwuffs_base__frame_config::width() {\n return wuffs_base__frame_config__width(this);\n}\n\ninline uint32_t //\nwuffs_base__frame_config::height() {\n return wuffs_base__frame_config__height(this);\n}\n\ninline wuffs_base__flicks //\nwuffs_base__frame_config::du" +
+ "ration() {\n return wuffs_base__frame_config__duration(this);\n}\n\ninline uint64_t //\nwuffs_base__frame_config::index() {\n return wuffs_base__frame_config__index(this);\n}\n\ninline uint64_t //\nwuffs_base__frame_config::io_position() {\n return wuffs_base__frame_config__io_position(this);\n}\n\ninline wuffs_base__animation_blend //\nwuffs_base__frame_config::blend() {\n return wuffs_base__frame_config__blend(this);\n}\n\ninline wuffs_base__animation_disposal //\nwuffs_base__frame_config::disposal() {\n return wuffs_base__frame_config__disposal(this);\n}\n\n#endif // __cplusplus\n\n" +
+ "" +
+ "// --------\n\ntypedef struct {\n wuffs_base__pixel_config pixcfg;\n\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__table_u8 planes[WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX];\n // TODO: color spaces.\n } private_impl;\n\n#ifdef __cplusplus\n inline wuffs_base__status set_from_slice(wuffs_base__pixel_config* pixcfg,\n wuffs_base__slice_u8 pixbuf_memory);\n inline wuffs_base__slice_u8 palette();\n inline wuffs_base__pixel_format pixel_format();\n inline wuffs_base__table_u8 plane(uint32_t p);\n#endif // __cplusplus\n\n} wuffs_base__pixel_buffer;\n\nstatic inline wuffs_base__pixel_buffer //\nwuffs_base__null_pixel_buffer() {\n wuffs_base__pixel_buffer ret;\n ret.pixcfg = wuffs_base__null_pixel_config();\n ret.private_impl.planes[0] = wuffs_base__null_table_u8();\n ret.private_impl.planes[1] = wuffs_base__null_table_u8();\n ret.private_impl.planes[2] = wuffs_base__null_tabl" +
+ "e_u8();\n ret.private_impl.planes[3] = wuffs_base__null_table_u8();\n return ret;\n}\n\nstatic inline wuffs_base__status //\nwuffs_base__pixel_buffer__set_from_slice(wuffs_base__pixel_buffer* b,\n wuffs_base__pixel_config* pixcfg,\n wuffs_base__slice_u8 pixbuf_memory) {\n if (!b) {\n return wuffs_base__error__bad_receiver;\n }\n memset(b, 0, sizeof(*b));\n if (!pixcfg) {\n return wuffs_base__error__bad_argument;\n }\n if (wuffs_base__pixel_format__is_planar(pixcfg->private_impl.pixfmt)) {\n // TODO: support planar pixel formats, concious of pixel subsampling.\n return wuffs_base__error__bad_argument;\n }\n uint32_t bits_per_pixel =\n wuffs_base__pixel_format__bits_per_pixel(pixcfg->private_impl.pixfmt);\n if ((bits_per_pixel == 0) || ((bits_per_pixel % 8) != 0)) {\n return wuffs_base__error__bad_argument;\n }\n uint64_t bytes_per_pixel = bits_per_pixel / 8;\n\n uint8_t* ptr = pixbuf_memory.ptr;\n uint64_t len = pixbuf_memo" +
+ "ry.len;\n if (wuffs_base__pixel_format__is_indexed(pixcfg->private_impl.pixfmt)) {\n // Split a 1024 byte chunk (256 palette entries × 4 bytes per entry) from\n // the start of pixbuf_memory. We split from the start, not the end, so\n // that the both chunks' pointers have the same alignment as the original\n // pointer, up to an alignment of 1024.\n if (len < 1024) {\n return wuffs_base__error__bad_argument_length_too_short;\n }\n wuffs_base__table_u8* tab =\n &b->private_impl.planes[WUFFS_BASE__PIXEL_FORMAT__INDEXED__COLOR_PLANE];\n tab->ptr = ptr;\n tab->width = 1024;\n tab->height = 1;\n tab->stride = 1024;\n ptr += 1024;\n len -= 1024;\n }\n\n uint64_t wh = ((uint64_t)pixcfg->private_impl.width) *\n ((uint64_t)pixcfg->private_impl.height);\n size_t width = (size_t)(pixcfg->private_impl.width);\n if ((wh > (UINT64_MAX / bytes_per_pixel)) ||\n (width > (SIZE_MAX / bytes_per_pixel))) {\n return wuffs_base__error__bad_argument;\n }\n wh *= bytes_per_pix" +
+ "el;\n width *= bytes_per_pixel;\n if (wh > len) {\n return wuffs_base__error__bad_argument_length_too_short;\n }\n\n b->pixcfg = *pixcfg;\n wuffs_base__table_u8* tab = &b->private_impl.planes[0];\n tab->ptr = ptr;\n tab->width = width;\n tab->height = pixcfg->private_impl.height;\n tab->stride = width;\n return NULL;\n}\n\n// wuffs_base__pixel_buffer__palette returns the palette color data. If\n// non-empty, it will have length 1024.\nstatic inline wuffs_base__slice_u8 //\nwuffs_base__pixel_buffer__palette(wuffs_base__pixel_buffer* b) {\n if (b &&\n wuffs_base__pixel_format__is_indexed(b->pixcfg.private_impl.pixfmt)) {\n wuffs_base__table_u8* tab =\n &b->private_impl.planes[WUFFS_BASE__PIXEL_FORMAT__INDEXED__COLOR_PLANE];\n if ((tab->width == 1024) && (tab->height == 1)) {\n return wuffs_base__make_slice_u8(tab->ptr, 1024);\n }\n }\n return wuffs_base__make_slice_u8(NULL, 0);\n}\n\nstatic inline wuffs_base__pixel_format //\nwuffs_base__pixel_buffer__pixel_format(wuffs_base__pixel_buffer* b) {\n i" +
+ "f (b) {\n return b->pixcfg.private_impl.pixfmt;\n }\n return WUFFS_BASE__PIXEL_FORMAT__INVALID;\n}\n\nstatic inline wuffs_base__table_u8 //\nwuffs_base__pixel_buffer__plane(wuffs_base__pixel_buffer* b, uint32_t p) {\n if (b && (p < WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX)) {\n return b->private_impl.planes[p];\n }\n\n wuffs_base__table_u8 ret;\n ret.ptr = NULL;\n ret.width = 0;\n ret.height = 0;\n ret.stride = 0;\n return ret;\n}\n\n#ifdef __cplusplus\n\ninline wuffs_base__status //\nwuffs_base__pixel_buffer::set_from_slice(wuffs_base__pixel_config* pixcfg,\n wuffs_base__slice_u8 pixbuf_memory) {\n return wuffs_base__pixel_buffer__set_from_slice(this, pixcfg, pixbuf_memory);\n}\n\ninline wuffs_base__slice_u8 //\nwuffs_base__pixel_buffer::palette() {\n return wuffs_base__pixel_buffer__palette(this);\n}\n\ninline wuffs_base__pixel_format //\nwuffs_base__pixel_buffer::pixel_format() {\n return wuffs_base__pixel_buffer__pixel_format(this);\n}\n\ninline wuffs_base__table_u8 //\nwuffs_base" +
+ "__pixel_buffer::plane(uint32_t p) {\n return wuffs_base__pixel_buffer__plane(this, p);\n}\n\n#endif // __cplusplus\n\n" +
+ "" +
+ "// --------\n\ntypedef struct {\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 uint8_t TODO;\n } private_impl;\n\n#ifdef __cplusplus\n#endif // __cplusplus\n\n} wuffs_base__decode_frame_options;\n\n#ifdef __cplusplus\n\n#endif // __cplusplus\n\n" +
+ "" +
+ "// --------\n\ntypedef struct {\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 // TODO: should the func type take restrict pointers?\n uint64_t (*func)(wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src);\n } private_impl;\n\n#ifdef __cplusplus\n inline void prepare(wuffs_base__pixel_format dst_format,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__pixel_format src_format,\n wuffs_base__slice_u8 src_palette);\n inline uint64_t swizzle_packed(wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src);\n#endif // __cplusplus\n\n} wuffs_base__pixel_swizzler;\n\n// TODO: should prepare (both the C and C++ methods) return a status?\n\nvoid //\nwuffs_base__pixel_swizzler__prepare(wuffs_base__pixel_swi" +
+ "zzler* p,\n wuffs_base__pixel_format dst_format,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__pixel_format src_format,\n wuffs_base__slice_u8 src_palette);\n\nuint64_t //\nwuffs_base__pixel_swizzler__swizzle_packed(wuffs_base__pixel_swizzler* p,\n wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src);\n\n#ifdef __cplusplus\n\ninline void //\nwuffs_base__pixel_swizzler::prepare(wuffs_base__pixel_format dst_format,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__pixel_format src_format,\n wuffs_base__slice_u8 src_palette) {\n wuffs_base__pixel_swizzler__prepare(this, dst_format, dst_palette, src_format,\n " +
+ " src_palette);\n}\n\nuint64_t //\nwuffs_base__pixel_swizzler::swizzle_packed(wuffs_base__slice_u8 dst,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src) {\n return wuffs_base__pixel_swizzler__swizzle_packed(this, dst, dst_palette,\n src);\n}\n\n#endif // __cplusplus\n" +
+ ""
+
+const baseIOPrivateH = "" +
+ "// ---------------- I/O\n\nstatic inline bool //\nwuffs_base__io_buffer__is_valid(wuffs_base__io_buffer buf) {\n return (buf.data.ptr || (buf.data.len == 0)) &&\n (buf.data.len >= buf.meta.wi) && (buf.meta.wi >= buf.meta.ri);\n}\n\n// TODO: wuffs_base__io_reader__is_eof is no longer used by Wuffs per se, but\n// it might be handy to programs that use Wuffs. Either delete it, or promote\n// it to the public API.\n//\n// If making this function public (i.e. moving it to base-header.h), it also\n// needs to allow NULL (i.e. implicit, callee-calculated) mark/limit.\n\nstatic inline bool //\nwuffs_base__io_reader__is_eof(wuffs_base__io_reader o) {\n wuffs_base__io_buffer* buf = o.private_impl.buf;\n return buf && buf->meta.closed &&\n (buf->data.ptr + buf->meta.wi == o.private_impl.limit);\n}\n\nstatic inline bool //\nwuffs_base__io_reader__is_valid(wuffs_base__io_reader o) {\n wuffs_base__io_buffer* buf = o.private_impl.buf;\n // Note: if making this function public (i.e. moving it to base-header.h), it\n // also " +
+ "needs to allow NULL (i.e. implicit, callee-calculated) mark/limit.\n return buf ? ((buf->data.ptr <= o.private_impl.mark) &&\n (o.private_impl.mark <= o.private_impl.limit) &&\n (o.private_impl.limit <= buf->data.ptr + buf->data.len))\n : ((o.private_impl.mark == NULL) &&\n (o.private_impl.limit == NULL));\n}\n\nstatic inline bool //\nwuffs_base__io_writer__is_valid(wuffs_base__io_writer o) {\n wuffs_base__io_buffer* buf = o.private_impl.buf;\n // Note: if making this function public (i.e. moving it to base-header.h), it\n // also needs to allow NULL (i.e. implicit, callee-calculated) mark/limit.\n return buf ? ((buf->data.ptr <= o.private_impl.mark) &&\n (o.private_impl.mark <= o.private_impl.limit) &&\n (o.private_impl.limit <= buf->data.ptr + buf->data.len))\n : ((o.private_impl.mark == NULL) &&\n (o.private_impl.limit == NULL));\n}\n\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n_from_history(uin" +
+ "t8_t** ptr_iop_w,\n uint8_t* io0_w,\n uint8_t* io1_w,\n uint32_t length,\n uint32_t distance) {\n if (!distance) {\n return 0;\n }\n uint8_t* p = *ptr_iop_w;\n if ((size_t)(p - io0_w) < (size_t)(distance)) {\n return 0;\n }\n uint8_t* q = p - distance;\n size_t n = (size_t)(io1_w - p);\n if ((size_t)(length) > n) {\n length = (uint32_t)(n);\n } else {\n n = (size_t)(length);\n }\n // TODO: unrolling by 3 seems best for the std/deflate benchmarks, but that\n // is mostly because 3 is the minimum length for the deflate format. This\n // function implementation shouldn't overfit to that one format. Perhaps the\n // copy_n_from_history Wuffs method should 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__io_writer__copy_n_from_history_fast below.\n //\n " +
+ "// Alternatively, or additionally, have a sloppy_copy_n_from_history method\n // that copies 8 bytes at a time, possibly writing more than length bytes?\n for (; n >= 3; n -= 3) {\n *p++ = *q++;\n *p++ = *q++;\n *p++ = *q++;\n }\n for (; n; n--) {\n *p++ = *q++;\n }\n *ptr_iop_w = p;\n return length;\n}\n\n// wuffs_base__io_writer__copy_n_from_history_fast is like the\n// wuffs_base__io_writer__copy_n_from_history function above, but has stronger\n// pre-conditions. The caller needs to prove that:\n// - distance > 0\n// - distance <= (*ptr_iop_w - io0_w)\n// - length <= (io1_w - *ptr_iop_w)\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n_from_history_fast(uint8_t** ptr_iop_w,\n uint8_t* io0_w,\n uint8_t* io1_w,\n uint32_t length,\n uint32_t distance) {\n uint8_t* p = *ptr_iop_w;\n uint8_t* q = p - distance;\n " +
+ " uint32_t n = length;\n for (; n >= 3; n -= 3) {\n *p++ = *q++;\n *p++ = *q++;\n *p++ = *q++;\n }\n for (; n; n--) {\n *p++ = *q++;\n }\n *ptr_iop_w = p;\n return length;\n}\n\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n_from_reader(uint8_t** ptr_iop_w,\n uint8_t* io1_w,\n uint32_t length,\n uint8_t** ptr_iop_r,\n uint8_t* io1_r) {\n uint8_t* iop_w = *ptr_iop_w;\n size_t n = length;\n if (n > ((size_t)(io1_w - iop_w))) {\n n = (size_t)(io1_w - iop_w);\n }\n uint8_t* iop_r = *ptr_iop_r;\n if (n > ((size_t)(io1_r - iop_r))) {\n n = (size_t)(io1_r - iop_r);\n }\n if (n > 0) {\n memmove(iop_w, iop_r, n);\n *ptr_iop_w += n;\n *ptr_iop_r += n;\n }\n return (uint32_t)(n);\n}\n\nstatic inline uint64_t //\nwuffs_base__io_writer__copy_from_slice(uint8_t** ptr_iop_w,\n uint8_t* io1_w,\n " +
+ " wuffs_base__slice_u8 src) {\n uint8_t* iop_w = *ptr_iop_w;\n size_t n = src.len;\n if (n > ((size_t)(io1_w - iop_w))) {\n n = (size_t)(io1_w - iop_w);\n }\n if (n > 0) {\n memmove(iop_w, src.ptr, n);\n *ptr_iop_w += n;\n }\n return (uint64_t)(n);\n}\n\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n_from_slice(uint8_t** ptr_iop_w,\n uint8_t* io1_w,\n uint32_t length,\n wuffs_base__slice_u8 src) {\n uint8_t* iop_w = *ptr_iop_w;\n size_t n = src.len;\n if (n > length) {\n n = length;\n }\n if (n > ((size_t)(io1_w - iop_w))) {\n n = (size_t)(io1_w - iop_w);\n }\n if (n > 0) {\n memmove(iop_w, src.ptr, n);\n *ptr_iop_w += n;\n }\n return (uint32_t)(n);\n}\n\nstatic inline wuffs_base__empty_struct //\nwuffs_base__io_reader__set(wuffs_base__io_reader* o,\n wuffs_base__io_buffer* b,\n uint8_t** ptr_iop_r,\n " +
+ " uint8_t** ptr_io1_r,\n wuffs_base__slice_u8 data) {\n b->data = data;\n b->meta.wi = data.len;\n b->meta.ri = 0;\n b->meta.pos = 0;\n b->meta.closed = false;\n\n o->private_impl.buf = b;\n o->private_impl.mark = data.ptr;\n o->private_impl.limit = data.ptr + data.len;\n *ptr_iop_r = data.ptr;\n *ptr_io1_r = data.ptr + data.len;\n\n wuffs_base__empty_struct ret;\n ret.private_impl = 0;\n return ret;\n}\n\nstatic inline wuffs_base__empty_struct //\nwuffs_base__io_reader__set_limit(wuffs_base__io_reader* o,\n uint8_t* iop_r,\n uint64_t limit) {\n if (o && (((size_t)(o->private_impl.limit - iop_r)) > limit)) {\n o->private_impl.limit = iop_r + limit;\n }\n\n wuffs_base__empty_struct ret;\n ret.private_impl = 0;\n return ret;\n}\n\nstatic inline wuffs_base__empty_struct //\nwuffs_base__io_reader__set_mark(wuffs_base__io_reader* o, uint8_t* mark) {\n o->private_impl.mark = mark;\n\n wuffs_base__empty_struct ret;\n ret." +
+ "private_impl = 0;\n return ret;\n}\n\nstatic inline wuffs_base__slice_u8 //\nwuffs_base__io_reader__take(uint8_t** ptr_iop_r, uint8_t* io1_r, uint64_t n) {\n if (n <= ((size_t)(io1_r - *ptr_iop_r))) {\n uint8_t* p = *ptr_iop_r;\n *ptr_iop_r += n;\n return wuffs_base__make_slice_u8(p, n);\n }\n return wuffs_base__make_slice_u8(NULL, 0);\n}\n\nstatic inline wuffs_base__empty_struct //\nwuffs_base__io_writer__set(wuffs_base__io_writer* o,\n wuffs_base__io_buffer* b,\n uint8_t** ptr_iop_w,\n uint8_t** ptr_io1_w,\n wuffs_base__slice_u8 data) {\n b->data = data;\n b->meta.wi = 0;\n b->meta.ri = 0;\n b->meta.pos = 0;\n b->meta.closed = false;\n\n o->private_impl.buf = b;\n o->private_impl.mark = data.ptr;\n o->private_impl.limit = data.ptr + data.len;\n *ptr_iop_w = data.ptr;\n *ptr_io1_w = data.ptr + data.len;\n\n wuffs_base__empty_struct ret;\n ret.private_impl = 0;\n return ret;\n}\n\nstatic inline wuffs_base__empty_str" +
+ "uct //\nwuffs_base__io_writer__set_mark(wuffs_base__io_writer* o, uint8_t* mark) {\n o->private_impl.mark = mark;\n\n wuffs_base__empty_struct ret;\n ret.private_impl = 0;\n return ret;\n}\n\n" +
+ "" +
+ "// ---------------- I/O (Utility)\n\n#define wuffs_base__utility__null_io_reader wuffs_base__null_io_reader\n#define wuffs_base__utility__null_io_writer wuffs_base__null_io_writer\n" +
+ ""
+
+const baseIOPublicH = "" +
+ "// ---------------- I/O\n\nstruct wuffs_base__io_buffer__struct;\n\ntypedef struct {\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 struct wuffs_base__io_buffer__struct* buf;\n // The bounds values are typically NULL, when created by the Wuffs public\n // API. NULL means that the callee substitutes the implicit bounds derived\n // from buf.\n uint8_t* mark;\n uint8_t* limit;\n } private_impl;\n} wuffs_base__io_reader;\n\ntypedef struct {\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 struct wuffs_base__io_buffer__struct* buf;\n // The bounds values are typically NULL, when created by the Wuffs public\n // API. NULL means that the callee substitutes the implicit bounds derived\n // from buf.\n uint8_t* mark;\n uint8_t* limit;\n } private_impl;\n} wuffs_base__io_writer;\n\n// wuffs_base__io_buffer_meta is the met" +
+ "adata for a wuffs_base__io_buffer's\n// data.\ntypedef struct {\n size_t wi; // Write index. Invariant: wi <= len.\n size_t ri; // Read index. Invariant: ri <= wi.\n uint64_t pos; // Position of the buffer start relative to the stream start.\n bool closed; // No further writes are expected.\n} wuffs_base__io_buffer_meta;\n\n// wuffs_base__io_buffer is a 1-dimensional buffer (a pointer and length) plus\n// additional metadata.\n//\n// A value with all fields zero is a valid, empty buffer.\ntypedef struct wuffs_base__io_buffer__struct {\n wuffs_base__slice_u8 data;\n wuffs_base__io_buffer_meta meta;\n\n#ifdef __cplusplus\n inline void compact();\n inline wuffs_base__io_reader reader();\n inline wuffs_base__io_writer writer();\n inline uint64_t reader_io_position();\n inline uint64_t writer_io_position();\n#endif // __cplusplus\n\n} wuffs_base__io_buffer;\n\nstatic inline wuffs_base__io_buffer //\nwuffs_base__make_io_buffer(wuffs_base__slice_u8 data,\n wuffs_base__io_buffer_meta meta) {\n w" +
+ "uffs_base__io_buffer ret;\n ret.data = data;\n ret.meta = meta;\n return ret;\n}\n\nstatic inline wuffs_base__io_buffer_meta //\nwuffs_base__make_io_buffer_meta(size_t wi,\n size_t ri,\n uint64_t pos,\n bool closed) {\n wuffs_base__io_buffer_meta ret;\n ret.wi = wi;\n ret.ri = ri;\n ret.pos = pos;\n ret.closed = closed;\n return ret;\n}\n\nstatic inline wuffs_base__io_buffer //\nwuffs_base__null_io_buffer() {\n wuffs_base__io_buffer ret;\n ret.data.ptr = NULL;\n ret.data.len = 0;\n ret.meta.wi = 0;\n ret.meta.ri = 0;\n ret.meta.pos = 0;\n ret.meta.closed = false;\n return ret;\n}\n\nstatic inline wuffs_base__io_buffer_meta //\nwuffs_base__null_io_buffer_meta() {\n wuffs_base__io_buffer_meta ret;\n ret.wi = 0;\n ret.ri = 0;\n ret.pos = 0;\n ret.closed = false;\n return ret;\n}\n\nstatic inline wuffs_base__io_reader //\nwuffs_base__null_io_reader() {\n wuffs_base__io_reader ret;\n ret.private_impl.buf = NULL;\n ret.private_impl.mark =" +
+ " NULL;\n ret.private_impl.limit = NULL;\n return ret;\n}\n\nstatic inline wuffs_base__io_writer //\nwuffs_base__null_io_writer() {\n wuffs_base__io_writer ret;\n ret.private_impl.buf = NULL;\n ret.private_impl.mark = NULL;\n ret.private_impl.limit = NULL;\n return ret;\n}\n\n// wuffs_base__io_buffer__compact moves any written but unread bytes to the\n// start of the buffer.\nstatic inline void //\nwuffs_base__io_buffer__compact(wuffs_base__io_buffer* buf) {\n if (!buf || (buf->meta.ri == 0)) {\n return;\n }\n buf->meta.pos = wuffs_base__u64__sat_add(buf->meta.pos, buf->meta.ri);\n size_t n = buf->meta.wi - buf->meta.ri;\n if (n != 0) {\n memmove(buf->data.ptr, buf->data.ptr + buf->meta.ri, n);\n }\n buf->meta.wi = n;\n buf->meta.ri = 0;\n}\n\nstatic inline wuffs_base__io_reader //\nwuffs_base__io_buffer__reader(wuffs_base__io_buffer* buf) {\n wuffs_base__io_reader ret;\n ret.private_impl.buf = buf;\n ret.private_impl.mark = NULL;\n ret.private_impl.limit = NULL;\n return ret;\n}\n\nstatic inline wuffs_base__io_writer " +
+ "//\nwuffs_base__io_buffer__writer(wuffs_base__io_buffer* buf) {\n wuffs_base__io_writer ret;\n ret.private_impl.buf = buf;\n ret.private_impl.mark = NULL;\n ret.private_impl.limit = NULL;\n return ret;\n}\n\nstatic inline uint64_t //\nwuffs_base__io_buffer__reader_io_position(wuffs_base__io_buffer* buf) {\n return buf ? wuffs_base__u64__sat_add(buf->meta.pos, buf->meta.ri) : 0;\n}\n\nstatic inline uint64_t //\nwuffs_base__io_buffer__writer_io_position(wuffs_base__io_buffer* buf) {\n return buf ? wuffs_base__u64__sat_add(buf->meta.pos, buf->meta.wi) : 0;\n}\n\n#ifdef __cplusplus\n\ninline void //\nwuffs_base__io_buffer__struct::compact() {\n wuffs_base__io_buffer__compact(this);\n}\n\ninline wuffs_base__io_reader //\nwuffs_base__io_buffer__struct::reader() {\n return wuffs_base__io_buffer__reader(this);\n}\n\ninline wuffs_base__io_writer //\nwuffs_base__io_buffer__struct::writer() {\n return wuffs_base__io_buffer__writer(this);\n}\n\ninline uint64_t //\nwuffs_base__io_buffer__struct::reader_io_position() {\n return wuffs_base__io_" +
+ "buffer__reader_io_position(this);\n}\n\ninline uint64_t //\nwuffs_base__io_buffer__struct::writer_io_position() {\n return wuffs_base__io_buffer__writer_io_position(this);\n}\n\n#endif // __cplusplus\n" +
+ ""
+
+const baseRangePrivateH = "" +
+ "// ---------------- Ranges and Rects\n\nstatic inline uint32_t //\nwuffs_base__range_ii_u32__get_min_incl(const wuffs_base__range_ii_u32* r) {\n return r->min_incl;\n}\n\nstatic inline uint32_t //\nwuffs_base__range_ii_u32__get_max_incl(const wuffs_base__range_ii_u32* r) {\n return r->max_incl;\n}\n\nstatic inline uint32_t //\nwuffs_base__range_ie_u32__get_min_incl(const wuffs_base__range_ie_u32* r) {\n return r->min_incl;\n}\n\nstatic inline uint32_t //\nwuffs_base__range_ie_u32__get_max_excl(const wuffs_base__range_ie_u32* r) {\n return r->max_excl;\n}\n\nstatic inline uint64_t //\nwuffs_base__range_ii_u64__get_min_incl(const wuffs_base__range_ii_u64* r) {\n return r->min_incl;\n}\n\nstatic inline uint64_t //\nwuffs_base__range_ii_u64__get_max_incl(const wuffs_base__range_ii_u64* r) {\n return r->max_incl;\n}\n\nstatic inline uint64_t //\nwuffs_base__range_ie_u64__get_min_incl(const wuffs_base__range_ie_u64* r) {\n return r->min_incl;\n}\n\nstatic inline uint64_t //\nwuffs_base__range_ie_u64__get_max_excl(const wuffs_base__range_" +
+ "ie_u64* r) {\n return r->max_excl;\n}\n\n" +
+ "" +
+ "// ---------------- Ranges and Rects (Utility)\n\n#define wuffs_base__utility__make_range_ii_u32 wuffs_base__make_range_ii_u32\n#define wuffs_base__utility__make_range_ie_u32 wuffs_base__make_range_ie_u32\n#define wuffs_base__utility__make_range_ii_u64 wuffs_base__make_range_ii_u64\n#define wuffs_base__utility__make_range_ie_u64 wuffs_base__make_range_ie_u64\n#define wuffs_base__utility__make_rect_ii_u32 wuffs_base__make_rect_ii_u32\n#define wuffs_base__utility__make_rect_ie_u32 wuffs_base__make_rect_ie_u32\n\n" +
+ ""
+
+const baseRangePublicH = "" +
+ "// ---------------- Ranges and Rects\n\n// Ranges are either inclusive (\"range_ii\") or exclusive (\"range_ie\") on the\n// high end. Both the \"ii\" and \"ie\" flavors are useful in practice.\n//\n// The \"ei\" and \"ee\" flavors also exist in theory, but aren't widely used. In\n// Wuffs, the low end is always inclusive.\n//\n// The \"ii\" (closed interval) flavor is useful when refining e.g. \"the set of\n// all uint32_t values\" to a contiguous subset: \"uint32_t values in the closed\n// interval [M, N]\", for uint32_t values M and N. An unrefined type (in other\n// words, the set of all uint32_t values) is not representable in the \"ie\"\n// flavor because if N equals ((1<<32) - 1) then (N + 1) will overflow.\n//\n// On the other hand, the \"ie\" (half-open interval) flavor is recommended by\n// Dijkstra's \"Why numbering should start at zero\" at\n// http://www.cs.utexas.edu/users/EWD/ewd08xx/EWD831.PDF and a further\n// discussion of motivating rationale is at\n// https://www.quora.com/Why-are-Python-ranges-half-open-exclusive-instead-of-close" +
+ "d-inclusive\n//\n// For example, with \"ie\", the number of elements in \"uint32_t values in the\n// half-open interval [M, N)\" is equal to max(0, N-M). Furthermore, that number\n// of elements (in one dimension, a length, in two dimensions, a width or\n// height) is itself representable as a uint32_t without overflow, again for\n// uint32_t values M and N. In the contrasting \"ii\" flavor, the length of the\n// closed interval [0, (1<<32) - 1] is 1<<32, which cannot be represented as a\n// uint32_t. In Wuffs, because of this potential overflow, the \"ie\" flavor has\n// length / width / height methods, but the \"ii\" flavor does not.\n//\n// It is valid for min > max (for range_ii) or for min >= max (for range_ie),\n// in which case the range is empty. There are multiple representations of an\n// empty range.\n\ntypedef struct wuffs_base__range_ii_u32__struct {\n uint32_t min_incl;\n uint32_t max_incl;\n\n#ifdef __cplusplus\n inline bool is_empty();\n inline bool equals(wuffs_base__range_ii_u32__struct s);\n inline wuffs_base__range_" +
+ "ii_u32__struct intersect(\n wuffs_base__range_ii_u32__struct s);\n inline wuffs_base__range_ii_u32__struct unite(\n wuffs_base__range_ii_u32__struct s);\n inline bool contains(uint32_t x);\n inline bool contains_range(wuffs_base__range_ii_u32__struct s);\n#endif // __cplusplus\n\n} wuffs_base__range_ii_u32;\n\nstatic inline wuffs_base__range_ii_u32 //\nwuffs_base__make_range_ii_u32(uint32_t min_incl, uint32_t max_incl) {\n wuffs_base__range_ii_u32 ret;\n ret.min_incl = min_incl;\n ret.max_incl = max_incl;\n return ret;\n}\n\nstatic inline bool //\nwuffs_base__range_ii_u32__is_empty(wuffs_base__range_ii_u32* r) {\n return r->min_incl > r->max_incl;\n}\n\nstatic inline bool //\nwuffs_base__range_ii_u32__equals(wuffs_base__range_ii_u32* r,\n wuffs_base__range_ii_u32 s) {\n return (r->min_incl == s.min_incl && r->max_incl == s.max_incl) ||\n (wuffs_base__range_ii_u32__is_empty(r) &&\n wuffs_base__range_ii_u32__is_empty(&s));\n}\n\nstatic inline wuffs_base__range_ii_u32 //" +
+ "\nwuffs_base__range_ii_u32__intersect(wuffs_base__range_ii_u32* r,\n wuffs_base__range_ii_u32 s) {\n wuffs_base__range_ii_u32 t;\n t.min_incl = wuffs_base__u32__max(r->min_incl, s.min_incl);\n t.max_incl = wuffs_base__u32__min(r->max_incl, s.max_incl);\n return t;\n}\n\nstatic inline wuffs_base__range_ii_u32 //\nwuffs_base__range_ii_u32__unite(wuffs_base__range_ii_u32* r,\n wuffs_base__range_ii_u32 s) {\n if (wuffs_base__range_ii_u32__is_empty(r)) {\n return s;\n }\n if (wuffs_base__range_ii_u32__is_empty(&s)) {\n return *r;\n }\n wuffs_base__range_ii_u32 t;\n t.min_incl = wuffs_base__u32__min(r->min_incl, s.min_incl);\n t.max_incl = wuffs_base__u32__max(r->max_incl, s.max_incl);\n return t;\n}\n\nstatic inline bool //\nwuffs_base__range_ii_u32__contains(wuffs_base__range_ii_u32* r, uint32_t x) {\n return (r->min_incl <= x) && (x <= r->max_incl);\n}\n\nstatic inline bool //\nwuffs_base__range_ii_u32__contains_range(wuffs_base__range_ii_u32* r,\n " +
+ " wuffs_base__range_ii_u32 s) {\n return wuffs_base__range_ii_u32__equals(\n &s, wuffs_base__range_ii_u32__intersect(r, s));\n}\n\n#ifdef __cplusplus\n\ninline bool //\nwuffs_base__range_ii_u32::is_empty() {\n return wuffs_base__range_ii_u32__is_empty(this);\n}\n\ninline bool //\nwuffs_base__range_ii_u32::equals(wuffs_base__range_ii_u32 s) {\n return wuffs_base__range_ii_u32__equals(this, s);\n}\n\ninline wuffs_base__range_ii_u32 //\nwuffs_base__range_ii_u32::intersect(wuffs_base__range_ii_u32 s) {\n return wuffs_base__range_ii_u32__intersect(this, s);\n}\n\ninline wuffs_base__range_ii_u32 //\nwuffs_base__range_ii_u32::unite(wuffs_base__range_ii_u32 s) {\n return wuffs_base__range_ii_u32__unite(this, s);\n}\n\ninline bool //\nwuffs_base__range_ii_u32::contains(uint32_t x) {\n return wuffs_base__range_ii_u32__contains(this, x);\n}\n\ninline bool //\nwuffs_base__range_ii_u32::contains_range(wuffs_base__range_ii_u32 s) {\n return wuffs_base__range_ii_u32__contains_range(this, s);\n}\n\n#endif // __c" +
+ "plusplus\n\n" +
+ "" +
+ "// --------\n\ntypedef struct wuffs_base__range_ie_u32__struct {\n uint32_t min_incl;\n uint32_t max_excl;\n\n#ifdef __cplusplus\n inline bool is_empty();\n inline bool equals(wuffs_base__range_ie_u32__struct s);\n inline wuffs_base__range_ie_u32__struct intersect(\n wuffs_base__range_ie_u32__struct s);\n inline wuffs_base__range_ie_u32__struct unite(\n wuffs_base__range_ie_u32__struct s);\n inline bool contains(uint32_t x);\n inline bool contains_range(wuffs_base__range_ie_u32__struct s);\n inline uint32_t length();\n#endif // __cplusplus\n\n} wuffs_base__range_ie_u32;\n\nstatic inline wuffs_base__range_ie_u32 //\nwuffs_base__make_range_ie_u32(uint32_t min_incl, uint32_t max_excl) {\n wuffs_base__range_ie_u32 ret;\n ret.min_incl = min_incl;\n ret.max_excl = max_excl;\n return ret;\n}\n\nstatic inline bool //\nwuffs_base__range_ie_u32__is_empty(wuffs_base__range_ie_u32* r) {\n return r->min_incl >= r->max_excl;\n}\n\nstatic inline bool //\nwuffs_base__range_ie_u32__equals(wuffs_base__range_ie_u32* r,\n " +
+ " wuffs_base__range_ie_u32 s) {\n return (r->min_incl == s.min_incl && r->max_excl == s.max_excl) ||\n (wuffs_base__range_ie_u32__is_empty(r) &&\n wuffs_base__range_ie_u32__is_empty(&s));\n}\n\nstatic inline wuffs_base__range_ie_u32 //\nwuffs_base__range_ie_u32__intersect(wuffs_base__range_ie_u32* r,\n wuffs_base__range_ie_u32 s) {\n wuffs_base__range_ie_u32 t;\n t.min_incl = wuffs_base__u32__max(r->min_incl, s.min_incl);\n t.max_excl = wuffs_base__u32__min(r->max_excl, s.max_excl);\n return t;\n}\n\nstatic inline wuffs_base__range_ie_u32 //\nwuffs_base__range_ie_u32__unite(wuffs_base__range_ie_u32* r,\n wuffs_base__range_ie_u32 s) {\n if (wuffs_base__range_ie_u32__is_empty(r)) {\n return s;\n }\n if (wuffs_base__range_ie_u32__is_empty(&s)) {\n return *r;\n }\n wuffs_base__range_ie_u32 t;\n t.min_incl = wuffs_base__u32__min(r->min_incl, s.min_incl);\n t.max_excl = wuffs_base__u32__max(r->max_excl, s.max_excl);\n retu" +
+ "rn t;\n}\n\nstatic inline bool //\nwuffs_base__range_ie_u32__contains(wuffs_base__range_ie_u32* r, uint32_t x) {\n return (r->min_incl <= x) && (x < r->max_excl);\n}\n\nstatic inline bool //\nwuffs_base__range_ie_u32__contains_range(wuffs_base__range_ie_u32* r,\n wuffs_base__range_ie_u32 s) {\n return wuffs_base__range_ie_u32__equals(\n &s, wuffs_base__range_ie_u32__intersect(r, s));\n}\n\nstatic inline uint32_t //\nwuffs_base__range_ie_u32__length(wuffs_base__range_ie_u32* r) {\n return wuffs_base__u32__sat_sub(r->max_excl, r->min_incl);\n}\n\n#ifdef __cplusplus\n\ninline bool //\nwuffs_base__range_ie_u32::is_empty() {\n return wuffs_base__range_ie_u32__is_empty(this);\n}\n\ninline bool //\nwuffs_base__range_ie_u32::equals(wuffs_base__range_ie_u32 s) {\n return wuffs_base__range_ie_u32__equals(this, s);\n}\n\ninline wuffs_base__range_ie_u32 //\nwuffs_base__range_ie_u32::intersect(wuffs_base__range_ie_u32 s) {\n return wuffs_base__range_ie_u32__intersect(this, s);\n}\n\ninline wuffs_base__" +
+ "range_ie_u32 //\nwuffs_base__range_ie_u32::unite(wuffs_base__range_ie_u32 s) {\n return wuffs_base__range_ie_u32__unite(this, s);\n}\n\ninline bool //\nwuffs_base__range_ie_u32::contains(uint32_t x) {\n return wuffs_base__range_ie_u32__contains(this, x);\n}\n\ninline bool //\nwuffs_base__range_ie_u32::contains_range(wuffs_base__range_ie_u32 s) {\n return wuffs_base__range_ie_u32__contains_range(this, s);\n}\n\ninline uint32_t //\nwuffs_base__range_ie_u32::length() {\n return wuffs_base__range_ie_u32__length(this);\n}\n\n#endif // __cplusplus\n\n" +
+ "" +
+ "// --------\n\ntypedef struct wuffs_base__range_ii_u64__struct {\n uint64_t min_incl;\n uint64_t max_incl;\n\n#ifdef __cplusplus\n inline bool is_empty();\n inline bool equals(wuffs_base__range_ii_u64__struct s);\n inline wuffs_base__range_ii_u64__struct intersect(\n wuffs_base__range_ii_u64__struct s);\n inline wuffs_base__range_ii_u64__struct unite(\n wuffs_base__range_ii_u64__struct s);\n inline bool contains(uint64_t x);\n inline bool contains_range(wuffs_base__range_ii_u64__struct s);\n#endif // __cplusplus\n\n} wuffs_base__range_ii_u64;\n\nstatic inline wuffs_base__range_ii_u64 //\nwuffs_base__make_range_ii_u64(uint64_t min_incl, uint64_t max_incl) {\n wuffs_base__range_ii_u64 ret;\n ret.min_incl = min_incl;\n ret.max_incl = max_incl;\n return ret;\n}\n\nstatic inline bool //\nwuffs_base__range_ii_u64__is_empty(wuffs_base__range_ii_u64* r) {\n return r->min_incl > r->max_incl;\n}\n\nstatic inline bool //\nwuffs_base__range_ii_u64__equals(wuffs_base__range_ii_u64* r,\n wuffs_base" +
+ "__range_ii_u64 s) {\n return (r->min_incl == s.min_incl && r->max_incl == s.max_incl) ||\n (wuffs_base__range_ii_u64__is_empty(r) &&\n wuffs_base__range_ii_u64__is_empty(&s));\n}\n\nstatic inline wuffs_base__range_ii_u64 //\nwuffs_base__range_ii_u64__intersect(wuffs_base__range_ii_u64* r,\n wuffs_base__range_ii_u64 s) {\n wuffs_base__range_ii_u64 t;\n t.min_incl = wuffs_base__u64__max(r->min_incl, s.min_incl);\n t.max_incl = wuffs_base__u64__min(r->max_incl, s.max_incl);\n return t;\n}\n\nstatic inline wuffs_base__range_ii_u64 //\nwuffs_base__range_ii_u64__unite(wuffs_base__range_ii_u64* r,\n wuffs_base__range_ii_u64 s) {\n if (wuffs_base__range_ii_u64__is_empty(r)) {\n return s;\n }\n if (wuffs_base__range_ii_u64__is_empty(&s)) {\n return *r;\n }\n wuffs_base__range_ii_u64 t;\n t.min_incl = wuffs_base__u64__min(r->min_incl, s.min_incl);\n t.max_incl = wuffs_base__u64__max(r->max_incl, s.max_incl);\n return t;\n}\n\nstatic inline bool " +
+ "//\nwuffs_base__range_ii_u64__contains(wuffs_base__range_ii_u64* r, uint64_t x) {\n return (r->min_incl <= x) && (x <= r->max_incl);\n}\n\nstatic inline bool //\nwuffs_base__range_ii_u64__contains_range(wuffs_base__range_ii_u64* r,\n wuffs_base__range_ii_u64 s) {\n return wuffs_base__range_ii_u64__equals(\n &s, wuffs_base__range_ii_u64__intersect(r, s));\n}\n\n#ifdef __cplusplus\n\ninline bool //\nwuffs_base__range_ii_u64::is_empty() {\n return wuffs_base__range_ii_u64__is_empty(this);\n}\n\ninline bool //\nwuffs_base__range_ii_u64::equals(wuffs_base__range_ii_u64 s) {\n return wuffs_base__range_ii_u64__equals(this, s);\n}\n\ninline wuffs_base__range_ii_u64 //\nwuffs_base__range_ii_u64::intersect(wuffs_base__range_ii_u64 s) {\n return wuffs_base__range_ii_u64__intersect(this, s);\n}\n\ninline wuffs_base__range_ii_u64 //\nwuffs_base__range_ii_u64::unite(wuffs_base__range_ii_u64 s) {\n return wuffs_base__range_ii_u64__unite(this, s);\n}\n\ninline bool //\nwuffs_base__range_ii_u64::contains" +
+ "(uint64_t x) {\n return wuffs_base__range_ii_u64__contains(this, x);\n}\n\ninline bool //\nwuffs_base__range_ii_u64::contains_range(wuffs_base__range_ii_u64 s) {\n return wuffs_base__range_ii_u64__contains_range(this, s);\n}\n\n#endif // __cplusplus\n\n" +
+ "" +
+ "// --------\n\ntypedef struct wuffs_base__range_ie_u64__struct {\n uint64_t min_incl;\n uint64_t max_excl;\n\n#ifdef __cplusplus\n inline bool is_empty();\n inline bool equals(wuffs_base__range_ie_u64__struct s);\n inline wuffs_base__range_ie_u64__struct intersect(\n wuffs_base__range_ie_u64__struct s);\n inline wuffs_base__range_ie_u64__struct unite(\n wuffs_base__range_ie_u64__struct s);\n inline bool contains(uint64_t x);\n inline bool contains_range(wuffs_base__range_ie_u64__struct s);\n inline uint64_t length();\n#endif // __cplusplus\n\n} wuffs_base__range_ie_u64;\n\nstatic inline wuffs_base__range_ie_u64 //\nwuffs_base__make_range_ie_u64(uint64_t min_incl, uint64_t max_excl) {\n wuffs_base__range_ie_u64 ret;\n ret.min_incl = min_incl;\n ret.max_excl = max_excl;\n return ret;\n}\n\nstatic inline bool //\nwuffs_base__range_ie_u64__is_empty(wuffs_base__range_ie_u64* r) {\n return r->min_incl >= r->max_excl;\n}\n\nstatic inline bool //\nwuffs_base__range_ie_u64__equals(wuffs_base__range_ie_u64* r,\n " +
+ " wuffs_base__range_ie_u64 s) {\n return (r->min_incl == s.min_incl && r->max_excl == s.max_excl) ||\n (wuffs_base__range_ie_u64__is_empty(r) &&\n wuffs_base__range_ie_u64__is_empty(&s));\n}\n\nstatic inline wuffs_base__range_ie_u64 //\nwuffs_base__range_ie_u64__intersect(wuffs_base__range_ie_u64* r,\n wuffs_base__range_ie_u64 s) {\n wuffs_base__range_ie_u64 t;\n t.min_incl = wuffs_base__u64__max(r->min_incl, s.min_incl);\n t.max_excl = wuffs_base__u64__min(r->max_excl, s.max_excl);\n return t;\n}\n\nstatic inline wuffs_base__range_ie_u64 //\nwuffs_base__range_ie_u64__unite(wuffs_base__range_ie_u64* r,\n wuffs_base__range_ie_u64 s) {\n if (wuffs_base__range_ie_u64__is_empty(r)) {\n return s;\n }\n if (wuffs_base__range_ie_u64__is_empty(&s)) {\n return *r;\n }\n wuffs_base__range_ie_u64 t;\n t.min_incl = wuffs_base__u64__min(r->min_incl, s.min_incl);\n t.max_excl = wuffs_base__u64__max(r->max_excl, s.max_excl);\n retu" +
+ "rn t;\n}\n\nstatic inline bool //\nwuffs_base__range_ie_u64__contains(wuffs_base__range_ie_u64* r, uint64_t x) {\n return (r->min_incl <= x) && (x < r->max_excl);\n}\n\nstatic inline bool //\nwuffs_base__range_ie_u64__contains_range(wuffs_base__range_ie_u64* r,\n wuffs_base__range_ie_u64 s) {\n return wuffs_base__range_ie_u64__equals(\n &s, wuffs_base__range_ie_u64__intersect(r, s));\n}\n\nstatic inline uint64_t //\nwuffs_base__range_ie_u64__length(wuffs_base__range_ie_u64* r) {\n return wuffs_base__u64__sat_sub(r->max_excl, r->min_incl);\n}\n\n#ifdef __cplusplus\n\ninline bool //\nwuffs_base__range_ie_u64::is_empty() {\n return wuffs_base__range_ie_u64__is_empty(this);\n}\n\ninline bool //\nwuffs_base__range_ie_u64::equals(wuffs_base__range_ie_u64 s) {\n return wuffs_base__range_ie_u64__equals(this, s);\n}\n\ninline wuffs_base__range_ie_u64 //\nwuffs_base__range_ie_u64::intersect(wuffs_base__range_ie_u64 s) {\n return wuffs_base__range_ie_u64__intersect(this, s);\n}\n\ninline wuffs_base__" +
+ "range_ie_u64 //\nwuffs_base__range_ie_u64::unite(wuffs_base__range_ie_u64 s) {\n return wuffs_base__range_ie_u64__unite(this, s);\n}\n\ninline bool //\nwuffs_base__range_ie_u64::contains(uint64_t x) {\n return wuffs_base__range_ie_u64__contains(this, x);\n}\n\ninline bool //\nwuffs_base__range_ie_u64::contains_range(wuffs_base__range_ie_u64 s) {\n return wuffs_base__range_ie_u64__contains_range(this, s);\n}\n\ninline uint64_t //\nwuffs_base__range_ie_u64::length() {\n return wuffs_base__range_ie_u64__length(this);\n}\n\n#endif // __cplusplus\n\n" +
+ "" +
+ "// --------\n\n// wuffs_base__rect_ii_u32 is a rectangle (a 2-dimensional range) on the\n// integer grid. The \"ii\" means that the bounds are inclusive on the low end\n// and inclusive on the high end. It contains all points (x, y) such that\n// ((min_incl_x <= x) && (x <= max_incl_x)) and likewise for y.\n//\n// It is valid for min > max, in which case the rectangle is empty. There are\n// multiple representations of an empty rectangle.\n//\n// The X and Y axes increase right and down.\ntypedef struct wuffs_base__rect_ii_u32__struct {\n uint32_t min_incl_x;\n uint32_t min_incl_y;\n uint32_t max_incl_x;\n uint32_t max_incl_y;\n\n#ifdef __cplusplus\n inline bool is_empty();\n inline bool equals(wuffs_base__rect_ii_u32__struct s);\n inline wuffs_base__rect_ii_u32__struct intersect(\n wuffs_base__rect_ii_u32__struct s);\n inline wuffs_base__rect_ii_u32__struct unite(\n wuffs_base__rect_ii_u32__struct s);\n inline bool contains(uint32_t x, uint32_t y);\n inline bool contains_rect(wuffs_base__rect_ii_u32__struct s);\n#en" +
+ "dif // __cplusplus\n\n} wuffs_base__rect_ii_u32;\n\nstatic inline wuffs_base__rect_ii_u32 //\nwuffs_base__make_rect_ii_u32(uint32_t min_incl_x,\n uint32_t min_incl_y,\n uint32_t max_incl_x,\n uint32_t max_incl_y) {\n wuffs_base__rect_ii_u32 ret;\n ret.min_incl_x = min_incl_x;\n ret.min_incl_y = min_incl_y;\n ret.max_incl_x = max_incl_x;\n ret.max_incl_y = max_incl_y;\n return ret;\n}\n\nstatic inline bool //\nwuffs_base__rect_ii_u32__is_empty(wuffs_base__rect_ii_u32* r) {\n return (r->min_incl_x > r->max_incl_x) || (r->min_incl_y > r->max_incl_y);\n}\n\nstatic inline bool //\nwuffs_base__rect_ii_u32__equals(wuffs_base__rect_ii_u32* r,\n wuffs_base__rect_ii_u32 s) {\n return (r->min_incl_x == s.min_incl_x && r->min_incl_y == s.min_incl_y &&\n r->max_incl_x == s.max_incl_x && r->max_incl_y == s.max_incl_y) ||\n (wuffs_base__rect_ii_u32__is_empty(r) &&\n wuffs_base__rect_ii_u32__is_empty(&" +
+ "s));\n}\n\nstatic inline wuffs_base__rect_ii_u32 //\nwuffs_base__rect_ii_u32__intersect(wuffs_base__rect_ii_u32* r,\n wuffs_base__rect_ii_u32 s) {\n wuffs_base__rect_ii_u32 t;\n t.min_incl_x = wuffs_base__u32__max(r->min_incl_x, s.min_incl_x);\n t.min_incl_y = wuffs_base__u32__max(r->min_incl_y, s.min_incl_y);\n t.max_incl_x = wuffs_base__u32__min(r->max_incl_x, s.max_incl_x);\n t.max_incl_y = wuffs_base__u32__min(r->max_incl_y, s.max_incl_y);\n return t;\n}\n\nstatic inline wuffs_base__rect_ii_u32 //\nwuffs_base__rect_ii_u32__unite(wuffs_base__rect_ii_u32* r,\n wuffs_base__rect_ii_u32 s) {\n if (wuffs_base__rect_ii_u32__is_empty(r)) {\n return s;\n }\n if (wuffs_base__rect_ii_u32__is_empty(&s)) {\n return *r;\n }\n wuffs_base__rect_ii_u32 t;\n t.min_incl_x = wuffs_base__u32__min(r->min_incl_x, s.min_incl_x);\n t.min_incl_y = wuffs_base__u32__min(r->min_incl_y, s.min_incl_y);\n t.max_incl_x = wuffs_base__u32__max(r->max_incl_x, s.max_incl_x);\n t.max" +
+ "_incl_y = wuffs_base__u32__max(r->max_incl_y, s.max_incl_y);\n return t;\n}\n\nstatic inline bool //\nwuffs_base__rect_ii_u32__contains(wuffs_base__rect_ii_u32* r,\n uint32_t x,\n uint32_t y) {\n return (r->min_incl_x <= x) && (x <= r->max_incl_x) && (r->min_incl_y <= y) &&\n (y <= r->max_incl_y);\n}\n\nstatic inline bool //\nwuffs_base__rect_ii_u32__contains_rect(wuffs_base__rect_ii_u32* r,\n wuffs_base__rect_ii_u32 s) {\n return wuffs_base__rect_ii_u32__equals(\n &s, wuffs_base__rect_ii_u32__intersect(r, s));\n}\n\n#ifdef __cplusplus\n\ninline bool //\nwuffs_base__rect_ii_u32::is_empty() {\n return wuffs_base__rect_ii_u32__is_empty(this);\n}\n\ninline bool //\nwuffs_base__rect_ii_u32::equals(wuffs_base__rect_ii_u32 s) {\n return wuffs_base__rect_ii_u32__equals(this, s);\n}\n\ninline wuffs_base__rect_ii_u32 //\nwuffs_base__rect_ii_u32::intersect(wuffs_base__rect_ii_u32 s) {\n return wuffs_base__rect_ii_u32__interse" +
+ "ct(this, s);\n}\n\ninline wuffs_base__rect_ii_u32 //\nwuffs_base__rect_ii_u32::unite(wuffs_base__rect_ii_u32 s) {\n return wuffs_base__rect_ii_u32__unite(this, s);\n}\n\ninline bool //\nwuffs_base__rect_ii_u32::contains(uint32_t x, uint32_t y) {\n return wuffs_base__rect_ii_u32__contains(this, x, y);\n}\n\ninline bool //\nwuffs_base__rect_ii_u32::contains_rect(wuffs_base__rect_ii_u32 s) {\n return wuffs_base__rect_ii_u32__contains_rect(this, s);\n}\n\n#endif // __cplusplus\n\n" +
+ "" +
+ "// --------\n\n// wuffs_base__rect_ie_u32 is a rectangle (a 2-dimensional range) on the\n// integer grid. The \"ie\" means that the bounds are inclusive on the low end\n// and exclusive on the high end. It contains all points (x, y) such that\n// ((min_incl_x <= x) && (x < max_excl_x)) and likewise for y.\n//\n// It is valid for min >= max, in which case the rectangle is empty. There are\n// multiple representations of an empty rectangle, including a value with all\n// fields zero.\n//\n// The X and Y axes increase right and down.\ntypedef struct wuffs_base__rect_ie_u32__struct {\n uint32_t min_incl_x;\n uint32_t min_incl_y;\n uint32_t max_excl_x;\n uint32_t max_excl_y;\n\n#ifdef __cplusplus\n inline bool is_empty();\n inline bool equals(wuffs_base__rect_ie_u32__struct s);\n inline wuffs_base__rect_ie_u32__struct intersect(\n wuffs_base__rect_ie_u32__struct s);\n inline wuffs_base__rect_ie_u32__struct unite(\n wuffs_base__rect_ie_u32__struct s);\n inline bool contains(uint32_t x, uint32_t y);\n inline bool contains_r" +
+ "ect(wuffs_base__rect_ie_u32__struct s);\n inline uint32_t width();\n inline uint32_t height();\n#endif // __cplusplus\n\n} wuffs_base__rect_ie_u32;\n\nstatic inline wuffs_base__rect_ie_u32 //\nwuffs_base__make_rect_ie_u32(uint32_t min_incl_x,\n uint32_t min_incl_y,\n uint32_t max_excl_x,\n uint32_t max_excl_y) {\n wuffs_base__rect_ie_u32 ret;\n ret.min_incl_x = min_incl_x;\n ret.min_incl_y = min_incl_y;\n ret.max_excl_x = max_excl_x;\n ret.max_excl_y = max_excl_y;\n return ret;\n}\n\nstatic inline bool //\nwuffs_base__rect_ie_u32__is_empty(wuffs_base__rect_ie_u32* r) {\n return (r->min_incl_x >= r->max_excl_x) || (r->min_incl_y >= r->max_excl_y);\n}\n\nstatic inline bool //\nwuffs_base__rect_ie_u32__equals(wuffs_base__rect_ie_u32* r,\n wuffs_base__rect_ie_u32 s) {\n return (r->min_incl_x == s.min_incl_x && r->min_incl_y == s.min_incl_y &&\n r->max_excl_x == s.max_excl_x && r->max_excl_y == s.max_excl_y" +
+ ") ||\n (wuffs_base__rect_ie_u32__is_empty(r) &&\n wuffs_base__rect_ie_u32__is_empty(&s));\n}\n\nstatic inline wuffs_base__rect_ie_u32 //\nwuffs_base__rect_ie_u32__intersect(wuffs_base__rect_ie_u32* r,\n wuffs_base__rect_ie_u32 s) {\n wuffs_base__rect_ie_u32 t;\n t.min_incl_x = wuffs_base__u32__max(r->min_incl_x, s.min_incl_x);\n t.min_incl_y = wuffs_base__u32__max(r->min_incl_y, s.min_incl_y);\n t.max_excl_x = wuffs_base__u32__min(r->max_excl_x, s.max_excl_x);\n t.max_excl_y = wuffs_base__u32__min(r->max_excl_y, s.max_excl_y);\n return t;\n}\n\nstatic inline wuffs_base__rect_ie_u32 //\nwuffs_base__rect_ie_u32__unite(wuffs_base__rect_ie_u32* r,\n wuffs_base__rect_ie_u32 s) {\n if (wuffs_base__rect_ie_u32__is_empty(r)) {\n return s;\n }\n if (wuffs_base__rect_ie_u32__is_empty(&s)) {\n return *r;\n }\n wuffs_base__rect_ie_u32 t;\n t.min_incl_x = wuffs_base__u32__min(r->min_incl_x, s.min_incl_x);\n t.min_incl_y = wuffs_base__u32__min(r->mi" +
+ "n_incl_y, s.min_incl_y);\n t.max_excl_x = wuffs_base__u32__max(r->max_excl_x, s.max_excl_x);\n t.max_excl_y = wuffs_base__u32__max(r->max_excl_y, s.max_excl_y);\n return t;\n}\n\nstatic inline bool //\nwuffs_base__rect_ie_u32__contains(wuffs_base__rect_ie_u32* r,\n uint32_t x,\n uint32_t y) {\n return (r->min_incl_x <= x) && (x < r->max_excl_x) && (r->min_incl_y <= y) &&\n (y < r->max_excl_y);\n}\n\nstatic inline bool //\nwuffs_base__rect_ie_u32__contains_rect(wuffs_base__rect_ie_u32* r,\n wuffs_base__rect_ie_u32 s) {\n return wuffs_base__rect_ie_u32__equals(\n &s, wuffs_base__rect_ie_u32__intersect(r, s));\n}\n\nstatic inline uint32_t //\nwuffs_base__rect_ie_u32__width(wuffs_base__rect_ie_u32* r) {\n return wuffs_base__u32__sat_sub(r->max_excl_x, r->min_incl_x);\n}\n\nstatic inline uint32_t //\nwuffs_base__rect_ie_u32__height(wuffs_base__rect_ie_u32* r) {\n return wuffs_base__u32__sat_sub(r->max_excl_y, r->min" +
+ "_incl_y);\n}\n\n#ifdef __cplusplus\n\ninline bool //\nwuffs_base__rect_ie_u32::is_empty() {\n return wuffs_base__rect_ie_u32__is_empty(this);\n}\n\ninline bool //\nwuffs_base__rect_ie_u32::equals(wuffs_base__rect_ie_u32 s) {\n return wuffs_base__rect_ie_u32__equals(this, s);\n}\n\ninline wuffs_base__rect_ie_u32 //\nwuffs_base__rect_ie_u32::intersect(wuffs_base__rect_ie_u32 s) {\n return wuffs_base__rect_ie_u32__intersect(this, s);\n}\n\ninline wuffs_base__rect_ie_u32 //\nwuffs_base__rect_ie_u32::unite(wuffs_base__rect_ie_u32 s) {\n return wuffs_base__rect_ie_u32__unite(this, s);\n}\n\ninline bool //\nwuffs_base__rect_ie_u32::contains(uint32_t x, uint32_t y) {\n return wuffs_base__rect_ie_u32__contains(this, x, y);\n}\n\ninline bool //\nwuffs_base__rect_ie_u32::contains_rect(wuffs_base__rect_ie_u32 s) {\n return wuffs_base__rect_ie_u32__contains_rect(this, s);\n}\n\ninline uint32_t //\nwuffs_base__rect_ie_u32::width() {\n return wuffs_base__rect_ie_u32__width(this);\n}\n\ninline uint32_t //\nwuffs_base__rect_ie_u32::height() {\n return" +
+ " wuffs_base__rect_ie_u32__height(this);\n}\n\n#endif // __cplusplus\n" +
+ ""
+
+const baseCopyright = "" +
+ "// 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" +
+ ""
diff --git a/cmd/wuffs-c/internal/cgen/expr.go b/internal/cgen/expr.go
similarity index 87%
rename from cmd/wuffs-c/internal/cgen/expr.go
rename to internal/cgen/expr.go
index a71ca4b..3315531 100644
--- a/cmd/wuffs-c/internal/cgen/expr.go
+++ b/internal/cgen/expr.go
@@ -62,8 +62,8 @@
} else if ident == t.IDCoroutineResumed {
if g.currFunk.astFunc.Effect().Coroutine() {
// TODO: don't hard-code [0], and allow recursive coroutines.
- b.printf("(self->private_impl.%s%s[0].coro_susp_point != 0)",
- cPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
+ b.printf("(self->private_impl.%s%s[0] != 0)",
+ pPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
} else {
b.writes("false")
}
@@ -75,6 +75,9 @@
return fmt.Errorf("unrecognized status %s", n.StatusQID().Str(g.tm))
}
+ } else if c, ok := g.scalarConstsMap[t.QID{0, n.Ident()}]; ok {
+ b.writes(c.Value().ConstValue().String())
+
} else {
if n.GlobalIdent() {
b.writes(g.pkgPrefix)
@@ -104,32 +107,26 @@
}
qid := recvTyp.QID()
- // Generate a 2 or 3 part expression using the comma operator:
- // "(memset call, check_wuffs_version call, return_empty_struct
- // call)". The final part is a function call (to a static inline
- // function) instead of a struct literal, to avoid a "expression
- // result unused" compiler error.
- //
- // The middle part, the check_wuffs_version call, is optional, for
- // some built-in types.
-
- b.printf("(memset(%s", addr)
- // TODO: ensure that the recv expression is idempotent.
- if err := g.writeExpr(b, recv, depth); err != nil {
- return err
- }
- b.printf(", 0, sizeof ((%s%s){}))", g.packagePrefix(qid), qid[1].Str(g.tm))
-
- if !isBaseRangeType(qid) {
- b.printf(", wuffs_base__ignore_check_wuffs_version_status("+
- "%s%s__check_wuffs_version(%s", g.packagePrefix(qid), qid[1].Str(g.tm), addr)
+ if isBaseRangeType(qid) {
+ // Generate a 2 part expression using the comma operator: "(memset
+ // call, return_empty_struct call)". The final part is a function
+ // call (to a static inline function) instead of a struct literal,
+ // to avoid a "expression result unused" compiler error.
+ b.printf("(memset(%s", addr)
if err := g.writeExpr(b, recv, depth); err != nil {
return err
}
- b.printf(", sizeof ((%s%s){}), WUFFS_VERSION))", g.packagePrefix(qid), qid[1].Str(g.tm))
+ b.printf(", 0, sizeof (%s%s)), wuffs_base__make_empty_struct())",
+ g.packagePrefix(qid), qid[1].Str(g.tm))
+ } else {
+ b.printf("wuffs_base__ignore_status("+
+ "%s%s__initialize(%s", g.packagePrefix(qid), qid[1].Str(g.tm), addr)
+ if err := g.writeExpr(b, recv, depth); err != nil {
+ return err
+ }
+ b.printf(", sizeof (%s%s), WUFFS_VERSION, 0))", g.packagePrefix(qid), qid[1].Str(g.tm))
}
- b.writes(", wuffs_base__return_empty_struct())")
return nil
}
@@ -168,13 +165,13 @@
lhsIsArray := lhs.MType().IsArrayType()
if lhsIsArray {
// TODO: don't assume that the slice is a slice of base.u8.
- b.writes("((wuffs_base__slice_u8){.ptr=")
+ b.writes("wuffs_base__make_slice_u8(")
}
if err := g.writeExpr(b, lhs, depth); err != nil {
return err
}
if lhsIsArray {
- b.printf(",.len=%v,})", lhs.MType().ArrayLength().ConstValue())
+ b.printf(", %v)", lhs.MType().ArrayLength().ConstValue())
}
if mhs != nil {
@@ -210,13 +207,29 @@
} else {
b.writes(".")
}
- b.writes("private_impl." + fPrefix)
+
+ b.writes(g.privateImplData(lhs.MType(), n.Ident()))
+ b.writeb('.')
+ b.writes(fPrefix)
b.writes(n.Ident().Str(g.tm))
return nil
}
return fmt.Errorf("unrecognized token (0x%X) for writeExprOther", n.Operator())
}
+func (g *gen) privateImplData(typ *a.TypeExpr, fieldName t.ID) string {
+ if p := typ.Decorator(); p == t.IDNptr || p == t.IDPtr {
+ typ = typ.Inner()
+ }
+ if s := g.structMap[typ.QID()]; s != nil {
+ qid := s.QID()
+ if _, ok := g.privateDataFields[t.QQID{qid[0], qid[1], fieldName}]; ok {
+ return "private_data"
+ }
+ }
+ return "private_impl"
+}
+
func (g *gen) writeExprUnaryOp(b *buffer, n *a.Expr, depth uint32) error {
op := n.Operator()
opName := cOpName(op)
@@ -316,12 +329,15 @@
n.Str(g.tm), recv.MType().Str(g.tm))
}
qid := recvTyp.QID()
- b.printf("%s%s__%s(%s", g.packagePrefix(qid), qid[1].Str(g.tm), method.Ident().Str(g.tm), addr)
- if err := g.writeExpr(b, recv, depth); err != nil {
- return err
- }
- if len(n.Args()) > 0 {
- b.writeb(',')
+ b.printf("%s%s__%s(", g.packagePrefix(qid), qid[1].Str(g.tm), method.Ident().Str(g.tm))
+ if !recvTyp.Eq(typeExprUtility) {
+ b.writes(addr)
+ if err := g.writeExpr(b, recv, depth); err != nil {
+ return err
+ }
+ if len(n.Args()) > 0 {
+ b.writeb(',')
+ }
}
return g.writeArgs(b, n.Args(), depth)
}
diff --git a/cmd/wuffs-c/internal/cgen/func.go b/internal/cgen/func.go
similarity index 86%
rename from cmd/wuffs-c/internal/cgen/func.go
rename to internal/cgen/func.go
index 7a73aa0..1030f78 100644
--- a/cmd/wuffs-c/internal/cgen/func.go
+++ b/internal/cgen/func.go
@@ -218,17 +218,39 @@
func (g *gen) writeOutParamZeroValue(b *buffer, typ *a.TypeExpr) error {
if typ == nil {
- b.writes("((wuffs_base__empty_struct){})")
+ b.writes("wuffs_base__make_empty_struct()")
+ return nil
} else if typ.IsNumType() {
b.writes("0")
- } else {
- b.writes("((")
- if err := g.writeCTypeName(b, typ, "", ""); err != nil {
- return err
+ return nil
+ } else if typ.IsSliceType() {
+ if inner := typ.Inner(); (inner.Decorator() == 0) && (inner.QID() == t.QID{t.IDBase, t.IDU8}) {
+ b.writes("wuffs_base__make_slice_u8(NULL, 0)")
+ return nil
}
- b.writes("){})")
+ } else if (typ.Decorator() == 0) && (typ.QID()[0] == t.IDBase) {
+ switch typ.QID()[1] {
+ case t.IDRangeIEU32:
+ b.writes("wuffs_base__utility__make_range_ie_u32(0, 0)")
+ return nil
+ case t.IDRangeIIU32:
+ b.writes("wuffs_base__utility__make_range_ii_u32(0, 0)")
+ return nil
+ case t.IDRangeIEU64:
+ b.writes("wuffs_base__utility__make_range_ie_u64(0, 0)")
+ return nil
+ case t.IDRangeIIU64:
+ b.writes("wuffs_base__utility__make_range_ii_u64(0, 0)")
+ return nil
+ case t.IDRectIEU32:
+ b.writes("wuffs_base__utility__make_rect_ie_u32(0, 0, 0, 0)")
+ return nil
+ case t.IDRectIIU32:
+ b.writes("wuffs_base__utility__make_rect_ii_u32(0, 0, 0, 0)")
+ return nil
+ }
}
- return nil
+ return fmt.Errorf("internal error: cannot write the zero value of type %q", typ.Str(g.tm))
}
func (g *gen) writeFuncImplPrologue(b *buffer) error {
@@ -244,11 +266,17 @@
}
b.writes(";}")
- b.writes("if (self->private_impl.magic != WUFFS_BASE__MAGIC) { return ")
+ if g.currFunk.astFunc.Effect().Pure() {
+ b.writes("if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&")
+ b.writes(" (self->private_impl.magic != WUFFS_BASE__DISABLED)) {")
+ } else {
+ b.writes("if (self->private_impl.magic != WUFFS_BASE__MAGIC) {")
+ }
+ b.writes("return ")
if g.currFunk.returnsStatus {
b.writes("(self->private_impl.magic == WUFFS_BASE__DISABLED) " +
"? wuffs_base__error__disabled_by_previous_error " +
- ": wuffs_base__error__check_wuffs_version_missing")
+ ": wuffs_base__error__initialize_not_called")
} else if err := g.writeOutParamZeroValue(b, out); err != nil {
return err
}
@@ -303,8 +331,8 @@
func (g *gen) writeFuncImplBodyResume(b *buffer) error {
if g.currFunk.astFunc.Effect().Coroutine() {
// TODO: don't hard-code [0], and allow recursive coroutines.
- b.printf("uint32_t coro_susp_point = self->private_impl.%s%s[0].coro_susp_point;\n",
- cPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
+ b.printf("uint32_t coro_susp_point = self->private_impl.%s%s[0];\n",
+ pPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
b.printf("if (coro_susp_point) {\n")
if err := g.writeResumeSuspend(b, &g.currFunk, false); err != nil {
return err
@@ -334,14 +362,14 @@
// suspension point so that the next call to this function starts at
// the top.
b.writes("\ngoto ok;ok:") // The goto avoids the "unused label" warning.
- b.printf("self->private_impl.%s%s[0].coro_susp_point = 0;\n",
- cPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
+ b.printf("self->private_impl.%s%s[0] = 0;\n",
+ pPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
b.writes("goto exit; }\n\n") // Close the coroutine switch.
b.writes("goto suspend;suspend:") // The goto avoids the "unused label" warning.
- b.printf("self->private_impl.%s%s[0].coro_susp_point = coro_susp_point;\n",
- cPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
+ b.printf("self->private_impl.%s%s[0] = coro_susp_point;\n",
+ pPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
if g.currFunk.astFunc.Public() {
b.printf("self->private_impl.active_coroutine = %d;\n", g.currFunk.coroID)
}
@@ -379,7 +407,7 @@
}
b.writes("return status;\n")
} else if g.currFunk.astFunc.Out() == nil {
- b.writes("return ((wuffs_base__empty_struct){});\n")
+ b.writes("return wuffs_base__make_empty_struct();\n")
}
return nil
}
@@ -448,7 +476,7 @@
b.writes("return wuffs_base__error__bad_argument;\n\n")
} else {
// TODO: don't assume that the return type is empty.
- b.printf("return ((wuffs_base__empty_struct){});\n")
+ b.printf("return wuffs_base__make_empty_struct();\n")
}
b.writes("}\n")
return nil
diff --git a/cmd/wuffs-c/internal/cgen/gen.go b/internal/cgen/gen.go
similarity index 100%
rename from cmd/wuffs-c/internal/cgen/gen.go
rename to internal/cgen/gen.go
diff --git a/cmd/wuffs-c/internal/cgen/resume.go b/internal/cgen/resume.go
similarity index 100%
rename from cmd/wuffs-c/internal/cgen/resume.go
rename to internal/cgen/resume.go
diff --git a/cmd/wuffs-c/internal/cgen/statement.go b/internal/cgen/statement.go
similarity index 94%
rename from cmd/wuffs-c/internal/cgen/statement.go
rename to internal/cgen/statement.go
index aaaad05..6fca3e8 100644
--- a/cmd/wuffs-c/internal/cgen/statement.go
+++ b/internal/cgen/statement.go
@@ -175,7 +175,7 @@
return err
}
- opName, closer := "", ""
+ opName, closer, disableWconversion := "", "", false
if lTyp := lhs.MType(); lTyp.IsArrayType() {
b.writes("memcpy(")
opName, closer = ",", fmt.Sprintf(", sizeof(%s))", lhsBuf)
@@ -194,6 +194,14 @@
b.printf("wuffs_base__u%d__sat_%s_indirect(&", uBits, uOp)
opName, closer = ",", ")"
+ case t.IDPlusEq, t.IDMinusEq:
+ if lTyp.IsNumType() {
+ if u := lTyp.QID()[1]; u == t.IDU8 || u == t.IDU16 {
+ disableWconversion = true
+ }
+ }
+ fallthrough
+
default:
opName = cOpName(op)
if opName == "" {
@@ -202,6 +210,16 @@
}
}
+ // "x += 1" triggers -Wconversion, if x is smaller than an int (i.e. a
+ // uint8_t or a uint16_t). This is arguably a clang/gcc bug, but in any
+ // case, we work around it in Wuffs.
+ if disableWconversion {
+ b.writes("#if defined(__GNUC__)\n")
+ b.writes("#pragma GCC diagnostic push\n")
+ b.writes("#pragma GCC diagnostic ignored \"-Wconversion\"\n")
+ b.writes("#endif\n")
+ }
+
b.writex(lhsBuf)
b.writes(opName)
if rhs.Effect().Coroutine() {
@@ -216,6 +234,12 @@
b.writes(closer)
b.writes(";\n")
+ if disableWconversion {
+ b.writes("#if defined(__GNUC__)\n")
+ b.writes("#pragma GCC diagnostic pop\n")
+ b.writes("#endif\n")
+ }
+
return nil
}
@@ -446,7 +470,7 @@
b.writes("return ")
if g.currFunk.astFunc.Out() == nil {
- return fmt.Errorf("TODO: allow empty return type (when not suspendible)")
+ b.writes("wuffs_base__make_empty_struct()")
} else if err := g.writeExpr(b, retExpr, depth); err != nil {
return err
}
diff --git a/cmd/wuffs-c/internal/cgen/var.go b/internal/cgen/var.go
similarity index 86%
rename from cmd/wuffs-c/internal/cgen/var.go
rename to internal/cgen/var.go
index 3465990..5a2cb50 100644
--- a/cmd/wuffs-c/internal/cgen/var.go
+++ b/internal/cgen/var.go
@@ -102,10 +102,8 @@
if header {
b.printf("uint8_t* %s%s = NULL;", iopPrefix, preName)
- b.printf("uint8_t* %s%s = NULL;", io0Prefix, preName)
- b.printf("uint8_t* %s%s = NULL;", io1Prefix, preName)
- b.printf("WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(%s%s);", io0Prefix, preName)
- b.printf("WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(%s%s);", io1Prefix, preName)
+ b.printf("uint8_t* %s%s WUFFS_BASE__POTENTIALLY_UNUSED = NULL;", io0Prefix, preName)
+ b.printf("uint8_t* %s%s WUFFS_BASE__POTENTIALLY_UNUSED = NULL;", io1Prefix, preName)
}
b.printf("if (%s.private_impl.buf) {", preName)
@@ -142,10 +140,10 @@
}
// TODO: also remove this hack.
if hack == "w" {
- b.printf("%sw.meta.wi = %s%sw - %sw.data.ptr;\n", uPrefix, iopPrefix, vPrefix, uPrefix)
+ b.printf("%sw.meta.wi = ((size_t)(%s%sw - %sw.data.ptr));\n", uPrefix, iopPrefix, vPrefix, uPrefix)
return nil
} else if hack == "r" {
- b.printf("%sr.meta.ri = %s%sr - %sr.data.ptr;\n", uPrefix, iopPrefix, vPrefix, uPrefix)
+ b.printf("%sr.meta.ri = ((size_t)(%s%sr - %sr.data.ptr));\n", uPrefix, iopPrefix, vPrefix, uPrefix)
return nil
}
@@ -166,7 +164,7 @@
}
b.printf("if (%s.private_impl.buf) {", preName)
- b.printf("%s.private_impl.buf->meta.%s = %s%s - %s.private_impl.buf->data.ptr;",
+ b.printf("%s.private_impl.buf->meta.%s = ((size_t)(%s%s - %s.private_impl.buf->data.ptr));",
preName, i0, iopPrefix, preName, preName)
b.printf("}\n")
return nil
@@ -231,7 +229,7 @@
local := fmt.Sprintf("%s%s", vPrefix, n.Name().Str(g.tm))
lhs := local
// TODO: don't hard-code [0], and allow recursive coroutines.
- rhs := fmt.Sprintf("self->private_impl.%s%s[0].%s", cPrefix, g.currFunk.astFunc.FuncName().Str(g.tm), lhs)
+ rhs := fmt.Sprintf("self->private_data.%s%s[0].%s", sPrefix, g.currFunk.astFunc.FuncName().Str(g.tm), lhs)
if suspend {
lhs, rhs = rhs, lhs
}
@@ -291,19 +289,23 @@
b.writes(" = false;\n")
} else if typ.IsStatus() {
b.writes(" = NULL;\n")
+ } else if typ.IsIOType() {
+ typName := "reader"
+ if typ.QID()[1] == t.IDIOWriter {
+ typName = "writer"
+ }
+ b.printf(" = wuffs_base__null_io_%s();\n", typName)
} else {
- b.writes(" = {};\n")
+ b.writes(" = {0};\n")
}
if typ.IsIOType() {
- b.printf("wuffs_base__io_buffer %s%s = {};\n", uPrefix, name)
+ b.printf("wuffs_base__io_buffer %s%s WUFFS_BASE__POTENTIALLY_UNUSED = "+
+ "wuffs_base__null_io_buffer();\n", uPrefix, name)
preName := vPrefix + name
// TODO: io0_etc variables?
- b.printf("uint8_t* %s%s = NULL;\n", iopPrefix, preName)
- b.printf("uint8_t* %s%s = NULL;\n", io1Prefix, preName)
- b.printf("WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(%s%s);\n", uPrefix, name)
- b.printf("WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(%s%s);\n", iopPrefix, preName)
- b.printf("WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(%s%s);\n", io1Prefix, preName)
+ b.printf("uint8_t* %s%s WUFFS_BASE__POTENTIALLY_UNUSED = NULL;\n", iopPrefix, preName)
+ b.printf("uint8_t* %s%s WUFFS_BASE__POTENTIALLY_UNUSED = NULL;\n", io1Prefix, preName)
}
}
return nil
diff --git a/internal/testcut/testcut.go b/internal/testcut/testcut.go
new file mode 100644
index 0000000..ba2d0ca
--- /dev/null
+++ b/internal/testcut/testcut.go
@@ -0,0 +1,179 @@
+// Copyright 2019 The Wuffs Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Package testcut provides support for testing flatecut and zlibcut.
+package testcut
+
+import (
+ "bytes"
+ "io"
+ "io/ioutil"
+ "testing"
+)
+
+func calculateDecodedLen(b []byte,
+ newReader func(io.Reader) (io.ReadCloser, error)) (int64, error) {
+
+ r, err := newReader(bytes.NewReader(b))
+ if err != nil {
+ return 0, err
+ }
+ n, err := io.Copy(ioutil.Discard, r)
+ if err != nil {
+ r.Close()
+ return 0, err
+ }
+ return n, r.Close()
+}
+
+func clone(b []byte) []byte {
+ return append([]byte(nil), b...)
+}
+
+func Test(t *testing.T,
+ smallestValidMaxEncodedLen int,
+ cut func([]byte, int) (int, int, error),
+ newReader func(io.Reader) (io.ReadCloser, error),
+ filenames []string) {
+
+ for _, filename := range filenames {
+ full, err := ioutil.ReadFile("../../test/data/" + filename)
+ if err != nil {
+ t.Errorf("f=%q: ReadFile: %v", filename, err)
+ continue
+ }
+ fullDecodedLen, err := calculateDecodedLen(full, newReader)
+ if err != nil {
+ t.Errorf("f=%q: calculateDecodedLen: %v", filename, err)
+ continue
+ }
+
+ maxEncodedLens := []int{
+ smallestValidMaxEncodedLen + 0,
+ smallestValidMaxEncodedLen + 1,
+ smallestValidMaxEncodedLen + 2,
+ smallestValidMaxEncodedLen + 3,
+ smallestValidMaxEncodedLen + 4,
+ smallestValidMaxEncodedLen + 5,
+ smallestValidMaxEncodedLen + 6,
+ smallestValidMaxEncodedLen + 7,
+ 20,
+ 77,
+ 234,
+ 512,
+ 1999,
+ 8192,
+ len(full) - 7,
+ len(full) - 6,
+ len(full) - 5,
+ len(full) - 4,
+ len(full) - 3,
+ len(full) - 2,
+ len(full) - 1,
+ len(full) + 0,
+ len(full) + 1,
+ len(full) + 2,
+ }
+
+ for _, maxEncodedLen := range maxEncodedLens {
+ if maxEncodedLen < smallestValidMaxEncodedLen {
+ continue
+ }
+ encoded := clone(full)
+ encLen, decLen, err := cut(encoded, maxEncodedLen)
+ if err != nil {
+ t.Errorf("f=%q, mEL=%d: cut: %v", filename, maxEncodedLen, err)
+ continue
+ }
+ if encLen > maxEncodedLen {
+ t.Errorf("f=%q, mEL=%d: encLen vs max: got %d, want <= %d",
+ filename, maxEncodedLen, encLen, maxEncodedLen)
+ continue
+ }
+ if encLen > len(encoded) {
+ t.Errorf("f=%q, mEL=%d: encLen vs len: got %d, want <= %d",
+ filename, maxEncodedLen, encLen, len(encoded))
+ continue
+ }
+
+ w := &bytes.Buffer{}
+ r, err := newReader(bytes.NewReader(encoded[:encLen]))
+ if err != nil {
+ t.Errorf("f=%q, mEL=%d: newReader: %v", filename, maxEncodedLen, err)
+ continue
+ }
+ if n, err := io.Copy(w, r); err != nil {
+ t.Errorf("f=%q, mEL=%d: io.Copy: %v", filename, maxEncodedLen, err)
+ continue
+ } else if n != int64(decLen) {
+ t.Errorf("f=%q, mEL=%d: io.Copy: got %d, want %d",
+ filename, maxEncodedLen, n, decLen)
+ continue
+ }
+
+ if (maxEncodedLen == len(encoded)) && (int64(decLen) != fullDecodedLen) {
+ t.Errorf("f=%q, mEL=%d: full decode: got %d, want %d",
+ filename, maxEncodedLen, decLen, fullDecodedLen)
+ continue
+ }
+
+ if err := r.Close(); err != nil {
+ t.Errorf("f=%q, mEL=%d: r.Close: %v", filename, maxEncodedLen, err)
+ continue
+ }
+ }
+ }
+}
+
+func Benchmark(b *testing.B,
+ smallestValidMaxEncodedLen int,
+ cut func([]byte, int) (int, int, error),
+ newReader func(io.Reader) (io.ReadCloser, error),
+ filename string,
+ trimPrefix int,
+ trimSuffix int,
+ decodedLen int64) {
+
+ full, err := ioutil.ReadFile("../../test/data/" + filename)
+ if err != nil {
+ b.Fatalf("ReadFile: %v", err)
+ }
+
+ if len(full) < (trimPrefix + trimSuffix) {
+ b.Fatalf("len(full): got %d, want >= %d", len(full), trimPrefix+trimSuffix)
+ }
+ full = full[trimPrefix : len(full)-trimSuffix]
+
+ if n, err := calculateDecodedLen(full, newReader); err != nil {
+ b.Fatalf("calculateDecodedLen: %v", err)
+ } else if n != decodedLen {
+ b.Fatalf("calculateDecodedLen: got %d, want %d", n, decodedLen)
+ }
+
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ for maxEncodedLen := 10; ; maxEncodedLen *= 10 {
+ if maxEncodedLen < smallestValidMaxEncodedLen {
+ continue
+ }
+ encoded := clone(full)
+ if _, _, err := cut(encoded, maxEncodedLen); err != nil {
+ b.Fatalf("cut: %v", err)
+ }
+ if maxEncodedLen >= len(full) {
+ break
+ }
+ }
+ }
+}
diff --git a/lang/ast/ast.go b/lang/ast/ast.go
index 10a7cf5..eac9489 100644
--- a/lang/ast/ast.go
+++ b/lang/ast/ast.go
@@ -102,6 +102,7 @@
FlagsClassy = Flags(0x00001000)
FlagsSubExprHasEffect = Flags(0x00002000)
FlagsRetsError = Flags(0x00004000)
+ FlagsPrivateData = Flags(0x00008000)
)
func (f Flags) AsEffect() Effect { return Effect(f) }
@@ -301,7 +302,7 @@
// - List0: <Arg|Expr> function call args, assoc. op args or list members.
//
// A zero ID0 means an identifier or literal in ID2, like `foo`, `42` or a
-// status literal like `"?foo"` or `pkg."$bar"`. For status literals, ID1 is
+// status literal like `"#foo"` or `pkg."$bar"`. For status literals, ID1 is
// the package.
//
// For unary operators, ID0 is the operator and RHS is the operand.
@@ -453,19 +454,22 @@
}
// Field is a "name type" struct field:
+// - FlagsPrivateData is the initializer need not explicitly memset to zero.
// - ID2: name
// - LHS: <TypeExpr>
type Field Node
-func (n *Field) AsNode() *Node { return (*Node)(n) }
-func (n *Field) Name() t.ID { return n.id2 }
-func (n *Field) XType() *TypeExpr { return n.lhs.AsTypeExpr() }
+func (n *Field) AsNode() *Node { return (*Node)(n) }
+func (n *Field) PrivateData() bool { return n.flags&FlagsPrivateData != 0 }
+func (n *Field) Name() t.ID { return n.id2 }
+func (n *Field) XType() *TypeExpr { return n.lhs.AsTypeExpr() }
-func NewField(name t.ID, xType *TypeExpr) *Field {
+func NewField(flags Flags, name t.ID, xType *TypeExpr) *Field {
return &Field{
- kind: KField,
- id2: name,
- lhs: xType.AsNode(),
+ kind: KField,
+ flags: flags,
+ id2: name,
+ lhs: xType.AsNode(),
}
}
diff --git a/lang/ast/string.go b/lang/ast/string.go
index 871814c..7a02a00 100644
--- a/lang/ast/string.go
+++ b/lang/ast/string.go
@@ -164,7 +164,7 @@
t.IDXBinaryTildeModMinus: " ~mod- ",
t.IDXBinaryTildeSatPlus: " ~sat+ ",
t.IDXBinaryTildeSatMinus: " ~sat- ",
- t.IDXBinaryNotEq: " != ",
+ t.IDXBinaryNotEq: " <> ",
t.IDXBinaryLessThan: " < ",
t.IDXBinaryLessEq: " <= ",
t.IDXBinaryEqEq: " == ",
diff --git a/lang/builtin/builtin.go b/lang/builtin/builtin.go
index 43d44ad..47de929 100644
--- a/lang/builtin/builtin.go
+++ b/lang/builtin/builtin.go
@@ -21,26 +21,28 @@
var Statuses = [...]string{
// Warnings.
- `"~end of data"`,
+ `"@end of data"`,
// Suspensions.
`"$short read"`,
`"$short write"`,
// Errors.
- `"?bad argument (length too short)"`,
- `"?bad argument"`,
- `"?bad call sequence"`,
- `"?bad receiver"`,
- `"?bad restart"`,
- `"?bad sizeof receiver"`,
- `"?bad workbuf length"`,
- `"?bad wuffs version"`,
- `"?cannot return a suspension"`,
- `"?check_wuffs_version not applicable"`,
- `"?check_wuffs_version missing"`,
- `"?disabled by previous error"`,
- `"?interleaved coroutine calls"`,
+ `"#bad argument (length too short)"`,
+ `"#bad argument"`,
+ `"#bad call sequence"`,
+ `"#bad receiver"`,
+ `"#bad restart"`,
+ `"#bad sizeof receiver"`,
+ `"#bad workbuf length"`,
+ `"#bad wuffs version"`,
+ `"#cannot return a suspension"`,
+ `"#disabled by previous error"`,
+ `"#initialize falsely claimed already zeroed"`,
+ `"#initialize not called"`,
+ `"#interleaved coroutine calls"`,
+ `"#not enough data"`,
+ `"#too much data"`,
}
// TODO: a collection of forbidden variable names like and, or, not, as, ref,
@@ -108,6 +110,7 @@
"utility.make_rect_ie_u32(min_incl_x u32, min_incl_y u32, max_excl_x u32, max_excl_y u32) rect_ie_u32",
"utility.null_io_reader() io_reader",
"utility.null_io_writer() io_writer",
+ "utility.null_slice_u8() slice u8",
// ---- ranges
diff --git a/lang/check/assert.go b/lang/check/assert.go
index 5c16a43..7ae3931 100644
--- a/lang/check/assert.go
+++ b/lang/check/assert.go
@@ -348,3 +348,22 @@
}
return nil
}
+
+func proveReasonRequirementForRHSLength(q *checker, op t.ID, lhs *a.Expr, rhs *a.Expr) error {
+ if err := proveReasonRequirement(q, op, lhs, rhs); err != nil {
+ if (op == t.IDXBinaryLessThan) || (op == t.IDXBinaryLessEq) {
+ for _, x := range q.facts {
+ // Try to prove "lhs op rhs" by proving "lhs op const", given a
+ // fact x of the form "rhs >= const".
+ if (x.Operator() == t.IDXBinaryGreaterEq) && x.LHS().AsExpr().Eq(rhs) &&
+ (x.RHS().AsExpr().ConstValue() != nil) &&
+ (proveReasonRequirement(q, op, lhs, x.RHS().AsExpr()) == nil) {
+
+ return nil
+ }
+ }
+ }
+ return err
+ }
+ return nil
+}
diff --git a/lang/check/bounds.go b/lang/check/bounds.go
index 615dfc7..a2d36ef 100644
--- a/lang/check/bounds.go
+++ b/lang/check/bounds.go
@@ -79,7 +79,7 @@
func isErrorStatus(literal t.ID, tm *t.Map) bool {
s := literal.Str(tm)
- return (len(s) >= 2) && (s[0] == '"') && (s[1] == '?')
+ return (len(s) >= 2) && (s[0] == '"') && (s[1] == '#')
}
func btoi(b bool) *big.Int {
@@ -308,7 +308,7 @@
if q.astFunc.Effect().Coroutine() {
lTyp = typeExprStatus
} else if lTyp == nil {
- return fmt.Errorf("TODO: allow returning nothing")
+ lTyp = typeExprEmptyStruct
}
if _, err := q.bcheckAssignment1(nil, lTyp, t.IDEq, n.Value()); err != nil {
return err
@@ -866,7 +866,7 @@
if err := proveReasonRequirement(q, t.IDXBinaryLessEq, zeroExpr, rhs); err != nil {
return bounds{}, err
}
- if err := proveReasonRequirement(q, t.IDXBinaryLessThan, rhs, lengthExpr); err != nil {
+ if err := proveReasonRequirementForRHSLength(q, t.IDXBinaryLessThan, rhs, lengthExpr); err != nil {
return bounds{}, err
}
@@ -915,7 +915,7 @@
return bounds{}, err
}
if rhs != lengthExpr {
- if err := proveReasonRequirement(q, t.IDXBinaryLessEq, rhs, lengthExpr); err != nil {
+ if err := proveReasonRequirementForRHSLength(q, t.IDXBinaryLessEq, rhs, lengthExpr); err != nil {
return bounds{}, err
}
}
diff --git a/lang/check/check.go b/lang/check/check.go
index 698b252..5c82f7a 100644
--- a/lang/check/check.go
+++ b/lang/check/check.go
@@ -220,7 +220,9 @@
switch n.Kind() {
case a.KConst:
- return fmt.Errorf("TODO: type-check a used-package const")
+ if err := c.checkConst(n); err != nil {
+ return err
+ }
case a.KFunc:
if err := c.checkFuncSignature(n); err != nil {
return err
diff --git a/lang/check/check_test.go b/lang/check/check_test.go
index 12aabca..d80cc9e 100644
--- a/lang/check/check_test.go
+++ b/lang/check/check_test.go
@@ -86,7 +86,7 @@
while:label p == q,
pre true,
inv true,
- post p != q,
+ post p <> q,
{
// Redundant, but shows the labeled jump syntax.
continue:label
@@ -191,7 +191,7 @@
"i = 10 | 3": 11,
"i = 10 ^ 3": 9,
- "b = 10 != 3": 1,
+ "b = 10 <> 3": 1,
"b = 10 < 3": 0,
"b = 10 <= 3": 0,
"b = 10 == 3": 0,
diff --git a/lang/check/resolve.go b/lang/check/resolve.go
index cf99f3d..a1ce9c9 100644
--- a/lang/check/resolve.go
+++ b/lang/check/resolve.go
@@ -138,7 +138,9 @@
}
}
}
- file, err := parse.Parse(c.tm, filename, tokens, nil)
+ file, err := parse.Parse(c.tm, filename, tokens, &parse.Options{
+ AllowBuiltInNames: true,
+ })
if err != nil {
return nil, fmt.Errorf("check: parsing %q: could not parse built-in funcs: %v", s, err)
}
diff --git a/lang/check/type.go b/lang/check/type.go
index f76ac6a..668e94b 100644
--- a/lang/check/type.go
+++ b/lang/check/type.go
@@ -173,7 +173,7 @@
if q.astFunc.Effect().Coroutine() {
lTyp = typeExprStatus
} else if lTyp == nil {
- return fmt.Errorf("TODO: allow returning nothing")
+ lTyp = typeExprEmptyStruct
}
value := n.Value()
if err := q.tcheckExpr(value, 0); err != nil {
@@ -391,6 +391,11 @@
n.SetMType(typeExprBool)
return nil
+ case t.IDNothing:
+ n.SetConstValue(zero)
+ n.SetMType(typeExprEmptyStruct)
+ return nil
+
case t.IDNullptr:
n.SetConstValue(zero)
n.SetMType(typeExprNullptr)
@@ -932,7 +937,7 @@
if err := q.tcheckExpr(b, 0); err != nil {
return err
}
- if b.ConstValue() == nil {
+ if q.exprConstValue(b) == nil {
return fmt.Errorf("check: %q is not constant", b.Str(q.tm))
}
}
@@ -958,7 +963,7 @@
if err := q.tcheckExpr(aLen, 0); err != nil {
return err
}
- if aLen.ConstValue() == nil {
+ if q.exprConstValue(aLen) == nil {
return fmt.Errorf("check: %q is not constant", aLen.Str(q.tm))
}
fallthrough
@@ -975,6 +980,21 @@
return nil
}
+func (q *checker) exprConstValue(n *a.Expr) *big.Int {
+ if cv := n.ConstValue(); cv != nil {
+ return cv
+ }
+ if n.Operator() == 0 {
+ if c, ok := q.c.consts[t.QID{0, n.Ident()}]; ok {
+ if cv := c.Value().ConstValue(); cv != nil {
+ n.SetConstValue(cv)
+ return cv
+ }
+ }
+ }
+ return nil
+}
+
var comparisonOps = [...]bool{
t.IDXBinaryNotEq: true,
t.IDXBinaryLessThan: true,
diff --git a/lang/generate/generate.go b/lang/generate/generate.go
index 1ec3f80..5f0f616 100644
--- a/lang/generate/generate.go
+++ b/lang/generate/generate.go
@@ -90,7 +90,7 @@
// Blacklist certain package names.
switch s {
case "base", "base_private", "base_private_header", "base_public", "base_public_header",
- "config", "implementation", "include_guard", "version":
+ "config", "implementation", "include_guard", "initialize", "version":
return ""
}
return s
diff --git a/lang/parse/parse.go b/lang/parse/parse.go
index 466c9d5..89f6468 100644
--- a/lang/parse/parse.go
+++ b/lang/parse/parse.go
@@ -24,6 +24,7 @@
)
type Options struct {
+ AllowBuiltInNames bool
AllowDoubleUnderscoreNames bool
}
@@ -156,6 +157,13 @@
if err != nil {
return nil, err
}
+ if !p.opts.AllowBuiltInNames {
+ switch id1 {
+ case t.IDInitialize, t.IDReset:
+ return nil, fmt.Errorf(`parse: cannot have a method named %q at %s:%d`,
+ id1.Str(p.tm), p.filename, p.line())
+ }
+ }
// TODO: should we require id0 != 0? In other words, always methods
// (attached to receivers) and never free standing functions?
if !p.opts.AllowDoubleUnderscoreNames && isDoubleUnderscore(p.tm.ByID(id1)) {
@@ -239,6 +247,13 @@
if err != nil {
return nil, err
}
+ if x := p.peek1(); x == t.IDOpenParen {
+ extraFields, err := p.parseList(t.IDCloseParen, (*parser).parseExtraFieldNode)
+ if err != nil {
+ return nil, err
+ }
+ fields = append(fields, extraFields...)
+ }
if x := p.peek1(); x != t.IDSemicolon {
got := p.tm.ByID(x)
return nil, fmt.Errorf(`parse: expected (implicit) ";", got %q at %s:%d`, got, p.filename, p.line())
@@ -323,6 +338,28 @@
}
func (p *parser) parseFieldNode() (*a.Node, error) {
+ return p.parseFieldNode1(0)
+}
+
+func (p *parser) parseExtraFieldNode() (*a.Node, error) {
+ n, err := p.parseFieldNode1(a.FlagsPrivateData)
+ if err != nil {
+ return nil, err
+ }
+ typ := n.AsField().XType()
+ for typ.Decorator() == t.IDArray {
+ typ = typ.Inner()
+ }
+ if (typ.Decorator() != 0) ||
+ (typ.QID()[0] == t.IDBase) && (!typ.IsNumType() || typ.IsRefined()) {
+
+ return nil, fmt.Errorf(`parse: invalid extra-field type %q at %s:%d`,
+ n.AsField().XType().Str(p.tm), p.filename, p.line())
+ }
+ return n, nil
+}
+
+func (p *parser) parseFieldNode1(flags a.Flags) (*a.Node, error) {
name, err := p.parseIdent()
if err != nil {
return nil, err
@@ -331,7 +368,10 @@
if err != nil {
return nil, err
}
- return a.NewField(name, typ).AsNode(), nil
+ if pkg := typ.Innermost().QID()[0]; (pkg != 0) && (pkg != t.IDBase) {
+ flags |= a.FlagsPrivateData
+ }
+ return a.NewField(flags, name, typ).AsNode(), nil
}
func (p *parser) parseTypeExpr() (*a.TypeExpr, error) {
@@ -602,8 +642,14 @@
case t.IDReturn, t.IDYield:
p.src = p.src[1:]
- if x == t.IDYield && !p.funcEffect.Coroutine() {
- return nil, fmt.Errorf(`parse: yield within non-coroutine at %s:%d`, p.filename, p.line())
+ if x == t.IDYield {
+ if !p.funcEffect.Coroutine() {
+ return nil, fmt.Errorf(`parse: yield within non-coroutine at %s:%d`, p.filename, p.line())
+ }
+ if p.peek1() != t.IDQuestion {
+ return nil, fmt.Errorf(`parse: yield not followed by '?' at %s:%d`, p.filename, p.line())
+ }
+ p.src = p.src[1:]
}
value, err := p.parseExpr()
if err != nil {
diff --git a/lang/render/render.go b/lang/render/render.go
index 1ee8746..1265dd6 100644
--- a/lang/render/render.go
+++ b/lang/render/render.go
@@ -164,6 +164,8 @@
return errors.New("render: too many \"}\" tokens")
}
indent--
+ } else if (tok.ID == t.IDQuestion) && (prevID == t.IDYield) {
+ buf = append(buf, ' ')
}
prevIsTightRight = tok.ID.IsTightRight()
@@ -262,7 +264,12 @@
line := lineTokens[0].Line
length := len(tm.ByID(lineTokens[x].ID))
- for (len(remaining) > x) && ((x == 0) || (remaining[0].ID == t.IDVar)) && (remaining[0].Line == line+1) {
+ for (len(remaining) > x) &&
+ ((x == 0) || (remaining[0].ID == t.IDVar)) &&
+ (remaining[0].Line == line+1) &&
+ (remaining[x].Line == line+1) &&
+ (remaining[x].ID.IsIdent(tm)) {
+
line = remaining[0].Line
length = max(length, len(tm.ByID(remaining[x].ID)))
diff --git a/lang/token/list.go b/lang/token/list.go
index 0dd118c..85cb5c5 100644
--- a/lang/token/list.go
+++ b/lang/token/list.go
@@ -382,8 +382,9 @@
IDFalse = ID(0xB0)
IDTrue = ID(0xB1)
- IDNullptr = ID(0xB2)
- IDOk = ID(0xB3)
+ IDNothing = ID(0xB2)
+ IDNullptr = ID(0xB3)
+ IDOk = ID(0xB4)
ID0 = ID(0xC0)
ID1 = ID(0xC1)
@@ -577,9 +578,11 @@
// -------- 0x200 block.
- IDReset = ID(0x200)
- IDSet = ID(0x201)
- IDUnroll = ID(0x202)
+ IDInitialize = ID(0x200)
+ IDReset = ID(0x201)
+ IDSet = ID(0x202)
+ IDUnroll = ID(0x203)
+ IDUpdate = ID(0x204)
// TODO: range/rect methods like intersection and contains?
@@ -657,7 +660,7 @@
IDTildeSatPlus: "~sat+",
IDTildeSatMinus: "~sat-",
- IDNotEq: "!=",
+ IDNotEq: "<>",
IDLessThan: "<",
IDLessEq: "<=",
IDEqEq: "==",
@@ -702,6 +705,7 @@
IDFalse: "false",
IDTrue: "true",
+ IDNothing: "nothing",
IDNullptr: "nullptr",
IDOk: "ok",
@@ -904,9 +908,11 @@
// -------- 0x200 block.
- IDReset: "reset",
- IDSet: "set",
- IDUnroll: "unroll",
+ IDInitialize: "initialize",
+ IDReset: "reset",
+ IDSet: "set",
+ IDUnroll: "unroll",
+ IDUpdate: "update",
IDHighBits: "high_bits",
IDLowBits: "low_bits",
@@ -950,6 +956,7 @@
'}': IDCloseCurly,
',': IDComma,
+ '!': IDExclam,
'?': IDQuestion,
':': IDColon,
';': IDSemicolon,
@@ -971,10 +978,6 @@
{".", IDDotDot},
{"", IDDot},
},
- '!': {
- {"=", IDNotEq},
- {"", IDExclam},
- },
'&': {
{"=", IDAmpEq},
{"", IDAmp},
@@ -1016,6 +1019,7 @@
{"<=", IDShiftLEq},
{"<", IDShiftL},
{"=", IDLessEq},
+ {">", IDNotEq},
{"", IDLessThan},
},
'>': {
diff --git a/lib/base38/base38.go b/lib/base38/base38.go
index 5877210..e22f8e5 100644
--- a/lib/base38/base38.go
+++ b/lib/base38/base38.go
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// ----------------
+
// Package base38 converts a 4-byte string, each byte in [ 0-9?a-z], to a base
// 38 number.
package base38
diff --git a/lib/flatecut/flatecut.go b/lib/flatecut/flatecut.go
new file mode 100644
index 0000000..cc4e7fc
--- /dev/null
+++ b/lib/flatecut/flatecut.go
@@ -0,0 +1,637 @@
+// Copyright 2019 The Wuffs Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// ----------------
+
+// Package flatecut produces DEFLATE-formatted data subject to a maximum
+// compressed size.
+//
+// The typical compression problem is to encode all of the given source data in
+// some number of bytes. This package's problem is finding a reasonably long
+// prefix of the source data that encodes in up to a given number of bytes.
+package flatecut
+
+import (
+ "errors"
+)
+
+var (
+ errMaxEncodedLenTooSmall = errors.New("flatecut: maxEncodedLen is too small")
+
+ errInternalNoProgress = errors.New("flatecut: internal: no progress")
+ errInternalSomeProgress = errors.New("flatecut: internal: some progress")
+
+ errInvalidBadBlockLength = errors.New("flatecut: invalid input: bad block length")
+ errInvalidBadBlockType = errors.New("flatecut: invalid input: bad block type")
+ errInvalidBadCodeLengths = errors.New("flatecut: invalid input: bad code lengths")
+ errInvalidBadHuffmanTree = errors.New("flatecut: invalid input: bad Huffman tree")
+ errInvalidBadSymbol = errors.New("flatecut: invalid input: bad symbol")
+ errInvalidNoEndOfBlock = errors.New("flatecut: invalid input: no end-of-block")
+ errInvalidNotEnoughData = errors.New("flatecut: invalid input: not enough data")
+ errInvalidTooManyCodes = errors.New("flatecut: invalid input: too many codes")
+)
+
+var (
+ // codeOrder is defined in RFC 1951 section 3.2.7.
+ codeOrder = [19]uint32{16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}
+
+ // These tables are defined in RFC 1951 section 3.2.5.
+ //
+ // The l-tables' indexes are biased by 256.
+ lBases = [32]int32{
+ mostNegativeInt32,
+ 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
+ 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258,
+ mostNegativeInt32, mostNegativeInt32,
+ }
+ lExtras = [32]uint32{
+ 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
+ 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0,
+ 0, 0,
+ }
+ dBases = [32]int32{
+ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
+ 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577,
+ mostNegativeInt32, mostNegativeInt32,
+ }
+ dExtras = [32]uint32{
+ 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
+ 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13,
+ 0, 0,
+ }
+)
+
+const (
+ // SmallestValidMaxEncodedLen is the length in bytes of the smallest valid
+ // DEFLATE-encoded data.
+ SmallestValidMaxEncodedLen = 2
+
+ maxCodeBits = 15
+ maxNumCodes = 288
+
+ mostNegativeInt32 = -0x80000000
+)
+
+type bitstream struct {
+ // bytes[index] is the next byte to load into the 'bits' field.
+ bytes []byte
+ index int
+
+ // The low nBits bits of the 'bits' field hold the next bits (in LSB-first
+ // order).
+ bits uint32
+ nBits uint32
+}
+
+func (b *bitstream) take(nBits uint32) int32 {
+ for b.nBits < nBits {
+ if b.index >= len(b.bytes) {
+ return mostNegativeInt32
+ }
+ b.bits |= uint32(b.bytes[b.index]) << b.nBits
+ b.nBits += 8
+ b.index++
+ }
+
+ mask := ((uint32(1)) << nBits) - 1
+ ret := b.bits & mask
+ b.bits >>= nBits
+ b.nBits -= nBits
+ return int32(ret)
+}
+
+// huffman represents a DEFLATE Huffman tree.
+//
+// For the "Consider the alphabet ABCDEFGH, with bit lengths (3, 3, 3, 3, 3, 2,
+// 4, 4)" example from RFC 1951 section 3.2.2, the huffman struct is
+// initialized by calling:
+//
+// h.construct([]uint32{
+// 'A': 3, 'B': 3, 'C': 3, 'D': 3, 'E': 3, 'F': 2, 'G': 4, 'H': 4,
+// })
+//
+// which results in:
+//
+// huffman{
+// counts: []uint32{
+// 2: 1, 3: 5, 4: 2,
+// },
+// symbols: []int32{
+// 0: 'F', 1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E', 6: 'G', 7: 'H',
+// },
+// }
+//
+// Continuing the example from the RFC, decoding "1110" from the bitstream will
+// produce the 'G' symbol.
+type huffman struct {
+ counts [maxCodeBits + 1]uint32
+ symbols [maxNumCodes]int32
+}
+
+func (h *huffman) decode(b *bitstream) int32 {
+ code := uint32(0) // The i bits from the bitstream.
+ first := uint32(0) // The first Huffman code of length i.
+ symIndex := uint32(0) // How many elements of h.symbols we've gone past.
+
+ // The "at this point" comments in the loop detail the `"1110" decodes to
+ // 'G'` example discussed above in the huffman type's doc comment.
+ //
+ // Note that, as a loop invariant, code >= first.
+ for i := 1; i <= maxCodeBits; i++ {
+ if b.nBits == 0 {
+ if b.index >= len(b.bytes) {
+ return mostNegativeInt32
+ }
+ b.bits = uint32(b.bytes[b.index])
+ b.nBits = 8
+ b.index++
+ }
+
+ code |= b.bits & 1
+ b.bits >>= 1
+ b.nBits -= 1
+
+ // At this point:
+ // - When i == 1, code is 1, symIndex is 0, first is 0.
+ // - When i == 2, code is 3, symIndex is 0, first is 0.
+ // - When i == 3, code is 7, symIndex is 1, first is 2.
+ // - When i == 4, code is 14, symIndex is 6, first is 14.
+
+ // Recall that h.counts is: {0, 0, 1, 5, 2, 0, 0, ...}.
+ count := h.counts[i]
+ if code < (count + first) {
+ // At this point:
+ // - When i == 4, code is 14, symIndex is 6, first is 14.
+ //
+ // h.symbols[6+14-14] is indeed 'G'.
+ return h.symbols[symIndex+code-first]
+ }
+
+ symIndex += count
+ first += count
+ first <<= 1
+ code <<= 1
+
+ // At this point:
+ // - When i == 1, code is 2, symIndex is 0, first is 0.
+ // - When i == 2, code is 6, symIndex is 1, first is 2.
+ // - When i == 3, code is 14, symIndex is 6, first is 14.
+ }
+ return mostNegativeInt32
+}
+
+func (h *huffman) construct(lengths []uint32) (endCodeBits uint32, endCodeNBits uint32, retErr error) {
+ for i := range h.counts {
+ h.counts[i] = 0
+ }
+ for _, x := range lengths {
+ h.counts[x]++
+ }
+ if h.counts[0] == uint32(len(lengths)) {
+ return 0, 0, errInvalidBadHuffmanTree
+ }
+
+ // Check for an over- or under-subscribed Huffman tree, and for the
+ // end-of-block code (with value 256).
+ const endCode = 256
+ remaining := uint32(1)
+ endCodeLength := uint32(0)
+ if len(lengths) > endCode {
+ endCodeLength = lengths[endCode]
+ }
+ for i := uint32(1); i <= maxCodeBits; i++ {
+ remaining *= 2
+ if remaining < h.counts[i] {
+ return 0, 0, errInvalidBadHuffmanTree
+ }
+ remaining -= h.counts[i]
+
+ if i == endCodeLength {
+ remainingForEndCode := remaining
+ for _, l := range lengths[endCode+1:] {
+ if l == endCodeLength {
+ remainingForEndCode++
+ }
+ }
+ endCodeBits = ((uint32(1) << endCodeLength) - 1) - remainingForEndCode
+ endCodeNBits = endCodeLength
+ }
+ }
+ if remaining != 0 {
+ return 0, 0, errInvalidBadHuffmanTree
+ }
+
+ offsets := [maxCodeBits + 1]uint32{}
+ for i := 1; i < maxCodeBits; i++ {
+ offsets[i+1] = offsets[i] + h.counts[i]
+ }
+
+ for symbol, length := range lengths {
+ if length != 0 {
+ h.symbols[offsets[length]] = int32(symbol)
+ offsets[length]++
+ }
+ }
+ return endCodeBits, endCodeNBits, nil
+}
+
+// cutEmpty sets encoding[:2] to contain valid DEFLATE-encoded data. Decoding
+// that data produces zero bytes.
+func cutEmpty(encoded []byte, maxEncodedLen int) (encodedLen int, decodedLen int, retErr error) {
+ if maxEncodedLen < SmallestValidMaxEncodedLen {
+ panic("unreachable")
+ }
+ // Set encoded[:2] to hold:
+ // - 1 bit ...._...._...._...1 finalBlock = true.
+ // - 2 bits ...._...._...._.01. blockType = 1 (static Huffman).
+ // - 7 bits ...._..00_0000_0... litLenSymbol = 256 (end-of-block).
+ // - 6 bits 0000_00.._...._.... padding.
+ encoded[0] = 0x03
+ encoded[1] = 0x00
+ return 2, 0, nil
+}
+
+// Cut modifies encoded's contents such that encoded[:encodedLen] is valid
+// DEFLATE-compressed data, assuming that encoded starts off containing valid
+// DEFLATE-compressed data.
+//
+// Decompressing that modified, shorter byte slice produces a prefix (of length
+// decodedLen) of the decompression of the original, longer byte slice.
+//
+// It does not necessarily return the largest possible decodedLen.
+func Cut(encoded []byte, maxEncodedLen int) (encodedLen int, decodedLen int, retErr error) {
+ if maxEncodedLen < SmallestValidMaxEncodedLen {
+ return 0, 0, errMaxEncodedLenTooSmall
+ }
+ const m = 1 << 30
+ if uint64(maxEncodedLen) > m {
+ maxEncodedLen = m
+ }
+ if maxEncodedLen > len(encoded) {
+ maxEncodedLen = len(encoded)
+ }
+ if maxEncodedLen < SmallestValidMaxEncodedLen {
+ return 0, 0, errInvalidNotEnoughData
+ }
+
+ c := cutter{
+ bits: bitstream{
+ bytes: encoded,
+ },
+ maxEncodedLen: maxEncodedLen,
+ }
+ return c.cut()
+}
+
+type cutter struct {
+ bits bitstream
+
+ maxEncodedLen int
+ decodedLen int32
+
+ endCodeBits uint32
+ endCodeNBits uint32
+
+ lHuff huffman
+ dHuff huffman
+}
+
+func (c *cutter) cut() (encodedLen int, decodedLen int, retErr error) {
+ prevFinalBlockIndex := -1
+ prevFinalBlockNBits := uint32(0)
+
+ for {
+ finalBlock := c.bits.take(1)
+ if finalBlock < 0 {
+ return 0, 0, errInvalidNotEnoughData
+ }
+
+ finalBlockIndex := c.bits.index
+ finalBlockNBits := c.bits.nBits
+
+ blockType := c.bits.take(2)
+ if blockType < 0 {
+ return 0, 0, errInvalidNotEnoughData
+ }
+
+ err := error(nil)
+ switch blockType {
+ case 0:
+ err = c.doStored()
+ case 1:
+ err = c.doStaticHuffman()
+ case 2:
+ err = c.doDynamicHuffman()
+ case 3:
+ return 0, 0, errInvalidBadBlockType
+ }
+
+ switch err {
+ case nil:
+ if finalBlock == 0 {
+ prevFinalBlockIndex = finalBlockIndex
+ prevFinalBlockNBits = finalBlockNBits
+ continue
+ }
+
+ case errInternalNoProgress:
+ if prevFinalBlockIndex < 0 {
+ return cutEmpty(c.bits.bytes, c.maxEncodedLen)
+ }
+
+ // Un-read to just before the finalBlock bit.
+ c.bits.index = finalBlockIndex
+ c.bits.nBits = finalBlockNBits + 1
+ if c.bits.nBits == 8 {
+ c.bits.index--
+ c.bits.nBits = 0
+ }
+
+ finalBlockIndex = prevFinalBlockIndex
+ finalBlockNBits = prevFinalBlockNBits
+ fallthrough
+
+ case errInternalSomeProgress:
+ // Set the n'th bit (LSB=0, MSB=7) of
+ // c.bits.bytes[finalBlockIndex-1] to be 1.
+ n := 7 - finalBlockNBits
+ mask := uint32(1) << n
+ c.bits.bytes[finalBlockIndex-1] |= uint8(mask)
+
+ default:
+ return 0, 0, err
+
+ }
+ break
+ }
+
+ if c.bits.nBits != 0 {
+ // Clear the high c.bits.nBits bits of c.bits.bytes[c.bits.index-1].
+ mask := (uint32(1) << (8 - c.bits.nBits)) - 1
+ c.bits.bytes[c.bits.index-1] &= uint8(mask)
+ }
+
+ return c.bits.index, int(c.decodedLen), nil
+}
+
+func (c *cutter) doStored() error {
+ if (c.maxEncodedLen - c.bits.index) < 4 {
+ return errInternalNoProgress
+ }
+ length := uint32(c.bits.bytes[c.bits.index+0]) | uint32(c.bits.bytes[c.bits.index+1])<<8
+ invLen := uint32(c.bits.bytes[c.bits.index+2]) | uint32(c.bits.bytes[c.bits.index+3])<<8
+ if length+invLen != 0xFFFF {
+ return errInvalidBadBlockLength
+ }
+
+ // Check for potential overflow.
+ if (c.decodedLen + int32(length)) < 0 {
+ return errInternalNoProgress
+ }
+
+ index := c.bits.index + 4
+ if remaining := c.maxEncodedLen - index; remaining >= int(length) {
+ c.bits.index = index + int(length)
+ c.bits.bits = 0
+ c.bits.nBits = 0
+ c.decodedLen += int32(length)
+ return nil
+ } else if remaining == 0 {
+ return errInternalNoProgress
+ } else {
+ length = uint32(remaining)
+ invLen = 0xFFFF - length
+ }
+
+ c.bits.bytes[c.bits.index+0] = uint8(length >> 0)
+ c.bits.bytes[c.bits.index+1] = uint8(length >> 8)
+ c.bits.bytes[c.bits.index+2] = uint8(invLen >> 0)
+ c.bits.bytes[c.bits.index+3] = uint8(invLen >> 8)
+ c.bits.index = index + int(length)
+ c.bits.bits = 0
+ c.bits.nBits = 0
+ c.decodedLen += int32(length)
+ return errInternalSomeProgress
+}
+
+func (c *cutter) doStaticHuffman() error {
+ const (
+ numLCodes = 288
+ numDCodes = 32
+ )
+
+ // Initialize lengths as per RFC 1951 section 3.2.6.
+ lengths := make([]uint32, numLCodes+numDCodes)
+ i := 0
+ for ; i < 144; i++ {
+ lengths[i] = 8
+ }
+ for ; i < 256; i++ {
+ lengths[i] = 9
+ }
+ for ; i < 280; i++ {
+ lengths[i] = 7
+ }
+ for ; i < 288; i++ {
+ lengths[i] = 8
+ }
+ for ; i < 320; i++ {
+ lengths[i] = 5
+ }
+
+ return c.doHuffman(lengths[:numLCodes], lengths[numLCodes:])
+}
+
+func (c *cutter) doDynamicHuffman() error {
+ numLCodes := 257 + c.bits.take(5)
+ if numLCodes < 0 {
+ return errInvalidNotEnoughData
+ }
+
+ numDCodes := 1 + c.bits.take(5)
+ if numDCodes < 0 {
+ return errInvalidNotEnoughData
+ }
+
+ numCodeLengths := 4 + c.bits.take(4)
+ if numCodeLengths < 0 {
+ return errInvalidNotEnoughData
+ }
+
+ // The 286 and 30 numbers come from RFC 1951 section 3.2.5.
+ if (numLCodes > 286) || (numDCodes > 30) {
+ return errInvalidTooManyCodes
+ }
+
+ lengths := make([]uint32, numLCodes+numDCodes)
+ for i := int32(0); i < numCodeLengths; i++ {
+ x := c.bits.take(3)
+ if x < 0 {
+ return errInvalidNotEnoughData
+ }
+ lengths[codeOrder[i]] = uint32(x)
+ }
+
+ if _, _, err := c.lHuff.construct(lengths); err != nil {
+ return err
+ }
+
+ for i := int32(0); i < (numLCodes + numDCodes); {
+ symbol := c.lHuff.decode(&c.bits)
+ if symbol < 0 {
+ return errInvalidBadCodeLengths
+ }
+ value, count := uint32(0), int32(0)
+
+ switch symbol {
+ default:
+ lengths[i] = uint32(symbol)
+ i++
+ continue
+
+ case 16:
+ if i == 0 {
+ return errInvalidBadCodeLengths
+ }
+ value = lengths[i-1]
+ count = 3 + c.bits.take(2)
+
+ case 17:
+ count = 3 + c.bits.take(3)
+
+ case 18:
+ count = 11 + c.bits.take(7)
+ }
+ if count < 0 {
+ return errInvalidNotEnoughData
+ }
+
+ if (i + count) > (numLCodes + numDCodes) {
+ return errInvalidBadCodeLengths
+ }
+ for ; count > 0; count-- {
+ lengths[i] = value
+ i++
+ }
+ }
+
+ return c.doHuffman(lengths[:numLCodes], lengths[numLCodes:])
+}
+
+func (c *cutter) doHuffman(lLengths []uint32, dLengths []uint32) error {
+ err := error(nil)
+ if c.endCodeBits, c.endCodeNBits, err = c.lHuff.construct(lLengths); err != nil {
+ return err
+ }
+ if c.endCodeNBits == 0 {
+ return errInvalidNoEndOfBlock
+ }
+ if _, _, err := c.dHuff.construct(dLengths); err != nil {
+ return err
+ }
+
+ if c.bits.index > c.maxEncodedLen {
+ return errInternalNoProgress
+ }
+
+ checkpointIndex := -1
+ checkpointNBits := uint32(0)
+ decodedLen := c.decodedLen
+
+ for {
+ lSymbol := c.lHuff.decode(&c.bits)
+ if lSymbol < 0 {
+ return errInvalidBadSymbol
+
+ } else if lSymbol < 256 {
+ // It's a literal byte.
+ decodedLen++
+
+ } else if lSymbol > 256 {
+ // It's a length/distance copy.
+ length := lBases[lSymbol-256] + c.bits.take(lExtras[lSymbol-256])
+ if length < 0 {
+ if lBases[lSymbol-256] < 0 {
+ return errInvalidBadSymbol
+ }
+ return errInvalidNotEnoughData
+ }
+
+ dSymbol := c.dHuff.decode(&c.bits)
+ if dSymbol < 0 {
+ return errInvalidBadSymbol
+ }
+ distance := dBases[dSymbol] + c.bits.take(dExtras[dSymbol])
+ if distance < 0 {
+ if dBases[dSymbol] < 0 {
+ return errInvalidBadSymbol
+ }
+ return errInvalidNotEnoughData
+ }
+
+ decodedLen += length
+
+ } else {
+ // It's the end-of-block.
+ return nil
+ }
+
+ // Check for overflow.
+ if decodedLen < 0 {
+ break
+ }
+
+ // Check the maxEncodedLen budget, considering that we might still need
+ // to write an end-of-block code.
+ encodedBits := 8*uint64(c.bits.index) - uint64(c.bits.nBits)
+ maxEncodedBits := 8 * uint64(c.maxEncodedLen)
+ if encodedBits+uint64(c.endCodeNBits) > maxEncodedBits {
+ break
+ }
+
+ checkpointIndex = c.bits.index
+ checkpointNBits = c.bits.nBits
+ c.decodedLen = decodedLen
+ }
+
+ if checkpointIndex < 0 {
+ return errInternalNoProgress
+ }
+ c.bits.index = checkpointIndex
+ c.bits.nBits = checkpointNBits
+ c.writeEndCode()
+ return errInternalSomeProgress
+}
+
+func (c *cutter) writeEndCode() {
+ // Change c.bits.bytes[c.bits.index-1:]'s bits to have the end-of-block
+ // code. That code's bits are given MSB-to-LSB but the wire format reads
+ // LSB-to-MSB.
+ for j := c.endCodeNBits; j > 0; j-- {
+ if c.bits.nBits == 0 {
+ c.bits.index++
+ c.bits.nBits = 8
+ }
+ c.bits.nBits--
+
+ // Set the n'th bit (LSB=0, MSB=7) of c.bits.bytes[c.bits.index-1] to
+ // be b.
+ n := 7 - c.bits.nBits
+ b := (c.endCodeBits >> (j - 1)) & 1
+ mask := uint32(1) << n
+ c.bits.bytes[c.bits.index-1] &^= uint8(mask)
+ c.bits.bytes[c.bits.index-1] |= uint8(mask * b)
+ }
+}
diff --git a/lib/flatecut/flatecut_test.go b/lib/flatecut/flatecut_test.go
new file mode 100644
index 0000000..7c649ca
--- /dev/null
+++ b/lib/flatecut/flatecut_test.go
@@ -0,0 +1,41 @@
+// Copyright 2019 The Wuffs Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package flatecut
+
+import (
+ "compress/flate"
+ "io"
+ "testing"
+
+ "github.com/google/wuffs/internal/testcut"
+)
+
+func TestCut(t *testing.T) {
+ testcut.Test(t, SmallestValidMaxEncodedLen, Cut, newReader, []string{
+ "artificial/deflate-backref-crosses-blocks.deflate",
+ "artificial/deflate-distance-32768.deflate",
+ "romeo.txt.deflate",
+ "romeo.txt.fixed-huff.deflate",
+ })
+}
+
+func BenchmarkCut(b *testing.B) {
+ testcut.Benchmark(b, SmallestValidMaxEncodedLen, Cut, newReader,
+ "pi.txt.zlib", 2, 4, 100003)
+}
+
+func newReader(r io.Reader) (io.ReadCloser, error) {
+ return flate.NewReader(r), nil
+}
diff --git a/lib/interval/interval.go b/lib/interval/interval.go
index a896add..e6f7899 100644
--- a/lib/interval/interval.go
+++ b/lib/interval/interval.go
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// ----------------
+
// Package interval provides interval arithmetic on big integers. Big means
// arbitrary-precision, as per the standard math/big package.
//
diff --git a/lib/rac/example_test.go b/lib/rac/example_test.go
new file mode 100644
index 0000000..2615649
--- /dev/null
+++ b/lib/rac/example_test.go
@@ -0,0 +1,193 @@
+// Copyright 2019 The Wuffs Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package rac_test
+
+import (
+ "bytes"
+ "compress/zlib"
+ "encoding/hex"
+ "fmt"
+ "hash/adler32"
+ "io"
+ "log"
+
+ "github.com/google/wuffs/lib/rac"
+)
+
+// ExampleILAEnd demonstrates using the low level "rac" package to encode a
+// RAC+Zlib formatted file with IndexLocationAtEnd.
+//
+// The sibling "raczlib" package (TODO) provides a higher level API that is
+// easier to use.
+//
+// See the RAC specification for an explanation of the file format.
+func ExampleILAEnd() {
+ // Manually construct a zlib encoding of "More!\n", one that uses a literal
+ // block (that's easy to see in a hex dump) instead of a more compressible
+ // Huffman block.
+ const src = "More!\n"
+ hasher := adler32.New()
+ hasher.Write([]byte(src))
+ enc := []byte{ // See RFCs 1950 and 1951 for details.
+ 0x78, // Deflate compression method; 32KiB window size.
+ 0x9C, // Default encoding algorithm; FCHECK bits.
+ 0x01, // Literal block (final).
+ 0x06, 0x00, // Literal length.
+ 0xF9, 0xFF, // Inverse of the literal length.
+ }
+ enc = append(enc, src...) // Literal bytes.
+ enc = hasher.Sum(enc) // Adler-32 hash.
+
+ // Check that we've constructed a valid zlib-formatted encoding, by
+ // checking that decoding enc produces src.
+ {
+ b := &bytes.Buffer{}
+ r, err := zlib.NewReader(bytes.NewReader(enc))
+ if err != nil {
+ log.Fatalf("NewReader: %v", err)
+ }
+ if _, err := io.Copy(b, r); err != nil {
+ log.Fatalf("Copy: %v", err)
+ }
+ if got := b.String(); got != src {
+ log.Fatalf("zlib check: got %q, want %q", got, src)
+ }
+ }
+
+ buf := &bytes.Buffer{}
+ w := &rac.Writer{
+ Writer: buf,
+ Codec: rac.CodecZlib,
+ }
+ if err := w.AddChunk(uint64(len(src)), enc, 0, 0); err != nil {
+ log.Fatalf("AddChunk: %v", err)
+ }
+ if err := w.Close(); err != nil {
+ log.Fatalf("Close: %v", err)
+ }
+
+ fmt.Printf("RAC file:\n%s", hex.Dump(buf.Bytes()))
+
+ // Output:
+ // RAC file:
+ // 00000000 72 c3 63 00 78 9c 01 06 00 f9 ff 4d 6f 72 65 21 |r.c.x......More!|
+ // 00000010 0a 07 42 01 bf 72 c3 63 01 65 a9 00 ff 06 00 00 |..B..r.c.e......|
+ // 00000020 00 00 00 00 01 04 00 00 00 00 00 01 ff 35 00 00 |.............5..|
+ // 00000030 00 00 00 01 01 |.....|
+}
+
+// ExampleILAStart demonstrates using the low level "rac" package to encode and
+// then decode a RAC+Zlib formatted file with IndexLocationAtStart.
+//
+// The sibling "raczlib" package (TODO) provides a higher level API that is
+// easier to use.
+//
+// See the RAC specification for an explanation of the file format.
+func ExampleILAStart() {
+ buf := &bytes.Buffer{}
+ w := &rac.Writer{
+ Writer: buf,
+ Codec: rac.CodecZlib,
+ IndexLocation: rac.IndexLocationAtStart,
+ TempFile: &bytes.Buffer{},
+ }
+
+ dict := []byte(" sheep.\n")
+ hasher := adler32.New()
+ hasher.Write(dict)
+ if len(dict) > 0xFFFF {
+ log.Fatal("len(dict) is too large")
+ }
+ encodedDict := []byte{
+ uint8(len(dict) >> 0),
+ uint8(len(dict) >> 8),
+ }
+ encodedDict = append(encodedDict, dict...)
+ encodedDict = hasher.Sum(encodedDict)
+ fmt.Printf("Encoded dictionary resource:\n%s\n", hex.Dump(encodedDict))
+
+ dictResource, err := w.AddResource(encodedDict)
+ if err != nil {
+ log.Fatalf("AddResource: %v", err)
+ }
+
+ chunks := []string{
+ "One sheep.\n",
+ "Two sheep.\n",
+ "Three sheep.\n",
+ }
+
+ for i, chunk := range chunks {
+ b := &bytes.Buffer{}
+ if z, err := zlib.NewWriterLevelDict(b, zlib.BestCompression, dict); err != nil {
+ log.Fatalf("NewWriterLevelDict: %v", err)
+ } else if _, err := z.Write([]byte(chunk)); err != nil {
+ log.Fatalf("Write: %v", err)
+ } else if err := z.Close(); err != nil {
+ log.Fatalf("Close: %v", err)
+ }
+ encodedChunk := b.Bytes()
+
+ if err := w.AddChunk(uint64(len(chunk)), encodedChunk, dictResource, 0); err != nil {
+ log.Fatalf("AddChunk: %v", err)
+ }
+
+ fmt.Printf("Encoded chunk #%d:\n%s\n", i, hex.Dump(encodedChunk))
+ }
+
+ if err := w.Close(); err != nil {
+ log.Fatalf("Close: %v", err)
+ }
+
+ fmt.Printf("RAC file:\n%s", hex.Dump(buf.Bytes()))
+
+ // TODO: decode the encoded bytes (the RAC-formatted bytes) to recover the
+ // original "One sheep.\nTwo sheep\.Three sheep.\n" source.
+
+ // Note that these exact bytes depends on the zlib encoder's algorithm, but
+ // there is more than one valid zlib encoding of any given input. This
+ // "compare to golden output" test is admittedly brittle, as the standard
+ // library's zlib package's output isn't necessarily stable across Go
+ // releases.
+
+ // Output:
+ // Encoded dictionary resource:
+ // 00000000 08 00 20 73 68 65 65 70 2e 0a 0b e0 02 6e |.. sheep.....n|
+ //
+ // Encoded chunk #0:
+ // 00000000 78 f9 0b e0 02 6e f2 cf 4b 85 31 01 01 00 00 ff |x....n..K.1.....|
+ // 00000010 ff 17 21 03 90 |..!..|
+ //
+ // Encoded chunk #1:
+ // 00000000 78 f9 0b e0 02 6e 0a 29 cf 87 31 01 01 00 00 ff |x....n.)..1.....|
+ // 00000010 ff 18 0c 03 a8 |.....|
+ //
+ // Encoded chunk #2:
+ // 00000000 78 f9 0b e0 02 6e 0a c9 28 4a 4d 85 71 00 01 00 |x....n..(JM.q...|
+ // 00000010 00 ff ff 21 6e 04 66 |...!n.f|
+ //
+ // RAC file:
+ // 00000000 72 c3 63 04 71 b5 00 ff 00 00 00 00 00 00 00 ff |r.c.q...........|
+ // 00000010 0b 00 00 00 00 00 00 ff 16 00 00 00 00 00 00 ff |................|
+ // 00000020 23 00 00 00 00 00 00 01 50 00 00 00 00 00 01 ff |#.......P.......|
+ // 00000030 5e 00 00 00 00 00 01 00 73 00 00 00 00 00 01 00 |^.......s.......|
+ // 00000040 88 00 00 00 00 00 01 00 9f 00 00 00 00 00 01 04 |................|
+ // 00000050 08 00 20 73 68 65 65 70 2e 0a 0b e0 02 6e 78 f9 |.. sheep.....nx.|
+ // 00000060 0b e0 02 6e f2 cf 4b 85 31 01 01 00 00 ff ff 17 |...n..K.1.......|
+ // 00000070 21 03 90 78 f9 0b e0 02 6e 0a 29 cf 87 31 01 01 |!..x....n.)..1..|
+ // 00000080 00 00 ff ff 18 0c 03 a8 78 f9 0b e0 02 6e 0a c9 |........x....n..|
+ // 00000090 28 4a 4d 85 71 00 01 00 00 ff ff 21 6e 04 66 |(JM.q......!n.f|
+
+}
diff --git a/lib/rac/rac.go b/lib/rac/rac.go
new file mode 100644
index 0000000..905fb15
--- /dev/null
+++ b/lib/rac/rac.go
@@ -0,0 +1,63 @@
+// Copyright 2019 The Wuffs Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// ----------------
+
+// Package rac provides access to RAC (Random Access Compression) files.
+//
+// RAC is just a container format, and this package ("rac") is a relatively
+// low-level. Users will typically want to process a particular compression
+// format wrapped in RAC, such as (RAC + Zlib). For that, look at e.g. the
+// sibling "raczlib" package (TODO).
+//
+// The RAC specification is at
+// https://github.com/google/wuffs/blob/master/doc/spec/rac-spec.md
+package rac
+
+const (
+ // MaxCSize is the maximum RAC file size (in both CSpace and DSpace).
+ MaxSize = (1 << 48) - 1
+
+ // invalidCOffsetCLength is ((1 << 64) - 1).
+ invalidCOffsetCLength = 0xFFFFFFFFFFFFFFFF
+)
+
+// Codec is the compression codec for the RAC file.
+//
+// See the RAC specification for further discussion.
+type Codec uint8
+
+const (
+ CodecZlib = Codec(0x01)
+ CodecBrotli = Codec(0x02)
+ CodecZstandard = Codec(0x04)
+)
+
+// IndexLocation is whether the index is at the start or end of the RAC file.
+//
+// See the RAC specification for further discussion.
+type IndexLocation uint8
+
+const (
+ IndexLocationAtEnd = IndexLocation(0)
+ IndexLocationAtStart = IndexLocation(1)
+)
+
+var indexLocationAtEndMagic = []byte("\x72\xC3\x63\x00")
+
+// OptResource is an option type, optionally holding a Writer-specific
+// identifier for a shared resource.
+//
+// Zero means that the option is not taken: no shared resource is used.
+type OptResource uint32
diff --git a/lib/rac/writer.go b/lib/rac/writer.go
new file mode 100644
index 0000000..002365f
--- /dev/null
+++ b/lib/rac/writer.go
@@ -0,0 +1,699 @@
+// Copyright 2019 The Wuffs Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package rac
+
+import (
+ "errors"
+ "hash/crc32"
+ "io"
+ "sort"
+)
+
+func isZeroOrAPowerOf2(x uint64) bool {
+ return (x & (x - 1)) == 0
+}
+
+func putU64LE(b []byte, v uint64) {
+ _ = b[7] // Early bounds check to guarantee safety of writes below.
+ b[0] = byte(v)
+ b[1] = byte(v >> 8)
+ b[2] = byte(v >> 16)
+ b[3] = byte(v >> 24)
+ b[4] = byte(v >> 32)
+ b[5] = byte(v >> 40)
+ b[6] = byte(v >> 48)
+ b[7] = byte(v >> 56)
+}
+
+// Writer provides a relatively simple way to write a RAC file - one that is
+// created starting from nothing, as opposed to incrementally modifying an
+// existing RAC file.
+//
+// Other packages may provide a more flexible (and more complicated) way to
+// write or append to RAC files, but that is out of scope of this package.
+//
+// Do not modify its exported fields after calling any of its methods.
+type Writer struct {
+ // Writer is where the RAC-encoded data is written to.
+ //
+ // Nil is an invalid value.
+ Writer io.Writer
+
+ // Codec is the compression codec for the RAC file.
+ //
+ // See the RAC specification for further discussion.
+ //
+ // Zero is an invalid value.
+ Codec Codec
+
+ // initialized is set true after the first AddXxx call.
+ initialized bool
+
+ // IndexLocation is whether the index is at the start or end of the RAC
+ // file.
+ //
+ // See the RAC specification for further discussion.
+ //
+ // The zero value of this field is IndexLocationAtEnd: a one pass encoding.
+ IndexLocation IndexLocation
+
+ // TempFile is a temporary file to use for a two pass encoding. The field
+ // name says "file" but it need not be a real file, in the operating system
+ // sense.
+ //
+ // For IndexLocationAtEnd, this must be nil. For IndexLocationAtStart, this
+ // must be non-nil.
+ //
+ // It does not need to implement io.Seeker, if it supports separate read
+ // and write positions (e.g. it is a bytes.Buffer). If it does implement
+ // io.Seeker (e.g. it is an os.File), its current position will be noted
+ // (via SeekCurrent), then it will be written to (via the rac.Writer.AddXxx
+ // methods), then its position will be reset (via SeekSet), then it will be
+ // read from (via the rac.Writer.Close method).
+ //
+ // The rac.Writer does not call TempFile.Close even if that method exists
+ // (e.g. the TempFile is an os.File). In that case, closing the temporary
+ // file (and deleting it) after the rac.Writer is closed is the
+ // responsibility of the rac.Writer caller, not the rac.Writer itself.
+ TempFile io.ReadWriter
+
+ // CPageSize guides padding the output to minimize the number of pages that
+ // each chunk occupies (in what the RAC spec calls CSpace).
+ //
+ // It must either be zero (which means no padding is inserted) or a power
+ // of 2, and no larger than MaxSize.
+ //
+ // For example, suppose that CSpace is partitioned into 1024-byte pages,
+ // that 1000 bytes have already been written to the output, and the next
+ // chunk is 1500 bytes long.
+ //
+ // - With no padding (i.e. with CPageSize set to 0), this chunk will
+ // occupy the half-open range [1000, 2500) in CSpace, which straddles
+ // three 1024-byte pages: the page [0, 1024), the page [1024, 2048) and
+ // the page [2048, 3072). Call those pages p0, p1 and p2.
+ //
+ // - With padding (i.e. with CPageSize set to 1024), 24 bytes of zeroes
+ // are first inserted so that this chunk occupies the half-open range
+ // [1024, 2524) in CSpace, which straddles only two pages (p1 and p2).
+ //
+ // This concept is similar, but not identical, to alignment. Even with a
+ // non-zero CPageSize, chunk start offsets are not necessarily aligned to
+ // page boundaries. For example, suppose that the chunk size was only 1040
+ // bytes, not 1500 bytes. No padding will be inserted, as both [1000, 2040)
+ // and [1024, 2064) straddle two pages: either pages p0 and p1, or pages p1
+ // and p2.
+ //
+ // Nonetheless, if all chunks (or all but the final chunk) have a size
+ // equal to (or just under) a multiple of the page size, then in practice,
+ // each chunk's starting offset will be aligned to a page boundary.
+ CPageSize uint64
+
+ // err is the first error encountered. It is sticky: once a non-nil error
+ // occurs, all public methods will return that error.
+ err error
+
+ // tempFileSeekStart is the TempFile's starting position, if the TempFile
+ // is an io.Seeker.
+ tempFileSeekStart int64
+
+ // dataSize is the total size (so far) of the data portion (as opposed to
+ // the index portion) of the compressed file. For a two pass encoding, this
+ // should equal the size of the TempFile.
+ dataSize uint64
+
+ // dFileSize is the total size (so far) of the decompressed file. It is the
+ // sum of all the dRangeSize arguments passed to AddChunk.
+ dFileSize uint64
+
+ // resourcesCOffCLens is the COffset and CLength values for each shared
+ // resource. Those values are for the compressed file (what the RAC spec
+ // calls CSpace).
+ //
+ // The first element (if it exists) is an unused placeholder, as a zero
+ // OptResource means unused.
+ resourcesCOffCLens []uint64
+
+ // leafNodes are the non-resource leaf nodes of the hierarchical index.
+ leafNodes []node
+
+ // log2CPageSize is the base-2 logarithm of CPageSize, or zero if CPageSize
+ // is zero.
+ log2CPageSize uint32
+
+ // padding is a slice of zeroes to pad output to CPageSize boundaries.
+ padding []byte
+}
+
+func (w *Writer) checkParameters() error {
+ if w.Writer == nil {
+ w.err = errors.New("rac: invalid Writer")
+ return w.err
+ }
+ if w.Codec == 0 {
+ w.err = errors.New("rac: invalid Codec")
+ return w.err
+ }
+ if !isZeroOrAPowerOf2(w.CPageSize) || (w.CPageSize > MaxSize) {
+ w.err = errors.New("rac: invalid CPageSize")
+ return w.err
+ } else if w.CPageSize > 0 {
+ for w.log2CPageSize = 1; w.CPageSize != (1 << w.log2CPageSize); w.log2CPageSize++ {
+ }
+ }
+ return nil
+}
+
+func (w *Writer) initialize() error {
+ if w.err != nil {
+ return w.err
+ }
+ if w.initialized {
+ return nil
+ }
+ w.initialized = true
+
+ if err := w.checkParameters(); err != nil {
+ return err
+ }
+
+ if s, ok := w.TempFile.(io.Seeker); ok {
+ if n, err := s.Seek(0, io.SeekCurrent); err != nil {
+ w.err = err
+ return err
+ } else {
+ w.tempFileSeekStart = n
+ }
+ }
+
+ switch w.IndexLocation {
+ case IndexLocationAtEnd:
+ if w.TempFile != nil {
+ w.err = errors.New("rac: IndexLocationAtEnd requires a nil TempFile")
+ return w.err
+ }
+ return w.write(indexLocationAtEndMagic)
+
+ case IndexLocationAtStart:
+ if w.TempFile == nil {
+ w.err = errors.New("rac: IndexLocationAtStart requires a non-nil TempFile")
+ return w.err
+ }
+ }
+ return nil
+}
+
+func (w *Writer) write(data []byte) error {
+ ioWriter := w.Writer
+ if w.TempFile != nil {
+ ioWriter = w.TempFile
+ }
+
+ if uint64(len(data)) > MaxSize {
+ w.err = errors.New("rac: too much input")
+ return w.err
+ }
+ if w.CPageSize > 0 {
+ if err := w.writePadding(ioWriter, uint64(len(data))); err != nil {
+ return err
+ }
+ }
+ if _, err := ioWriter.Write(data); err != nil {
+ w.err = err
+ return err
+ }
+ w.dataSize += uint64(len(data))
+ if w.dataSize > MaxSize {
+ w.err = errors.New("rac: too much input")
+ return w.err
+ }
+ return nil
+}
+
+func (w *Writer) writePadding(ioWriter io.Writer, lenData uint64) error {
+ if lenData == 0 {
+ return nil
+ }
+
+ offset0 := w.dataSize & (w.CPageSize - 1)
+ offset1WithPadding := (0 * offset0) + lenData
+ offset1SansPadding := (1 * offset0) + lenData
+ numPagesWithPadding := (offset1WithPadding + (w.CPageSize - 1)) >> w.log2CPageSize
+ numPagesSansPadding := (offset1SansPadding + (w.CPageSize - 1)) >> w.log2CPageSize
+
+ if numPagesSansPadding == numPagesWithPadding {
+ return nil
+ }
+ return w.padToPageSize(ioWriter, w.dataSize)
+}
+
+func (w *Writer) padToPageSize(ioWriter io.Writer, offset uint64) error {
+ offset &= w.CPageSize - 1
+ if (offset == 0) || (w.CPageSize == 0) {
+ return nil
+ }
+
+ if w.padding == nil {
+ n := w.CPageSize
+ if n > 4096 {
+ n = 4096
+ }
+ w.padding = make([]byte, n)
+ }
+
+ for remaining := w.CPageSize - offset; remaining > 0; {
+ padding := w.padding
+ if remaining < uint64(len(padding)) {
+ padding = padding[:remaining]
+ }
+
+ n, err := ioWriter.Write(padding)
+ if err != nil {
+ w.err = err
+ return err
+ }
+ remaining -= uint64(n)
+ w.dataSize += uint64(n)
+ if w.dataSize > MaxSize {
+ w.err = errors.New("rac: too much input")
+ return w.err
+ }
+ }
+ return nil
+}
+
+func (w *Writer) roundUpToCPageBoundary(x uint64) uint64 {
+ if w.CPageSize == 0 {
+ return x
+ }
+ return (x + w.CPageSize - 1) &^ (w.CPageSize - 1)
+}
+
+// AddResource adds a shared resource to the RAC file. It returns a non-zero
+// OptResource that identifies the resource's bytes. Future calls to AddChunk
+// can pass these identifiers to indicate that decompressing a chunk depends on
+// up to two shared resources.
+//
+// The caller may modify resource's contents after this method returns.
+func (w *Writer) AddResource(resource []byte) (OptResource, error) {
+ if len(w.resourcesCOffCLens) >= (1 << 30) {
+ w.err = errors.New("rac: too many resources")
+ return 0, w.err
+ }
+
+ if err := w.initialize(); err != nil {
+ return 0, err
+ }
+ if err := w.write(resource); err != nil {
+ return 0, err
+ }
+
+ if len(w.resourcesCOffCLens) == 0 {
+ w.resourcesCOffCLens = make([]uint64, 1, 8)
+ }
+ id := OptResource(len(w.resourcesCOffCLens))
+ cOffset := w.dataSize - uint64(len(resource))
+ cLength := calcCLength(len(resource))
+ w.resourcesCOffCLens = append(w.resourcesCOffCLens, cOffset|(cLength<<48))
+ return id, nil
+}
+
+// AddChunk adds a chunk of compressed data - the (primary, secondary,
+// tertiary) tuple - to the RAC file. Decompressing that chunk should produce
+// dRangeSize bytes, although the rac.Writer does not attempt to verify that.
+//
+// The OptResource arguments may be zero, meaning that no resource is used. In
+// that case, the corresponding STag or TTag (see the RAC specification for
+// further discussion) will be 0xFF.
+//
+// The caller may modify primary's contents after this method returns.
+func (w *Writer) AddChunk(dRangeSize uint64, primary []byte, secondary OptResource, tertiary OptResource) error {
+ if dRangeSize == 0 {
+ return nil
+ }
+ if (dRangeSize > MaxSize) || ((w.dFileSize + dRangeSize) > MaxSize) {
+ w.err = errors.New("rac: too much input")
+ return w.err
+ }
+ if len(w.leafNodes) >= (1 << 30) {
+ w.err = errors.New("rac: too many chunks")
+ return w.err
+ }
+
+ if err := w.initialize(); err != nil {
+ return err
+ }
+ if err := w.write(primary); err != nil {
+ return err
+ }
+
+ cOffset := w.dataSize - uint64(len(primary))
+ cLength := calcCLength(len(primary))
+ w.dFileSize += dRangeSize
+ w.leafNodes = append(w.leafNodes, node{
+ dRangeSize: dRangeSize,
+ cOffsetCLength: cOffset | (cLength << 48),
+ secondary: secondary,
+ tertiary: tertiary,
+ })
+ return nil
+}
+
+func writeEmpty(w io.Writer, codec Codec) error {
+ buf := [32]byte{
+ 0x72, 0xC3, 0x63, 0x01, 0x00, 0x00, 0x00, 0xFF,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, uint8(codec),
+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF,
+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
+ }
+
+ checksum := crc32.ChecksumIEEE(buf[6:])
+ checksum ^= checksum >> 16
+ buf[4] = uint8(checksum >> 0)
+ buf[5] = uint8(checksum >> 8)
+
+ _, err := w.Write(buf[:])
+ return err
+}
+
+// Close writes the RAC index to w.Writer and marks that w accepts no further
+// method calls.
+//
+// For a one pass encoding, no further action is taken. For a two pass encoding
+// (i.e. IndexLocationAtStart), it then copies w.TempFile to w.Writer. Either
+// way, if this method returns nil error, the entirety of what was written to
+// w.Writer constitutes a valid RAC file.
+//
+// Closing the underlying w.Writer, w.TempFile or both is the responsibility of
+// the rac.Writer caller, not the rac.Writer itself.
+//
+// It is not necessary to call Close, e.g. if an earlier AddXxx call returned a
+// non-nil error. Unlike an os.File, failing to call rac.Writer.Close will not
+// leak resources such as file descriptors.
+func (w *Writer) Close() error {
+ if w.err != nil {
+ return w.err
+ }
+ if !w.initialized {
+ if err := w.checkParameters(); err != nil {
+ return err
+ }
+ }
+
+ if len(w.leafNodes) == 0 {
+ return writeEmpty(w.Writer, w.Codec)
+ }
+ rootNode := gather(w.leafNodes)
+ indexSize := rootNode.calcEncodedSize(0)
+
+ nw := &nodeWriter{
+ w: w.Writer,
+ resourcesCOffCLens: w.resourcesCOffCLens,
+ codec: w.Codec,
+ }
+
+ if w.IndexLocation == IndexLocationAtEnd {
+ nw.indexCOffset = w.roundUpToCPageBoundary(w.dataSize)
+ nw.cFileSize = nw.indexCOffset + indexSize
+ } else {
+ nw.dataCOffset = w.roundUpToCPageBoundary(indexSize)
+ nw.cFileSize = nw.dataCOffset + w.dataSize
+ }
+ if nw.cFileSize > MaxSize {
+ w.err = errors.New("rac: too much input")
+ return w.err
+ }
+
+ if w.IndexLocation == IndexLocationAtEnd {
+ // Write the align-to-CPageSize padding.
+ if w.CPageSize > 0 {
+ if err := w.padToPageSize(w.Writer, w.dataSize); err != nil {
+ return err
+ }
+ }
+
+ // Write the index. The compressed data has already been written.
+ if err := nw.writeIndex(&rootNode); err != nil {
+ w.err = err
+ return err
+ }
+
+ } else {
+ expectedTempFileSize := w.dataSize
+
+ // Write the index.
+ if err := nw.writeIndex(&rootNode); err != nil {
+ w.err = err
+ return err
+ }
+
+ // Write the align-to-CPageSize padding.
+ if w.CPageSize > 0 {
+ if err := w.padToPageSize(w.Writer, indexSize); err != nil {
+ return err
+ }
+ }
+
+ // Write the compressed data.
+ if s, ok := w.TempFile.(io.Seeker); ok {
+ if _, err := s.Seek(w.tempFileSeekStart, io.SeekStart); err != nil {
+ w.err = err
+ return err
+ }
+ }
+ if n, err := io.Copy(w.Writer, w.TempFile); err != nil {
+ w.err = err
+ return err
+ } else if uint64(n) != expectedTempFileSize {
+ w.err = errors.New("rac: inconsistent compressed data size")
+ return w.err
+ }
+ }
+
+ w.err = errors.New("rac: Writer is closed")
+ return nil
+}
+
+type node struct {
+ dRangeSize uint64
+
+ children []node // Excludes resource-node chidren.
+ resources []int
+
+ cOffsetCLength uint64
+ secondary OptResource
+ tertiary OptResource
+}
+
+// calcEncodedSize accumulates the encoded size of n and its children,
+// traversing the nodes in depth-first order.
+//
+// As a side effect, it also sets n.cOffsetCLength for branch nodes.
+func (n *node) calcEncodedSize(accumulator uint64) (newAccumulator uint64) {
+ arity := len(n.children) + len(n.resources)
+ if arity == 0 {
+ return accumulator
+ }
+ size := (arity * 16) + 16
+ cLength := calcCLength(size)
+ n.cOffsetCLength = accumulator | (cLength << 48)
+ accumulator += uint64(size)
+ for i := range n.children {
+ accumulator = n.children[i].calcEncodedSize(accumulator)
+ }
+ return accumulator
+}
+
+type nodeWriter struct {
+ w io.Writer
+
+ cFileSize uint64
+ dataCOffset uint64
+ indexCOffset uint64
+ resourcesCOffCLens []uint64
+
+ codec Codec
+
+ // A node's maximum arity is 255, so a node's maximum size in bytes is
+ // ((255 * 16) + 16), which is 4096.
+ buffer [4096]byte
+}
+
+func (w *nodeWriter) writeIndex(n *node) error {
+ const tagFF = 0xFF << 56
+
+ buf, dPtr := w.buffer[:], uint64(0)
+ arity := uint64(len(n.children) + len(n.resources))
+ if arity > 0xFF {
+ return errors.New("rac: internal error: arity is too large")
+ }
+
+ // DPtr's. We write resources before regular children (non-resources), so
+ // that any TTag that refers to a resource always avoids the [0xC0, 0xFD]
+ // reserved zone. The ratio of resources to regulars is at most 2:1, as
+ // every chunk uses exactly 1 regular slot and up to 2 resource slots, and
+ // that reserved zone is less than 33% of the [0x00, 0xFF] space.
+ for i := range n.resources {
+ putU64LE(buf[8*i:], dPtr|tagFF)
+ }
+ buf = buf[8*len(n.resources):]
+ for i, o := range n.children {
+ putU64LE(buf[8*i:], dPtr|resourceToTag(n.resources, o.tertiary))
+ dPtr += o.dRangeSize
+ }
+ buf = buf[8*len(n.children):]
+
+ // DPtrMax.
+ putU64LE(buf, dPtr|(uint64(w.codec)<<56))
+ buf = buf[8:]
+
+ // CPtr's. While the RAC format allows otherwise, this Writer always keeps
+ // the CBias at zero, so that a CPtr equals a COffset.
+ for i, res := range n.resources {
+ cOffsetCLength := w.resourcesCOffCLens[res] + w.dataCOffset
+ putU64LE(buf[8*i:], cOffsetCLength|tagFF)
+ }
+ buf = buf[8*len(n.resources):]
+ for i, o := range n.children {
+ cOffsetCLength := o.cOffsetCLength
+ if len(o.children) == 0 {
+ cOffsetCLength += w.dataCOffset
+ } else {
+ cOffsetCLength += w.indexCOffset
+ }
+ putU64LE(buf[8*i:], cOffsetCLength|resourceToTag(n.resources, o.secondary))
+ }
+ buf = buf[8*len(n.children):]
+
+ // CPtrMax.
+ const version = 0x01
+ putU64LE(buf, w.cFileSize|(version<<48)|(arity<<56))
+
+ // Magic and Arity.
+ w.buffer[0] = 0x72
+ w.buffer[1] = 0xC3
+ w.buffer[2] = 0x63
+ w.buffer[3] = uint8(arity)
+
+ // Checksum.
+ size := (arity * 16) + 16
+ checksum := crc32.ChecksumIEEE(w.buffer[6:size])
+ checksum ^= checksum >> 16
+ w.buffer[4] = uint8(checksum >> 0)
+ w.buffer[5] = uint8(checksum >> 8)
+
+ _, err := w.w.Write(w.buffer[:size])
+ return err
+}
+
+func calcCLength(primarySize int) uint64 {
+ if primarySize <= 0 {
+ return 1
+ }
+
+ // Divide by 1024, rounding up.
+ primarySize = ((primarySize - 1) >> 10) + 1
+
+ if primarySize > 255 {
+ return 0
+ }
+ return uint64(primarySize)
+}
+
+func resourceToTag(resources []int, r OptResource) uint64 {
+ if r != 0 {
+ for i, res := range resources {
+ if res == int(r) {
+ return uint64(i) << 56
+ }
+ }
+ }
+ return 0xFF << 56
+}
+
+// gather brings the given nodes into a tree, such that every branch node's
+// arity (the count of its resource and non-resource child nodes) is at most
+// 0xFF. It returns the root of that tree.
+//
+// TODO: it currently builds a tree where all leaf nodes have equal depth. For
+// small RAC files (with only one branch node: the mandatory root node), this
+// doesn't matter. For larger RAC files, it might be better to build an uneven
+// tree to minimize average leaf node depth, with some branch nodes having both
+// branch node children and leaf node children. It might even be worth ensuring
+// that the root node always directly contains the first and last leaf nodes as
+// children, as those leaves presumably contain the most commonly accessed
+// parts of the decompressed file.
+func gather(nodes []node) node {
+ if len(nodes) == 0 {
+ panic("gather: no nodes")
+ }
+
+ resources := map[OptResource]bool{}
+ arity := 0
+
+ for {
+ i, j, newNodes := 0, 0, []node(nil)
+ for ; j < len(nodes); j++ {
+ o := &nodes[j]
+
+ arity++
+ if (o.secondary != 0) && !resources[o.secondary] {
+ resources[o.secondary] = true
+ arity++
+ }
+ if (o.tertiary != 0) && !resources[o.tertiary] {
+ resources[o.tertiary] = true
+ arity++
+ }
+ if arity <= 0xFF {
+ continue
+ }
+
+ newNodes = append(newNodes, makeBranch(nodes[i:j], resources))
+ i = j
+ arity = 0
+ if len(resources) != 0 {
+ resources = map[OptResource]bool{}
+ }
+ }
+
+ if i == 0 {
+ return makeBranch(nodes, resources)
+ }
+ nodes, newNodes = newNodes, nil
+ }
+}
+
+func makeBranch(children []node, resMap map[OptResource]bool) node {
+ dRangeSize := uint64(0)
+ for _, c := range children {
+ dRangeSize += c.dRangeSize
+ }
+
+ resList := []int(nil)
+ if len(resMap) != 0 {
+ resList = make([]int, 0, len(resMap))
+ for res := range resMap {
+ resList = append(resList, int(res))
+ }
+ sort.Ints(resList)
+ }
+
+ return node{
+ dRangeSize: dRangeSize,
+ children: children,
+ resources: resList,
+ cOffsetCLength: invalidCOffsetCLength,
+ }
+}
diff --git a/lib/rac/writer_test.go b/lib/rac/writer_test.go
new file mode 100644
index 0000000..08982af
--- /dev/null
+++ b/lib/rac/writer_test.go
@@ -0,0 +1,213 @@
+// Copyright 2019 The Wuffs Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package rac
+
+import (
+ "bytes"
+ "encoding/hex"
+ "fmt"
+ "io"
+ "io/ioutil"
+ "os"
+ "strings"
+ "testing"
+)
+
+// Note that these exact bytes depends on the zlib encoder's algorithm, but
+// there is more than one valid zlib encoding of any given input. This "compare
+// to golden output" test is admittedly brittle, as the standard library's zlib
+// package's output isn't necessarily stable across Go releases.
+
+const writerWantEmpty = "" +
+ "00000000 72 c3 63 01 30 14 00 ff 00 00 00 00 00 00 00 ee |r.c.0...........|\n" +
+ "00000010 20 00 00 00 00 00 01 ff 20 00 00 00 00 00 01 01 | ....... .......|\n"
+
+const writerWantILAEnd = "" +
+ "00000000 72 c3 63 00 52 72 72 53 73 41 61 61 42 62 62 62 |r.c.RrrSsAaaBbbb|\n" +
+ "00000010 43 63 63 63 63 63 63 63 63 63 31 32 72 c3 63 05 |Cccccccccc12r.c.|\n" +
+ "00000020 1d 45 00 ff 00 00 00 00 00 00 00 ff 00 00 00 00 |.E..............|\n" +
+ "00000030 00 00 00 ff 11 00 00 00 00 00 00 ff 33 00 00 00 |............3...|\n" +
+ "00000040 00 00 00 01 77 00 00 00 00 00 00 ee 04 00 00 00 |....w...........|\n" +
+ "00000050 00 00 01 ff 07 00 00 00 00 00 01 ff 09 00 00 00 |................|\n" +
+ "00000060 00 00 01 ff 0c 00 00 00 00 00 01 00 10 00 00 00 |................|\n" +
+ "00000070 00 00 01 00 7c 00 00 00 00 00 01 05 |....|.......|\n"
+
+const writerWantILAEndCPageSize8 = "" +
+ "00000000 72 c3 63 00 52 72 72 00 53 73 41 61 61 00 00 00 |r.c.Rrr.SsAaa...|\n" +
+ "00000010 42 62 62 62 43 63 63 63 63 63 63 63 63 63 31 32 |BbbbCccccccccc12|\n" +
+ "00000020 72 c3 63 05 90 5e 00 ff 00 00 00 00 00 00 00 ff |r.c..^..........|\n" +
+ "00000030 00 00 00 00 00 00 00 ff 11 00 00 00 00 00 00 ff |................|\n" +
+ "00000040 33 00 00 00 00 00 00 01 77 00 00 00 00 00 00 ee |3.......w.......|\n" +
+ "00000050 04 00 00 00 00 00 01 ff 08 00 00 00 00 00 01 ff |................|\n" +
+ "00000060 0a 00 00 00 00 00 01 ff 10 00 00 00 00 00 01 00 |................|\n" +
+ "00000070 14 00 00 00 00 00 01 00 80 00 00 00 00 00 01 05 |................|\n"
+
+const writerWantILAStart = "" +
+ "00000000 72 c3 63 05 bc dc 00 ff 00 00 00 00 00 00 00 ff |r.c.............|\n" +
+ "00000010 00 00 00 00 00 00 00 ff 11 00 00 00 00 00 00 ff |................|\n" +
+ "00000020 33 00 00 00 00 00 00 01 77 00 00 00 00 00 00 ee |3.......w.......|\n" +
+ "00000030 60 00 00 00 00 00 01 ff 63 00 00 00 00 00 01 ff |`.......c.......|\n" +
+ "00000040 65 00 00 00 00 00 01 ff 68 00 00 00 00 00 01 00 |e.......h.......|\n" +
+ "00000050 6c 00 00 00 00 00 01 00 78 00 00 00 00 00 01 05 |l.......x.......|\n" +
+ "00000060 52 72 72 53 73 41 61 61 42 62 62 62 43 63 63 63 |RrrSsAaaBbbbCccc|\n" +
+ "00000070 63 63 63 63 63 63 31 32 |cccccc12|\n"
+
+const writerWantILAStartCPageSize4 = "" +
+ "00000000 72 c3 63 05 fc 4c 00 ff 00 00 00 00 00 00 00 ff |r.c..L..........|\n" +
+ "00000010 00 00 00 00 00 00 00 ff 11 00 00 00 00 00 00 ff |................|\n" +
+ "00000020 33 00 00 00 00 00 00 01 77 00 00 00 00 00 00 ee |3.......w.......|\n" +
+ "00000030 60 00 00 00 00 00 01 ff 64 00 00 00 00 00 01 ff |`.......d.......|\n" +
+ "00000040 68 00 00 00 00 00 01 ff 6c 00 00 00 00 00 01 00 |h.......l.......|\n" +
+ "00000050 70 00 00 00 00 00 01 00 7c 00 00 00 00 00 01 05 |p.......|.......|\n" +
+ "00000060 52 72 72 00 53 73 00 00 41 61 61 00 42 62 62 62 |Rrr.Ss..Aaa.Bbbb|\n" +
+ "00000070 43 63 63 63 63 63 63 63 63 63 31 32 |Cccccccccc12|\n"
+
+const writerWantILAStartCPageSize128 = "" +
+ "00000000 72 c3 63 05 d8 df 00 ff 00 00 00 00 00 00 00 ff |r.c.............|\n" +
+ "00000010 00 00 00 00 00 00 00 ff 11 00 00 00 00 00 00 ff |................|\n" +
+ "00000020 33 00 00 00 00 00 00 01 77 00 00 00 00 00 00 ee |3.......w.......|\n" +
+ "00000030 80 00 00 00 00 00 01 ff 83 00 00 00 00 00 01 ff |................|\n" +
+ "00000040 85 00 00 00 00 00 01 ff 88 00 00 00 00 00 01 00 |................|\n" +
+ "00000050 8c 00 00 00 00 00 01 00 98 00 00 00 00 00 01 05 |................|\n" +
+ "00000060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|\n" +
+ "00000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|\n" +
+ "00000080 52 72 72 53 73 41 61 61 42 62 62 62 43 63 63 63 |RrrSsAaaBbbbCccc|\n" +
+ "00000090 63 63 63 63 63 63 31 32 |cccccc12|\n"
+
+func TestWriterILAEndEmpty(t *testing.T) {
+ if err := testWriter(IndexLocationAtEnd, nil, 0, true); err != nil {
+ t.Fatal(err)
+ }
+}
+
+func TestWriterILAStartEmpty(t *testing.T) {
+ tempFile := &bytes.Buffer{}
+ if err := testWriter(IndexLocationAtStart, tempFile, 0, true); err != nil {
+ t.Fatal(err)
+ }
+}
+
+func TestWriterILAEndNoTempFile(t *testing.T) {
+ if err := testWriter(IndexLocationAtEnd, nil, 0, false); err != nil {
+ t.Fatal(err)
+ }
+}
+
+func TestWriterILAEndMemTempFile(t *testing.T) {
+ tempFile := &bytes.Buffer{}
+ if err := testWriter(IndexLocationAtEnd, tempFile, 0, false); err == nil {
+ t.Fatal("err: got nil, want non-nil")
+ } else if !strings.HasPrefix(err.Error(), "rac: IndexLocationAtEnd requires") {
+ t.Fatal(err)
+ }
+}
+
+func TestWriterILAStartNoTempFile(t *testing.T) {
+ if err := testWriter(IndexLocationAtStart, nil, 0, false); err == nil {
+ t.Fatal("err: got nil, want non-nil")
+ } else if !strings.HasPrefix(err.Error(), "rac: IndexLocationAtStart requires") {
+ t.Fatal(err)
+ }
+}
+
+func TestWriterILAStartMemTempFile(t *testing.T) {
+ tempFile := &bytes.Buffer{}
+ if err := testWriter(IndexLocationAtStart, tempFile, 0, false); err != nil {
+ t.Fatal(err)
+ }
+}
+
+func TestWriterILAStartRealTempFile(t *testing.T) {
+ f, err := ioutil.TempFile("", "rac_test")
+ if err != nil {
+ t.Fatalf("TempFile: %v", err)
+ }
+ defer os.Remove(f.Name())
+ defer f.Close()
+
+ if err := testWriter(IndexLocationAtStart, f, 0, false); err != nil {
+ t.Fatal(err)
+ }
+}
+
+func TestWriterILAEndCPageSize8(t *testing.T) {
+ if err := testWriter(IndexLocationAtEnd, nil, 8, false); err != nil {
+ t.Fatal(err)
+ }
+}
+
+func TestWriterILAStartCPageSize4(t *testing.T) {
+ tempFile := &bytes.Buffer{}
+ if err := testWriter(IndexLocationAtStart, tempFile, 4, false); err != nil {
+ t.Fatal(err)
+ }
+}
+
+func TestWriterILAStartCPageSize128(t *testing.T) {
+ tempFile := &bytes.Buffer{}
+ if err := testWriter(IndexLocationAtStart, tempFile, 128, false); err != nil {
+ t.Fatal(err)
+ }
+}
+
+func testWriter(iloc IndexLocation, tempFile io.ReadWriter, cPageSize uint64, empty bool) error {
+ buf := &bytes.Buffer{}
+ const fakeCodec = Codec(0xEE)
+ w := &Writer{
+ Writer: buf,
+ Codec: fakeCodec,
+ IndexLocation: iloc,
+ TempFile: tempFile,
+ CPageSize: cPageSize,
+ }
+
+ if !empty {
+ // We ignore errors (assigning them to _) from the AddXxx calls. Any
+ // non-nil errors are sticky, and should be returned by Close.
+ res0, _ := w.AddResource([]byte("Rrr"))
+ res1, _ := w.AddResource([]byte("Ss"))
+ _ = w.AddChunk(0x11, []byte("Aaa"), 0, 0)
+ _ = w.AddChunk(0x22, []byte("Bbbb"), res0, 0)
+ _ = w.AddChunk(0x44, []byte("Cccccccccc12"), res0, res1)
+ }
+
+ if err := w.Close(); err != nil {
+ return err
+ }
+ got := hex.Dump(buf.Bytes())
+
+ want := ""
+ switch {
+ case empty:
+ want = writerWantEmpty
+ case (iloc == IndexLocationAtEnd) && (cPageSize == 0):
+ want = writerWantILAEnd
+ case (iloc == IndexLocationAtEnd) && (cPageSize == 8):
+ want = writerWantILAEndCPageSize8
+ case (iloc == IndexLocationAtStart) && (cPageSize == 0):
+ want = writerWantILAStart
+ case (iloc == IndexLocationAtStart) && (cPageSize == 4):
+ want = writerWantILAStartCPageSize4
+ case (iloc == IndexLocationAtStart) && (cPageSize == 128):
+ want = writerWantILAStartCPageSize128
+ default:
+ return fmt.Errorf("unsupported iloc/cPageSize combination")
+ }
+
+ if got != want {
+ return fmt.Errorf("\ngot:\n%s\nwant:\n%s", got, want)
+ }
+ return nil
+}
diff --git a/lib/zlibcut/zlibcut.go b/lib/zlibcut/zlibcut.go
new file mode 100644
index 0000000..4f7da1c
--- /dev/null
+++ b/lib/zlibcut/zlibcut.go
@@ -0,0 +1,112 @@
+// Copyright 2019 The Wuffs Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// ----------------
+
+// Package zlibcut produces zlib-formatted data subject to a maximum compressed
+// size.
+//
+// The typical compression problem is to encode all of the given source data in
+// some number of bytes. This package's problem is finding a reasonably long
+// prefix of the source data that encodes in up to a given number of bytes.
+package zlibcut
+
+import (
+ "bytes"
+ "compress/flate"
+ "errors"
+ "hash/adler32"
+ "io"
+
+ "github.com/google/wuffs/lib/flatecut"
+)
+
+var (
+ errMaxEncodedLenTooSmall = errors.New("zlibcut: maxEncodedLen is too small")
+ errUnsupportedZlibCompressionMethod = errors.New("zlibcut: unsupported zlib compression method")
+
+ errInternalInconsistentDecodedLen = errors.New("zlibcut: internal: inconsistent decodedLen")
+
+ errInvalidBadHeader = errors.New("zlibcut: invalid input: bad header")
+ errInvalidNotEnoughData = errors.New("zlibcut: invalid input: not enough data")
+)
+
+const (
+ // SmallestValidMaxEncodedLen is the length in bytes of the smallest valid
+ // zlib-encoded data.
+ SmallestValidMaxEncodedLen = 8
+)
+
+// Cut modifies encoded's contents such that encoded[:encodedLen] is valid
+// zlib-compressed data, assuming that encoded starts off containing valid
+// zlib-compressed data.
+//
+// Decompressing that modified, shorter byte slice produces a prefix (of length
+// decodedLen) of the decompression of the original, longer byte slice.
+//
+// It does not necessarily return the largest possible decodedLen.
+func Cut(encoded []byte, maxEncodedLen int) (encodedLen int, decodedLen int, retErr error) {
+ if len(encoded) < 2 {
+ return 0, 0, errInvalidNotEnoughData
+ }
+ header := uint32(encoded[0])<<8 | uint32(encoded[1])
+ if header%31 != 0 {
+ return 0, 0, errInvalidBadHeader
+ }
+ if (encoded[0] & 0x0F) != 0x08 {
+ return 0, 0, errUnsupportedZlibCompressionMethod
+ }
+
+ payloadStart := 2
+ if haveDict := (encoded[1] & 0x20) != 0; haveDict {
+ if len(encoded) < 6 {
+ return 0, 0, errInvalidNotEnoughData
+ }
+ payloadStart = 6
+ }
+
+ // Check that there's space for the trailing Adler-32 checksum.
+ if len(encoded) < (payloadStart + 4) {
+ return 0, 0, errInvalidNotEnoughData
+ }
+
+ if maxEncodedLen < (payloadStart + 4) {
+ return 0, 0, errMaxEncodedLenTooSmall
+ }
+
+ encodedLen, decodedLen, err := flatecut.Cut(
+ encoded[payloadStart:len(encoded)-4],
+ maxEncodedLen-payloadStart-4,
+ )
+ if err != nil {
+ return 0, 0, err
+ }
+
+ w := adler32.New()
+ r := bytes.NewReader(encoded[payloadStart : payloadStart+encodedLen])
+ if n, err := io.Copy(w, flate.NewReader(r)); err != nil {
+ return 0, 0, err
+ } else if n != int64(decodedLen) {
+ return 0, 0, errInternalInconsistentDecodedLen
+ }
+
+ hash := w.Sum32()
+ hashBytes := encoded[payloadStart+encodedLen : payloadStart+encodedLen+4]
+ hashBytes[0] = uint8(hash >> 24)
+ hashBytes[1] = uint8(hash >> 16)
+ hashBytes[2] = uint8(hash >> 8)
+ hashBytes[3] = uint8(hash >> 0)
+
+ return payloadStart + encodedLen + 4, decodedLen, nil
+}
diff --git a/lib/zlibcut/zlibcut_test.go b/lib/zlibcut/zlibcut_test.go
new file mode 100644
index 0000000..2dc8c34
--- /dev/null
+++ b/lib/zlibcut/zlibcut_test.go
@@ -0,0 +1,35 @@
+// Copyright 2019 The Wuffs Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package zlibcut
+
+import (
+ "compress/zlib"
+ "testing"
+
+ "github.com/google/wuffs/internal/testcut"
+)
+
+func TestCut(t *testing.T) {
+ testcut.Test(t, SmallestValidMaxEncodedLen, Cut, zlib.NewReader, []string{
+ "midsummer.txt.zlib",
+ "pi.txt.zlib",
+ "romeo.txt.zlib",
+ })
+}
+
+func BenchmarkCut(b *testing.B) {
+ testcut.Benchmark(b, SmallestValidMaxEncodedLen, Cut, zlib.NewReader,
+ "pi.txt.zlib", 0, 0, 100003)
+}
diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c
index f52ed58..dc00a84 100644
--- a/release/c/wuffs-unsupported-snapshot.c
+++ b/release/c/wuffs-unsupported-snapshot.c
@@ -26,6 +26,12 @@
#include <stdint.h>
#include <string.h>
+// GCC does not warn for unused *static inline* functions, but clang does.
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunused-function"
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -73,13 +79,57 @@
#define WUFFS_BASE__MAYBE_STATIC
#endif
+#if defined(__clang__)
+#define WUFFS_BASE__POTENTIALLY_UNUSED_FIELD __attribute__((unused))
+#else
+#define WUFFS_BASE__POTENTIALLY_UNUSED_FIELD
+#endif
+
// Clang also defines "__GNUC__".
#if defined(__GNUC__)
+#define WUFFS_BASE__POTENTIALLY_UNUSED __attribute__((unused))
#define WUFFS_BASE__WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#else
+#define WUFFS_BASE__POTENTIALLY_UNUSED
#define WUFFS_BASE__WARN_UNUSED_RESULT
#endif
+// Flags for wuffs_foo__bar__initialize functions.
+
+#define WUFFS_INITIALIZE__DEFAULT_OPTIONS ((uint32_t)0x00000000)
+
+// WUFFS_INITIALIZE__ALREADY_ZEROED means that the "self" receiver struct value
+// has already been set to all zeroes.
+#define WUFFS_INITIALIZE__ALREADY_ZEROED ((uint32_t)0x00000001)
+
+// WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED means that, absent
+// WUFFS_INITIALIZE__ALREADY_ZEROED, only some of the "self" receiver struct
+// value will be set to all zeroes. Internal buffers, which tend to be a large
+// proportion of the struct's size, will be left uninitialized. Internal means
+// that the buffer is contained by the receiver struct, as opposed to being
+// passed as a separately allocated "work buffer".
+//
+// With or without this bit set, the Wuffs compiler still enforces that no
+// reads or writes will overflow internal buffers' bounds. Even with this bit
+// set, the Wuffs standard library also considers reading from an uninitialized
+// buffer to be a bug, and strives to never do so, but unlike buffer overflows,
+// it is not a bug class that the Wuffs compiler eliminates.
+//
+// For those paranoid about security, leave this bit unset, so that
+// wuffs_foo__bar__initialize will initialize the entire struct value to zeroes
+// (unless WUFFS_INITIALIZE__ALREADY_ZEROED is set).
+//
+// Setting this bit gives a small absolute improvement on micro-benchmarks, but
+// this can be a large relative effect, up to 2x faster, when the actual work
+// to be done is also small, such as decompressing small input. See git commit
+// 438fc105 "Move some struct fields to private_data" for some numbers and a
+// discussion, noting that its commit message was written before this
+// WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED option was defined.
+#define WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED \
+ ((uint32_t)0x00000002)
+
+// --------
+
// 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
// Wuffs, if a function g returns empty, you can say "y = g()".
@@ -96,6 +146,13 @@
uint8_t private_impl;
} wuffs_base__empty_struct;
+static inline wuffs_base__empty_struct //
+wuffs_base__make_empty_struct() {
+ wuffs_base__empty_struct ret;
+ ret.private_impl = 0;
+ return ret;
+}
+
// wuffs_base__utility is a placeholder receiver type. It enables what Java
// calls static methods, as opposed to regular methods.
typedef struct {
@@ -145,19 +202,21 @@
extern const char* wuffs_base__error__bad_workbuf_length;
extern const char* wuffs_base__error__bad_wuffs_version;
extern const char* wuffs_base__error__cannot_return_a_suspension;
-extern const char* wuffs_base__error__check_wuffs_version_not_applicable;
-extern const char* wuffs_base__error__check_wuffs_version_missing;
extern const char* wuffs_base__error__disabled_by_previous_error;
+extern const char* wuffs_base__error__initialize_falsely_claimed_already_zeroed;
+extern const char* wuffs_base__error__initialize_not_called;
extern const char* wuffs_base__error__interleaved_coroutine_calls;
+extern const char* wuffs_base__error__not_enough_data;
+extern const char* wuffs_base__error__too_much_data;
static inline bool //
wuffs_base__status__is_complete(wuffs_base__status z) {
- return (z == NULL) || ((*z != '$') && (*z != '?'));
+ return (z == NULL) || ((*z != '$') && (*z != '#'));
}
static inline bool //
wuffs_base__status__is_error(wuffs_base__status z) {
- return z && (*z == '?');
+ return z && (*z == '#');
}
static inline bool //
@@ -172,7 +231,7 @@
static inline bool //
wuffs_base__status__is_warning(wuffs_base__status z) {
- return z && (*z != '$') && (*z != '?');
+ return z && (*z != '$') && (*z != '#');
}
// --------
@@ -236,57 +295,57 @@
static inline uint8_t //
wuffs_base__u8__sat_add(uint8_t x, uint8_t y) {
- uint8_t res = x + y;
- res |= -(res < x);
+ uint8_t res = (uint8_t)(x + y);
+ res |= (uint8_t)(-(res < x));
return res;
}
static inline uint8_t //
wuffs_base__u8__sat_sub(uint8_t x, uint8_t y) {
- uint8_t res = x - y;
- res &= -(res <= x);
+ uint8_t res = (uint8_t)(x - y);
+ res &= (uint8_t)(-(res <= x));
return res;
}
static inline uint16_t //
wuffs_base__u16__sat_add(uint16_t x, uint16_t y) {
- uint16_t res = x + y;
- res |= -(res < x);
+ uint16_t res = (uint16_t)(x + y);
+ res |= (uint16_t)(-(res < x));
return res;
}
static inline uint16_t //
wuffs_base__u16__sat_sub(uint16_t x, uint16_t y) {
- uint16_t res = x - y;
- res &= -(res <= x);
+ uint16_t res = (uint16_t)(x - y);
+ res &= (uint16_t)(-(res <= x));
return res;
}
static inline uint32_t //
wuffs_base__u32__sat_add(uint32_t x, uint32_t y) {
- uint32_t res = x + y;
- res |= -(res < x);
+ uint32_t res = (uint32_t)(x + y);
+ res |= (uint32_t)(-(res < x));
return res;
}
static inline uint32_t //
wuffs_base__u32__sat_sub(uint32_t x, uint32_t y) {
- uint32_t res = x - y;
- res &= -(res <= x);
+ uint32_t res = (uint32_t)(x - y);
+ res &= (uint32_t)(-(res <= x));
return res;
}
static inline uint64_t //
wuffs_base__u64__sat_add(uint64_t x, uint64_t y) {
- uint64_t res = x + y;
- res |= -(res < x);
+ uint64_t res = (uint64_t)(x + y);
+ res |= (uint64_t)(-(res < x));
return res;
}
static inline uint64_t //
wuffs_base__u64__sat_sub(uint64_t x, uint64_t y) {
- uint64_t res = x - y;
- res &= -(res <= x);
+ uint64_t res = (uint64_t)(x - y);
+ res &= (uint64_t)(-(res <= x));
return res;
}
@@ -327,18 +386,65 @@
typedef WUFFS_BASE__TABLE(uint32_t) wuffs_base__table_u32;
typedef WUFFS_BASE__TABLE(uint64_t) wuffs_base__table_u64;
+static inline wuffs_base__slice_u8 //
+wuffs_base__make_slice_u8(uint8_t* ptr, size_t len) {
+ wuffs_base__slice_u8 ret;
+ ret.ptr = ptr;
+ ret.len = len;
+ return ret;
+}
+
+static inline wuffs_base__slice_u16 //
+wuffs_base__make_slice_u16(uint16_t* ptr, size_t len) {
+ wuffs_base__slice_u16 ret;
+ ret.ptr = ptr;
+ ret.len = len;
+ return ret;
+}
+
+static inline wuffs_base__slice_u32 //
+wuffs_base__make_slice_u32(uint32_t* ptr, size_t len) {
+ wuffs_base__slice_u32 ret;
+ ret.ptr = ptr;
+ ret.len = len;
+ return ret;
+}
+
+static inline wuffs_base__slice_u64 //
+wuffs_base__make_slice_u64(uint64_t* ptr, size_t len) {
+ wuffs_base__slice_u64 ret;
+ ret.ptr = ptr;
+ ret.len = len;
+ return ret;
+}
+
+static inline wuffs_base__slice_u8 //
+wuffs_base__null_slice_u8() {
+ wuffs_base__slice_u8 ret;
+ ret.ptr = NULL;
+ ret.len = 0;
+ return ret;
+}
+
+static inline wuffs_base__table_u8 //
+wuffs_base__null_table_u8() {
+ wuffs_base__table_u8 ret;
+ ret.ptr = NULL;
+ ret.width = 0;
+ ret.height = 0;
+ ret.stride = 0;
+ return ret;
+}
+
// wuffs_base__slice_u8__subslice_i returns s[i:].
//
// It returns an empty slice if i is out of bounds.
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 ((wuffs_base__slice_u8){
- .ptr = s.ptr + i,
- .len = s.len - i,
- });
+ return wuffs_base__make_slice_u8(s.ptr + i, s.len - i);
}
- return ((wuffs_base__slice_u8){});
+ return wuffs_base__make_slice_u8(NULL, 0);
}
// wuffs_base__slice_u8__subslice_j returns s[:j].
@@ -347,12 +453,9 @@
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 ((wuffs_base__slice_u8){
- .ptr = s.ptr,
- .len = j,
- });
+ return wuffs_base__make_slice_u8(s.ptr, j);
}
- return ((wuffs_base__slice_u8){});
+ return wuffs_base__make_slice_u8(NULL, 0);
}
// wuffs_base__slice_u8__subslice_ij returns s[i:j].
@@ -363,12 +466,9 @@
uint64_t i,
uint64_t j) {
if ((i <= j) && (j <= SIZE_MAX) && (j <= s.len)) {
- return ((wuffs_base__slice_u8){
- .ptr = s.ptr + i,
- .len = j - i,
- });
+ return wuffs_base__make_slice_u8(s.ptr + i, j - i);
}
- return ((wuffs_base__slice_u8){});
+ return wuffs_base__make_slice_u8(NULL, 0);
}
// ---------------- Ranges and Rects
@@ -411,15 +511,24 @@
#ifdef __cplusplus
inline bool is_empty();
inline bool equals(wuffs_base__range_ii_u32__struct s);
- inline bool contains(uint32_t x);
inline wuffs_base__range_ii_u32__struct intersect(
wuffs_base__range_ii_u32__struct s);
inline wuffs_base__range_ii_u32__struct unite(
wuffs_base__range_ii_u32__struct s);
+ inline bool contains(uint32_t x);
+ inline bool contains_range(wuffs_base__range_ii_u32__struct s);
#endif // __cplusplus
} wuffs_base__range_ii_u32;
+static inline wuffs_base__range_ii_u32 //
+wuffs_base__make_range_ii_u32(uint32_t min_incl, uint32_t max_incl) {
+ wuffs_base__range_ii_u32 ret;
+ ret.min_incl = min_incl;
+ ret.max_incl = max_incl;
+ return ret;
+}
+
static inline bool //
wuffs_base__range_ii_u32__is_empty(wuffs_base__range_ii_u32* r) {
return r->min_incl > r->max_incl;
@@ -433,25 +542,18 @@
wuffs_base__range_ii_u32__is_empty(&s));
}
-static inline bool //
-wuffs_base__range_ii_u32__contains(wuffs_base__range_ii_u32* r, uint32_t x) {
- return (r->min_incl <= x) && (x <= r->max_incl);
-}
-
-static inline //
- wuffs_base__range_ii_u32
- wuffs_base__range_ii_u32__intersect(wuffs_base__range_ii_u32* r,
- wuffs_base__range_ii_u32 s) {
+static inline wuffs_base__range_ii_u32 //
+wuffs_base__range_ii_u32__intersect(wuffs_base__range_ii_u32* r,
+ wuffs_base__range_ii_u32 s) {
wuffs_base__range_ii_u32 t;
t.min_incl = wuffs_base__u32__max(r->min_incl, s.min_incl);
t.max_incl = wuffs_base__u32__min(r->max_incl, s.max_incl);
return t;
}
-static inline //
- wuffs_base__range_ii_u32
- wuffs_base__range_ii_u32__unite(wuffs_base__range_ii_u32* r,
- wuffs_base__range_ii_u32 s) {
+static inline wuffs_base__range_ii_u32 //
+wuffs_base__range_ii_u32__unite(wuffs_base__range_ii_u32* r,
+ wuffs_base__range_ii_u32 s) {
if (wuffs_base__range_ii_u32__is_empty(r)) {
return s;
}
@@ -464,6 +566,18 @@
return t;
}
+static inline bool //
+wuffs_base__range_ii_u32__contains(wuffs_base__range_ii_u32* r, uint32_t x) {
+ return (r->min_incl <= x) && (x <= r->max_incl);
+}
+
+static inline bool //
+wuffs_base__range_ii_u32__contains_range(wuffs_base__range_ii_u32* r,
+ wuffs_base__range_ii_u32 s) {
+ return wuffs_base__range_ii_u32__equals(
+ &s, wuffs_base__range_ii_u32__intersect(r, s));
+}
+
#ifdef __cplusplus
inline bool //
@@ -476,11 +590,6 @@
return wuffs_base__range_ii_u32__equals(this, s);
}
-inline bool //
-wuffs_base__range_ii_u32::contains(uint32_t x) {
- return wuffs_base__range_ii_u32__contains(this, x);
-}
-
inline wuffs_base__range_ii_u32 //
wuffs_base__range_ii_u32::intersect(wuffs_base__range_ii_u32 s) {
return wuffs_base__range_ii_u32__intersect(this, s);
@@ -491,6 +600,16 @@
return wuffs_base__range_ii_u32__unite(this, s);
}
+inline bool //
+wuffs_base__range_ii_u32::contains(uint32_t x) {
+ return wuffs_base__range_ii_u32__contains(this, x);
+}
+
+inline bool //
+wuffs_base__range_ii_u32::contains_range(wuffs_base__range_ii_u32 s) {
+ return wuffs_base__range_ii_u32__contains_range(this, s);
+}
+
#endif // __cplusplus
// --------
@@ -502,16 +621,25 @@
#ifdef __cplusplus
inline bool is_empty();
inline bool equals(wuffs_base__range_ie_u32__struct s);
- inline bool contains(uint32_t x);
inline wuffs_base__range_ie_u32__struct intersect(
wuffs_base__range_ie_u32__struct s);
inline wuffs_base__range_ie_u32__struct unite(
wuffs_base__range_ie_u32__struct s);
+ inline bool contains(uint32_t x);
+ inline bool contains_range(wuffs_base__range_ie_u32__struct s);
inline uint32_t length();
#endif // __cplusplus
} wuffs_base__range_ie_u32;
+static inline wuffs_base__range_ie_u32 //
+wuffs_base__make_range_ie_u32(uint32_t min_incl, uint32_t max_excl) {
+ wuffs_base__range_ie_u32 ret;
+ ret.min_incl = min_incl;
+ ret.max_excl = max_excl;
+ return ret;
+}
+
static inline bool //
wuffs_base__range_ie_u32__is_empty(wuffs_base__range_ie_u32* r) {
return r->min_incl >= r->max_excl;
@@ -525,11 +653,6 @@
wuffs_base__range_ie_u32__is_empty(&s));
}
-static inline bool //
-wuffs_base__range_ie_u32__contains(wuffs_base__range_ie_u32* r, uint32_t x) {
- return (r->min_incl <= x) && (x < r->max_excl);
-}
-
static inline wuffs_base__range_ie_u32 //
wuffs_base__range_ie_u32__intersect(wuffs_base__range_ie_u32* r,
wuffs_base__range_ie_u32 s) {
@@ -554,6 +677,18 @@
return t;
}
+static inline bool //
+wuffs_base__range_ie_u32__contains(wuffs_base__range_ie_u32* r, uint32_t x) {
+ return (r->min_incl <= x) && (x < r->max_excl);
+}
+
+static inline bool //
+wuffs_base__range_ie_u32__contains_range(wuffs_base__range_ie_u32* r,
+ wuffs_base__range_ie_u32 s) {
+ return wuffs_base__range_ie_u32__equals(
+ &s, wuffs_base__range_ie_u32__intersect(r, s));
+}
+
static inline uint32_t //
wuffs_base__range_ie_u32__length(wuffs_base__range_ie_u32* r) {
return wuffs_base__u32__sat_sub(r->max_excl, r->min_incl);
@@ -571,11 +706,6 @@
return wuffs_base__range_ie_u32__equals(this, s);
}
-inline bool //
-wuffs_base__range_ie_u32::contains(uint32_t x) {
- return wuffs_base__range_ie_u32__contains(this, x);
-}
-
inline wuffs_base__range_ie_u32 //
wuffs_base__range_ie_u32::intersect(wuffs_base__range_ie_u32 s) {
return wuffs_base__range_ie_u32__intersect(this, s);
@@ -586,6 +716,16 @@
return wuffs_base__range_ie_u32__unite(this, s);
}
+inline bool //
+wuffs_base__range_ie_u32::contains(uint32_t x) {
+ return wuffs_base__range_ie_u32__contains(this, x);
+}
+
+inline bool //
+wuffs_base__range_ie_u32::contains_range(wuffs_base__range_ie_u32 s) {
+ return wuffs_base__range_ie_u32__contains_range(this, s);
+}
+
inline uint32_t //
wuffs_base__range_ie_u32::length() {
return wuffs_base__range_ie_u32__length(this);
@@ -602,15 +742,24 @@
#ifdef __cplusplus
inline bool is_empty();
inline bool equals(wuffs_base__range_ii_u64__struct s);
- inline bool contains(uint64_t x);
inline wuffs_base__range_ii_u64__struct intersect(
wuffs_base__range_ii_u64__struct s);
inline wuffs_base__range_ii_u64__struct unite(
wuffs_base__range_ii_u64__struct s);
+ inline bool contains(uint64_t x);
+ inline bool contains_range(wuffs_base__range_ii_u64__struct s);
#endif // __cplusplus
} wuffs_base__range_ii_u64;
+static inline wuffs_base__range_ii_u64 //
+wuffs_base__make_range_ii_u64(uint64_t min_incl, uint64_t max_incl) {
+ wuffs_base__range_ii_u64 ret;
+ ret.min_incl = min_incl;
+ ret.max_incl = max_incl;
+ return ret;
+}
+
static inline bool //
wuffs_base__range_ii_u64__is_empty(wuffs_base__range_ii_u64* r) {
return r->min_incl > r->max_incl;
@@ -624,11 +773,6 @@
wuffs_base__range_ii_u64__is_empty(&s));
}
-static inline bool //
-wuffs_base__range_ii_u64__contains(wuffs_base__range_ii_u64* r, uint64_t x) {
- return (r->min_incl <= x) && (x <= r->max_incl);
-}
-
static inline wuffs_base__range_ii_u64 //
wuffs_base__range_ii_u64__intersect(wuffs_base__range_ii_u64* r,
wuffs_base__range_ii_u64 s) {
@@ -653,6 +797,18 @@
return t;
}
+static inline bool //
+wuffs_base__range_ii_u64__contains(wuffs_base__range_ii_u64* r, uint64_t x) {
+ return (r->min_incl <= x) && (x <= r->max_incl);
+}
+
+static inline bool //
+wuffs_base__range_ii_u64__contains_range(wuffs_base__range_ii_u64* r,
+ wuffs_base__range_ii_u64 s) {
+ return wuffs_base__range_ii_u64__equals(
+ &s, wuffs_base__range_ii_u64__intersect(r, s));
+}
+
#ifdef __cplusplus
inline bool //
@@ -665,11 +821,6 @@
return wuffs_base__range_ii_u64__equals(this, s);
}
-inline bool //
-wuffs_base__range_ii_u64::contains(uint64_t x) {
- return wuffs_base__range_ii_u64__contains(this, x);
-}
-
inline wuffs_base__range_ii_u64 //
wuffs_base__range_ii_u64::intersect(wuffs_base__range_ii_u64 s) {
return wuffs_base__range_ii_u64__intersect(this, s);
@@ -680,6 +831,16 @@
return wuffs_base__range_ii_u64__unite(this, s);
}
+inline bool //
+wuffs_base__range_ii_u64::contains(uint64_t x) {
+ return wuffs_base__range_ii_u64__contains(this, x);
+}
+
+inline bool //
+wuffs_base__range_ii_u64::contains_range(wuffs_base__range_ii_u64 s) {
+ return wuffs_base__range_ii_u64__contains_range(this, s);
+}
+
#endif // __cplusplus
// --------
@@ -691,16 +852,25 @@
#ifdef __cplusplus
inline bool is_empty();
inline bool equals(wuffs_base__range_ie_u64__struct s);
- inline bool contains(uint64_t x);
inline wuffs_base__range_ie_u64__struct intersect(
wuffs_base__range_ie_u64__struct s);
inline wuffs_base__range_ie_u64__struct unite(
wuffs_base__range_ie_u64__struct s);
+ inline bool contains(uint64_t x);
+ inline bool contains_range(wuffs_base__range_ie_u64__struct s);
inline uint64_t length();
#endif // __cplusplus
} wuffs_base__range_ie_u64;
+static inline wuffs_base__range_ie_u64 //
+wuffs_base__make_range_ie_u64(uint64_t min_incl, uint64_t max_excl) {
+ wuffs_base__range_ie_u64 ret;
+ ret.min_incl = min_incl;
+ ret.max_excl = max_excl;
+ return ret;
+}
+
static inline bool //
wuffs_base__range_ie_u64__is_empty(wuffs_base__range_ie_u64* r) {
return r->min_incl >= r->max_excl;
@@ -714,11 +884,6 @@
wuffs_base__range_ie_u64__is_empty(&s));
}
-static inline bool //
-wuffs_base__range_ie_u64__contains(wuffs_base__range_ie_u64* r, uint64_t x) {
- return (r->min_incl <= x) && (x < r->max_excl);
-}
-
static inline wuffs_base__range_ie_u64 //
wuffs_base__range_ie_u64__intersect(wuffs_base__range_ie_u64* r,
wuffs_base__range_ie_u64 s) {
@@ -743,6 +908,18 @@
return t;
}
+static inline bool //
+wuffs_base__range_ie_u64__contains(wuffs_base__range_ie_u64* r, uint64_t x) {
+ return (r->min_incl <= x) && (x < r->max_excl);
+}
+
+static inline bool //
+wuffs_base__range_ie_u64__contains_range(wuffs_base__range_ie_u64* r,
+ wuffs_base__range_ie_u64 s) {
+ return wuffs_base__range_ie_u64__equals(
+ &s, wuffs_base__range_ie_u64__intersect(r, s));
+}
+
static inline uint64_t //
wuffs_base__range_ie_u64__length(wuffs_base__range_ie_u64* r) {
return wuffs_base__u64__sat_sub(r->max_excl, r->min_incl);
@@ -760,11 +937,6 @@
return wuffs_base__range_ie_u64__equals(this, s);
}
-inline bool //
-wuffs_base__range_ie_u64::contains(uint64_t x) {
- return wuffs_base__range_ie_u64__contains(this, x);
-}
-
inline wuffs_base__range_ie_u64 //
wuffs_base__range_ie_u64::intersect(wuffs_base__range_ie_u64 s) {
return wuffs_base__range_ie_u64__intersect(this, s);
@@ -775,6 +947,16 @@
return wuffs_base__range_ie_u64__unite(this, s);
}
+inline bool //
+wuffs_base__range_ie_u64::contains(uint64_t x) {
+ return wuffs_base__range_ie_u64__contains(this, x);
+}
+
+inline bool //
+wuffs_base__range_ie_u64::contains_range(wuffs_base__range_ie_u64 s) {
+ return wuffs_base__range_ie_u64__contains_range(this, s);
+}
+
inline uint64_t //
wuffs_base__range_ie_u64::length() {
return wuffs_base__range_ie_u64__length(this);
@@ -802,15 +984,29 @@
#ifdef __cplusplus
inline bool is_empty();
inline bool equals(wuffs_base__rect_ii_u32__struct s);
- inline bool contains(uint32_t x, uint32_t y);
inline wuffs_base__rect_ii_u32__struct intersect(
wuffs_base__rect_ii_u32__struct s);
inline wuffs_base__rect_ii_u32__struct unite(
wuffs_base__rect_ii_u32__struct s);
+ inline bool contains(uint32_t x, uint32_t y);
+ inline bool contains_rect(wuffs_base__rect_ii_u32__struct s);
#endif // __cplusplus
} wuffs_base__rect_ii_u32;
+static inline wuffs_base__rect_ii_u32 //
+wuffs_base__make_rect_ii_u32(uint32_t min_incl_x,
+ uint32_t min_incl_y,
+ uint32_t max_incl_x,
+ uint32_t max_incl_y) {
+ wuffs_base__rect_ii_u32 ret;
+ ret.min_incl_x = min_incl_x;
+ ret.min_incl_y = min_incl_y;
+ ret.max_incl_x = max_incl_x;
+ ret.max_incl_y = max_incl_y;
+ return ret;
+}
+
static inline bool //
wuffs_base__rect_ii_u32__is_empty(wuffs_base__rect_ii_u32* r) {
return (r->min_incl_x > r->max_incl_x) || (r->min_incl_y > r->max_incl_y);
@@ -825,14 +1021,6 @@
wuffs_base__rect_ii_u32__is_empty(&s));
}
-static inline bool //
-wuffs_base__rect_ii_u32__contains(wuffs_base__rect_ii_u32* r,
- uint32_t x,
- uint32_t y) {
- return (r->min_incl_x <= x) && (x <= r->max_incl_x) && (r->min_incl_y <= y) &&
- (y <= r->max_incl_y);
-}
-
static inline wuffs_base__rect_ii_u32 //
wuffs_base__rect_ii_u32__intersect(wuffs_base__rect_ii_u32* r,
wuffs_base__rect_ii_u32 s) {
@@ -861,6 +1049,21 @@
return t;
}
+static inline bool //
+wuffs_base__rect_ii_u32__contains(wuffs_base__rect_ii_u32* r,
+ uint32_t x,
+ uint32_t y) {
+ return (r->min_incl_x <= x) && (x <= r->max_incl_x) && (r->min_incl_y <= y) &&
+ (y <= r->max_incl_y);
+}
+
+static inline bool //
+wuffs_base__rect_ii_u32__contains_rect(wuffs_base__rect_ii_u32* r,
+ wuffs_base__rect_ii_u32 s) {
+ return wuffs_base__rect_ii_u32__equals(
+ &s, wuffs_base__rect_ii_u32__intersect(r, s));
+}
+
#ifdef __cplusplus
inline bool //
@@ -873,11 +1076,6 @@
return wuffs_base__rect_ii_u32__equals(this, s);
}
-inline bool //
-wuffs_base__rect_ii_u32::contains(uint32_t x, uint32_t y) {
- return wuffs_base__rect_ii_u32__contains(this, x, y);
-}
-
inline wuffs_base__rect_ii_u32 //
wuffs_base__rect_ii_u32::intersect(wuffs_base__rect_ii_u32 s) {
return wuffs_base__rect_ii_u32__intersect(this, s);
@@ -888,6 +1086,16 @@
return wuffs_base__rect_ii_u32__unite(this, s);
}
+inline bool //
+wuffs_base__rect_ii_u32::contains(uint32_t x, uint32_t y) {
+ return wuffs_base__rect_ii_u32__contains(this, x, y);
+}
+
+inline bool //
+wuffs_base__rect_ii_u32::contains_rect(wuffs_base__rect_ii_u32 s) {
+ return wuffs_base__rect_ii_u32__contains_rect(this, s);
+}
+
#endif // __cplusplus
// --------
@@ -911,17 +1119,31 @@
#ifdef __cplusplus
inline bool is_empty();
inline bool equals(wuffs_base__rect_ie_u32__struct s);
- inline bool contains(uint32_t x, uint32_t y);
inline wuffs_base__rect_ie_u32__struct intersect(
wuffs_base__rect_ie_u32__struct s);
inline wuffs_base__rect_ie_u32__struct unite(
wuffs_base__rect_ie_u32__struct s);
+ inline bool contains(uint32_t x, uint32_t y);
+ inline bool contains_rect(wuffs_base__rect_ie_u32__struct s);
inline uint32_t width();
inline uint32_t height();
#endif // __cplusplus
} wuffs_base__rect_ie_u32;
+static inline wuffs_base__rect_ie_u32 //
+wuffs_base__make_rect_ie_u32(uint32_t min_incl_x,
+ uint32_t min_incl_y,
+ uint32_t max_excl_x,
+ uint32_t max_excl_y) {
+ wuffs_base__rect_ie_u32 ret;
+ ret.min_incl_x = min_incl_x;
+ ret.min_incl_y = min_incl_y;
+ ret.max_excl_x = max_excl_x;
+ ret.max_excl_y = max_excl_y;
+ return ret;
+}
+
static inline bool //
wuffs_base__rect_ie_u32__is_empty(wuffs_base__rect_ie_u32* r) {
return (r->min_incl_x >= r->max_excl_x) || (r->min_incl_y >= r->max_excl_y);
@@ -936,14 +1158,6 @@
wuffs_base__rect_ie_u32__is_empty(&s));
}
-static inline bool //
-wuffs_base__rect_ie_u32__contains(wuffs_base__rect_ie_u32* r,
- uint32_t x,
- uint32_t y) {
- return (r->min_incl_x <= x) && (x < r->max_excl_x) && (r->min_incl_y <= y) &&
- (y < r->max_excl_y);
-}
-
static inline wuffs_base__rect_ie_u32 //
wuffs_base__rect_ie_u32__intersect(wuffs_base__rect_ie_u32* r,
wuffs_base__rect_ie_u32 s) {
@@ -972,6 +1186,21 @@
return t;
}
+static inline bool //
+wuffs_base__rect_ie_u32__contains(wuffs_base__rect_ie_u32* r,
+ uint32_t x,
+ uint32_t y) {
+ return (r->min_incl_x <= x) && (x < r->max_excl_x) && (r->min_incl_y <= y) &&
+ (y < r->max_excl_y);
+}
+
+static inline bool //
+wuffs_base__rect_ie_u32__contains_rect(wuffs_base__rect_ie_u32* r,
+ wuffs_base__rect_ie_u32 s) {
+ return wuffs_base__rect_ie_u32__equals(
+ &s, wuffs_base__rect_ie_u32__intersect(r, s));
+}
+
static inline uint32_t //
wuffs_base__rect_ie_u32__width(wuffs_base__rect_ie_u32* r) {
return wuffs_base__u32__sat_sub(r->max_excl_x, r->min_incl_x);
@@ -994,11 +1223,6 @@
return wuffs_base__rect_ie_u32__equals(this, s);
}
-inline bool //
-wuffs_base__rect_ie_u32::contains(uint32_t x, uint32_t y) {
- return wuffs_base__rect_ie_u32__contains(this, x, y);
-}
-
inline wuffs_base__rect_ie_u32 //
wuffs_base__rect_ie_u32::intersect(wuffs_base__rect_ie_u32 s) {
return wuffs_base__rect_ie_u32__intersect(this, s);
@@ -1009,6 +1233,16 @@
return wuffs_base__rect_ie_u32__unite(this, s);
}
+inline bool //
+wuffs_base__rect_ie_u32::contains(uint32_t x, uint32_t y) {
+ return wuffs_base__rect_ie_u32__contains(this, x, y);
+}
+
+inline bool //
+wuffs_base__rect_ie_u32::contains_rect(wuffs_base__rect_ie_u32 s) {
+ return wuffs_base__rect_ie_u32__contains_rect(this, s);
+}
+
inline uint32_t //
wuffs_base__rect_ie_u32::width() {
return wuffs_base__rect_ie_u32__width(this);
@@ -1078,6 +1312,68 @@
} wuffs_base__io_buffer;
+static inline wuffs_base__io_buffer //
+wuffs_base__make_io_buffer(wuffs_base__slice_u8 data,
+ wuffs_base__io_buffer_meta meta) {
+ wuffs_base__io_buffer ret;
+ ret.data = data;
+ ret.meta = meta;
+ return ret;
+}
+
+static inline wuffs_base__io_buffer_meta //
+wuffs_base__make_io_buffer_meta(size_t wi,
+ size_t ri,
+ uint64_t pos,
+ bool closed) {
+ wuffs_base__io_buffer_meta ret;
+ ret.wi = wi;
+ ret.ri = ri;
+ ret.pos = pos;
+ ret.closed = closed;
+ return ret;
+}
+
+static inline wuffs_base__io_buffer //
+wuffs_base__null_io_buffer() {
+ wuffs_base__io_buffer ret;
+ ret.data.ptr = NULL;
+ ret.data.len = 0;
+ ret.meta.wi = 0;
+ ret.meta.ri = 0;
+ ret.meta.pos = 0;
+ ret.meta.closed = false;
+ return ret;
+}
+
+static inline wuffs_base__io_buffer_meta //
+wuffs_base__null_io_buffer_meta() {
+ wuffs_base__io_buffer_meta ret;
+ ret.wi = 0;
+ ret.ri = 0;
+ ret.pos = 0;
+ ret.closed = false;
+ return ret;
+}
+
+static inline wuffs_base__io_reader //
+wuffs_base__null_io_reader() {
+ wuffs_base__io_reader ret;
+ ret.private_impl.buf = NULL;
+ ret.private_impl.mark = NULL;
+ ret.private_impl.limit = NULL;
+ return ret;
+}
+
+static inline wuffs_base__io_writer //
+wuffs_base__null_io_writer() {
+ wuffs_base__io_writer ret;
+ ret.private_impl.buf = NULL;
+ ret.private_impl.mark = NULL;
+ ret.private_impl.limit = NULL;
+ return ret;
+}
+
// wuffs_base__io_buffer__compact moves any written but unread bytes to the
// start of the buffer.
static inline void //
@@ -1096,15 +1392,19 @@
static inline wuffs_base__io_reader //
wuffs_base__io_buffer__reader(wuffs_base__io_buffer* buf) {
- wuffs_base__io_reader ret = ((wuffs_base__io_reader){});
+ wuffs_base__io_reader ret;
ret.private_impl.buf = buf;
+ ret.private_impl.mark = NULL;
+ ret.private_impl.limit = NULL;
return ret;
}
static inline wuffs_base__io_writer //
wuffs_base__io_buffer__writer(wuffs_base__io_buffer* buf) {
- wuffs_base__io_writer ret = ((wuffs_base__io_writer){});
+ wuffs_base__io_writer ret;
ret.private_impl.buf = buf;
+ ret.private_impl.mark = NULL;
+ ret.private_impl.limit = NULL;
return ret;
}
@@ -1167,13 +1467,10 @@
if (malloc_func && (num_u8 <= (SIZE_MAX / sizeof(uint8_t)))) {
void* p = (*malloc_func)(num_u8 * sizeof(uint8_t));
if (p) {
- return ((wuffs_base__slice_u8){
- .ptr = (uint8_t*)(p),
- .len = num_u8,
- });
+ return wuffs_base__make_slice_u8((uint8_t*)(p), num_u8);
}
}
- return ((wuffs_base__slice_u8){});
+ return wuffs_base__make_slice_u8(NULL, 0);
}
static inline wuffs_base__slice_u16 //
@@ -1181,13 +1478,10 @@
if (malloc_func && (num_u16 <= (SIZE_MAX / sizeof(uint16_t)))) {
void* p = (*malloc_func)(num_u16 * sizeof(uint16_t));
if (p) {
- return ((wuffs_base__slice_u16){
- .ptr = (uint16_t*)(p),
- .len = num_u16,
- });
+ return wuffs_base__make_slice_u16((uint16_t*)(p), num_u16);
}
}
- return ((wuffs_base__slice_u16){});
+ return wuffs_base__make_slice_u16(NULL, 0);
}
static inline wuffs_base__slice_u32 //
@@ -1195,13 +1489,10 @@
if (malloc_func && (num_u32 <= (SIZE_MAX / sizeof(uint32_t)))) {
void* p = (*malloc_func)(num_u32 * sizeof(uint32_t));
if (p) {
- return ((wuffs_base__slice_u32){
- .ptr = (uint32_t*)(p),
- .len = num_u32,
- });
+ return wuffs_base__make_slice_u32((uint32_t*)(p), num_u32);
}
}
- return ((wuffs_base__slice_u32){});
+ return wuffs_base__make_slice_u32(NULL, 0);
}
static inline wuffs_base__slice_u64 //
@@ -1209,13 +1500,10 @@
if (malloc_func && (num_u64 <= (SIZE_MAX / sizeof(uint64_t)))) {
void* p = (*malloc_func)(num_u64 * sizeof(uint64_t));
if (p) {
- return ((wuffs_base__slice_u64){
- .ptr = (uint64_t*)(p),
- .len = num_u64,
- });
+ return wuffs_base__make_slice_u64((uint64_t*)(p), num_u64);
}
}
- return ((wuffs_base__slice_u64){});
+ return wuffs_base__make_slice_u64(NULL, 0);
}
// ---------------- Images
@@ -1551,6 +1839,16 @@
} wuffs_base__pixel_config;
+static inline wuffs_base__pixel_config //
+wuffs_base__null_pixel_config() {
+ wuffs_base__pixel_config ret;
+ ret.private_impl.pixfmt = 0;
+ ret.private_impl.pixsub = 0;
+ ret.private_impl.width = 0;
+ ret.private_impl.height = 0;
+ return ret;
+}
+
// TODO: Should this function return bool? An error type?
static inline void //
wuffs_base__pixel_config__set(wuffs_base__pixel_config* c,
@@ -1572,13 +1870,20 @@
return;
}
}
- *c = ((wuffs_base__pixel_config){});
+
+ c->private_impl.pixfmt = 0;
+ c->private_impl.pixsub = 0;
+ c->private_impl.width = 0;
+ c->private_impl.height = 0;
}
static inline void //
wuffs_base__pixel_config__invalidate(wuffs_base__pixel_config* c) {
if (c) {
- *c = ((wuffs_base__pixel_config){});
+ c->private_impl.pixfmt = 0;
+ c->private_impl.pixsub = 0;
+ c->private_impl.width = 0;
+ c->private_impl.height = 0;
}
}
@@ -1599,13 +1904,21 @@
static inline wuffs_base__rect_ie_u32 //
wuffs_base__pixel_config__bounds(wuffs_base__pixel_config* c) {
- return c ? ((wuffs_base__rect_ie_u32){
- .min_incl_x = 0,
- .min_incl_y = 0,
- .max_excl_x = c->private_impl.width,
- .max_excl_y = c->private_impl.height,
- })
- : ((wuffs_base__rect_ie_u32){});
+ if (c) {
+ wuffs_base__rect_ie_u32 ret;
+ ret.min_incl_x = 0;
+ ret.min_incl_y = 0;
+ ret.max_excl_x = c->private_impl.width;
+ ret.max_excl_y = c->private_impl.height;
+ return ret;
+ }
+
+ wuffs_base__rect_ie_u32 ret;
+ ret.min_incl_x = 0;
+ ret.min_incl_y = 0;
+ ret.max_excl_x = 0;
+ ret.max_excl_y = 0;
+ return ret;
}
static inline uint32_t //
@@ -1734,6 +2047,15 @@
} wuffs_base__image_config;
+static inline wuffs_base__image_config //
+wuffs_base__null_image_config() {
+ wuffs_base__image_config ret;
+ ret.pixcfg = wuffs_base__null_pixel_config();
+ ret.private_impl.first_frame_io_position = 0;
+ ret.private_impl.first_frame_is_opaque = false;
+ return ret;
+}
+
// TODO: Should this function return bool? An error type?
static inline void //
wuffs_base__image_config__set(wuffs_base__image_config* c,
@@ -1755,13 +2077,24 @@
c->private_impl.first_frame_is_opaque = first_frame_is_opaque;
return;
}
- *c = ((wuffs_base__image_config){});
+
+ c->pixcfg.private_impl.pixfmt = 0;
+ c->pixcfg.private_impl.pixsub = 0;
+ c->pixcfg.private_impl.width = 0;
+ c->pixcfg.private_impl.height = 0;
+ c->private_impl.first_frame_io_position = 0;
+ c->private_impl.first_frame_is_opaque = 0;
}
static inline void //
wuffs_base__image_config__invalidate(wuffs_base__image_config* c) {
if (c) {
- *c = ((wuffs_base__image_config){});
+ c->pixcfg.private_impl.pixfmt = 0;
+ c->pixcfg.private_impl.pixsub = 0;
+ c->pixcfg.private_impl.width = 0;
+ c->pixcfg.private_impl.height = 0;
+ c->private_impl.first_frame_io_position = 0;
+ c->private_impl.first_frame_is_opaque = 0;
}
}
@@ -1886,6 +2219,18 @@
} wuffs_base__frame_config;
+static inline wuffs_base__frame_config //
+wuffs_base__null_frame_config() {
+ wuffs_base__frame_config ret;
+ ret.private_impl.bounds = wuffs_base__make_rect_ie_u32(0, 0, 0, 0);
+ ret.private_impl.duration = 0;
+ ret.private_impl.index = 0;
+ ret.private_impl.io_position = 0;
+ ret.private_impl.blend = 0;
+ ret.private_impl.disposal = 0;
+ return ret;
+}
+
static inline void //
wuffs_base__frame_config__update(wuffs_base__frame_config* c,
wuffs_base__rect_ie_u32 bounds,
@@ -1908,7 +2253,16 @@
static inline wuffs_base__rect_ie_u32 //
wuffs_base__frame_config__bounds(wuffs_base__frame_config* c) {
- return c ? c->private_impl.bounds : ((wuffs_base__rect_ie_u32){});
+ if (c) {
+ return c->private_impl.bounds;
+ }
+
+ wuffs_base__rect_ie_u32 ret;
+ ret.min_incl_x = 0;
+ ret.min_incl_y = 0;
+ ret.max_excl_x = 0;
+ ret.max_excl_y = 0;
+ return ret;
}
static inline uint32_t //
@@ -2033,6 +2387,17 @@
} wuffs_base__pixel_buffer;
+static inline wuffs_base__pixel_buffer //
+wuffs_base__null_pixel_buffer() {
+ wuffs_base__pixel_buffer ret;
+ ret.pixcfg = wuffs_base__null_pixel_config();
+ ret.private_impl.planes[0] = wuffs_base__null_table_u8();
+ ret.private_impl.planes[1] = wuffs_base__null_table_u8();
+ ret.private_impl.planes[2] = wuffs_base__null_table_u8();
+ ret.private_impl.planes[3] = wuffs_base__null_table_u8();
+ return ret;
+}
+
static inline wuffs_base__status //
wuffs_base__pixel_buffer__set_from_slice(wuffs_base__pixel_buffer* b,
wuffs_base__pixel_config* pixcfg,
@@ -2040,7 +2405,7 @@
if (!b) {
return wuffs_base__error__bad_receiver;
}
- *b = ((wuffs_base__pixel_buffer){});
+ memset(b, 0, sizeof(*b));
if (!pixcfg) {
return wuffs_base__error__bad_argument;
}
@@ -2106,13 +2471,10 @@
wuffs_base__table_u8* tab =
&b->private_impl.planes[WUFFS_BASE__PIXEL_FORMAT__INDEXED__COLOR_PLANE];
if ((tab->width == 1024) && (tab->height == 1)) {
- return ((wuffs_base__slice_u8){
- .ptr = tab->ptr,
- .len = 1024,
- });
+ return wuffs_base__make_slice_u8(tab->ptr, 1024);
}
}
- return ((wuffs_base__slice_u8){});
+ return wuffs_base__make_slice_u8(NULL, 0);
}
static inline wuffs_base__pixel_format //
@@ -2125,9 +2487,16 @@
static inline wuffs_base__table_u8 //
wuffs_base__pixel_buffer__plane(wuffs_base__pixel_buffer* b, uint32_t p) {
- return (b && (p < WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX))
- ? b->private_impl.planes[p]
- : ((wuffs_base__table_u8){});
+ if (b && (p < WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX)) {
+ return b->private_impl.planes[p];
+ }
+
+ wuffs_base__table_u8 ret;
+ ret.ptr = NULL;
+ ret.width = 0;
+ ret.height = 0;
+ ret.stride = 0;
+ return ret;
}
#ifdef __cplusplus
@@ -2237,6 +2606,10 @@
} // extern "C"
#endif
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -2251,15 +2624,17 @@
// ---------------- Public Initializer Prototypes
-// wuffs_adler32__hasher__check_wuffs_version is an initializer function.
-//
-// It should be called before any other wuffs_adler32__hasher__* function.
+// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
+// etc)" should be called before any other "wuffs_foo__bar__xxx(self, etc)".
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
+// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for initialize_flags.
+
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
-wuffs_adler32__hasher__check_wuffs_version(wuffs_adler32__hasher* self,
- size_t sizeof_star_self,
- uint64_t wuffs_version);
+wuffs_adler32__hasher__initialize(wuffs_adler32__hasher* self,
+ size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags);
size_t //
sizeof__wuffs_adler32__hasher();
@@ -2282,12 +2657,13 @@
struct wuffs_adler32__hasher__struct {
#ifdef WUFFS_IMPLEMENTATION
- // 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
- // wuffs_foo__bar__baz functions.
+ // Do not access the private_impl's or private_data's fields directly. There
+ // is no API/ABI compatibility or safety guarantee if you do so. Instead, use
+ // the wuffs_foo__bar__baz functions.
//
- // It is a struct, not a struct*, so that the outermost wuffs_foo__bar
- // struct can be stack allocated when WUFFS_IMPLEMENTATION is defined.
+ // It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct
+ // can be stack allocated when WUFFS_IMPLEMENTATION is defined.
+
struct {
uint32_t magic;
uint32_t active_coroutine;
@@ -2313,7 +2689,7 @@
union {
uint32_t align_as_per_magic_field;
uint8_t placeholder[1073741824]; // 1 GiB.
- } private_impl;
+ } private_impl WUFFS_BASE__POTENTIALLY_UNUSED_FIELD;
public:
@@ -2322,9 +2698,11 @@
#ifdef __cplusplus
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
- check_wuffs_version(size_t sizeof_star_self, uint64_t wuffs_version) {
- return wuffs_adler32__hasher__check_wuffs_version(this, sizeof_star_self,
- wuffs_version);
+ initialize(size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags) {
+ return wuffs_adler32__hasher__initialize(this, sizeof_star_self,
+ wuffs_version, initialize_flags);
}
inline uint32_t //
@@ -2363,15 +2741,17 @@
// ---------------- Public Initializer Prototypes
-// wuffs_crc32__ieee_hasher__check_wuffs_version is an initializer function.
-//
-// It should be called before any other wuffs_crc32__ieee_hasher__* function.
+// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
+// etc)" should be called before any other "wuffs_foo__bar__xxx(self, etc)".
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
+// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for initialize_flags.
+
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
-wuffs_crc32__ieee_hasher__check_wuffs_version(wuffs_crc32__ieee_hasher* self,
- size_t sizeof_star_self,
- uint64_t wuffs_version);
+wuffs_crc32__ieee_hasher__initialize(wuffs_crc32__ieee_hasher* self,
+ size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags);
size_t //
sizeof__wuffs_crc32__ieee_hasher();
@@ -2394,12 +2774,13 @@
struct wuffs_crc32__ieee_hasher__struct {
#ifdef WUFFS_IMPLEMENTATION
- // 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
- // wuffs_foo__bar__baz functions.
+ // Do not access the private_impl's or private_data's fields directly. There
+ // is no API/ABI compatibility or safety guarantee if you do so. Instead, use
+ // the wuffs_foo__bar__baz functions.
//
- // It is a struct, not a struct*, so that the outermost wuffs_foo__bar
- // struct can be stack allocated when WUFFS_IMPLEMENTATION is defined.
+ // It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct
+ // can be stack allocated when WUFFS_IMPLEMENTATION is defined.
+
struct {
uint32_t magic;
uint32_t active_coroutine;
@@ -2424,7 +2805,7 @@
union {
uint32_t align_as_per_magic_field;
uint8_t placeholder[1073741824]; // 1 GiB.
- } private_impl;
+ } private_impl WUFFS_BASE__POTENTIALLY_UNUSED_FIELD;
public:
@@ -2433,9 +2814,11 @@
#ifdef __cplusplus
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
- check_wuffs_version(size_t sizeof_star_self, uint64_t wuffs_version) {
- return wuffs_crc32__ieee_hasher__check_wuffs_version(this, sizeof_star_self,
- wuffs_version);
+ initialize(size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags) {
+ return wuffs_crc32__ieee_hasher__initialize(
+ this, sizeof_star_self, wuffs_version, initialize_flags);
}
inline uint32_t //
@@ -2483,31 +2866,43 @@
// ---------------- Public Consts
+#define WUFFS_DEFLATE__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 1
+
+static const uint64_t //
+ wuffs_deflate__decoder_workbuf_len_max_incl_worst_case //
+ WUFFS_BASE__POTENTIALLY_UNUSED = 1;
+
// ---------------- Struct Declarations
typedef struct wuffs_deflate__decoder__struct wuffs_deflate__decoder;
// ---------------- Public Initializer Prototypes
-// wuffs_deflate__decoder__check_wuffs_version is an initializer function.
-//
-// It should be called before any other wuffs_deflate__decoder__* function.
+// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
+// etc)" should be called before any other "wuffs_foo__bar__xxx(self, etc)".
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
+// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for initialize_flags.
+
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
-wuffs_deflate__decoder__check_wuffs_version(wuffs_deflate__decoder* self,
- size_t sizeof_star_self,
- uint64_t wuffs_version);
+wuffs_deflate__decoder__initialize(wuffs_deflate__decoder* self,
+ size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags);
size_t //
sizeof__wuffs_deflate__decoder();
// ---------------- Public Function Prototypes
+WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 //
+wuffs_deflate__decoder__workbuf_len(const wuffs_deflate__decoder* self);
+
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_deflate__decoder__decode_io_writer(wuffs_deflate__decoder* self,
wuffs_base__io_writer a_dst,
- wuffs_base__io_reader a_src);
+ wuffs_base__io_reader a_src,
+ wuffs_base__slice_u8 a_workbuf);
// ---------------- Struct Definitions
@@ -2521,39 +2916,43 @@
struct wuffs_deflate__decoder__struct {
#ifdef WUFFS_IMPLEMENTATION
- // 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
- // wuffs_foo__bar__baz functions.
+ // Do not access the private_impl's or private_data's fields directly. There
+ // is no API/ABI compatibility or safety guarantee if you do so. Instead, use
+ // the wuffs_foo__bar__baz functions.
//
- // It is a struct, not a struct*, so that the outermost wuffs_foo__bar
- // struct can be stack allocated when WUFFS_IMPLEMENTATION is defined.
+ // It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct
+ // can be stack allocated when WUFFS_IMPLEMENTATION is defined.
+
struct {
uint32_t magic;
uint32_t active_coroutine;
uint32_t f_bits;
uint32_t f_n_bits;
- uint32_t f_huffs[2][1234];
- uint32_t f_n_huffs_bits[2];
- uint8_t f_history[32768];
uint32_t f_history_index;
- uint8_t f_code_lengths[320];
+ uint32_t f_n_huffs_bits[2];
bool f_end_of_block;
+ uint32_t p_decode_io_writer[1];
+ uint32_t p_decode_blocks[1];
+ uint32_t p_decode_uncompressed[1];
+ uint32_t p_init_dynamic_huffman[1];
+ uint32_t p_decode_huffman_slow[1];
+ } private_impl;
+
+ struct {
+ uint32_t f_huffs[2][1024];
+ uint8_t f_history[32768];
+ uint8_t f_code_lengths[320];
+
struct {
- uint32_t coro_susp_point;
- } c_decode_io_writer[1];
- struct {
- uint32_t coro_susp_point;
uint32_t v_final;
- } c_decode_blocks[1];
+ } s_decode_blocks[1];
struct {
- uint32_t coro_susp_point;
uint32_t v_length;
uint64_t scratch;
- } c_decode_uncompressed[1];
+ } s_decode_uncompressed[1];
struct {
- uint32_t coro_susp_point;
uint32_t v_bits;
uint32_t v_n_bits;
uint32_t v_n_lit;
@@ -2565,9 +2964,8 @@
uint32_t v_n_extra_bits;
uint8_t v_rep_symbol;
uint32_t v_rep_count;
- } c_init_dynamic_huffman[1];
+ } s_init_dynamic_huffman[1];
struct {
- uint32_t coro_susp_point;
uint32_t v_bits;
uint32_t v_n_bits;
uint32_t v_table_entry;
@@ -2580,8 +2978,8 @@
uint32_t v_dist_minus_1;
uint32_t v_hlen;
uint32_t v_hdist;
- } c_decode_huffman_slow[1];
- } private_impl;
+ } s_decode_huffman_slow[1];
+ } private_data;
#else // WUFFS_IMPLEMENTATION
@@ -2599,7 +2997,7 @@
union {
uint32_t align_as_per_magic_field;
uint8_t placeholder[1073741824]; // 1 GiB.
- } private_impl;
+ } private_impl WUFFS_BASE__POTENTIALLY_UNUSED_FIELD;
public:
@@ -2608,14 +3006,24 @@
#ifdef __cplusplus
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
- check_wuffs_version(size_t sizeof_star_self, uint64_t wuffs_version) {
- return wuffs_deflate__decoder__check_wuffs_version(this, sizeof_star_self,
- wuffs_version);
+ initialize(size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags) {
+ return wuffs_deflate__decoder__initialize(this, sizeof_star_self,
+ wuffs_version, initialize_flags);
+ }
+
+ inline wuffs_base__range_ii_u64 //
+ workbuf_len() const {
+ return wuffs_deflate__decoder__workbuf_len(this);
}
inline wuffs_base__status //
- decode_io_writer(wuffs_base__io_writer a_dst, wuffs_base__io_reader a_src) {
- return wuffs_deflate__decoder__decode_io_writer(this, a_dst, a_src);
+ decode_io_writer(wuffs_base__io_writer a_dst,
+ wuffs_base__io_reader a_src,
+ wuffs_base__slice_u8 a_workbuf) {
+ return wuffs_deflate__decoder__decode_io_writer(this, a_dst, a_src,
+ a_workbuf);
}
#if (__cplusplus >= 201103L) && !defined(WUFFS_IMPLEMENTATION)
@@ -2646,21 +3054,29 @@
// ---------------- Public Consts
+#define WUFFS_LZW__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0
+
+static const uint64_t //
+ wuffs_lzw__decoder_workbuf_len_max_incl_worst_case //
+ WUFFS_BASE__POTENTIALLY_UNUSED = 0;
+
// ---------------- Struct Declarations
typedef struct wuffs_lzw__decoder__struct wuffs_lzw__decoder;
// ---------------- Public Initializer Prototypes
-// wuffs_lzw__decoder__check_wuffs_version is an initializer function.
-//
-// It should be called before any other wuffs_lzw__decoder__* function.
+// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
+// etc)" should be called before any other "wuffs_foo__bar__xxx(self, etc)".
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
+// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for initialize_flags.
+
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
-wuffs_lzw__decoder__check_wuffs_version(wuffs_lzw__decoder* self,
- size_t sizeof_star_self,
- uint64_t wuffs_version);
+wuffs_lzw__decoder__initialize(wuffs_lzw__decoder* self,
+ size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags);
size_t //
sizeof__wuffs_lzw__decoder();
@@ -2670,10 +3086,14 @@
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct //
wuffs_lzw__decoder__set_literal_width(wuffs_lzw__decoder* self, uint32_t a_lw);
+WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 //
+wuffs_lzw__decoder__workbuf_len(const wuffs_lzw__decoder* self);
+
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_lzw__decoder__decode_io_writer(wuffs_lzw__decoder* self,
wuffs_base__io_writer a_dst,
- wuffs_base__io_reader a_src);
+ wuffs_base__io_reader a_src,
+ wuffs_base__slice_u8 a_workbuf);
WUFFS_BASE__MAYBE_STATIC wuffs_base__slice_u8 //
wuffs_lzw__decoder__flush(wuffs_lzw__decoder* self);
@@ -2690,17 +3110,18 @@
struct wuffs_lzw__decoder__struct {
#ifdef WUFFS_IMPLEMENTATION
- // 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
- // wuffs_foo__bar__baz functions.
+ // Do not access the private_impl's or private_data's fields directly. There
+ // is no API/ABI compatibility or safety guarantee if you do so. Instead, use
+ // the wuffs_foo__bar__baz functions.
//
- // It is a struct, not a struct*, so that the outermost wuffs_foo__bar
- // struct can be stack allocated when WUFFS_IMPLEMENTATION is defined.
+ // It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct
+ // can be stack allocated when WUFFS_IMPLEMENTATION is defined.
+
struct {
uint32_t magic;
uint32_t active_coroutine;
- uint32_t f_lw;
+ uint32_t f_set_literal_width_arg;
uint32_t f_literal_width;
uint32_t f_clear_code;
uint32_t f_end_code;
@@ -2712,18 +3133,18 @@
uint32_t f_output_ri;
uint32_t f_output_wi;
uint32_t f_read_from_return_value;
- uint8_t f_suffixes[4096][8];
uint16_t f_prefixes[4096];
+
+ uint32_t p_decode_io_writer[1];
+ uint32_t p_write_to[1];
+ } private_impl;
+
+ struct {
+ uint8_t f_suffixes[4096][8];
uint16_t f_lm1s[4096];
uint8_t f_output[8199];
- struct {
- uint32_t coro_susp_point;
- } c_decode_io_writer[1];
- struct {
- uint32_t coro_susp_point;
- } c_write_to[1];
- } private_impl;
+ } private_data;
#else // WUFFS_IMPLEMENTATION
@@ -2741,7 +3162,7 @@
union {
uint32_t align_as_per_magic_field;
uint8_t placeholder[1073741824]; // 1 GiB.
- } private_impl;
+ } private_impl WUFFS_BASE__POTENTIALLY_UNUSED_FIELD;
public:
@@ -2750,9 +3171,11 @@
#ifdef __cplusplus
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
- check_wuffs_version(size_t sizeof_star_self, uint64_t wuffs_version) {
- return wuffs_lzw__decoder__check_wuffs_version(this, sizeof_star_self,
- wuffs_version);
+ initialize(size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags) {
+ return wuffs_lzw__decoder__initialize(this, sizeof_star_self, wuffs_version,
+ initialize_flags);
}
inline wuffs_base__empty_struct //
@@ -2760,9 +3183,16 @@
return wuffs_lzw__decoder__set_literal_width(this, a_lw);
}
+ inline wuffs_base__range_ii_u64 //
+ workbuf_len() const {
+ return wuffs_lzw__decoder__workbuf_len(this);
+ }
+
inline wuffs_base__status //
- decode_io_writer(wuffs_base__io_writer a_dst, wuffs_base__io_reader a_src) {
- return wuffs_lzw__decoder__decode_io_writer(this, a_dst, a_src);
+ decode_io_writer(wuffs_base__io_writer a_dst,
+ wuffs_base__io_reader a_src,
+ wuffs_base__slice_u8 a_workbuf) {
+ return wuffs_lzw__decoder__decode_io_writer(this, a_dst, a_src, a_workbuf);
}
inline wuffs_base__slice_u8 //
@@ -2798,26 +3228,32 @@
extern const char* wuffs_gif__error__bad_graphic_control;
extern const char* wuffs_gif__error__bad_header;
extern const char* wuffs_gif__error__bad_literal_width;
-extern const char* wuffs_gif__error__not_enough_pixel_data;
-extern const char* wuffs_gif__error__too_much_pixel_data;
// ---------------- Public Consts
+#define WUFFS_GIF__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 1
+
+static const uint64_t //
+ wuffs_gif__decoder_workbuf_len_max_incl_worst_case //
+ WUFFS_BASE__POTENTIALLY_UNUSED = 1;
+
// ---------------- Struct Declarations
typedef struct wuffs_gif__decoder__struct wuffs_gif__decoder;
// ---------------- Public Initializer Prototypes
-// wuffs_gif__decoder__check_wuffs_version is an initializer function.
-//
-// It should be called before any other wuffs_gif__decoder__* function.
+// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
+// etc)" should be called before any other "wuffs_foo__bar__xxx(self, etc)".
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
+// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for initialize_flags.
+
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
-wuffs_gif__decoder__check_wuffs_version(wuffs_gif__decoder* self,
- size_t sizeof_star_self,
- uint64_t wuffs_version);
+wuffs_gif__decoder__initialize(wuffs_gif__decoder* self,
+ size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags);
size_t //
sizeof__wuffs_gif__decoder();
@@ -2873,12 +3309,13 @@
struct wuffs_gif__decoder__struct {
#ifdef WUFFS_IMPLEMENTATION
- // 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
- // wuffs_foo__bar__baz functions.
+ // Do not access the private_impl's or private_data's fields directly. There
+ // is no API/ABI compatibility or safety guarantee if you do so. Instead, use
+ // the wuffs_foo__bar__baz functions.
//
- // It is a struct, not a struct*, so that the outermost wuffs_foo__bar
- // struct can be stack allocated when WUFFS_IMPLEMENTATION is defined.
+ // It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct
+ // can be stack allocated when WUFFS_IMPLEMENTATION is defined.
+
struct {
uint32_t magic;
uint32_t active_coroutine;
@@ -2910,77 +3347,70 @@
wuffs_base__range_ie_u32 f_dirty_y;
uint64_t f_compressed_ri;
uint64_t f_compressed_wi;
+ wuffs_base__pixel_swizzler f_swizzler;
+
+ uint32_t p_decode_image_config[1];
+ uint32_t p_decode_frame_config[1];
+ uint32_t p_skip_frame[1];
+ uint32_t p_decode_frame[1];
+ uint32_t p_decode_up_to_id_part1[1];
+ uint32_t p_decode_header[1];
+ uint32_t p_decode_lsd[1];
+ uint32_t p_decode_extension[1];
+ uint32_t p_skip_blocks[1];
+ uint32_t p_decode_ae[1];
+ uint32_t p_decode_gc[1];
+ uint32_t p_decode_id_part0[1];
+ uint32_t p_decode_id_part1[1];
+ uint32_t p_decode_id_part2[1];
+ } private_impl;
+
+ struct {
uint8_t f_compressed[4096];
uint8_t f_palettes[2][1024];
uint8_t f_dst_palette[1024];
- wuffs_base__pixel_swizzler f_swizzler;
- wuffs_base__utility f_util;
wuffs_lzw__decoder f_lzw;
struct {
- uint32_t coro_susp_point;
- } c_decode_image_config[1];
- struct {
- uint32_t coro_susp_point;
- } c_decode_frame_config[1];
- struct {
- uint32_t coro_susp_point;
uint64_t scratch;
- } c_skip_frame[1];
+ } s_skip_frame[1];
struct {
- uint32_t coro_susp_point;
- } c_decode_frame[1];
- struct {
- uint32_t coro_susp_point;
- } c_decode_up_to_id_part1[1];
- struct {
- uint32_t coro_susp_point;
uint8_t v_c[6];
uint32_t v_i;
- } c_decode_header[1];
+ } s_decode_header[1];
struct {
- uint32_t coro_susp_point;
uint8_t v_flags;
uint32_t v_num_palette_entries;
uint32_t v_i;
uint64_t scratch;
- } c_decode_lsd[1];
+ } s_decode_lsd[1];
struct {
- uint32_t coro_susp_point;
- } c_decode_extension[1];
- struct {
- uint32_t coro_susp_point;
uint64_t scratch;
- } c_skip_blocks[1];
+ } s_skip_blocks[1];
struct {
- uint32_t coro_susp_point;
uint8_t v_block_size;
bool v_not_animexts;
bool v_not_netscape;
uint64_t scratch;
- } c_decode_ae[1];
+ } s_decode_ae[1];
struct {
- uint32_t coro_susp_point;
uint64_t scratch;
- } c_decode_gc[1];
+ } s_decode_gc[1];
struct {
- uint32_t coro_susp_point;
uint64_t scratch;
- } c_decode_id_part0[1];
+ } s_decode_id_part0[1];
struct {
- uint32_t coro_susp_point;
uint32_t v_num_palette_entries;
uint32_t v_i;
uint64_t scratch;
- } c_decode_id_part1[1];
+ } s_decode_id_part1[1];
struct {
- uint32_t coro_susp_point;
uint64_t v_block_size;
bool v_need_block_size;
wuffs_base__status v_lzw_status;
uint64_t scratch;
- } c_decode_id_part2[1];
- } private_impl;
+ } s_decode_id_part2[1];
+ } private_data;
#else // WUFFS_IMPLEMENTATION
@@ -2998,7 +3428,7 @@
union {
uint32_t align_as_per_magic_field;
uint8_t placeholder[1073741824]; // 1 GiB.
- } private_impl;
+ } private_impl WUFFS_BASE__POTENTIALLY_UNUSED_FIELD;
public:
@@ -3007,9 +3437,11 @@
#ifdef __cplusplus
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
- check_wuffs_version(size_t sizeof_star_self, uint64_t wuffs_version) {
- return wuffs_gif__decoder__check_wuffs_version(this, sizeof_star_self,
- wuffs_version);
+ initialize(size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags) {
+ return wuffs_gif__decoder__initialize(this, sizeof_star_self, wuffs_version,
+ initialize_flags);
}
inline wuffs_base__status //
@@ -3093,21 +3525,29 @@
// ---------------- Public Consts
+#define WUFFS_GZIP__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 1
+
+static const uint64_t //
+ wuffs_gzip__decoder_workbuf_len_max_incl_worst_case //
+ WUFFS_BASE__POTENTIALLY_UNUSED = 1;
+
// ---------------- Struct Declarations
typedef struct wuffs_gzip__decoder__struct wuffs_gzip__decoder;
// ---------------- Public Initializer Prototypes
-// wuffs_gzip__decoder__check_wuffs_version is an initializer function.
-//
-// It should be called before any other wuffs_gzip__decoder__* function.
+// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
+// etc)" should be called before any other "wuffs_foo__bar__xxx(self, etc)".
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
+// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for initialize_flags.
+
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
-wuffs_gzip__decoder__check_wuffs_version(wuffs_gzip__decoder* self,
- size_t sizeof_star_self,
- uint64_t wuffs_version);
+wuffs_gzip__decoder__initialize(wuffs_gzip__decoder* self,
+ size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags);
size_t //
sizeof__wuffs_gzip__decoder();
@@ -3117,10 +3557,14 @@
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct //
wuffs_gzip__decoder__set_ignore_checksum(wuffs_gzip__decoder* self, bool a_ic);
+WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 //
+wuffs_gzip__decoder__workbuf_len(const wuffs_gzip__decoder* self);
+
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_gzip__decoder__decode_io_writer(wuffs_gzip__decoder* self,
wuffs_base__io_writer a_dst,
- wuffs_base__io_reader a_src);
+ wuffs_base__io_reader a_src,
+ wuffs_base__slice_u8 a_workbuf);
// ---------------- Struct Definitions
@@ -3134,29 +3578,34 @@
struct wuffs_gzip__decoder__struct {
#ifdef WUFFS_IMPLEMENTATION
- // 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
- // wuffs_foo__bar__baz functions.
+ // Do not access the private_impl's or private_data's fields directly. There
+ // is no API/ABI compatibility or safety guarantee if you do so. Instead, use
+ // the wuffs_foo__bar__baz functions.
//
- // It is a struct, not a struct*, so that the outermost wuffs_foo__bar
- // struct can be stack allocated when WUFFS_IMPLEMENTATION is defined.
+ // It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct
+ // can be stack allocated when WUFFS_IMPLEMENTATION is defined.
+
struct {
uint32_t magic;
uint32_t active_coroutine;
- wuffs_deflate__decoder f_flate;
- wuffs_crc32__ieee_hasher f_checksum;
bool f_ignore_checksum;
+ uint32_t p_decode_io_writer[1];
+ } private_impl;
+
+ struct {
+ wuffs_crc32__ieee_hasher f_checksum;
+ wuffs_deflate__decoder f_flate;
+
struct {
- uint32_t coro_susp_point;
uint8_t v_flags;
uint32_t v_checksum_got;
uint32_t v_decoded_length_got;
uint32_t v_checksum_want;
uint64_t scratch;
- } c_decode_io_writer[1];
- } private_impl;
+ } s_decode_io_writer[1];
+ } private_data;
#else // WUFFS_IMPLEMENTATION
@@ -3174,7 +3623,7 @@
union {
uint32_t align_as_per_magic_field;
uint8_t placeholder[1073741824]; // 1 GiB.
- } private_impl;
+ } private_impl WUFFS_BASE__POTENTIALLY_UNUSED_FIELD;
public:
@@ -3183,9 +3632,11 @@
#ifdef __cplusplus
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
- check_wuffs_version(size_t sizeof_star_self, uint64_t wuffs_version) {
- return wuffs_gzip__decoder__check_wuffs_version(this, sizeof_star_self,
- wuffs_version);
+ initialize(size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags) {
+ return wuffs_gzip__decoder__initialize(this, sizeof_star_self,
+ wuffs_version, initialize_flags);
}
inline wuffs_base__empty_struct //
@@ -3193,9 +3644,16 @@
return wuffs_gzip__decoder__set_ignore_checksum(this, a_ic);
}
+ inline wuffs_base__range_ii_u64 //
+ workbuf_len() const {
+ return wuffs_gzip__decoder__workbuf_len(this);
+ }
+
inline wuffs_base__status //
- decode_io_writer(wuffs_base__io_writer a_dst, wuffs_base__io_reader a_src) {
- return wuffs_gzip__decoder__decode_io_writer(this, a_dst, a_src);
+ decode_io_writer(wuffs_base__io_writer a_dst,
+ wuffs_base__io_reader a_src,
+ wuffs_base__slice_u8 a_workbuf) {
+ return wuffs_gzip__decoder__decode_io_writer(this, a_dst, a_src, a_workbuf);
}
#if (__cplusplus >= 201103L) && !defined(WUFFS_IMPLEMENTATION)
@@ -3228,21 +3686,29 @@
// ---------------- Public Consts
+#define WUFFS_ZLIB__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 1
+
+static const uint64_t //
+ wuffs_zlib__decoder_workbuf_len_max_incl_worst_case //
+ WUFFS_BASE__POTENTIALLY_UNUSED = 1;
+
// ---------------- Struct Declarations
typedef struct wuffs_zlib__decoder__struct wuffs_zlib__decoder;
// ---------------- Public Initializer Prototypes
-// wuffs_zlib__decoder__check_wuffs_version is an initializer function.
-//
-// It should be called before any other wuffs_zlib__decoder__* function.
+// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
+// etc)" should be called before any other "wuffs_foo__bar__xxx(self, etc)".
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
+// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for initialize_flags.
+
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
-wuffs_zlib__decoder__check_wuffs_version(wuffs_zlib__decoder* self,
- size_t sizeof_star_self,
- uint64_t wuffs_version);
+wuffs_zlib__decoder__initialize(wuffs_zlib__decoder* self,
+ size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags);
size_t //
sizeof__wuffs_zlib__decoder();
@@ -3252,10 +3718,14 @@
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct //
wuffs_zlib__decoder__set_ignore_checksum(wuffs_zlib__decoder* self, bool a_ic);
+WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 //
+wuffs_zlib__decoder__workbuf_len(const wuffs_zlib__decoder* self);
+
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_zlib__decoder__decode_io_writer(wuffs_zlib__decoder* self,
wuffs_base__io_writer a_dst,
- wuffs_base__io_reader a_src);
+ wuffs_base__io_reader a_src,
+ wuffs_base__slice_u8 a_workbuf);
// ---------------- Struct Definitions
@@ -3269,26 +3739,31 @@
struct wuffs_zlib__decoder__struct {
#ifdef WUFFS_IMPLEMENTATION
- // 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
- // wuffs_foo__bar__baz functions.
+ // Do not access the private_impl's or private_data's fields directly. There
+ // is no API/ABI compatibility or safety guarantee if you do so. Instead, use
+ // the wuffs_foo__bar__baz functions.
//
- // It is a struct, not a struct*, so that the outermost wuffs_foo__bar
- // struct can be stack allocated when WUFFS_IMPLEMENTATION is defined.
+ // It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct
+ // can be stack allocated when WUFFS_IMPLEMENTATION is defined.
+
struct {
uint32_t magic;
uint32_t active_coroutine;
- wuffs_deflate__decoder f_flate;
- wuffs_adler32__hasher f_checksum;
bool f_ignore_checksum;
+ uint32_t p_decode_io_writer[1];
+ } private_impl;
+
+ struct {
+ wuffs_adler32__hasher f_checksum;
+ wuffs_deflate__decoder f_flate;
+
struct {
- uint32_t coro_susp_point;
uint32_t v_checksum_got;
uint64_t scratch;
- } c_decode_io_writer[1];
- } private_impl;
+ } s_decode_io_writer[1];
+ } private_data;
#else // WUFFS_IMPLEMENTATION
@@ -3306,7 +3781,7 @@
union {
uint32_t align_as_per_magic_field;
uint8_t placeholder[1073741824]; // 1 GiB.
- } private_impl;
+ } private_impl WUFFS_BASE__POTENTIALLY_UNUSED_FIELD;
public:
@@ -3315,9 +3790,11 @@
#ifdef __cplusplus
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
- check_wuffs_version(size_t sizeof_star_self, uint64_t wuffs_version) {
- return wuffs_zlib__decoder__check_wuffs_version(this, sizeof_star_self,
- wuffs_version);
+ initialize(size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags) {
+ return wuffs_zlib__decoder__initialize(this, sizeof_star_self,
+ wuffs_version, initialize_flags);
}
inline wuffs_base__empty_struct //
@@ -3325,9 +3802,16 @@
return wuffs_zlib__decoder__set_ignore_checksum(this, a_ic);
}
+ inline wuffs_base__range_ii_u64 //
+ workbuf_len() const {
+ return wuffs_zlib__decoder__workbuf_len(this);
+ }
+
inline wuffs_base__status //
- decode_io_writer(wuffs_base__io_writer a_dst, wuffs_base__io_reader a_src) {
- return wuffs_zlib__decoder__decode_io_writer(this, a_dst, a_src);
+ decode_io_writer(wuffs_base__io_writer a_dst,
+ wuffs_base__io_reader a_src,
+ wuffs_base__slice_u8 a_workbuf) {
+ return wuffs_zlib__decoder__decode_io_writer(this, a_dst, a_src, a_workbuf);
}
#if (__cplusplus >= 201103L) && !defined(WUFFS_IMPLEMENTATION)
@@ -3350,14 +3834,20 @@
// WUFFS C HEADER ENDS HERE.
#ifdef WUFFS_IMPLEMENTATION
+// GCC does not warn for unused *static inline* functions, but clang does.
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunused-function"
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
-#define WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(x) (void)(x)
-
-static inline void wuffs_base__ignore_check_wuffs_version_status(
- wuffs_base__status z) {}
+static inline wuffs_base__empty_struct //
+wuffs_base__ignore_status(wuffs_base__status z) {
+ return wuffs_base__make_empty_struct();
+}
// 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,
@@ -3375,7 +3865,7 @@
// Denote intentional fallthroughs for -Wimplicit-fallthrough.
//
// The order matters here. Clang also defines "__GNUC__".
-#if defined(__clang__) && __cplusplus >= 201103L
+#if defined(__clang__) && defined(__cplusplus) && (__cplusplus >= 201103L)
#define WUFFS_BASE__FALLTHROUGH [[clang::fallthrough]]
#elif !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 7)
#define WUFFS_BASE__FALLTHROUGH __attribute__((fallthrough))
@@ -3423,11 +3913,6 @@
// inline attribute to guide optimizations such as inlining, to avoid the
// -Wunused-function warning, and we like to compile with -Wall -Werror.
-static inline wuffs_base__empty_struct //
-wuffs_base__return_empty_struct() {
- return ((wuffs_base__empty_struct){});
-}
-
// ---------------- Numeric Types
static inline uint8_t //
@@ -3437,12 +3922,12 @@
static inline uint16_t //
wuffs_base__load_u16be(uint8_t* p) {
- return ((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0);
+ return (uint16_t)(((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0));
}
static inline uint16_t //
wuffs_base__load_u16le(uint8_t* p) {
- return ((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8);
+ return (uint16_t)(((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8));
}
static inline uint32_t //
@@ -3538,128 +4023,128 @@
static inline void //
wuffs_base__store_u16be(uint8_t* p, uint16_t x) {
- p[0] = x >> 8;
- p[1] = x >> 0;
+ p[0] = (uint8_t)(x >> 8);
+ p[1] = (uint8_t)(x >> 0);
}
static inline void //
wuffs_base__store_u16le(uint8_t* p, uint16_t x) {
- p[0] = x >> 0;
- p[1] = x >> 8;
+ p[0] = (uint8_t)(x >> 0);
+ p[1] = (uint8_t)(x >> 8);
}
static inline void //
wuffs_base__store_u24be(uint8_t* p, uint32_t x) {
- p[0] = x >> 16;
- p[1] = x >> 8;
- p[2] = x >> 0;
+ p[0] = (uint8_t)(x >> 16);
+ p[1] = (uint8_t)(x >> 8);
+ p[2] = (uint8_t)(x >> 0);
}
static inline void //
wuffs_base__store_u24le(uint8_t* p, uint32_t x) {
- p[0] = x >> 0;
- p[1] = x >> 8;
- p[2] = x >> 16;
+ p[0] = (uint8_t)(x >> 0);
+ p[1] = (uint8_t)(x >> 8);
+ p[2] = (uint8_t)(x >> 16);
}
static inline void //
wuffs_base__store_u32be(uint8_t* p, uint32_t x) {
- p[0] = x >> 24;
- p[1] = x >> 16;
- p[2] = x >> 8;
- p[3] = x >> 0;
+ p[0] = (uint8_t)(x >> 24);
+ p[1] = (uint8_t)(x >> 16);
+ p[2] = (uint8_t)(x >> 8);
+ p[3] = (uint8_t)(x >> 0);
}
static inline void //
wuffs_base__store_u32le(uint8_t* p, uint32_t x) {
- p[0] = x >> 0;
- p[1] = x >> 8;
- p[2] = x >> 16;
- p[3] = x >> 24;
+ p[0] = (uint8_t)(x >> 0);
+ p[1] = (uint8_t)(x >> 8);
+ p[2] = (uint8_t)(x >> 16);
+ p[3] = (uint8_t)(x >> 24);
}
static inline void //
wuffs_base__store_u40be(uint8_t* p, uint64_t x) {
- p[0] = x >> 32;
- p[1] = x >> 24;
- p[2] = x >> 16;
- p[3] = x >> 8;
- p[4] = x >> 0;
+ p[0] = (uint8_t)(x >> 32);
+ p[1] = (uint8_t)(x >> 24);
+ p[2] = (uint8_t)(x >> 16);
+ p[3] = (uint8_t)(x >> 8);
+ p[4] = (uint8_t)(x >> 0);
}
static inline void //
wuffs_base__store_u40le(uint8_t* p, uint64_t x) {
- p[0] = x >> 0;
- p[1] = x >> 8;
- p[2] = x >> 16;
- p[3] = x >> 24;
- p[4] = x >> 32;
+ p[0] = (uint8_t)(x >> 0);
+ p[1] = (uint8_t)(x >> 8);
+ p[2] = (uint8_t)(x >> 16);
+ p[3] = (uint8_t)(x >> 24);
+ p[4] = (uint8_t)(x >> 32);
}
static inline void //
wuffs_base__store_u48be(uint8_t* p, uint64_t x) {
- p[0] = x >> 40;
- p[1] = x >> 32;
- p[2] = x >> 24;
- p[3] = x >> 16;
- p[4] = x >> 8;
- p[5] = x >> 0;
+ p[0] = (uint8_t)(x >> 40);
+ p[1] = (uint8_t)(x >> 32);
+ p[2] = (uint8_t)(x >> 24);
+ p[3] = (uint8_t)(x >> 16);
+ p[4] = (uint8_t)(x >> 8);
+ p[5] = (uint8_t)(x >> 0);
}
static inline void //
wuffs_base__store_u48le(uint8_t* p, uint64_t x) {
- p[0] = x >> 0;
- p[1] = x >> 8;
- p[2] = x >> 16;
- p[3] = x >> 24;
- p[4] = x >> 32;
- p[5] = x >> 40;
+ p[0] = (uint8_t)(x >> 0);
+ p[1] = (uint8_t)(x >> 8);
+ p[2] = (uint8_t)(x >> 16);
+ p[3] = (uint8_t)(x >> 24);
+ p[4] = (uint8_t)(x >> 32);
+ p[5] = (uint8_t)(x >> 40);
}
static inline void //
wuffs_base__store_u56be(uint8_t* p, uint64_t x) {
- p[0] = x >> 48;
- p[1] = x >> 40;
- p[2] = x >> 32;
- p[3] = x >> 24;
- p[4] = x >> 16;
- p[5] = x >> 8;
- p[6] = x >> 0;
+ p[0] = (uint8_t)(x >> 48);
+ p[1] = (uint8_t)(x >> 40);
+ p[2] = (uint8_t)(x >> 32);
+ p[3] = (uint8_t)(x >> 24);
+ p[4] = (uint8_t)(x >> 16);
+ p[5] = (uint8_t)(x >> 8);
+ p[6] = (uint8_t)(x >> 0);
}
static inline void //
wuffs_base__store_u56le(uint8_t* p, uint64_t x) {
- p[0] = x >> 0;
- p[1] = x >> 8;
- p[2] = x >> 16;
- p[3] = x >> 24;
- p[4] = x >> 32;
- p[5] = x >> 40;
- p[6] = x >> 48;
+ p[0] = (uint8_t)(x >> 0);
+ p[1] = (uint8_t)(x >> 8);
+ p[2] = (uint8_t)(x >> 16);
+ p[3] = (uint8_t)(x >> 24);
+ p[4] = (uint8_t)(x >> 32);
+ p[5] = (uint8_t)(x >> 40);
+ p[6] = (uint8_t)(x >> 48);
}
static inline void //
wuffs_base__store_u64be(uint8_t* p, uint64_t x) {
- p[0] = x >> 56;
- p[1] = x >> 48;
- p[2] = x >> 40;
- p[3] = x >> 32;
- p[4] = x >> 24;
- p[5] = x >> 16;
- p[6] = x >> 8;
- p[7] = x >> 0;
+ p[0] = (uint8_t)(x >> 56);
+ p[1] = (uint8_t)(x >> 48);
+ p[2] = (uint8_t)(x >> 40);
+ p[3] = (uint8_t)(x >> 32);
+ p[4] = (uint8_t)(x >> 24);
+ p[5] = (uint8_t)(x >> 16);
+ p[6] = (uint8_t)(x >> 8);
+ p[7] = (uint8_t)(x >> 0);
}
static inline void //
wuffs_base__store_u64le(uint8_t* p, uint64_t x) {
- p[0] = x >> 0;
- p[1] = x >> 8;
- p[2] = x >> 16;
- p[3] = x >> 24;
- p[4] = x >> 32;
- p[5] = x >> 40;
- p[6] = x >> 48;
- p[7] = x >> 56;
+ p[0] = (uint8_t)(x >> 0);
+ p[1] = (uint8_t)(x >> 8);
+ p[2] = (uint8_t)(x >> 16);
+ p[3] = (uint8_t)(x >> 24);
+ p[4] = (uint8_t)(x >> 32);
+ p[5] = (uint8_t)(x >> 40);
+ p[6] = (uint8_t)(x >> 48);
+ p[7] = (uint8_t)(x >> 56);
}
// --------
@@ -3757,14 +4242,15 @@
static inline wuffs_base__slice_u8 //
wuffs_base__table_u8__row(wuffs_base__table_u8 t, uint32_t y) {
if (y < t.height) {
- return ((wuffs_base__slice_u8){
- .ptr = t.ptr + (t.stride * y),
- .len = t.width,
- });
+ return wuffs_base__make_slice_u8(t.ptr + (t.stride * y), t.width);
}
- return ((wuffs_base__slice_u8){});
+ return wuffs_base__make_slice_u8(NULL, 0);
}
+ // ---------------- Slices and Tables (Utility)
+
+#define wuffs_base__utility__null_slice_u8 wuffs_base__null_slice_u8
+
// ---------------- Ranges and Rects
static inline uint32_t //
@@ -3807,75 +4293,14 @@
return r->max_excl;
}
-// ---------------- Ranges and Rects (Utility)
+ // ---------------- Ranges and Rects (Utility)
-static inline wuffs_base__range_ii_u32 //
-wuffs_base__utility__make_range_ii_u32(const wuffs_base__utility* ignored,
- uint32_t min_incl,
- uint32_t max_incl) {
- return ((wuffs_base__range_ii_u32){
- .min_incl = min_incl,
- .max_incl = max_incl,
- });
-}
-
-static inline wuffs_base__range_ie_u32 //
-wuffs_base__utility__make_range_ie_u32(const wuffs_base__utility* ignored,
- uint32_t min_incl,
- uint32_t max_excl) {
- return ((wuffs_base__range_ie_u32){
- .min_incl = min_incl,
- .max_excl = max_excl,
- });
-}
-
-static inline wuffs_base__range_ii_u64 //
-wuffs_base__utility__make_range_ii_u64(const wuffs_base__utility* ignored,
- uint64_t min_incl,
- uint64_t max_incl) {
- return ((wuffs_base__range_ii_u64){
- .min_incl = min_incl,
- .max_incl = max_incl,
- });
-}
-
-static inline wuffs_base__range_ie_u64 //
-wuffs_base__utility__make_range_ie_u64(const wuffs_base__utility* ignored,
- uint64_t min_incl,
- uint64_t max_excl) {
- return ((wuffs_base__range_ie_u64){
- .min_incl = min_incl,
- .max_excl = max_excl,
- });
-}
-
-static inline wuffs_base__rect_ii_u32 //
-wuffs_base__utility__make_rect_ii_u32(const wuffs_base__utility* ignored,
- uint32_t min_incl_x,
- uint32_t min_incl_y,
- uint32_t max_incl_x,
- uint32_t max_incl_y) {
- return ((wuffs_base__rect_ii_u32){
- .min_incl_x = min_incl_x,
- .min_incl_y = min_incl_y,
- .max_incl_x = max_incl_x,
- .max_incl_y = max_incl_y,
- });
-}
-
-static inline wuffs_base__rect_ie_u32 //
-wuffs_base__utility__make_rect_ie_u32(const wuffs_base__utility* ignored,
- uint32_t min_incl_x,
- uint32_t min_incl_y,
- uint32_t max_excl_x,
- uint32_t max_excl_y) {
- return ((wuffs_base__rect_ie_u32){
- .min_incl_x = min_incl_x,
- .min_incl_y = min_incl_y,
- .max_excl_x = max_excl_x,
- .max_excl_y = max_excl_y,
- });
-}
+#define wuffs_base__utility__make_range_ii_u32 wuffs_base__make_range_ii_u32
+#define wuffs_base__utility__make_range_ie_u32 wuffs_base__make_range_ie_u32
+#define wuffs_base__utility__make_range_ii_u64 wuffs_base__make_range_ii_u64
+#define wuffs_base__utility__make_range_ie_u64 wuffs_base__make_range_ie_u64
+#define wuffs_base__utility__make_rect_ii_u32 wuffs_base__make_rect_ii_u32
+#define wuffs_base__utility__make_rect_ie_u32 wuffs_base__make_rect_ie_u32
// ---------------- I/O
@@ -3937,11 +4362,11 @@
return 0;
}
uint8_t* q = p - distance;
- size_t n = io1_w - p;
+ size_t n = (size_t)(io1_w - p);
if ((size_t)(length) > n) {
- length = n;
+ length = (uint32_t)(n);
} else {
- n = length;
+ n = (size_t)(length);
}
// TODO: unrolling by 3 seems best for the std/deflate benchmarks, but that
// is mostly because 3 is the minimum length for the deflate format. This
@@ -4001,18 +4426,18 @@
uint8_t* iop_w = *ptr_iop_w;
size_t n = length;
if (n > ((size_t)(io1_w - iop_w))) {
- n = io1_w - iop_w;
+ n = (size_t)(io1_w - iop_w);
}
uint8_t* iop_r = *ptr_iop_r;
if (n > ((size_t)(io1_r - iop_r))) {
- n = io1_r - iop_r;
+ n = (size_t)(io1_r - iop_r);
}
if (n > 0) {
memmove(iop_w, iop_r, n);
*ptr_iop_w += n;
*ptr_iop_r += n;
}
- return n;
+ return (uint32_t)(n);
}
static inline uint64_t //
@@ -4022,13 +4447,13 @@
uint8_t* iop_w = *ptr_iop_w;
size_t n = src.len;
if (n > ((size_t)(io1_w - iop_w))) {
- n = io1_w - iop_w;
+ n = (size_t)(io1_w - iop_w);
}
if (n > 0) {
memmove(iop_w, src.ptr, n);
*ptr_iop_w += n;
}
- return n;
+ return (uint64_t)(n);
}
static inline uint32_t //
@@ -4042,13 +4467,13 @@
n = length;
}
if (n > ((size_t)(io1_w - iop_w))) {
- n = io1_w - iop_w;
+ n = (size_t)(io1_w - iop_w);
}
if (n > 0) {
memmove(iop_w, src.ptr, n);
*ptr_iop_w += n;
}
- return n;
+ return (uint32_t)(n);
}
static inline wuffs_base__empty_struct //
@@ -4068,7 +4493,10 @@
o->private_impl.limit = data.ptr + data.len;
*ptr_iop_r = data.ptr;
*ptr_io1_r = data.ptr + data.len;
- return ((wuffs_base__empty_struct){});
+
+ wuffs_base__empty_struct ret;
+ ret.private_impl = 0;
+ return ret;
}
static inline wuffs_base__empty_struct //
@@ -4078,13 +4506,19 @@
if (o && (((size_t)(o->private_impl.limit - iop_r)) > limit)) {
o->private_impl.limit = iop_r + limit;
}
- return ((wuffs_base__empty_struct){});
+
+ wuffs_base__empty_struct ret;
+ ret.private_impl = 0;
+ return ret;
}
static inline wuffs_base__empty_struct //
wuffs_base__io_reader__set_mark(wuffs_base__io_reader* o, uint8_t* mark) {
o->private_impl.mark = mark;
- return ((wuffs_base__empty_struct){});
+
+ wuffs_base__empty_struct ret;
+ ret.private_impl = 0;
+ return ret;
}
static inline wuffs_base__slice_u8 //
@@ -4092,12 +4526,9 @@
if (n <= ((size_t)(io1_r - *ptr_iop_r))) {
uint8_t* p = *ptr_iop_r;
*ptr_iop_r += n;
- return ((wuffs_base__slice_u8){
- .ptr = p,
- .len = n,
- });
+ return wuffs_base__make_slice_u8(p, n);
}
- return ((wuffs_base__slice_u8){});
+ return wuffs_base__make_slice_u8(NULL, 0);
}
static inline wuffs_base__empty_struct //
@@ -4117,26 +4548,25 @@
o->private_impl.limit = data.ptr + data.len;
*ptr_iop_w = data.ptr;
*ptr_io1_w = data.ptr + data.len;
- return ((wuffs_base__empty_struct){});
+
+ wuffs_base__empty_struct ret;
+ ret.private_impl = 0;
+ return ret;
}
static inline wuffs_base__empty_struct //
wuffs_base__io_writer__set_mark(wuffs_base__io_writer* o, uint8_t* mark) {
o->private_impl.mark = mark;
- return ((wuffs_base__empty_struct){});
+
+ wuffs_base__empty_struct ret;
+ ret.private_impl = 0;
+ return ret;
}
-// ---------------- I/O (Utility)
+ // ---------------- I/O (Utility)
-static inline wuffs_base__io_reader //
-wuffs_base__utility__null_io_reader(const wuffs_base__utility* ignored) {
- return ((wuffs_base__io_reader){});
-}
-
-static inline wuffs_base__io_writer //
-wuffs_base__utility__null_io_writer(const wuffs_base__utility* ignored) {
- return ((wuffs_base__io_writer){});
-}
+#define wuffs_base__utility__null_io_reader wuffs_base__null_io_reader
+#define wuffs_base__utility__null_io_writer wuffs_base__null_io_writer
// ---------------- Memory Allocation
@@ -4187,29 +4617,31 @@
0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF,
};
-const char* wuffs_base__warning__end_of_data = "~base: end of data";
+const char* wuffs_base__warning__end_of_data = "@base: end of data";
const char* wuffs_base__suspension__short_read = "$base: short read";
const char* wuffs_base__suspension__short_write = "$base: short write";
const char* wuffs_base__error__bad_argument_length_too_short =
- "?base: bad argument (length too short)";
-const char* wuffs_base__error__bad_argument = "?base: bad argument";
-const char* wuffs_base__error__bad_call_sequence = "?base: bad call sequence";
-const char* wuffs_base__error__bad_receiver = "?base: bad receiver";
-const char* wuffs_base__error__bad_restart = "?base: bad restart";
+ "#base: bad argument (length too short)";
+const char* wuffs_base__error__bad_argument = "#base: bad argument";
+const char* wuffs_base__error__bad_call_sequence = "#base: bad call sequence";
+const char* wuffs_base__error__bad_receiver = "#base: bad receiver";
+const char* wuffs_base__error__bad_restart = "#base: bad restart";
const char* wuffs_base__error__bad_sizeof_receiver =
- "?base: bad sizeof receiver";
-const char* wuffs_base__error__bad_workbuf_length = "?base: bad workbuf length";
-const char* wuffs_base__error__bad_wuffs_version = "?base: bad wuffs version";
+ "#base: bad sizeof receiver";
+const char* wuffs_base__error__bad_workbuf_length = "#base: bad workbuf length";
+const char* wuffs_base__error__bad_wuffs_version = "#base: bad wuffs version";
const char* wuffs_base__error__cannot_return_a_suspension =
- "?base: cannot return a suspension";
-const char* wuffs_base__error__check_wuffs_version_not_applicable =
- "?base: check_wuffs_version not applicable";
-const char* wuffs_base__error__check_wuffs_version_missing =
- "?base: check_wuffs_version missing";
+ "#base: cannot return a suspension";
const char* wuffs_base__error__disabled_by_previous_error =
- "?base: disabled by previous error";
+ "#base: disabled by previous error";
+const char* wuffs_base__error__initialize_falsely_claimed_already_zeroed =
+ "#base: initialize falsely claimed already zeroed";
+const char* wuffs_base__error__initialize_not_called =
+ "#base: initialize not called";
const char* wuffs_base__error__interleaved_coroutine_calls =
- "?base: interleaved coroutine calls";
+ "#base: interleaved coroutine calls";
+const char* wuffs_base__error__not_enough_data = "#base: not enough data";
+const char* wuffs_base__error__too_much_data = "#base: too much data";
// ---------------- Images
@@ -4256,7 +4688,7 @@
s += 1 * N;
d += 4 * N;
- n -= 1 * N;
+ n -= (size_t)(1 * N);
}
while (n >= 1) {
@@ -4266,7 +4698,7 @@
s += 1 * 1;
d += 4 * 1;
- n -= 1 * 1;
+ n -= (size_t)(1 * 1);
}
return len;
@@ -4370,6 +4802,10 @@
} // extern "C"
#endif
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ADLER32)
// ---------------- Status Codes Implementations
@@ -4383,9 +4819,10 @@
// ---------------- Initializer Implementations
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
-wuffs_adler32__hasher__check_wuffs_version(wuffs_adler32__hasher* self,
- size_t sizeof_star_self,
- uint64_t wuffs_version) {
+wuffs_adler32__hasher__initialize(wuffs_adler32__hasher* self,
+ size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags) {
if (!self) {
return wuffs_base__error__bad_receiver;
}
@@ -4396,16 +4833,39 @@
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
return wuffs_base__error__bad_wuffs_version;
}
- if (self->private_impl.magic != 0) {
- return wuffs_base__error__check_wuffs_version_not_applicable;
+
+ if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
+// The whole point of this if-check is to detect an uninitialized *self.
+// We disable the warning on GCC. Clang-5.0 does not have this warning.
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+#endif
+ if (self->private_impl.magic != 0) {
+ return wuffs_base__error__initialize_falsely_claimed_already_zeroed;
+ }
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
+ } else {
+ void* p = &(self->private_impl);
+ size_t n = sizeof(self->private_impl);
+ if ((initialize_flags &
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
+ p = self;
+ n = sizeof(*self);
+ initialize_flags |= WUFFS_INITIALIZE__ALREADY_ZEROED;
+ }
+ memset(p, 0, n);
}
+
self->private_impl.magic = WUFFS_BASE__MAGIC;
return NULL;
}
size_t //
sizeof__wuffs_adler32__hasher() {
- return sizeof((wuffs_adler32__hasher){});
+ return sizeof(wuffs_adler32__hasher);
}
// ---------------- Function Implementations
@@ -4424,8 +4884,8 @@
uint32_t v_s1 = 0;
uint32_t v_s2 = 0;
- wuffs_base__slice_u8 v_remaining = {};
- wuffs_base__slice_u8 v_p = {};
+ wuffs_base__slice_u8 v_remaining = {0};
+ wuffs_base__slice_u8 v_p = {0};
if (!self->private_impl.f_started) {
self->private_impl.f_started = true;
@@ -4495,727 +4955,873 @@
// ---------------- Private Consts
-static const uint32_t wuffs_crc32__ieee_table[16][256] = {
- {
- 0, 1996959894, 3993919788, 2567524794, 124634137, 1886057615,
- 3915621685, 2657392035, 249268274, 2044508324, 3772115230, 2547177864,
- 162941995, 2125561021, 3887607047, 2428444049, 498536548, 1789927666,
- 4089016648, 2227061214, 450548861, 1843258603, 4107580753, 2211677639,
- 325883990, 1684777152, 4251122042, 2321926636, 335633487, 1661365465,
- 4195302755, 2366115317, 997073096, 1281953886, 3579855332, 2724688242,
- 1006888145, 1258607687, 3524101629, 2768942443, 901097722, 1119000684,
- 3686517206, 2898065728, 853044451, 1172266101, 3705015759, 2882616665,
- 651767980, 1373503546, 3369554304, 3218104598, 565507253, 1454621731,
- 3485111705, 3099436303, 671266974, 1594198024, 3322730930, 2970347812,
- 795835527, 1483230225, 3244367275, 3060149565, 1994146192, 31158534,
- 2563907772, 4023717930, 1907459465, 112637215, 2680153253, 3904427059,
- 2013776290, 251722036, 2517215374, 3775830040, 2137656763, 141376813,
- 2439277719, 3865271297, 1802195444, 476864866, 2238001368, 4066508878,
- 1812370925, 453092731, 2181625025, 4111451223, 1706088902, 314042704,
- 2344532202, 4240017532, 1658658271, 366619977, 2362670323, 4224994405,
- 1303535960, 984961486, 2747007092, 3569037538, 1256170817, 1037604311,
- 2765210733, 3554079995, 1131014506, 879679996, 2909243462, 3663771856,
- 1141124467, 855842277, 2852801631, 3708648649, 1342533948, 654459306,
- 3188396048, 3373015174, 1466479909, 544179635, 3110523913, 3462522015,
- 1591671054, 702138776, 2966460450, 3352799412, 1504918807, 783551873,
- 3082640443, 3233442989, 3988292384, 2596254646, 62317068, 1957810842,
- 3939845945, 2647816111, 81470997, 1943803523, 3814918930, 2489596804,
- 225274430, 2053790376, 3826175755, 2466906013, 167816743, 2097651377,
- 4027552580, 2265490386, 503444072, 1762050814, 4150417245, 2154129355,
- 426522225, 1852507879, 4275313526, 2312317920, 282753626, 1742555852,
- 4189708143, 2394877945, 397917763, 1622183637, 3604390888, 2714866558,
- 953729732, 1340076626, 3518719985, 2797360999, 1068828381, 1219638859,
- 3624741850, 2936675148, 906185462, 1090812512, 3747672003, 2825379669,
- 829329135, 1181335161, 3412177804, 3160834842, 628085408, 1382605366,
- 3423369109, 3138078467, 570562233, 1426400815, 3317316542, 2998733608,
- 733239954, 1555261956, 3268935591, 3050360625, 752459403, 1541320221,
- 2607071920, 3965973030, 1969922972, 40735498, 2617837225, 3943577151,
- 1913087877, 83908371, 2512341634, 3803740692, 2075208622, 213261112,
- 2463272603, 3855990285, 2094854071, 198958881, 2262029012, 4057260610,
- 1759359992, 534414190, 2176718541, 4139329115, 1873836001, 414664567,
- 2282248934, 4279200368, 1711684554, 285281116, 2405801727, 4167216745,
- 1634467795, 376229701, 2685067896, 3608007406, 1308918612, 956543938,
- 2808555105, 3495958263, 1231636301, 1047427035, 2932959818, 3654703836,
- 1088359270, 936918000, 2847714899, 3736837829, 1202900863, 817233897,
- 3183342108, 3401237130, 1404277552, 615818150, 3134207493, 3453421203,
- 1423857449, 601450431, 3009837614, 3294710456, 1567103746, 711928724,
- 3020668471, 3272380065, 1510334235, 755167117,
- },
- {
- 0, 421212481, 842424962, 724390851, 1684849924, 2105013317,
- 1448781702, 1329698503, 3369699848, 3519200073, 4210026634, 3824474571,
- 2897563404, 3048111693, 2659397006, 2274893007, 1254232657, 1406739216,
- 2029285587, 1643069842, 783210325, 934667796, 479770071, 92505238,
- 2182846553, 2600511768, 2955803355, 2838940570, 3866582365, 4285295644,
- 3561045983, 3445231262, 2508465314, 2359236067, 2813478432, 3198777185,
- 4058571174, 3908292839, 3286139684, 3670389349, 1566420650, 1145479147,
- 1869335592, 1987116393, 959540142, 539646703, 185010476, 303839341,
- 3745920755, 3327985586, 3983561841, 4100678960, 3140154359, 2721170102,
- 2300350837, 2416418868, 396344571, 243568058, 631889529, 1018359608,
- 1945336319, 1793607870, 1103436669, 1490954812, 4034481925, 3915546180,
- 3259968903, 3679722694, 2484439553, 2366552896, 2787371139, 3208174018,
- 950060301, 565965900, 177645455, 328046286, 1556873225, 1171730760,
- 1861902987, 2011255754, 3132841300, 2745199637, 2290958294, 2442530455,
- 3738671184, 3352078609, 3974232786, 4126854035, 1919080284, 1803150877,
- 1079293406, 1498383519, 370020952, 253043481, 607678682, 1025720731,
- 1711106983, 2095471334, 1472923941, 1322268772, 26324643, 411738082,
- 866634785, 717028704, 2904875439, 3024081134, 2668790573, 2248782444,
- 3376948395, 3495106026, 4219356713, 3798300520, 792689142, 908347575,
- 487136116, 68299317, 1263779058, 1380486579, 2036719216, 1618931505,
- 3890672638, 4278043327, 3587215740, 3435896893, 2206873338, 2593195963,
- 2981909624, 2829542713, 998479947, 580430090, 162921161, 279890824,
- 1609522511, 1190423566, 1842954189, 1958874764, 4082766403, 3930137346,
- 3245109441, 3631694208, 2536953671, 2385372678, 2768287173, 3155920004,
- 1900120602, 1750776667, 1131931800, 1517083097, 355290910, 204897887,
- 656092572, 1040194781, 3113746450, 2692952403, 2343461520, 2461357009,
- 3723805974, 3304059991, 4022511508, 4141455061, 2919742697, 3072101800,
- 2620513899, 2234183466, 3396041197, 3547351212, 4166851439, 3779471918,
- 1725839073, 2143618976, 1424512099, 1307796770, 45282277, 464110244,
- 813994343, 698327078, 3838160568, 4259225593, 3606301754, 3488152955,
- 2158586812, 2578602749, 2996767038, 2877569151, 740041904, 889656817,
- 506086962, 120682355, 1215357364, 1366020341, 2051441462, 1667084919,
- 3422213966, 3538019855, 4190942668, 3772220557, 2945847882, 3062702859,
- 2644537544, 2226864521, 52649286, 439905287, 823476164, 672009861,
- 1733269570, 2119477507, 1434057408, 1281543041, 2167981343, 2552493150,
- 3004082077, 2853541596, 3847487515, 4233048410, 3613549209, 3464057816,
- 1239502615, 1358593622, 2077699477, 1657543892, 764250643, 882293586,
- 532408465, 111204816, 1585378284, 1197851309, 1816695150, 1968414767,
- 974272232, 587794345, 136598634, 289367339, 2527558116, 2411481253,
- 2760973158, 3179948583, 4073438432, 3956313505, 3237863010, 3655790371,
- 347922877, 229101820, 646611775, 1066513022, 1892689081, 1774917112,
- 1122387515, 1543337850, 3697634229, 3313392372, 3998419255, 4148705398,
- 3087642289, 2702352368, 2319436851, 2468674930,
- },
- {
- 0, 29518391, 59036782, 38190681, 118073564, 114017003,
- 76381362, 89069189, 236147128, 265370511, 228034006, 206958561,
- 152762724, 148411219, 178138378, 190596925, 472294256, 501532999,
- 530741022, 509615401, 456068012, 451764635, 413917122, 426358261,
- 305525448, 334993663, 296822438, 275991697, 356276756, 352202787,
- 381193850, 393929805, 944588512, 965684439, 1003065998, 973863097,
- 1061482044, 1049003019, 1019230802, 1023561829, 912136024, 933002607,
- 903529270, 874031361, 827834244, 815125939, 852716522, 856752605,
- 611050896, 631869351, 669987326, 640506825, 593644876, 580921211,
- 551983394, 556069653, 712553512, 733666847, 704405574, 675154545,
- 762387700, 749958851, 787859610, 792175277, 1889177024, 1901651959,
- 1931368878, 1927033753, 2006131996, 1985040171, 1947726194, 1976933189,
- 2122964088, 2135668303, 2098006038, 2093965857, 2038461604, 2017599123,
- 2047123658, 2076625661, 1824272048, 1836991623, 1866005214, 1861914857,
- 1807058540, 1786244187, 1748062722, 1777547317, 1655668488, 1668093247,
- 1630251878, 1625932113, 1705433044, 1684323811, 1713505210, 1742760333,
- 1222101792, 1226154263, 1263738702, 1251046777, 1339974652, 1310460363,
- 1281013650, 1301863845, 1187289752, 1191637167, 1161842422, 1149379777,
- 1103966788, 1074747507, 1112139306, 1133218845, 1425107024, 1429406311,
- 1467333694, 1454888457, 1408811148, 1379576507, 1350309090, 1371438805,
- 1524775400, 1528845279, 1499917702, 1487177649, 1575719220, 1546255107,
- 1584350554, 1605185389, 3778354048, 3774312887, 3803303918, 3816007129,
- 3862737756, 3892238699, 3854067506, 3833203973, 4012263992, 4007927823,
- 3970080342, 3982554209, 3895452388, 3924658387, 3953866378, 3932773565,
- 4245928176, 4241609415, 4271336606, 4283762345, 4196012076, 4225268251,
- 4187931714, 4166823541, 4076923208, 4072833919, 4035198246, 4047918865,
- 4094247316, 4123732899, 4153251322, 4132437965, 3648544096, 3636082519,
- 3673983246, 3678331705, 3732010428, 3753090955, 3723829714, 3694611429,
- 3614117080, 3601426159, 3572488374, 3576541825, 3496125444, 3516976691,
- 3555094634, 3525581405, 3311336976, 3298595879, 3336186494, 3340255305,
- 3260503756, 3281337595, 3251864226, 3222399125, 3410866088, 3398419871,
- 3368647622, 3372945905, 3427010420, 3448139075, 3485520666, 3456284973,
- 2444203584, 2423127159, 2452308526, 2481530905, 2527477404, 2539934891,
- 2502093554, 2497740997, 2679949304, 2659102159, 2620920726, 2650438049,
- 2562027300, 2574714131, 2603727690, 2599670141, 2374579504, 2353749767,
- 2383274334, 2412743529, 2323684844, 2336421851, 2298759554, 2294686645,
- 2207933576, 2186809023, 2149495014, 2178734801, 2224278612, 2236720739,
- 2266437690, 2262135309, 2850214048, 2820717207, 2858812622, 2879680249,
- 2934667388, 2938704459, 2909776914, 2897069605, 2817622296, 2788420399,
- 2759153014, 2780249921, 2700618180, 2704950259, 2742877610, 2730399645,
- 3049550800, 3020298727, 3057690558, 3078802825, 2999835404, 3004150075,
- 2974355298, 2961925461, 3151438440, 3121956959, 3092510214, 3113327665,
- 3168701108, 3172786307, 3210370778, 3197646061,
- },
- {
- 0, 3099354981, 2852767883, 313896942, 2405603159, 937357362,
- 627793884, 2648127673, 3316918511, 2097696650, 1874714724, 3607201537,
- 1255587768, 4067088605, 3772741427, 1482887254, 1343838111, 3903140090,
- 4195393300, 1118632049, 3749429448, 1741137837, 1970407491, 3452858150,
- 2511175536, 756094997, 1067759611, 2266550430, 449832999, 2725482306,
- 2965774508, 142231497, 2687676222, 412010587, 171665333, 2995192016,
- 793786473, 2548850444, 2237264098, 1038456711, 1703315409, 3711623348,
- 3482275674, 1999841343, 3940814982, 1381529571, 1089329165, 4166106984,
- 4029413537, 1217896388, 1512189994, 3802027855, 2135519222, 3354724499,
- 3577784189, 1845280792, 899665998, 2367928107, 2677414085, 657096608,
- 3137160985, 37822588, 284462994, 2823350519, 2601801789, 598228824,
- 824021174, 2309093331, 343330666, 2898962447, 3195996129, 113467524,
- 1587572946, 3860600759, 4104763481, 1276501820, 3519211397, 1769898208,
- 2076913422, 3279374443, 3406630818, 1941006535, 1627703081, 3652755532,
- 1148164341, 4241751952, 3999682686, 1457141531, 247015245, 3053797416,
- 2763059142, 470583459, 2178658330, 963106687, 735213713, 2473467892,
- 992409347, 2207944806, 2435792776, 697522413, 3024379988, 217581361,
- 508405983, 2800865210, 4271038444, 1177467017, 1419450215, 3962007554,
- 1911572667, 3377213406, 3690561584, 1665525589, 1799331996, 3548628985,
- 3241568279, 2039091058, 3831314379, 1558270126, 1314193216, 4142438437,
- 2928380019, 372764438, 75645176, 3158189981, 568925988, 2572515393,
- 2346768303, 861712586, 3982079547, 1441124702, 1196457648, 4293663189,
- 1648042348, 3666298377, 3358779879, 1888390786, 686661332, 2421291441,
- 2196002399, 978858298, 2811169155, 523464422, 226935048, 3040519789,
- 3175145892, 100435649, 390670639, 2952089162, 841119475, 2325614998,
- 2553003640, 546822429, 2029308235, 3225988654, 3539796416, 1782671013,
- 4153826844, 1328167289, 1570739863, 3844338162, 1298864389, 4124540512,
- 3882013070, 1608431339, 3255406162, 2058742071, 1744848601, 3501990332,
- 2296328682, 811816591, 584513889, 2590678532, 129869501, 3204563416,
- 2914283062, 352848211, 494030490, 2781751807, 3078325777, 264757620,
- 2450577869, 715964072, 941166918, 2158327331, 3636881013, 1618608400,
- 1926213374, 3396585883, 1470427426, 4011365959, 4255988137, 1158766284,
- 1984818694, 3471935843, 3695453837, 1693991400, 4180638033, 1100160564,
- 1395044826, 3952793279, 3019491049, 189112716, 435162722, 2706139399,
- 1016811966, 2217162459, 2526189877, 774831696, 643086745, 2666061564,
- 2354934034, 887166583, 2838900430, 294275499, 54519365, 3145957664,
- 3823145334, 1532818963, 1240029693, 4048895640, 1820460577, 3560857924,
- 3331051178, 2117577167, 3598663992, 1858283101, 2088143283, 3301633750,
- 1495127663, 3785470218, 4078182116, 1269332353, 332098007, 2876706482,
- 3116540252, 25085497, 2628386432, 605395429, 916469259, 2384220526,
- 2254837415, 1054503362, 745528876, 2496903497, 151290352, 2981684885,
- 2735556987, 464596510, 1137851976, 4218313005, 3923506883, 1365741990,
- 3434129695, 1946996346, 1723425172, 3724871409,
- },
- {
- 0, 1029712304, 2059424608, 1201699536, 4118849216, 3370159984,
- 2403399072, 2988497936, 812665793, 219177585, 1253054625, 2010132753,
- 3320900865, 4170237105, 3207642721, 2186319825, 1625331586, 1568718386,
- 438355170, 658566482, 2506109250, 2818578674, 4020265506, 3535817618,
- 1351670851, 1844508147, 709922595, 389064339, 2769320579, 2557498163,
- 3754961379, 3803185235, 3250663172, 4238411444, 3137436772, 2254525908,
- 876710340, 153198708, 1317132964, 1944187668, 4054934725, 3436268917,
- 2339452837, 3054575125, 70369797, 961670069, 2129760613, 1133623509,
- 2703341702, 2621542710, 3689016294, 3867263574, 1419845190, 1774270454,
- 778128678, 318858390, 2438067015, 2888948471, 3952189479, 3606153623,
- 1691440519, 1504803895, 504432359, 594620247, 1492342857, 1704161785,
- 573770537, 525542041, 2910060169, 2417219385, 3618876905, 3939730521,
- 1753420680, 1440954936, 306397416, 790849880, 2634265928, 2690882808,
- 3888375336, 3668168600, 940822475, 91481723, 1121164459, 2142483739,
- 3448989963, 4042473659, 3075684971, 2318603227, 140739594, 889433530,
- 1923340138, 1338244826, 4259521226, 3229813626, 2267247018, 3124975642,
- 2570221389, 2756861693, 3824297005, 3734113693, 1823658381, 1372780605,
- 376603373, 722643805, 2839690380, 2485261628, 3548540908, 4007806556,
- 1556257356, 1638052860, 637716780, 459464860, 4191346895, 3300051327,
- 2199040943, 3195181599, 206718479, 825388991, 1989285231, 1274166495,
- 3382881038, 4106388158, 3009607790, 2382549470, 1008864718, 21111934,
- 1189240494, 2072147742, 2984685714, 2357631266, 3408323570, 4131834434,
- 1147541074, 2030452706, 1051084082, 63335554, 2174155603, 3170292451,
- 4216760371, 3325460867, 1947622803, 1232499747, 248909555, 867575619,
- 3506841360, 3966111392, 2881909872, 2527485376, 612794832, 434546784,
- 1581699760, 1663499008, 3782634705, 3692447073, 2612412337, 2799048193,
- 351717905, 697754529, 1849071985, 1398190273, 1881644950, 1296545318,
- 182963446, 931652934, 2242328918, 3100053734, 4284967478, 3255255942,
- 1079497815, 2100821479, 983009079, 133672583, 3050795671, 2293717799,
- 3474399735, 4067887175, 281479188, 765927844, 1778867060, 1466397380,
- 3846680276, 3626469220, 2676489652, 2733102084, 548881365, 500656741,
- 1517752501, 1729575173, 3577210133, 3898068133, 2952246901, 2459410373,
- 3910527195, 3564487019, 2480257979, 2931134987, 479546907, 569730987,
- 1716854139, 1530213579, 3647316762, 3825568426, 2745561210, 2663766474,
- 753206746, 293940330, 1445287610, 1799716618, 2314567513, 3029685993,
- 4080348217, 3461678473, 2088098201, 1091956777, 112560889, 1003856713,
- 3112514712, 2229607720, 3276105720, 4263857736, 1275433560, 1902492648,
- 918929720, 195422344, 685033439, 364179055, 1377080511, 1869921551,
- 3713294623, 3761522863, 2811507327, 2599689167, 413436958, 633644462,
- 1650777982, 1594160846, 3978570462, 3494118254, 2548332990, 2860797966,
- 1211387997, 1968470509, 854852413, 261368461, 3182753437, 2161434413,
- 3346310653, 4195650637, 2017729436, 1160000044, 42223868, 1071931724,
- 2378480988, 2963576044, 4144295484, 3395602316,
- },
- {
- 0, 3411858341, 1304994059, 2257875630, 2609988118, 1355649459,
- 3596215069, 486879416, 3964895853, 655315400, 2711298918, 1791488195,
- 2009251963, 3164476382, 973758832, 4048990933, 64357019, 3364540734,
- 1310630800, 2235723829, 2554806413, 1394316072, 3582976390, 517157411,
- 4018503926, 618222419, 2722963965, 1762783832, 1947517664, 3209171269,
- 970744811, 4068520014, 128714038, 3438335635, 1248109629, 2167961496,
- 2621261600, 1466012805, 3522553387, 447296910, 3959392091, 547575038,
- 2788632144, 1835791861, 1886307661, 3140622056, 1034314822, 4143626211,
- 75106221, 3475428360, 1236444838, 2196665603, 2682996155, 1421317662,
- 3525567664, 427767573, 3895035328, 594892389, 2782995659, 1857943406,
- 1941489622, 3101955187, 1047553757, 4113347960, 257428076, 3288652233,
- 1116777319, 2311878850, 2496219258, 1603640287, 3640781169, 308099796,
- 3809183745, 676813732, 2932025610, 1704983215, 2023410199, 3016104370,
- 894593820, 4262377657, 210634999, 3352484690, 1095150076, 2316991065,
- 2535410401, 1547934020, 3671583722, 294336591, 3772615322, 729897279,
- 2903845777, 1716123700, 2068629644, 2953845545, 914647431, 4258839074,
- 150212442, 3282623743, 1161604689, 2388688372, 2472889676, 1480171241,
- 3735940167, 368132066, 3836185911, 805002898, 2842635324, 1647574937,
- 2134298401, 3026852996, 855535146, 4188192143, 186781121, 3229539940,
- 1189784778, 2377547631, 2427670487, 1542429810, 3715886812, 371670393,
- 3882979244, 741170185, 2864262823, 1642462466, 2095107514, 3082559007,
- 824732849, 4201955092, 514856152, 3589064573, 1400419795, 2552522358,
- 2233554638, 1316849003, 3370776517, 62202976, 4075001525, 968836368,
- 3207280574, 1954014235, 1769133219, 2720925446, 616199592, 4024870413,
- 493229635, 3594175974, 1353627464, 2616354029, 2264355925, 1303087088,
- 3409966430, 6498043, 4046820398, 979978123, 3170710821, 2007099008,
- 1789187640, 2717386141, 661419827, 3962610838, 421269998, 3527459403,
- 1423225061, 2676515648, 2190300152, 1238466653, 3477467891, 68755798,
- 4115633027, 1041448998, 3095868040, 1943789869, 1860096405, 2776760880,
- 588673182, 3897205563, 449450869, 3516317904, 1459794558, 2623431131,
- 2170245475, 1242006214, 3432247400, 131015629, 4137259288, 1036337853,
- 3142660115, 1879958454, 1829294862, 2790523051, 549483013, 3952910752,
- 300424884, 3669282065, 1545650111, 2541513754, 2323209378, 1092980487,
- 3350330793, 216870412, 4256931033, 921128828, 2960342482, 2066738807,
- 1714085583, 2910195050, 736264132, 3770592353, 306060335, 3647131530,
- 1610005796, 2494197377, 2309971513, 1123257756, 3295149874, 255536279,
- 4268596802, 892423655, 3013951305, 2029645036, 1711070292, 2929725425,
- 674528607, 3815288570, 373562242, 3709388839, 1535949449, 2429577516,
- 2379569556, 1183418929, 3223189663, 188820282, 4195850735, 827017802,
- 3084859620, 2089020225, 1636228089, 2866415708, 743340786, 3876759895,
- 361896217, 3738094268, 1482340370, 2466671543, 2382584591, 1163888810,
- 3284924932, 144124321, 4190215028, 849168593, 3020503679, 2136336858,
- 1649465698, 2836138695, 798521449, 3838094284,
- },
- {
- 0, 2792819636, 2543784233, 837294749, 4098827283, 1379413927,
- 1674589498, 3316072078, 871321191, 2509784531, 2758827854, 34034938,
- 3349178996, 1641505216, 1346337629, 4131942633, 1742642382, 3249117050,
- 4030828007, 1446413907, 2475800797, 904311657, 68069876, 2725880384,
- 1412551337, 4064729373, 3283010432, 1708771380, 2692675258, 101317902,
- 937551763, 2442587175, 3485284764, 1774858792, 1478633653, 4266992385,
- 1005723023, 2642744891, 2892827814, 169477906, 4233263099, 1512406095,
- 1808623314, 3451546982, 136139752, 2926205020, 2676114113, 972376437,
- 2825102674, 236236518, 1073525883, 2576072655, 1546420545, 4200303349,
- 3417542760, 1841601500, 2609703733, 1039917185, 202635804, 2858742184,
- 1875103526, 3384067218, 4166835727, 1579931067, 1141601657, 3799809741,
- 3549717584, 1977839588, 2957267306, 372464350, 668680259, 2175552503,
- 2011446046, 3516084394, 3766168119, 1175200131, 2209029901, 635180217,
- 338955812, 2990736784, 601221559, 2242044419, 3024812190, 306049834,
- 3617246628, 1911408144, 1074125965, 3866285881, 272279504, 3058543716,
- 2275784441, 567459149, 3832906691, 1107462263, 1944752874, 3583875422,
- 2343980261, 767641425, 472473036, 3126744696, 2147051766, 3649987394,
- 3899029983, 1309766251, 3092841090, 506333494, 801510315, 2310084639,
- 1276520081, 3932237093, 3683203000, 2113813516, 3966292011, 1243601823,
- 2079834370, 3716205238, 405271608, 3192979340, 2411259153, 701492901,
- 3750207052, 2045810168, 1209569125, 4000285905, 734575199, 2378150379,
- 3159862134, 438345922, 2283203314, 778166598, 529136603, 3120492655,
- 2086260449, 3660498261, 3955679176, 1303499900, 3153699989, 495890209,
- 744928700, 2316418568, 1337360518, 3921775410, 3626602927, 2120129051,
- 4022892092, 1237286280, 2018993941, 3726666913, 461853231, 3186645403,
- 2350400262, 711936178, 3693557851, 2052076527, 1270360434, 3989775046,
- 677911624, 2384402428, 3220639073, 427820757, 1202443118, 3789347034,
- 3493118535, 1984154099, 3018127229, 362020041, 612099668, 2181885408,
- 1950653705, 3526596285, 3822816288, 1168934804, 2148251930, 645706414,
- 395618355, 2984485767, 544559008, 2248295444, 3085590153, 295523645,
- 3560598451, 1917673479, 1134918298, 3855773998, 328860103, 3052210803,
- 2214924526, 577903450, 3889505748, 1101147744, 1883911421, 3594338121,
- 3424493451, 1785369663, 1535282850, 4260726038, 944946072, 2653270060,
- 2949491377, 163225861, 4294103532, 1501944408, 1752023237, 3457862513,
- 196998655, 2915761739, 2619532502, 978710370, 2881684293, 229902577,
- 1012666988, 2586515928, 1603020630, 4193987810, 3356702335, 1852063179,
- 2553040162, 1046169238, 263412747, 2848217023, 1818454321, 3390333573,
- 4227627032, 1569420204, 60859927, 2782375331, 2487203646, 843627658,
- 4159668740, 1368951216, 1617990445, 3322386585, 810543216, 2520310724,
- 2815490393, 27783917, 3288386659, 1652017111, 1402985802, 4125677310,
- 1685994201, 3255382381, 4091620336, 1435902020, 2419138250, 910562686,
- 128847843, 2715354199, 1469150398, 4058414858, 3222168983, 1719234083,
- 2749255853, 94984985, 876691844, 2453031472,
- },
- {
- 0, 3433693342, 1109723005, 2391738339, 2219446010, 1222643300,
- 3329165703, 180685081, 3555007413, 525277995, 2445286600, 1567235158,
- 1471092047, 2600801745, 361370162, 3642757804, 2092642603, 2953916853,
- 1050555990, 4063508168, 4176560081, 878395215, 3134470316, 1987983410,
- 2942184094, 1676945920, 3984272867, 567356797, 722740324, 3887998202,
- 1764827929, 2778407815, 4185285206, 903635656, 3142804779, 2012833205,
- 2101111980, 2979425330, 1058630609, 4088621903, 714308067, 3862526333,
- 1756790430, 2753330688, 2933487385, 1651734407, 3975966820, 542535930,
- 2244825981, 1231508451, 3353891840, 188896414, 25648519, 3442302233,
- 1134713594, 2399689316, 1445480648, 2592229462, 336416693, 3634843435,
- 3529655858, 516441772, 2420588879, 1559052753, 698204909, 3845636723,
- 1807271312, 2803025166, 2916600855, 1635634313, 4025666410, 593021940,
- 4202223960, 919787974, 3093159461, 1962401467, 2117261218, 2996361020,
- 1008193759, 4038971457, 1428616134, 2576151384, 386135227, 3685348389,
- 3513580860, 499580322, 2471098945, 1608776415, 2260985971, 1248454893,
- 3303468814, 139259792, 42591881, 3458459159, 1085071860, 2349261162,
- 3505103035, 474062885, 2463016902, 1583654744, 1419882049, 2550902495,
- 377792828, 3660491170, 51297038, 3483679632, 1093385331, 2374089965,
- 2269427188, 1273935210, 3311514249, 164344343, 2890961296, 1627033870,
- 4000683757, 585078387, 672833386, 3836780532, 1782552599, 2794821769,
- 2142603813, 3005188795, 1032883544, 4047146438, 4227826911, 928351297,
- 3118105506, 1970307900, 1396409818, 2677114180, 287212199, 3719594553,
- 3614542624, 467372990, 2505346141, 1509854403, 2162073199, 1282711281,
- 3271268626, 240228748, 76845205, 3359543307, 1186043880, 2317064054,
- 796964081, 3811226735, 1839575948, 2702160658, 2882189835, 1734392469,
- 3924802934, 625327592, 4234522436, 818917338, 3191908409, 1927981223,
- 2016387518, 3028656416, 973776579, 4137723485, 2857232268, 1726474002,
- 3899187441, 616751215, 772270454, 3803048424, 1814228491, 2693328533,
- 2041117753, 3036871847, 999160644, 4146592730, 4259508931, 826864221,
- 3217552830, 1936586016, 3606501031, 442291769, 2496909786, 1484378436,
- 1388107869, 2652297411, 278519584, 3694387134, 85183762, 3384397196,
- 1194773103, 2342308593, 2170143720, 1307820918, 3279733909, 265733131,
- 2057717559, 3054258089, 948125770, 4096344276, 4276898253, 843467091,
- 3167309488, 1885556270, 2839764098, 1709792284, 3949353983, 667704161,
- 755585656, 3785577190, 1865176325, 2743489947, 102594076, 3401021058,
- 1144549729, 2291298815, 2186770662, 1325234296, 3228729243, 215514885,
- 3589828009, 424832311, 2547870420, 1534552650, 1370645331, 2635621325,
- 328688686, 3745342640, 2211456353, 1333405183, 3254067740, 224338562,
- 127544219, 3408931589, 1170156774, 2299866232, 1345666772, 2627681866,
- 303053225, 3736746295, 3565105198, 416624816, 2522494803, 1525692365,
- 4285207626, 868291796, 3176010551, 1910772649, 2065767088, 3079346734,
- 956571085, 4121828691, 747507711, 3760459617, 1856702594, 2717976604,
- 2831417605, 1684930971, 3940615800, 642451174,
- },
- {
- 0, 393942083, 787884166, 965557445, 1575768332, 1251427663,
- 1931114890, 1684106697, 3151536664, 2896410203, 2502855326, 2186649309,
- 3862229780, 4048545623, 3368213394, 3753496529, 2898281073, 3149616690,
- 2184604407, 2504883892, 4046197629, 3864463166, 3755621371, 3366006712,
- 387506281, 6550570, 971950319, 781573292, 1257550181, 1569695014,
- 1677892067, 1937345952, 2196865699, 2508887776, 2886183461, 3145514598,
- 3743273903, 3362179052, 4058774313, 3868258154, 958996667, 777139448,
- 400492605, 10755198, 1690661303, 1941857780, 1244879153, 1565019506,
- 775012562, 961205393, 13101140, 398261271, 1943900638, 1688634781,
- 1563146584, 1246801179, 2515100362, 2190636681, 3139390028, 2892258831,
- 3355784134, 3749586821, 3874691904, 4052225795, 3734110983, 3387496260,
- 4033096577, 3877584834, 2206093835, 2483373640, 2911402637, 3136515790,
- 1699389727, 1915860316, 1270647193, 1556585946, 950464531, 803071056,
- 374397077, 19647702, 1917993334, 1697207605, 1554278896, 1272937907,
- 800985210, 952435769, 21510396, 372452543, 3381322606, 3740399405,
- 3883715560, 4027047851, 2489758306, 2199758369, 3130039012, 2917895847,
- 1550025124, 1259902439, 1922410786, 1710144865, 26202280, 385139947,
- 796522542, 939715693, 3887801276, 4039129087, 3377269562, 3728088953,
- 3126293168, 2905368307, 2493602358, 2212122229, 4037264341, 3889747862,
- 3730172755, 3375300368, 2907673305, 3124004506, 2209987167, 2495786524,
- 1266377165, 1543533966, 1703758155, 1928748296, 379007169, 32253058,
- 945887303, 790236164, 1716846671, 1898845196, 1218652361, 1608006794,
- 1002000707, 750929152, 357530053, 36990342, 3717046871, 3405166100,
- 4084959953, 3825245842, 2153902939, 2535122712, 2929187805, 3119304606,
- 3398779454, 3723384445, 3831720632, 4078468859, 2541294386, 2147616625,
- 3113171892, 2935238647, 1900929062, 1714877541, 1606142112, 1220599011,
- 748794154, 1004184937, 39295404, 355241455, 3835986668, 4091516591,
- 3394415210, 3710500393, 3108557792, 2922629027, 2545875814, 2160455461,
- 1601970420, 1208431799, 1904871538, 1727077425, 43020792, 367748539,
- 744905086, 991776061, 1214562461, 1595921630, 1720903707, 1911159896,
- 361271697, 49513938, 998160663, 738569556, 4089209477, 3838277318,
- 3712633347, 3392233024, 2924491657, 3106613194, 2158369551, 2547846988,
- 3100050248, 2948339467, 2519804878, 2169126797, 3844821572, 4065347079,
- 3420289730, 3701894785, 52404560, 342144275, 770279894, 982687125,
- 1593045084, 1233708063, 1879431386, 1736363161, 336019769, 58479994,
- 988899775, 764050940, 1240141877, 1586496630, 1729968307, 1885744368,
- 2950685473, 3097818978, 2166999975, 2522013668, 4063474221, 3846743662,
- 3703937707, 3418263272, 976650731, 760059304, 348170605, 62635310,
- 1742393575, 1889649828, 1227683937, 1582820386, 2179867635, 2526361520,
- 2937588597, 3093503798, 3691148031, 3413731004, 4076100217, 3851374138,
- 2532754330, 2173556697, 3087067932, 2944139103, 3407516310, 3697379029,
- 3857496592, 4070026835, 758014338, 978679233, 64506116, 346250567,
- 1891774606, 1740186829, 1580472328, 1229917259,
- },
- {
- 0, 4022496062, 83218493, 3946298115, 166436986, 3861498692,
- 220098631, 3806075769, 332873972, 4229245898, 388141257, 4175494135,
- 440197262, 4127099824, 516501683, 4044053389, 665747944, 3362581206,
- 593187285, 3432594155, 776282514, 3246869164, 716239279, 3312622225,
- 880394524, 3686509090, 814485793, 3746462239, 1033003366, 3528460888,
- 963096923, 3601193573, 1331495888, 2694801646, 1269355501, 2758457555,
- 1186374570, 2843003028, 1111716759, 2910918825, 1552565028, 3007850522,
- 1484755737, 3082680359, 1432478558, 3131279456, 1368666979, 3193329757,
- 1760789048, 2268195078, 1812353541, 2210675003, 1628971586, 2396670332,
- 1710092927, 2318375233, 2066006732, 2498144754, 2144408305, 2417195471,
- 1926193846, 2634877320, 1983558283, 2583222709, 2662991776, 1903717534,
- 2588923805, 1972223139, 2538711002, 2022952164, 2477029351, 2087066841,
- 2372749140, 1655647338, 2308478825, 1717238871, 2223433518, 1799654416,
- 2155034387, 1873894445, 3105130056, 1456926070, 3185661557, 1378041163,
- 2969511474, 1597852940, 3020617231, 1539874097, 2864957116, 1157737858,
- 2922780289, 1106542015, 2737333958, 1290407416, 2816325371, 1210047941,
- 3521578096, 1042640718, 3574781005, 986759027, 3624707082, 936300340,
- 3707335735, 859512585, 3257943172, 770846650, 3334837433, 688390023,
- 3420185854, 605654976, 3475911875, 552361981, 4132013464, 428600998,
- 4072428965, 494812827, 4288816610, 274747100, 4216845791, 345349857,
- 3852387692, 173846098, 3781891409, 245988975, 3967116566, 62328360,
- 3900749099, 121822741, 3859089665, 164061759, 3807435068, 221426178,
- 4025395579, 2933317, 3944446278, 81334904, 4124199413, 437265099,
- 4045904328, 518386422, 4231653775, 335250097, 4174133682, 386814604,
- 3249244393, 778691543, 3311294676, 714879978, 3359647891, 662848429,
- 3434477742, 595039120, 3531393053, 1035903779, 3599308832, 961245982,
- 3684132967, 877986649, 3747788890, 815846244, 2841119441, 1184522735,
- 2913852140, 1114616274, 2696129195, 1332855189, 2756082326, 1266946472,
- 3129952805, 1431118107, 3195705880, 1371074854, 3009735263, 1554415969,
- 3079748194, 1481855324, 2398522169, 1630855175, 2315475716, 1707159610,
- 2266835779, 1759461501, 2213084030, 1814728768, 2636237773, 1927520499,
- 2580814832, 1981182158, 2496293815, 2064121993, 2420095882, 2147340468,
- 2025787041, 2541577631, 2085281436, 2475210146, 1901375195, 2660681189,
- 1973518054, 2590184920, 1801997909, 2225743211, 1872600680, 2153772374,
- 1652813359, 2369881361, 1719025170, 2310296876, 1594986313, 2966676599,
- 1541693300, 3022402634, 1459236659, 3107472397, 1376780046, 3184366640,
- 1288097725, 2734990467, 1211309952, 2817619134, 1160605639, 2867791097,
- 1104723962, 2920993988, 937561457, 3626001999, 857201996, 3704993394,
- 1040821515, 3519792693, 989625654, 3577615880, 607473029, 3421972155,
- 549494200, 3473077894, 769584639, 3256649409, 690699714, 3337180924,
- 273452185, 4287555495, 347692196, 4219156378, 430386403, 4133832669,
- 491977950, 4069562336, 60542061, 3965298515, 124656720, 3903616878,
- 175139863, 3853649705, 243645482, 3779581716,
- },
- {
- 0, 3247366080, 1483520449, 2581751297, 2967040898, 1901571138,
- 3904227907, 691737987, 3133399365, 2068659845, 3803142276, 589399876,
- 169513671, 3415493895, 1383475974, 2482566342, 2935407819, 1870142219,
- 4137319690, 924099274, 506443593, 3751897225, 1178799752, 2278412616,
- 339027342, 3585866318, 1280941135, 2379694991, 2766951948, 1700956620,
- 4236308429, 1024339981, 2258407383, 1192382487, 3740284438, 528411094,
- 910556245, 4157285269, 1848198548, 2946996820, 1012887186, 4258378066,
- 1681119059, 2780629139, 2357599504, 1292419792, 3572147409, 358906641,
- 678054684, 3924071644, 1879503581, 2978491677, 2561882270, 1497229150,
- 3235873119, 22109855, 2460592729, 1395094937, 3401913240, 189516888,
- 577821147, 3825075739, 2048679962, 3146956762, 3595049455, 398902831,
- 2384764974, 1336573934, 1720805997, 2803873197, 1056822188, 4285729900,
- 1821112490, 2902796138, 887570795, 4117339819, 3696397096, 500978920,
- 2218668777, 1169222953, 2025774372, 3106931428, 550659301, 3780950821,
- 3362238118, 166293862, 2416645991, 1367722151, 3262987361, 66315169,
- 2584839584, 1537170016, 1923370979, 3005911075, 717813282, 3947244002,
- 1356109368, 2438613496, 146288633, 3375820857, 3759007162, 562248314,
- 3093388411, 2045739963, 3927406461, 731490493, 2994458300, 1945440636,
- 1523451135, 2604718911, 44219710, 3274466046, 4263662323, 1068272947,
- 2790189874, 1740649714, 1325080945, 2406874801, 379033776, 3608758128,
- 1155642294, 2238671990, 479005303, 3708016055, 4097359924, 901128180,
- 2891217397, 1843045941, 2011248031, 3060787807, 797805662, 3993195422,
- 3342353949, 112630237, 2673147868, 1591353372, 3441611994, 212601626,
- 2504944923, 1421914843, 2113644376, 3161815192, 630660761, 3826893145,
- 3642224980, 412692116, 2172340373, 1089836885, 1775141590, 2822790422,
- 832715543, 4029474007, 1674842129, 2723860433, 1001957840, 4197873168,
- 3540870035, 310623315, 2338445906, 1257178514, 4051548744, 821257608,
- 2836464521, 1755307081, 1101318602, 2150241802, 432566283, 3628511179,
- 1270766349, 2318435533, 332587724, 3529260300, 4217841807, 988411727,
- 2735444302, 1652903566, 1602977411, 2651169091, 132630338, 3328776322,
- 4015131905, 786223809, 3074340032, 1991273216, 3846741958, 616972294,
- 3173262855, 2091579847, 1435626564, 2485072772, 234706309, 3430124101,
- 2712218736, 1613231024, 4190475697, 944458353, 292577266, 3506339890,
- 1226630707, 2291284467, 459984181, 3672380149, 1124496628, 2189994804,
- 2880683703, 1782407543, 4091479926, 844224694, 257943739, 3469817723,
- 1462980986, 2529005242, 3213269817, 2114471161, 3890881272, 644152632,
- 3046902270, 1947391550, 3991973951, 746483711, 88439420, 3301680572,
- 1563018173, 2628197501, 657826727, 3871046759, 2136545894, 3201811878,
- 2548879397, 1449267173, 3481299428, 235845156, 2650161890, 1551408418,
- 3315268387, 68429027, 758067552, 3970035360, 1967360161, 3033356129,
- 2311284588, 1213053100, 3517963949, 270598509, 958010606, 4170500910,
- 1635167535, 2700636911, 855672361, 4069415401, 1802256360, 2866995240,
- 2212099499, 1113008747, 3686091882, 440112042,
- },
- {
- 0, 2611301487, 3963330207, 2006897392, 50740095, 2560849680,
- 4013794784, 1956178319, 101480190, 2645113489, 3929532513, 1905435662,
- 84561281, 2662269422, 3912356638, 1922342769, 202960380, 2545787283,
- 3760419683, 2072395532, 253679235, 2495322860, 3810871324, 2021655667,
- 169122562, 2444351341, 3861841309, 2106214898, 152215677, 2461527058,
- 3844685538, 2123133581, 405920760, 2207553431, 4094313831, 1873742088,
- 456646791, 2157096168, 4144791064, 1823027831, 507358470, 2241388905,
- 4060492697, 1772322806, 490444409, 2258557462, 4043311334, 1789215881,
- 338245124, 2408348267, 4161972379, 1672996084, 388959611, 2357870868,
- 4212429796, 1622269835, 304431354, 2306870421, 4263435877, 1706791434,
- 287538053, 2324051946, 4246267162, 1723705717, 811841520, 2881944479,
- 3696765295, 1207788800, 862293135, 2831204576, 3747484176, 1157324415,
- 913293582, 2915732833, 3662962577, 1106318334, 896137841, 2932651550,
- 3646055662, 1123494017, 1014716940, 2816349795, 3493905555, 1273334012,
- 1065181555, 2765630748, 3544645612, 1222882179, 980888818, 2714919069,
- 3595350637, 1307180546, 963712909, 2731826146, 3578431762, 1324336509,
- 676490248, 3019317351, 3295277719, 1607253752, 726947703, 2968591128,
- 3345992168, 1556776327, 777919222, 3053147801, 3261432937, 1505806342,
- 760750473, 3070062054, 3244539670, 1522987897, 608862708, 3220163995,
- 3362856811, 1406423812, 659339915, 3169449700, 3413582868, 1355966587,
- 575076106, 3118709605, 3464325525, 1440228858, 557894773, 3135602714,
- 3447411434, 1457397381, 1623683040, 4217512847, 2365387135, 391757072,
- 1673614495, 4167309552, 2415577600, 341804655, 1724586270, 4251866481,
- 2331019137, 290835438, 1707942497, 4268256782, 2314648830, 307490961,
- 1826587164, 4152020595, 2162433155, 457265388, 1876539747, 4101829900,
- 2212636668, 407333779, 1792275682, 4051089549, 2263378557, 491595282,
- 1775619997, 4067460082, 2246988034, 508239213, 2029433880, 3813931127,
- 2496473735, 258500328, 2079362919, 3763716872, 2546668024, 208559511,
- 2130363110, 3848244873, 2462145657, 157552662, 2113730969, 3864638966,
- 2445764358, 174205801, 1961777636, 4014675339, 2564147067, 57707284,
- 2011718299, 3964481268, 2614361092, 7778411, 1927425818, 3913769845,
- 2665066885, 92077546, 1910772837, 3930150922, 2648673018, 108709525,
- 1352980496, 3405878399, 3164554895, 658115296, 1403183983, 3355946752,
- 3214507504, 607924639, 1453895406, 3440239233, 3130208369, 557218846,
- 1437504913, 3456883198, 3113552654, 573589345, 1555838444, 3340335491,
- 2961681267, 723707676, 1606028947, 3290383100, 3011612684, 673504355,
- 1521500946, 3239382909, 3062619533, 758026722, 1505130605, 3256038402,
- 3045975794, 774417053, 1217725416, 3543158663, 2762906999, 1057739032,
- 1267939479, 3493229816, 2812847624, 1007544935, 1318679830, 3577493881,
- 2728586121, 956803046, 1302285929, 3594125830, 2711933174, 973184153,
- 1150152212, 3743982203, 2830528651, 856898788, 1200346475, 3694041348,
- 2880457716, 806684571, 1115789546, 3643069573, 2931426933, 891243034,
- 1099408277, 3659722746, 2914794762, 907637093,
- },
- {
- 0, 3717650821, 1616688459, 3184159950, 3233376918, 489665299,
- 2699419613, 2104690264, 1510200173, 2274691816, 979330598, 3888758691,
- 2595928571, 1194090622, 4209380528, 661706037, 3020400346, 1771143007,
- 3562738577, 164481556, 1958661196, 2837976521, 350386439, 3379863682,
- 3993269687, 865250354, 2388181244, 1406015865, 784146209, 4079732388,
- 1323412074, 2474079215, 3011398645, 1860735600, 3542286014, 246687547,
- 1942430051, 2924607718, 328963112, 3456978349, 3917322392, 887832861,
- 2300653011, 1421341782, 700772878, 4099025803, 1234716485, 2483986112,
- 125431087, 3673109674, 1730500708, 3132326369, 3351283641, 441867836,
- 2812031730, 2047535991, 1568292418, 2163009479, 1025936137, 3769651852,
- 2646824148, 1079348561, 4255113631, 537475098, 3180171691, 1612400686,
- 3721471200, 4717925, 2100624189, 2694980280, 493375094, 3237910515,
- 3884860102, 974691139, 2278750093, 1514417672, 657926224, 4204917205,
- 1198234907, 2600289438, 160053105, 3558665972, 1775665722, 3024116671,
- 3375586791, 346391650, 2842683564, 1962488105, 1401545756, 2384412057,
- 869618007, 3997403346, 2469432970, 1319524111, 4083956673, 788193860,
- 250862174, 3546612699, 1856990997, 3006903952, 3461001416, 333211981,
- 2920678787, 1937824774, 1425017139, 2305216694, 883735672, 3912918525,
- 2487837605, 1239398944, 4095071982, 696455019, 3136584836, 1734518017,
- 3668494799, 121507914, 2051872274, 2816200599, 437363545, 3347544796,
- 3774328809, 1029797484, 2158697122, 1564328743, 542033279, 4258798842,
- 1074950196, 2642717105, 2691310871, 2113731730, 3224801372, 497043929,
- 1624461185, 3175454212, 9435850, 3709412175, 4201248378, 671035391,
- 2587181873, 1201904308, 986750188, 3880142185, 1519135143, 2266689570,
- 342721485, 3388693064, 1949382278, 2846355203, 3570723163, 155332830,
- 3028835344, 1763607957, 1315852448, 2482538789, 775087595, 4087626862,
- 2396469814, 1396827059, 4002123645, 857560824, 320106210, 3464673127,
- 1934154665, 2933785132, 3551331444, 238804465, 3018961215, 1852270778,
- 1226292623, 2491507722, 692783300, 4108177729, 2309936921, 1412959900,
- 3924976210, 879016919, 2803091512, 2055541181, 3343875443, 450471158,
- 1739236014, 3124525867, 133568485, 3663777376, 4245691221, 545702608,
- 2639048222, 1088059291, 1034514883, 3762268230, 1576387720, 2153979149,
- 501724348, 3228659001, 2109407735, 2687359090, 3713981994, 13109167,
- 3171052385, 1620357860, 1206151121, 2591211092, 666423962, 4197321503,
- 2271022407, 1523307714, 3875649548, 982999433, 2850034278, 1953942499,
- 3384583981, 338329256, 1767471344, 3033506165, 151375291, 3566408766,
- 4091789579, 779425934, 2478797888, 1311354309, 861580189, 4006375960,
- 1392910038, 2391852883, 2929327945, 1930372812, 3469036034, 324244359,
- 1847629279, 3015068762, 243015828, 3555391761, 4103744548, 688715169,
- 2496043375, 1229996266, 874727090, 3920994103, 1417671673, 2313759356,
- 446585235, 3339223062, 2059594968, 2807313757, 3660002053, 129100416,
- 3128657486, 1743609803, 1084066558, 2634765179, 549535669, 4250396208,
- 2149900392, 1571961325, 3765982499, 1039043750,
- },
- {
- 0, 2635063670, 3782132909, 2086741467, 430739227, 2225303149,
- 4173482934, 1707977408, 861478454, 2924937024, 3526875803, 1329085421,
- 720736557, 3086643291, 3415954816, 1452586230, 1722956908, 4223524122,
- 2279405761, 450042295, 2132718455, 3792785921, 2658170842, 58693292,
- 1441473114, 3370435372, 3028674295, 696911745, 1279765825, 3511176247,
- 2905172460, 807831706, 3445913816, 1349228974, 738901109, 2969918723,
- 3569940419, 1237784245, 900084590, 2829701656, 4265436910, 1664255896,
- 525574723, 2187084597, 3885099509, 2057177219, 117386584, 2616249390,
- 2882946228, 920233410, 1253605401, 3619119471, 2994391983, 796207833,
- 1393823490, 3457937012, 2559531650, 92322804, 2044829231, 3840835417,
- 2166609305, 472659183, 1615663412, 4249022530, 1102706673, 3702920839,
- 2698457948, 1037619754, 1477802218, 3306854812, 3111894087, 611605809,
- 1927342535, 4025419953, 2475568490, 243387420, 1800169180, 4131620778,
- 2317525617, 388842247, 655084445, 3120835307, 3328511792, 1533734470,
- 1051149446, 2745738736, 3754524715, 1120297309, 340972971, 2304586973,
- 4114354438, 1748234352, 234773168, 2431761350, 3968900637, 1906278251,
- 2363330345, 299003487, 1840466820, 4038896370, 2507210802, 142532932,
- 1948239007, 3910149609, 3213136159, 579563625, 1592415666, 3286611140,
- 2787646980, 992477042, 1195825833, 3662232543, 3933188933, 2002801203,
- 184645608, 2517538462, 4089658462, 1858919720, 313391347, 2409765253,
- 3644239219, 1144605701, 945318366, 2773977256, 3231326824, 1570095902,
- 569697989, 3170568115, 2205413346, 511446676, 1646078799, 4279421497,
- 2598330617, 131105167, 2075239508, 3871229218, 2955604436, 757403810,
- 1363424633, 3427521551, 2844163791, 881434553, 1223211618, 3588709140,
- 3854685070, 2026779384, 78583587, 2577462869, 4235025557, 1633861091,
- 486774840, 2148301134, 3600338360, 1268198606, 938871061, 2868504675,
- 3476308643, 1379640277, 777684494, 3008718712, 1310168890, 3541595724,
- 2943964055, 846639841, 1471879201, 3400857943, 3067468940, 735723002,
- 2102298892, 3762382970, 2619362721, 19901655, 1692534295, 4193118049,
- 2240594618, 411247564, 681945942, 3047836192, 3385552891, 1422167693,
- 822682701, 2886124859, 3496468704, 1298661782, 469546336, 2264093718,
- 4203901389, 1738379451, 38812283, 2673859341, 3812556502, 2117148576,
- 3268024339, 1606809957, 598006974, 3198893512, 3680933640, 1181316734,
- 973624229, 2802299603, 4052944421, 1822222163, 285065864, 2381456382,
- 3896478014, 1966106696, 156323219, 2489232613, 2759337087, 964150537,
- 1159127250, 3625517476, 3184831332, 551242258, 1555722185, 3249901247,
- 2535537225, 170842943, 1984954084, 3946848146, 2391651666, 327308324,
- 1877176831, 4075589769, 263086283, 2460058045, 4005602406, 1942963472,
- 369291216, 2332888742, 4151061373, 1784924683, 1022852861, 2717425547,
- 3717839440, 1083595558, 626782694, 3092517008, 3291821387, 1497027645,
- 1763466407, 4094934481, 2289211402, 360544636, 1890636732, 3988730570,
- 2447251217, 215086695, 1514488465, 3343557607, 3140191804, 639919946,
- 1139395978, 3739626748, 2726758695, 1065936977,
- },
- {
- 0, 3120290792, 2827399569, 293431929, 2323408227, 864534155,
- 586863858, 2600537882, 3481914503, 1987188591, 1729068310, 3740575486,
- 1173727716, 4228805132, 3983743093, 1418249117, 1147313999, 4254680231,
- 3974377182, 1428157750, 3458136620, 2011505092, 1721256893, 3747844181,
- 2347455432, 839944224, 594403929, 2593536433, 26687147, 3094146371,
- 2836498234, 283794642, 2294627998, 826205558, 541298447, 2578994407,
- 45702141, 3141697557, 2856315500, 331624836, 1196225049, 4273416689,
- 4023010184, 1446090848, 3442513786, 1959480466, 1706436331, 3696098563,
- 3433538001, 1968994873, 1679888448, 3722103720, 1188807858, 4280295258,
- 3999102243, 1470541515, 53374294, 3134568126, 2879970503, 307431215,
- 2303854645, 816436189, 567589284, 2553242188, 3405478781, 1929420949,
- 1652411116, 3682996484, 1082596894, 4185703926, 3892424591, 1375368295,
- 91404282, 3163122706, 2918450795, 336584067, 2400113305, 922028401,
- 663249672, 2658384096, 2392450098, 929185754, 639587747, 2682555979,
- 82149713, 3172883129, 2892181696, 362343208, 1091578037, 4176212829,
- 3918960932, 1349337804, 3412872662, 1922537022, 1676344391, 3658557359,
- 1111377379, 4224032267, 3937989746, 1396912026, 3359776896, 1908013928,
- 1623494929, 3644803833, 2377615716, 877417100, 623982837, 2630542109,
- 130804743, 3190831087, 2941083030, 381060734, 106748588, 3215393092,
- 2933549885, 388083925, 2350956495, 903570471, 614862430, 2640172470,
- 3386185259, 1882115523, 1632872378, 3634920530, 1135178568, 4199721120,
- 3945775833, 1389631793, 1317531835, 4152109907, 3858841898, 1610259138,
- 3304822232, 2097172016, 1820140617, 3582394273, 2165193788, 955639764,
- 696815021, 2423477829, 192043359, 2995356343, 2750736590, 437203750,
- 182808564, 3005133852, 2724453989, 462947725, 2157513367, 962777471,
- 673168134, 2447663342, 3312231283, 2090301595, 1844056802, 3557935370,
- 1326499344, 4142603768, 3885397889, 1584245865, 3326266917, 2142836173,
- 1858371508, 3611272284, 1279175494, 4123357358, 3837270743, 1564721471,
- 164299426, 2955991370, 2706223923, 414607579, 2209834945, 978107433,
- 724686416, 2462715320, 2183156074, 1004243586, 715579643, 2472360723,
- 140260361, 2980573153, 2698675608, 421617264, 1302961645, 4099032581,
- 3845074044, 1557460884, 3352688782, 2116952934, 1867729183, 3601371895,
- 2222754758, 1032278062, 754596439, 2499928511, 234942117, 3086693709,
- 2793824052, 528319708, 1274365761, 4061043881, 3816027856, 1518873912,
- 3246989858, 2020800970, 1762628531, 3505670235, 3223196809, 2045103969,
- 1754834200, 3512958704, 1247965674, 4086934018, 3806642299, 1528765331,
- 261609486, 3060532198, 2802936223, 518697591, 2246819181, 1007707781,
- 762121468, 2492913428, 213497176, 3041029808, 2755593417, 499441441,
- 2261110843, 1061030867, 776167850, 2545465922, 3274734047, 2060165687,
- 1807140942, 3528266662, 1229724860, 4038575956, 3788156205, 1479636677,
- 1222322711, 4045468159, 3764231046, 1504067694, 3265744756, 2069664924,
- 1780612837, 3554288909, 2270357136, 1051278712, 802445057, 2519698665,
- 221152243, 3033880603, 2779263586, 475261322,
- },
- {
- 0, 2926088593, 2275419491, 701019378, 3560000647, 2052709654,
- 1402038756, 4261017717, 1930665807, 3715829470, 4105419308, 1524313021,
- 2804077512, 155861593, 545453739, 2397726522, 3861331614, 1213181711,
- 1636244477, 3488582252, 840331801, 2625561480, 3048626042, 467584747,
- 2503254481, 995897408, 311723186, 3170637091, 1090907478, 4016929991,
- 3332753461, 1758288292, 390036349, 3109546732, 2426363422, 1056427919,
- 3272488954, 1835443819, 1152258713, 3938878216, 1680663602, 3393484195,
- 3817652561, 1306808512, 2954733749, 510998820, 935169494, 2580880455,
- 4044899811, 1601229938, 1991794816, 3637571857, 623446372, 2336332021,
- 2726898695, 216120726, 2181814956, 744704829, 95158223, 2881711710,
- 1446680107, 4166125498, 3516576584, 2146575065, 780072698, 2148951915,
- 2849952665, 129384968, 4199529085, 1411853292, 2112855838, 3548843663,
- 1567451573, 4077254692, 3670887638, 1957027143, 2304517426, 657765539,
- 251396177, 2694091200, 3361327204, 1714510325, 1341779207, 3784408214,
- 476611811, 2986349938, 2613617024, 899690513, 3142211371, 354600634,
- 1021997640, 2458051545, 1870338988, 3239283261, 3906682575, 1186180958,
- 960597383, 2536053782, 3202459876, 277428597, 3983589632, 1125666961,
- 1792074851, 3300423154, 1246892744, 3829039961, 3455203243, 1671079482,
- 2657312335, 806080478, 432241452, 3081497277, 3748049689, 1896751752,
- 1489409658, 4138600427, 190316446, 2772397583, 2365053693, 580864876,
- 2893360214, 35503559, 735381813, 2243795108, 2017747153, 3593269568,
- 4293150130, 1368183843, 1560145396, 4069882981, 3680356503, 1966430470,
- 2295112051, 648294626, 258769936, 2701399425, 804156091, 2173100842,
- 2823706584, 103204425, 4225711676, 1438101421, 2088704863, 3524758222,
- 3134903146, 347226875, 1031468553, 2467456920, 1860935661, 3229814396,
- 3914054286, 1193487135, 3385412645, 1738661300, 1315531078, 3758225623,
- 502792354, 3012596019, 2589468097, 875607120, 1271043721, 3853125400,
- 3429020650, 1644831355, 2683558414, 832261023, 408158061, 3057348348,
- 953223622, 2528745559, 3211865253, 286899508, 3974120769, 1116263632,
- 1799381026, 3307794867, 2917509143, 59586950, 709201268, 2217549029,
- 2043995280, 3619452161, 4269064691, 1344032866, 3740677976, 1889445577,
- 1498812987, 4148069290, 180845535, 2762992206, 2372361916, 588238637,
- 1921194766, 3706423967, 4112727661, 1531686908, 2796705673, 148555288,
- 554857194, 2407195515, 26248257, 2952271312, 2251333922, 676868275,
- 3584149702, 2076793175, 1375858085, 4234771508, 2493785488, 986493953,
- 319029491, 3178008930, 1083533591, 4009621638, 3342158964, 1767759333,
- 3887577823, 1239362382, 1612160956, 3464433197, 864482904, 2649647049,
- 3022443323, 441336490, 1706844275, 3419730402, 3793503504, 1282724993,
- 2978819316, 535149925, 908921239, 2554697734, 380632892, 3100077741,
- 2433735263, 1063734222, 3265180603, 1828069930, 1161729752, 3948283721,
- 2207997677, 770953084, 71007118, 2857626143, 1470763626, 4190274555,
- 3490330377, 2120394392, 4035494306, 1591758899, 1999168705, 3644880208,
- 616140069, 2328960180, 2736367686, 225524183,
- },
+static const uint32_t //
+ wuffs_crc32__ieee_table[16][256] //
+ WUFFS_BASE__POTENTIALLY_UNUSED = {
+ {
+ 0, 1996959894, 3993919788, 2567524794, 124634137,
+ 1886057615, 3915621685, 2657392035, 249268274, 2044508324,
+ 3772115230, 2547177864, 162941995, 2125561021, 3887607047,
+ 2428444049, 498536548, 1789927666, 4089016648, 2227061214,
+ 450548861, 1843258603, 4107580753, 2211677639, 325883990,
+ 1684777152, 4251122042, 2321926636, 335633487, 1661365465,
+ 4195302755, 2366115317, 997073096, 1281953886, 3579855332,
+ 2724688242, 1006888145, 1258607687, 3524101629, 2768942443,
+ 901097722, 1119000684, 3686517206, 2898065728, 853044451,
+ 1172266101, 3705015759, 2882616665, 651767980, 1373503546,
+ 3369554304, 3218104598, 565507253, 1454621731, 3485111705,
+ 3099436303, 671266974, 1594198024, 3322730930, 2970347812,
+ 795835527, 1483230225, 3244367275, 3060149565, 1994146192,
+ 31158534, 2563907772, 4023717930, 1907459465, 112637215,
+ 2680153253, 3904427059, 2013776290, 251722036, 2517215374,
+ 3775830040, 2137656763, 141376813, 2439277719, 3865271297,
+ 1802195444, 476864866, 2238001368, 4066508878, 1812370925,
+ 453092731, 2181625025, 4111451223, 1706088902, 314042704,
+ 2344532202, 4240017532, 1658658271, 366619977, 2362670323,
+ 4224994405, 1303535960, 984961486, 2747007092, 3569037538,
+ 1256170817, 1037604311, 2765210733, 3554079995, 1131014506,
+ 879679996, 2909243462, 3663771856, 1141124467, 855842277,
+ 2852801631, 3708648649, 1342533948, 654459306, 3188396048,
+ 3373015174, 1466479909, 544179635, 3110523913, 3462522015,
+ 1591671054, 702138776, 2966460450, 3352799412, 1504918807,
+ 783551873, 3082640443, 3233442989, 3988292384, 2596254646,
+ 62317068, 1957810842, 3939845945, 2647816111, 81470997,
+ 1943803523, 3814918930, 2489596804, 225274430, 2053790376,
+ 3826175755, 2466906013, 167816743, 2097651377, 4027552580,
+ 2265490386, 503444072, 1762050814, 4150417245, 2154129355,
+ 426522225, 1852507879, 4275313526, 2312317920, 282753626,
+ 1742555852, 4189708143, 2394877945, 397917763, 1622183637,
+ 3604390888, 2714866558, 953729732, 1340076626, 3518719985,
+ 2797360999, 1068828381, 1219638859, 3624741850, 2936675148,
+ 906185462, 1090812512, 3747672003, 2825379669, 829329135,
+ 1181335161, 3412177804, 3160834842, 628085408, 1382605366,
+ 3423369109, 3138078467, 570562233, 1426400815, 3317316542,
+ 2998733608, 733239954, 1555261956, 3268935591, 3050360625,
+ 752459403, 1541320221, 2607071920, 3965973030, 1969922972,
+ 40735498, 2617837225, 3943577151, 1913087877, 83908371,
+ 2512341634, 3803740692, 2075208622, 213261112, 2463272603,
+ 3855990285, 2094854071, 198958881, 2262029012, 4057260610,
+ 1759359992, 534414190, 2176718541, 4139329115, 1873836001,
+ 414664567, 2282248934, 4279200368, 1711684554, 285281116,
+ 2405801727, 4167216745, 1634467795, 376229701, 2685067896,
+ 3608007406, 1308918612, 956543938, 2808555105, 3495958263,
+ 1231636301, 1047427035, 2932959818, 3654703836, 1088359270,
+ 936918000, 2847714899, 3736837829, 1202900863, 817233897,
+ 3183342108, 3401237130, 1404277552, 615818150, 3134207493,
+ 3453421203, 1423857449, 601450431, 3009837614, 3294710456,
+ 1567103746, 711928724, 3020668471, 3272380065, 1510334235,
+ 755167117,
+ },
+ {
+ 0, 421212481, 842424962, 724390851, 1684849924,
+ 2105013317, 1448781702, 1329698503, 3369699848, 3519200073,
+ 4210026634, 3824474571, 2897563404, 3048111693, 2659397006,
+ 2274893007, 1254232657, 1406739216, 2029285587, 1643069842,
+ 783210325, 934667796, 479770071, 92505238, 2182846553,
+ 2600511768, 2955803355, 2838940570, 3866582365, 4285295644,
+ 3561045983, 3445231262, 2508465314, 2359236067, 2813478432,
+ 3198777185, 4058571174, 3908292839, 3286139684, 3670389349,
+ 1566420650, 1145479147, 1869335592, 1987116393, 959540142,
+ 539646703, 185010476, 303839341, 3745920755, 3327985586,
+ 3983561841, 4100678960, 3140154359, 2721170102, 2300350837,
+ 2416418868, 396344571, 243568058, 631889529, 1018359608,
+ 1945336319, 1793607870, 1103436669, 1490954812, 4034481925,
+ 3915546180, 3259968903, 3679722694, 2484439553, 2366552896,
+ 2787371139, 3208174018, 950060301, 565965900, 177645455,
+ 328046286, 1556873225, 1171730760, 1861902987, 2011255754,
+ 3132841300, 2745199637, 2290958294, 2442530455, 3738671184,
+ 3352078609, 3974232786, 4126854035, 1919080284, 1803150877,
+ 1079293406, 1498383519, 370020952, 253043481, 607678682,
+ 1025720731, 1711106983, 2095471334, 1472923941, 1322268772,
+ 26324643, 411738082, 866634785, 717028704, 2904875439,
+ 3024081134, 2668790573, 2248782444, 3376948395, 3495106026,
+ 4219356713, 3798300520, 792689142, 908347575, 487136116,
+ 68299317, 1263779058, 1380486579, 2036719216, 1618931505,
+ 3890672638, 4278043327, 3587215740, 3435896893, 2206873338,
+ 2593195963, 2981909624, 2829542713, 998479947, 580430090,
+ 162921161, 279890824, 1609522511, 1190423566, 1842954189,
+ 1958874764, 4082766403, 3930137346, 3245109441, 3631694208,
+ 2536953671, 2385372678, 2768287173, 3155920004, 1900120602,
+ 1750776667, 1131931800, 1517083097, 355290910, 204897887,
+ 656092572, 1040194781, 3113746450, 2692952403, 2343461520,
+ 2461357009, 3723805974, 3304059991, 4022511508, 4141455061,
+ 2919742697, 3072101800, 2620513899, 2234183466, 3396041197,
+ 3547351212, 4166851439, 3779471918, 1725839073, 2143618976,
+ 1424512099, 1307796770, 45282277, 464110244, 813994343,
+ 698327078, 3838160568, 4259225593, 3606301754, 3488152955,
+ 2158586812, 2578602749, 2996767038, 2877569151, 740041904,
+ 889656817, 506086962, 120682355, 1215357364, 1366020341,
+ 2051441462, 1667084919, 3422213966, 3538019855, 4190942668,
+ 3772220557, 2945847882, 3062702859, 2644537544, 2226864521,
+ 52649286, 439905287, 823476164, 672009861, 1733269570,
+ 2119477507, 1434057408, 1281543041, 2167981343, 2552493150,
+ 3004082077, 2853541596, 3847487515, 4233048410, 3613549209,
+ 3464057816, 1239502615, 1358593622, 2077699477, 1657543892,
+ 764250643, 882293586, 532408465, 111204816, 1585378284,
+ 1197851309, 1816695150, 1968414767, 974272232, 587794345,
+ 136598634, 289367339, 2527558116, 2411481253, 2760973158,
+ 3179948583, 4073438432, 3956313505, 3237863010, 3655790371,
+ 347922877, 229101820, 646611775, 1066513022, 1892689081,
+ 1774917112, 1122387515, 1543337850, 3697634229, 3313392372,
+ 3998419255, 4148705398, 3087642289, 2702352368, 2319436851,
+ 2468674930,
+ },
+ {
+ 0, 29518391, 59036782, 38190681, 118073564,
+ 114017003, 76381362, 89069189, 236147128, 265370511,
+ 228034006, 206958561, 152762724, 148411219, 178138378,
+ 190596925, 472294256, 501532999, 530741022, 509615401,
+ 456068012, 451764635, 413917122, 426358261, 305525448,
+ 334993663, 296822438, 275991697, 356276756, 352202787,
+ 381193850, 393929805, 944588512, 965684439, 1003065998,
+ 973863097, 1061482044, 1049003019, 1019230802, 1023561829,
+ 912136024, 933002607, 903529270, 874031361, 827834244,
+ 815125939, 852716522, 856752605, 611050896, 631869351,
+ 669987326, 640506825, 593644876, 580921211, 551983394,
+ 556069653, 712553512, 733666847, 704405574, 675154545,
+ 762387700, 749958851, 787859610, 792175277, 1889177024,
+ 1901651959, 1931368878, 1927033753, 2006131996, 1985040171,
+ 1947726194, 1976933189, 2122964088, 2135668303, 2098006038,
+ 2093965857, 2038461604, 2017599123, 2047123658, 2076625661,
+ 1824272048, 1836991623, 1866005214, 1861914857, 1807058540,
+ 1786244187, 1748062722, 1777547317, 1655668488, 1668093247,
+ 1630251878, 1625932113, 1705433044, 1684323811, 1713505210,
+ 1742760333, 1222101792, 1226154263, 1263738702, 1251046777,
+ 1339974652, 1310460363, 1281013650, 1301863845, 1187289752,
+ 1191637167, 1161842422, 1149379777, 1103966788, 1074747507,
+ 1112139306, 1133218845, 1425107024, 1429406311, 1467333694,
+ 1454888457, 1408811148, 1379576507, 1350309090, 1371438805,
+ 1524775400, 1528845279, 1499917702, 1487177649, 1575719220,
+ 1546255107, 1584350554, 1605185389, 3778354048, 3774312887,
+ 3803303918, 3816007129, 3862737756, 3892238699, 3854067506,
+ 3833203973, 4012263992, 4007927823, 3970080342, 3982554209,
+ 3895452388, 3924658387, 3953866378, 3932773565, 4245928176,
+ 4241609415, 4271336606, 4283762345, 4196012076, 4225268251,
+ 4187931714, 4166823541, 4076923208, 4072833919, 4035198246,
+ 4047918865, 4094247316, 4123732899, 4153251322, 4132437965,
+ 3648544096, 3636082519, 3673983246, 3678331705, 3732010428,
+ 3753090955, 3723829714, 3694611429, 3614117080, 3601426159,
+ 3572488374, 3576541825, 3496125444, 3516976691, 3555094634,
+ 3525581405, 3311336976, 3298595879, 3336186494, 3340255305,
+ 3260503756, 3281337595, 3251864226, 3222399125, 3410866088,
+ 3398419871, 3368647622, 3372945905, 3427010420, 3448139075,
+ 3485520666, 3456284973, 2444203584, 2423127159, 2452308526,
+ 2481530905, 2527477404, 2539934891, 2502093554, 2497740997,
+ 2679949304, 2659102159, 2620920726, 2650438049, 2562027300,
+ 2574714131, 2603727690, 2599670141, 2374579504, 2353749767,
+ 2383274334, 2412743529, 2323684844, 2336421851, 2298759554,
+ 2294686645, 2207933576, 2186809023, 2149495014, 2178734801,
+ 2224278612, 2236720739, 2266437690, 2262135309, 2850214048,
+ 2820717207, 2858812622, 2879680249, 2934667388, 2938704459,
+ 2909776914, 2897069605, 2817622296, 2788420399, 2759153014,
+ 2780249921, 2700618180, 2704950259, 2742877610, 2730399645,
+ 3049550800, 3020298727, 3057690558, 3078802825, 2999835404,
+ 3004150075, 2974355298, 2961925461, 3151438440, 3121956959,
+ 3092510214, 3113327665, 3168701108, 3172786307, 3210370778,
+ 3197646061,
+ },
+ {
+ 0, 3099354981, 2852767883, 313896942, 2405603159,
+ 937357362, 627793884, 2648127673, 3316918511, 2097696650,
+ 1874714724, 3607201537, 1255587768, 4067088605, 3772741427,
+ 1482887254, 1343838111, 3903140090, 4195393300, 1118632049,
+ 3749429448, 1741137837, 1970407491, 3452858150, 2511175536,
+ 756094997, 1067759611, 2266550430, 449832999, 2725482306,
+ 2965774508, 142231497, 2687676222, 412010587, 171665333,
+ 2995192016, 793786473, 2548850444, 2237264098, 1038456711,
+ 1703315409, 3711623348, 3482275674, 1999841343, 3940814982,
+ 1381529571, 1089329165, 4166106984, 4029413537, 1217896388,
+ 1512189994, 3802027855, 2135519222, 3354724499, 3577784189,
+ 1845280792, 899665998, 2367928107, 2677414085, 657096608,
+ 3137160985, 37822588, 284462994, 2823350519, 2601801789,
+ 598228824, 824021174, 2309093331, 343330666, 2898962447,
+ 3195996129, 113467524, 1587572946, 3860600759, 4104763481,
+ 1276501820, 3519211397, 1769898208, 2076913422, 3279374443,
+ 3406630818, 1941006535, 1627703081, 3652755532, 1148164341,
+ 4241751952, 3999682686, 1457141531, 247015245, 3053797416,
+ 2763059142, 470583459, 2178658330, 963106687, 735213713,
+ 2473467892, 992409347, 2207944806, 2435792776, 697522413,
+ 3024379988, 217581361, 508405983, 2800865210, 4271038444,
+ 1177467017, 1419450215, 3962007554, 1911572667, 3377213406,
+ 3690561584, 1665525589, 1799331996, 3548628985, 3241568279,
+ 2039091058, 3831314379, 1558270126, 1314193216, 4142438437,
+ 2928380019, 372764438, 75645176, 3158189981, 568925988,
+ 2572515393, 2346768303, 861712586, 3982079547, 1441124702,
+ 1196457648, 4293663189, 1648042348, 3666298377, 3358779879,
+ 1888390786, 686661332, 2421291441, 2196002399, 978858298,
+ 2811169155, 523464422, 226935048, 3040519789, 3175145892,
+ 100435649, 390670639, 2952089162, 841119475, 2325614998,
+ 2553003640, 546822429, 2029308235, 3225988654, 3539796416,
+ 1782671013, 4153826844, 1328167289, 1570739863, 3844338162,
+ 1298864389, 4124540512, 3882013070, 1608431339, 3255406162,
+ 2058742071, 1744848601, 3501990332, 2296328682, 811816591,
+ 584513889, 2590678532, 129869501, 3204563416, 2914283062,
+ 352848211, 494030490, 2781751807, 3078325777, 264757620,
+ 2450577869, 715964072, 941166918, 2158327331, 3636881013,
+ 1618608400, 1926213374, 3396585883, 1470427426, 4011365959,
+ 4255988137, 1158766284, 1984818694, 3471935843, 3695453837,
+ 1693991400, 4180638033, 1100160564, 1395044826, 3952793279,
+ 3019491049, 189112716, 435162722, 2706139399, 1016811966,
+ 2217162459, 2526189877, 774831696, 643086745, 2666061564,
+ 2354934034, 887166583, 2838900430, 294275499, 54519365,
+ 3145957664, 3823145334, 1532818963, 1240029693, 4048895640,
+ 1820460577, 3560857924, 3331051178, 2117577167, 3598663992,
+ 1858283101, 2088143283, 3301633750, 1495127663, 3785470218,
+ 4078182116, 1269332353, 332098007, 2876706482, 3116540252,
+ 25085497, 2628386432, 605395429, 916469259, 2384220526,
+ 2254837415, 1054503362, 745528876, 2496903497, 151290352,
+ 2981684885, 2735556987, 464596510, 1137851976, 4218313005,
+ 3923506883, 1365741990, 3434129695, 1946996346, 1723425172,
+ 3724871409,
+ },
+ {
+ 0, 1029712304, 2059424608, 1201699536, 4118849216,
+ 3370159984, 2403399072, 2988497936, 812665793, 219177585,
+ 1253054625, 2010132753, 3320900865, 4170237105, 3207642721,
+ 2186319825, 1625331586, 1568718386, 438355170, 658566482,
+ 2506109250, 2818578674, 4020265506, 3535817618, 1351670851,
+ 1844508147, 709922595, 389064339, 2769320579, 2557498163,
+ 3754961379, 3803185235, 3250663172, 4238411444, 3137436772,
+ 2254525908, 876710340, 153198708, 1317132964, 1944187668,
+ 4054934725, 3436268917, 2339452837, 3054575125, 70369797,
+ 961670069, 2129760613, 1133623509, 2703341702, 2621542710,
+ 3689016294, 3867263574, 1419845190, 1774270454, 778128678,
+ 318858390, 2438067015, 2888948471, 3952189479, 3606153623,
+ 1691440519, 1504803895, 504432359, 594620247, 1492342857,
+ 1704161785, 573770537, 525542041, 2910060169, 2417219385,
+ 3618876905, 3939730521, 1753420680, 1440954936, 306397416,
+ 790849880, 2634265928, 2690882808, 3888375336, 3668168600,
+ 940822475, 91481723, 1121164459, 2142483739, 3448989963,
+ 4042473659, 3075684971, 2318603227, 140739594, 889433530,
+ 1923340138, 1338244826, 4259521226, 3229813626, 2267247018,
+ 3124975642, 2570221389, 2756861693, 3824297005, 3734113693,
+ 1823658381, 1372780605, 376603373, 722643805, 2839690380,
+ 2485261628, 3548540908, 4007806556, 1556257356, 1638052860,
+ 637716780, 459464860, 4191346895, 3300051327, 2199040943,
+ 3195181599, 206718479, 825388991, 1989285231, 1274166495,
+ 3382881038, 4106388158, 3009607790, 2382549470, 1008864718,
+ 21111934, 1189240494, 2072147742, 2984685714, 2357631266,
+ 3408323570, 4131834434, 1147541074, 2030452706, 1051084082,
+ 63335554, 2174155603, 3170292451, 4216760371, 3325460867,
+ 1947622803, 1232499747, 248909555, 867575619, 3506841360,
+ 3966111392, 2881909872, 2527485376, 612794832, 434546784,
+ 1581699760, 1663499008, 3782634705, 3692447073, 2612412337,
+ 2799048193, 351717905, 697754529, 1849071985, 1398190273,
+ 1881644950, 1296545318, 182963446, 931652934, 2242328918,
+ 3100053734, 4284967478, 3255255942, 1079497815, 2100821479,
+ 983009079, 133672583, 3050795671, 2293717799, 3474399735,
+ 4067887175, 281479188, 765927844, 1778867060, 1466397380,
+ 3846680276, 3626469220, 2676489652, 2733102084, 548881365,
+ 500656741, 1517752501, 1729575173, 3577210133, 3898068133,
+ 2952246901, 2459410373, 3910527195, 3564487019, 2480257979,
+ 2931134987, 479546907, 569730987, 1716854139, 1530213579,
+ 3647316762, 3825568426, 2745561210, 2663766474, 753206746,
+ 293940330, 1445287610, 1799716618, 2314567513, 3029685993,
+ 4080348217, 3461678473, 2088098201, 1091956777, 112560889,
+ 1003856713, 3112514712, 2229607720, 3276105720, 4263857736,
+ 1275433560, 1902492648, 918929720, 195422344, 685033439,
+ 364179055, 1377080511, 1869921551, 3713294623, 3761522863,
+ 2811507327, 2599689167, 413436958, 633644462, 1650777982,
+ 1594160846, 3978570462, 3494118254, 2548332990, 2860797966,
+ 1211387997, 1968470509, 854852413, 261368461, 3182753437,
+ 2161434413, 3346310653, 4195650637, 2017729436, 1160000044,
+ 42223868, 1071931724, 2378480988, 2963576044, 4144295484,
+ 3395602316,
+ },
+ {
+ 0, 3411858341, 1304994059, 2257875630, 2609988118,
+ 1355649459, 3596215069, 486879416, 3964895853, 655315400,
+ 2711298918, 1791488195, 2009251963, 3164476382, 973758832,
+ 4048990933, 64357019, 3364540734, 1310630800, 2235723829,
+ 2554806413, 1394316072, 3582976390, 517157411, 4018503926,
+ 618222419, 2722963965, 1762783832, 1947517664, 3209171269,
+ 970744811, 4068520014, 128714038, 3438335635, 1248109629,
+ 2167961496, 2621261600, 1466012805, 3522553387, 447296910,
+ 3959392091, 547575038, 2788632144, 1835791861, 1886307661,
+ 3140622056, 1034314822, 4143626211, 75106221, 3475428360,
+ 1236444838, 2196665603, 2682996155, 1421317662, 3525567664,
+ 427767573, 3895035328, 594892389, 2782995659, 1857943406,
+ 1941489622, 3101955187, 1047553757, 4113347960, 257428076,
+ 3288652233, 1116777319, 2311878850, 2496219258, 1603640287,
+ 3640781169, 308099796, 3809183745, 676813732, 2932025610,
+ 1704983215, 2023410199, 3016104370, 894593820, 4262377657,
+ 210634999, 3352484690, 1095150076, 2316991065, 2535410401,
+ 1547934020, 3671583722, 294336591, 3772615322, 729897279,
+ 2903845777, 1716123700, 2068629644, 2953845545, 914647431,
+ 4258839074, 150212442, 3282623743, 1161604689, 2388688372,
+ 2472889676, 1480171241, 3735940167, 368132066, 3836185911,
+ 805002898, 2842635324, 1647574937, 2134298401, 3026852996,
+ 855535146, 4188192143, 186781121, 3229539940, 1189784778,
+ 2377547631, 2427670487, 1542429810, 3715886812, 371670393,
+ 3882979244, 741170185, 2864262823, 1642462466, 2095107514,
+ 3082559007, 824732849, 4201955092, 514856152, 3589064573,
+ 1400419795, 2552522358, 2233554638, 1316849003, 3370776517,
+ 62202976, 4075001525, 968836368, 3207280574, 1954014235,
+ 1769133219, 2720925446, 616199592, 4024870413, 493229635,
+ 3594175974, 1353627464, 2616354029, 2264355925, 1303087088,
+ 3409966430, 6498043, 4046820398, 979978123, 3170710821,
+ 2007099008, 1789187640, 2717386141, 661419827, 3962610838,
+ 421269998, 3527459403, 1423225061, 2676515648, 2190300152,
+ 1238466653, 3477467891, 68755798, 4115633027, 1041448998,
+ 3095868040, 1943789869, 1860096405, 2776760880, 588673182,
+ 3897205563, 449450869, 3516317904, 1459794558, 2623431131,
+ 2170245475, 1242006214, 3432247400, 131015629, 4137259288,
+ 1036337853, 3142660115, 1879958454, 1829294862, 2790523051,
+ 549483013, 3952910752, 300424884, 3669282065, 1545650111,
+ 2541513754, 2323209378, 1092980487, 3350330793, 216870412,
+ 4256931033, 921128828, 2960342482, 2066738807, 1714085583,
+ 2910195050, 736264132, 3770592353, 306060335, 3647131530,
+ 1610005796, 2494197377, 2309971513, 1123257756, 3295149874,
+ 255536279, 4268596802, 892423655, 3013951305, 2029645036,
+ 1711070292, 2929725425, 674528607, 3815288570, 373562242,
+ 3709388839, 1535949449, 2429577516, 2379569556, 1183418929,
+ 3223189663, 188820282, 4195850735, 827017802, 3084859620,
+ 2089020225, 1636228089, 2866415708, 743340786, 3876759895,
+ 361896217, 3738094268, 1482340370, 2466671543, 2382584591,
+ 1163888810, 3284924932, 144124321, 4190215028, 849168593,
+ 3020503679, 2136336858, 1649465698, 2836138695, 798521449,
+ 3838094284,
+ },
+ {
+ 0, 2792819636, 2543784233, 837294749, 4098827283,
+ 1379413927, 1674589498, 3316072078, 871321191, 2509784531,
+ 2758827854, 34034938, 3349178996, 1641505216, 1346337629,
+ 4131942633, 1742642382, 3249117050, 4030828007, 1446413907,
+ 2475800797, 904311657, 68069876, 2725880384, 1412551337,
+ 4064729373, 3283010432, 1708771380, 2692675258, 101317902,
+ 937551763, 2442587175, 3485284764, 1774858792, 1478633653,
+ 4266992385, 1005723023, 2642744891, 2892827814, 169477906,
+ 4233263099, 1512406095, 1808623314, 3451546982, 136139752,
+ 2926205020, 2676114113, 972376437, 2825102674, 236236518,
+ 1073525883, 2576072655, 1546420545, 4200303349, 3417542760,
+ 1841601500, 2609703733, 1039917185, 202635804, 2858742184,
+ 1875103526, 3384067218, 4166835727, 1579931067, 1141601657,
+ 3799809741, 3549717584, 1977839588, 2957267306, 372464350,
+ 668680259, 2175552503, 2011446046, 3516084394, 3766168119,
+ 1175200131, 2209029901, 635180217, 338955812, 2990736784,
+ 601221559, 2242044419, 3024812190, 306049834, 3617246628,
+ 1911408144, 1074125965, 3866285881, 272279504, 3058543716,
+ 2275784441, 567459149, 3832906691, 1107462263, 1944752874,
+ 3583875422, 2343980261, 767641425, 472473036, 3126744696,
+ 2147051766, 3649987394, 3899029983, 1309766251, 3092841090,
+ 506333494, 801510315, 2310084639, 1276520081, 3932237093,
+ 3683203000, 2113813516, 3966292011, 1243601823, 2079834370,
+ 3716205238, 405271608, 3192979340, 2411259153, 701492901,
+ 3750207052, 2045810168, 1209569125, 4000285905, 734575199,
+ 2378150379, 3159862134, 438345922, 2283203314, 778166598,
+ 529136603, 3120492655, 2086260449, 3660498261, 3955679176,
+ 1303499900, 3153699989, 495890209, 744928700, 2316418568,
+ 1337360518, 3921775410, 3626602927, 2120129051, 4022892092,
+ 1237286280, 2018993941, 3726666913, 461853231, 3186645403,
+ 2350400262, 711936178, 3693557851, 2052076527, 1270360434,
+ 3989775046, 677911624, 2384402428, 3220639073, 427820757,
+ 1202443118, 3789347034, 3493118535, 1984154099, 3018127229,
+ 362020041, 612099668, 2181885408, 1950653705, 3526596285,
+ 3822816288, 1168934804, 2148251930, 645706414, 395618355,
+ 2984485767, 544559008, 2248295444, 3085590153, 295523645,
+ 3560598451, 1917673479, 1134918298, 3855773998, 328860103,
+ 3052210803, 2214924526, 577903450, 3889505748, 1101147744,
+ 1883911421, 3594338121, 3424493451, 1785369663, 1535282850,
+ 4260726038, 944946072, 2653270060, 2949491377, 163225861,
+ 4294103532, 1501944408, 1752023237, 3457862513, 196998655,
+ 2915761739, 2619532502, 978710370, 2881684293, 229902577,
+ 1012666988, 2586515928, 1603020630, 4193987810, 3356702335,
+ 1852063179, 2553040162, 1046169238, 263412747, 2848217023,
+ 1818454321, 3390333573, 4227627032, 1569420204, 60859927,
+ 2782375331, 2487203646, 843627658, 4159668740, 1368951216,
+ 1617990445, 3322386585, 810543216, 2520310724, 2815490393,
+ 27783917, 3288386659, 1652017111, 1402985802, 4125677310,
+ 1685994201, 3255382381, 4091620336, 1435902020, 2419138250,
+ 910562686, 128847843, 2715354199, 1469150398, 4058414858,
+ 3222168983, 1719234083, 2749255853, 94984985, 876691844,
+ 2453031472,
+ },
+ {
+ 0, 3433693342, 1109723005, 2391738339, 2219446010,
+ 1222643300, 3329165703, 180685081, 3555007413, 525277995,
+ 2445286600, 1567235158, 1471092047, 2600801745, 361370162,
+ 3642757804, 2092642603, 2953916853, 1050555990, 4063508168,
+ 4176560081, 878395215, 3134470316, 1987983410, 2942184094,
+ 1676945920, 3984272867, 567356797, 722740324, 3887998202,
+ 1764827929, 2778407815, 4185285206, 903635656, 3142804779,
+ 2012833205, 2101111980, 2979425330, 1058630609, 4088621903,
+ 714308067, 3862526333, 1756790430, 2753330688, 2933487385,
+ 1651734407, 3975966820, 542535930, 2244825981, 1231508451,
+ 3353891840, 188896414, 25648519, 3442302233, 1134713594,
+ 2399689316, 1445480648, 2592229462, 336416693, 3634843435,
+ 3529655858, 516441772, 2420588879, 1559052753, 698204909,
+ 3845636723, 1807271312, 2803025166, 2916600855, 1635634313,
+ 4025666410, 593021940, 4202223960, 919787974, 3093159461,
+ 1962401467, 2117261218, 2996361020, 1008193759, 4038971457,
+ 1428616134, 2576151384, 386135227, 3685348389, 3513580860,
+ 499580322, 2471098945, 1608776415, 2260985971, 1248454893,
+ 3303468814, 139259792, 42591881, 3458459159, 1085071860,
+ 2349261162, 3505103035, 474062885, 2463016902, 1583654744,
+ 1419882049, 2550902495, 377792828, 3660491170, 51297038,
+ 3483679632, 1093385331, 2374089965, 2269427188, 1273935210,
+ 3311514249, 164344343, 2890961296, 1627033870, 4000683757,
+ 585078387, 672833386, 3836780532, 1782552599, 2794821769,
+ 2142603813, 3005188795, 1032883544, 4047146438, 4227826911,
+ 928351297, 3118105506, 1970307900, 1396409818, 2677114180,
+ 287212199, 3719594553, 3614542624, 467372990, 2505346141,
+ 1509854403, 2162073199, 1282711281, 3271268626, 240228748,
+ 76845205, 3359543307, 1186043880, 2317064054, 796964081,
+ 3811226735, 1839575948, 2702160658, 2882189835, 1734392469,
+ 3924802934, 625327592, 4234522436, 818917338, 3191908409,
+ 1927981223, 2016387518, 3028656416, 973776579, 4137723485,
+ 2857232268, 1726474002, 3899187441, 616751215, 772270454,
+ 3803048424, 1814228491, 2693328533, 2041117753, 3036871847,
+ 999160644, 4146592730, 4259508931, 826864221, 3217552830,
+ 1936586016, 3606501031, 442291769, 2496909786, 1484378436,
+ 1388107869, 2652297411, 278519584, 3694387134, 85183762,
+ 3384397196, 1194773103, 2342308593, 2170143720, 1307820918,
+ 3279733909, 265733131, 2057717559, 3054258089, 948125770,
+ 4096344276, 4276898253, 843467091, 3167309488, 1885556270,
+ 2839764098, 1709792284, 3949353983, 667704161, 755585656,
+ 3785577190, 1865176325, 2743489947, 102594076, 3401021058,
+ 1144549729, 2291298815, 2186770662, 1325234296, 3228729243,
+ 215514885, 3589828009, 424832311, 2547870420, 1534552650,
+ 1370645331, 2635621325, 328688686, 3745342640, 2211456353,
+ 1333405183, 3254067740, 224338562, 127544219, 3408931589,
+ 1170156774, 2299866232, 1345666772, 2627681866, 303053225,
+ 3736746295, 3565105198, 416624816, 2522494803, 1525692365,
+ 4285207626, 868291796, 3176010551, 1910772649, 2065767088,
+ 3079346734, 956571085, 4121828691, 747507711, 3760459617,
+ 1856702594, 2717976604, 2831417605, 1684930971, 3940615800,
+ 642451174,
+ },
+ {
+ 0, 393942083, 787884166, 965557445, 1575768332,
+ 1251427663, 1931114890, 1684106697, 3151536664, 2896410203,
+ 2502855326, 2186649309, 3862229780, 4048545623, 3368213394,
+ 3753496529, 2898281073, 3149616690, 2184604407, 2504883892,
+ 4046197629, 3864463166, 3755621371, 3366006712, 387506281,
+ 6550570, 971950319, 781573292, 1257550181, 1569695014,
+ 1677892067, 1937345952, 2196865699, 2508887776, 2886183461,
+ 3145514598, 3743273903, 3362179052, 4058774313, 3868258154,
+ 958996667, 777139448, 400492605, 10755198, 1690661303,
+ 1941857780, 1244879153, 1565019506, 775012562, 961205393,
+ 13101140, 398261271, 1943900638, 1688634781, 1563146584,
+ 1246801179, 2515100362, 2190636681, 3139390028, 2892258831,
+ 3355784134, 3749586821, 3874691904, 4052225795, 3734110983,
+ 3387496260, 4033096577, 3877584834, 2206093835, 2483373640,
+ 2911402637, 3136515790, 1699389727, 1915860316, 1270647193,
+ 1556585946, 950464531, 803071056, 374397077, 19647702,
+ 1917993334, 1697207605, 1554278896, 1272937907, 800985210,
+ 952435769, 21510396, 372452543, 3381322606, 3740399405,
+ 3883715560, 4027047851, 2489758306, 2199758369, 3130039012,
+ 2917895847, 1550025124, 1259902439, 1922410786, 1710144865,
+ 26202280, 385139947, 796522542, 939715693, 3887801276,
+ 4039129087, 3377269562, 3728088953, 3126293168, 2905368307,
+ 2493602358, 2212122229, 4037264341, 3889747862, 3730172755,
+ 3375300368, 2907673305, 3124004506, 2209987167, 2495786524,
+ 1266377165, 1543533966, 1703758155, 1928748296, 379007169,
+ 32253058, 945887303, 790236164, 1716846671, 1898845196,
+ 1218652361, 1608006794, 1002000707, 750929152, 357530053,
+ 36990342, 3717046871, 3405166100, 4084959953, 3825245842,
+ 2153902939, 2535122712, 2929187805, 3119304606, 3398779454,
+ 3723384445, 3831720632, 4078468859, 2541294386, 2147616625,
+ 3113171892, 2935238647, 1900929062, 1714877541, 1606142112,
+ 1220599011, 748794154, 1004184937, 39295404, 355241455,
+ 3835986668, 4091516591, 3394415210, 3710500393, 3108557792,
+ 2922629027, 2545875814, 2160455461, 1601970420, 1208431799,
+ 1904871538, 1727077425, 43020792, 367748539, 744905086,
+ 991776061, 1214562461, 1595921630, 1720903707, 1911159896,
+ 361271697, 49513938, 998160663, 738569556, 4089209477,
+ 3838277318, 3712633347, 3392233024, 2924491657, 3106613194,
+ 2158369551, 2547846988, 3100050248, 2948339467, 2519804878,
+ 2169126797, 3844821572, 4065347079, 3420289730, 3701894785,
+ 52404560, 342144275, 770279894, 982687125, 1593045084,
+ 1233708063, 1879431386, 1736363161, 336019769, 58479994,
+ 988899775, 764050940, 1240141877, 1586496630, 1729968307,
+ 1885744368, 2950685473, 3097818978, 2166999975, 2522013668,
+ 4063474221, 3846743662, 3703937707, 3418263272, 976650731,
+ 760059304, 348170605, 62635310, 1742393575, 1889649828,
+ 1227683937, 1582820386, 2179867635, 2526361520, 2937588597,
+ 3093503798, 3691148031, 3413731004, 4076100217, 3851374138,
+ 2532754330, 2173556697, 3087067932, 2944139103, 3407516310,
+ 3697379029, 3857496592, 4070026835, 758014338, 978679233,
+ 64506116, 346250567, 1891774606, 1740186829, 1580472328,
+ 1229917259,
+ },
+ {
+ 0, 4022496062, 83218493, 3946298115, 166436986,
+ 3861498692, 220098631, 3806075769, 332873972, 4229245898,
+ 388141257, 4175494135, 440197262, 4127099824, 516501683,
+ 4044053389, 665747944, 3362581206, 593187285, 3432594155,
+ 776282514, 3246869164, 716239279, 3312622225, 880394524,
+ 3686509090, 814485793, 3746462239, 1033003366, 3528460888,
+ 963096923, 3601193573, 1331495888, 2694801646, 1269355501,
+ 2758457555, 1186374570, 2843003028, 1111716759, 2910918825,
+ 1552565028, 3007850522, 1484755737, 3082680359, 1432478558,
+ 3131279456, 1368666979, 3193329757, 1760789048, 2268195078,
+ 1812353541, 2210675003, 1628971586, 2396670332, 1710092927,
+ 2318375233, 2066006732, 2498144754, 2144408305, 2417195471,
+ 1926193846, 2634877320, 1983558283, 2583222709, 2662991776,
+ 1903717534, 2588923805, 1972223139, 2538711002, 2022952164,
+ 2477029351, 2087066841, 2372749140, 1655647338, 2308478825,
+ 1717238871, 2223433518, 1799654416, 2155034387, 1873894445,
+ 3105130056, 1456926070, 3185661557, 1378041163, 2969511474,
+ 1597852940, 3020617231, 1539874097, 2864957116, 1157737858,
+ 2922780289, 1106542015, 2737333958, 1290407416, 2816325371,
+ 1210047941, 3521578096, 1042640718, 3574781005, 986759027,
+ 3624707082, 936300340, 3707335735, 859512585, 3257943172,
+ 770846650, 3334837433, 688390023, 3420185854, 605654976,
+ 3475911875, 552361981, 4132013464, 428600998, 4072428965,
+ 494812827, 4288816610, 274747100, 4216845791, 345349857,
+ 3852387692, 173846098, 3781891409, 245988975, 3967116566,
+ 62328360, 3900749099, 121822741, 3859089665, 164061759,
+ 3807435068, 221426178, 4025395579, 2933317, 3944446278,
+ 81334904, 4124199413, 437265099, 4045904328, 518386422,
+ 4231653775, 335250097, 4174133682, 386814604, 3249244393,
+ 778691543, 3311294676, 714879978, 3359647891, 662848429,
+ 3434477742, 595039120, 3531393053, 1035903779, 3599308832,
+ 961245982, 3684132967, 877986649, 3747788890, 815846244,
+ 2841119441, 1184522735, 2913852140, 1114616274, 2696129195,
+ 1332855189, 2756082326, 1266946472, 3129952805, 1431118107,
+ 3195705880, 1371074854, 3009735263, 1554415969, 3079748194,
+ 1481855324, 2398522169, 1630855175, 2315475716, 1707159610,
+ 2266835779, 1759461501, 2213084030, 1814728768, 2636237773,
+ 1927520499, 2580814832, 1981182158, 2496293815, 2064121993,
+ 2420095882, 2147340468, 2025787041, 2541577631, 2085281436,
+ 2475210146, 1901375195, 2660681189, 1973518054, 2590184920,
+ 1801997909, 2225743211, 1872600680, 2153772374, 1652813359,
+ 2369881361, 1719025170, 2310296876, 1594986313, 2966676599,
+ 1541693300, 3022402634, 1459236659, 3107472397, 1376780046,
+ 3184366640, 1288097725, 2734990467, 1211309952, 2817619134,
+ 1160605639, 2867791097, 1104723962, 2920993988, 937561457,
+ 3626001999, 857201996, 3704993394, 1040821515, 3519792693,
+ 989625654, 3577615880, 607473029, 3421972155, 549494200,
+ 3473077894, 769584639, 3256649409, 690699714, 3337180924,
+ 273452185, 4287555495, 347692196, 4219156378, 430386403,
+ 4133832669, 491977950, 4069562336, 60542061, 3965298515,
+ 124656720, 3903616878, 175139863, 3853649705, 243645482,
+ 3779581716,
+ },
+ {
+ 0, 3247366080, 1483520449, 2581751297, 2967040898,
+ 1901571138, 3904227907, 691737987, 3133399365, 2068659845,
+ 3803142276, 589399876, 169513671, 3415493895, 1383475974,
+ 2482566342, 2935407819, 1870142219, 4137319690, 924099274,
+ 506443593, 3751897225, 1178799752, 2278412616, 339027342,
+ 3585866318, 1280941135, 2379694991, 2766951948, 1700956620,
+ 4236308429, 1024339981, 2258407383, 1192382487, 3740284438,
+ 528411094, 910556245, 4157285269, 1848198548, 2946996820,
+ 1012887186, 4258378066, 1681119059, 2780629139, 2357599504,
+ 1292419792, 3572147409, 358906641, 678054684, 3924071644,
+ 1879503581, 2978491677, 2561882270, 1497229150, 3235873119,
+ 22109855, 2460592729, 1395094937, 3401913240, 189516888,
+ 577821147, 3825075739, 2048679962, 3146956762, 3595049455,
+ 398902831, 2384764974, 1336573934, 1720805997, 2803873197,
+ 1056822188, 4285729900, 1821112490, 2902796138, 887570795,
+ 4117339819, 3696397096, 500978920, 2218668777, 1169222953,
+ 2025774372, 3106931428, 550659301, 3780950821, 3362238118,
+ 166293862, 2416645991, 1367722151, 3262987361, 66315169,
+ 2584839584, 1537170016, 1923370979, 3005911075, 717813282,
+ 3947244002, 1356109368, 2438613496, 146288633, 3375820857,
+ 3759007162, 562248314, 3093388411, 2045739963, 3927406461,
+ 731490493, 2994458300, 1945440636, 1523451135, 2604718911,
+ 44219710, 3274466046, 4263662323, 1068272947, 2790189874,
+ 1740649714, 1325080945, 2406874801, 379033776, 3608758128,
+ 1155642294, 2238671990, 479005303, 3708016055, 4097359924,
+ 901128180, 2891217397, 1843045941, 2011248031, 3060787807,
+ 797805662, 3993195422, 3342353949, 112630237, 2673147868,
+ 1591353372, 3441611994, 212601626, 2504944923, 1421914843,
+ 2113644376, 3161815192, 630660761, 3826893145, 3642224980,
+ 412692116, 2172340373, 1089836885, 1775141590, 2822790422,
+ 832715543, 4029474007, 1674842129, 2723860433, 1001957840,
+ 4197873168, 3540870035, 310623315, 2338445906, 1257178514,
+ 4051548744, 821257608, 2836464521, 1755307081, 1101318602,
+ 2150241802, 432566283, 3628511179, 1270766349, 2318435533,
+ 332587724, 3529260300, 4217841807, 988411727, 2735444302,
+ 1652903566, 1602977411, 2651169091, 132630338, 3328776322,
+ 4015131905, 786223809, 3074340032, 1991273216, 3846741958,
+ 616972294, 3173262855, 2091579847, 1435626564, 2485072772,
+ 234706309, 3430124101, 2712218736, 1613231024, 4190475697,
+ 944458353, 292577266, 3506339890, 1226630707, 2291284467,
+ 459984181, 3672380149, 1124496628, 2189994804, 2880683703,
+ 1782407543, 4091479926, 844224694, 257943739, 3469817723,
+ 1462980986, 2529005242, 3213269817, 2114471161, 3890881272,
+ 644152632, 3046902270, 1947391550, 3991973951, 746483711,
+ 88439420, 3301680572, 1563018173, 2628197501, 657826727,
+ 3871046759, 2136545894, 3201811878, 2548879397, 1449267173,
+ 3481299428, 235845156, 2650161890, 1551408418, 3315268387,
+ 68429027, 758067552, 3970035360, 1967360161, 3033356129,
+ 2311284588, 1213053100, 3517963949, 270598509, 958010606,
+ 4170500910, 1635167535, 2700636911, 855672361, 4069415401,
+ 1802256360, 2866995240, 2212099499, 1113008747, 3686091882,
+ 440112042,
+ },
+ {
+ 0, 2611301487, 3963330207, 2006897392, 50740095,
+ 2560849680, 4013794784, 1956178319, 101480190, 2645113489,
+ 3929532513, 1905435662, 84561281, 2662269422, 3912356638,
+ 1922342769, 202960380, 2545787283, 3760419683, 2072395532,
+ 253679235, 2495322860, 3810871324, 2021655667, 169122562,
+ 2444351341, 3861841309, 2106214898, 152215677, 2461527058,
+ 3844685538, 2123133581, 405920760, 2207553431, 4094313831,
+ 1873742088, 456646791, 2157096168, 4144791064, 1823027831,
+ 507358470, 2241388905, 4060492697, 1772322806, 490444409,
+ 2258557462, 4043311334, 1789215881, 338245124, 2408348267,
+ 4161972379, 1672996084, 388959611, 2357870868, 4212429796,
+ 1622269835, 304431354, 2306870421, 4263435877, 1706791434,
+ 287538053, 2324051946, 4246267162, 1723705717, 811841520,
+ 2881944479, 3696765295, 1207788800, 862293135, 2831204576,
+ 3747484176, 1157324415, 913293582, 2915732833, 3662962577,
+ 1106318334, 896137841, 2932651550, 3646055662, 1123494017,
+ 1014716940, 2816349795, 3493905555, 1273334012, 1065181555,
+ 2765630748, 3544645612, 1222882179, 980888818, 2714919069,
+ 3595350637, 1307180546, 963712909, 2731826146, 3578431762,
+ 1324336509, 676490248, 3019317351, 3295277719, 1607253752,
+ 726947703, 2968591128, 3345992168, 1556776327, 777919222,
+ 3053147801, 3261432937, 1505806342, 760750473, 3070062054,
+ 3244539670, 1522987897, 608862708, 3220163995, 3362856811,
+ 1406423812, 659339915, 3169449700, 3413582868, 1355966587,
+ 575076106, 3118709605, 3464325525, 1440228858, 557894773,
+ 3135602714, 3447411434, 1457397381, 1623683040, 4217512847,
+ 2365387135, 391757072, 1673614495, 4167309552, 2415577600,
+ 341804655, 1724586270, 4251866481, 2331019137, 290835438,
+ 1707942497, 4268256782, 2314648830, 307490961, 1826587164,
+ 4152020595, 2162433155, 457265388, 1876539747, 4101829900,
+ 2212636668, 407333779, 1792275682, 4051089549, 2263378557,
+ 491595282, 1775619997, 4067460082, 2246988034, 508239213,
+ 2029433880, 3813931127, 2496473735, 258500328, 2079362919,
+ 3763716872, 2546668024, 208559511, 2130363110, 3848244873,
+ 2462145657, 157552662, 2113730969, 3864638966, 2445764358,
+ 174205801, 1961777636, 4014675339, 2564147067, 57707284,
+ 2011718299, 3964481268, 2614361092, 7778411, 1927425818,
+ 3913769845, 2665066885, 92077546, 1910772837, 3930150922,
+ 2648673018, 108709525, 1352980496, 3405878399, 3164554895,
+ 658115296, 1403183983, 3355946752, 3214507504, 607924639,
+ 1453895406, 3440239233, 3130208369, 557218846, 1437504913,
+ 3456883198, 3113552654, 573589345, 1555838444, 3340335491,
+ 2961681267, 723707676, 1606028947, 3290383100, 3011612684,
+ 673504355, 1521500946, 3239382909, 3062619533, 758026722,
+ 1505130605, 3256038402, 3045975794, 774417053, 1217725416,
+ 3543158663, 2762906999, 1057739032, 1267939479, 3493229816,
+ 2812847624, 1007544935, 1318679830, 3577493881, 2728586121,
+ 956803046, 1302285929, 3594125830, 2711933174, 973184153,
+ 1150152212, 3743982203, 2830528651, 856898788, 1200346475,
+ 3694041348, 2880457716, 806684571, 1115789546, 3643069573,
+ 2931426933, 891243034, 1099408277, 3659722746, 2914794762,
+ 907637093,
+ },
+ {
+ 0, 3717650821, 1616688459, 3184159950, 3233376918,
+ 489665299, 2699419613, 2104690264, 1510200173, 2274691816,
+ 979330598, 3888758691, 2595928571, 1194090622, 4209380528,
+ 661706037, 3020400346, 1771143007, 3562738577, 164481556,
+ 1958661196, 2837976521, 350386439, 3379863682, 3993269687,
+ 865250354, 2388181244, 1406015865, 784146209, 4079732388,
+ 1323412074, 2474079215, 3011398645, 1860735600, 3542286014,
+ 246687547, 1942430051, 2924607718, 328963112, 3456978349,
+ 3917322392, 887832861, 2300653011, 1421341782, 700772878,
+ 4099025803, 1234716485, 2483986112, 125431087, 3673109674,
+ 1730500708, 3132326369, 3351283641, 441867836, 2812031730,
+ 2047535991, 1568292418, 2163009479, 1025936137, 3769651852,
+ 2646824148, 1079348561, 4255113631, 537475098, 3180171691,
+ 1612400686, 3721471200, 4717925, 2100624189, 2694980280,
+ 493375094, 3237910515, 3884860102, 974691139, 2278750093,
+ 1514417672, 657926224, 4204917205, 1198234907, 2600289438,
+ 160053105, 3558665972, 1775665722, 3024116671, 3375586791,
+ 346391650, 2842683564, 1962488105, 1401545756, 2384412057,
+ 869618007, 3997403346, 2469432970, 1319524111, 4083956673,
+ 788193860, 250862174, 3546612699, 1856990997, 3006903952,
+ 3461001416, 333211981, 2920678787, 1937824774, 1425017139,
+ 2305216694, 883735672, 3912918525, 2487837605, 1239398944,
+ 4095071982, 696455019, 3136584836, 1734518017, 3668494799,
+ 121507914, 2051872274, 2816200599, 437363545, 3347544796,
+ 3774328809, 1029797484, 2158697122, 1564328743, 542033279,
+ 4258798842, 1074950196, 2642717105, 2691310871, 2113731730,
+ 3224801372, 497043929, 1624461185, 3175454212, 9435850,
+ 3709412175, 4201248378, 671035391, 2587181873, 1201904308,
+ 986750188, 3880142185, 1519135143, 2266689570, 342721485,
+ 3388693064, 1949382278, 2846355203, 3570723163, 155332830,
+ 3028835344, 1763607957, 1315852448, 2482538789, 775087595,
+ 4087626862, 2396469814, 1396827059, 4002123645, 857560824,
+ 320106210, 3464673127, 1934154665, 2933785132, 3551331444,
+ 238804465, 3018961215, 1852270778, 1226292623, 2491507722,
+ 692783300, 4108177729, 2309936921, 1412959900, 3924976210,
+ 879016919, 2803091512, 2055541181, 3343875443, 450471158,
+ 1739236014, 3124525867, 133568485, 3663777376, 4245691221,
+ 545702608, 2639048222, 1088059291, 1034514883, 3762268230,
+ 1576387720, 2153979149, 501724348, 3228659001, 2109407735,
+ 2687359090, 3713981994, 13109167, 3171052385, 1620357860,
+ 1206151121, 2591211092, 666423962, 4197321503, 2271022407,
+ 1523307714, 3875649548, 982999433, 2850034278, 1953942499,
+ 3384583981, 338329256, 1767471344, 3033506165, 151375291,
+ 3566408766, 4091789579, 779425934, 2478797888, 1311354309,
+ 861580189, 4006375960, 1392910038, 2391852883, 2929327945,
+ 1930372812, 3469036034, 324244359, 1847629279, 3015068762,
+ 243015828, 3555391761, 4103744548, 688715169, 2496043375,
+ 1229996266, 874727090, 3920994103, 1417671673, 2313759356,
+ 446585235, 3339223062, 2059594968, 2807313757, 3660002053,
+ 129100416, 3128657486, 1743609803, 1084066558, 2634765179,
+ 549535669, 4250396208, 2149900392, 1571961325, 3765982499,
+ 1039043750,
+ },
+ {
+ 0, 2635063670, 3782132909, 2086741467, 430739227,
+ 2225303149, 4173482934, 1707977408, 861478454, 2924937024,
+ 3526875803, 1329085421, 720736557, 3086643291, 3415954816,
+ 1452586230, 1722956908, 4223524122, 2279405761, 450042295,
+ 2132718455, 3792785921, 2658170842, 58693292, 1441473114,
+ 3370435372, 3028674295, 696911745, 1279765825, 3511176247,
+ 2905172460, 807831706, 3445913816, 1349228974, 738901109,
+ 2969918723, 3569940419, 1237784245, 900084590, 2829701656,
+ 4265436910, 1664255896, 525574723, 2187084597, 3885099509,
+ 2057177219, 117386584, 2616249390, 2882946228, 920233410,
+ 1253605401, 3619119471, 2994391983, 796207833, 1393823490,
+ 3457937012, 2559531650, 92322804, 2044829231, 3840835417,
+ 2166609305, 472659183, 1615663412, 4249022530, 1102706673,
+ 3702920839, 2698457948, 1037619754, 1477802218, 3306854812,
+ 3111894087, 611605809, 1927342535, 4025419953, 2475568490,
+ 243387420, 1800169180, 4131620778, 2317525617, 388842247,
+ 655084445, 3120835307, 3328511792, 1533734470, 1051149446,
+ 2745738736, 3754524715, 1120297309, 340972971, 2304586973,
+ 4114354438, 1748234352, 234773168, 2431761350, 3968900637,
+ 1906278251, 2363330345, 299003487, 1840466820, 4038896370,
+ 2507210802, 142532932, 1948239007, 3910149609, 3213136159,
+ 579563625, 1592415666, 3286611140, 2787646980, 992477042,
+ 1195825833, 3662232543, 3933188933, 2002801203, 184645608,
+ 2517538462, 4089658462, 1858919720, 313391347, 2409765253,
+ 3644239219, 1144605701, 945318366, 2773977256, 3231326824,
+ 1570095902, 569697989, 3170568115, 2205413346, 511446676,
+ 1646078799, 4279421497, 2598330617, 131105167, 2075239508,
+ 3871229218, 2955604436, 757403810, 1363424633, 3427521551,
+ 2844163791, 881434553, 1223211618, 3588709140, 3854685070,
+ 2026779384, 78583587, 2577462869, 4235025557, 1633861091,
+ 486774840, 2148301134, 3600338360, 1268198606, 938871061,
+ 2868504675, 3476308643, 1379640277, 777684494, 3008718712,
+ 1310168890, 3541595724, 2943964055, 846639841, 1471879201,
+ 3400857943, 3067468940, 735723002, 2102298892, 3762382970,
+ 2619362721, 19901655, 1692534295, 4193118049, 2240594618,
+ 411247564, 681945942, 3047836192, 3385552891, 1422167693,
+ 822682701, 2886124859, 3496468704, 1298661782, 469546336,
+ 2264093718, 4203901389, 1738379451, 38812283, 2673859341,
+ 3812556502, 2117148576, 3268024339, 1606809957, 598006974,
+ 3198893512, 3680933640, 1181316734, 973624229, 2802299603,
+ 4052944421, 1822222163, 285065864, 2381456382, 3896478014,
+ 1966106696, 156323219, 2489232613, 2759337087, 964150537,
+ 1159127250, 3625517476, 3184831332, 551242258, 1555722185,
+ 3249901247, 2535537225, 170842943, 1984954084, 3946848146,
+ 2391651666, 327308324, 1877176831, 4075589769, 263086283,
+ 2460058045, 4005602406, 1942963472, 369291216, 2332888742,
+ 4151061373, 1784924683, 1022852861, 2717425547, 3717839440,
+ 1083595558, 626782694, 3092517008, 3291821387, 1497027645,
+ 1763466407, 4094934481, 2289211402, 360544636, 1890636732,
+ 3988730570, 2447251217, 215086695, 1514488465, 3343557607,
+ 3140191804, 639919946, 1139395978, 3739626748, 2726758695,
+ 1065936977,
+ },
+ {
+ 0, 3120290792, 2827399569, 293431929, 2323408227,
+ 864534155, 586863858, 2600537882, 3481914503, 1987188591,
+ 1729068310, 3740575486, 1173727716, 4228805132, 3983743093,
+ 1418249117, 1147313999, 4254680231, 3974377182, 1428157750,
+ 3458136620, 2011505092, 1721256893, 3747844181, 2347455432,
+ 839944224, 594403929, 2593536433, 26687147, 3094146371,
+ 2836498234, 283794642, 2294627998, 826205558, 541298447,
+ 2578994407, 45702141, 3141697557, 2856315500, 331624836,
+ 1196225049, 4273416689, 4023010184, 1446090848, 3442513786,
+ 1959480466, 1706436331, 3696098563, 3433538001, 1968994873,
+ 1679888448, 3722103720, 1188807858, 4280295258, 3999102243,
+ 1470541515, 53374294, 3134568126, 2879970503, 307431215,
+ 2303854645, 816436189, 567589284, 2553242188, 3405478781,
+ 1929420949, 1652411116, 3682996484, 1082596894, 4185703926,
+ 3892424591, 1375368295, 91404282, 3163122706, 2918450795,
+ 336584067, 2400113305, 922028401, 663249672, 2658384096,
+ 2392450098, 929185754, 639587747, 2682555979, 82149713,
+ 3172883129, 2892181696, 362343208, 1091578037, 4176212829,
+ 3918960932, 1349337804, 3412872662, 1922537022, 1676344391,
+ 3658557359, 1111377379, 4224032267, 3937989746, 1396912026,
+ 3359776896, 1908013928, 1623494929, 3644803833, 2377615716,
+ 877417100, 623982837, 2630542109, 130804743, 3190831087,
+ 2941083030, 381060734, 106748588, 3215393092, 2933549885,
+ 388083925, 2350956495, 903570471, 614862430, 2640172470,
+ 3386185259, 1882115523, 1632872378, 3634920530, 1135178568,
+ 4199721120, 3945775833, 1389631793, 1317531835, 4152109907,
+ 3858841898, 1610259138, 3304822232, 2097172016, 1820140617,
+ 3582394273, 2165193788, 955639764, 696815021, 2423477829,
+ 192043359, 2995356343, 2750736590, 437203750, 182808564,
+ 3005133852, 2724453989, 462947725, 2157513367, 962777471,
+ 673168134, 2447663342, 3312231283, 2090301595, 1844056802,
+ 3557935370, 1326499344, 4142603768, 3885397889, 1584245865,
+ 3326266917, 2142836173, 1858371508, 3611272284, 1279175494,
+ 4123357358, 3837270743, 1564721471, 164299426, 2955991370,
+ 2706223923, 414607579, 2209834945, 978107433, 724686416,
+ 2462715320, 2183156074, 1004243586, 715579643, 2472360723,
+ 140260361, 2980573153, 2698675608, 421617264, 1302961645,
+ 4099032581, 3845074044, 1557460884, 3352688782, 2116952934,
+ 1867729183, 3601371895, 2222754758, 1032278062, 754596439,
+ 2499928511, 234942117, 3086693709, 2793824052, 528319708,
+ 1274365761, 4061043881, 3816027856, 1518873912, 3246989858,
+ 2020800970, 1762628531, 3505670235, 3223196809, 2045103969,
+ 1754834200, 3512958704, 1247965674, 4086934018, 3806642299,
+ 1528765331, 261609486, 3060532198, 2802936223, 518697591,
+ 2246819181, 1007707781, 762121468, 2492913428, 213497176,
+ 3041029808, 2755593417, 499441441, 2261110843, 1061030867,
+ 776167850, 2545465922, 3274734047, 2060165687, 1807140942,
+ 3528266662, 1229724860, 4038575956, 3788156205, 1479636677,
+ 1222322711, 4045468159, 3764231046, 1504067694, 3265744756,
+ 2069664924, 1780612837, 3554288909, 2270357136, 1051278712,
+ 802445057, 2519698665, 221152243, 3033880603, 2779263586,
+ 475261322,
+ },
+ {
+ 0, 2926088593, 2275419491, 701019378, 3560000647,
+ 2052709654, 1402038756, 4261017717, 1930665807, 3715829470,
+ 4105419308, 1524313021, 2804077512, 155861593, 545453739,
+ 2397726522, 3861331614, 1213181711, 1636244477, 3488582252,
+ 840331801, 2625561480, 3048626042, 467584747, 2503254481,
+ 995897408, 311723186, 3170637091, 1090907478, 4016929991,
+ 3332753461, 1758288292, 390036349, 3109546732, 2426363422,
+ 1056427919, 3272488954, 1835443819, 1152258713, 3938878216,
+ 1680663602, 3393484195, 3817652561, 1306808512, 2954733749,
+ 510998820, 935169494, 2580880455, 4044899811, 1601229938,
+ 1991794816, 3637571857, 623446372, 2336332021, 2726898695,
+ 216120726, 2181814956, 744704829, 95158223, 2881711710,
+ 1446680107, 4166125498, 3516576584, 2146575065, 780072698,
+ 2148951915, 2849952665, 129384968, 4199529085, 1411853292,
+ 2112855838, 3548843663, 1567451573, 4077254692, 3670887638,
+ 1957027143, 2304517426, 657765539, 251396177, 2694091200,
+ 3361327204, 1714510325, 1341779207, 3784408214, 476611811,
+ 2986349938, 2613617024, 899690513, 3142211371, 354600634,
+ 1021997640, 2458051545, 1870338988, 3239283261, 3906682575,
+ 1186180958, 960597383, 2536053782, 3202459876, 277428597,
+ 3983589632, 1125666961, 1792074851, 3300423154, 1246892744,
+ 3829039961, 3455203243, 1671079482, 2657312335, 806080478,
+ 432241452, 3081497277, 3748049689, 1896751752, 1489409658,
+ 4138600427, 190316446, 2772397583, 2365053693, 580864876,
+ 2893360214, 35503559, 735381813, 2243795108, 2017747153,
+ 3593269568, 4293150130, 1368183843, 1560145396, 4069882981,
+ 3680356503, 1966430470, 2295112051, 648294626, 258769936,
+ 2701399425, 804156091, 2173100842, 2823706584, 103204425,
+ 4225711676, 1438101421, 2088704863, 3524758222, 3134903146,
+ 347226875, 1031468553, 2467456920, 1860935661, 3229814396,
+ 3914054286, 1193487135, 3385412645, 1738661300, 1315531078,
+ 3758225623, 502792354, 3012596019, 2589468097, 875607120,
+ 1271043721, 3853125400, 3429020650, 1644831355, 2683558414,
+ 832261023, 408158061, 3057348348, 953223622, 2528745559,
+ 3211865253, 286899508, 3974120769, 1116263632, 1799381026,
+ 3307794867, 2917509143, 59586950, 709201268, 2217549029,
+ 2043995280, 3619452161, 4269064691, 1344032866, 3740677976,
+ 1889445577, 1498812987, 4148069290, 180845535, 2762992206,
+ 2372361916, 588238637, 1921194766, 3706423967, 4112727661,
+ 1531686908, 2796705673, 148555288, 554857194, 2407195515,
+ 26248257, 2952271312, 2251333922, 676868275, 3584149702,
+ 2076793175, 1375858085, 4234771508, 2493785488, 986493953,
+ 319029491, 3178008930, 1083533591, 4009621638, 3342158964,
+ 1767759333, 3887577823, 1239362382, 1612160956, 3464433197,
+ 864482904, 2649647049, 3022443323, 441336490, 1706844275,
+ 3419730402, 3793503504, 1282724993, 2978819316, 535149925,
+ 908921239, 2554697734, 380632892, 3100077741, 2433735263,
+ 1063734222, 3265180603, 1828069930, 1161729752, 3948283721,
+ 2207997677, 770953084, 71007118, 2857626143, 1470763626,
+ 4190274555, 3490330377, 2120394392, 4035494306, 1591758899,
+ 1999168705, 3644880208, 616140069, 2328960180, 2736367686,
+ 225524183,
+ },
};
// ---------------- Private Initializer Prototypes
@@ -5225,9 +5831,10 @@
// ---------------- Initializer Implementations
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
-wuffs_crc32__ieee_hasher__check_wuffs_version(wuffs_crc32__ieee_hasher* self,
- size_t sizeof_star_self,
- uint64_t wuffs_version) {
+wuffs_crc32__ieee_hasher__initialize(wuffs_crc32__ieee_hasher* self,
+ size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags) {
if (!self) {
return wuffs_base__error__bad_receiver;
}
@@ -5238,16 +5845,39 @@
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
return wuffs_base__error__bad_wuffs_version;
}
- if (self->private_impl.magic != 0) {
- return wuffs_base__error__check_wuffs_version_not_applicable;
+
+ if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
+// The whole point of this if-check is to detect an uninitialized *self.
+// We disable the warning on GCC. Clang-5.0 does not have this warning.
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+#endif
+ if (self->private_impl.magic != 0) {
+ return wuffs_base__error__initialize_falsely_claimed_already_zeroed;
+ }
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
+ } else {
+ void* p = &(self->private_impl);
+ size_t n = sizeof(self->private_impl);
+ if ((initialize_flags &
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
+ p = self;
+ n = sizeof(*self);
+ initialize_flags |= WUFFS_INITIALIZE__ALREADY_ZEROED;
+ }
+ memset(p, 0, n);
}
+
self->private_impl.magic = WUFFS_BASE__MAGIC;
return NULL;
}
size_t //
sizeof__wuffs_crc32__ieee_hasher() {
- return sizeof((wuffs_crc32__ieee_hasher){});
+ return sizeof(wuffs_crc32__ieee_hasher);
}
// ---------------- Function Implementations
@@ -5265,7 +5895,7 @@
}
uint32_t v_s = 0;
- wuffs_base__slice_u8 v_p = {};
+ wuffs_base__slice_u8 v_p = {0};
v_s = (4294967295 ^ self->private_impl.f_state);
{
@@ -5360,82 +5990,101 @@
// ---------------- Status Codes Implementations
const char* wuffs_deflate__error__bad_huffman_code_over_subscribed =
- "?deflate: bad Huffman code (over-subscribed)";
+ "#deflate: bad Huffman code (over-subscribed)";
const char* wuffs_deflate__error__bad_huffman_code_under_subscribed =
- "?deflate: bad Huffman code (under-subscribed)";
+ "#deflate: bad Huffman code (under-subscribed)";
const char* wuffs_deflate__error__bad_huffman_code_length_count =
- "?deflate: bad Huffman code length count";
+ "#deflate: bad Huffman code length count";
const char* wuffs_deflate__error__bad_huffman_code_length_repetition =
- "?deflate: bad Huffman code length repetition";
+ "#deflate: bad Huffman code length repetition";
const char* wuffs_deflate__error__bad_huffman_code =
- "?deflate: bad Huffman code";
+ "#deflate: bad Huffman code";
const char* wuffs_deflate__error__bad_huffman_minimum_code_length =
- "?deflate: bad Huffman minimum code length";
-const char* wuffs_deflate__error__bad_block = "?deflate: bad block";
-const char* wuffs_deflate__error__bad_distance = "?deflate: bad distance";
+ "#deflate: bad Huffman minimum code length";
+const char* wuffs_deflate__error__bad_block = "#deflate: bad block";
+const char* wuffs_deflate__error__bad_distance = "#deflate: bad distance";
const char* wuffs_deflate__error__bad_distance_code_count =
- "?deflate: bad distance code count";
+ "#deflate: bad distance code count";
const char* wuffs_deflate__error__bad_literal_length_code_count =
- "?deflate: bad literal/length code count";
+ "#deflate: bad literal/length code count";
const char* wuffs_deflate__error__inconsistent_stored_block_length =
- "?deflate: inconsistent stored block length";
+ "#deflate: inconsistent stored block length";
const char* wuffs_deflate__error__missing_end_of_block_code =
- "?deflate: missing end-of-block code";
+ "#deflate: missing end-of-block code";
const char* wuffs_deflate__error__no_huffman_codes =
- "?deflate: no Huffman codes";
+ "#deflate: no Huffman codes";
const char*
wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state =
- "?deflate: internal error: inconsistent Huffman decoder state";
+ "#deflate: internal error: inconsistent Huffman decoder state";
const char* wuffs_deflate__error__internal_error_inconsistent_i_o =
- "?deflate: internal error: inconsistent I/O";
+ "#deflate: internal error: inconsistent I/O";
const char* wuffs_deflate__error__internal_error_inconsistent_distance =
- "?deflate: internal error: inconsistent distance";
+ "#deflate: internal error: inconsistent distance";
const char* wuffs_deflate__error__internal_error_inconsistent_n_bits =
- "?deflate: internal error: inconsistent n_bits";
+ "#deflate: internal error: inconsistent n_bits";
// ---------------- Private Consts
-static const uint8_t wuffs_deflate__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 //
+ wuffs_deflate__code_order[19] //
+ WUFFS_BASE__POTENTIALLY_UNUSED = {
+ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15,
};
-static const uint8_t wuffs_deflate__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,
- 12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252,
- 2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242,
- 10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250,
- 6, 134, 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246,
- 14, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190, 126, 254,
- 1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209, 49, 177, 113, 241,
- 9, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249,
- 5, 133, 69, 197, 37, 165, 101, 229, 21, 149, 85, 213, 53, 181, 117, 245,
- 13, 141, 77, 205, 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253,
- 3, 131, 67, 195, 35, 163, 99, 227, 19, 147, 83, 211, 51, 179, 115, 243,
- 11, 139, 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251,
- 7, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247,
- 15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255,
+static const uint8_t //
+ wuffs_deflate__reverse8[256] //
+ WUFFS_BASE__POTENTIALLY_UNUSED = {
+ 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, 12, 140, 76, 204, 44, 172, 108, 236,
+ 28, 156, 92, 220, 60, 188, 124, 252, 2, 130, 66, 194, 34, 162,
+ 98, 226, 18, 146, 82, 210, 50, 178, 114, 242, 10, 138, 74, 202,
+ 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250, 6, 134,
+ 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246,
+ 14, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190,
+ 126, 254, 1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209,
+ 49, 177, 113, 241, 9, 137, 73, 201, 41, 169, 105, 233, 25, 153,
+ 89, 217, 57, 185, 121, 249, 5, 133, 69, 197, 37, 165, 101, 229,
+ 21, 149, 85, 213, 53, 181, 117, 245, 13, 141, 77, 205, 45, 173,
+ 109, 237, 29, 157, 93, 221, 61, 189, 125, 253, 3, 131, 67, 195,
+ 35, 163, 99, 227, 19, 147, 83, 211, 51, 179, 115, 243, 11, 139,
+ 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251,
+ 7, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183,
+ 119, 247, 15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223,
+ 63, 191, 127, 255,
};
-static const uint32_t wuffs_deflate__lcode_magic_numbers[32] = {
- 1073741824, 1073742080, 1073742336, 1073742592, 1073742848, 1073743104,
- 1073743360, 1073743616, 1073743888, 1073744400, 1073744912, 1073745424,
- 1073745952, 1073746976, 1073748000, 1073749024, 1073750064, 1073752112,
- 1073754160, 1073756208, 1073758272, 1073762368, 1073766464, 1073770560,
- 1073774672, 1073782864, 1073791056, 1073799248, 1073807104, 134217728,
- 134217728, 134217728,
+static const uint32_t //
+ wuffs_deflate__lcode_magic_numbers[32] //
+ WUFFS_BASE__POTENTIALLY_UNUSED = {
+ 1073741824, 1073742080, 1073742336, 1073742592, 1073742848, 1073743104,
+ 1073743360, 1073743616, 1073743888, 1073744400, 1073744912, 1073745424,
+ 1073745952, 1073746976, 1073748000, 1073749024, 1073750064, 1073752112,
+ 1073754160, 1073756208, 1073758272, 1073762368, 1073766464, 1073770560,
+ 1073774672, 1073782864, 1073791056, 1073799248, 1073807104, 134217728,
+ 134217728, 134217728,
};
-static const uint32_t wuffs_deflate__dcode_magic_numbers[32] = {
- 1073741824, 1073742080, 1073742336, 1073742592, 1073742864, 1073743376,
- 1073743904, 1073744928, 1073745968, 1073748016, 1073750080, 1073754176,
- 1073758288, 1073766480, 1073774688, 1073791072, 1073807472, 1073840240,
- 1073873024, 1073938560, 1074004112, 1074135184, 1074266272, 1074528416,
- 1074790576, 1075314864, 1075839168, 1076887744, 1077936336, 1080033488,
- 134217728, 134217728,
+static const uint32_t //
+ wuffs_deflate__dcode_magic_numbers[32] //
+ WUFFS_BASE__POTENTIALLY_UNUSED = {
+ 1073741824, 1073742080, 1073742336, 1073742592, 1073742864, 1073743376,
+ 1073743904, 1073744928, 1073745968, 1073748016, 1073750080, 1073754176,
+ 1073758288, 1073766480, 1073774688, 1073791072, 1073807472, 1073840240,
+ 1073873024, 1073938560, 1074004112, 1074135184, 1074266272, 1074528416,
+ 1074790576, 1075314864, 1075839168, 1076887744, 1077936336, 1080033488,
+ 134217728, 134217728,
};
+static const uint32_t //
+ wuffs_deflate__huffs_table_size //
+ WUFFS_BASE__POTENTIALLY_UNUSED = 1024;
+
+static const uint32_t //
+ wuffs_deflate__huffs_table_mask //
+ WUFFS_BASE__POTENTIALLY_UNUSED = 1023;
+
// ---------------- Private Initializer Prototypes
// ---------------- Private Function Prototypes
@@ -5477,9 +6126,10 @@
// ---------------- Initializer Implementations
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
-wuffs_deflate__decoder__check_wuffs_version(wuffs_deflate__decoder* self,
- size_t sizeof_star_self,
- uint64_t wuffs_version) {
+wuffs_deflate__decoder__initialize(wuffs_deflate__decoder* self,
+ size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags) {
if (!self) {
return wuffs_base__error__bad_receiver;
}
@@ -5490,33 +6140,72 @@
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
return wuffs_base__error__bad_wuffs_version;
}
- if (self->private_impl.magic != 0) {
- return wuffs_base__error__check_wuffs_version_not_applicable;
+
+ if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
+// The whole point of this if-check is to detect an uninitialized *self.
+// We disable the warning on GCC. Clang-5.0 does not have this warning.
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+#endif
+ if (self->private_impl.magic != 0) {
+ return wuffs_base__error__initialize_falsely_claimed_already_zeroed;
+ }
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
+ } else {
+ void* p = &(self->private_impl);
+ size_t n = sizeof(self->private_impl);
+ if ((initialize_flags &
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
+ p = self;
+ n = sizeof(*self);
+ initialize_flags |= WUFFS_INITIALIZE__ALREADY_ZEROED;
+ }
+ memset(p, 0, n);
}
+
self->private_impl.magic = WUFFS_BASE__MAGIC;
return NULL;
}
size_t //
sizeof__wuffs_deflate__decoder() {
- return sizeof((wuffs_deflate__decoder){});
+ return sizeof(wuffs_deflate__decoder);
}
// ---------------- Function Implementations
+// -------- func deflate.decoder.workbuf_len
+
+WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 //
+wuffs_deflate__decoder__workbuf_len(const wuffs_deflate__decoder* self) {
+ if (!self) {
+ return wuffs_base__utility__make_range_ii_u64(0, 0);
+ }
+ if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
+ (self->private_impl.magic != WUFFS_BASE__DISABLED)) {
+ return wuffs_base__utility__make_range_ii_u64(0, 0);
+ }
+
+ return wuffs_base__utility__make_range_ii_u64(1, 1);
+}
+
// -------- func deflate.decoder.decode_io_writer
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_deflate__decoder__decode_io_writer(wuffs_deflate__decoder* self,
wuffs_base__io_writer a_dst,
- wuffs_base__io_reader a_src) {
+ wuffs_base__io_reader a_src,
+ wuffs_base__slice_u8 a_workbuf) {
if (!self) {
return wuffs_base__error__bad_receiver;
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return (self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
- : wuffs_base__error__check_wuffs_version_missing;
+ : wuffs_base__error__initialize_not_called;
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 1)) {
@@ -5527,15 +6216,13 @@
wuffs_base__status status = NULL;
wuffs_base__status v_status = NULL;
- wuffs_base__slice_u8 v_written = {};
+ wuffs_base__slice_u8 v_written = {0};
uint64_t v_n_copied = 0;
uint32_t v_already_full = 0;
uint8_t* iop_a_dst = NULL;
- uint8_t* io0_a_dst = NULL;
- uint8_t* io1_a_dst = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_dst);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_dst);
+ uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst.private_impl.buf) {
iop_a_dst =
a_dst.private_impl.buf->data.ptr + a_dst.private_impl.buf->meta.wi;
@@ -5551,8 +6238,7 @@
io1_a_dst = a_dst.private_impl.limit;
}
- uint32_t coro_susp_point =
- self->private_impl.c_decode_io_writer[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_io_writer[0];
if (coro_susp_point) {
}
switch (coro_susp_point) {
@@ -5563,7 +6249,7 @@
{
if (a_dst.private_impl.buf) {
a_dst.private_impl.buf->meta.wi =
- iop_a_dst - a_dst.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_dst - a_dst.private_impl.buf->data.ptr));
}
wuffs_base__status t_0 =
wuffs_deflate__decoder__decode_blocks(self, a_dst, a_src);
@@ -5583,35 +6269,25 @@
}
goto ok;
}
- v_written = ((wuffs_base__slice_u8){
- .ptr = a_dst.private_impl.mark,
- .len = (size_t)(iop_a_dst - a_dst.private_impl.mark),
- });
+ v_written = wuffs_base__make_slice_u8(
+ a_dst.private_impl.mark,
+ (size_t)(iop_a_dst - a_dst.private_impl.mark));
if (((uint64_t)(v_written.len)) >= 32768) {
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,
- }),
+ wuffs_base__make_slice_u8(self->private_data.f_history, 32768),
v_written);
self->private_impl.f_history_index = 32768;
} else {
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,
- }),
+ wuffs_base__make_slice_u8(self->private_data.f_history, 32768),
(self->private_impl.f_history_index & 32767)),
v_written);
if (v_n_copied < ((uint64_t)(v_written.len))) {
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,
- }),
+ wuffs_base__make_slice_u8(self->private_data.f_history, 32768),
v_written);
self->private_impl.f_history_index =
(((uint32_t)((v_n_copied & 32767))) + 32768);
@@ -5631,20 +6307,20 @@
goto ok;
ok:
- self->private_impl.c_decode_io_writer[0].coro_susp_point = 0;
+ self->private_impl.p_decode_io_writer[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_io_writer[0].coro_susp_point = coro_susp_point;
+ self->private_impl.p_decode_io_writer[0] = coro_susp_point;
self->private_impl.active_coroutine = 1;
goto exit;
exit:
if (a_dst.private_impl.buf) {
a_dst.private_impl.buf->meta.wi =
- iop_a_dst - a_dst.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_dst - a_dst.private_impl.buf->data.ptr));
}
if (wuffs_base__status__is_error(status)) {
@@ -5667,10 +6343,8 @@
wuffs_base__status v_status = NULL;
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -5683,10 +6357,9 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point =
- self->private_impl.c_decode_blocks[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_blocks[0];
if (coro_susp_point) {
- v_final = self->private_impl.c_decode_blocks[0].v_final;
+ v_final = self->private_data.s_decode_blocks[0].v_final;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -5713,7 +6386,7 @@
if (v_type == 0) {
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
status =
@@ -5741,7 +6414,7 @@
} else if (v_type == 2) {
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
status = wuffs_deflate__decoder__init_dynamic_huffman(self, a_src);
@@ -5760,7 +6433,7 @@
while (true) {
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
v_status =
wuffs_deflate__decoder__decode_huffman_fast(self, a_dst, a_src);
@@ -5777,7 +6450,7 @@
}
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
status =
@@ -5797,20 +6470,20 @@
goto ok;
ok:
- self->private_impl.c_decode_blocks[0].coro_susp_point = 0;
+ self->private_impl.p_decode_blocks[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_blocks[0].coro_susp_point = coro_susp_point;
- self->private_impl.c_decode_blocks[0].v_final = v_final;
+ self->private_impl.p_decode_blocks[0] = coro_susp_point;
+ self->private_data.s_decode_blocks[0].v_final = v_final;
goto exit;
exit:
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -5828,10 +6501,8 @@
uint32_t v_n_copied = 0;
uint8_t* iop_a_dst = NULL;
- uint8_t* io0_a_dst = NULL;
- uint8_t* io1_a_dst = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_dst);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_dst);
+ uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst.private_impl.buf) {
iop_a_dst =
a_dst.private_impl.buf->data.ptr + a_dst.private_impl.buf->meta.wi;
@@ -5847,10 +6518,8 @@
io1_a_dst = a_dst.private_impl.limit;
}
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -5863,10 +6532,9 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point =
- self->private_impl.c_decode_uncompressed[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_uncompressed[0];
if (coro_susp_point) {
- v_length = self->private_impl.c_decode_uncompressed[0].v_length;
+ v_length = self->private_data.s_decode_uncompressed[0].v_length;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -5886,7 +6554,7 @@
t_0 = wuffs_base__load_u32le(iop_a_src);
iop_a_src += 4;
} else {
- self->private_impl.c_decode_uncompressed[0].scratch = 0;
+ self->private_data.s_decode_uncompressed[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
@@ -5894,13 +6562,13 @@
goto suspend;
}
uint64_t* scratch =
- &self->private_impl.c_decode_uncompressed[0].scratch;
- uint32_t num_bits_0 = *scratch >> 56;
+ &self->private_data.s_decode_uncompressed[0].scratch;
+ uint32_t num_bits_0 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_0;
if (num_bits_0 == 24) {
- t_0 = *scratch;
+ t_0 = ((uint32_t)(*scratch));
break;
}
num_bits_0 += 8;
@@ -5933,24 +6601,24 @@
goto ok;
ok:
- self->private_impl.c_decode_uncompressed[0].coro_susp_point = 0;
+ self->private_impl.p_decode_uncompressed[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_uncompressed[0].coro_susp_point = coro_susp_point;
- self->private_impl.c_decode_uncompressed[0].v_length = v_length;
+ self->private_impl.p_decode_uncompressed[0] = coro_susp_point;
+ self->private_data.s_decode_uncompressed[0].v_length = v_length;
goto exit;
exit:
if (a_dst.private_impl.buf) {
a_dst.private_impl.buf->meta.wi =
- iop_a_dst - a_dst.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_dst - a_dst.private_impl.buf->data.ptr));
}
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -5964,23 +6632,23 @@
wuffs_base__status v_status = NULL;
while (v_i < 144) {
- self->private_impl.f_code_lengths[v_i] = 8;
+ self->private_data.f_code_lengths[v_i] = 8;
v_i += 1;
}
while (v_i < 256) {
- self->private_impl.f_code_lengths[v_i] = 9;
+ self->private_data.f_code_lengths[v_i] = 9;
v_i += 1;
}
while (v_i < 280) {
- self->private_impl.f_code_lengths[v_i] = 7;
+ self->private_data.f_code_lengths[v_i] = 7;
v_i += 1;
}
while (v_i < 288) {
- self->private_impl.f_code_lengths[v_i] = 8;
+ self->private_data.f_code_lengths[v_i] = 8;
v_i += 1;
}
while (v_i < 320) {
- self->private_impl.f_code_lengths[v_i] = 5;
+ self->private_data.f_code_lengths[v_i] = 5;
v_i += 1;
}
v_status = wuffs_deflate__decoder__init_huff(self, 0, 0, 288, 257);
@@ -6020,10 +6688,8 @@
uint32_t v_b3 = 0;
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -6036,21 +6702,20 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point =
- self->private_impl.c_init_dynamic_huffman[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_init_dynamic_huffman[0];
if (coro_susp_point) {
- v_bits = self->private_impl.c_init_dynamic_huffman[0].v_bits;
- v_n_bits = self->private_impl.c_init_dynamic_huffman[0].v_n_bits;
- v_n_lit = self->private_impl.c_init_dynamic_huffman[0].v_n_lit;
- v_n_dist = self->private_impl.c_init_dynamic_huffman[0].v_n_dist;
- v_n_clen = self->private_impl.c_init_dynamic_huffman[0].v_n_clen;
- v_i = self->private_impl.c_init_dynamic_huffman[0].v_i;
- v_mask = self->private_impl.c_init_dynamic_huffman[0].v_mask;
- v_table_entry = self->private_impl.c_init_dynamic_huffman[0].v_table_entry;
+ v_bits = self->private_data.s_init_dynamic_huffman[0].v_bits;
+ v_n_bits = self->private_data.s_init_dynamic_huffman[0].v_n_bits;
+ v_n_lit = self->private_data.s_init_dynamic_huffman[0].v_n_lit;
+ v_n_dist = self->private_data.s_init_dynamic_huffman[0].v_n_dist;
+ v_n_clen = self->private_data.s_init_dynamic_huffman[0].v_n_clen;
+ v_i = self->private_data.s_init_dynamic_huffman[0].v_i;
+ v_mask = self->private_data.s_init_dynamic_huffman[0].v_mask;
+ v_table_entry = self->private_data.s_init_dynamic_huffman[0].v_table_entry;
v_n_extra_bits =
- self->private_impl.c_init_dynamic_huffman[0].v_n_extra_bits;
- v_rep_symbol = self->private_impl.c_init_dynamic_huffman[0].v_rep_symbol;
- v_rep_count = self->private_impl.c_init_dynamic_huffman[0].v_rep_count;
+ self->private_data.s_init_dynamic_huffman[0].v_n_extra_bits;
+ v_rep_symbol = self->private_data.s_init_dynamic_huffman[0].v_rep_symbol;
+ v_rep_count = self->private_data.s_init_dynamic_huffman[0].v_rep_count;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -6100,14 +6765,14 @@
v_bits |= (v_b1 << v_n_bits);
v_n_bits += 8;
}
- self->private_impl.f_code_lengths[wuffs_deflate__code_order[v_i]] =
+ self->private_data.f_code_lengths[wuffs_deflate__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[wuffs_deflate__code_order[v_i]] = 0;
+ self->private_data.f_code_lengths[wuffs_deflate__code_order[v_i]] = 0;
v_i += 1;
}
v_status = wuffs_deflate__decoder__init_huff(self, 0, 0, 19, 4095);
@@ -6120,7 +6785,7 @@
label_0_continue:;
while (v_i < (v_n_lit + v_n_dist)) {
while (true) {
- v_table_entry = self->private_impl.f_huffs[0][(v_bits & v_mask)];
+ v_table_entry = self->private_data.f_huffs[0][(v_bits & v_mask)];
v_table_entry_n_bits = (v_table_entry & 15);
if (v_n_bits >= v_table_entry_n_bits) {
v_bits >>= v_table_entry_n_bits;
@@ -6147,7 +6812,7 @@
}
v_table_entry = ((v_table_entry >> 8) & 255);
if (v_table_entry < 16) {
- self->private_impl.f_code_lengths[v_i] = ((uint8_t)(v_table_entry));
+ self->private_data.f_code_lengths[v_i] = ((uint8_t)(v_table_entry));
v_i += 1;
goto label_0_continue;
}
@@ -6160,7 +6825,7 @@
status = wuffs_deflate__error__bad_huffman_code_length_repetition;
goto exit;
}
- v_rep_symbol = self->private_impl.f_code_lengths[(v_i - 1)];
+ v_rep_symbol = (self->private_data.f_code_lengths[(v_i - 1)] & 15);
v_rep_count = 3;
} else if (v_table_entry == 17) {
v_n_extra_bits = 3;
@@ -6196,7 +6861,7 @@
status = wuffs_deflate__error__bad_huffman_code_length_count;
goto exit;
}
- self->private_impl.f_code_lengths[v_i] = v_rep_symbol;
+ self->private_data.f_code_lengths[v_i] = v_rep_symbol;
v_i += 1;
v_rep_count -= 1;
}
@@ -6205,7 +6870,7 @@
status = wuffs_deflate__error__bad_huffman_code_length_count;
goto exit;
}
- if (self->private_impl.f_code_lengths[256] == 0) {
+ if (self->private_data.f_code_lengths[256] == 0) {
status = wuffs_deflate__error__missing_end_of_block_code;
goto exit;
}
@@ -6225,31 +6890,30 @@
goto ok;
ok:
- self->private_impl.c_init_dynamic_huffman[0].coro_susp_point = 0;
+ self->private_impl.p_init_dynamic_huffman[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_init_dynamic_huffman[0].coro_susp_point =
- coro_susp_point;
- self->private_impl.c_init_dynamic_huffman[0].v_bits = v_bits;
- self->private_impl.c_init_dynamic_huffman[0].v_n_bits = v_n_bits;
- self->private_impl.c_init_dynamic_huffman[0].v_n_lit = v_n_lit;
- self->private_impl.c_init_dynamic_huffman[0].v_n_dist = v_n_dist;
- self->private_impl.c_init_dynamic_huffman[0].v_n_clen = v_n_clen;
- self->private_impl.c_init_dynamic_huffman[0].v_i = v_i;
- self->private_impl.c_init_dynamic_huffman[0].v_mask = v_mask;
- self->private_impl.c_init_dynamic_huffman[0].v_table_entry = v_table_entry;
- self->private_impl.c_init_dynamic_huffman[0].v_n_extra_bits = v_n_extra_bits;
- self->private_impl.c_init_dynamic_huffman[0].v_rep_symbol = v_rep_symbol;
- self->private_impl.c_init_dynamic_huffman[0].v_rep_count = v_rep_count;
+ self->private_impl.p_init_dynamic_huffman[0] = coro_susp_point;
+ self->private_data.s_init_dynamic_huffman[0].v_bits = v_bits;
+ self->private_data.s_init_dynamic_huffman[0].v_n_bits = v_n_bits;
+ self->private_data.s_init_dynamic_huffman[0].v_n_lit = v_n_lit;
+ self->private_data.s_init_dynamic_huffman[0].v_n_dist = v_n_dist;
+ self->private_data.s_init_dynamic_huffman[0].v_n_clen = v_n_clen;
+ self->private_data.s_init_dynamic_huffman[0].v_i = v_i;
+ self->private_data.s_init_dynamic_huffman[0].v_mask = v_mask;
+ self->private_data.s_init_dynamic_huffman[0].v_table_entry = v_table_entry;
+ self->private_data.s_init_dynamic_huffman[0].v_n_extra_bits = v_n_extra_bits;
+ self->private_data.s_init_dynamic_huffman[0].v_rep_symbol = v_rep_symbol;
+ self->private_data.s_init_dynamic_huffman[0].v_rep_count = v_rep_count;
goto exit;
exit:
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -6263,13 +6927,13 @@
uint32_t a_n_codes0,
uint32_t a_n_codes1,
uint32_t a_base_symbol) {
- uint16_t v_counts[16] = {};
+ uint16_t v_counts[16] = {0};
uint32_t v_i = 0;
uint32_t v_remaining = 0;
- uint16_t v_offsets[16] = {};
+ uint16_t v_offsets[16] = {0};
uint32_t v_n_symbols = 0;
uint32_t v_count = 0;
- uint16_t v_symbols[320] = {};
+ uint16_t v_symbols[320] = {0};
uint32_t v_min_cl = 0;
uint32_t v_max_cl = 0;
uint32_t v_initial_high_bits = 0;
@@ -6290,10 +6954,17 @@
v_i = a_n_codes0;
while (v_i < a_n_codes1) {
- if (v_counts[self->private_impl.f_code_lengths[v_i]] >= 320) {
+ if (v_counts[(self->private_data.f_code_lengths[v_i] & 15)] >= 320) {
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
}
- v_counts[self->private_impl.f_code_lengths[v_i]] += 1;
+#if defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wconversion"
+#endif
+ v_counts[(self->private_data.f_code_lengths[v_i] & 15)] += 1;
+#if defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
v_i += 1;
}
if ((((uint32_t)(v_counts[0])) + a_n_codes0) == a_n_codes1) {
@@ -6333,13 +7004,20 @@
if (v_i < a_n_codes0) {
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
}
- if (self->private_impl.f_code_lengths[v_i] != 0) {
- if (v_offsets[self->private_impl.f_code_lengths[v_i]] >= 320) {
+ if (self->private_data.f_code_lengths[v_i] != 0) {
+ if (v_offsets[(self->private_data.f_code_lengths[v_i] & 15)] >= 320) {
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
}
- v_symbols[v_offsets[self->private_impl.f_code_lengths[v_i]]] =
+ v_symbols[v_offsets[(self->private_data.f_code_lengths[v_i] & 15)]] =
((uint16_t)((v_i - a_n_codes0)));
- v_offsets[self->private_impl.f_code_lengths[v_i]] += 1;
+#if defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wconversion"
+#endif
+ v_offsets[(self->private_data.f_code_lengths[v_i] & 15)] += 1;
+#if defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
}
v_i += 1;
}
@@ -6382,8 +7060,9 @@
if (v_max_cl < 9) {
v_initial_high_bits = (((uint32_t)(1)) << v_max_cl);
}
- v_prev_cl = ((uint32_t)(self->private_impl.f_code_lengths[(
- a_n_codes0 + ((uint32_t)(v_symbols[0])))]));
+ v_prev_cl = ((uint32_t)((self->private_data.f_code_lengths[(
+ a_n_codes0 + ((uint32_t)(v_symbols[0])))] &
+ 15)));
v_prev_redirect_key = 4294967295;
v_top = 0;
v_next_top = 512;
@@ -6394,8 +7073,9 @@
if ((a_n_codes0 + ((uint32_t)(v_symbols[v_i]))) >= 320) {
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
}
- v_cl = ((uint32_t)(self->private_impl.f_code_lengths[(
- a_n_codes0 + ((uint32_t)(v_symbols[v_i])))]));
+ v_cl = ((uint32_t)((self->private_data.f_code_lengths[(
+ a_n_codes0 + ((uint32_t)(v_symbols[v_i])))] &
+ 15)));
if (v_cl > v_prev_cl) {
v_code <<= (v_cl - v_prev_cl);
if (v_code >= 32768) {
@@ -6430,21 +7110,28 @@
v_j -= 9;
v_initial_high_bits = (((uint32_t)(1)) << v_j);
v_top = v_next_top;
- if ((v_top + (((uint32_t)(1)) << v_j)) > 1234) {
+ if ((v_top + (((uint32_t)(1)) << v_j)) > 1024) {
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
}
v_next_top = (v_top + (((uint32_t)(1)) << v_j));
v_redirect_key =
(((uint32_t)(wuffs_deflate__reverse8[(v_redirect_key >> 1)])) |
((v_redirect_key & 1) << 8));
- self->private_impl.f_huffs[a_which][v_redirect_key] =
+ self->private_data.f_huffs[a_which][v_redirect_key] =
(268435465 | (v_top << 8) | (v_j << 4));
}
}
if ((v_key >= 512) || (v_counts[v_prev_cl] <= 0)) {
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
}
+#if defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wconversion"
+#endif
v_counts[v_prev_cl] -= 1;
+#if defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
v_reversed_key = (((uint32_t)(wuffs_deflate__reverse8[(v_key >> 1)])) |
((v_key & 1) << 8));
v_reversed_key >>= (9 - v_cl);
@@ -6467,10 +7154,10 @@
v_delta = (((uint32_t)(1)) << v_cl);
while (v_high_bits >= v_delta) {
v_high_bits -= v_delta;
- if ((v_top + ((v_high_bits | v_reversed_key) & 511)) >= 1234) {
+ if ((v_top + ((v_high_bits | v_reversed_key) & 511)) >= 1024) {
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
}
- self->private_impl
+ self->private_data
.f_huffs[a_which][(v_top + ((v_high_bits | v_reversed_key) & 511))] =
v_value;
}
@@ -6510,10 +7197,8 @@
uint32_t v_hdist = 0;
uint8_t* iop_a_dst = NULL;
- uint8_t* io0_a_dst = NULL;
- uint8_t* io1_a_dst = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_dst);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_dst);
+ uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst.private_impl.buf) {
iop_a_dst =
a_dst.private_impl.buf->data.ptr + a_dst.private_impl.buf->meta.wi;
@@ -6529,10 +7214,8 @@
io1_a_dst = a_dst.private_impl.limit;
}
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -6559,21 +7242,21 @@
(((uint64_t)(io1_a_src - iop_a_src)) >= 12)) {
if (v_n_bits < 15) {
v_bits |= (((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
v_n_bits += 8;
v_bits |= (((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
v_n_bits += 8;
} else {
}
- v_table_entry = self->private_impl.f_huffs[0][(v_bits & v_lmask)];
+ v_table_entry = self->private_data.f_huffs[0][(v_bits & v_lmask)];
v_table_entry_n_bits = (v_table_entry & 15);
v_bits >>= v_table_entry_n_bits;
v_n_bits -= v_table_entry_n_bits;
if ((v_table_entry >> 31) != 0) {
(wuffs_base__store_u8be(iop_a_dst,
((uint8_t)(((v_table_entry >> 8) & 255)))),
- iop_a_dst += 1, wuffs_base__return_empty_struct());
+ iop_a_dst += 1, wuffs_base__make_empty_struct());
goto label_0_continue;
} else if ((v_table_entry >> 30) != 0) {
} else if ((v_table_entry >> 29) != 0) {
@@ -6582,29 +7265,25 @@
} else if ((v_table_entry >> 28) != 0) {
if (v_n_bits < 15) {
v_bits |= (((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
v_n_bits += 8;
v_bits |= (((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
v_n_bits += 8;
} else {
}
v_redir_top = ((v_table_entry >> 8) & 65535);
v_redir_mask = ((((uint32_t)(1)) << ((v_table_entry >> 4) & 15)) - 1);
- if ((v_redir_top + (v_bits & v_redir_mask)) >= 1234) {
- status =
- wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
- goto exit;
- }
- v_table_entry = self->private_impl
- .f_huffs[0][(v_redir_top + (v_bits & v_redir_mask))];
+ v_table_entry =
+ self->private_data
+ .f_huffs[0][((v_redir_top + (v_bits & v_redir_mask)) & 1023)];
v_table_entry_n_bits = (v_table_entry & 15);
v_bits >>= v_table_entry_n_bits;
v_n_bits -= v_table_entry_n_bits;
if ((v_table_entry >> 31) != 0) {
(wuffs_base__store_u8be(iop_a_dst,
((uint8_t)(((v_table_entry >> 8) & 255)))),
- iop_a_dst += 1, wuffs_base__return_empty_struct());
+ iop_a_dst += 1, wuffs_base__make_empty_struct());
goto label_0_continue;
} else if ((v_table_entry >> 30) != 0) {
} else if ((v_table_entry >> 29) != 0) {
@@ -6635,10 +7314,10 @@
if (v_table_entry_n_bits > 0) {
if (v_n_bits < 15) {
v_bits |= (((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
v_n_bits += 8;
v_bits |= (((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
v_n_bits += 8;
} else {
}
@@ -6653,36 +7332,32 @@
}
if (v_n_bits < 15) {
v_bits |= (((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
v_n_bits += 8;
v_bits |= (((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
v_n_bits += 8;
} else {
}
- v_table_entry = self->private_impl.f_huffs[1][(v_bits & v_dmask)];
+ v_table_entry = self->private_data.f_huffs[1][(v_bits & v_dmask)];
v_table_entry_n_bits = (v_table_entry & 15);
v_bits >>= v_table_entry_n_bits;
v_n_bits -= v_table_entry_n_bits;
if ((v_table_entry >> 28) == 1) {
if (v_n_bits < 15) {
v_bits |= (((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
v_n_bits += 8;
v_bits |= (((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
v_n_bits += 8;
} else {
}
v_redir_top = ((v_table_entry >> 8) & 65535);
v_redir_mask = ((((uint32_t)(1)) << ((v_table_entry >> 4) & 15)) - 1);
- if ((v_redir_top + (v_bits & v_redir_mask)) >= 1234) {
- status =
- wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
- goto exit;
- }
- v_table_entry = self->private_impl
- .f_huffs[1][(v_redir_top + (v_bits & v_redir_mask))];
+ v_table_entry =
+ self->private_data
+ .f_huffs[1][((v_redir_top + (v_bits & v_redir_mask)) & 1023)];
v_table_entry_n_bits = (v_table_entry & 15);
v_bits >>= v_table_entry_n_bits;
v_n_bits -= v_table_entry_n_bits;
@@ -6701,10 +7376,10 @@
v_table_entry_n_bits = ((v_table_entry >> 4) & 15);
if (v_n_bits < v_table_entry_n_bits) {
v_bits |= (((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
v_n_bits += 8;
v_bits |= (((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
v_n_bits += 8;
}
v_dist_minus_1 =
@@ -6737,10 +7412,8 @@
v_n_copied = wuffs_base__io_writer__copy_n_from_slice(
&iop_a_dst, io1_a_dst, v_hlen,
wuffs_base__slice_u8__subslice_i(
- ((wuffs_base__slice_u8){
- .ptr = self->private_impl.f_history,
- .len = 32768,
- }),
+ wuffs_base__make_slice_u8(self->private_data.f_history,
+ 32768),
(v_hdist & 32767)));
if (v_hlen <= v_n_copied) {
goto label_1_break;
@@ -6748,10 +7421,7 @@
v_hlen -= v_n_copied;
wuffs_base__io_writer__copy_n_from_slice(
&iop_a_dst, io1_a_dst, v_hlen,
- ((wuffs_base__slice_u8){
- .ptr = self->private_impl.f_history,
- .len = 32768,
- }));
+ wuffs_base__make_slice_u8(self->private_data.f_history, 32768));
goto label_1_break;
}
label_1_break:;
@@ -6775,7 +7445,7 @@
while (v_n_bits >= 8) {
v_n_bits -= 8;
if (iop_a_src > io0_a_src) {
- (iop_a_src--, wuffs_base__return_empty_struct());
+ (iop_a_src--, wuffs_base__make_empty_struct());
} else {
status = wuffs_deflate__error__internal_error_inconsistent_i_o;
goto exit;
@@ -6792,11 +7462,11 @@
exit:
if (a_dst.private_impl.buf) {
a_dst.private_impl.buf->meta.wi =
- iop_a_dst - a_dst.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_dst - a_dst.private_impl.buf->data.ptr));
}
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -6831,10 +7501,8 @@
uint32_t v_hdist = 0;
uint8_t* iop_a_dst = NULL;
- uint8_t* io0_a_dst = NULL;
- uint8_t* io1_a_dst = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_dst);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_dst);
+ uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst.private_impl.buf) {
iop_a_dst =
a_dst.private_impl.buf->data.ptr + a_dst.private_impl.buf->meta.wi;
@@ -6850,10 +7518,8 @@
io1_a_dst = a_dst.private_impl.limit;
}
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -6866,22 +7532,21 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point =
- self->private_impl.c_decode_huffman_slow[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_huffman_slow[0];
if (coro_susp_point) {
- v_bits = self->private_impl.c_decode_huffman_slow[0].v_bits;
- v_n_bits = self->private_impl.c_decode_huffman_slow[0].v_n_bits;
- v_table_entry = self->private_impl.c_decode_huffman_slow[0].v_table_entry;
+ v_bits = self->private_data.s_decode_huffman_slow[0].v_bits;
+ v_n_bits = self->private_data.s_decode_huffman_slow[0].v_n_bits;
+ v_table_entry = self->private_data.s_decode_huffman_slow[0].v_table_entry;
v_table_entry_n_bits =
- self->private_impl.c_decode_huffman_slow[0].v_table_entry_n_bits;
- v_lmask = self->private_impl.c_decode_huffman_slow[0].v_lmask;
- v_dmask = self->private_impl.c_decode_huffman_slow[0].v_dmask;
- v_redir_top = self->private_impl.c_decode_huffman_slow[0].v_redir_top;
- v_redir_mask = self->private_impl.c_decode_huffman_slow[0].v_redir_mask;
- v_length = self->private_impl.c_decode_huffman_slow[0].v_length;
- v_dist_minus_1 = self->private_impl.c_decode_huffman_slow[0].v_dist_minus_1;
- v_hlen = self->private_impl.c_decode_huffman_slow[0].v_hlen;
- v_hdist = self->private_impl.c_decode_huffman_slow[0].v_hdist;
+ self->private_data.s_decode_huffman_slow[0].v_table_entry_n_bits;
+ v_lmask = self->private_data.s_decode_huffman_slow[0].v_lmask;
+ v_dmask = self->private_data.s_decode_huffman_slow[0].v_dmask;
+ v_redir_top = self->private_data.s_decode_huffman_slow[0].v_redir_top;
+ v_redir_mask = self->private_data.s_decode_huffman_slow[0].v_redir_mask;
+ v_length = self->private_data.s_decode_huffman_slow[0].v_length;
+ v_dist_minus_1 = self->private_data.s_decode_huffman_slow[0].v_dist_minus_1;
+ v_hlen = self->private_data.s_decode_huffman_slow[0].v_hlen;
+ v_hdist = self->private_data.s_decode_huffman_slow[0].v_hdist;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -6897,10 +7562,9 @@
v_lmask = ((((uint32_t)(1)) << self->private_impl.f_n_huffs_bits[0]) - 1);
v_dmask = ((((uint32_t)(1)) << self->private_impl.f_n_huffs_bits[1]) - 1);
label_0_continue:;
- while (
- !(self->private_impl.c_decode_huffman_slow[0].coro_susp_point != 0)) {
+ while (!(self->private_impl.p_decode_huffman_slow[0] != 0)) {
while (true) {
- v_table_entry = self->private_impl.f_huffs[0][(v_bits & v_lmask)];
+ v_table_entry = self->private_data.f_huffs[0][(v_bits & v_lmask)];
v_table_entry_n_bits = (v_table_entry & 15);
if (v_n_bits >= v_table_entry_n_bits) {
v_bits >>= v_table_entry_n_bits;
@@ -6936,14 +7600,9 @@
v_redir_top = ((v_table_entry >> 8) & 65535);
v_redir_mask = ((((uint32_t)(1)) << ((v_table_entry >> 4) & 15)) - 1);
while (true) {
- if ((v_redir_top + (v_bits & v_redir_mask)) >= 1234) {
- status =
- wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
- goto exit;
- }
v_table_entry =
- self->private_impl
- .f_huffs[0][(v_redir_top + (v_bits & v_redir_mask))];
+ self->private_data
+ .f_huffs[0][((v_redir_top + (v_bits & v_redir_mask)) & 1023)];
v_table_entry_n_bits = (v_table_entry & 15);
if (v_n_bits >= v_table_entry_n_bits) {
v_bits >>= v_table_entry_n_bits;
@@ -7020,7 +7679,7 @@
v_n_bits -= v_table_entry_n_bits;
}
while (true) {
- v_table_entry = self->private_impl.f_huffs[1][(v_bits & v_dmask)];
+ v_table_entry = self->private_data.f_huffs[1][(v_bits & v_dmask)];
v_table_entry_n_bits = (v_table_entry & 15);
if (v_n_bits >= v_table_entry_n_bits) {
v_bits >>= v_table_entry_n_bits;
@@ -7044,14 +7703,9 @@
v_redir_top = ((v_table_entry >> 8) & 65535);
v_redir_mask = ((((uint32_t)(1)) << ((v_table_entry >> 4) & 15)) - 1);
while (true) {
- if ((v_redir_top + (v_bits & v_redir_mask)) >= 1234) {
- status =
- wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
- goto exit;
- }
v_table_entry =
- self->private_impl
- .f_huffs[1][(v_redir_top + (v_bits & v_redir_mask))];
+ self->private_data
+ .f_huffs[1][((v_redir_top + (v_bits & v_redir_mask)) & 1023)];
v_table_entry_n_bits = (v_table_entry & 15);
if (v_n_bits >= v_table_entry_n_bits) {
v_bits >>= v_table_entry_n_bits;
@@ -7126,10 +7780,8 @@
v_n_copied = wuffs_base__io_writer__copy_n_from_slice(
&iop_a_dst, io1_a_dst, v_hlen,
wuffs_base__slice_u8__subslice_i(
- ((wuffs_base__slice_u8){
- .ptr = self->private_impl.f_history,
- .len = 32768,
- }),
+ wuffs_base__make_slice_u8(self->private_data.f_history,
+ 32768),
(v_hdist & 32767)));
if (v_hlen <= v_n_copied) {
v_hlen = 0;
@@ -7151,10 +7803,8 @@
v_n_copied = wuffs_base__io_writer__copy_n_from_slice(
&iop_a_dst, io1_a_dst, v_hlen,
wuffs_base__slice_u8__subslice_i(
- ((wuffs_base__slice_u8){
- .ptr = self->private_impl.f_history,
- .len = 32768,
- }),
+ wuffs_base__make_slice_u8(self->private_data.f_history,
+ 32768),
(v_hdist & 32767)));
if (v_hlen <= v_n_copied) {
v_hlen = 0;
@@ -7196,36 +7846,36 @@
goto ok;
ok:
- self->private_impl.c_decode_huffman_slow[0].coro_susp_point = 0;
+ self->private_impl.p_decode_huffman_slow[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_huffman_slow[0].coro_susp_point = coro_susp_point;
- self->private_impl.c_decode_huffman_slow[0].v_bits = v_bits;
- self->private_impl.c_decode_huffman_slow[0].v_n_bits = v_n_bits;
- self->private_impl.c_decode_huffman_slow[0].v_table_entry = v_table_entry;
- self->private_impl.c_decode_huffman_slow[0].v_table_entry_n_bits =
+ self->private_impl.p_decode_huffman_slow[0] = coro_susp_point;
+ self->private_data.s_decode_huffman_slow[0].v_bits = v_bits;
+ self->private_data.s_decode_huffman_slow[0].v_n_bits = v_n_bits;
+ self->private_data.s_decode_huffman_slow[0].v_table_entry = v_table_entry;
+ self->private_data.s_decode_huffman_slow[0].v_table_entry_n_bits =
v_table_entry_n_bits;
- self->private_impl.c_decode_huffman_slow[0].v_lmask = v_lmask;
- self->private_impl.c_decode_huffman_slow[0].v_dmask = v_dmask;
- self->private_impl.c_decode_huffman_slow[0].v_redir_top = v_redir_top;
- self->private_impl.c_decode_huffman_slow[0].v_redir_mask = v_redir_mask;
- self->private_impl.c_decode_huffman_slow[0].v_length = v_length;
- self->private_impl.c_decode_huffman_slow[0].v_dist_minus_1 = v_dist_minus_1;
- self->private_impl.c_decode_huffman_slow[0].v_hlen = v_hlen;
- self->private_impl.c_decode_huffman_slow[0].v_hdist = v_hdist;
+ self->private_data.s_decode_huffman_slow[0].v_lmask = v_lmask;
+ self->private_data.s_decode_huffman_slow[0].v_dmask = v_dmask;
+ self->private_data.s_decode_huffman_slow[0].v_redir_top = v_redir_top;
+ self->private_data.s_decode_huffman_slow[0].v_redir_mask = v_redir_mask;
+ self->private_data.s_decode_huffman_slow[0].v_length = v_length;
+ self->private_data.s_decode_huffman_slow[0].v_dist_minus_1 = v_dist_minus_1;
+ self->private_data.s_decode_huffman_slow[0].v_hlen = v_hlen;
+ self->private_data.s_decode_huffman_slow[0].v_hdist = v_hdist;
goto exit;
exit:
if (a_dst.private_impl.buf) {
a_dst.private_impl.buf->meta.wi =
- iop_a_dst - a_dst.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_dst - a_dst.private_impl.buf->data.ptr));
}
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -7238,9 +7888,9 @@
// ---------------- Status Codes Implementations
-const char* wuffs_lzw__error__bad_code = "?lzw: bad code";
+const char* wuffs_lzw__error__bad_code = "#lzw: bad code";
const char* wuffs_lzw__error__internal_error_inconsistent_i_o =
- "?lzw: internal error: inconsistent I/O";
+ "#lzw: internal error: inconsistent I/O";
// ---------------- Private Consts
@@ -7259,9 +7909,10 @@
// ---------------- Initializer Implementations
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
-wuffs_lzw__decoder__check_wuffs_version(wuffs_lzw__decoder* self,
- size_t sizeof_star_self,
- uint64_t wuffs_version) {
+wuffs_lzw__decoder__initialize(wuffs_lzw__decoder* self,
+ size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags) {
if (!self) {
return wuffs_base__error__bad_receiver;
}
@@ -7272,16 +7923,39 @@
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
return wuffs_base__error__bad_wuffs_version;
}
- if (self->private_impl.magic != 0) {
- return wuffs_base__error__check_wuffs_version_not_applicable;
+
+ if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
+// The whole point of this if-check is to detect an uninitialized *self.
+// We disable the warning on GCC. Clang-5.0 does not have this warning.
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+#endif
+ if (self->private_impl.magic != 0) {
+ return wuffs_base__error__initialize_falsely_claimed_already_zeroed;
+ }
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
+ } else {
+ void* p = &(self->private_impl);
+ size_t n = sizeof(self->private_impl);
+ if ((initialize_flags &
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
+ p = self;
+ n = sizeof(*self);
+ initialize_flags |= WUFFS_INITIALIZE__ALREADY_ZEROED;
+ }
+ memset(p, 0, n);
}
+
self->private_impl.magic = WUFFS_BASE__MAGIC;
return NULL;
}
size_t //
sizeof__wuffs_lzw__decoder() {
- return sizeof((wuffs_lzw__decoder){});
+ return sizeof(wuffs_lzw__decoder);
}
// ---------------- Function Implementations
@@ -7291,18 +7965,33 @@
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct //
wuffs_lzw__decoder__set_literal_width(wuffs_lzw__decoder* self, uint32_t a_lw) {
if (!self) {
- return ((wuffs_base__empty_struct){});
+ return wuffs_base__make_empty_struct();
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
- return ((wuffs_base__empty_struct){});
+ return wuffs_base__make_empty_struct();
}
if (a_lw < 2 || a_lw > 8) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
- return ((wuffs_base__empty_struct){});
+ return wuffs_base__make_empty_struct();
}
- self->private_impl.f_lw = a_lw;
- return ((wuffs_base__empty_struct){});
+ self->private_impl.f_set_literal_width_arg = a_lw;
+ return wuffs_base__make_empty_struct();
+}
+
+// -------- func lzw.decoder.workbuf_len
+
+WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 //
+wuffs_lzw__decoder__workbuf_len(const wuffs_lzw__decoder* self) {
+ if (!self) {
+ return wuffs_base__utility__make_range_ii_u64(0, 0);
+ }
+ if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
+ (self->private_impl.magic != WUFFS_BASE__DISABLED)) {
+ return wuffs_base__utility__make_range_ii_u64(0, 0);
+ }
+
+ return wuffs_base__utility__make_range_ii_u64(0, 0);
}
// -------- func lzw.decoder.decode_io_writer
@@ -7310,14 +7999,15 @@
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_lzw__decoder__decode_io_writer(wuffs_lzw__decoder* self,
wuffs_base__io_writer a_dst,
- wuffs_base__io_reader a_src) {
+ wuffs_base__io_reader a_src,
+ wuffs_base__slice_u8 a_workbuf) {
if (!self) {
return wuffs_base__error__bad_receiver;
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return (self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
- : wuffs_base__error__check_wuffs_version_missing;
+ : wuffs_base__error__initialize_not_called;
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 1)) {
@@ -7329,16 +8019,16 @@
uint32_t v_i = 0;
- uint32_t coro_susp_point =
- self->private_impl.c_decode_io_writer[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_io_writer[0];
if (coro_susp_point) {
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
self->private_impl.f_literal_width = 8;
- if (self->private_impl.f_lw >= 2) {
- self->private_impl.f_literal_width = self->private_impl.f_lw;
+ if (self->private_impl.f_set_literal_width_arg >= 2) {
+ self->private_impl.f_literal_width =
+ self->private_impl.f_set_literal_width_arg;
}
self->private_impl.f_clear_code =
(((uint32_t)(1)) << self->private_impl.f_literal_width);
@@ -7352,8 +8042,8 @@
self->private_impl.f_output_wi = 0;
v_i = 0;
while (v_i < self->private_impl.f_clear_code) {
- self->private_impl.f_lm1s[v_i] = 0;
- self->private_impl.f_suffixes[v_i][0] = ((uint8_t)(v_i));
+ self->private_data.f_lm1s[v_i] = 0;
+ self->private_data.f_suffixes[v_i][0] = ((uint8_t)(v_i));
v_i += 1;
}
label_0_continue:;
@@ -7385,13 +8075,13 @@
goto ok;
ok:
- self->private_impl.c_decode_io_writer[0].coro_susp_point = 0;
+ self->private_impl.p_decode_io_writer[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_io_writer[0].coro_susp_point = coro_susp_point;
+ self->private_impl.p_decode_io_writer[0] = coro_susp_point;
self->private_impl.active_coroutine = 1;
goto exit;
@@ -7424,10 +8114,8 @@
uint16_t v_lm1_a = 0;
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -7452,15 +8140,14 @@
if (v_n_bits < v_width) {
if (((uint64_t)(io1_a_src - iop_a_src)) >= 4) {
v_bits |= (wuffs_base__load_u32le(iop_a_src) << v_n_bits);
- (iop_a_src += ((31 - v_n_bits) >> 3),
- wuffs_base__return_empty_struct());
+ (iop_a_src += ((31 - v_n_bits) >> 3), wuffs_base__make_empty_struct());
v_n_bits |= 24;
} else if (((uint64_t)(io1_a_src - iop_a_src)) <= 0) {
self->private_impl.f_read_from_return_value = 2;
goto label_0_break;
} else {
v_bits |= (((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
v_n_bits += 8;
if (v_n_bits >= v_width) {
} else if (((uint64_t)(io1_a_src - iop_a_src)) <= 0) {
@@ -7469,7 +8156,7 @@
} else {
v_bits |=
(((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
v_n_bits += 8;
if (v_n_bits < v_width) {
self->private_impl.f_read_from_return_value = 4;
@@ -7482,23 +8169,23 @@
v_bits >>= v_width;
v_n_bits -= v_width;
if (v_code < v_clear_code) {
- self->private_impl.f_output[v_output_wi] = ((uint8_t)(v_code));
+ self->private_data.f_output[v_output_wi] = ((uint8_t)(v_code));
v_output_wi = ((v_output_wi + 1) & 8191);
if (v_save_code <= 4095) {
- v_lm1_a = ((self->private_impl.f_lm1s[v_prev_code] + 1) & 4095);
- self->private_impl.f_lm1s[v_save_code] = v_lm1_a;
+ v_lm1_a = ((self->private_data.f_lm1s[v_prev_code] + 1) & 4095);
+ self->private_data.f_lm1s[v_save_code] = v_lm1_a;
if ((v_lm1_a % 8) != 0) {
self->private_impl.f_prefixes[v_save_code] =
self->private_impl.f_prefixes[v_prev_code];
- memcpy(self->private_impl.f_suffixes[v_save_code],
- self->private_impl.f_suffixes[v_prev_code],
- sizeof(self->private_impl.f_suffixes[v_save_code]));
- self->private_impl.f_suffixes[v_save_code][(v_lm1_a % 8)] =
+ memcpy(self->private_data.f_suffixes[v_save_code],
+ self->private_data.f_suffixes[v_prev_code],
+ sizeof(self->private_data.f_suffixes[v_save_code]));
+ self->private_data.f_suffixes[v_save_code][(v_lm1_a % 8)] =
((uint8_t)(v_code));
} else {
self->private_impl.f_prefixes[v_save_code] =
((uint16_t)(v_prev_code));
- self->private_impl.f_suffixes[v_save_code][0] = ((uint8_t)(v_code));
+ self->private_data.f_suffixes[v_save_code][0] = ((uint8_t)(v_code));
}
v_save_code += 1;
if (v_width < 12) {
@@ -7520,15 +8207,15 @@
v_c = v_prev_code;
}
v_o = ((v_output_wi +
- (((uint32_t)(self->private_impl.f_lm1s[v_c])) & 4294967288)) &
+ (((uint32_t)(self->private_data.f_lm1s[v_c])) & 4294967288)) &
8191);
v_output_wi =
- ((v_output_wi + 1 + ((uint32_t)(self->private_impl.f_lm1s[v_c]))) &
+ ((v_output_wi + 1 + ((uint32_t)(self->private_data.f_lm1s[v_c]))) &
8191);
- v_steps = (((uint32_t)(self->private_impl.f_lm1s[v_c])) >> 3);
+ v_steps = (((uint32_t)(self->private_data.f_lm1s[v_c])) >> 3);
while (true) {
- memcpy((self->private_impl.f_output) + (v_o),
- (self->private_impl.f_suffixes[v_c]), 8);
+ memcpy((self->private_data.f_output) + (v_o),
+ (self->private_data.f_suffixes[v_c]), 8);
if (v_steps <= 0) {
goto label_1_break;
}
@@ -7537,26 +8224,26 @@
v_c = ((uint32_t)(self->private_impl.f_prefixes[v_c]));
}
label_1_break:;
- v_first_byte = self->private_impl.f_suffixes[v_c][0];
+ v_first_byte = self->private_data.f_suffixes[v_c][0];
if (v_code == v_save_code) {
- self->private_impl.f_output[v_output_wi] = v_first_byte;
+ self->private_data.f_output[v_output_wi] = v_first_byte;
v_output_wi = ((v_output_wi + 1) & 8191);
}
if (v_save_code <= 4095) {
- v_lm1_b = ((self->private_impl.f_lm1s[v_prev_code] + 1) & 4095);
- self->private_impl.f_lm1s[v_save_code] = v_lm1_b;
+ v_lm1_b = ((self->private_data.f_lm1s[v_prev_code] + 1) & 4095);
+ self->private_data.f_lm1s[v_save_code] = v_lm1_b;
if ((v_lm1_b % 8) != 0) {
self->private_impl.f_prefixes[v_save_code] =
self->private_impl.f_prefixes[v_prev_code];
- memcpy(self->private_impl.f_suffixes[v_save_code],
- self->private_impl.f_suffixes[v_prev_code],
- sizeof(self->private_impl.f_suffixes[v_save_code]));
- self->private_impl.f_suffixes[v_save_code][(v_lm1_b % 8)] =
+ memcpy(self->private_data.f_suffixes[v_save_code],
+ self->private_data.f_suffixes[v_prev_code],
+ sizeof(self->private_data.f_suffixes[v_save_code]));
+ self->private_data.f_suffixes[v_save_code][(v_lm1_b % 8)] =
v_first_byte;
} else {
self->private_impl.f_prefixes[v_save_code] =
((uint16_t)(v_prev_code));
- self->private_impl.f_suffixes[v_save_code][0] =
+ self->private_data.f_suffixes[v_save_code][0] =
((uint8_t)(v_first_byte));
}
v_save_code += 1;
@@ -7579,7 +8266,7 @@
while (v_n_bits >= 8) {
v_n_bits -= 8;
if (iop_a_src > io0_a_src) {
- (iop_a_src--, wuffs_base__return_empty_struct());
+ (iop_a_src--, wuffs_base__make_empty_struct());
} else {
self->private_impl.f_read_from_return_value = 4;
goto label_2_break;
@@ -7595,10 +8282,10 @@
self->private_impl.f_output_wi = v_output_wi;
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
- return ((wuffs_base__empty_struct){});
+ return wuffs_base__make_empty_struct();
}
// -------- func lzw.decoder.write_to
@@ -7608,14 +8295,12 @@
wuffs_base__io_writer a_dst) {
wuffs_base__status status = NULL;
- wuffs_base__slice_u8 v_s = {};
+ wuffs_base__slice_u8 v_s = {0};
uint64_t v_n = 0;
uint8_t* iop_a_dst = NULL;
- uint8_t* io0_a_dst = NULL;
- uint8_t* io1_a_dst = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_dst);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_dst);
+ uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst.private_impl.buf) {
iop_a_dst =
a_dst.private_impl.buf->data.ptr + a_dst.private_impl.buf->meta.wi;
@@ -7631,7 +8316,7 @@
io1_a_dst = a_dst.private_impl.limit;
}
- uint32_t coro_susp_point = self->private_impl.c_write_to[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_write_to[0];
if (coro_susp_point) {
}
switch (coro_susp_point) {
@@ -7643,10 +8328,7 @@
goto exit;
}
v_s = wuffs_base__slice_u8__subslice_ij(
- ((wuffs_base__slice_u8){
- .ptr = self->private_impl.f_output,
- .len = 8199,
- }),
+ wuffs_base__make_slice_u8(self->private_data.f_output, 8199),
self->private_impl.f_output_ri, self->private_impl.f_output_wi);
v_n = wuffs_base__io_writer__copy_from_slice(&iop_a_dst, io1_a_dst, v_s);
if (v_n == ((uint64_t)(v_s.len))) {
@@ -7664,19 +8346,19 @@
goto ok;
ok:
- self->private_impl.c_write_to[0].coro_susp_point = 0;
+ self->private_impl.p_write_to[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_write_to[0].coro_susp_point = coro_susp_point;
+ self->private_impl.p_write_to[0] = coro_susp_point;
goto exit;
exit:
if (a_dst.private_impl.buf) {
a_dst.private_impl.buf->meta.wi =
- iop_a_dst - a_dst.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_dst - a_dst.private_impl.buf->data.ptr));
}
return status;
@@ -7687,20 +8369,17 @@
WUFFS_BASE__MAYBE_STATIC wuffs_base__slice_u8 //
wuffs_lzw__decoder__flush(wuffs_lzw__decoder* self) {
if (!self) {
- return ((wuffs_base__slice_u8){});
+ return wuffs_base__make_slice_u8(NULL, 0);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
- return ((wuffs_base__slice_u8){});
+ return wuffs_base__make_slice_u8(NULL, 0);
}
- wuffs_base__slice_u8 v_s = {};
+ wuffs_base__slice_u8 v_s = {0};
if (self->private_impl.f_output_ri <= self->private_impl.f_output_wi) {
v_s = wuffs_base__slice_u8__subslice_ij(
- ((wuffs_base__slice_u8){
- .ptr = self->private_impl.f_output,
- .len = 8199,
- }),
+ wuffs_base__make_slice_u8(self->private_data.f_output, 8199),
self->private_impl.f_output_ri, self->private_impl.f_output_wi);
}
self->private_impl.f_output_ri = 0;
@@ -7714,33 +8393,38 @@
// ---------------- Status Codes Implementations
-const char* wuffs_gif__error__bad_block = "?gif: bad block";
-const char* wuffs_gif__error__bad_extension_label = "?gif: bad extension label";
-const char* wuffs_gif__error__bad_graphic_control = "?gif: bad graphic control";
-const char* wuffs_gif__error__bad_header = "?gif: bad header";
-const char* wuffs_gif__error__bad_literal_width = "?gif: bad literal width";
-const char* wuffs_gif__error__not_enough_pixel_data =
- "?gif: not enough pixel data";
-const char* wuffs_gif__error__too_much_pixel_data = "?gif: too much pixel data";
+const char* wuffs_gif__error__bad_block = "#gif: bad block";
+const char* wuffs_gif__error__bad_extension_label = "#gif: bad extension label";
+const char* wuffs_gif__error__bad_graphic_control = "#gif: bad graphic control";
+const char* wuffs_gif__error__bad_header = "#gif: bad header";
+const char* wuffs_gif__error__bad_literal_width = "#gif: bad literal width";
const char* wuffs_gif__error__internal_error_inconsistent_ri_wi =
- "?gif: internal error: inconsistent ri/wi";
+ "#gif: internal error: inconsistent ri/wi";
// ---------------- Private Consts
-static const uint32_t wuffs_gif__interlace_start[5] = {
- 4294967295, 1, 2, 4, 0,
+static const uint32_t //
+ wuffs_gif__interlace_start[5] //
+ WUFFS_BASE__POTENTIALLY_UNUSED = {
+ 4294967295, 1, 2, 4, 0,
};
-static const uint8_t wuffs_gif__interlace_delta[5] = {
- 1, 2, 4, 8, 8,
+static const uint8_t //
+ wuffs_gif__interlace_delta[5] //
+ WUFFS_BASE__POTENTIALLY_UNUSED = {
+ 1, 2, 4, 8, 8,
};
-static const uint8_t wuffs_gif__animexts1dot0[11] = {
- 65, 78, 73, 77, 69, 88, 84, 83, 49, 46, 48,
+static const uint8_t //
+ wuffs_gif__animexts1dot0[11] //
+ WUFFS_BASE__POTENTIALLY_UNUSED = {
+ 65, 78, 73, 77, 69, 88, 84, 83, 49, 46, 48,
};
-static const uint8_t wuffs_gif__netscape2dot0[11] = {
- 78, 69, 84, 83, 67, 65, 80, 69, 50, 46, 48,
+static const uint8_t //
+ wuffs_gif__netscape2dot0[11] //
+ WUFFS_BASE__POTENTIALLY_UNUSED = {
+ 78, 69, 84, 83, 67, 65, 80, 69, 50, 46, 48,
};
// ---------------- Private Initializer Prototypes
@@ -7805,9 +8489,10 @@
// ---------------- Initializer Implementations
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
-wuffs_gif__decoder__check_wuffs_version(wuffs_gif__decoder* self,
- size_t sizeof_star_self,
- uint64_t wuffs_version) {
+wuffs_gif__decoder__initialize(wuffs_gif__decoder* self,
+ size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags) {
if (!self) {
return wuffs_base__error__bad_receiver;
}
@@ -7818,13 +8503,36 @@
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
return wuffs_base__error__bad_wuffs_version;
}
- if (self->private_impl.magic != 0) {
- return wuffs_base__error__check_wuffs_version_not_applicable;
+
+ if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
+// The whole point of this if-check is to detect an uninitialized *self.
+// We disable the warning on GCC. Clang-5.0 does not have this warning.
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+#endif
+ if (self->private_impl.magic != 0) {
+ return wuffs_base__error__initialize_falsely_claimed_already_zeroed;
+ }
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
+ } else {
+ void* p = &(self->private_impl);
+ size_t n = sizeof(self->private_impl);
+ if ((initialize_flags &
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
+ p = self;
+ n = sizeof(*self);
+ initialize_flags |= WUFFS_INITIALIZE__ALREADY_ZEROED;
+ }
+ memset(p, 0, n);
}
+
{
- wuffs_base__status z = wuffs_lzw__decoder__check_wuffs_version(
- &self->private_impl.f_lzw, sizeof(self->private_impl.f_lzw),
- WUFFS_VERSION);
+ wuffs_base__status z = wuffs_lzw__decoder__initialize(
+ &self->private_data.f_lzw, sizeof(self->private_data.f_lzw),
+ WUFFS_VERSION, initialize_flags);
if (z) {
return z;
}
@@ -7835,7 +8543,7 @@
size_t //
sizeof__wuffs_gif__decoder() {
- return sizeof((wuffs_gif__decoder){});
+ return sizeof(wuffs_gif__decoder);
}
// ---------------- Function Implementations
@@ -7852,7 +8560,7 @@
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return (self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
- : wuffs_base__error__check_wuffs_version_missing;
+ : wuffs_base__error__initialize_not_called;
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 1)) {
@@ -7864,8 +8572,7 @@
bool v_ffio = false;
- uint32_t coro_susp_point =
- self->private_impl.c_decode_image_config[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_image_config[0];
if (coro_susp_point) {
}
switch (coro_susp_point) {
@@ -7875,9 +8582,6 @@
status = wuffs_base__error__bad_call_sequence;
goto exit;
}
- (memset(&self->private_impl.f_dirty_y, 0,
- sizeof((wuffs_base__range_ie_u32){})),
- wuffs_base__return_empty_struct());
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_gif__decoder__decode_header(self, a_src);
if (status) {
@@ -7909,13 +8613,13 @@
goto ok;
ok:
- self->private_impl.c_decode_image_config[0].coro_susp_point = 0;
+ self->private_impl.p_decode_image_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_image_config[0].coro_susp_point = coro_susp_point;
+ self->private_impl.p_decode_image_config[0] = coro_susp_point;
self->private_impl.active_coroutine = 1;
goto exit;
@@ -7933,7 +8637,8 @@
if (!self) {
return 0;
}
- if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
+ if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
+ (self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
@@ -7950,7 +8655,8 @@
if (!self) {
return 0;
}
- if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
+ if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
+ (self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
@@ -7964,7 +8670,8 @@
if (!self) {
return 0;
}
- if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
+ if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
+ (self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
@@ -7976,16 +8683,19 @@
WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32 //
wuffs_gif__decoder__frame_dirty_rect(const wuffs_gif__decoder* self) {
if (!self) {
- return ((wuffs_base__rect_ie_u32){});
+ return wuffs_base__utility__make_rect_ie_u32(0, 0, 0, 0);
}
- if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
- return ((wuffs_base__rect_ie_u32){});
+ if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
+ (self->private_impl.magic != WUFFS_BASE__DISABLED)) {
+ return wuffs_base__utility__make_rect_ie_u32(0, 0, 0, 0);
}
return wuffs_base__utility__make_rect_ie_u32(
- &self->private_impl.f_util, self->private_impl.f_frame_rect_x0,
+ wuffs_base__u32__min(self->private_impl.f_frame_rect_x0,
+ self->private_impl.f_width),
wuffs_base__range_ie_u32__get_min_incl(&self->private_impl.f_dirty_y),
- self->private_impl.f_frame_rect_x1,
+ wuffs_base__u32__min(self->private_impl.f_frame_rect_x1,
+ self->private_impl.f_width),
wuffs_base__range_ie_u32__get_max_excl(&self->private_impl.f_dirty_y));
}
@@ -7994,15 +8704,14 @@
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 //
wuffs_gif__decoder__workbuf_len(const wuffs_gif__decoder* self) {
if (!self) {
- return ((wuffs_base__range_ii_u64){});
+ return wuffs_base__utility__make_range_ii_u64(0, 0);
}
- if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
- return ((wuffs_base__range_ii_u64){});
+ if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
+ (self->private_impl.magic != WUFFS_BASE__DISABLED)) {
+ return wuffs_base__utility__make_range_ii_u64(0, 0);
}
- return wuffs_base__utility__make_range_ii_u64(
- &self->private_impl.f_util, ((uint64_t)(self->private_impl.f_width)),
- ((uint64_t)(self->private_impl.f_width)));
+ return wuffs_base__utility__make_range_ii_u64(1, 1);
}
// -------- func gif.decoder.restart_frame
@@ -8017,7 +8726,7 @@
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return (self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
- : wuffs_base__error__check_wuffs_version_missing;
+ : wuffs_base__error__initialize_not_called;
}
if (self->private_impl.f_call_sequence == 0) {
@@ -8044,7 +8753,7 @@
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return (self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
- : wuffs_base__error__check_wuffs_version_missing;
+ : wuffs_base__error__initialize_not_called;
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 2)) {
@@ -8056,13 +8765,14 @@
uint8_t v_blend = 0;
- uint32_t coro_susp_point =
- self->private_impl.c_decode_frame_config[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
if (coro_susp_point) {
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
+ (memset(&self->private_impl.f_dirty_y, 0, sizeof(wuffs_base__range_ie_u32)),
+ wuffs_base__make_empty_struct());
if (!self->private_impl.f_end_of_data) {
if (self->private_impl.f_call_sequence == 0) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
@@ -8097,7 +8807,6 @@
wuffs_base__frame_config__update(
a_dst,
wuffs_base__utility__make_rect_ie_u32(
- &self->private_impl.f_util,
wuffs_base__u32__min(self->private_impl.f_frame_rect_x0,
self->private_impl.f_width),
wuffs_base__u32__min(self->private_impl.f_frame_rect_y0,
@@ -8106,7 +8815,7 @@
self->private_impl.f_width),
wuffs_base__u32__min(self->private_impl.f_frame_rect_y1,
self->private_impl.f_height)),
- self->private_impl.f_gc_duration,
+ ((wuffs_base__flicks)(self->private_impl.f_gc_duration)),
self->private_impl.f_num_decoded_frame_configs_value,
self->private_impl.f_frame_config_io_position, v_blend,
self->private_impl.f_gc_disposal);
@@ -8117,13 +8826,13 @@
goto ok;
ok:
- self->private_impl.c_decode_frame_config[0].coro_susp_point = 0;
+ self->private_impl.p_decode_frame_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_frame_config[0].coro_susp_point = coro_susp_point;
+ self->private_impl.p_decode_frame_config[0] = coro_susp_point;
self->private_impl.active_coroutine = 2;
goto exit;
@@ -8144,10 +8853,8 @@
uint8_t v_flags = 0;
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -8160,7 +8867,7 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point = self->private_impl.c_skip_frame[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_skip_frame[0];
if (coro_susp_point) {
}
switch (coro_susp_point) {
@@ -8176,17 +8883,18 @@
v_flags = t_0;
}
if ((v_flags & 128) != 0) {
- self->private_impl.c_skip_frame[0].scratch =
+ self->private_data.s_skip_frame[0].scratch =
(((uint32_t)(3)) << (1 + (v_flags & 7)));
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
- if (self->private_impl.c_skip_frame[0].scratch >
+ if (self->private_data.s_skip_frame[0].scratch >
((uint64_t)(io1_a_src - iop_a_src))) {
- self->private_impl.c_skip_frame[0].scratch -= io1_a_src - iop_a_src;
+ self->private_data.s_skip_frame[0].scratch -=
+ ((uint64_t)(io1_a_src - iop_a_src));
iop_a_src = io1_a_src;
status = wuffs_base__suspension__short_read;
goto suspend;
}
- iop_a_src += self->private_impl.c_skip_frame[0].scratch;
+ iop_a_src += self->private_data.s_skip_frame[0].scratch;
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
@@ -8196,7 +8904,7 @@
iop_a_src++;
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
status = wuffs_gif__decoder__skip_blocks(self, a_src);
@@ -8213,19 +8921,19 @@
goto ok;
ok:
- self->private_impl.c_skip_frame[0].coro_susp_point = 0;
+ self->private_impl.p_skip_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_skip_frame[0].coro_susp_point = coro_susp_point;
+ self->private_impl.p_skip_frame[0] = coro_susp_point;
goto exit;
exit:
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -8245,7 +8953,7 @@
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return (self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
- : wuffs_base__error__check_wuffs_version_missing;
+ : wuffs_base__error__initialize_not_called;
}
if (!a_dst) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
@@ -8259,8 +8967,7 @@
self->private_impl.active_coroutine = 0;
wuffs_base__status status = NULL;
- uint32_t coro_susp_point =
- self->private_impl.c_decode_frame[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
if (coro_susp_point) {
}
switch (coro_susp_point) {
@@ -8289,13 +8996,13 @@
goto ok;
ok:
- self->private_impl.c_decode_frame[0].coro_susp_point = 0;
+ self->private_impl.p_decode_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_frame[0].coro_susp_point = coro_susp_point;
+ self->private_impl.p_decode_frame[0] = coro_susp_point;
self->private_impl.active_coroutine = 3;
goto exit;
@@ -8316,7 +9023,7 @@
self->private_impl.f_gc_transparent_index = 0;
self->private_impl.f_gc_disposal = 0;
self->private_impl.f_gc_duration = 0;
- return ((wuffs_base__empty_struct){});
+ return wuffs_base__make_empty_struct();
}
// -------- func gif.decoder.decode_up_to_id_part1
@@ -8329,10 +9036,8 @@
uint8_t v_block_type = 0;
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -8345,8 +9050,7 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point =
- self->private_impl.c_decode_up_to_id_part1[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_up_to_id_part1[0];
if (coro_susp_point) {
}
switch (coro_susp_point) {
@@ -8357,13 +9061,14 @@
(a_src.private_impl.buf
? wuffs_base__u64__sat_add(
a_src.private_impl.buf->meta.pos,
- iop_a_src - a_src.private_impl.buf->data.ptr)
+ ((uint64_t)(iop_a_src - a_src.private_impl.buf->data.ptr)))
: 0);
} else if (self->private_impl.f_frame_config_io_position !=
(a_src.private_impl.buf
? wuffs_base__u64__sat_add(
a_src.private_impl.buf->meta.pos,
- iop_a_src - a_src.private_impl.buf->data.ptr)
+ ((uint64_t)(iop_a_src -
+ a_src.private_impl.buf->data.ptr)))
: 0)) {
status = wuffs_base__error__bad_restart;
goto exit;
@@ -8383,7 +9088,7 @@
if (v_block_type == 33) {
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
status = wuffs_gif__decoder__decode_extension(self, a_src);
@@ -8397,7 +9102,7 @@
} else if (v_block_type == 44) {
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
status = wuffs_gif__decoder__decode_id_part0(self, a_src);
@@ -8421,20 +9126,19 @@
goto ok;
ok:
- self->private_impl.c_decode_up_to_id_part1[0].coro_susp_point = 0;
+ self->private_impl.p_decode_up_to_id_part1[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_up_to_id_part1[0].coro_susp_point =
- coro_susp_point;
+ self->private_impl.p_decode_up_to_id_part1[0] = coro_susp_point;
goto exit;
exit:
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -8447,14 +9151,12 @@
wuffs_base__io_reader a_src) {
wuffs_base__status status = NULL;
- uint8_t v_c[6] = {};
+ uint8_t v_c[6] = {0};
uint32_t v_i = 0;
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -8467,11 +9169,10 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point =
- self->private_impl.c_decode_header[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_header[0];
if (coro_susp_point) {
- memcpy(v_c, self->private_impl.c_decode_header[0].v_c, sizeof(v_c));
- v_i = self->private_impl.c_decode_header[0].v_i;
+ memcpy(v_c, self->private_data.s_decode_header[0].v_c, sizeof(v_c));
+ v_i = self->private_data.s_decode_header[0].v_i;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -8496,21 +9197,21 @@
goto ok;
ok:
- self->private_impl.c_decode_header[0].coro_susp_point = 0;
+ self->private_impl.p_decode_header[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_header[0].coro_susp_point = coro_susp_point;
- memcpy(self->private_impl.c_decode_header[0].v_c, v_c, sizeof(v_c));
- self->private_impl.c_decode_header[0].v_i = v_i;
+ self->private_impl.p_decode_header[0] = coro_susp_point;
+ memcpy(self->private_data.s_decode_header[0].v_c, v_c, sizeof(v_c));
+ self->private_data.s_decode_header[0].v_i = v_i;
goto exit;
exit:
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -8529,10 +9230,8 @@
uint32_t v_argb = 0;
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -8545,12 +9244,12 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point = self->private_impl.c_decode_lsd[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_lsd[0];
if (coro_susp_point) {
- v_flags = self->private_impl.c_decode_lsd[0].v_flags;
+ v_flags = self->private_data.s_decode_lsd[0].v_flags;
v_num_palette_entries =
- self->private_impl.c_decode_lsd[0].v_num_palette_entries;
- v_i = self->private_impl.c_decode_lsd[0].v_i;
+ self->private_data.s_decode_lsd[0].v_num_palette_entries;
+ v_i = self->private_data.s_decode_lsd[0].v_i;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -8562,15 +9261,15 @@
t_0 = ((uint32_t)(wuffs_base__load_u16le(iop_a_src)));
iop_a_src += 2;
} else {
- self->private_impl.c_decode_lsd[0].scratch = 0;
+ self->private_data.s_decode_lsd[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
status = wuffs_base__suspension__short_read;
goto suspend;
}
- uint64_t* scratch = &self->private_impl.c_decode_lsd[0].scratch;
- uint32_t num_bits_0 = *scratch >> 56;
+ uint64_t* scratch = &self->private_data.s_decode_lsd[0].scratch;
+ uint32_t num_bits_0 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_0;
@@ -8591,15 +9290,15 @@
t_1 = ((uint32_t)(wuffs_base__load_u16le(iop_a_src)));
iop_a_src += 2;
} else {
- self->private_impl.c_decode_lsd[0].scratch = 0;
+ self->private_data.s_decode_lsd[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
status = wuffs_base__suspension__short_read;
goto suspend;
}
- uint64_t* scratch = &self->private_impl.c_decode_lsd[0].scratch;
- uint32_t num_bits_1 = *scratch >> 56;
+ uint64_t* scratch = &self->private_data.s_decode_lsd[0].scratch;
+ uint32_t num_bits_1 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_1;
@@ -8622,16 +9321,17 @@
uint8_t t_2 = *iop_a_src++;
v_flags = t_2;
}
- self->private_impl.c_decode_lsd[0].scratch = 2;
+ self->private_data.s_decode_lsd[0].scratch = 2;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
- if (self->private_impl.c_decode_lsd[0].scratch >
+ if (self->private_data.s_decode_lsd[0].scratch >
((uint64_t)(io1_a_src - iop_a_src))) {
- self->private_impl.c_decode_lsd[0].scratch -= io1_a_src - iop_a_src;
+ self->private_data.s_decode_lsd[0].scratch -=
+ ((uint64_t)(io1_a_src - iop_a_src));
iop_a_src = io1_a_src;
status = wuffs_base__suspension__short_read;
goto suspend;
}
- iop_a_src += self->private_impl.c_decode_lsd[0].scratch;
+ iop_a_src += self->private_data.s_decode_lsd[0].scratch;
if ((v_flags & 128) != 0) {
v_num_palette_entries = (((uint32_t)(1)) << (1 + (v_flags & 7)));
v_i = 0;
@@ -8643,15 +9343,15 @@
t_3 = ((uint32_t)(wuffs_base__load_u24be(iop_a_src)));
iop_a_src += 3;
} else {
- self->private_impl.c_decode_lsd[0].scratch = 0;
+ self->private_data.s_decode_lsd[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
status = wuffs_base__suspension__short_read;
goto suspend;
}
- uint64_t* scratch = &self->private_impl.c_decode_lsd[0].scratch;
- uint32_t num_bits_3 = *scratch & 0xFF;
+ uint64_t* scratch = &self->private_data.s_decode_lsd[0].scratch;
+ uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3);
@@ -8666,44 +9366,44 @@
v_argb = t_3;
}
v_argb |= 4278190080;
- self->private_impl.f_palettes[0][((4 * v_i) + 0)] =
+ self->private_data.f_palettes[0][((4 * v_i) + 0)] =
((uint8_t)(((v_argb >> 0) & 255)));
- self->private_impl.f_palettes[0][((4 * v_i) + 1)] =
+ self->private_data.f_palettes[0][((4 * v_i) + 1)] =
((uint8_t)(((v_argb >> 8) & 255)));
- self->private_impl.f_palettes[0][((4 * v_i) + 2)] =
+ self->private_data.f_palettes[0][((4 * v_i) + 2)] =
((uint8_t)(((v_argb >> 16) & 255)));
- self->private_impl.f_palettes[0][((4 * v_i) + 3)] =
+ self->private_data.f_palettes[0][((4 * v_i) + 3)] =
((uint8_t)(((v_argb >> 24) & 255)));
v_i += 1;
}
while (v_i < 256) {
- self->private_impl.f_palettes[0][((4 * v_i) + 0)] = 0;
- self->private_impl.f_palettes[0][((4 * v_i) + 1)] = 0;
- self->private_impl.f_palettes[0][((4 * v_i) + 2)] = 0;
- self->private_impl.f_palettes[0][((4 * v_i) + 3)] = 255;
+ self->private_data.f_palettes[0][((4 * v_i) + 0)] = 0;
+ self->private_data.f_palettes[0][((4 * v_i) + 1)] = 0;
+ self->private_data.f_palettes[0][((4 * v_i) + 2)] = 0;
+ self->private_data.f_palettes[0][((4 * v_i) + 3)] = 255;
v_i += 1;
}
}
goto ok;
ok:
- self->private_impl.c_decode_lsd[0].coro_susp_point = 0;
+ self->private_impl.p_decode_lsd[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_lsd[0].coro_susp_point = coro_susp_point;
- self->private_impl.c_decode_lsd[0].v_flags = v_flags;
- self->private_impl.c_decode_lsd[0].v_num_palette_entries =
+ self->private_impl.p_decode_lsd[0] = coro_susp_point;
+ self->private_data.s_decode_lsd[0].v_flags = v_flags;
+ self->private_data.s_decode_lsd[0].v_num_palette_entries =
v_num_palette_entries;
- self->private_impl.c_decode_lsd[0].v_i = v_i;
+ self->private_data.s_decode_lsd[0].v_i = v_i;
goto exit;
exit:
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -8719,10 +9419,8 @@
uint8_t v_label = 0;
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -8735,8 +9433,7 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point =
- self->private_impl.c_decode_extension[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_extension[0];
if (coro_susp_point) {
}
switch (coro_susp_point) {
@@ -8754,7 +9451,7 @@
if (v_label == 249) {
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
status = wuffs_gif__decoder__decode_gc(self, a_src);
@@ -8770,7 +9467,7 @@
} else if (v_label == 255) {
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
status = wuffs_gif__decoder__decode_ae(self, a_src);
@@ -8786,7 +9483,7 @@
}
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
status = wuffs_gif__decoder__skip_blocks(self, a_src);
@@ -8800,19 +9497,19 @@
goto ok;
ok:
- self->private_impl.c_decode_extension[0].coro_susp_point = 0;
+ self->private_impl.p_decode_extension[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_extension[0].coro_susp_point = coro_susp_point;
+ self->private_impl.p_decode_extension[0] = coro_susp_point;
goto exit;
exit:
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -8828,10 +9525,8 @@
uint8_t v_block_size = 0;
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -8844,8 +9539,7 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point =
- self->private_impl.c_skip_blocks[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_skip_blocks[0];
if (coro_susp_point) {
}
switch (coro_susp_point) {
@@ -8865,33 +9559,34 @@
status = NULL;
goto ok;
}
- self->private_impl.c_skip_blocks[0].scratch = ((uint32_t)(v_block_size));
+ self->private_data.s_skip_blocks[0].scratch = ((uint32_t)(v_block_size));
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
- if (self->private_impl.c_skip_blocks[0].scratch >
+ if (self->private_data.s_skip_blocks[0].scratch >
((uint64_t)(io1_a_src - iop_a_src))) {
- self->private_impl.c_skip_blocks[0].scratch -= io1_a_src - iop_a_src;
+ self->private_data.s_skip_blocks[0].scratch -=
+ ((uint64_t)(io1_a_src - iop_a_src));
iop_a_src = io1_a_src;
status = wuffs_base__suspension__short_read;
goto suspend;
}
- iop_a_src += self->private_impl.c_skip_blocks[0].scratch;
+ iop_a_src += self->private_data.s_skip_blocks[0].scratch;
}
goto ok;
ok:
- self->private_impl.c_skip_blocks[0].coro_susp_point = 0;
+ self->private_impl.p_skip_blocks[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_skip_blocks[0].coro_susp_point = coro_susp_point;
+ self->private_impl.p_skip_blocks[0] = coro_susp_point;
goto exit;
exit:
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -8910,10 +9605,8 @@
bool v_not_netscape = false;
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -8926,11 +9619,11 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point = self->private_impl.c_decode_ae[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_ae[0];
if (coro_susp_point) {
- v_block_size = self->private_impl.c_decode_ae[0].v_block_size;
- v_not_animexts = self->private_impl.c_decode_ae[0].v_not_animexts;
- v_not_netscape = self->private_impl.c_decode_ae[0].v_not_netscape;
+ v_block_size = self->private_data.s_decode_ae[0].v_block_size;
+ v_not_animexts = self->private_data.s_decode_ae[0].v_not_animexts;
+ v_not_netscape = self->private_data.s_decode_ae[0].v_not_netscape;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -8950,16 +9643,17 @@
goto ok;
}
if (v_block_size != 11) {
- self->private_impl.c_decode_ae[0].scratch = ((uint32_t)(v_block_size));
+ self->private_data.s_decode_ae[0].scratch = ((uint32_t)(v_block_size));
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
- if (self->private_impl.c_decode_ae[0].scratch >
+ if (self->private_data.s_decode_ae[0].scratch >
((uint64_t)(io1_a_src - iop_a_src))) {
- self->private_impl.c_decode_ae[0].scratch -= io1_a_src - iop_a_src;
+ self->private_data.s_decode_ae[0].scratch -=
+ ((uint64_t)(io1_a_src - iop_a_src));
iop_a_src = io1_a_src;
status = wuffs_base__suspension__short_read;
goto suspend;
}
- iop_a_src += self->private_impl.c_decode_ae[0].scratch;
+ iop_a_src += self->private_data.s_decode_ae[0].scratch;
goto label_0_break;
}
v_not_animexts = false;
@@ -8979,7 +9673,14 @@
(v_not_animexts || (v_c != wuffs_gif__animexts1dot0[v_block_size]));
v_not_netscape =
(v_not_netscape || (v_c != wuffs_gif__netscape2dot0[v_block_size]));
+#if defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wconversion"
+#endif
v_block_size += 1;
+#if defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
}
if (v_not_animexts && v_not_netscape) {
goto label_0_break;
@@ -8994,16 +9695,17 @@
v_block_size = t_2;
}
if (v_block_size != 3) {
- self->private_impl.c_decode_ae[0].scratch = ((uint32_t)(v_block_size));
+ self->private_data.s_decode_ae[0].scratch = ((uint32_t)(v_block_size));
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
- if (self->private_impl.c_decode_ae[0].scratch >
+ if (self->private_data.s_decode_ae[0].scratch >
((uint64_t)(io1_a_src - iop_a_src))) {
- self->private_impl.c_decode_ae[0].scratch -= io1_a_src - iop_a_src;
+ self->private_data.s_decode_ae[0].scratch -=
+ ((uint64_t)(io1_a_src - iop_a_src));
iop_a_src = io1_a_src;
status = wuffs_base__suspension__short_read;
goto suspend;
}
- iop_a_src += self->private_impl.c_decode_ae[0].scratch;
+ iop_a_src += self->private_data.s_decode_ae[0].scratch;
goto label_0_break;
}
{
@@ -9016,16 +9718,17 @@
v_c = t_3;
}
if (v_c != 1) {
- self->private_impl.c_decode_ae[0].scratch = 2;
+ self->private_data.s_decode_ae[0].scratch = 2;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
- if (self->private_impl.c_decode_ae[0].scratch >
+ if (self->private_data.s_decode_ae[0].scratch >
((uint64_t)(io1_a_src - iop_a_src))) {
- self->private_impl.c_decode_ae[0].scratch -= io1_a_src - iop_a_src;
+ self->private_data.s_decode_ae[0].scratch -=
+ ((uint64_t)(io1_a_src - iop_a_src));
iop_a_src = io1_a_src;
status = wuffs_base__suspension__short_read;
goto suspend;
}
- iop_a_src += self->private_impl.c_decode_ae[0].scratch;
+ iop_a_src += self->private_data.s_decode_ae[0].scratch;
goto label_0_break;
}
{
@@ -9035,15 +9738,15 @@
t_4 = ((uint32_t)(wuffs_base__load_u16le(iop_a_src)));
iop_a_src += 2;
} else {
- self->private_impl.c_decode_ae[0].scratch = 0;
+ self->private_data.s_decode_ae[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
status = wuffs_base__suspension__short_read;
goto suspend;
}
- uint64_t* scratch = &self->private_impl.c_decode_ae[0].scratch;
- uint32_t num_bits_4 = *scratch >> 56;
+ uint64_t* scratch = &self->private_data.s_decode_ae[0].scratch;
+ uint32_t num_bits_4 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_4;
@@ -9067,7 +9770,7 @@
label_0_break:;
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
status = wuffs_gif__decoder__skip_blocks(self, a_src);
@@ -9081,22 +9784,22 @@
goto ok;
ok:
- self->private_impl.c_decode_ae[0].coro_susp_point = 0;
+ self->private_impl.p_decode_ae[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_ae[0].coro_susp_point = coro_susp_point;
- self->private_impl.c_decode_ae[0].v_block_size = v_block_size;
- self->private_impl.c_decode_ae[0].v_not_animexts = v_not_animexts;
- self->private_impl.c_decode_ae[0].v_not_netscape = v_not_netscape;
+ self->private_impl.p_decode_ae[0] = coro_susp_point;
+ self->private_data.s_decode_ae[0].v_block_size = v_block_size;
+ self->private_data.s_decode_ae[0].v_not_animexts = v_not_animexts;
+ self->private_data.s_decode_ae[0].v_not_netscape = v_not_netscape;
goto exit;
exit:
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -9114,10 +9817,8 @@
uint16_t v_gc_duration_centiseconds = 0;
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -9130,7 +9831,7 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point = self->private_impl.c_decode_gc[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_gc[0];
if (coro_susp_point) {
}
switch (coro_susp_point) {
@@ -9178,20 +9879,20 @@
t_2 = wuffs_base__load_u16le(iop_a_src);
iop_a_src += 2;
} else {
- self->private_impl.c_decode_gc[0].scratch = 0;
+ self->private_data.s_decode_gc[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
status = wuffs_base__suspension__short_read;
goto suspend;
}
- uint64_t* scratch = &self->private_impl.c_decode_gc[0].scratch;
- uint32_t num_bits_2 = *scratch >> 56;
+ uint64_t* scratch = &self->private_data.s_decode_gc[0].scratch;
+ uint32_t num_bits_2 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_2;
if (num_bits_2 == 8) {
- t_2 = *scratch;
+ t_2 = ((uint16_t)(*scratch));
break;
}
num_bits_2 += 8;
@@ -9228,19 +9929,19 @@
goto ok;
ok:
- self->private_impl.c_decode_gc[0].coro_susp_point = 0;
+ self->private_impl.p_decode_gc[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_gc[0].coro_susp_point = coro_susp_point;
+ self->private_impl.p_decode_gc[0] = coro_susp_point;
goto exit;
exit:
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -9254,10 +9955,8 @@
wuffs_base__status status = NULL;
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -9270,8 +9969,7 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point =
- self->private_impl.c_decode_id_part0[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_id_part0[0];
if (coro_susp_point) {
}
switch (coro_susp_point) {
@@ -9284,15 +9982,15 @@
t_0 = ((uint32_t)(wuffs_base__load_u16le(iop_a_src)));
iop_a_src += 2;
} else {
- self->private_impl.c_decode_id_part0[0].scratch = 0;
+ self->private_data.s_decode_id_part0[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
status = wuffs_base__suspension__short_read;
goto suspend;
}
- uint64_t* scratch = &self->private_impl.c_decode_id_part0[0].scratch;
- uint32_t num_bits_0 = *scratch >> 56;
+ uint64_t* scratch = &self->private_data.s_decode_id_part0[0].scratch;
+ uint32_t num_bits_0 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_0;
@@ -9313,15 +10011,15 @@
t_1 = ((uint32_t)(wuffs_base__load_u16le(iop_a_src)));
iop_a_src += 2;
} else {
- self->private_impl.c_decode_id_part0[0].scratch = 0;
+ self->private_data.s_decode_id_part0[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
status = wuffs_base__suspension__short_read;
goto suspend;
}
- uint64_t* scratch = &self->private_impl.c_decode_id_part0[0].scratch;
- uint32_t num_bits_1 = *scratch >> 56;
+ uint64_t* scratch = &self->private_data.s_decode_id_part0[0].scratch;
+ uint32_t num_bits_1 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_1;
@@ -9342,15 +10040,15 @@
t_2 = ((uint32_t)(wuffs_base__load_u16le(iop_a_src)));
iop_a_src += 2;
} else {
- self->private_impl.c_decode_id_part0[0].scratch = 0;
+ self->private_data.s_decode_id_part0[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
status = wuffs_base__suspension__short_read;
goto suspend;
}
- uint64_t* scratch = &self->private_impl.c_decode_id_part0[0].scratch;
- uint32_t num_bits_2 = *scratch >> 56;
+ uint64_t* scratch = &self->private_data.s_decode_id_part0[0].scratch;
+ uint32_t num_bits_2 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_2;
@@ -9372,15 +10070,15 @@
t_3 = ((uint32_t)(wuffs_base__load_u16le(iop_a_src)));
iop_a_src += 2;
} else {
- self->private_impl.c_decode_id_part0[0].scratch = 0;
+ self->private_data.s_decode_id_part0[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
status = wuffs_base__suspension__short_read;
goto suspend;
}
- uint64_t* scratch = &self->private_impl.c_decode_id_part0[0].scratch;
- uint32_t num_bits_3 = *scratch >> 56;
+ uint64_t* scratch = &self->private_data.s_decode_id_part0[0].scratch;
+ uint32_t num_bits_3 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_3;
@@ -9406,19 +10104,19 @@
goto ok;
ok:
- self->private_impl.c_decode_id_part0[0].coro_susp_point = 0;
+ self->private_impl.p_decode_id_part0[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_id_part0[0].coro_susp_point = coro_susp_point;
+ self->private_impl.p_decode_id_part0[0] = coro_susp_point;
goto exit;
exit:
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -9436,14 +10134,12 @@
uint32_t v_num_palette_entries = 0;
uint32_t v_i = 0;
uint32_t v_argb = 0;
- wuffs_base__slice_u8 v_dst_palette = {};
+ wuffs_base__slice_u8 v_dst_palette = {0};
uint8_t v_lw = 0;
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -9456,12 +10152,11 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point =
- self->private_impl.c_decode_id_part1[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_id_part1[0];
if (coro_susp_point) {
v_num_palette_entries =
- self->private_impl.c_decode_id_part1[0].v_num_palette_entries;
- v_i = self->private_impl.c_decode_id_part1[0].v_i;
+ self->private_data.s_decode_id_part1[0].v_num_palette_entries;
+ v_i = self->private_data.s_decode_id_part1[0].v_i;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -9492,7 +10187,7 @@
t_1 = ((uint32_t)(wuffs_base__load_u24be(iop_a_src)));
iop_a_src += 3;
} else {
- self->private_impl.c_decode_id_part1[0].scratch = 0;
+ self->private_data.s_decode_id_part1[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
@@ -9500,8 +10195,8 @@
goto suspend;
}
uint64_t* scratch =
- &self->private_impl.c_decode_id_part1[0].scratch;
- uint32_t num_bits_1 = *scratch & 0xFF;
+ &self->private_data.s_decode_id_part1[0].scratch;
+ uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1);
@@ -9516,73 +10211,60 @@
v_argb = t_1;
}
v_argb |= 4278190080;
- self->private_impl.f_palettes[1][((4 * v_i) + 0)] =
+ self->private_data.f_palettes[1][((4 * v_i) + 0)] =
((uint8_t)(((v_argb >> 0) & 255)));
- self->private_impl.f_palettes[1][((4 * v_i) + 1)] =
+ self->private_data.f_palettes[1][((4 * v_i) + 1)] =
((uint8_t)(((v_argb >> 8) & 255)));
- self->private_impl.f_palettes[1][((4 * v_i) + 2)] =
+ self->private_data.f_palettes[1][((4 * v_i) + 2)] =
((uint8_t)(((v_argb >> 16) & 255)));
- self->private_impl.f_palettes[1][((4 * v_i) + 3)] =
+ self->private_data.f_palettes[1][((4 * v_i) + 3)] =
((uint8_t)(((v_argb >> 24) & 255)));
v_i += 1;
}
while (v_i < 256) {
- self->private_impl.f_palettes[1][((4 * v_i) + 0)] = 0;
- self->private_impl.f_palettes[1][((4 * v_i) + 1)] = 0;
- self->private_impl.f_palettes[1][((4 * v_i) + 2)] = 0;
- self->private_impl.f_palettes[1][((4 * v_i) + 3)] = 255;
+ self->private_data.f_palettes[1][((4 * v_i) + 0)] = 0;
+ self->private_data.f_palettes[1][((4 * v_i) + 1)] = 0;
+ self->private_data.f_palettes[1][((4 * v_i) + 2)] = 0;
+ self->private_data.f_palettes[1][((4 * v_i) + 3)] = 255;
v_i += 1;
}
} else if (self->private_impl.f_gc_has_transparent_index) {
wuffs_base__slice_u8__copy_from_slice(
- ((wuffs_base__slice_u8){
- .ptr = self->private_impl.f_palettes[1],
- .len = 1024,
- }),
- ((wuffs_base__slice_u8){
- .ptr = self->private_impl.f_palettes[0],
- .len = 1024,
- }));
+ wuffs_base__make_slice_u8(self->private_data.f_palettes[1], 1024),
+ wuffs_base__make_slice_u8(self->private_data.f_palettes[0], 1024));
} else {
self->private_impl.f_which_palette = 0;
}
if (self->private_impl.f_gc_has_transparent_index) {
- self->private_impl.f_palettes[1][(
+ self->private_data.f_palettes[1][(
(4 * ((uint32_t)(self->private_impl.f_gc_transparent_index))) + 0)] =
0;
- self->private_impl.f_palettes[1][(
+ self->private_data.f_palettes[1][(
(4 * ((uint32_t)(self->private_impl.f_gc_transparent_index))) + 1)] =
0;
- self->private_impl.f_palettes[1][(
+ self->private_data.f_palettes[1][(
(4 * ((uint32_t)(self->private_impl.f_gc_transparent_index))) + 2)] =
0;
- self->private_impl.f_palettes[1][(
+ self->private_data.f_palettes[1][(
(4 * ((uint32_t)(self->private_impl.f_gc_transparent_index))) + 3)] =
0;
}
v_dst_palette = wuffs_base__pixel_buffer__palette(a_dst);
if (((uint64_t)(v_dst_palette.len)) == 0) {
- v_dst_palette = ((wuffs_base__slice_u8){
- .ptr = self->private_impl.f_dst_palette,
- .len = 1024,
- });
+ v_dst_palette =
+ wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024);
}
wuffs_base__pixel_swizzler__prepare(
&self->private_impl.f_swizzler,
wuffs_base__pixel_buffer__pixel_format(a_dst), v_dst_palette,
1191444488,
- ((wuffs_base__slice_u8){
- .ptr = self->private_impl
- .f_palettes[self->private_impl.f_which_palette],
- .len = 1024,
- }));
+ wuffs_base__make_slice_u8(
+ self->private_data.f_palettes[self->private_impl.f_which_palette],
+ 1024));
if (self->private_impl.f_previous_lzw_decode_ended_abruptly) {
- (memset(&self->private_impl.f_lzw, 0, sizeof((wuffs_lzw__decoder){})),
- wuffs_base__ignore_check_wuffs_version_status(
- wuffs_lzw__decoder__check_wuffs_version(
- &self->private_impl.f_lzw, sizeof((wuffs_lzw__decoder){}),
- WUFFS_VERSION)),
- wuffs_base__return_empty_struct());
+ wuffs_base__ignore_status(wuffs_lzw__decoder__initialize(
+ &self->private_data.f_lzw, sizeof(wuffs_lzw__decoder), WUFFS_VERSION,
+ 0));
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
@@ -9597,28 +10279,28 @@
status = wuffs_gif__error__bad_literal_width;
goto exit;
}
- wuffs_lzw__decoder__set_literal_width(&self->private_impl.f_lzw,
+ wuffs_lzw__decoder__set_literal_width(&self->private_data.f_lzw,
((uint32_t)(v_lw)));
self->private_impl.f_previous_lzw_decode_ended_abruptly = true;
goto ok;
ok:
- self->private_impl.c_decode_id_part1[0].coro_susp_point = 0;
+ self->private_impl.p_decode_id_part1[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_id_part1[0].coro_susp_point = coro_susp_point;
- self->private_impl.c_decode_id_part1[0].v_num_palette_entries =
+ self->private_impl.p_decode_id_part1[0] = coro_susp_point;
+ self->private_data.s_decode_id_part1[0].v_num_palette_entries =
v_num_palette_entries;
- self->private_impl.c_decode_id_part1[0].v_i = v_i;
+ self->private_data.s_decode_id_part1[0].v_i = v_i;
goto exit;
exit:
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -9636,23 +10318,19 @@
uint64_t v_block_size = 0;
bool v_need_block_size = false;
uint64_t v_n_compressed = 0;
- wuffs_base__slice_u8 v_compressed = {};
- wuffs_base__io_reader v_r = {};
- wuffs_base__io_buffer u_r = {};
- uint8_t* iop_v_r = NULL;
- uint8_t* io1_v_r = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(u_r);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(iop_v_r);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_v_r);
+ wuffs_base__slice_u8 v_compressed = {0};
+ wuffs_base__io_reader v_r = wuffs_base__null_io_reader();
+ wuffs_base__io_buffer u_r WUFFS_BASE__POTENTIALLY_UNUSED =
+ wuffs_base__null_io_buffer();
+ uint8_t* iop_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
wuffs_base__status v_lzw_status = NULL;
wuffs_base__status v_copy_status = NULL;
- wuffs_base__slice_u8 v_uncompressed = {};
+ wuffs_base__slice_u8 v_uncompressed = {0};
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -9665,13 +10343,12 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point =
- self->private_impl.c_decode_id_part2[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_id_part2[0];
if (coro_susp_point) {
- v_block_size = self->private_impl.c_decode_id_part2[0].v_block_size;
+ v_block_size = self->private_data.s_decode_id_part2[0].v_block_size;
v_need_block_size =
- self->private_impl.c_decode_id_part2[0].v_need_block_size;
- v_lzw_status = self->private_impl.c_decode_id_part2[0].v_lzw_status;
+ self->private_data.s_decode_id_part2[0].v_need_block_size;
+ v_lzw_status = self->private_data.s_decode_id_part2[0].v_lzw_status;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -9713,10 +10390,8 @@
wuffs_base__io_reader__take(&iop_a_src, io1_a_src, v_n_compressed);
wuffs_base__slice_u8__copy_from_slice(
wuffs_base__slice_u8__subslice_i(
- ((wuffs_base__slice_u8){
- .ptr = self->private_impl.f_compressed,
- .len = 4096,
- }),
+ wuffs_base__make_slice_u8(self->private_data.f_compressed,
+ 4096),
self->private_impl.f_compressed_wi),
v_compressed);
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_compressed_wi,
@@ -9730,15 +10405,10 @@
goto label_1_break;
}
v_block_size = ((uint64_t)(wuffs_base__load_u8be(iop_a_src)));
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
}
label_1_break:;
- if (((uint64_t)(self->private_impl.f_width)) <
- ((uint64_t)(a_workbuf.len))) {
- a_workbuf = wuffs_base__slice_u8__subslice_j(
- a_workbuf, ((uint64_t)(self->private_impl.f_width)));
- } else if (((uint64_t)(self->private_impl.f_width)) >
- ((uint64_t)(a_workbuf.len))) {
+ if (1 > ((uint64_t)(a_workbuf.len))) {
status = wuffs_base__error__bad_workbuf_length;
goto exit;
}
@@ -9757,18 +10427,16 @@
wuffs_base__io_reader__set(
&v_r, &u_r, &iop_v_r, &io1_v_r,
wuffs_base__slice_u8__subslice_ij(
- ((wuffs_base__slice_u8){
- .ptr = self->private_impl.f_compressed,
- .len = 4096,
- }),
+ wuffs_base__make_slice_u8(self->private_data.f_compressed,
+ 4096),
self->private_impl.f_compressed_ri,
self->private_impl.f_compressed_wi));
{
- u_r.meta.ri = iop_v_r - u_r.data.ptr;
+ u_r.meta.ri = ((size_t)(iop_v_r - u_r.data.ptr));
wuffs_base__status t_1 = wuffs_lzw__decoder__decode_io_writer(
- &self->private_impl.f_lzw,
- wuffs_base__utility__null_io_writer(&self->private_impl.f_util),
- v_r);
+ &self->private_data.f_lzw,
+ wuffs_base__utility__null_io_writer(), v_r,
+ wuffs_base__utility__null_slice_u8());
iop_v_r = u_r.data.ptr + u_r.meta.ri;
v_lzw_status = t_1;
}
@@ -9779,7 +10447,7 @@
iop_v_r = o_0_iop_v_r;
io1_v_r = o_0_io1_v_r;
}
- v_uncompressed = wuffs_lzw__decoder__flush(&self->private_impl.f_lzw);
+ v_uncompressed = wuffs_lzw__decoder__flush(&self->private_data.f_lzw);
if (((uint64_t)(v_uncompressed.len)) > 0) {
v_copy_status = wuffs_gif__decoder__copy_to_image_buffer(
self, a_dst, v_uncompressed);
@@ -9791,21 +10459,21 @@
if (wuffs_base__status__is_ok(v_lzw_status)) {
self->private_impl.f_previous_lzw_decode_ended_abruptly = false;
if (v_need_block_size || (v_block_size > 0)) {
- self->private_impl.c_decode_id_part2[0].scratch =
+ self->private_data.s_decode_id_part2[0].scratch =
((uint32_t)(v_block_size));
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
- if (self->private_impl.c_decode_id_part2[0].scratch >
+ if (self->private_data.s_decode_id_part2[0].scratch >
((uint64_t)(io1_a_src - iop_a_src))) {
- self->private_impl.c_decode_id_part2[0].scratch -=
- io1_a_src - iop_a_src;
+ self->private_data.s_decode_id_part2[0].scratch -=
+ ((uint64_t)(io1_a_src - iop_a_src));
iop_a_src = io1_a_src;
status = wuffs_base__suspension__short_read;
goto suspend;
}
- iop_a_src += self->private_impl.c_decode_id_part2[0].scratch;
+ iop_a_src += self->private_data.s_decode_id_part2[0].scratch;
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
status = wuffs_gif__decoder__skip_blocks(self, a_src);
@@ -9836,25 +10504,33 @@
label_0_break:;
self->private_impl.f_compressed_ri = 0;
self->private_impl.f_compressed_wi = 0;
+ if ((self->private_impl.f_dst_y < self->private_impl.f_frame_rect_y1) &&
+ (self->private_impl.f_frame_rect_x0 !=
+ self->private_impl.f_frame_rect_x1) &&
+ (self->private_impl.f_frame_rect_y0 !=
+ self->private_impl.f_frame_rect_y1)) {
+ status = wuffs_base__error__not_enough_data;
+ goto exit;
+ }
goto ok;
ok:
- self->private_impl.c_decode_id_part2[0].coro_susp_point = 0;
+ self->private_impl.p_decode_id_part2[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_id_part2[0].coro_susp_point = coro_susp_point;
- self->private_impl.c_decode_id_part2[0].v_block_size = v_block_size;
- self->private_impl.c_decode_id_part2[0].v_need_block_size = v_need_block_size;
- self->private_impl.c_decode_id_part2[0].v_lzw_status = v_lzw_status;
+ self->private_impl.p_decode_id_part2[0] = coro_susp_point;
+ self->private_data.s_decode_id_part2[0].v_block_size = v_block_size;
+ self->private_data.s_decode_id_part2[0].v_need_block_size = v_need_block_size;
+ self->private_data.s_decode_id_part2[0].v_lzw_status = v_lzw_status;
goto exit;
exit:
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -9866,13 +10542,13 @@
wuffs_gif__decoder__copy_to_image_buffer(wuffs_gif__decoder* self,
wuffs_base__pixel_buffer* a_pb,
wuffs_base__slice_u8 a_src) {
- wuffs_base__slice_u8 v_dst = {};
- wuffs_base__slice_u8 v_src = {};
+ wuffs_base__slice_u8 v_dst = {0};
+ wuffs_base__slice_u8 v_src = {0};
uint64_t v_n = 0;
uint64_t v_src_ri = 0;
uint32_t v_bytes_per_pixel = 0;
uint32_t v_pixfmt = 0;
- wuffs_base__table_u8 v_tab = {};
+ wuffs_base__table_u8 v_tab = {0};
uint64_t v_i = 0;
uint64_t v_j = 0;
@@ -9888,7 +10564,7 @@
while (v_src_ri < ((uint64_t)(a_src.len))) {
v_src = wuffs_base__slice_u8__subslice_i(a_src, v_src_ri);
if (self->private_impl.f_dst_y >= self->private_impl.f_frame_rect_y1) {
- return wuffs_gif__error__too_much_pixel_data;
+ return wuffs_base__error__too_much_data;
}
v_dst = wuffs_base__table_u8__row(v_tab, self->private_impl.f_dst_y);
v_i = (((uint64_t)(self->private_impl.f_dst_x)) *
@@ -9903,10 +10579,7 @@
}
v_n = wuffs_base__pixel_swizzler__swizzle_packed(
&self->private_impl.f_swizzler, v_dst,
- ((wuffs_base__slice_u8){
- .ptr = self->private_impl.f_dst_palette,
- .len = 1024,
- }),
+ wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024),
v_src);
wuffs_base__u64__sat_add_indirect(&v_src_ri, v_n);
wuffs_base__u32__sat_add_indirect(&self->private_impl.f_dst_x,
@@ -9914,7 +10587,7 @@
self->private_impl.f_dirty_y = wuffs_base__range_ie_u32__unite(
&self->private_impl.f_dirty_y,
wuffs_base__utility__make_range_ie_u32(
- &self->private_impl.f_util, self->private_impl.f_dst_y,
+ self->private_impl.f_dst_y,
wuffs_base__u32__sat_add(self->private_impl.f_dst_y, 1)));
}
if (self->private_impl.f_frame_rect_x1 <= self->private_impl.f_dst_x) {
@@ -9926,7 +10599,14 @@
while (
(self->private_impl.f_interlace > 0) &&
(self->private_impl.f_dst_y >= self->private_impl.f_frame_rect_y1)) {
+#if defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wconversion"
+#endif
self->private_impl.f_interlace -= 1;
+#if defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
self->private_impl.f_dst_y = wuffs_base__u32__sat_add(
self->private_impl.f_frame_rect_y0,
wuffs_gif__interlace_start[self->private_impl.f_interlace]);
@@ -9953,7 +10633,14 @@
while (
(self->private_impl.f_interlace > 0) &&
(self->private_impl.f_dst_y >= self->private_impl.f_frame_rect_y1)) {
+#if defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wconversion"
+#endif
self->private_impl.f_interlace -= 1;
+#if defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
self->private_impl.f_dst_y = wuffs_base__u32__sat_add(
self->private_impl.f_frame_rect_y0,
wuffs_gif__interlace_start[self->private_impl.f_interlace]);
@@ -9975,11 +10662,11 @@
// ---------------- Status Codes Implementations
-const char* wuffs_gzip__error__bad_checksum = "?gzip: bad checksum";
+const char* wuffs_gzip__error__bad_checksum = "#gzip: bad checksum";
const char* wuffs_gzip__error__bad_compression_method =
- "?gzip: bad compression method";
-const char* wuffs_gzip__error__bad_encoding_flags = "?gzip: bad encoding flags";
-const char* wuffs_gzip__error__bad_header = "?gzip: bad header";
+ "#gzip: bad compression method";
+const char* wuffs_gzip__error__bad_encoding_flags = "#gzip: bad encoding flags";
+const char* wuffs_gzip__error__bad_header = "#gzip: bad header";
// ---------------- Private Consts
@@ -9990,9 +10677,10 @@
// ---------------- Initializer Implementations
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
-wuffs_gzip__decoder__check_wuffs_version(wuffs_gzip__decoder* self,
- size_t sizeof_star_self,
- uint64_t wuffs_version) {
+wuffs_gzip__decoder__initialize(wuffs_gzip__decoder* self,
+ size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags) {
if (!self) {
return wuffs_base__error__bad_receiver;
}
@@ -10003,21 +10691,44 @@
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
return wuffs_base__error__bad_wuffs_version;
}
- if (self->private_impl.magic != 0) {
- return wuffs_base__error__check_wuffs_version_not_applicable;
+
+ if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
+// The whole point of this if-check is to detect an uninitialized *self.
+// We disable the warning on GCC. Clang-5.0 does not have this warning.
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+#endif
+ if (self->private_impl.magic != 0) {
+ return wuffs_base__error__initialize_falsely_claimed_already_zeroed;
+ }
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
+ } else {
+ void* p = &(self->private_impl);
+ size_t n = sizeof(self->private_impl);
+ if ((initialize_flags &
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
+ p = self;
+ n = sizeof(*self);
+ initialize_flags |= WUFFS_INITIALIZE__ALREADY_ZEROED;
+ }
+ memset(p, 0, n);
}
+
{
- wuffs_base__status z = wuffs_deflate__decoder__check_wuffs_version(
- &self->private_impl.f_flate, sizeof(self->private_impl.f_flate),
- WUFFS_VERSION);
+ wuffs_base__status z = wuffs_crc32__ieee_hasher__initialize(
+ &self->private_data.f_checksum, sizeof(self->private_data.f_checksum),
+ WUFFS_VERSION, initialize_flags);
if (z) {
return z;
}
}
{
- wuffs_base__status z = wuffs_crc32__ieee_hasher__check_wuffs_version(
- &self->private_impl.f_checksum, sizeof(self->private_impl.f_checksum),
- WUFFS_VERSION);
+ wuffs_base__status z = wuffs_deflate__decoder__initialize(
+ &self->private_data.f_flate, sizeof(self->private_data.f_flate),
+ WUFFS_VERSION, initialize_flags);
if (z) {
return z;
}
@@ -10028,7 +10739,7 @@
size_t //
sizeof__wuffs_gzip__decoder() {
- return sizeof((wuffs_gzip__decoder){});
+ return sizeof(wuffs_gzip__decoder);
}
// ---------------- Function Implementations
@@ -10038,14 +10749,29 @@
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct //
wuffs_gzip__decoder__set_ignore_checksum(wuffs_gzip__decoder* self, bool a_ic) {
if (!self) {
- return ((wuffs_base__empty_struct){});
+ return wuffs_base__make_empty_struct();
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
- return ((wuffs_base__empty_struct){});
+ return wuffs_base__make_empty_struct();
}
self->private_impl.f_ignore_checksum = a_ic;
- return ((wuffs_base__empty_struct){});
+ return wuffs_base__make_empty_struct();
+}
+
+// -------- func gzip.decoder.workbuf_len
+
+WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 //
+wuffs_gzip__decoder__workbuf_len(const wuffs_gzip__decoder* self) {
+ if (!self) {
+ return wuffs_base__utility__make_range_ii_u64(0, 0);
+ }
+ if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
+ (self->private_impl.magic != WUFFS_BASE__DISABLED)) {
+ return wuffs_base__utility__make_range_ii_u64(0, 0);
+ }
+
+ return wuffs_base__utility__make_range_ii_u64(1, 1);
}
// -------- func gzip.decoder.decode_io_writer
@@ -10053,14 +10779,15 @@
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_gzip__decoder__decode_io_writer(wuffs_gzip__decoder* self,
wuffs_base__io_writer a_dst,
- wuffs_base__io_reader a_src) {
+ wuffs_base__io_reader a_src,
+ wuffs_base__slice_u8 a_workbuf) {
if (!self) {
return wuffs_base__error__bad_receiver;
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return (self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
- : wuffs_base__error__check_wuffs_version_missing;
+ : wuffs_base__error__initialize_not_called;
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 1)) {
@@ -10080,10 +10807,8 @@
uint32_t v_decoded_length_want = 0;
uint8_t* iop_a_dst = NULL;
- uint8_t* io0_a_dst = NULL;
- uint8_t* io1_a_dst = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_dst);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_dst);
+ uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst.private_impl.buf) {
iop_a_dst =
a_dst.private_impl.buf->data.ptr + a_dst.private_impl.buf->meta.wi;
@@ -10099,10 +10824,8 @@
io1_a_dst = a_dst.private_impl.limit;
}
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -10115,14 +10838,13 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point =
- self->private_impl.c_decode_io_writer[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_io_writer[0];
if (coro_susp_point) {
- v_flags = self->private_impl.c_decode_io_writer[0].v_flags;
- v_checksum_got = self->private_impl.c_decode_io_writer[0].v_checksum_got;
+ v_flags = self->private_data.s_decode_io_writer[0].v_flags;
+ v_checksum_got = self->private_data.s_decode_io_writer[0].v_checksum_got;
v_decoded_length_got =
- self->private_impl.c_decode_io_writer[0].v_decoded_length_got;
- v_checksum_want = self->private_impl.c_decode_io_writer[0].v_checksum_want;
+ self->private_data.s_decode_io_writer[0].v_decoded_length_got;
+ v_checksum_want = self->private_data.s_decode_io_writer[0].v_checksum_want;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -10175,16 +10897,17 @@
uint8_t t_3 = *iop_a_src++;
v_flags = t_3;
}
- self->private_impl.c_decode_io_writer[0].scratch = 6;
+ self->private_data.s_decode_io_writer[0].scratch = 6;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
- if (self->private_impl.c_decode_io_writer[0].scratch >
+ if (self->private_data.s_decode_io_writer[0].scratch >
((uint64_t)(io1_a_src - iop_a_src))) {
- self->private_impl.c_decode_io_writer[0].scratch -= io1_a_src - iop_a_src;
+ self->private_data.s_decode_io_writer[0].scratch -=
+ ((uint64_t)(io1_a_src - iop_a_src));
iop_a_src = io1_a_src;
status = wuffs_base__suspension__short_read;
goto suspend;
}
- iop_a_src += self->private_impl.c_decode_io_writer[0].scratch;
+ iop_a_src += self->private_data.s_decode_io_writer[0].scratch;
if ((v_flags & 4) != 0) {
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
@@ -10193,7 +10916,7 @@
t_4 = wuffs_base__load_u16le(iop_a_src);
iop_a_src += 2;
} else {
- self->private_impl.c_decode_io_writer[0].scratch = 0;
+ self->private_data.s_decode_io_writer[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
@@ -10201,13 +10924,13 @@
goto suspend;
}
uint64_t* scratch =
- &self->private_impl.c_decode_io_writer[0].scratch;
- uint32_t num_bits_4 = *scratch >> 56;
+ &self->private_data.s_decode_io_writer[0].scratch;
+ uint32_t num_bits_4 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_4;
if (num_bits_4 == 8) {
- t_4 = *scratch;
+ t_4 = ((uint16_t)(*scratch));
break;
}
num_bits_4 += 8;
@@ -10216,17 +10939,17 @@
}
v_xlen = t_4;
}
- self->private_impl.c_decode_io_writer[0].scratch = ((uint32_t)(v_xlen));
+ self->private_data.s_decode_io_writer[0].scratch = ((uint32_t)(v_xlen));
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
- if (self->private_impl.c_decode_io_writer[0].scratch >
+ if (self->private_data.s_decode_io_writer[0].scratch >
((uint64_t)(io1_a_src - iop_a_src))) {
- self->private_impl.c_decode_io_writer[0].scratch -=
- io1_a_src - iop_a_src;
+ self->private_data.s_decode_io_writer[0].scratch -=
+ ((uint64_t)(io1_a_src - iop_a_src));
iop_a_src = io1_a_src;
status = wuffs_base__suspension__short_read;
goto suspend;
}
- iop_a_src += self->private_impl.c_decode_io_writer[0].scratch;
+ iop_a_src += self->private_data.s_decode_io_writer[0].scratch;
}
if ((v_flags & 8) != 0) {
while (true) {
@@ -10263,17 +10986,17 @@
label_1_break:;
}
if ((v_flags & 2) != 0) {
- self->private_impl.c_decode_io_writer[0].scratch = 2;
+ self->private_data.s_decode_io_writer[0].scratch = 2;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
- if (self->private_impl.c_decode_io_writer[0].scratch >
+ if (self->private_data.s_decode_io_writer[0].scratch >
((uint64_t)(io1_a_src - iop_a_src))) {
- self->private_impl.c_decode_io_writer[0].scratch -=
- io1_a_src - iop_a_src;
+ self->private_data.s_decode_io_writer[0].scratch -=
+ ((uint64_t)(io1_a_src - iop_a_src));
iop_a_src = io1_a_src;
status = wuffs_base__suspension__short_read;
goto suspend;
}
- iop_a_src += self->private_impl.c_decode_io_writer[0].scratch;
+ iop_a_src += self->private_data.s_decode_io_writer[0].scratch;
}
if ((v_flags & 224) != 0) {
status = wuffs_gzip__error__bad_encoding_flags;
@@ -10284,14 +11007,14 @@
{
if (a_dst.private_impl.buf) {
a_dst.private_impl.buf->meta.wi =
- iop_a_dst - a_dst.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_dst - a_dst.private_impl.buf->data.ptr));
}
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
wuffs_base__status t_7 = wuffs_deflate__decoder__decode_io_writer(
- &self->private_impl.f_flate, a_dst, a_src);
+ &self->private_data.f_flate, a_dst, a_src, a_workbuf);
if (a_dst.private_impl.buf) {
iop_a_dst = a_dst.private_impl.buf->data.ptr +
a_dst.private_impl.buf->meta.wi;
@@ -10304,11 +11027,10 @@
}
if (!self->private_impl.f_ignore_checksum) {
v_checksum_got = wuffs_crc32__ieee_hasher__update(
- &self->private_impl.f_checksum,
- ((wuffs_base__slice_u8){
- .ptr = a_dst.private_impl.mark,
- .len = (size_t)(iop_a_dst - a_dst.private_impl.mark),
- }));
+ &self->private_data.f_checksum,
+ wuffs_base__make_slice_u8(
+ a_dst.private_impl.mark,
+ (size_t)(iop_a_dst - a_dst.private_impl.mark)));
v_decoded_length_got += ((uint32_t)(
(((uint64_t)(iop_a_dst - a_dst.private_impl.mark)) & 4294967295)));
}
@@ -10326,20 +11048,20 @@
t_8 = wuffs_base__load_u32le(iop_a_src);
iop_a_src += 4;
} else {
- self->private_impl.c_decode_io_writer[0].scratch = 0;
+ self->private_data.s_decode_io_writer[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(14);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
status = wuffs_base__suspension__short_read;
goto suspend;
}
- uint64_t* scratch = &self->private_impl.c_decode_io_writer[0].scratch;
- uint32_t num_bits_8 = *scratch >> 56;
+ uint64_t* scratch = &self->private_data.s_decode_io_writer[0].scratch;
+ uint32_t num_bits_8 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_8;
if (num_bits_8 == 24) {
- t_8 = *scratch;
+ t_8 = ((uint32_t)(*scratch));
break;
}
num_bits_8 += 8;
@@ -10355,20 +11077,20 @@
t_9 = wuffs_base__load_u32le(iop_a_src);
iop_a_src += 4;
} else {
- self->private_impl.c_decode_io_writer[0].scratch = 0;
+ self->private_data.s_decode_io_writer[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
status = wuffs_base__suspension__short_read;
goto suspend;
}
- uint64_t* scratch = &self->private_impl.c_decode_io_writer[0].scratch;
- uint32_t num_bits_9 = *scratch >> 56;
+ uint64_t* scratch = &self->private_data.s_decode_io_writer[0].scratch;
+ uint32_t num_bits_9 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_9;
if (num_bits_9 == 24) {
- t_9 = *scratch;
+ t_9 = ((uint32_t)(*scratch));
break;
}
num_bits_9 += 8;
@@ -10386,29 +11108,29 @@
goto ok;
ok:
- self->private_impl.c_decode_io_writer[0].coro_susp_point = 0;
+ self->private_impl.p_decode_io_writer[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_io_writer[0].coro_susp_point = coro_susp_point;
+ self->private_impl.p_decode_io_writer[0] = coro_susp_point;
self->private_impl.active_coroutine = 1;
- self->private_impl.c_decode_io_writer[0].v_flags = v_flags;
- self->private_impl.c_decode_io_writer[0].v_checksum_got = v_checksum_got;
- self->private_impl.c_decode_io_writer[0].v_decoded_length_got =
+ self->private_data.s_decode_io_writer[0].v_flags = v_flags;
+ self->private_data.s_decode_io_writer[0].v_checksum_got = v_checksum_got;
+ self->private_data.s_decode_io_writer[0].v_decoded_length_got =
v_decoded_length_got;
- self->private_impl.c_decode_io_writer[0].v_checksum_want = v_checksum_want;
+ self->private_data.s_decode_io_writer[0].v_checksum_want = v_checksum_want;
goto exit;
exit:
if (a_dst.private_impl.buf) {
a_dst.private_impl.buf->meta.wi =
- iop_a_dst - a_dst.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_dst - a_dst.private_impl.buf->data.ptr));
}
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
if (wuffs_base__status__is_error(status)) {
@@ -10424,14 +11146,14 @@
// ---------------- Status Codes Implementations
-const char* wuffs_zlib__error__bad_checksum = "?zlib: bad checksum";
+const char* wuffs_zlib__error__bad_checksum = "#zlib: bad checksum";
const char* wuffs_zlib__error__bad_compression_method =
- "?zlib: bad compression method";
+ "#zlib: bad compression method";
const char* wuffs_zlib__error__bad_compression_window_size =
- "?zlib: bad compression window size";
-const char* wuffs_zlib__error__bad_parity_check = "?zlib: bad parity check";
+ "#zlib: bad compression window size";
+const char* wuffs_zlib__error__bad_parity_check = "#zlib: bad parity check";
const char* wuffs_zlib__error__todo_unsupported_preset_dictionary =
- "?zlib: TODO: unsupported preset dictionary";
+ "#zlib: TODO: unsupported preset dictionary";
// ---------------- Private Consts
@@ -10442,9 +11164,10 @@
// ---------------- Initializer Implementations
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
-wuffs_zlib__decoder__check_wuffs_version(wuffs_zlib__decoder* self,
- size_t sizeof_star_self,
- uint64_t wuffs_version) {
+wuffs_zlib__decoder__initialize(wuffs_zlib__decoder* self,
+ size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags) {
if (!self) {
return wuffs_base__error__bad_receiver;
}
@@ -10455,21 +11178,44 @@
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
return wuffs_base__error__bad_wuffs_version;
}
- if (self->private_impl.magic != 0) {
- return wuffs_base__error__check_wuffs_version_not_applicable;
+
+ if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
+// The whole point of this if-check is to detect an uninitialized *self.
+// We disable the warning on GCC. Clang-5.0 does not have this warning.
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+#endif
+ if (self->private_impl.magic != 0) {
+ return wuffs_base__error__initialize_falsely_claimed_already_zeroed;
+ }
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
+ } else {
+ void* p = &(self->private_impl);
+ size_t n = sizeof(self->private_impl);
+ if ((initialize_flags &
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
+ p = self;
+ n = sizeof(*self);
+ initialize_flags |= WUFFS_INITIALIZE__ALREADY_ZEROED;
+ }
+ memset(p, 0, n);
}
+
{
- wuffs_base__status z = wuffs_deflate__decoder__check_wuffs_version(
- &self->private_impl.f_flate, sizeof(self->private_impl.f_flate),
- WUFFS_VERSION);
+ wuffs_base__status z = wuffs_adler32__hasher__initialize(
+ &self->private_data.f_checksum, sizeof(self->private_data.f_checksum),
+ WUFFS_VERSION, initialize_flags);
if (z) {
return z;
}
}
{
- wuffs_base__status z = wuffs_adler32__hasher__check_wuffs_version(
- &self->private_impl.f_checksum, sizeof(self->private_impl.f_checksum),
- WUFFS_VERSION);
+ wuffs_base__status z = wuffs_deflate__decoder__initialize(
+ &self->private_data.f_flate, sizeof(self->private_data.f_flate),
+ WUFFS_VERSION, initialize_flags);
if (z) {
return z;
}
@@ -10480,7 +11226,7 @@
size_t //
sizeof__wuffs_zlib__decoder() {
- return sizeof((wuffs_zlib__decoder){});
+ return sizeof(wuffs_zlib__decoder);
}
// ---------------- Function Implementations
@@ -10490,14 +11236,29 @@
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct //
wuffs_zlib__decoder__set_ignore_checksum(wuffs_zlib__decoder* self, bool a_ic) {
if (!self) {
- return ((wuffs_base__empty_struct){});
+ return wuffs_base__make_empty_struct();
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
- return ((wuffs_base__empty_struct){});
+ return wuffs_base__make_empty_struct();
}
self->private_impl.f_ignore_checksum = a_ic;
- return ((wuffs_base__empty_struct){});
+ return wuffs_base__make_empty_struct();
+}
+
+// -------- func zlib.decoder.workbuf_len
+
+WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 //
+wuffs_zlib__decoder__workbuf_len(const wuffs_zlib__decoder* self) {
+ if (!self) {
+ return wuffs_base__utility__make_range_ii_u64(0, 0);
+ }
+ if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
+ (self->private_impl.magic != WUFFS_BASE__DISABLED)) {
+ return wuffs_base__utility__make_range_ii_u64(0, 0);
+ }
+
+ return wuffs_base__utility__make_range_ii_u64(1, 1);
}
// -------- func zlib.decoder.decode_io_writer
@@ -10505,14 +11266,15 @@
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_zlib__decoder__decode_io_writer(wuffs_zlib__decoder* self,
wuffs_base__io_writer a_dst,
- wuffs_base__io_reader a_src) {
+ wuffs_base__io_reader a_src,
+ wuffs_base__slice_u8 a_workbuf) {
if (!self) {
return wuffs_base__error__bad_receiver;
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return (self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
- : wuffs_base__error__check_wuffs_version_missing;
+ : wuffs_base__error__initialize_not_called;
}
if ((self->private_impl.active_coroutine != 0) &&
(self->private_impl.active_coroutine != 1)) {
@@ -10528,10 +11290,8 @@
uint32_t v_checksum_want = 0;
uint8_t* iop_a_dst = NULL;
- uint8_t* io0_a_dst = NULL;
- uint8_t* io1_a_dst = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_dst);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_dst);
+ uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst.private_impl.buf) {
iop_a_dst =
a_dst.private_impl.buf->data.ptr + a_dst.private_impl.buf->meta.wi;
@@ -10547,10 +11307,8 @@
io1_a_dst = a_dst.private_impl.limit;
}
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -10563,10 +11321,9 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point =
- self->private_impl.c_decode_io_writer[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_io_writer[0];
if (coro_susp_point) {
- v_checksum_got = self->private_impl.c_decode_io_writer[0].v_checksum_got;
+ v_checksum_got = self->private_data.s_decode_io_writer[0].v_checksum_got;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -10578,20 +11335,20 @@
t_0 = wuffs_base__load_u16be(iop_a_src);
iop_a_src += 2;
} else {
- self->private_impl.c_decode_io_writer[0].scratch = 0;
+ self->private_data.s_decode_io_writer[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
status = wuffs_base__suspension__short_read;
goto suspend;
}
- uint64_t* scratch = &self->private_impl.c_decode_io_writer[0].scratch;
- uint32_t num_bits_0 = *scratch & 0xFF;
+ uint64_t* scratch = &self->private_data.s_decode_io_writer[0].scratch;
+ uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0);
if (num_bits_0 == 8) {
- t_0 = *scratch >> 48;
+ t_0 = ((uint16_t)(*scratch >> 48));
break;
}
num_bits_0 += 8;
@@ -10621,14 +11378,14 @@
{
if (a_dst.private_impl.buf) {
a_dst.private_impl.buf->meta.wi =
- iop_a_dst - a_dst.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_dst - a_dst.private_impl.buf->data.ptr));
}
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
wuffs_base__status t_1 = wuffs_deflate__decoder__decode_io_writer(
- &self->private_impl.f_flate, a_dst, a_src);
+ &self->private_data.f_flate, a_dst, a_src, a_workbuf);
if (a_dst.private_impl.buf) {
iop_a_dst = a_dst.private_impl.buf->data.ptr +
a_dst.private_impl.buf->meta.wi;
@@ -10641,11 +11398,10 @@
}
if (!self->private_impl.f_ignore_checksum) {
v_checksum_got = wuffs_adler32__hasher__update(
- &self->private_impl.f_checksum,
- ((wuffs_base__slice_u8){
- .ptr = a_dst.private_impl.mark,
- .len = (size_t)(iop_a_dst - a_dst.private_impl.mark),
- }));
+ &self->private_data.f_checksum,
+ wuffs_base__make_slice_u8(
+ a_dst.private_impl.mark,
+ (size_t)(iop_a_dst - a_dst.private_impl.mark)));
}
if (wuffs_base__status__is_ok(v_status)) {
goto label_0_break;
@@ -10661,20 +11417,20 @@
t_2 = wuffs_base__load_u32be(iop_a_src);
iop_a_src += 4;
} else {
- self->private_impl.c_decode_io_writer[0].scratch = 0;
+ self->private_data.s_decode_io_writer[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
status = wuffs_base__suspension__short_read;
goto suspend;
}
- uint64_t* scratch = &self->private_impl.c_decode_io_writer[0].scratch;
- uint32_t num_bits_2 = *scratch & 0xFF;
+ uint64_t* scratch = &self->private_data.s_decode_io_writer[0].scratch;
+ uint32_t num_bits_2 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_2);
if (num_bits_2 == 24) {
- t_2 = *scratch >> 32;
+ t_2 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_2 += 8;
@@ -10691,25 +11447,25 @@
goto ok;
ok:
- self->private_impl.c_decode_io_writer[0].coro_susp_point = 0;
+ self->private_impl.p_decode_io_writer[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_io_writer[0].coro_susp_point = coro_susp_point;
+ self->private_impl.p_decode_io_writer[0] = coro_susp_point;
self->private_impl.active_coroutine = 1;
- self->private_impl.c_decode_io_writer[0].v_checksum_got = v_checksum_got;
+ self->private_data.s_decode_io_writer[0].v_checksum_got = v_checksum_got;
goto exit;
exit:
if (a_dst.private_impl.buf) {
a_dst.private_impl.buf->meta.wi =
- iop_a_dst - a_dst.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_dst - a_dst.private_impl.buf->data.ptr));
}
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
if (wuffs_base__status__is_error(status)) {
diff --git a/release/c/wuffs-v0.2.c b/release/c/wuffs-v0.2.c
index c60db23..8ea6abd 100644
--- a/release/c/wuffs-v0.2.c
+++ b/release/c/wuffs-v0.2.c
@@ -26,6 +26,12 @@
#include <stdint.h>
#include <string.h>
+// GCC does not warn for unused *static inline* functions, but clang does.
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunused-function"
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -54,15 +60,15 @@
// each major.minor branch, the commit count should increase monotonically.
//
// WUFFS_VERSION was overridden by "wuffs gen -version" based on revision
-// dec519d9b42107797ef2d81249fe1a7485921253 committed on 2019-01-19.
+// 6b9f658c593bb57851e3fac7df2e5f3949a4fac8 committed on 2019-04-07.
#define WUFFS_VERSION ((uint64_t)0x0000000000020000)
#define WUFFS_VERSION_MAJOR ((uint64_t)0x00000000)
#define WUFFS_VERSION_MINOR ((uint64_t)0x0002)
#define WUFFS_VERSION_PATCH ((uint64_t)0x0000)
-#define WUFFS_VERSION_PRE_RELEASE_LABEL "alpha.29"
-#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 1556
-#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20190119
-#define WUFFS_VERSION_STRING "0.2.0-alpha.29+1556.20190119"
+#define WUFFS_VERSION_PRE_RELEASE_LABEL "alpha.36"
+#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 1675
+#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20190407
+#define WUFFS_VERSION_STRING "0.2.0-alpha.36+1675.20190407"
// Define WUFFS_CONFIG__STATIC_FUNCTIONS to make all of Wuffs' functions have
// static storage. The motivation is discussed in the "ALLOW STATIC
@@ -74,13 +80,57 @@
#define WUFFS_BASE__MAYBE_STATIC
#endif
+#if defined(__clang__)
+#define WUFFS_BASE__POTENTIALLY_UNUSED_FIELD __attribute__((unused))
+#else
+#define WUFFS_BASE__POTENTIALLY_UNUSED_FIELD
+#endif
+
// Clang also defines "__GNUC__".
#if defined(__GNUC__)
+#define WUFFS_BASE__POTENTIALLY_UNUSED __attribute__((unused))
#define WUFFS_BASE__WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#else
+#define WUFFS_BASE__POTENTIALLY_UNUSED
#define WUFFS_BASE__WARN_UNUSED_RESULT
#endif
+// Flags for wuffs_foo__bar__initialize functions.
+
+#define WUFFS_INITIALIZE__DEFAULT_OPTIONS ((uint32_t)0x00000000)
+
+// WUFFS_INITIALIZE__ALREADY_ZEROED means that the "self" receiver struct value
+// has already been set to all zeroes.
+#define WUFFS_INITIALIZE__ALREADY_ZEROED ((uint32_t)0x00000001)
+
+// WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED means that, absent
+// WUFFS_INITIALIZE__ALREADY_ZEROED, only some of the "self" receiver struct
+// value will be set to all zeroes. Internal buffers, which tend to be a large
+// proportion of the struct's size, will be left uninitialized. Internal means
+// that the buffer is contained by the receiver struct, as opposed to being
+// passed as a separately allocated "work buffer".
+//
+// With or without this bit set, the Wuffs compiler still enforces that no
+// reads or writes will overflow internal buffers' bounds. Even with this bit
+// set, the Wuffs standard library also considers reading from an uninitialized
+// buffer to be a bug, and strives to never do so, but unlike buffer overflows,
+// it is not a bug class that the Wuffs compiler eliminates.
+//
+// For those paranoid about security, leave this bit unset, so that
+// wuffs_foo__bar__initialize will initialize the entire struct value to zeroes
+// (unless WUFFS_INITIALIZE__ALREADY_ZEROED is set).
+//
+// Setting this bit gives a small absolute improvement on micro-benchmarks, but
+// this can be a large relative effect, up to 2x faster, when the actual work
+// to be done is also small, such as decompressing small input. See git commit
+// 438fc105 "Move some struct fields to private_data" for some numbers and a
+// discussion, noting that its commit message was written before this
+// WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED option was defined.
+#define WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED \
+ ((uint32_t)0x00000002)
+
+// --------
+
// 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
// Wuffs, if a function g returns empty, you can say "y = g()".
@@ -97,6 +147,13 @@
uint8_t private_impl;
} wuffs_base__empty_struct;
+static inline wuffs_base__empty_struct //
+wuffs_base__make_empty_struct() {
+ wuffs_base__empty_struct ret;
+ ret.private_impl = 0;
+ return ret;
+}
+
// wuffs_base__utility is a placeholder receiver type. It enables what Java
// calls static methods, as opposed to regular methods.
typedef struct {
@@ -146,18 +203,21 @@
extern const char* wuffs_base__error__bad_workbuf_length;
extern const char* wuffs_base__error__bad_wuffs_version;
extern const char* wuffs_base__error__cannot_return_a_suspension;
-extern const char* wuffs_base__error__check_wuffs_version_not_applicable;
-extern const char* wuffs_base__error__check_wuffs_version_missing;
extern const char* wuffs_base__error__disabled_by_previous_error;
+extern const char* wuffs_base__error__initialize_falsely_claimed_already_zeroed;
+extern const char* wuffs_base__error__initialize_not_called;
+extern const char* wuffs_base__error__interleaved_coroutine_calls;
+extern const char* wuffs_base__error__not_enough_data;
+extern const char* wuffs_base__error__too_much_data;
static inline bool //
wuffs_base__status__is_complete(wuffs_base__status z) {
- return (z == NULL) || ((*z != '$') && (*z != '?'));
+ return (z == NULL) || ((*z != '$') && (*z != '#'));
}
static inline bool //
wuffs_base__status__is_error(wuffs_base__status z) {
- return z && (*z == '?');
+ return z && (*z == '#');
}
static inline bool //
@@ -172,7 +232,7 @@
static inline bool //
wuffs_base__status__is_warning(wuffs_base__status z) {
- return z && (*z != '$') && (*z != '?');
+ return z && (*z != '$') && (*z != '#');
}
// --------
@@ -236,57 +296,57 @@
static inline uint8_t //
wuffs_base__u8__sat_add(uint8_t x, uint8_t y) {
- uint8_t res = x + y;
- res |= -(res < x);
+ uint8_t res = (uint8_t)(x + y);
+ res |= (uint8_t)(-(res < x));
return res;
}
static inline uint8_t //
wuffs_base__u8__sat_sub(uint8_t x, uint8_t y) {
- uint8_t res = x - y;
- res &= -(res <= x);
+ uint8_t res = (uint8_t)(x - y);
+ res &= (uint8_t)(-(res <= x));
return res;
}
static inline uint16_t //
wuffs_base__u16__sat_add(uint16_t x, uint16_t y) {
- uint16_t res = x + y;
- res |= -(res < x);
+ uint16_t res = (uint16_t)(x + y);
+ res |= (uint16_t)(-(res < x));
return res;
}
static inline uint16_t //
wuffs_base__u16__sat_sub(uint16_t x, uint16_t y) {
- uint16_t res = x - y;
- res &= -(res <= x);
+ uint16_t res = (uint16_t)(x - y);
+ res &= (uint16_t)(-(res <= x));
return res;
}
static inline uint32_t //
wuffs_base__u32__sat_add(uint32_t x, uint32_t y) {
- uint32_t res = x + y;
- res |= -(res < x);
+ uint32_t res = (uint32_t)(x + y);
+ res |= (uint32_t)(-(res < x));
return res;
}
static inline uint32_t //
wuffs_base__u32__sat_sub(uint32_t x, uint32_t y) {
- uint32_t res = x - y;
- res &= -(res <= x);
+ uint32_t res = (uint32_t)(x - y);
+ res &= (uint32_t)(-(res <= x));
return res;
}
static inline uint64_t //
wuffs_base__u64__sat_add(uint64_t x, uint64_t y) {
- uint64_t res = x + y;
- res |= -(res < x);
+ uint64_t res = (uint64_t)(x + y);
+ res |= (uint64_t)(-(res < x));
return res;
}
static inline uint64_t //
wuffs_base__u64__sat_sub(uint64_t x, uint64_t y) {
- uint64_t res = x - y;
- res &= -(res <= x);
+ uint64_t res = (uint64_t)(x - y);
+ res &= (uint64_t)(-(res <= x));
return res;
}
@@ -327,18 +387,65 @@
typedef WUFFS_BASE__TABLE(uint32_t) wuffs_base__table_u32;
typedef WUFFS_BASE__TABLE(uint64_t) wuffs_base__table_u64;
+static inline wuffs_base__slice_u8 //
+wuffs_base__make_slice_u8(uint8_t* ptr, size_t len) {
+ wuffs_base__slice_u8 ret;
+ ret.ptr = ptr;
+ ret.len = len;
+ return ret;
+}
+
+static inline wuffs_base__slice_u16 //
+wuffs_base__make_slice_u16(uint16_t* ptr, size_t len) {
+ wuffs_base__slice_u16 ret;
+ ret.ptr = ptr;
+ ret.len = len;
+ return ret;
+}
+
+static inline wuffs_base__slice_u32 //
+wuffs_base__make_slice_u32(uint32_t* ptr, size_t len) {
+ wuffs_base__slice_u32 ret;
+ ret.ptr = ptr;
+ ret.len = len;
+ return ret;
+}
+
+static inline wuffs_base__slice_u64 //
+wuffs_base__make_slice_u64(uint64_t* ptr, size_t len) {
+ wuffs_base__slice_u64 ret;
+ ret.ptr = ptr;
+ ret.len = len;
+ return ret;
+}
+
+static inline wuffs_base__slice_u8 //
+wuffs_base__null_slice_u8() {
+ wuffs_base__slice_u8 ret;
+ ret.ptr = NULL;
+ ret.len = 0;
+ return ret;
+}
+
+static inline wuffs_base__table_u8 //
+wuffs_base__null_table_u8() {
+ wuffs_base__table_u8 ret;
+ ret.ptr = NULL;
+ ret.width = 0;
+ ret.height = 0;
+ ret.stride = 0;
+ return ret;
+}
+
// wuffs_base__slice_u8__subslice_i returns s[i:].
//
// It returns an empty slice if i is out of bounds.
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 ((wuffs_base__slice_u8){
- .ptr = s.ptr + i,
- .len = s.len - i,
- });
+ return wuffs_base__make_slice_u8(s.ptr + i, s.len - i);
}
- return ((wuffs_base__slice_u8){});
+ return wuffs_base__make_slice_u8(NULL, 0);
}
// wuffs_base__slice_u8__subslice_j returns s[:j].
@@ -347,12 +454,9 @@
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 ((wuffs_base__slice_u8){
- .ptr = s.ptr,
- .len = j,
- });
+ return wuffs_base__make_slice_u8(s.ptr, j);
}
- return ((wuffs_base__slice_u8){});
+ return wuffs_base__make_slice_u8(NULL, 0);
}
// wuffs_base__slice_u8__subslice_ij returns s[i:j].
@@ -363,12 +467,9 @@
uint64_t i,
uint64_t j) {
if ((i <= j) && (j <= SIZE_MAX) && (j <= s.len)) {
- return ((wuffs_base__slice_u8){
- .ptr = s.ptr + i,
- .len = j - i,
- });
+ return wuffs_base__make_slice_u8(s.ptr + i, j - i);
}
- return ((wuffs_base__slice_u8){});
+ return wuffs_base__make_slice_u8(NULL, 0);
}
// ---------------- Ranges and Rects
@@ -411,15 +512,24 @@
#ifdef __cplusplus
inline bool is_empty();
inline bool equals(wuffs_base__range_ii_u32__struct s);
- inline bool contains(uint32_t x);
inline wuffs_base__range_ii_u32__struct intersect(
wuffs_base__range_ii_u32__struct s);
inline wuffs_base__range_ii_u32__struct unite(
wuffs_base__range_ii_u32__struct s);
+ inline bool contains(uint32_t x);
+ inline bool contains_range(wuffs_base__range_ii_u32__struct s);
#endif // __cplusplus
} wuffs_base__range_ii_u32;
+static inline wuffs_base__range_ii_u32 //
+wuffs_base__make_range_ii_u32(uint32_t min_incl, uint32_t max_incl) {
+ wuffs_base__range_ii_u32 ret;
+ ret.min_incl = min_incl;
+ ret.max_incl = max_incl;
+ return ret;
+}
+
static inline bool //
wuffs_base__range_ii_u32__is_empty(wuffs_base__range_ii_u32* r) {
return r->min_incl > r->max_incl;
@@ -433,25 +543,18 @@
wuffs_base__range_ii_u32__is_empty(&s));
}
-static inline bool //
-wuffs_base__range_ii_u32__contains(wuffs_base__range_ii_u32* r, uint32_t x) {
- return (r->min_incl <= x) && (x <= r->max_incl);
-}
-
-static inline //
- wuffs_base__range_ii_u32
- wuffs_base__range_ii_u32__intersect(wuffs_base__range_ii_u32* r,
- wuffs_base__range_ii_u32 s) {
+static inline wuffs_base__range_ii_u32 //
+wuffs_base__range_ii_u32__intersect(wuffs_base__range_ii_u32* r,
+ wuffs_base__range_ii_u32 s) {
wuffs_base__range_ii_u32 t;
t.min_incl = wuffs_base__u32__max(r->min_incl, s.min_incl);
t.max_incl = wuffs_base__u32__min(r->max_incl, s.max_incl);
return t;
}
-static inline //
- wuffs_base__range_ii_u32
- wuffs_base__range_ii_u32__unite(wuffs_base__range_ii_u32* r,
- wuffs_base__range_ii_u32 s) {
+static inline wuffs_base__range_ii_u32 //
+wuffs_base__range_ii_u32__unite(wuffs_base__range_ii_u32* r,
+ wuffs_base__range_ii_u32 s) {
if (wuffs_base__range_ii_u32__is_empty(r)) {
return s;
}
@@ -464,6 +567,18 @@
return t;
}
+static inline bool //
+wuffs_base__range_ii_u32__contains(wuffs_base__range_ii_u32* r, uint32_t x) {
+ return (r->min_incl <= x) && (x <= r->max_incl);
+}
+
+static inline bool //
+wuffs_base__range_ii_u32__contains_range(wuffs_base__range_ii_u32* r,
+ wuffs_base__range_ii_u32 s) {
+ return wuffs_base__range_ii_u32__equals(
+ &s, wuffs_base__range_ii_u32__intersect(r, s));
+}
+
#ifdef __cplusplus
inline bool //
@@ -476,11 +591,6 @@
return wuffs_base__range_ii_u32__equals(this, s);
}
-inline bool //
-wuffs_base__range_ii_u32::contains(uint32_t x) {
- return wuffs_base__range_ii_u32__contains(this, x);
-}
-
inline wuffs_base__range_ii_u32 //
wuffs_base__range_ii_u32::intersect(wuffs_base__range_ii_u32 s) {
return wuffs_base__range_ii_u32__intersect(this, s);
@@ -491,6 +601,16 @@
return wuffs_base__range_ii_u32__unite(this, s);
}
+inline bool //
+wuffs_base__range_ii_u32::contains(uint32_t x) {
+ return wuffs_base__range_ii_u32__contains(this, x);
+}
+
+inline bool //
+wuffs_base__range_ii_u32::contains_range(wuffs_base__range_ii_u32 s) {
+ return wuffs_base__range_ii_u32__contains_range(this, s);
+}
+
#endif // __cplusplus
// --------
@@ -502,16 +622,25 @@
#ifdef __cplusplus
inline bool is_empty();
inline bool equals(wuffs_base__range_ie_u32__struct s);
- inline bool contains(uint32_t x);
inline wuffs_base__range_ie_u32__struct intersect(
wuffs_base__range_ie_u32__struct s);
inline wuffs_base__range_ie_u32__struct unite(
wuffs_base__range_ie_u32__struct s);
+ inline bool contains(uint32_t x);
+ inline bool contains_range(wuffs_base__range_ie_u32__struct s);
inline uint32_t length();
#endif // __cplusplus
} wuffs_base__range_ie_u32;
+static inline wuffs_base__range_ie_u32 //
+wuffs_base__make_range_ie_u32(uint32_t min_incl, uint32_t max_excl) {
+ wuffs_base__range_ie_u32 ret;
+ ret.min_incl = min_incl;
+ ret.max_excl = max_excl;
+ return ret;
+}
+
static inline bool //
wuffs_base__range_ie_u32__is_empty(wuffs_base__range_ie_u32* r) {
return r->min_incl >= r->max_excl;
@@ -525,11 +654,6 @@
wuffs_base__range_ie_u32__is_empty(&s));
}
-static inline bool //
-wuffs_base__range_ie_u32__contains(wuffs_base__range_ie_u32* r, uint32_t x) {
- return (r->min_incl <= x) && (x < r->max_excl);
-}
-
static inline wuffs_base__range_ie_u32 //
wuffs_base__range_ie_u32__intersect(wuffs_base__range_ie_u32* r,
wuffs_base__range_ie_u32 s) {
@@ -554,6 +678,18 @@
return t;
}
+static inline bool //
+wuffs_base__range_ie_u32__contains(wuffs_base__range_ie_u32* r, uint32_t x) {
+ return (r->min_incl <= x) && (x < r->max_excl);
+}
+
+static inline bool //
+wuffs_base__range_ie_u32__contains_range(wuffs_base__range_ie_u32* r,
+ wuffs_base__range_ie_u32 s) {
+ return wuffs_base__range_ie_u32__equals(
+ &s, wuffs_base__range_ie_u32__intersect(r, s));
+}
+
static inline uint32_t //
wuffs_base__range_ie_u32__length(wuffs_base__range_ie_u32* r) {
return wuffs_base__u32__sat_sub(r->max_excl, r->min_incl);
@@ -571,11 +707,6 @@
return wuffs_base__range_ie_u32__equals(this, s);
}
-inline bool //
-wuffs_base__range_ie_u32::contains(uint32_t x) {
- return wuffs_base__range_ie_u32__contains(this, x);
-}
-
inline wuffs_base__range_ie_u32 //
wuffs_base__range_ie_u32::intersect(wuffs_base__range_ie_u32 s) {
return wuffs_base__range_ie_u32__intersect(this, s);
@@ -586,6 +717,16 @@
return wuffs_base__range_ie_u32__unite(this, s);
}
+inline bool //
+wuffs_base__range_ie_u32::contains(uint32_t x) {
+ return wuffs_base__range_ie_u32__contains(this, x);
+}
+
+inline bool //
+wuffs_base__range_ie_u32::contains_range(wuffs_base__range_ie_u32 s) {
+ return wuffs_base__range_ie_u32__contains_range(this, s);
+}
+
inline uint32_t //
wuffs_base__range_ie_u32::length() {
return wuffs_base__range_ie_u32__length(this);
@@ -602,15 +743,24 @@
#ifdef __cplusplus
inline bool is_empty();
inline bool equals(wuffs_base__range_ii_u64__struct s);
- inline bool contains(uint64_t x);
inline wuffs_base__range_ii_u64__struct intersect(
wuffs_base__range_ii_u64__struct s);
inline wuffs_base__range_ii_u64__struct unite(
wuffs_base__range_ii_u64__struct s);
+ inline bool contains(uint64_t x);
+ inline bool contains_range(wuffs_base__range_ii_u64__struct s);
#endif // __cplusplus
} wuffs_base__range_ii_u64;
+static inline wuffs_base__range_ii_u64 //
+wuffs_base__make_range_ii_u64(uint64_t min_incl, uint64_t max_incl) {
+ wuffs_base__range_ii_u64 ret;
+ ret.min_incl = min_incl;
+ ret.max_incl = max_incl;
+ return ret;
+}
+
static inline bool //
wuffs_base__range_ii_u64__is_empty(wuffs_base__range_ii_u64* r) {
return r->min_incl > r->max_incl;
@@ -624,11 +774,6 @@
wuffs_base__range_ii_u64__is_empty(&s));
}
-static inline bool //
-wuffs_base__range_ii_u64__contains(wuffs_base__range_ii_u64* r, uint64_t x) {
- return (r->min_incl <= x) && (x <= r->max_incl);
-}
-
static inline wuffs_base__range_ii_u64 //
wuffs_base__range_ii_u64__intersect(wuffs_base__range_ii_u64* r,
wuffs_base__range_ii_u64 s) {
@@ -653,6 +798,18 @@
return t;
}
+static inline bool //
+wuffs_base__range_ii_u64__contains(wuffs_base__range_ii_u64* r, uint64_t x) {
+ return (r->min_incl <= x) && (x <= r->max_incl);
+}
+
+static inline bool //
+wuffs_base__range_ii_u64__contains_range(wuffs_base__range_ii_u64* r,
+ wuffs_base__range_ii_u64 s) {
+ return wuffs_base__range_ii_u64__equals(
+ &s, wuffs_base__range_ii_u64__intersect(r, s));
+}
+
#ifdef __cplusplus
inline bool //
@@ -665,11 +822,6 @@
return wuffs_base__range_ii_u64__equals(this, s);
}
-inline bool //
-wuffs_base__range_ii_u64::contains(uint64_t x) {
- return wuffs_base__range_ii_u64__contains(this, x);
-}
-
inline wuffs_base__range_ii_u64 //
wuffs_base__range_ii_u64::intersect(wuffs_base__range_ii_u64 s) {
return wuffs_base__range_ii_u64__intersect(this, s);
@@ -680,6 +832,16 @@
return wuffs_base__range_ii_u64__unite(this, s);
}
+inline bool //
+wuffs_base__range_ii_u64::contains(uint64_t x) {
+ return wuffs_base__range_ii_u64__contains(this, x);
+}
+
+inline bool //
+wuffs_base__range_ii_u64::contains_range(wuffs_base__range_ii_u64 s) {
+ return wuffs_base__range_ii_u64__contains_range(this, s);
+}
+
#endif // __cplusplus
// --------
@@ -691,16 +853,25 @@
#ifdef __cplusplus
inline bool is_empty();
inline bool equals(wuffs_base__range_ie_u64__struct s);
- inline bool contains(uint64_t x);
inline wuffs_base__range_ie_u64__struct intersect(
wuffs_base__range_ie_u64__struct s);
inline wuffs_base__range_ie_u64__struct unite(
wuffs_base__range_ie_u64__struct s);
+ inline bool contains(uint64_t x);
+ inline bool contains_range(wuffs_base__range_ie_u64__struct s);
inline uint64_t length();
#endif // __cplusplus
} wuffs_base__range_ie_u64;
+static inline wuffs_base__range_ie_u64 //
+wuffs_base__make_range_ie_u64(uint64_t min_incl, uint64_t max_excl) {
+ wuffs_base__range_ie_u64 ret;
+ ret.min_incl = min_incl;
+ ret.max_excl = max_excl;
+ return ret;
+}
+
static inline bool //
wuffs_base__range_ie_u64__is_empty(wuffs_base__range_ie_u64* r) {
return r->min_incl >= r->max_excl;
@@ -714,11 +885,6 @@
wuffs_base__range_ie_u64__is_empty(&s));
}
-static inline bool //
-wuffs_base__range_ie_u64__contains(wuffs_base__range_ie_u64* r, uint64_t x) {
- return (r->min_incl <= x) && (x < r->max_excl);
-}
-
static inline wuffs_base__range_ie_u64 //
wuffs_base__range_ie_u64__intersect(wuffs_base__range_ie_u64* r,
wuffs_base__range_ie_u64 s) {
@@ -743,6 +909,18 @@
return t;
}
+static inline bool //
+wuffs_base__range_ie_u64__contains(wuffs_base__range_ie_u64* r, uint64_t x) {
+ return (r->min_incl <= x) && (x < r->max_excl);
+}
+
+static inline bool //
+wuffs_base__range_ie_u64__contains_range(wuffs_base__range_ie_u64* r,
+ wuffs_base__range_ie_u64 s) {
+ return wuffs_base__range_ie_u64__equals(
+ &s, wuffs_base__range_ie_u64__intersect(r, s));
+}
+
static inline uint64_t //
wuffs_base__range_ie_u64__length(wuffs_base__range_ie_u64* r) {
return wuffs_base__u64__sat_sub(r->max_excl, r->min_incl);
@@ -760,11 +938,6 @@
return wuffs_base__range_ie_u64__equals(this, s);
}
-inline bool //
-wuffs_base__range_ie_u64::contains(uint64_t x) {
- return wuffs_base__range_ie_u64__contains(this, x);
-}
-
inline wuffs_base__range_ie_u64 //
wuffs_base__range_ie_u64::intersect(wuffs_base__range_ie_u64 s) {
return wuffs_base__range_ie_u64__intersect(this, s);
@@ -775,6 +948,16 @@
return wuffs_base__range_ie_u64__unite(this, s);
}
+inline bool //
+wuffs_base__range_ie_u64::contains(uint64_t x) {
+ return wuffs_base__range_ie_u64__contains(this, x);
+}
+
+inline bool //
+wuffs_base__range_ie_u64::contains_range(wuffs_base__range_ie_u64 s) {
+ return wuffs_base__range_ie_u64__contains_range(this, s);
+}
+
inline uint64_t //
wuffs_base__range_ie_u64::length() {
return wuffs_base__range_ie_u64__length(this);
@@ -802,15 +985,29 @@
#ifdef __cplusplus
inline bool is_empty();
inline bool equals(wuffs_base__rect_ii_u32__struct s);
- inline bool contains(uint32_t x, uint32_t y);
inline wuffs_base__rect_ii_u32__struct intersect(
wuffs_base__rect_ii_u32__struct s);
inline wuffs_base__rect_ii_u32__struct unite(
wuffs_base__rect_ii_u32__struct s);
+ inline bool contains(uint32_t x, uint32_t y);
+ inline bool contains_rect(wuffs_base__rect_ii_u32__struct s);
#endif // __cplusplus
} wuffs_base__rect_ii_u32;
+static inline wuffs_base__rect_ii_u32 //
+wuffs_base__make_rect_ii_u32(uint32_t min_incl_x,
+ uint32_t min_incl_y,
+ uint32_t max_incl_x,
+ uint32_t max_incl_y) {
+ wuffs_base__rect_ii_u32 ret;
+ ret.min_incl_x = min_incl_x;
+ ret.min_incl_y = min_incl_y;
+ ret.max_incl_x = max_incl_x;
+ ret.max_incl_y = max_incl_y;
+ return ret;
+}
+
static inline bool //
wuffs_base__rect_ii_u32__is_empty(wuffs_base__rect_ii_u32* r) {
return (r->min_incl_x > r->max_incl_x) || (r->min_incl_y > r->max_incl_y);
@@ -825,14 +1022,6 @@
wuffs_base__rect_ii_u32__is_empty(&s));
}
-static inline bool //
-wuffs_base__rect_ii_u32__contains(wuffs_base__rect_ii_u32* r,
- uint32_t x,
- uint32_t y) {
- return (r->min_incl_x <= x) && (x <= r->max_incl_x) && (r->min_incl_y <= y) &&
- (y <= r->max_incl_y);
-}
-
static inline wuffs_base__rect_ii_u32 //
wuffs_base__rect_ii_u32__intersect(wuffs_base__rect_ii_u32* r,
wuffs_base__rect_ii_u32 s) {
@@ -861,6 +1050,21 @@
return t;
}
+static inline bool //
+wuffs_base__rect_ii_u32__contains(wuffs_base__rect_ii_u32* r,
+ uint32_t x,
+ uint32_t y) {
+ return (r->min_incl_x <= x) && (x <= r->max_incl_x) && (r->min_incl_y <= y) &&
+ (y <= r->max_incl_y);
+}
+
+static inline bool //
+wuffs_base__rect_ii_u32__contains_rect(wuffs_base__rect_ii_u32* r,
+ wuffs_base__rect_ii_u32 s) {
+ return wuffs_base__rect_ii_u32__equals(
+ &s, wuffs_base__rect_ii_u32__intersect(r, s));
+}
+
#ifdef __cplusplus
inline bool //
@@ -873,11 +1077,6 @@
return wuffs_base__rect_ii_u32__equals(this, s);
}
-inline bool //
-wuffs_base__rect_ii_u32::contains(uint32_t x, uint32_t y) {
- return wuffs_base__rect_ii_u32__contains(this, x, y);
-}
-
inline wuffs_base__rect_ii_u32 //
wuffs_base__rect_ii_u32::intersect(wuffs_base__rect_ii_u32 s) {
return wuffs_base__rect_ii_u32__intersect(this, s);
@@ -888,6 +1087,16 @@
return wuffs_base__rect_ii_u32__unite(this, s);
}
+inline bool //
+wuffs_base__rect_ii_u32::contains(uint32_t x, uint32_t y) {
+ return wuffs_base__rect_ii_u32__contains(this, x, y);
+}
+
+inline bool //
+wuffs_base__rect_ii_u32::contains_rect(wuffs_base__rect_ii_u32 s) {
+ return wuffs_base__rect_ii_u32__contains_rect(this, s);
+}
+
#endif // __cplusplus
// --------
@@ -911,17 +1120,31 @@
#ifdef __cplusplus
inline bool is_empty();
inline bool equals(wuffs_base__rect_ie_u32__struct s);
- inline bool contains(uint32_t x, uint32_t y);
inline wuffs_base__rect_ie_u32__struct intersect(
wuffs_base__rect_ie_u32__struct s);
inline wuffs_base__rect_ie_u32__struct unite(
wuffs_base__rect_ie_u32__struct s);
+ inline bool contains(uint32_t x, uint32_t y);
+ inline bool contains_rect(wuffs_base__rect_ie_u32__struct s);
inline uint32_t width();
inline uint32_t height();
#endif // __cplusplus
} wuffs_base__rect_ie_u32;
+static inline wuffs_base__rect_ie_u32 //
+wuffs_base__make_rect_ie_u32(uint32_t min_incl_x,
+ uint32_t min_incl_y,
+ uint32_t max_excl_x,
+ uint32_t max_excl_y) {
+ wuffs_base__rect_ie_u32 ret;
+ ret.min_incl_x = min_incl_x;
+ ret.min_incl_y = min_incl_y;
+ ret.max_excl_x = max_excl_x;
+ ret.max_excl_y = max_excl_y;
+ return ret;
+}
+
static inline bool //
wuffs_base__rect_ie_u32__is_empty(wuffs_base__rect_ie_u32* r) {
return (r->min_incl_x >= r->max_excl_x) || (r->min_incl_y >= r->max_excl_y);
@@ -936,14 +1159,6 @@
wuffs_base__rect_ie_u32__is_empty(&s));
}
-static inline bool //
-wuffs_base__rect_ie_u32__contains(wuffs_base__rect_ie_u32* r,
- uint32_t x,
- uint32_t y) {
- return (r->min_incl_x <= x) && (x < r->max_excl_x) && (r->min_incl_y <= y) &&
- (y < r->max_excl_y);
-}
-
static inline wuffs_base__rect_ie_u32 //
wuffs_base__rect_ie_u32__intersect(wuffs_base__rect_ie_u32* r,
wuffs_base__rect_ie_u32 s) {
@@ -972,6 +1187,21 @@
return t;
}
+static inline bool //
+wuffs_base__rect_ie_u32__contains(wuffs_base__rect_ie_u32* r,
+ uint32_t x,
+ uint32_t y) {
+ return (r->min_incl_x <= x) && (x < r->max_excl_x) && (r->min_incl_y <= y) &&
+ (y < r->max_excl_y);
+}
+
+static inline bool //
+wuffs_base__rect_ie_u32__contains_rect(wuffs_base__rect_ie_u32* r,
+ wuffs_base__rect_ie_u32 s) {
+ return wuffs_base__rect_ie_u32__equals(
+ &s, wuffs_base__rect_ie_u32__intersect(r, s));
+}
+
static inline uint32_t //
wuffs_base__rect_ie_u32__width(wuffs_base__rect_ie_u32* r) {
return wuffs_base__u32__sat_sub(r->max_excl_x, r->min_incl_x);
@@ -994,11 +1224,6 @@
return wuffs_base__rect_ie_u32__equals(this, s);
}
-inline bool //
-wuffs_base__rect_ie_u32::contains(uint32_t x, uint32_t y) {
- return wuffs_base__rect_ie_u32__contains(this, x, y);
-}
-
inline wuffs_base__rect_ie_u32 //
wuffs_base__rect_ie_u32::intersect(wuffs_base__rect_ie_u32 s) {
return wuffs_base__rect_ie_u32__intersect(this, s);
@@ -1009,6 +1234,16 @@
return wuffs_base__rect_ie_u32__unite(this, s);
}
+inline bool //
+wuffs_base__rect_ie_u32::contains(uint32_t x, uint32_t y) {
+ return wuffs_base__rect_ie_u32__contains(this, x, y);
+}
+
+inline bool //
+wuffs_base__rect_ie_u32::contains_rect(wuffs_base__rect_ie_u32 s) {
+ return wuffs_base__rect_ie_u32__contains_rect(this, s);
+}
+
inline uint32_t //
wuffs_base__rect_ie_u32::width() {
return wuffs_base__rect_ie_u32__width(this);
@@ -1078,6 +1313,68 @@
} wuffs_base__io_buffer;
+static inline wuffs_base__io_buffer //
+wuffs_base__make_io_buffer(wuffs_base__slice_u8 data,
+ wuffs_base__io_buffer_meta meta) {
+ wuffs_base__io_buffer ret;
+ ret.data = data;
+ ret.meta = meta;
+ return ret;
+}
+
+static inline wuffs_base__io_buffer_meta //
+wuffs_base__make_io_buffer_meta(size_t wi,
+ size_t ri,
+ uint64_t pos,
+ bool closed) {
+ wuffs_base__io_buffer_meta ret;
+ ret.wi = wi;
+ ret.ri = ri;
+ ret.pos = pos;
+ ret.closed = closed;
+ return ret;
+}
+
+static inline wuffs_base__io_buffer //
+wuffs_base__null_io_buffer() {
+ wuffs_base__io_buffer ret;
+ ret.data.ptr = NULL;
+ ret.data.len = 0;
+ ret.meta.wi = 0;
+ ret.meta.ri = 0;
+ ret.meta.pos = 0;
+ ret.meta.closed = false;
+ return ret;
+}
+
+static inline wuffs_base__io_buffer_meta //
+wuffs_base__null_io_buffer_meta() {
+ wuffs_base__io_buffer_meta ret;
+ ret.wi = 0;
+ ret.ri = 0;
+ ret.pos = 0;
+ ret.closed = false;
+ return ret;
+}
+
+static inline wuffs_base__io_reader //
+wuffs_base__null_io_reader() {
+ wuffs_base__io_reader ret;
+ ret.private_impl.buf = NULL;
+ ret.private_impl.mark = NULL;
+ ret.private_impl.limit = NULL;
+ return ret;
+}
+
+static inline wuffs_base__io_writer //
+wuffs_base__null_io_writer() {
+ wuffs_base__io_writer ret;
+ ret.private_impl.buf = NULL;
+ ret.private_impl.mark = NULL;
+ ret.private_impl.limit = NULL;
+ return ret;
+}
+
// wuffs_base__io_buffer__compact moves any written but unread bytes to the
// start of the buffer.
static inline void //
@@ -1096,15 +1393,19 @@
static inline wuffs_base__io_reader //
wuffs_base__io_buffer__reader(wuffs_base__io_buffer* buf) {
- wuffs_base__io_reader ret = ((wuffs_base__io_reader){});
+ wuffs_base__io_reader ret;
ret.private_impl.buf = buf;
+ ret.private_impl.mark = NULL;
+ ret.private_impl.limit = NULL;
return ret;
}
static inline wuffs_base__io_writer //
wuffs_base__io_buffer__writer(wuffs_base__io_buffer* buf) {
- wuffs_base__io_writer ret = ((wuffs_base__io_writer){});
+ wuffs_base__io_writer ret;
ret.private_impl.buf = buf;
+ ret.private_impl.mark = NULL;
+ ret.private_impl.limit = NULL;
return ret;
}
@@ -1167,13 +1468,10 @@
if (malloc_func && (num_u8 <= (SIZE_MAX / sizeof(uint8_t)))) {
void* p = (*malloc_func)(num_u8 * sizeof(uint8_t));
if (p) {
- return ((wuffs_base__slice_u8){
- .ptr = (uint8_t*)(p),
- .len = num_u8,
- });
+ return wuffs_base__make_slice_u8((uint8_t*)(p), num_u8);
}
}
- return ((wuffs_base__slice_u8){});
+ return wuffs_base__make_slice_u8(NULL, 0);
}
static inline wuffs_base__slice_u16 //
@@ -1181,13 +1479,10 @@
if (malloc_func && (num_u16 <= (SIZE_MAX / sizeof(uint16_t)))) {
void* p = (*malloc_func)(num_u16 * sizeof(uint16_t));
if (p) {
- return ((wuffs_base__slice_u16){
- .ptr = (uint16_t*)(p),
- .len = num_u16,
- });
+ return wuffs_base__make_slice_u16((uint16_t*)(p), num_u16);
}
}
- return ((wuffs_base__slice_u16){});
+ return wuffs_base__make_slice_u16(NULL, 0);
}
static inline wuffs_base__slice_u32 //
@@ -1195,13 +1490,10 @@
if (malloc_func && (num_u32 <= (SIZE_MAX / sizeof(uint32_t)))) {
void* p = (*malloc_func)(num_u32 * sizeof(uint32_t));
if (p) {
- return ((wuffs_base__slice_u32){
- .ptr = (uint32_t*)(p),
- .len = num_u32,
- });
+ return wuffs_base__make_slice_u32((uint32_t*)(p), num_u32);
}
}
- return ((wuffs_base__slice_u32){});
+ return wuffs_base__make_slice_u32(NULL, 0);
}
static inline wuffs_base__slice_u64 //
@@ -1209,13 +1501,10 @@
if (malloc_func && (num_u64 <= (SIZE_MAX / sizeof(uint64_t)))) {
void* p = (*malloc_func)(num_u64 * sizeof(uint64_t));
if (p) {
- return ((wuffs_base__slice_u64){
- .ptr = (uint64_t*)(p),
- .len = num_u64,
- });
+ return wuffs_base__make_slice_u64((uint64_t*)(p), num_u64);
}
}
- return ((wuffs_base__slice_u64){});
+ return wuffs_base__make_slice_u64(NULL, 0);
}
// ---------------- Images
@@ -1535,10 +1824,10 @@
} private_impl;
#ifdef __cplusplus
- inline void initialize(wuffs_base__pixel_format pixfmt,
- wuffs_base__pixel_subsampling pixsub,
- uint32_t width,
- uint32_t height);
+ inline void set(wuffs_base__pixel_format pixfmt,
+ wuffs_base__pixel_subsampling pixsub,
+ uint32_t width,
+ uint32_t height);
inline void invalidate();
inline bool is_valid();
inline wuffs_base__pixel_format pixel_format();
@@ -1551,13 +1840,23 @@
} wuffs_base__pixel_config;
+static inline wuffs_base__pixel_config //
+wuffs_base__null_pixel_config() {
+ wuffs_base__pixel_config ret;
+ ret.private_impl.pixfmt = 0;
+ ret.private_impl.pixsub = 0;
+ ret.private_impl.width = 0;
+ ret.private_impl.height = 0;
+ return ret;
+}
+
// TODO: Should this function return bool? An error type?
static inline void //
-wuffs_base__pixel_config__initialize(wuffs_base__pixel_config* c,
- wuffs_base__pixel_format pixfmt,
- wuffs_base__pixel_subsampling pixsub,
- uint32_t width,
- uint32_t height) {
+wuffs_base__pixel_config__set(wuffs_base__pixel_config* c,
+ wuffs_base__pixel_format pixfmt,
+ wuffs_base__pixel_subsampling pixsub,
+ uint32_t width,
+ uint32_t height) {
if (!c) {
return;
}
@@ -1572,13 +1871,20 @@
return;
}
}
- *c = ((wuffs_base__pixel_config){});
+
+ c->private_impl.pixfmt = 0;
+ c->private_impl.pixsub = 0;
+ c->private_impl.width = 0;
+ c->private_impl.height = 0;
}
static inline void //
wuffs_base__pixel_config__invalidate(wuffs_base__pixel_config* c) {
if (c) {
- *c = ((wuffs_base__pixel_config){});
+ c->private_impl.pixfmt = 0;
+ c->private_impl.pixsub = 0;
+ c->private_impl.width = 0;
+ c->private_impl.height = 0;
}
}
@@ -1599,13 +1905,21 @@
static inline wuffs_base__rect_ie_u32 //
wuffs_base__pixel_config__bounds(wuffs_base__pixel_config* c) {
- return c ? ((wuffs_base__rect_ie_u32){
- .min_incl_x = 0,
- .min_incl_y = 0,
- .max_excl_x = c->private_impl.width,
- .max_excl_y = c->private_impl.height,
- })
- : ((wuffs_base__rect_ie_u32){});
+ if (c) {
+ wuffs_base__rect_ie_u32 ret;
+ ret.min_incl_x = 0;
+ ret.min_incl_y = 0;
+ ret.max_excl_x = c->private_impl.width;
+ ret.max_excl_y = c->private_impl.height;
+ return ret;
+ }
+
+ wuffs_base__rect_ie_u32 ret;
+ ret.min_incl_x = 0;
+ ret.min_incl_y = 0;
+ ret.max_excl_x = 0;
+ ret.max_excl_y = 0;
+ return ret;
}
static inline uint32_t //
@@ -1658,11 +1972,11 @@
#ifdef __cplusplus
inline void //
-wuffs_base__pixel_config::initialize(wuffs_base__pixel_format pixfmt,
- wuffs_base__pixel_subsampling pixsub,
- uint32_t width,
- uint32_t height) {
- wuffs_base__pixel_config__initialize(this, pixfmt, pixsub, width, height);
+wuffs_base__pixel_config::set(wuffs_base__pixel_format pixfmt,
+ wuffs_base__pixel_subsampling pixsub,
+ uint32_t width,
+ uint32_t height) {
+ wuffs_base__pixel_config__set(this, pixfmt, pixsub, width, height);
}
inline void //
@@ -1720,12 +2034,12 @@
} private_impl;
#ifdef __cplusplus
- inline void initialize(wuffs_base__pixel_format pixfmt,
- wuffs_base__pixel_subsampling pixsub,
- uint32_t width,
- uint32_t height,
- uint64_t first_frame_io_position,
- bool first_frame_is_opaque);
+ inline void set(wuffs_base__pixel_format pixfmt,
+ wuffs_base__pixel_subsampling pixsub,
+ uint32_t width,
+ uint32_t height,
+ uint64_t first_frame_io_position,
+ bool first_frame_is_opaque);
inline void invalidate();
inline bool is_valid();
inline uint64_t first_frame_io_position();
@@ -1734,15 +2048,24 @@
} wuffs_base__image_config;
+static inline wuffs_base__image_config //
+wuffs_base__null_image_config() {
+ wuffs_base__image_config ret;
+ ret.pixcfg = wuffs_base__null_pixel_config();
+ ret.private_impl.first_frame_io_position = 0;
+ ret.private_impl.first_frame_is_opaque = false;
+ return ret;
+}
+
// TODO: Should this function return bool? An error type?
static inline void //
-wuffs_base__image_config__initialize(wuffs_base__image_config* c,
- wuffs_base__pixel_format pixfmt,
- wuffs_base__pixel_subsampling pixsub,
- uint32_t width,
- uint32_t height,
- uint64_t first_frame_io_position,
- bool first_frame_is_opaque) {
+wuffs_base__image_config__set(wuffs_base__image_config* c,
+ wuffs_base__pixel_format pixfmt,
+ wuffs_base__pixel_subsampling pixsub,
+ uint32_t width,
+ uint32_t height,
+ uint64_t first_frame_io_position,
+ bool first_frame_is_opaque) {
if (!c) {
return;
}
@@ -1755,13 +2078,24 @@
c->private_impl.first_frame_is_opaque = first_frame_is_opaque;
return;
}
- *c = ((wuffs_base__image_config){});
+
+ c->pixcfg.private_impl.pixfmt = 0;
+ c->pixcfg.private_impl.pixsub = 0;
+ c->pixcfg.private_impl.width = 0;
+ c->pixcfg.private_impl.height = 0;
+ c->private_impl.first_frame_io_position = 0;
+ c->private_impl.first_frame_is_opaque = 0;
}
static inline void //
wuffs_base__image_config__invalidate(wuffs_base__image_config* c) {
if (c) {
- *c = ((wuffs_base__image_config){});
+ c->pixcfg.private_impl.pixfmt = 0;
+ c->pixcfg.private_impl.pixsub = 0;
+ c->pixcfg.private_impl.width = 0;
+ c->pixcfg.private_impl.height = 0;
+ c->private_impl.first_frame_io_position = 0;
+ c->private_impl.first_frame_is_opaque = 0;
}
}
@@ -1783,15 +2117,14 @@
#ifdef __cplusplus
inline void //
-wuffs_base__image_config::initialize(wuffs_base__pixel_format pixfmt,
- wuffs_base__pixel_subsampling pixsub,
- uint32_t width,
- uint32_t height,
- uint64_t first_frame_io_position,
- bool first_frame_is_opaque) {
- wuffs_base__image_config__initialize(this, pixfmt, pixsub, width, height,
- first_frame_io_position,
- first_frame_is_opaque);
+wuffs_base__image_config::set(wuffs_base__pixel_format pixfmt,
+ wuffs_base__pixel_subsampling pixsub,
+ uint32_t width,
+ uint32_t height,
+ uint64_t first_frame_io_position,
+ bool first_frame_is_opaque) {
+ wuffs_base__image_config__set(this, pixfmt, pixsub, width, height,
+ first_frame_io_position, first_frame_is_opaque);
}
inline void //
@@ -1887,6 +2220,18 @@
} wuffs_base__frame_config;
+static inline wuffs_base__frame_config //
+wuffs_base__null_frame_config() {
+ wuffs_base__frame_config ret;
+ ret.private_impl.bounds = wuffs_base__make_rect_ie_u32(0, 0, 0, 0);
+ ret.private_impl.duration = 0;
+ ret.private_impl.index = 0;
+ ret.private_impl.io_position = 0;
+ ret.private_impl.blend = 0;
+ ret.private_impl.disposal = 0;
+ return ret;
+}
+
static inline void //
wuffs_base__frame_config__update(wuffs_base__frame_config* c,
wuffs_base__rect_ie_u32 bounds,
@@ -1909,7 +2254,16 @@
static inline wuffs_base__rect_ie_u32 //
wuffs_base__frame_config__bounds(wuffs_base__frame_config* c) {
- return c ? c->private_impl.bounds : ((wuffs_base__rect_ie_u32){});
+ if (c) {
+ return c->private_impl.bounds;
+ }
+
+ wuffs_base__rect_ie_u32 ret;
+ ret.min_incl_x = 0;
+ ret.min_incl_y = 0;
+ ret.max_excl_x = 0;
+ ret.max_excl_y = 0;
+ return ret;
}
static inline uint32_t //
@@ -2034,6 +2388,17 @@
} wuffs_base__pixel_buffer;
+static inline wuffs_base__pixel_buffer //
+wuffs_base__null_pixel_buffer() {
+ wuffs_base__pixel_buffer ret;
+ ret.pixcfg = wuffs_base__null_pixel_config();
+ ret.private_impl.planes[0] = wuffs_base__null_table_u8();
+ ret.private_impl.planes[1] = wuffs_base__null_table_u8();
+ ret.private_impl.planes[2] = wuffs_base__null_table_u8();
+ ret.private_impl.planes[3] = wuffs_base__null_table_u8();
+ return ret;
+}
+
static inline wuffs_base__status //
wuffs_base__pixel_buffer__set_from_slice(wuffs_base__pixel_buffer* b,
wuffs_base__pixel_config* pixcfg,
@@ -2041,7 +2406,7 @@
if (!b) {
return wuffs_base__error__bad_receiver;
}
- *b = ((wuffs_base__pixel_buffer){});
+ memset(b, 0, sizeof(*b));
if (!pixcfg) {
return wuffs_base__error__bad_argument;
}
@@ -2107,13 +2472,10 @@
wuffs_base__table_u8* tab =
&b->private_impl.planes[WUFFS_BASE__PIXEL_FORMAT__INDEXED__COLOR_PLANE];
if ((tab->width == 1024) && (tab->height == 1)) {
- return ((wuffs_base__slice_u8){
- .ptr = tab->ptr,
- .len = 1024,
- });
+ return wuffs_base__make_slice_u8(tab->ptr, 1024);
}
}
- return ((wuffs_base__slice_u8){});
+ return wuffs_base__make_slice_u8(NULL, 0);
}
static inline wuffs_base__pixel_format //
@@ -2126,9 +2488,16 @@
static inline wuffs_base__table_u8 //
wuffs_base__pixel_buffer__plane(wuffs_base__pixel_buffer* b, uint32_t p) {
- return (b && (p < WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX))
- ? b->private_impl.planes[p]
- : ((wuffs_base__table_u8){});
+ if (b && (p < WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX)) {
+ return b->private_impl.planes[p];
+ }
+
+ wuffs_base__table_u8 ret;
+ ret.ptr = NULL;
+ ret.width = 0;
+ ret.height = 0;
+ ret.stride = 0;
+ return ret;
}
#ifdef __cplusplus
@@ -2187,10 +2556,10 @@
} private_impl;
#ifdef __cplusplus
- inline void initialize(wuffs_base__pixel_format dst_format,
- wuffs_base__slice_u8 dst_palette,
- wuffs_base__pixel_format src_format,
- wuffs_base__slice_u8 src_palette);
+ inline void prepare(wuffs_base__pixel_format dst_format,
+ wuffs_base__slice_u8 dst_palette,
+ wuffs_base__pixel_format src_format,
+ wuffs_base__slice_u8 src_palette);
inline uint64_t swizzle_packed(wuffs_base__slice_u8 dst,
wuffs_base__slice_u8 dst_palette,
wuffs_base__slice_u8 src);
@@ -2198,14 +2567,14 @@
} wuffs_base__pixel_swizzler;
-// TODO: should initialize (both the C and C++ methods) return a status?
+// TODO: should prepare (both the C and C++ methods) return a status?
void //
-wuffs_base__pixel_swizzler__initialize(wuffs_base__pixel_swizzler* p,
- wuffs_base__pixel_format dst_format,
- wuffs_base__slice_u8 dst_palette,
- wuffs_base__pixel_format src_format,
- wuffs_base__slice_u8 src_palette);
+wuffs_base__pixel_swizzler__prepare(wuffs_base__pixel_swizzler* p,
+ wuffs_base__pixel_format dst_format,
+ wuffs_base__slice_u8 dst_palette,
+ wuffs_base__pixel_format src_format,
+ wuffs_base__slice_u8 src_palette);
uint64_t //
wuffs_base__pixel_swizzler__swizzle_packed(wuffs_base__pixel_swizzler* p,
@@ -2216,12 +2585,12 @@
#ifdef __cplusplus
inline void //
-wuffs_base__pixel_swizzler::initialize(wuffs_base__pixel_format dst_format,
- wuffs_base__slice_u8 dst_palette,
- wuffs_base__pixel_format src_format,
- wuffs_base__slice_u8 src_palette) {
- wuffs_base__pixel_swizzler__initialize(this, dst_format, dst_palette,
- src_format, src_palette);
+wuffs_base__pixel_swizzler::prepare(wuffs_base__pixel_format dst_format,
+ wuffs_base__slice_u8 dst_palette,
+ wuffs_base__pixel_format src_format,
+ wuffs_base__slice_u8 src_palette) {
+ wuffs_base__pixel_swizzler__prepare(this, dst_format, dst_palette, src_format,
+ src_palette);
}
uint64_t //
@@ -2238,6 +2607,10 @@
} // extern "C"
#endif
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -2252,15 +2625,17 @@
// ---------------- Public Initializer Prototypes
-// wuffs_adler32__hasher__check_wuffs_version is an initializer function.
-//
-// It should be called before any other wuffs_adler32__hasher__* function.
+// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
+// etc)" should be called before any other "wuffs_foo__bar__xxx(self, etc)".
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
+// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for initialize_flags.
+
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
-wuffs_adler32__hasher__check_wuffs_version(wuffs_adler32__hasher* self,
- size_t sizeof_star_self,
- uint64_t wuffs_version);
+wuffs_adler32__hasher__initialize(wuffs_adler32__hasher* self,
+ size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags);
size_t //
sizeof__wuffs_adler32__hasher();
@@ -2283,14 +2658,16 @@
struct wuffs_adler32__hasher__struct {
#ifdef WUFFS_IMPLEMENTATION
- // 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
- // wuffs_foo__bar__baz functions.
+ // Do not access the private_impl's or private_data's fields directly. There
+ // is no API/ABI compatibility or safety guarantee if you do so. Instead, use
+ // the wuffs_foo__bar__baz functions.
//
- // It is a struct, not a struct*, so that the outermost wuffs_foo__bar
- // struct can be stack allocated when WUFFS_IMPLEMENTATION is defined.
+ // It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct
+ // can be stack allocated when WUFFS_IMPLEMENTATION is defined.
+
struct {
uint32_t magic;
+ uint32_t active_coroutine;
uint32_t f_state;
bool f_started;
@@ -2309,18 +2686,24 @@
// Even when WUFFS_IMPLEMENTATION is not defined, the outermost struct still
// defines C++ convenience methods. These methods forward on "this", so that
// you can write "bar->baz(etc)" instead of "wuffs_foo__bar__baz(bar, etc)".
- struct {
+ private:
+ union {
+ uint32_t align_as_per_magic_field;
uint8_t placeholder[1073741824]; // 1 GiB.
- } private_impl;
+ } private_impl WUFFS_BASE__POTENTIALLY_UNUSED_FIELD;
+
+ public:
#endif // WUFFS_IMPLEMENTATION
#ifdef __cplusplus
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
- check_wuffs_version(size_t sizeof_star_self, uint64_t wuffs_version) {
- return wuffs_adler32__hasher__check_wuffs_version(this, sizeof_star_self,
- wuffs_version);
+ initialize(size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags) {
+ return wuffs_adler32__hasher__initialize(this, sizeof_star_self,
+ wuffs_version, initialize_flags);
}
inline uint32_t //
@@ -2359,15 +2742,17 @@
// ---------------- Public Initializer Prototypes
-// wuffs_crc32__ieee_hasher__check_wuffs_version is an initializer function.
-//
-// It should be called before any other wuffs_crc32__ieee_hasher__* function.
+// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
+// etc)" should be called before any other "wuffs_foo__bar__xxx(self, etc)".
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
+// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for initialize_flags.
+
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
-wuffs_crc32__ieee_hasher__check_wuffs_version(wuffs_crc32__ieee_hasher* self,
- size_t sizeof_star_self,
- uint64_t wuffs_version);
+wuffs_crc32__ieee_hasher__initialize(wuffs_crc32__ieee_hasher* self,
+ size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags);
size_t //
sizeof__wuffs_crc32__ieee_hasher();
@@ -2390,14 +2775,16 @@
struct wuffs_crc32__ieee_hasher__struct {
#ifdef WUFFS_IMPLEMENTATION
- // 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
- // wuffs_foo__bar__baz functions.
+ // Do not access the private_impl's or private_data's fields directly. There
+ // is no API/ABI compatibility or safety guarantee if you do so. Instead, use
+ // the wuffs_foo__bar__baz functions.
//
- // It is a struct, not a struct*, so that the outermost wuffs_foo__bar
- // struct can be stack allocated when WUFFS_IMPLEMENTATION is defined.
+ // It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct
+ // can be stack allocated when WUFFS_IMPLEMENTATION is defined.
+
struct {
uint32_t magic;
+ uint32_t active_coroutine;
uint32_t f_state;
@@ -2415,18 +2802,24 @@
// Even when WUFFS_IMPLEMENTATION is not defined, the outermost struct still
// defines C++ convenience methods. These methods forward on "this", so that
// you can write "bar->baz(etc)" instead of "wuffs_foo__bar__baz(bar, etc)".
- struct {
+ private:
+ union {
+ uint32_t align_as_per_magic_field;
uint8_t placeholder[1073741824]; // 1 GiB.
- } private_impl;
+ } private_impl WUFFS_BASE__POTENTIALLY_UNUSED_FIELD;
+
+ public:
#endif // WUFFS_IMPLEMENTATION
#ifdef __cplusplus
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
- check_wuffs_version(size_t sizeof_star_self, uint64_t wuffs_version) {
- return wuffs_crc32__ieee_hasher__check_wuffs_version(this, sizeof_star_self,
- wuffs_version);
+ initialize(size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags) {
+ return wuffs_crc32__ieee_hasher__initialize(
+ this, sizeof_star_self, wuffs_version, initialize_flags);
}
inline uint32_t //
@@ -2474,31 +2867,43 @@
// ---------------- Public Consts
+#define WUFFS_DEFLATE__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 1
+
+static const uint64_t //
+ wuffs_deflate__decoder_workbuf_len_max_incl_worst_case //
+ WUFFS_BASE__POTENTIALLY_UNUSED = 1;
+
// ---------------- Struct Declarations
typedef struct wuffs_deflate__decoder__struct wuffs_deflate__decoder;
// ---------------- Public Initializer Prototypes
-// wuffs_deflate__decoder__check_wuffs_version is an initializer function.
-//
-// It should be called before any other wuffs_deflate__decoder__* function.
+// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
+// etc)" should be called before any other "wuffs_foo__bar__xxx(self, etc)".
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
+// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for initialize_flags.
+
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
-wuffs_deflate__decoder__check_wuffs_version(wuffs_deflate__decoder* self,
- size_t sizeof_star_self,
- uint64_t wuffs_version);
+wuffs_deflate__decoder__initialize(wuffs_deflate__decoder* self,
+ size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags);
size_t //
sizeof__wuffs_deflate__decoder();
// ---------------- Public Function Prototypes
+WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 //
+wuffs_deflate__decoder__workbuf_len(const wuffs_deflate__decoder* self);
+
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_deflate__decoder__decode_io_writer(wuffs_deflate__decoder* self,
wuffs_base__io_writer a_dst,
- wuffs_base__io_reader a_src);
+ wuffs_base__io_reader a_src,
+ wuffs_base__slice_u8 a_workbuf);
// ---------------- Struct Definitions
@@ -2512,38 +2917,43 @@
struct wuffs_deflate__decoder__struct {
#ifdef WUFFS_IMPLEMENTATION
- // 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
- // wuffs_foo__bar__baz functions.
+ // Do not access the private_impl's or private_data's fields directly. There
+ // is no API/ABI compatibility or safety guarantee if you do so. Instead, use
+ // the wuffs_foo__bar__baz functions.
//
- // It is a struct, not a struct*, so that the outermost wuffs_foo__bar
- // struct can be stack allocated when WUFFS_IMPLEMENTATION is defined.
+ // It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct
+ // can be stack allocated when WUFFS_IMPLEMENTATION is defined.
+
struct {
uint32_t magic;
+ uint32_t active_coroutine;
uint32_t f_bits;
uint32_t f_n_bits;
- uint32_t f_huffs[2][1234];
- uint32_t f_n_huffs_bits[2];
- uint8_t f_history[32768];
uint32_t f_history_index;
- uint8_t f_code_lengths[320];
+ uint32_t f_n_huffs_bits[2];
bool f_end_of_block;
+ uint32_t p_decode_io_writer[1];
+ uint32_t p_decode_blocks[1];
+ uint32_t p_decode_uncompressed[1];
+ uint32_t p_init_dynamic_huffman[1];
+ uint32_t p_decode_huffman_slow[1];
+ } private_impl;
+
+ struct {
+ uint32_t f_huffs[2][1024];
+ uint8_t f_history[32768];
+ uint8_t f_code_lengths[320];
+
struct {
- uint32_t coro_susp_point;
- } c_decode_io_writer[1];
- struct {
- uint32_t coro_susp_point;
uint32_t v_final;
- } c_decode_blocks[1];
+ } s_decode_blocks[1];
struct {
- uint32_t coro_susp_point;
uint32_t v_length;
uint64_t scratch;
- } c_decode_uncompressed[1];
+ } s_decode_uncompressed[1];
struct {
- uint32_t coro_susp_point;
uint32_t v_bits;
uint32_t v_n_bits;
uint32_t v_n_lit;
@@ -2555,9 +2965,8 @@
uint32_t v_n_extra_bits;
uint8_t v_rep_symbol;
uint32_t v_rep_count;
- } c_init_dynamic_huffman[1];
+ } s_init_dynamic_huffman[1];
struct {
- uint32_t coro_susp_point;
uint32_t v_bits;
uint32_t v_n_bits;
uint32_t v_table_entry;
@@ -2570,8 +2979,8 @@
uint32_t v_dist_minus_1;
uint32_t v_hlen;
uint32_t v_hdist;
- } c_decode_huffman_slow[1];
- } private_impl;
+ } s_decode_huffman_slow[1];
+ } private_data;
#else // WUFFS_IMPLEMENTATION
@@ -2585,23 +2994,37 @@
// Even when WUFFS_IMPLEMENTATION is not defined, the outermost struct still
// defines C++ convenience methods. These methods forward on "this", so that
// you can write "bar->baz(etc)" instead of "wuffs_foo__bar__baz(bar, etc)".
- struct {
+ private:
+ union {
+ uint32_t align_as_per_magic_field;
uint8_t placeholder[1073741824]; // 1 GiB.
- } private_impl;
+ } private_impl WUFFS_BASE__POTENTIALLY_UNUSED_FIELD;
+
+ public:
#endif // WUFFS_IMPLEMENTATION
#ifdef __cplusplus
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
- check_wuffs_version(size_t sizeof_star_self, uint64_t wuffs_version) {
- return wuffs_deflate__decoder__check_wuffs_version(this, sizeof_star_self,
- wuffs_version);
+ initialize(size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags) {
+ return wuffs_deflate__decoder__initialize(this, sizeof_star_self,
+ wuffs_version, initialize_flags);
+ }
+
+ inline wuffs_base__range_ii_u64 //
+ workbuf_len() const {
+ return wuffs_deflate__decoder__workbuf_len(this);
}
inline wuffs_base__status //
- decode_io_writer(wuffs_base__io_writer a_dst, wuffs_base__io_reader a_src) {
- return wuffs_deflate__decoder__decode_io_writer(this, a_dst, a_src);
+ decode_io_writer(wuffs_base__io_writer a_dst,
+ wuffs_base__io_reader a_src,
+ wuffs_base__slice_u8 a_workbuf) {
+ return wuffs_deflate__decoder__decode_io_writer(this, a_dst, a_src,
+ a_workbuf);
}
#if (__cplusplus >= 201103L) && !defined(WUFFS_IMPLEMENTATION)
@@ -2632,21 +3055,29 @@
// ---------------- Public Consts
+#define WUFFS_LZW__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 0
+
+static const uint64_t //
+ wuffs_lzw__decoder_workbuf_len_max_incl_worst_case //
+ WUFFS_BASE__POTENTIALLY_UNUSED = 0;
+
// ---------------- Struct Declarations
typedef struct wuffs_lzw__decoder__struct wuffs_lzw__decoder;
// ---------------- Public Initializer Prototypes
-// wuffs_lzw__decoder__check_wuffs_version is an initializer function.
-//
-// It should be called before any other wuffs_lzw__decoder__* function.
+// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
+// etc)" should be called before any other "wuffs_foo__bar__xxx(self, etc)".
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
+// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for initialize_flags.
+
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
-wuffs_lzw__decoder__check_wuffs_version(wuffs_lzw__decoder* self,
- size_t sizeof_star_self,
- uint64_t wuffs_version);
+wuffs_lzw__decoder__initialize(wuffs_lzw__decoder* self,
+ size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags);
size_t //
sizeof__wuffs_lzw__decoder();
@@ -2656,10 +3087,14 @@
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct //
wuffs_lzw__decoder__set_literal_width(wuffs_lzw__decoder* self, uint32_t a_lw);
+WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 //
+wuffs_lzw__decoder__workbuf_len(const wuffs_lzw__decoder* self);
+
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_lzw__decoder__decode_io_writer(wuffs_lzw__decoder* self,
wuffs_base__io_writer a_dst,
- wuffs_base__io_reader a_src);
+ wuffs_base__io_reader a_src,
+ wuffs_base__slice_u8 a_workbuf);
WUFFS_BASE__MAYBE_STATIC wuffs_base__slice_u8 //
wuffs_lzw__decoder__flush(wuffs_lzw__decoder* self);
@@ -2676,16 +3111,18 @@
struct wuffs_lzw__decoder__struct {
#ifdef WUFFS_IMPLEMENTATION
- // 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
- // wuffs_foo__bar__baz functions.
+ // Do not access the private_impl's or private_data's fields directly. There
+ // is no API/ABI compatibility or safety guarantee if you do so. Instead, use
+ // the wuffs_foo__bar__baz functions.
//
- // It is a struct, not a struct*, so that the outermost wuffs_foo__bar
- // struct can be stack allocated when WUFFS_IMPLEMENTATION is defined.
+ // It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct
+ // can be stack allocated when WUFFS_IMPLEMENTATION is defined.
+
struct {
uint32_t magic;
+ uint32_t active_coroutine;
- uint32_t f_lw;
+ uint32_t f_set_literal_width_arg;
uint32_t f_literal_width;
uint32_t f_clear_code;
uint32_t f_end_code;
@@ -2697,18 +3134,18 @@
uint32_t f_output_ri;
uint32_t f_output_wi;
uint32_t f_read_from_return_value;
- uint8_t f_suffixes[4096][8];
uint16_t f_prefixes[4096];
+
+ uint32_t p_decode_io_writer[1];
+ uint32_t p_write_to[1];
+ } private_impl;
+
+ struct {
+ uint8_t f_suffixes[4096][8];
uint16_t f_lm1s[4096];
uint8_t f_output[8199];
- struct {
- uint32_t coro_susp_point;
- } c_decode_io_writer[1];
- struct {
- uint32_t coro_susp_point;
- } c_write_to[1];
- } private_impl;
+ } private_data;
#else // WUFFS_IMPLEMENTATION
@@ -2722,18 +3159,24 @@
// Even when WUFFS_IMPLEMENTATION is not defined, the outermost struct still
// defines C++ convenience methods. These methods forward on "this", so that
// you can write "bar->baz(etc)" instead of "wuffs_foo__bar__baz(bar, etc)".
- struct {
+ private:
+ union {
+ uint32_t align_as_per_magic_field;
uint8_t placeholder[1073741824]; // 1 GiB.
- } private_impl;
+ } private_impl WUFFS_BASE__POTENTIALLY_UNUSED_FIELD;
+
+ public:
#endif // WUFFS_IMPLEMENTATION
#ifdef __cplusplus
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
- check_wuffs_version(size_t sizeof_star_self, uint64_t wuffs_version) {
- return wuffs_lzw__decoder__check_wuffs_version(this, sizeof_star_self,
- wuffs_version);
+ initialize(size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags) {
+ return wuffs_lzw__decoder__initialize(this, sizeof_star_self, wuffs_version,
+ initialize_flags);
}
inline wuffs_base__empty_struct //
@@ -2741,9 +3184,16 @@
return wuffs_lzw__decoder__set_literal_width(this, a_lw);
}
+ inline wuffs_base__range_ii_u64 //
+ workbuf_len() const {
+ return wuffs_lzw__decoder__workbuf_len(this);
+ }
+
inline wuffs_base__status //
- decode_io_writer(wuffs_base__io_writer a_dst, wuffs_base__io_reader a_src) {
- return wuffs_lzw__decoder__decode_io_writer(this, a_dst, a_src);
+ decode_io_writer(wuffs_base__io_writer a_dst,
+ wuffs_base__io_reader a_src,
+ wuffs_base__slice_u8 a_workbuf) {
+ return wuffs_lzw__decoder__decode_io_writer(this, a_dst, a_src, a_workbuf);
}
inline wuffs_base__slice_u8 //
@@ -2779,26 +3229,32 @@
extern const char* wuffs_gif__error__bad_graphic_control;
extern const char* wuffs_gif__error__bad_header;
extern const char* wuffs_gif__error__bad_literal_width;
-extern const char* wuffs_gif__error__not_enough_pixel_data;
-extern const char* wuffs_gif__error__too_much_pixel_data;
// ---------------- Public Consts
+#define WUFFS_GIF__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 1
+
+static const uint64_t //
+ wuffs_gif__decoder_workbuf_len_max_incl_worst_case //
+ WUFFS_BASE__POTENTIALLY_UNUSED = 1;
+
// ---------------- Struct Declarations
typedef struct wuffs_gif__decoder__struct wuffs_gif__decoder;
// ---------------- Public Initializer Prototypes
-// wuffs_gif__decoder__check_wuffs_version is an initializer function.
-//
-// It should be called before any other wuffs_gif__decoder__* function.
+// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
+// etc)" should be called before any other "wuffs_foo__bar__xxx(self, etc)".
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
+// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for initialize_flags.
+
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
-wuffs_gif__decoder__check_wuffs_version(wuffs_gif__decoder* self,
- size_t sizeof_star_self,
- uint64_t wuffs_version);
+wuffs_gif__decoder__initialize(wuffs_gif__decoder* self,
+ size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags);
size_t //
sizeof__wuffs_gif__decoder();
@@ -2854,14 +3310,16 @@
struct wuffs_gif__decoder__struct {
#ifdef WUFFS_IMPLEMENTATION
- // 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
- // wuffs_foo__bar__baz functions.
+ // Do not access the private_impl's or private_data's fields directly. There
+ // is no API/ABI compatibility or safety guarantee if you do so. Instead, use
+ // the wuffs_foo__bar__baz functions.
//
- // It is a struct, not a struct*, so that the outermost wuffs_foo__bar
- // struct can be stack allocated when WUFFS_IMPLEMENTATION is defined.
+ // It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct
+ // can be stack allocated when WUFFS_IMPLEMENTATION is defined.
+
struct {
uint32_t magic;
+ uint32_t active_coroutine;
uint32_t f_width;
uint32_t f_height;
@@ -2890,77 +3348,70 @@
wuffs_base__range_ie_u32 f_dirty_y;
uint64_t f_compressed_ri;
uint64_t f_compressed_wi;
+ wuffs_base__pixel_swizzler f_swizzler;
+
+ uint32_t p_decode_image_config[1];
+ uint32_t p_decode_frame_config[1];
+ uint32_t p_skip_frame[1];
+ uint32_t p_decode_frame[1];
+ uint32_t p_decode_up_to_id_part1[1];
+ uint32_t p_decode_header[1];
+ uint32_t p_decode_lsd[1];
+ uint32_t p_decode_extension[1];
+ uint32_t p_skip_blocks[1];
+ uint32_t p_decode_ae[1];
+ uint32_t p_decode_gc[1];
+ uint32_t p_decode_id_part0[1];
+ uint32_t p_decode_id_part1[1];
+ uint32_t p_decode_id_part2[1];
+ } private_impl;
+
+ struct {
uint8_t f_compressed[4096];
uint8_t f_palettes[2][1024];
uint8_t f_dst_palette[1024];
- wuffs_base__pixel_swizzler f_swizzler;
- wuffs_base__utility f_util;
wuffs_lzw__decoder f_lzw;
struct {
- uint32_t coro_susp_point;
- } c_decode_image_config[1];
- struct {
- uint32_t coro_susp_point;
- } c_decode_frame_config[1];
- struct {
- uint32_t coro_susp_point;
uint64_t scratch;
- } c_skip_frame[1];
+ } s_skip_frame[1];
struct {
- uint32_t coro_susp_point;
- } c_decode_frame[1];
- struct {
- uint32_t coro_susp_point;
- } c_decode_up_to_id_part1[1];
- struct {
- uint32_t coro_susp_point;
uint8_t v_c[6];
uint32_t v_i;
- } c_decode_header[1];
+ } s_decode_header[1];
struct {
- uint32_t coro_susp_point;
uint8_t v_flags;
uint32_t v_num_palette_entries;
uint32_t v_i;
uint64_t scratch;
- } c_decode_lsd[1];
+ } s_decode_lsd[1];
struct {
- uint32_t coro_susp_point;
- } c_decode_extension[1];
- struct {
- uint32_t coro_susp_point;
uint64_t scratch;
- } c_skip_blocks[1];
+ } s_skip_blocks[1];
struct {
- uint32_t coro_susp_point;
uint8_t v_block_size;
bool v_not_animexts;
bool v_not_netscape;
uint64_t scratch;
- } c_decode_ae[1];
+ } s_decode_ae[1];
struct {
- uint32_t coro_susp_point;
uint64_t scratch;
- } c_decode_gc[1];
+ } s_decode_gc[1];
struct {
- uint32_t coro_susp_point;
uint64_t scratch;
- } c_decode_id_part0[1];
+ } s_decode_id_part0[1];
struct {
- uint32_t coro_susp_point;
uint32_t v_num_palette_entries;
uint32_t v_i;
uint64_t scratch;
- } c_decode_id_part1[1];
+ } s_decode_id_part1[1];
struct {
- uint32_t coro_susp_point;
uint64_t v_block_size;
bool v_need_block_size;
wuffs_base__status v_lzw_status;
uint64_t scratch;
- } c_decode_id_part2[1];
- } private_impl;
+ } s_decode_id_part2[1];
+ } private_data;
#else // WUFFS_IMPLEMENTATION
@@ -2974,18 +3425,24 @@
// Even when WUFFS_IMPLEMENTATION is not defined, the outermost struct still
// defines C++ convenience methods. These methods forward on "this", so that
// you can write "bar->baz(etc)" instead of "wuffs_foo__bar__baz(bar, etc)".
- struct {
+ private:
+ union {
+ uint32_t align_as_per_magic_field;
uint8_t placeholder[1073741824]; // 1 GiB.
- } private_impl;
+ } private_impl WUFFS_BASE__POTENTIALLY_UNUSED_FIELD;
+
+ public:
#endif // WUFFS_IMPLEMENTATION
#ifdef __cplusplus
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
- check_wuffs_version(size_t sizeof_star_self, uint64_t wuffs_version) {
- return wuffs_gif__decoder__check_wuffs_version(this, sizeof_star_self,
- wuffs_version);
+ initialize(size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags) {
+ return wuffs_gif__decoder__initialize(this, sizeof_star_self, wuffs_version,
+ initialize_flags);
}
inline wuffs_base__status //
@@ -3069,21 +3526,29 @@
// ---------------- Public Consts
+#define WUFFS_GZIP__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 1
+
+static const uint64_t //
+ wuffs_gzip__decoder_workbuf_len_max_incl_worst_case //
+ WUFFS_BASE__POTENTIALLY_UNUSED = 1;
+
// ---------------- Struct Declarations
typedef struct wuffs_gzip__decoder__struct wuffs_gzip__decoder;
// ---------------- Public Initializer Prototypes
-// wuffs_gzip__decoder__check_wuffs_version is an initializer function.
-//
-// It should be called before any other wuffs_gzip__decoder__* function.
+// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
+// etc)" should be called before any other "wuffs_foo__bar__xxx(self, etc)".
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
+// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for initialize_flags.
+
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
-wuffs_gzip__decoder__check_wuffs_version(wuffs_gzip__decoder* self,
- size_t sizeof_star_self,
- uint64_t wuffs_version);
+wuffs_gzip__decoder__initialize(wuffs_gzip__decoder* self,
+ size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags);
size_t //
sizeof__wuffs_gzip__decoder();
@@ -3093,10 +3558,14 @@
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct //
wuffs_gzip__decoder__set_ignore_checksum(wuffs_gzip__decoder* self, bool a_ic);
+WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 //
+wuffs_gzip__decoder__workbuf_len(const wuffs_gzip__decoder* self);
+
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_gzip__decoder__decode_io_writer(wuffs_gzip__decoder* self,
wuffs_base__io_writer a_dst,
- wuffs_base__io_reader a_src);
+ wuffs_base__io_reader a_src,
+ wuffs_base__slice_u8 a_workbuf);
// ---------------- Struct Definitions
@@ -3110,28 +3579,34 @@
struct wuffs_gzip__decoder__struct {
#ifdef WUFFS_IMPLEMENTATION
- // 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
- // wuffs_foo__bar__baz functions.
+ // Do not access the private_impl's or private_data's fields directly. There
+ // is no API/ABI compatibility or safety guarantee if you do so. Instead, use
+ // the wuffs_foo__bar__baz functions.
//
- // It is a struct, not a struct*, so that the outermost wuffs_foo__bar
- // struct can be stack allocated when WUFFS_IMPLEMENTATION is defined.
+ // It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct
+ // can be stack allocated when WUFFS_IMPLEMENTATION is defined.
+
struct {
uint32_t magic;
+ uint32_t active_coroutine;
- wuffs_deflate__decoder f_flate;
- wuffs_crc32__ieee_hasher f_checksum;
bool f_ignore_checksum;
+ uint32_t p_decode_io_writer[1];
+ } private_impl;
+
+ struct {
+ wuffs_crc32__ieee_hasher f_checksum;
+ wuffs_deflate__decoder f_flate;
+
struct {
- uint32_t coro_susp_point;
uint8_t v_flags;
uint32_t v_checksum_got;
uint32_t v_decoded_length_got;
uint32_t v_checksum_want;
uint64_t scratch;
- } c_decode_io_writer[1];
- } private_impl;
+ } s_decode_io_writer[1];
+ } private_data;
#else // WUFFS_IMPLEMENTATION
@@ -3145,18 +3620,24 @@
// Even when WUFFS_IMPLEMENTATION is not defined, the outermost struct still
// defines C++ convenience methods. These methods forward on "this", so that
// you can write "bar->baz(etc)" instead of "wuffs_foo__bar__baz(bar, etc)".
- struct {
+ private:
+ union {
+ uint32_t align_as_per_magic_field;
uint8_t placeholder[1073741824]; // 1 GiB.
- } private_impl;
+ } private_impl WUFFS_BASE__POTENTIALLY_UNUSED_FIELD;
+
+ public:
#endif // WUFFS_IMPLEMENTATION
#ifdef __cplusplus
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
- check_wuffs_version(size_t sizeof_star_self, uint64_t wuffs_version) {
- return wuffs_gzip__decoder__check_wuffs_version(this, sizeof_star_self,
- wuffs_version);
+ initialize(size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags) {
+ return wuffs_gzip__decoder__initialize(this, sizeof_star_self,
+ wuffs_version, initialize_flags);
}
inline wuffs_base__empty_struct //
@@ -3164,9 +3645,16 @@
return wuffs_gzip__decoder__set_ignore_checksum(this, a_ic);
}
+ inline wuffs_base__range_ii_u64 //
+ workbuf_len() const {
+ return wuffs_gzip__decoder__workbuf_len(this);
+ }
+
inline wuffs_base__status //
- decode_io_writer(wuffs_base__io_writer a_dst, wuffs_base__io_reader a_src) {
- return wuffs_gzip__decoder__decode_io_writer(this, a_dst, a_src);
+ decode_io_writer(wuffs_base__io_writer a_dst,
+ wuffs_base__io_reader a_src,
+ wuffs_base__slice_u8 a_workbuf) {
+ return wuffs_gzip__decoder__decode_io_writer(this, a_dst, a_src, a_workbuf);
}
#if (__cplusplus >= 201103L) && !defined(WUFFS_IMPLEMENTATION)
@@ -3199,21 +3687,29 @@
// ---------------- Public Consts
+#define WUFFS_ZLIB__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE 1
+
+static const uint64_t //
+ wuffs_zlib__decoder_workbuf_len_max_incl_worst_case //
+ WUFFS_BASE__POTENTIALLY_UNUSED = 1;
+
// ---------------- Struct Declarations
typedef struct wuffs_zlib__decoder__struct wuffs_zlib__decoder;
// ---------------- Public Initializer Prototypes
-// wuffs_zlib__decoder__check_wuffs_version is an initializer function.
-//
-// It should be called before any other wuffs_zlib__decoder__* function.
+// For any given "wuffs_foo__bar* self", "wuffs_foo__bar__initialize(self,
+// etc)" should be called before any other "wuffs_foo__bar__xxx(self, etc)".
//
// Pass sizeof(*self) and WUFFS_VERSION for sizeof_star_self and wuffs_version.
+// Pass 0 (or some combination of WUFFS_INITIALIZE__XXX) for initialize_flags.
+
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
-wuffs_zlib__decoder__check_wuffs_version(wuffs_zlib__decoder* self,
- size_t sizeof_star_self,
- uint64_t wuffs_version);
+wuffs_zlib__decoder__initialize(wuffs_zlib__decoder* self,
+ size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags);
size_t //
sizeof__wuffs_zlib__decoder();
@@ -3223,10 +3719,14 @@
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct //
wuffs_zlib__decoder__set_ignore_checksum(wuffs_zlib__decoder* self, bool a_ic);
+WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 //
+wuffs_zlib__decoder__workbuf_len(const wuffs_zlib__decoder* self);
+
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_zlib__decoder__decode_io_writer(wuffs_zlib__decoder* self,
wuffs_base__io_writer a_dst,
- wuffs_base__io_reader a_src);
+ wuffs_base__io_reader a_src,
+ wuffs_base__slice_u8 a_workbuf);
// ---------------- Struct Definitions
@@ -3240,25 +3740,31 @@
struct wuffs_zlib__decoder__struct {
#ifdef WUFFS_IMPLEMENTATION
- // 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
- // wuffs_foo__bar__baz functions.
+ // Do not access the private_impl's or private_data's fields directly. There
+ // is no API/ABI compatibility or safety guarantee if you do so. Instead, use
+ // the wuffs_foo__bar__baz functions.
//
- // It is a struct, not a struct*, so that the outermost wuffs_foo__bar
- // struct can be stack allocated when WUFFS_IMPLEMENTATION is defined.
+ // It is a struct, not a struct*, so that the outermost wuffs_foo__bar struct
+ // can be stack allocated when WUFFS_IMPLEMENTATION is defined.
+
struct {
uint32_t magic;
+ uint32_t active_coroutine;
- wuffs_deflate__decoder f_flate;
- wuffs_adler32__hasher f_checksum;
bool f_ignore_checksum;
+ uint32_t p_decode_io_writer[1];
+ } private_impl;
+
+ struct {
+ wuffs_adler32__hasher f_checksum;
+ wuffs_deflate__decoder f_flate;
+
struct {
- uint32_t coro_susp_point;
uint32_t v_checksum_got;
uint64_t scratch;
- } c_decode_io_writer[1];
- } private_impl;
+ } s_decode_io_writer[1];
+ } private_data;
#else // WUFFS_IMPLEMENTATION
@@ -3272,18 +3778,24 @@
// Even when WUFFS_IMPLEMENTATION is not defined, the outermost struct still
// defines C++ convenience methods. These methods forward on "this", so that
// you can write "bar->baz(etc)" instead of "wuffs_foo__bar__baz(bar, etc)".
- struct {
+ private:
+ union {
+ uint32_t align_as_per_magic_field;
uint8_t placeholder[1073741824]; // 1 GiB.
- } private_impl;
+ } private_impl WUFFS_BASE__POTENTIALLY_UNUSED_FIELD;
+
+ public:
#endif // WUFFS_IMPLEMENTATION
#ifdef __cplusplus
inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
- check_wuffs_version(size_t sizeof_star_self, uint64_t wuffs_version) {
- return wuffs_zlib__decoder__check_wuffs_version(this, sizeof_star_self,
- wuffs_version);
+ initialize(size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags) {
+ return wuffs_zlib__decoder__initialize(this, sizeof_star_self,
+ wuffs_version, initialize_flags);
}
inline wuffs_base__empty_struct //
@@ -3291,9 +3803,16 @@
return wuffs_zlib__decoder__set_ignore_checksum(this, a_ic);
}
+ inline wuffs_base__range_ii_u64 //
+ workbuf_len() const {
+ return wuffs_zlib__decoder__workbuf_len(this);
+ }
+
inline wuffs_base__status //
- decode_io_writer(wuffs_base__io_writer a_dst, wuffs_base__io_reader a_src) {
- return wuffs_zlib__decoder__decode_io_writer(this, a_dst, a_src);
+ decode_io_writer(wuffs_base__io_writer a_dst,
+ wuffs_base__io_reader a_src,
+ wuffs_base__slice_u8 a_workbuf) {
+ return wuffs_zlib__decoder__decode_io_writer(this, a_dst, a_src, a_workbuf);
}
#if (__cplusplus >= 201103L) && !defined(WUFFS_IMPLEMENTATION)
@@ -3316,14 +3835,20 @@
// WUFFS C HEADER ENDS HERE.
#ifdef WUFFS_IMPLEMENTATION
+// GCC does not warn for unused *static inline* functions, but clang does.
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunused-function"
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
-#define WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(x) (void)(x)
-
-static inline void wuffs_base__ignore_check_wuffs_version_status(
- wuffs_base__status z) {}
+static inline wuffs_base__empty_struct //
+wuffs_base__ignore_status(wuffs_base__status z) {
+ return wuffs_base__make_empty_struct();
+}
// 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,
@@ -3341,7 +3866,7 @@
// Denote intentional fallthroughs for -Wimplicit-fallthrough.
//
// The order matters here. Clang also defines "__GNUC__".
-#if defined(__clang__) && __cplusplus >= 201103L
+#if defined(__clang__) && defined(__cplusplus) && (__cplusplus >= 201103L)
#define WUFFS_BASE__FALLTHROUGH [[clang::fallthrough]]
#elif !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 7)
#define WUFFS_BASE__FALLTHROUGH __attribute__((fallthrough))
@@ -3389,11 +3914,6 @@
// inline attribute to guide optimizations such as inlining, to avoid the
// -Wunused-function warning, and we like to compile with -Wall -Werror.
-static inline wuffs_base__empty_struct //
-wuffs_base__return_empty_struct() {
- return ((wuffs_base__empty_struct){});
-}
-
// ---------------- Numeric Types
static inline uint8_t //
@@ -3403,12 +3923,12 @@
static inline uint16_t //
wuffs_base__load_u16be(uint8_t* p) {
- return ((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0);
+ return (uint16_t)(((uint16_t)(p[0]) << 8) | ((uint16_t)(p[1]) << 0));
}
static inline uint16_t //
wuffs_base__load_u16le(uint8_t* p) {
- return ((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8);
+ return (uint16_t)(((uint16_t)(p[0]) << 0) | ((uint16_t)(p[1]) << 8));
}
static inline uint32_t //
@@ -3504,128 +4024,128 @@
static inline void //
wuffs_base__store_u16be(uint8_t* p, uint16_t x) {
- p[0] = x >> 8;
- p[1] = x >> 0;
+ p[0] = (uint8_t)(x >> 8);
+ p[1] = (uint8_t)(x >> 0);
}
static inline void //
wuffs_base__store_u16le(uint8_t* p, uint16_t x) {
- p[0] = x >> 0;
- p[1] = x >> 8;
+ p[0] = (uint8_t)(x >> 0);
+ p[1] = (uint8_t)(x >> 8);
}
static inline void //
wuffs_base__store_u24be(uint8_t* p, uint32_t x) {
- p[0] = x >> 16;
- p[1] = x >> 8;
- p[2] = x >> 0;
+ p[0] = (uint8_t)(x >> 16);
+ p[1] = (uint8_t)(x >> 8);
+ p[2] = (uint8_t)(x >> 0);
}
static inline void //
wuffs_base__store_u24le(uint8_t* p, uint32_t x) {
- p[0] = x >> 0;
- p[1] = x >> 8;
- p[2] = x >> 16;
+ p[0] = (uint8_t)(x >> 0);
+ p[1] = (uint8_t)(x >> 8);
+ p[2] = (uint8_t)(x >> 16);
}
static inline void //
wuffs_base__store_u32be(uint8_t* p, uint32_t x) {
- p[0] = x >> 24;
- p[1] = x >> 16;
- p[2] = x >> 8;
- p[3] = x >> 0;
+ p[0] = (uint8_t)(x >> 24);
+ p[1] = (uint8_t)(x >> 16);
+ p[2] = (uint8_t)(x >> 8);
+ p[3] = (uint8_t)(x >> 0);
}
static inline void //
wuffs_base__store_u32le(uint8_t* p, uint32_t x) {
- p[0] = x >> 0;
- p[1] = x >> 8;
- p[2] = x >> 16;
- p[3] = x >> 24;
+ p[0] = (uint8_t)(x >> 0);
+ p[1] = (uint8_t)(x >> 8);
+ p[2] = (uint8_t)(x >> 16);
+ p[3] = (uint8_t)(x >> 24);
}
static inline void //
wuffs_base__store_u40be(uint8_t* p, uint64_t x) {
- p[0] = x >> 32;
- p[1] = x >> 24;
- p[2] = x >> 16;
- p[3] = x >> 8;
- p[4] = x >> 0;
+ p[0] = (uint8_t)(x >> 32);
+ p[1] = (uint8_t)(x >> 24);
+ p[2] = (uint8_t)(x >> 16);
+ p[3] = (uint8_t)(x >> 8);
+ p[4] = (uint8_t)(x >> 0);
}
static inline void //
wuffs_base__store_u40le(uint8_t* p, uint64_t x) {
- p[0] = x >> 0;
- p[1] = x >> 8;
- p[2] = x >> 16;
- p[3] = x >> 24;
- p[4] = x >> 32;
+ p[0] = (uint8_t)(x >> 0);
+ p[1] = (uint8_t)(x >> 8);
+ p[2] = (uint8_t)(x >> 16);
+ p[3] = (uint8_t)(x >> 24);
+ p[4] = (uint8_t)(x >> 32);
}
static inline void //
wuffs_base__store_u48be(uint8_t* p, uint64_t x) {
- p[0] = x >> 40;
- p[1] = x >> 32;
- p[2] = x >> 24;
- p[3] = x >> 16;
- p[4] = x >> 8;
- p[5] = x >> 0;
+ p[0] = (uint8_t)(x >> 40);
+ p[1] = (uint8_t)(x >> 32);
+ p[2] = (uint8_t)(x >> 24);
+ p[3] = (uint8_t)(x >> 16);
+ p[4] = (uint8_t)(x >> 8);
+ p[5] = (uint8_t)(x >> 0);
}
static inline void //
wuffs_base__store_u48le(uint8_t* p, uint64_t x) {
- p[0] = x >> 0;
- p[1] = x >> 8;
- p[2] = x >> 16;
- p[3] = x >> 24;
- p[4] = x >> 32;
- p[5] = x >> 40;
+ p[0] = (uint8_t)(x >> 0);
+ p[1] = (uint8_t)(x >> 8);
+ p[2] = (uint8_t)(x >> 16);
+ p[3] = (uint8_t)(x >> 24);
+ p[4] = (uint8_t)(x >> 32);
+ p[5] = (uint8_t)(x >> 40);
}
static inline void //
wuffs_base__store_u56be(uint8_t* p, uint64_t x) {
- p[0] = x >> 48;
- p[1] = x >> 40;
- p[2] = x >> 32;
- p[3] = x >> 24;
- p[4] = x >> 16;
- p[5] = x >> 8;
- p[6] = x >> 0;
+ p[0] = (uint8_t)(x >> 48);
+ p[1] = (uint8_t)(x >> 40);
+ p[2] = (uint8_t)(x >> 32);
+ p[3] = (uint8_t)(x >> 24);
+ p[4] = (uint8_t)(x >> 16);
+ p[5] = (uint8_t)(x >> 8);
+ p[6] = (uint8_t)(x >> 0);
}
static inline void //
wuffs_base__store_u56le(uint8_t* p, uint64_t x) {
- p[0] = x >> 0;
- p[1] = x >> 8;
- p[2] = x >> 16;
- p[3] = x >> 24;
- p[4] = x >> 32;
- p[5] = x >> 40;
- p[6] = x >> 48;
+ p[0] = (uint8_t)(x >> 0);
+ p[1] = (uint8_t)(x >> 8);
+ p[2] = (uint8_t)(x >> 16);
+ p[3] = (uint8_t)(x >> 24);
+ p[4] = (uint8_t)(x >> 32);
+ p[5] = (uint8_t)(x >> 40);
+ p[6] = (uint8_t)(x >> 48);
}
static inline void //
wuffs_base__store_u64be(uint8_t* p, uint64_t x) {
- p[0] = x >> 56;
- p[1] = x >> 48;
- p[2] = x >> 40;
- p[3] = x >> 32;
- p[4] = x >> 24;
- p[5] = x >> 16;
- p[6] = x >> 8;
- p[7] = x >> 0;
+ p[0] = (uint8_t)(x >> 56);
+ p[1] = (uint8_t)(x >> 48);
+ p[2] = (uint8_t)(x >> 40);
+ p[3] = (uint8_t)(x >> 32);
+ p[4] = (uint8_t)(x >> 24);
+ p[5] = (uint8_t)(x >> 16);
+ p[6] = (uint8_t)(x >> 8);
+ p[7] = (uint8_t)(x >> 0);
}
static inline void //
wuffs_base__store_u64le(uint8_t* p, uint64_t x) {
- p[0] = x >> 0;
- p[1] = x >> 8;
- p[2] = x >> 16;
- p[3] = x >> 24;
- p[4] = x >> 32;
- p[5] = x >> 40;
- p[6] = x >> 48;
- p[7] = x >> 56;
+ p[0] = (uint8_t)(x >> 0);
+ p[1] = (uint8_t)(x >> 8);
+ p[2] = (uint8_t)(x >> 16);
+ p[3] = (uint8_t)(x >> 24);
+ p[4] = (uint8_t)(x >> 32);
+ p[5] = (uint8_t)(x >> 40);
+ p[6] = (uint8_t)(x >> 48);
+ p[7] = (uint8_t)(x >> 56);
}
// --------
@@ -3723,14 +4243,15 @@
static inline wuffs_base__slice_u8 //
wuffs_base__table_u8__row(wuffs_base__table_u8 t, uint32_t y) {
if (y < t.height) {
- return ((wuffs_base__slice_u8){
- .ptr = t.ptr + (t.stride * y),
- .len = t.width,
- });
+ return wuffs_base__make_slice_u8(t.ptr + (t.stride * y), t.width);
}
- return ((wuffs_base__slice_u8){});
+ return wuffs_base__make_slice_u8(NULL, 0);
}
+ // ---------------- Slices and Tables (Utility)
+
+#define wuffs_base__utility__null_slice_u8 wuffs_base__null_slice_u8
+
// ---------------- Ranges and Rects
static inline uint32_t //
@@ -3773,75 +4294,14 @@
return r->max_excl;
}
-// ---------------- Ranges and Rects (Utility)
+ // ---------------- Ranges and Rects (Utility)
-static inline wuffs_base__range_ii_u32 //
-wuffs_base__utility__make_range_ii_u32(const wuffs_base__utility* ignored,
- uint32_t min_incl,
- uint32_t max_incl) {
- return ((wuffs_base__range_ii_u32){
- .min_incl = min_incl,
- .max_incl = max_incl,
- });
-}
-
-static inline wuffs_base__range_ie_u32 //
-wuffs_base__utility__make_range_ie_u32(const wuffs_base__utility* ignored,
- uint32_t min_incl,
- uint32_t max_excl) {
- return ((wuffs_base__range_ie_u32){
- .min_incl = min_incl,
- .max_excl = max_excl,
- });
-}
-
-static inline wuffs_base__range_ii_u64 //
-wuffs_base__utility__make_range_ii_u64(const wuffs_base__utility* ignored,
- uint64_t min_incl,
- uint64_t max_incl) {
- return ((wuffs_base__range_ii_u64){
- .min_incl = min_incl,
- .max_incl = max_incl,
- });
-}
-
-static inline wuffs_base__range_ie_u64 //
-wuffs_base__utility__make_range_ie_u64(const wuffs_base__utility* ignored,
- uint64_t min_incl,
- uint64_t max_excl) {
- return ((wuffs_base__range_ie_u64){
- .min_incl = min_incl,
- .max_excl = max_excl,
- });
-}
-
-static inline wuffs_base__rect_ii_u32 //
-wuffs_base__utility__make_rect_ii_u32(const wuffs_base__utility* ignored,
- uint32_t min_incl_x,
- uint32_t min_incl_y,
- uint32_t max_incl_x,
- uint32_t max_incl_y) {
- return ((wuffs_base__rect_ii_u32){
- .min_incl_x = min_incl_x,
- .min_incl_y = min_incl_y,
- .max_incl_x = max_incl_x,
- .max_incl_y = max_incl_y,
- });
-}
-
-static inline wuffs_base__rect_ie_u32 //
-wuffs_base__utility__make_rect_ie_u32(const wuffs_base__utility* ignored,
- uint32_t min_incl_x,
- uint32_t min_incl_y,
- uint32_t max_excl_x,
- uint32_t max_excl_y) {
- return ((wuffs_base__rect_ie_u32){
- .min_incl_x = min_incl_x,
- .min_incl_y = min_incl_y,
- .max_excl_x = max_excl_x,
- .max_excl_y = max_excl_y,
- });
-}
+#define wuffs_base__utility__make_range_ii_u32 wuffs_base__make_range_ii_u32
+#define wuffs_base__utility__make_range_ie_u32 wuffs_base__make_range_ie_u32
+#define wuffs_base__utility__make_range_ii_u64 wuffs_base__make_range_ii_u64
+#define wuffs_base__utility__make_range_ie_u64 wuffs_base__make_range_ie_u64
+#define wuffs_base__utility__make_rect_ii_u32 wuffs_base__make_rect_ii_u32
+#define wuffs_base__utility__make_rect_ie_u32 wuffs_base__make_rect_ie_u32
// ---------------- I/O
@@ -3903,11 +4363,11 @@
return 0;
}
uint8_t* q = p - distance;
- size_t n = io1_w - p;
+ size_t n = (size_t)(io1_w - p);
if ((size_t)(length) > n) {
- length = n;
+ length = (uint32_t)(n);
} else {
- n = length;
+ n = (size_t)(length);
}
// TODO: unrolling by 3 seems best for the std/deflate benchmarks, but that
// is mostly because 3 is the minimum length for the deflate format. This
@@ -3967,18 +4427,18 @@
uint8_t* iop_w = *ptr_iop_w;
size_t n = length;
if (n > ((size_t)(io1_w - iop_w))) {
- n = io1_w - iop_w;
+ n = (size_t)(io1_w - iop_w);
}
uint8_t* iop_r = *ptr_iop_r;
if (n > ((size_t)(io1_r - iop_r))) {
- n = io1_r - iop_r;
+ n = (size_t)(io1_r - iop_r);
}
if (n > 0) {
memmove(iop_w, iop_r, n);
*ptr_iop_w += n;
*ptr_iop_r += n;
}
- return n;
+ return (uint32_t)(n);
}
static inline uint64_t //
@@ -3988,13 +4448,13 @@
uint8_t* iop_w = *ptr_iop_w;
size_t n = src.len;
if (n > ((size_t)(io1_w - iop_w))) {
- n = io1_w - iop_w;
+ n = (size_t)(io1_w - iop_w);
}
if (n > 0) {
memmove(iop_w, src.ptr, n);
*ptr_iop_w += n;
}
- return n;
+ return (uint64_t)(n);
}
static inline uint32_t //
@@ -4008,13 +4468,13 @@
n = length;
}
if (n > ((size_t)(io1_w - iop_w))) {
- n = io1_w - iop_w;
+ n = (size_t)(io1_w - iop_w);
}
if (n > 0) {
memmove(iop_w, src.ptr, n);
*ptr_iop_w += n;
}
- return n;
+ return (uint32_t)(n);
}
static inline wuffs_base__empty_struct //
@@ -4034,7 +4494,10 @@
o->private_impl.limit = data.ptr + data.len;
*ptr_iop_r = data.ptr;
*ptr_io1_r = data.ptr + data.len;
- return ((wuffs_base__empty_struct){});
+
+ wuffs_base__empty_struct ret;
+ ret.private_impl = 0;
+ return ret;
}
static inline wuffs_base__empty_struct //
@@ -4044,13 +4507,19 @@
if (o && (((size_t)(o->private_impl.limit - iop_r)) > limit)) {
o->private_impl.limit = iop_r + limit;
}
- return ((wuffs_base__empty_struct){});
+
+ wuffs_base__empty_struct ret;
+ ret.private_impl = 0;
+ return ret;
}
static inline wuffs_base__empty_struct //
wuffs_base__io_reader__set_mark(wuffs_base__io_reader* o, uint8_t* mark) {
o->private_impl.mark = mark;
- return ((wuffs_base__empty_struct){});
+
+ wuffs_base__empty_struct ret;
+ ret.private_impl = 0;
+ return ret;
}
static inline wuffs_base__slice_u8 //
@@ -4058,12 +4527,9 @@
if (n <= ((size_t)(io1_r - *ptr_iop_r))) {
uint8_t* p = *ptr_iop_r;
*ptr_iop_r += n;
- return ((wuffs_base__slice_u8){
- .ptr = p,
- .len = n,
- });
+ return wuffs_base__make_slice_u8(p, n);
}
- return ((wuffs_base__slice_u8){});
+ return wuffs_base__make_slice_u8(NULL, 0);
}
static inline wuffs_base__empty_struct //
@@ -4083,26 +4549,25 @@
o->private_impl.limit = data.ptr + data.len;
*ptr_iop_w = data.ptr;
*ptr_io1_w = data.ptr + data.len;
- return ((wuffs_base__empty_struct){});
+
+ wuffs_base__empty_struct ret;
+ ret.private_impl = 0;
+ return ret;
}
static inline wuffs_base__empty_struct //
wuffs_base__io_writer__set_mark(wuffs_base__io_writer* o, uint8_t* mark) {
o->private_impl.mark = mark;
- return ((wuffs_base__empty_struct){});
+
+ wuffs_base__empty_struct ret;
+ ret.private_impl = 0;
+ return ret;
}
-// ---------------- I/O (Utility)
+ // ---------------- I/O (Utility)
-static inline wuffs_base__io_reader //
-wuffs_base__utility__null_io_reader(const wuffs_base__utility* ignored) {
- return ((wuffs_base__io_reader){});
-}
-
-static inline wuffs_base__io_writer //
-wuffs_base__utility__null_io_writer(const wuffs_base__utility* ignored) {
- return ((wuffs_base__io_writer){});
-}
+#define wuffs_base__utility__null_io_reader wuffs_base__null_io_reader
+#define wuffs_base__utility__null_io_writer wuffs_base__null_io_writer
// ---------------- Memory Allocation
@@ -4153,27 +4618,31 @@
0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF,
};
-const char* wuffs_base__warning__end_of_data = "~base: end of data";
+const char* wuffs_base__warning__end_of_data = "@base: end of data";
const char* wuffs_base__suspension__short_read = "$base: short read";
const char* wuffs_base__suspension__short_write = "$base: short write";
const char* wuffs_base__error__bad_argument_length_too_short =
- "?base: bad argument (length too short)";
-const char* wuffs_base__error__bad_argument = "?base: bad argument";
-const char* wuffs_base__error__bad_call_sequence = "?base: bad call sequence";
-const char* wuffs_base__error__bad_receiver = "?base: bad receiver";
-const char* wuffs_base__error__bad_restart = "?base: bad restart";
+ "#base: bad argument (length too short)";
+const char* wuffs_base__error__bad_argument = "#base: bad argument";
+const char* wuffs_base__error__bad_call_sequence = "#base: bad call sequence";
+const char* wuffs_base__error__bad_receiver = "#base: bad receiver";
+const char* wuffs_base__error__bad_restart = "#base: bad restart";
const char* wuffs_base__error__bad_sizeof_receiver =
- "?base: bad sizeof receiver";
-const char* wuffs_base__error__bad_workbuf_length = "?base: bad workbuf length";
-const char* wuffs_base__error__bad_wuffs_version = "?base: bad wuffs version";
+ "#base: bad sizeof receiver";
+const char* wuffs_base__error__bad_workbuf_length = "#base: bad workbuf length";
+const char* wuffs_base__error__bad_wuffs_version = "#base: bad wuffs version";
const char* wuffs_base__error__cannot_return_a_suspension =
- "?base: cannot return a suspension";
-const char* wuffs_base__error__check_wuffs_version_not_applicable =
- "?base: check_wuffs_version not applicable";
-const char* wuffs_base__error__check_wuffs_version_missing =
- "?base: check_wuffs_version missing";
+ "#base: cannot return a suspension";
const char* wuffs_base__error__disabled_by_previous_error =
- "?base: disabled by previous error";
+ "#base: disabled by previous error";
+const char* wuffs_base__error__initialize_falsely_claimed_already_zeroed =
+ "#base: initialize falsely claimed already zeroed";
+const char* wuffs_base__error__initialize_not_called =
+ "#base: initialize not called";
+const char* wuffs_base__error__interleaved_coroutine_calls =
+ "#base: interleaved coroutine calls";
+const char* wuffs_base__error__not_enough_data = "#base: not enough data";
+const char* wuffs_base__error__too_much_data = "#base: too much data";
// ---------------- Images
@@ -4220,7 +4689,7 @@
s += 1 * N;
d += 4 * N;
- n -= 1 * N;
+ n -= (size_t)(1 * N);
}
while (n >= 1) {
@@ -4230,7 +4699,7 @@
s += 1 * 1;
d += 4 * 1;
- n -= 1 * 1;
+ n -= (size_t)(1 * 1);
}
return len;
@@ -4260,11 +4729,11 @@
}
void //
-wuffs_base__pixel_swizzler__initialize(wuffs_base__pixel_swizzler* p,
- wuffs_base__pixel_format dst_format,
- wuffs_base__slice_u8 dst_palette,
- wuffs_base__pixel_format src_format,
- wuffs_base__slice_u8 src_palette) {
+wuffs_base__pixel_swizzler__prepare(wuffs_base__pixel_swizzler* p,
+ wuffs_base__pixel_format dst_format,
+ wuffs_base__slice_u8 dst_palette,
+ wuffs_base__pixel_format src_format,
+ wuffs_base__slice_u8 src_palette) {
if (!p) {
return;
}
@@ -4334,6 +4803,10 @@
} // extern "C"
#endif
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+
#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__ADLER32)
// ---------------- Status Codes Implementations
@@ -4347,9 +4820,10 @@
// ---------------- Initializer Implementations
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
-wuffs_adler32__hasher__check_wuffs_version(wuffs_adler32__hasher* self,
- size_t sizeof_star_self,
- uint64_t wuffs_version) {
+wuffs_adler32__hasher__initialize(wuffs_adler32__hasher* self,
+ size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags) {
if (!self) {
return wuffs_base__error__bad_receiver;
}
@@ -4360,16 +4834,39 @@
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
return wuffs_base__error__bad_wuffs_version;
}
- if (self->private_impl.magic != 0) {
- return wuffs_base__error__check_wuffs_version_not_applicable;
+
+ if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
+// The whole point of this if-check is to detect an uninitialized *self.
+// We disable the warning on GCC. Clang-5.0 does not have this warning.
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+#endif
+ if (self->private_impl.magic != 0) {
+ return wuffs_base__error__initialize_falsely_claimed_already_zeroed;
+ }
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
+ } else {
+ void* p = &(self->private_impl);
+ size_t n = sizeof(self->private_impl);
+ if ((initialize_flags &
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
+ p = self;
+ n = sizeof(*self);
+ initialize_flags |= WUFFS_INITIALIZE__ALREADY_ZEROED;
+ }
+ memset(p, 0, n);
}
+
self->private_impl.magic = WUFFS_BASE__MAGIC;
return NULL;
}
size_t //
sizeof__wuffs_adler32__hasher() {
- return sizeof((wuffs_adler32__hasher){});
+ return sizeof(wuffs_adler32__hasher);
}
// ---------------- Function Implementations
@@ -4388,8 +4885,8 @@
uint32_t v_s1 = 0;
uint32_t v_s2 = 0;
- wuffs_base__slice_u8 v_remaining = {};
- wuffs_base__slice_u8 v_p = {};
+ wuffs_base__slice_u8 v_remaining = {0};
+ wuffs_base__slice_u8 v_p = {0};
if (!self->private_impl.f_started) {
self->private_impl.f_started = true;
@@ -4459,727 +4956,873 @@
// ---------------- Private Consts
-static const uint32_t wuffs_crc32__ieee_table[16][256] = {
- {
- 0, 1996959894, 3993919788, 2567524794, 124634137, 1886057615,
- 3915621685, 2657392035, 249268274, 2044508324, 3772115230, 2547177864,
- 162941995, 2125561021, 3887607047, 2428444049, 498536548, 1789927666,
- 4089016648, 2227061214, 450548861, 1843258603, 4107580753, 2211677639,
- 325883990, 1684777152, 4251122042, 2321926636, 335633487, 1661365465,
- 4195302755, 2366115317, 997073096, 1281953886, 3579855332, 2724688242,
- 1006888145, 1258607687, 3524101629, 2768942443, 901097722, 1119000684,
- 3686517206, 2898065728, 853044451, 1172266101, 3705015759, 2882616665,
- 651767980, 1373503546, 3369554304, 3218104598, 565507253, 1454621731,
- 3485111705, 3099436303, 671266974, 1594198024, 3322730930, 2970347812,
- 795835527, 1483230225, 3244367275, 3060149565, 1994146192, 31158534,
- 2563907772, 4023717930, 1907459465, 112637215, 2680153253, 3904427059,
- 2013776290, 251722036, 2517215374, 3775830040, 2137656763, 141376813,
- 2439277719, 3865271297, 1802195444, 476864866, 2238001368, 4066508878,
- 1812370925, 453092731, 2181625025, 4111451223, 1706088902, 314042704,
- 2344532202, 4240017532, 1658658271, 366619977, 2362670323, 4224994405,
- 1303535960, 984961486, 2747007092, 3569037538, 1256170817, 1037604311,
- 2765210733, 3554079995, 1131014506, 879679996, 2909243462, 3663771856,
- 1141124467, 855842277, 2852801631, 3708648649, 1342533948, 654459306,
- 3188396048, 3373015174, 1466479909, 544179635, 3110523913, 3462522015,
- 1591671054, 702138776, 2966460450, 3352799412, 1504918807, 783551873,
- 3082640443, 3233442989, 3988292384, 2596254646, 62317068, 1957810842,
- 3939845945, 2647816111, 81470997, 1943803523, 3814918930, 2489596804,
- 225274430, 2053790376, 3826175755, 2466906013, 167816743, 2097651377,
- 4027552580, 2265490386, 503444072, 1762050814, 4150417245, 2154129355,
- 426522225, 1852507879, 4275313526, 2312317920, 282753626, 1742555852,
- 4189708143, 2394877945, 397917763, 1622183637, 3604390888, 2714866558,
- 953729732, 1340076626, 3518719985, 2797360999, 1068828381, 1219638859,
- 3624741850, 2936675148, 906185462, 1090812512, 3747672003, 2825379669,
- 829329135, 1181335161, 3412177804, 3160834842, 628085408, 1382605366,
- 3423369109, 3138078467, 570562233, 1426400815, 3317316542, 2998733608,
- 733239954, 1555261956, 3268935591, 3050360625, 752459403, 1541320221,
- 2607071920, 3965973030, 1969922972, 40735498, 2617837225, 3943577151,
- 1913087877, 83908371, 2512341634, 3803740692, 2075208622, 213261112,
- 2463272603, 3855990285, 2094854071, 198958881, 2262029012, 4057260610,
- 1759359992, 534414190, 2176718541, 4139329115, 1873836001, 414664567,
- 2282248934, 4279200368, 1711684554, 285281116, 2405801727, 4167216745,
- 1634467795, 376229701, 2685067896, 3608007406, 1308918612, 956543938,
- 2808555105, 3495958263, 1231636301, 1047427035, 2932959818, 3654703836,
- 1088359270, 936918000, 2847714899, 3736837829, 1202900863, 817233897,
- 3183342108, 3401237130, 1404277552, 615818150, 3134207493, 3453421203,
- 1423857449, 601450431, 3009837614, 3294710456, 1567103746, 711928724,
- 3020668471, 3272380065, 1510334235, 755167117,
- },
- {
- 0, 421212481, 842424962, 724390851, 1684849924, 2105013317,
- 1448781702, 1329698503, 3369699848, 3519200073, 4210026634, 3824474571,
- 2897563404, 3048111693, 2659397006, 2274893007, 1254232657, 1406739216,
- 2029285587, 1643069842, 783210325, 934667796, 479770071, 92505238,
- 2182846553, 2600511768, 2955803355, 2838940570, 3866582365, 4285295644,
- 3561045983, 3445231262, 2508465314, 2359236067, 2813478432, 3198777185,
- 4058571174, 3908292839, 3286139684, 3670389349, 1566420650, 1145479147,
- 1869335592, 1987116393, 959540142, 539646703, 185010476, 303839341,
- 3745920755, 3327985586, 3983561841, 4100678960, 3140154359, 2721170102,
- 2300350837, 2416418868, 396344571, 243568058, 631889529, 1018359608,
- 1945336319, 1793607870, 1103436669, 1490954812, 4034481925, 3915546180,
- 3259968903, 3679722694, 2484439553, 2366552896, 2787371139, 3208174018,
- 950060301, 565965900, 177645455, 328046286, 1556873225, 1171730760,
- 1861902987, 2011255754, 3132841300, 2745199637, 2290958294, 2442530455,
- 3738671184, 3352078609, 3974232786, 4126854035, 1919080284, 1803150877,
- 1079293406, 1498383519, 370020952, 253043481, 607678682, 1025720731,
- 1711106983, 2095471334, 1472923941, 1322268772, 26324643, 411738082,
- 866634785, 717028704, 2904875439, 3024081134, 2668790573, 2248782444,
- 3376948395, 3495106026, 4219356713, 3798300520, 792689142, 908347575,
- 487136116, 68299317, 1263779058, 1380486579, 2036719216, 1618931505,
- 3890672638, 4278043327, 3587215740, 3435896893, 2206873338, 2593195963,
- 2981909624, 2829542713, 998479947, 580430090, 162921161, 279890824,
- 1609522511, 1190423566, 1842954189, 1958874764, 4082766403, 3930137346,
- 3245109441, 3631694208, 2536953671, 2385372678, 2768287173, 3155920004,
- 1900120602, 1750776667, 1131931800, 1517083097, 355290910, 204897887,
- 656092572, 1040194781, 3113746450, 2692952403, 2343461520, 2461357009,
- 3723805974, 3304059991, 4022511508, 4141455061, 2919742697, 3072101800,
- 2620513899, 2234183466, 3396041197, 3547351212, 4166851439, 3779471918,
- 1725839073, 2143618976, 1424512099, 1307796770, 45282277, 464110244,
- 813994343, 698327078, 3838160568, 4259225593, 3606301754, 3488152955,
- 2158586812, 2578602749, 2996767038, 2877569151, 740041904, 889656817,
- 506086962, 120682355, 1215357364, 1366020341, 2051441462, 1667084919,
- 3422213966, 3538019855, 4190942668, 3772220557, 2945847882, 3062702859,
- 2644537544, 2226864521, 52649286, 439905287, 823476164, 672009861,
- 1733269570, 2119477507, 1434057408, 1281543041, 2167981343, 2552493150,
- 3004082077, 2853541596, 3847487515, 4233048410, 3613549209, 3464057816,
- 1239502615, 1358593622, 2077699477, 1657543892, 764250643, 882293586,
- 532408465, 111204816, 1585378284, 1197851309, 1816695150, 1968414767,
- 974272232, 587794345, 136598634, 289367339, 2527558116, 2411481253,
- 2760973158, 3179948583, 4073438432, 3956313505, 3237863010, 3655790371,
- 347922877, 229101820, 646611775, 1066513022, 1892689081, 1774917112,
- 1122387515, 1543337850, 3697634229, 3313392372, 3998419255, 4148705398,
- 3087642289, 2702352368, 2319436851, 2468674930,
- },
- {
- 0, 29518391, 59036782, 38190681, 118073564, 114017003,
- 76381362, 89069189, 236147128, 265370511, 228034006, 206958561,
- 152762724, 148411219, 178138378, 190596925, 472294256, 501532999,
- 530741022, 509615401, 456068012, 451764635, 413917122, 426358261,
- 305525448, 334993663, 296822438, 275991697, 356276756, 352202787,
- 381193850, 393929805, 944588512, 965684439, 1003065998, 973863097,
- 1061482044, 1049003019, 1019230802, 1023561829, 912136024, 933002607,
- 903529270, 874031361, 827834244, 815125939, 852716522, 856752605,
- 611050896, 631869351, 669987326, 640506825, 593644876, 580921211,
- 551983394, 556069653, 712553512, 733666847, 704405574, 675154545,
- 762387700, 749958851, 787859610, 792175277, 1889177024, 1901651959,
- 1931368878, 1927033753, 2006131996, 1985040171, 1947726194, 1976933189,
- 2122964088, 2135668303, 2098006038, 2093965857, 2038461604, 2017599123,
- 2047123658, 2076625661, 1824272048, 1836991623, 1866005214, 1861914857,
- 1807058540, 1786244187, 1748062722, 1777547317, 1655668488, 1668093247,
- 1630251878, 1625932113, 1705433044, 1684323811, 1713505210, 1742760333,
- 1222101792, 1226154263, 1263738702, 1251046777, 1339974652, 1310460363,
- 1281013650, 1301863845, 1187289752, 1191637167, 1161842422, 1149379777,
- 1103966788, 1074747507, 1112139306, 1133218845, 1425107024, 1429406311,
- 1467333694, 1454888457, 1408811148, 1379576507, 1350309090, 1371438805,
- 1524775400, 1528845279, 1499917702, 1487177649, 1575719220, 1546255107,
- 1584350554, 1605185389, 3778354048, 3774312887, 3803303918, 3816007129,
- 3862737756, 3892238699, 3854067506, 3833203973, 4012263992, 4007927823,
- 3970080342, 3982554209, 3895452388, 3924658387, 3953866378, 3932773565,
- 4245928176, 4241609415, 4271336606, 4283762345, 4196012076, 4225268251,
- 4187931714, 4166823541, 4076923208, 4072833919, 4035198246, 4047918865,
- 4094247316, 4123732899, 4153251322, 4132437965, 3648544096, 3636082519,
- 3673983246, 3678331705, 3732010428, 3753090955, 3723829714, 3694611429,
- 3614117080, 3601426159, 3572488374, 3576541825, 3496125444, 3516976691,
- 3555094634, 3525581405, 3311336976, 3298595879, 3336186494, 3340255305,
- 3260503756, 3281337595, 3251864226, 3222399125, 3410866088, 3398419871,
- 3368647622, 3372945905, 3427010420, 3448139075, 3485520666, 3456284973,
- 2444203584, 2423127159, 2452308526, 2481530905, 2527477404, 2539934891,
- 2502093554, 2497740997, 2679949304, 2659102159, 2620920726, 2650438049,
- 2562027300, 2574714131, 2603727690, 2599670141, 2374579504, 2353749767,
- 2383274334, 2412743529, 2323684844, 2336421851, 2298759554, 2294686645,
- 2207933576, 2186809023, 2149495014, 2178734801, 2224278612, 2236720739,
- 2266437690, 2262135309, 2850214048, 2820717207, 2858812622, 2879680249,
- 2934667388, 2938704459, 2909776914, 2897069605, 2817622296, 2788420399,
- 2759153014, 2780249921, 2700618180, 2704950259, 2742877610, 2730399645,
- 3049550800, 3020298727, 3057690558, 3078802825, 2999835404, 3004150075,
- 2974355298, 2961925461, 3151438440, 3121956959, 3092510214, 3113327665,
- 3168701108, 3172786307, 3210370778, 3197646061,
- },
- {
- 0, 3099354981, 2852767883, 313896942, 2405603159, 937357362,
- 627793884, 2648127673, 3316918511, 2097696650, 1874714724, 3607201537,
- 1255587768, 4067088605, 3772741427, 1482887254, 1343838111, 3903140090,
- 4195393300, 1118632049, 3749429448, 1741137837, 1970407491, 3452858150,
- 2511175536, 756094997, 1067759611, 2266550430, 449832999, 2725482306,
- 2965774508, 142231497, 2687676222, 412010587, 171665333, 2995192016,
- 793786473, 2548850444, 2237264098, 1038456711, 1703315409, 3711623348,
- 3482275674, 1999841343, 3940814982, 1381529571, 1089329165, 4166106984,
- 4029413537, 1217896388, 1512189994, 3802027855, 2135519222, 3354724499,
- 3577784189, 1845280792, 899665998, 2367928107, 2677414085, 657096608,
- 3137160985, 37822588, 284462994, 2823350519, 2601801789, 598228824,
- 824021174, 2309093331, 343330666, 2898962447, 3195996129, 113467524,
- 1587572946, 3860600759, 4104763481, 1276501820, 3519211397, 1769898208,
- 2076913422, 3279374443, 3406630818, 1941006535, 1627703081, 3652755532,
- 1148164341, 4241751952, 3999682686, 1457141531, 247015245, 3053797416,
- 2763059142, 470583459, 2178658330, 963106687, 735213713, 2473467892,
- 992409347, 2207944806, 2435792776, 697522413, 3024379988, 217581361,
- 508405983, 2800865210, 4271038444, 1177467017, 1419450215, 3962007554,
- 1911572667, 3377213406, 3690561584, 1665525589, 1799331996, 3548628985,
- 3241568279, 2039091058, 3831314379, 1558270126, 1314193216, 4142438437,
- 2928380019, 372764438, 75645176, 3158189981, 568925988, 2572515393,
- 2346768303, 861712586, 3982079547, 1441124702, 1196457648, 4293663189,
- 1648042348, 3666298377, 3358779879, 1888390786, 686661332, 2421291441,
- 2196002399, 978858298, 2811169155, 523464422, 226935048, 3040519789,
- 3175145892, 100435649, 390670639, 2952089162, 841119475, 2325614998,
- 2553003640, 546822429, 2029308235, 3225988654, 3539796416, 1782671013,
- 4153826844, 1328167289, 1570739863, 3844338162, 1298864389, 4124540512,
- 3882013070, 1608431339, 3255406162, 2058742071, 1744848601, 3501990332,
- 2296328682, 811816591, 584513889, 2590678532, 129869501, 3204563416,
- 2914283062, 352848211, 494030490, 2781751807, 3078325777, 264757620,
- 2450577869, 715964072, 941166918, 2158327331, 3636881013, 1618608400,
- 1926213374, 3396585883, 1470427426, 4011365959, 4255988137, 1158766284,
- 1984818694, 3471935843, 3695453837, 1693991400, 4180638033, 1100160564,
- 1395044826, 3952793279, 3019491049, 189112716, 435162722, 2706139399,
- 1016811966, 2217162459, 2526189877, 774831696, 643086745, 2666061564,
- 2354934034, 887166583, 2838900430, 294275499, 54519365, 3145957664,
- 3823145334, 1532818963, 1240029693, 4048895640, 1820460577, 3560857924,
- 3331051178, 2117577167, 3598663992, 1858283101, 2088143283, 3301633750,
- 1495127663, 3785470218, 4078182116, 1269332353, 332098007, 2876706482,
- 3116540252, 25085497, 2628386432, 605395429, 916469259, 2384220526,
- 2254837415, 1054503362, 745528876, 2496903497, 151290352, 2981684885,
- 2735556987, 464596510, 1137851976, 4218313005, 3923506883, 1365741990,
- 3434129695, 1946996346, 1723425172, 3724871409,
- },
- {
- 0, 1029712304, 2059424608, 1201699536, 4118849216, 3370159984,
- 2403399072, 2988497936, 812665793, 219177585, 1253054625, 2010132753,
- 3320900865, 4170237105, 3207642721, 2186319825, 1625331586, 1568718386,
- 438355170, 658566482, 2506109250, 2818578674, 4020265506, 3535817618,
- 1351670851, 1844508147, 709922595, 389064339, 2769320579, 2557498163,
- 3754961379, 3803185235, 3250663172, 4238411444, 3137436772, 2254525908,
- 876710340, 153198708, 1317132964, 1944187668, 4054934725, 3436268917,
- 2339452837, 3054575125, 70369797, 961670069, 2129760613, 1133623509,
- 2703341702, 2621542710, 3689016294, 3867263574, 1419845190, 1774270454,
- 778128678, 318858390, 2438067015, 2888948471, 3952189479, 3606153623,
- 1691440519, 1504803895, 504432359, 594620247, 1492342857, 1704161785,
- 573770537, 525542041, 2910060169, 2417219385, 3618876905, 3939730521,
- 1753420680, 1440954936, 306397416, 790849880, 2634265928, 2690882808,
- 3888375336, 3668168600, 940822475, 91481723, 1121164459, 2142483739,
- 3448989963, 4042473659, 3075684971, 2318603227, 140739594, 889433530,
- 1923340138, 1338244826, 4259521226, 3229813626, 2267247018, 3124975642,
- 2570221389, 2756861693, 3824297005, 3734113693, 1823658381, 1372780605,
- 376603373, 722643805, 2839690380, 2485261628, 3548540908, 4007806556,
- 1556257356, 1638052860, 637716780, 459464860, 4191346895, 3300051327,
- 2199040943, 3195181599, 206718479, 825388991, 1989285231, 1274166495,
- 3382881038, 4106388158, 3009607790, 2382549470, 1008864718, 21111934,
- 1189240494, 2072147742, 2984685714, 2357631266, 3408323570, 4131834434,
- 1147541074, 2030452706, 1051084082, 63335554, 2174155603, 3170292451,
- 4216760371, 3325460867, 1947622803, 1232499747, 248909555, 867575619,
- 3506841360, 3966111392, 2881909872, 2527485376, 612794832, 434546784,
- 1581699760, 1663499008, 3782634705, 3692447073, 2612412337, 2799048193,
- 351717905, 697754529, 1849071985, 1398190273, 1881644950, 1296545318,
- 182963446, 931652934, 2242328918, 3100053734, 4284967478, 3255255942,
- 1079497815, 2100821479, 983009079, 133672583, 3050795671, 2293717799,
- 3474399735, 4067887175, 281479188, 765927844, 1778867060, 1466397380,
- 3846680276, 3626469220, 2676489652, 2733102084, 548881365, 500656741,
- 1517752501, 1729575173, 3577210133, 3898068133, 2952246901, 2459410373,
- 3910527195, 3564487019, 2480257979, 2931134987, 479546907, 569730987,
- 1716854139, 1530213579, 3647316762, 3825568426, 2745561210, 2663766474,
- 753206746, 293940330, 1445287610, 1799716618, 2314567513, 3029685993,
- 4080348217, 3461678473, 2088098201, 1091956777, 112560889, 1003856713,
- 3112514712, 2229607720, 3276105720, 4263857736, 1275433560, 1902492648,
- 918929720, 195422344, 685033439, 364179055, 1377080511, 1869921551,
- 3713294623, 3761522863, 2811507327, 2599689167, 413436958, 633644462,
- 1650777982, 1594160846, 3978570462, 3494118254, 2548332990, 2860797966,
- 1211387997, 1968470509, 854852413, 261368461, 3182753437, 2161434413,
- 3346310653, 4195650637, 2017729436, 1160000044, 42223868, 1071931724,
- 2378480988, 2963576044, 4144295484, 3395602316,
- },
- {
- 0, 3411858341, 1304994059, 2257875630, 2609988118, 1355649459,
- 3596215069, 486879416, 3964895853, 655315400, 2711298918, 1791488195,
- 2009251963, 3164476382, 973758832, 4048990933, 64357019, 3364540734,
- 1310630800, 2235723829, 2554806413, 1394316072, 3582976390, 517157411,
- 4018503926, 618222419, 2722963965, 1762783832, 1947517664, 3209171269,
- 970744811, 4068520014, 128714038, 3438335635, 1248109629, 2167961496,
- 2621261600, 1466012805, 3522553387, 447296910, 3959392091, 547575038,
- 2788632144, 1835791861, 1886307661, 3140622056, 1034314822, 4143626211,
- 75106221, 3475428360, 1236444838, 2196665603, 2682996155, 1421317662,
- 3525567664, 427767573, 3895035328, 594892389, 2782995659, 1857943406,
- 1941489622, 3101955187, 1047553757, 4113347960, 257428076, 3288652233,
- 1116777319, 2311878850, 2496219258, 1603640287, 3640781169, 308099796,
- 3809183745, 676813732, 2932025610, 1704983215, 2023410199, 3016104370,
- 894593820, 4262377657, 210634999, 3352484690, 1095150076, 2316991065,
- 2535410401, 1547934020, 3671583722, 294336591, 3772615322, 729897279,
- 2903845777, 1716123700, 2068629644, 2953845545, 914647431, 4258839074,
- 150212442, 3282623743, 1161604689, 2388688372, 2472889676, 1480171241,
- 3735940167, 368132066, 3836185911, 805002898, 2842635324, 1647574937,
- 2134298401, 3026852996, 855535146, 4188192143, 186781121, 3229539940,
- 1189784778, 2377547631, 2427670487, 1542429810, 3715886812, 371670393,
- 3882979244, 741170185, 2864262823, 1642462466, 2095107514, 3082559007,
- 824732849, 4201955092, 514856152, 3589064573, 1400419795, 2552522358,
- 2233554638, 1316849003, 3370776517, 62202976, 4075001525, 968836368,
- 3207280574, 1954014235, 1769133219, 2720925446, 616199592, 4024870413,
- 493229635, 3594175974, 1353627464, 2616354029, 2264355925, 1303087088,
- 3409966430, 6498043, 4046820398, 979978123, 3170710821, 2007099008,
- 1789187640, 2717386141, 661419827, 3962610838, 421269998, 3527459403,
- 1423225061, 2676515648, 2190300152, 1238466653, 3477467891, 68755798,
- 4115633027, 1041448998, 3095868040, 1943789869, 1860096405, 2776760880,
- 588673182, 3897205563, 449450869, 3516317904, 1459794558, 2623431131,
- 2170245475, 1242006214, 3432247400, 131015629, 4137259288, 1036337853,
- 3142660115, 1879958454, 1829294862, 2790523051, 549483013, 3952910752,
- 300424884, 3669282065, 1545650111, 2541513754, 2323209378, 1092980487,
- 3350330793, 216870412, 4256931033, 921128828, 2960342482, 2066738807,
- 1714085583, 2910195050, 736264132, 3770592353, 306060335, 3647131530,
- 1610005796, 2494197377, 2309971513, 1123257756, 3295149874, 255536279,
- 4268596802, 892423655, 3013951305, 2029645036, 1711070292, 2929725425,
- 674528607, 3815288570, 373562242, 3709388839, 1535949449, 2429577516,
- 2379569556, 1183418929, 3223189663, 188820282, 4195850735, 827017802,
- 3084859620, 2089020225, 1636228089, 2866415708, 743340786, 3876759895,
- 361896217, 3738094268, 1482340370, 2466671543, 2382584591, 1163888810,
- 3284924932, 144124321, 4190215028, 849168593, 3020503679, 2136336858,
- 1649465698, 2836138695, 798521449, 3838094284,
- },
- {
- 0, 2792819636, 2543784233, 837294749, 4098827283, 1379413927,
- 1674589498, 3316072078, 871321191, 2509784531, 2758827854, 34034938,
- 3349178996, 1641505216, 1346337629, 4131942633, 1742642382, 3249117050,
- 4030828007, 1446413907, 2475800797, 904311657, 68069876, 2725880384,
- 1412551337, 4064729373, 3283010432, 1708771380, 2692675258, 101317902,
- 937551763, 2442587175, 3485284764, 1774858792, 1478633653, 4266992385,
- 1005723023, 2642744891, 2892827814, 169477906, 4233263099, 1512406095,
- 1808623314, 3451546982, 136139752, 2926205020, 2676114113, 972376437,
- 2825102674, 236236518, 1073525883, 2576072655, 1546420545, 4200303349,
- 3417542760, 1841601500, 2609703733, 1039917185, 202635804, 2858742184,
- 1875103526, 3384067218, 4166835727, 1579931067, 1141601657, 3799809741,
- 3549717584, 1977839588, 2957267306, 372464350, 668680259, 2175552503,
- 2011446046, 3516084394, 3766168119, 1175200131, 2209029901, 635180217,
- 338955812, 2990736784, 601221559, 2242044419, 3024812190, 306049834,
- 3617246628, 1911408144, 1074125965, 3866285881, 272279504, 3058543716,
- 2275784441, 567459149, 3832906691, 1107462263, 1944752874, 3583875422,
- 2343980261, 767641425, 472473036, 3126744696, 2147051766, 3649987394,
- 3899029983, 1309766251, 3092841090, 506333494, 801510315, 2310084639,
- 1276520081, 3932237093, 3683203000, 2113813516, 3966292011, 1243601823,
- 2079834370, 3716205238, 405271608, 3192979340, 2411259153, 701492901,
- 3750207052, 2045810168, 1209569125, 4000285905, 734575199, 2378150379,
- 3159862134, 438345922, 2283203314, 778166598, 529136603, 3120492655,
- 2086260449, 3660498261, 3955679176, 1303499900, 3153699989, 495890209,
- 744928700, 2316418568, 1337360518, 3921775410, 3626602927, 2120129051,
- 4022892092, 1237286280, 2018993941, 3726666913, 461853231, 3186645403,
- 2350400262, 711936178, 3693557851, 2052076527, 1270360434, 3989775046,
- 677911624, 2384402428, 3220639073, 427820757, 1202443118, 3789347034,
- 3493118535, 1984154099, 3018127229, 362020041, 612099668, 2181885408,
- 1950653705, 3526596285, 3822816288, 1168934804, 2148251930, 645706414,
- 395618355, 2984485767, 544559008, 2248295444, 3085590153, 295523645,
- 3560598451, 1917673479, 1134918298, 3855773998, 328860103, 3052210803,
- 2214924526, 577903450, 3889505748, 1101147744, 1883911421, 3594338121,
- 3424493451, 1785369663, 1535282850, 4260726038, 944946072, 2653270060,
- 2949491377, 163225861, 4294103532, 1501944408, 1752023237, 3457862513,
- 196998655, 2915761739, 2619532502, 978710370, 2881684293, 229902577,
- 1012666988, 2586515928, 1603020630, 4193987810, 3356702335, 1852063179,
- 2553040162, 1046169238, 263412747, 2848217023, 1818454321, 3390333573,
- 4227627032, 1569420204, 60859927, 2782375331, 2487203646, 843627658,
- 4159668740, 1368951216, 1617990445, 3322386585, 810543216, 2520310724,
- 2815490393, 27783917, 3288386659, 1652017111, 1402985802, 4125677310,
- 1685994201, 3255382381, 4091620336, 1435902020, 2419138250, 910562686,
- 128847843, 2715354199, 1469150398, 4058414858, 3222168983, 1719234083,
- 2749255853, 94984985, 876691844, 2453031472,
- },
- {
- 0, 3433693342, 1109723005, 2391738339, 2219446010, 1222643300,
- 3329165703, 180685081, 3555007413, 525277995, 2445286600, 1567235158,
- 1471092047, 2600801745, 361370162, 3642757804, 2092642603, 2953916853,
- 1050555990, 4063508168, 4176560081, 878395215, 3134470316, 1987983410,
- 2942184094, 1676945920, 3984272867, 567356797, 722740324, 3887998202,
- 1764827929, 2778407815, 4185285206, 903635656, 3142804779, 2012833205,
- 2101111980, 2979425330, 1058630609, 4088621903, 714308067, 3862526333,
- 1756790430, 2753330688, 2933487385, 1651734407, 3975966820, 542535930,
- 2244825981, 1231508451, 3353891840, 188896414, 25648519, 3442302233,
- 1134713594, 2399689316, 1445480648, 2592229462, 336416693, 3634843435,
- 3529655858, 516441772, 2420588879, 1559052753, 698204909, 3845636723,
- 1807271312, 2803025166, 2916600855, 1635634313, 4025666410, 593021940,
- 4202223960, 919787974, 3093159461, 1962401467, 2117261218, 2996361020,
- 1008193759, 4038971457, 1428616134, 2576151384, 386135227, 3685348389,
- 3513580860, 499580322, 2471098945, 1608776415, 2260985971, 1248454893,
- 3303468814, 139259792, 42591881, 3458459159, 1085071860, 2349261162,
- 3505103035, 474062885, 2463016902, 1583654744, 1419882049, 2550902495,
- 377792828, 3660491170, 51297038, 3483679632, 1093385331, 2374089965,
- 2269427188, 1273935210, 3311514249, 164344343, 2890961296, 1627033870,
- 4000683757, 585078387, 672833386, 3836780532, 1782552599, 2794821769,
- 2142603813, 3005188795, 1032883544, 4047146438, 4227826911, 928351297,
- 3118105506, 1970307900, 1396409818, 2677114180, 287212199, 3719594553,
- 3614542624, 467372990, 2505346141, 1509854403, 2162073199, 1282711281,
- 3271268626, 240228748, 76845205, 3359543307, 1186043880, 2317064054,
- 796964081, 3811226735, 1839575948, 2702160658, 2882189835, 1734392469,
- 3924802934, 625327592, 4234522436, 818917338, 3191908409, 1927981223,
- 2016387518, 3028656416, 973776579, 4137723485, 2857232268, 1726474002,
- 3899187441, 616751215, 772270454, 3803048424, 1814228491, 2693328533,
- 2041117753, 3036871847, 999160644, 4146592730, 4259508931, 826864221,
- 3217552830, 1936586016, 3606501031, 442291769, 2496909786, 1484378436,
- 1388107869, 2652297411, 278519584, 3694387134, 85183762, 3384397196,
- 1194773103, 2342308593, 2170143720, 1307820918, 3279733909, 265733131,
- 2057717559, 3054258089, 948125770, 4096344276, 4276898253, 843467091,
- 3167309488, 1885556270, 2839764098, 1709792284, 3949353983, 667704161,
- 755585656, 3785577190, 1865176325, 2743489947, 102594076, 3401021058,
- 1144549729, 2291298815, 2186770662, 1325234296, 3228729243, 215514885,
- 3589828009, 424832311, 2547870420, 1534552650, 1370645331, 2635621325,
- 328688686, 3745342640, 2211456353, 1333405183, 3254067740, 224338562,
- 127544219, 3408931589, 1170156774, 2299866232, 1345666772, 2627681866,
- 303053225, 3736746295, 3565105198, 416624816, 2522494803, 1525692365,
- 4285207626, 868291796, 3176010551, 1910772649, 2065767088, 3079346734,
- 956571085, 4121828691, 747507711, 3760459617, 1856702594, 2717976604,
- 2831417605, 1684930971, 3940615800, 642451174,
- },
- {
- 0, 393942083, 787884166, 965557445, 1575768332, 1251427663,
- 1931114890, 1684106697, 3151536664, 2896410203, 2502855326, 2186649309,
- 3862229780, 4048545623, 3368213394, 3753496529, 2898281073, 3149616690,
- 2184604407, 2504883892, 4046197629, 3864463166, 3755621371, 3366006712,
- 387506281, 6550570, 971950319, 781573292, 1257550181, 1569695014,
- 1677892067, 1937345952, 2196865699, 2508887776, 2886183461, 3145514598,
- 3743273903, 3362179052, 4058774313, 3868258154, 958996667, 777139448,
- 400492605, 10755198, 1690661303, 1941857780, 1244879153, 1565019506,
- 775012562, 961205393, 13101140, 398261271, 1943900638, 1688634781,
- 1563146584, 1246801179, 2515100362, 2190636681, 3139390028, 2892258831,
- 3355784134, 3749586821, 3874691904, 4052225795, 3734110983, 3387496260,
- 4033096577, 3877584834, 2206093835, 2483373640, 2911402637, 3136515790,
- 1699389727, 1915860316, 1270647193, 1556585946, 950464531, 803071056,
- 374397077, 19647702, 1917993334, 1697207605, 1554278896, 1272937907,
- 800985210, 952435769, 21510396, 372452543, 3381322606, 3740399405,
- 3883715560, 4027047851, 2489758306, 2199758369, 3130039012, 2917895847,
- 1550025124, 1259902439, 1922410786, 1710144865, 26202280, 385139947,
- 796522542, 939715693, 3887801276, 4039129087, 3377269562, 3728088953,
- 3126293168, 2905368307, 2493602358, 2212122229, 4037264341, 3889747862,
- 3730172755, 3375300368, 2907673305, 3124004506, 2209987167, 2495786524,
- 1266377165, 1543533966, 1703758155, 1928748296, 379007169, 32253058,
- 945887303, 790236164, 1716846671, 1898845196, 1218652361, 1608006794,
- 1002000707, 750929152, 357530053, 36990342, 3717046871, 3405166100,
- 4084959953, 3825245842, 2153902939, 2535122712, 2929187805, 3119304606,
- 3398779454, 3723384445, 3831720632, 4078468859, 2541294386, 2147616625,
- 3113171892, 2935238647, 1900929062, 1714877541, 1606142112, 1220599011,
- 748794154, 1004184937, 39295404, 355241455, 3835986668, 4091516591,
- 3394415210, 3710500393, 3108557792, 2922629027, 2545875814, 2160455461,
- 1601970420, 1208431799, 1904871538, 1727077425, 43020792, 367748539,
- 744905086, 991776061, 1214562461, 1595921630, 1720903707, 1911159896,
- 361271697, 49513938, 998160663, 738569556, 4089209477, 3838277318,
- 3712633347, 3392233024, 2924491657, 3106613194, 2158369551, 2547846988,
- 3100050248, 2948339467, 2519804878, 2169126797, 3844821572, 4065347079,
- 3420289730, 3701894785, 52404560, 342144275, 770279894, 982687125,
- 1593045084, 1233708063, 1879431386, 1736363161, 336019769, 58479994,
- 988899775, 764050940, 1240141877, 1586496630, 1729968307, 1885744368,
- 2950685473, 3097818978, 2166999975, 2522013668, 4063474221, 3846743662,
- 3703937707, 3418263272, 976650731, 760059304, 348170605, 62635310,
- 1742393575, 1889649828, 1227683937, 1582820386, 2179867635, 2526361520,
- 2937588597, 3093503798, 3691148031, 3413731004, 4076100217, 3851374138,
- 2532754330, 2173556697, 3087067932, 2944139103, 3407516310, 3697379029,
- 3857496592, 4070026835, 758014338, 978679233, 64506116, 346250567,
- 1891774606, 1740186829, 1580472328, 1229917259,
- },
- {
- 0, 4022496062, 83218493, 3946298115, 166436986, 3861498692,
- 220098631, 3806075769, 332873972, 4229245898, 388141257, 4175494135,
- 440197262, 4127099824, 516501683, 4044053389, 665747944, 3362581206,
- 593187285, 3432594155, 776282514, 3246869164, 716239279, 3312622225,
- 880394524, 3686509090, 814485793, 3746462239, 1033003366, 3528460888,
- 963096923, 3601193573, 1331495888, 2694801646, 1269355501, 2758457555,
- 1186374570, 2843003028, 1111716759, 2910918825, 1552565028, 3007850522,
- 1484755737, 3082680359, 1432478558, 3131279456, 1368666979, 3193329757,
- 1760789048, 2268195078, 1812353541, 2210675003, 1628971586, 2396670332,
- 1710092927, 2318375233, 2066006732, 2498144754, 2144408305, 2417195471,
- 1926193846, 2634877320, 1983558283, 2583222709, 2662991776, 1903717534,
- 2588923805, 1972223139, 2538711002, 2022952164, 2477029351, 2087066841,
- 2372749140, 1655647338, 2308478825, 1717238871, 2223433518, 1799654416,
- 2155034387, 1873894445, 3105130056, 1456926070, 3185661557, 1378041163,
- 2969511474, 1597852940, 3020617231, 1539874097, 2864957116, 1157737858,
- 2922780289, 1106542015, 2737333958, 1290407416, 2816325371, 1210047941,
- 3521578096, 1042640718, 3574781005, 986759027, 3624707082, 936300340,
- 3707335735, 859512585, 3257943172, 770846650, 3334837433, 688390023,
- 3420185854, 605654976, 3475911875, 552361981, 4132013464, 428600998,
- 4072428965, 494812827, 4288816610, 274747100, 4216845791, 345349857,
- 3852387692, 173846098, 3781891409, 245988975, 3967116566, 62328360,
- 3900749099, 121822741, 3859089665, 164061759, 3807435068, 221426178,
- 4025395579, 2933317, 3944446278, 81334904, 4124199413, 437265099,
- 4045904328, 518386422, 4231653775, 335250097, 4174133682, 386814604,
- 3249244393, 778691543, 3311294676, 714879978, 3359647891, 662848429,
- 3434477742, 595039120, 3531393053, 1035903779, 3599308832, 961245982,
- 3684132967, 877986649, 3747788890, 815846244, 2841119441, 1184522735,
- 2913852140, 1114616274, 2696129195, 1332855189, 2756082326, 1266946472,
- 3129952805, 1431118107, 3195705880, 1371074854, 3009735263, 1554415969,
- 3079748194, 1481855324, 2398522169, 1630855175, 2315475716, 1707159610,
- 2266835779, 1759461501, 2213084030, 1814728768, 2636237773, 1927520499,
- 2580814832, 1981182158, 2496293815, 2064121993, 2420095882, 2147340468,
- 2025787041, 2541577631, 2085281436, 2475210146, 1901375195, 2660681189,
- 1973518054, 2590184920, 1801997909, 2225743211, 1872600680, 2153772374,
- 1652813359, 2369881361, 1719025170, 2310296876, 1594986313, 2966676599,
- 1541693300, 3022402634, 1459236659, 3107472397, 1376780046, 3184366640,
- 1288097725, 2734990467, 1211309952, 2817619134, 1160605639, 2867791097,
- 1104723962, 2920993988, 937561457, 3626001999, 857201996, 3704993394,
- 1040821515, 3519792693, 989625654, 3577615880, 607473029, 3421972155,
- 549494200, 3473077894, 769584639, 3256649409, 690699714, 3337180924,
- 273452185, 4287555495, 347692196, 4219156378, 430386403, 4133832669,
- 491977950, 4069562336, 60542061, 3965298515, 124656720, 3903616878,
- 175139863, 3853649705, 243645482, 3779581716,
- },
- {
- 0, 3247366080, 1483520449, 2581751297, 2967040898, 1901571138,
- 3904227907, 691737987, 3133399365, 2068659845, 3803142276, 589399876,
- 169513671, 3415493895, 1383475974, 2482566342, 2935407819, 1870142219,
- 4137319690, 924099274, 506443593, 3751897225, 1178799752, 2278412616,
- 339027342, 3585866318, 1280941135, 2379694991, 2766951948, 1700956620,
- 4236308429, 1024339981, 2258407383, 1192382487, 3740284438, 528411094,
- 910556245, 4157285269, 1848198548, 2946996820, 1012887186, 4258378066,
- 1681119059, 2780629139, 2357599504, 1292419792, 3572147409, 358906641,
- 678054684, 3924071644, 1879503581, 2978491677, 2561882270, 1497229150,
- 3235873119, 22109855, 2460592729, 1395094937, 3401913240, 189516888,
- 577821147, 3825075739, 2048679962, 3146956762, 3595049455, 398902831,
- 2384764974, 1336573934, 1720805997, 2803873197, 1056822188, 4285729900,
- 1821112490, 2902796138, 887570795, 4117339819, 3696397096, 500978920,
- 2218668777, 1169222953, 2025774372, 3106931428, 550659301, 3780950821,
- 3362238118, 166293862, 2416645991, 1367722151, 3262987361, 66315169,
- 2584839584, 1537170016, 1923370979, 3005911075, 717813282, 3947244002,
- 1356109368, 2438613496, 146288633, 3375820857, 3759007162, 562248314,
- 3093388411, 2045739963, 3927406461, 731490493, 2994458300, 1945440636,
- 1523451135, 2604718911, 44219710, 3274466046, 4263662323, 1068272947,
- 2790189874, 1740649714, 1325080945, 2406874801, 379033776, 3608758128,
- 1155642294, 2238671990, 479005303, 3708016055, 4097359924, 901128180,
- 2891217397, 1843045941, 2011248031, 3060787807, 797805662, 3993195422,
- 3342353949, 112630237, 2673147868, 1591353372, 3441611994, 212601626,
- 2504944923, 1421914843, 2113644376, 3161815192, 630660761, 3826893145,
- 3642224980, 412692116, 2172340373, 1089836885, 1775141590, 2822790422,
- 832715543, 4029474007, 1674842129, 2723860433, 1001957840, 4197873168,
- 3540870035, 310623315, 2338445906, 1257178514, 4051548744, 821257608,
- 2836464521, 1755307081, 1101318602, 2150241802, 432566283, 3628511179,
- 1270766349, 2318435533, 332587724, 3529260300, 4217841807, 988411727,
- 2735444302, 1652903566, 1602977411, 2651169091, 132630338, 3328776322,
- 4015131905, 786223809, 3074340032, 1991273216, 3846741958, 616972294,
- 3173262855, 2091579847, 1435626564, 2485072772, 234706309, 3430124101,
- 2712218736, 1613231024, 4190475697, 944458353, 292577266, 3506339890,
- 1226630707, 2291284467, 459984181, 3672380149, 1124496628, 2189994804,
- 2880683703, 1782407543, 4091479926, 844224694, 257943739, 3469817723,
- 1462980986, 2529005242, 3213269817, 2114471161, 3890881272, 644152632,
- 3046902270, 1947391550, 3991973951, 746483711, 88439420, 3301680572,
- 1563018173, 2628197501, 657826727, 3871046759, 2136545894, 3201811878,
- 2548879397, 1449267173, 3481299428, 235845156, 2650161890, 1551408418,
- 3315268387, 68429027, 758067552, 3970035360, 1967360161, 3033356129,
- 2311284588, 1213053100, 3517963949, 270598509, 958010606, 4170500910,
- 1635167535, 2700636911, 855672361, 4069415401, 1802256360, 2866995240,
- 2212099499, 1113008747, 3686091882, 440112042,
- },
- {
- 0, 2611301487, 3963330207, 2006897392, 50740095, 2560849680,
- 4013794784, 1956178319, 101480190, 2645113489, 3929532513, 1905435662,
- 84561281, 2662269422, 3912356638, 1922342769, 202960380, 2545787283,
- 3760419683, 2072395532, 253679235, 2495322860, 3810871324, 2021655667,
- 169122562, 2444351341, 3861841309, 2106214898, 152215677, 2461527058,
- 3844685538, 2123133581, 405920760, 2207553431, 4094313831, 1873742088,
- 456646791, 2157096168, 4144791064, 1823027831, 507358470, 2241388905,
- 4060492697, 1772322806, 490444409, 2258557462, 4043311334, 1789215881,
- 338245124, 2408348267, 4161972379, 1672996084, 388959611, 2357870868,
- 4212429796, 1622269835, 304431354, 2306870421, 4263435877, 1706791434,
- 287538053, 2324051946, 4246267162, 1723705717, 811841520, 2881944479,
- 3696765295, 1207788800, 862293135, 2831204576, 3747484176, 1157324415,
- 913293582, 2915732833, 3662962577, 1106318334, 896137841, 2932651550,
- 3646055662, 1123494017, 1014716940, 2816349795, 3493905555, 1273334012,
- 1065181555, 2765630748, 3544645612, 1222882179, 980888818, 2714919069,
- 3595350637, 1307180546, 963712909, 2731826146, 3578431762, 1324336509,
- 676490248, 3019317351, 3295277719, 1607253752, 726947703, 2968591128,
- 3345992168, 1556776327, 777919222, 3053147801, 3261432937, 1505806342,
- 760750473, 3070062054, 3244539670, 1522987897, 608862708, 3220163995,
- 3362856811, 1406423812, 659339915, 3169449700, 3413582868, 1355966587,
- 575076106, 3118709605, 3464325525, 1440228858, 557894773, 3135602714,
- 3447411434, 1457397381, 1623683040, 4217512847, 2365387135, 391757072,
- 1673614495, 4167309552, 2415577600, 341804655, 1724586270, 4251866481,
- 2331019137, 290835438, 1707942497, 4268256782, 2314648830, 307490961,
- 1826587164, 4152020595, 2162433155, 457265388, 1876539747, 4101829900,
- 2212636668, 407333779, 1792275682, 4051089549, 2263378557, 491595282,
- 1775619997, 4067460082, 2246988034, 508239213, 2029433880, 3813931127,
- 2496473735, 258500328, 2079362919, 3763716872, 2546668024, 208559511,
- 2130363110, 3848244873, 2462145657, 157552662, 2113730969, 3864638966,
- 2445764358, 174205801, 1961777636, 4014675339, 2564147067, 57707284,
- 2011718299, 3964481268, 2614361092, 7778411, 1927425818, 3913769845,
- 2665066885, 92077546, 1910772837, 3930150922, 2648673018, 108709525,
- 1352980496, 3405878399, 3164554895, 658115296, 1403183983, 3355946752,
- 3214507504, 607924639, 1453895406, 3440239233, 3130208369, 557218846,
- 1437504913, 3456883198, 3113552654, 573589345, 1555838444, 3340335491,
- 2961681267, 723707676, 1606028947, 3290383100, 3011612684, 673504355,
- 1521500946, 3239382909, 3062619533, 758026722, 1505130605, 3256038402,
- 3045975794, 774417053, 1217725416, 3543158663, 2762906999, 1057739032,
- 1267939479, 3493229816, 2812847624, 1007544935, 1318679830, 3577493881,
- 2728586121, 956803046, 1302285929, 3594125830, 2711933174, 973184153,
- 1150152212, 3743982203, 2830528651, 856898788, 1200346475, 3694041348,
- 2880457716, 806684571, 1115789546, 3643069573, 2931426933, 891243034,
- 1099408277, 3659722746, 2914794762, 907637093,
- },
- {
- 0, 3717650821, 1616688459, 3184159950, 3233376918, 489665299,
- 2699419613, 2104690264, 1510200173, 2274691816, 979330598, 3888758691,
- 2595928571, 1194090622, 4209380528, 661706037, 3020400346, 1771143007,
- 3562738577, 164481556, 1958661196, 2837976521, 350386439, 3379863682,
- 3993269687, 865250354, 2388181244, 1406015865, 784146209, 4079732388,
- 1323412074, 2474079215, 3011398645, 1860735600, 3542286014, 246687547,
- 1942430051, 2924607718, 328963112, 3456978349, 3917322392, 887832861,
- 2300653011, 1421341782, 700772878, 4099025803, 1234716485, 2483986112,
- 125431087, 3673109674, 1730500708, 3132326369, 3351283641, 441867836,
- 2812031730, 2047535991, 1568292418, 2163009479, 1025936137, 3769651852,
- 2646824148, 1079348561, 4255113631, 537475098, 3180171691, 1612400686,
- 3721471200, 4717925, 2100624189, 2694980280, 493375094, 3237910515,
- 3884860102, 974691139, 2278750093, 1514417672, 657926224, 4204917205,
- 1198234907, 2600289438, 160053105, 3558665972, 1775665722, 3024116671,
- 3375586791, 346391650, 2842683564, 1962488105, 1401545756, 2384412057,
- 869618007, 3997403346, 2469432970, 1319524111, 4083956673, 788193860,
- 250862174, 3546612699, 1856990997, 3006903952, 3461001416, 333211981,
- 2920678787, 1937824774, 1425017139, 2305216694, 883735672, 3912918525,
- 2487837605, 1239398944, 4095071982, 696455019, 3136584836, 1734518017,
- 3668494799, 121507914, 2051872274, 2816200599, 437363545, 3347544796,
- 3774328809, 1029797484, 2158697122, 1564328743, 542033279, 4258798842,
- 1074950196, 2642717105, 2691310871, 2113731730, 3224801372, 497043929,
- 1624461185, 3175454212, 9435850, 3709412175, 4201248378, 671035391,
- 2587181873, 1201904308, 986750188, 3880142185, 1519135143, 2266689570,
- 342721485, 3388693064, 1949382278, 2846355203, 3570723163, 155332830,
- 3028835344, 1763607957, 1315852448, 2482538789, 775087595, 4087626862,
- 2396469814, 1396827059, 4002123645, 857560824, 320106210, 3464673127,
- 1934154665, 2933785132, 3551331444, 238804465, 3018961215, 1852270778,
- 1226292623, 2491507722, 692783300, 4108177729, 2309936921, 1412959900,
- 3924976210, 879016919, 2803091512, 2055541181, 3343875443, 450471158,
- 1739236014, 3124525867, 133568485, 3663777376, 4245691221, 545702608,
- 2639048222, 1088059291, 1034514883, 3762268230, 1576387720, 2153979149,
- 501724348, 3228659001, 2109407735, 2687359090, 3713981994, 13109167,
- 3171052385, 1620357860, 1206151121, 2591211092, 666423962, 4197321503,
- 2271022407, 1523307714, 3875649548, 982999433, 2850034278, 1953942499,
- 3384583981, 338329256, 1767471344, 3033506165, 151375291, 3566408766,
- 4091789579, 779425934, 2478797888, 1311354309, 861580189, 4006375960,
- 1392910038, 2391852883, 2929327945, 1930372812, 3469036034, 324244359,
- 1847629279, 3015068762, 243015828, 3555391761, 4103744548, 688715169,
- 2496043375, 1229996266, 874727090, 3920994103, 1417671673, 2313759356,
- 446585235, 3339223062, 2059594968, 2807313757, 3660002053, 129100416,
- 3128657486, 1743609803, 1084066558, 2634765179, 549535669, 4250396208,
- 2149900392, 1571961325, 3765982499, 1039043750,
- },
- {
- 0, 2635063670, 3782132909, 2086741467, 430739227, 2225303149,
- 4173482934, 1707977408, 861478454, 2924937024, 3526875803, 1329085421,
- 720736557, 3086643291, 3415954816, 1452586230, 1722956908, 4223524122,
- 2279405761, 450042295, 2132718455, 3792785921, 2658170842, 58693292,
- 1441473114, 3370435372, 3028674295, 696911745, 1279765825, 3511176247,
- 2905172460, 807831706, 3445913816, 1349228974, 738901109, 2969918723,
- 3569940419, 1237784245, 900084590, 2829701656, 4265436910, 1664255896,
- 525574723, 2187084597, 3885099509, 2057177219, 117386584, 2616249390,
- 2882946228, 920233410, 1253605401, 3619119471, 2994391983, 796207833,
- 1393823490, 3457937012, 2559531650, 92322804, 2044829231, 3840835417,
- 2166609305, 472659183, 1615663412, 4249022530, 1102706673, 3702920839,
- 2698457948, 1037619754, 1477802218, 3306854812, 3111894087, 611605809,
- 1927342535, 4025419953, 2475568490, 243387420, 1800169180, 4131620778,
- 2317525617, 388842247, 655084445, 3120835307, 3328511792, 1533734470,
- 1051149446, 2745738736, 3754524715, 1120297309, 340972971, 2304586973,
- 4114354438, 1748234352, 234773168, 2431761350, 3968900637, 1906278251,
- 2363330345, 299003487, 1840466820, 4038896370, 2507210802, 142532932,
- 1948239007, 3910149609, 3213136159, 579563625, 1592415666, 3286611140,
- 2787646980, 992477042, 1195825833, 3662232543, 3933188933, 2002801203,
- 184645608, 2517538462, 4089658462, 1858919720, 313391347, 2409765253,
- 3644239219, 1144605701, 945318366, 2773977256, 3231326824, 1570095902,
- 569697989, 3170568115, 2205413346, 511446676, 1646078799, 4279421497,
- 2598330617, 131105167, 2075239508, 3871229218, 2955604436, 757403810,
- 1363424633, 3427521551, 2844163791, 881434553, 1223211618, 3588709140,
- 3854685070, 2026779384, 78583587, 2577462869, 4235025557, 1633861091,
- 486774840, 2148301134, 3600338360, 1268198606, 938871061, 2868504675,
- 3476308643, 1379640277, 777684494, 3008718712, 1310168890, 3541595724,
- 2943964055, 846639841, 1471879201, 3400857943, 3067468940, 735723002,
- 2102298892, 3762382970, 2619362721, 19901655, 1692534295, 4193118049,
- 2240594618, 411247564, 681945942, 3047836192, 3385552891, 1422167693,
- 822682701, 2886124859, 3496468704, 1298661782, 469546336, 2264093718,
- 4203901389, 1738379451, 38812283, 2673859341, 3812556502, 2117148576,
- 3268024339, 1606809957, 598006974, 3198893512, 3680933640, 1181316734,
- 973624229, 2802299603, 4052944421, 1822222163, 285065864, 2381456382,
- 3896478014, 1966106696, 156323219, 2489232613, 2759337087, 964150537,
- 1159127250, 3625517476, 3184831332, 551242258, 1555722185, 3249901247,
- 2535537225, 170842943, 1984954084, 3946848146, 2391651666, 327308324,
- 1877176831, 4075589769, 263086283, 2460058045, 4005602406, 1942963472,
- 369291216, 2332888742, 4151061373, 1784924683, 1022852861, 2717425547,
- 3717839440, 1083595558, 626782694, 3092517008, 3291821387, 1497027645,
- 1763466407, 4094934481, 2289211402, 360544636, 1890636732, 3988730570,
- 2447251217, 215086695, 1514488465, 3343557607, 3140191804, 639919946,
- 1139395978, 3739626748, 2726758695, 1065936977,
- },
- {
- 0, 3120290792, 2827399569, 293431929, 2323408227, 864534155,
- 586863858, 2600537882, 3481914503, 1987188591, 1729068310, 3740575486,
- 1173727716, 4228805132, 3983743093, 1418249117, 1147313999, 4254680231,
- 3974377182, 1428157750, 3458136620, 2011505092, 1721256893, 3747844181,
- 2347455432, 839944224, 594403929, 2593536433, 26687147, 3094146371,
- 2836498234, 283794642, 2294627998, 826205558, 541298447, 2578994407,
- 45702141, 3141697557, 2856315500, 331624836, 1196225049, 4273416689,
- 4023010184, 1446090848, 3442513786, 1959480466, 1706436331, 3696098563,
- 3433538001, 1968994873, 1679888448, 3722103720, 1188807858, 4280295258,
- 3999102243, 1470541515, 53374294, 3134568126, 2879970503, 307431215,
- 2303854645, 816436189, 567589284, 2553242188, 3405478781, 1929420949,
- 1652411116, 3682996484, 1082596894, 4185703926, 3892424591, 1375368295,
- 91404282, 3163122706, 2918450795, 336584067, 2400113305, 922028401,
- 663249672, 2658384096, 2392450098, 929185754, 639587747, 2682555979,
- 82149713, 3172883129, 2892181696, 362343208, 1091578037, 4176212829,
- 3918960932, 1349337804, 3412872662, 1922537022, 1676344391, 3658557359,
- 1111377379, 4224032267, 3937989746, 1396912026, 3359776896, 1908013928,
- 1623494929, 3644803833, 2377615716, 877417100, 623982837, 2630542109,
- 130804743, 3190831087, 2941083030, 381060734, 106748588, 3215393092,
- 2933549885, 388083925, 2350956495, 903570471, 614862430, 2640172470,
- 3386185259, 1882115523, 1632872378, 3634920530, 1135178568, 4199721120,
- 3945775833, 1389631793, 1317531835, 4152109907, 3858841898, 1610259138,
- 3304822232, 2097172016, 1820140617, 3582394273, 2165193788, 955639764,
- 696815021, 2423477829, 192043359, 2995356343, 2750736590, 437203750,
- 182808564, 3005133852, 2724453989, 462947725, 2157513367, 962777471,
- 673168134, 2447663342, 3312231283, 2090301595, 1844056802, 3557935370,
- 1326499344, 4142603768, 3885397889, 1584245865, 3326266917, 2142836173,
- 1858371508, 3611272284, 1279175494, 4123357358, 3837270743, 1564721471,
- 164299426, 2955991370, 2706223923, 414607579, 2209834945, 978107433,
- 724686416, 2462715320, 2183156074, 1004243586, 715579643, 2472360723,
- 140260361, 2980573153, 2698675608, 421617264, 1302961645, 4099032581,
- 3845074044, 1557460884, 3352688782, 2116952934, 1867729183, 3601371895,
- 2222754758, 1032278062, 754596439, 2499928511, 234942117, 3086693709,
- 2793824052, 528319708, 1274365761, 4061043881, 3816027856, 1518873912,
- 3246989858, 2020800970, 1762628531, 3505670235, 3223196809, 2045103969,
- 1754834200, 3512958704, 1247965674, 4086934018, 3806642299, 1528765331,
- 261609486, 3060532198, 2802936223, 518697591, 2246819181, 1007707781,
- 762121468, 2492913428, 213497176, 3041029808, 2755593417, 499441441,
- 2261110843, 1061030867, 776167850, 2545465922, 3274734047, 2060165687,
- 1807140942, 3528266662, 1229724860, 4038575956, 3788156205, 1479636677,
- 1222322711, 4045468159, 3764231046, 1504067694, 3265744756, 2069664924,
- 1780612837, 3554288909, 2270357136, 1051278712, 802445057, 2519698665,
- 221152243, 3033880603, 2779263586, 475261322,
- },
- {
- 0, 2926088593, 2275419491, 701019378, 3560000647, 2052709654,
- 1402038756, 4261017717, 1930665807, 3715829470, 4105419308, 1524313021,
- 2804077512, 155861593, 545453739, 2397726522, 3861331614, 1213181711,
- 1636244477, 3488582252, 840331801, 2625561480, 3048626042, 467584747,
- 2503254481, 995897408, 311723186, 3170637091, 1090907478, 4016929991,
- 3332753461, 1758288292, 390036349, 3109546732, 2426363422, 1056427919,
- 3272488954, 1835443819, 1152258713, 3938878216, 1680663602, 3393484195,
- 3817652561, 1306808512, 2954733749, 510998820, 935169494, 2580880455,
- 4044899811, 1601229938, 1991794816, 3637571857, 623446372, 2336332021,
- 2726898695, 216120726, 2181814956, 744704829, 95158223, 2881711710,
- 1446680107, 4166125498, 3516576584, 2146575065, 780072698, 2148951915,
- 2849952665, 129384968, 4199529085, 1411853292, 2112855838, 3548843663,
- 1567451573, 4077254692, 3670887638, 1957027143, 2304517426, 657765539,
- 251396177, 2694091200, 3361327204, 1714510325, 1341779207, 3784408214,
- 476611811, 2986349938, 2613617024, 899690513, 3142211371, 354600634,
- 1021997640, 2458051545, 1870338988, 3239283261, 3906682575, 1186180958,
- 960597383, 2536053782, 3202459876, 277428597, 3983589632, 1125666961,
- 1792074851, 3300423154, 1246892744, 3829039961, 3455203243, 1671079482,
- 2657312335, 806080478, 432241452, 3081497277, 3748049689, 1896751752,
- 1489409658, 4138600427, 190316446, 2772397583, 2365053693, 580864876,
- 2893360214, 35503559, 735381813, 2243795108, 2017747153, 3593269568,
- 4293150130, 1368183843, 1560145396, 4069882981, 3680356503, 1966430470,
- 2295112051, 648294626, 258769936, 2701399425, 804156091, 2173100842,
- 2823706584, 103204425, 4225711676, 1438101421, 2088704863, 3524758222,
- 3134903146, 347226875, 1031468553, 2467456920, 1860935661, 3229814396,
- 3914054286, 1193487135, 3385412645, 1738661300, 1315531078, 3758225623,
- 502792354, 3012596019, 2589468097, 875607120, 1271043721, 3853125400,
- 3429020650, 1644831355, 2683558414, 832261023, 408158061, 3057348348,
- 953223622, 2528745559, 3211865253, 286899508, 3974120769, 1116263632,
- 1799381026, 3307794867, 2917509143, 59586950, 709201268, 2217549029,
- 2043995280, 3619452161, 4269064691, 1344032866, 3740677976, 1889445577,
- 1498812987, 4148069290, 180845535, 2762992206, 2372361916, 588238637,
- 1921194766, 3706423967, 4112727661, 1531686908, 2796705673, 148555288,
- 554857194, 2407195515, 26248257, 2952271312, 2251333922, 676868275,
- 3584149702, 2076793175, 1375858085, 4234771508, 2493785488, 986493953,
- 319029491, 3178008930, 1083533591, 4009621638, 3342158964, 1767759333,
- 3887577823, 1239362382, 1612160956, 3464433197, 864482904, 2649647049,
- 3022443323, 441336490, 1706844275, 3419730402, 3793503504, 1282724993,
- 2978819316, 535149925, 908921239, 2554697734, 380632892, 3100077741,
- 2433735263, 1063734222, 3265180603, 1828069930, 1161729752, 3948283721,
- 2207997677, 770953084, 71007118, 2857626143, 1470763626, 4190274555,
- 3490330377, 2120394392, 4035494306, 1591758899, 1999168705, 3644880208,
- 616140069, 2328960180, 2736367686, 225524183,
- },
+static const uint32_t //
+ wuffs_crc32__ieee_table[16][256] //
+ WUFFS_BASE__POTENTIALLY_UNUSED = {
+ {
+ 0, 1996959894, 3993919788, 2567524794, 124634137,
+ 1886057615, 3915621685, 2657392035, 249268274, 2044508324,
+ 3772115230, 2547177864, 162941995, 2125561021, 3887607047,
+ 2428444049, 498536548, 1789927666, 4089016648, 2227061214,
+ 450548861, 1843258603, 4107580753, 2211677639, 325883990,
+ 1684777152, 4251122042, 2321926636, 335633487, 1661365465,
+ 4195302755, 2366115317, 997073096, 1281953886, 3579855332,
+ 2724688242, 1006888145, 1258607687, 3524101629, 2768942443,
+ 901097722, 1119000684, 3686517206, 2898065728, 853044451,
+ 1172266101, 3705015759, 2882616665, 651767980, 1373503546,
+ 3369554304, 3218104598, 565507253, 1454621731, 3485111705,
+ 3099436303, 671266974, 1594198024, 3322730930, 2970347812,
+ 795835527, 1483230225, 3244367275, 3060149565, 1994146192,
+ 31158534, 2563907772, 4023717930, 1907459465, 112637215,
+ 2680153253, 3904427059, 2013776290, 251722036, 2517215374,
+ 3775830040, 2137656763, 141376813, 2439277719, 3865271297,
+ 1802195444, 476864866, 2238001368, 4066508878, 1812370925,
+ 453092731, 2181625025, 4111451223, 1706088902, 314042704,
+ 2344532202, 4240017532, 1658658271, 366619977, 2362670323,
+ 4224994405, 1303535960, 984961486, 2747007092, 3569037538,
+ 1256170817, 1037604311, 2765210733, 3554079995, 1131014506,
+ 879679996, 2909243462, 3663771856, 1141124467, 855842277,
+ 2852801631, 3708648649, 1342533948, 654459306, 3188396048,
+ 3373015174, 1466479909, 544179635, 3110523913, 3462522015,
+ 1591671054, 702138776, 2966460450, 3352799412, 1504918807,
+ 783551873, 3082640443, 3233442989, 3988292384, 2596254646,
+ 62317068, 1957810842, 3939845945, 2647816111, 81470997,
+ 1943803523, 3814918930, 2489596804, 225274430, 2053790376,
+ 3826175755, 2466906013, 167816743, 2097651377, 4027552580,
+ 2265490386, 503444072, 1762050814, 4150417245, 2154129355,
+ 426522225, 1852507879, 4275313526, 2312317920, 282753626,
+ 1742555852, 4189708143, 2394877945, 397917763, 1622183637,
+ 3604390888, 2714866558, 953729732, 1340076626, 3518719985,
+ 2797360999, 1068828381, 1219638859, 3624741850, 2936675148,
+ 906185462, 1090812512, 3747672003, 2825379669, 829329135,
+ 1181335161, 3412177804, 3160834842, 628085408, 1382605366,
+ 3423369109, 3138078467, 570562233, 1426400815, 3317316542,
+ 2998733608, 733239954, 1555261956, 3268935591, 3050360625,
+ 752459403, 1541320221, 2607071920, 3965973030, 1969922972,
+ 40735498, 2617837225, 3943577151, 1913087877, 83908371,
+ 2512341634, 3803740692, 2075208622, 213261112, 2463272603,
+ 3855990285, 2094854071, 198958881, 2262029012, 4057260610,
+ 1759359992, 534414190, 2176718541, 4139329115, 1873836001,
+ 414664567, 2282248934, 4279200368, 1711684554, 285281116,
+ 2405801727, 4167216745, 1634467795, 376229701, 2685067896,
+ 3608007406, 1308918612, 956543938, 2808555105, 3495958263,
+ 1231636301, 1047427035, 2932959818, 3654703836, 1088359270,
+ 936918000, 2847714899, 3736837829, 1202900863, 817233897,
+ 3183342108, 3401237130, 1404277552, 615818150, 3134207493,
+ 3453421203, 1423857449, 601450431, 3009837614, 3294710456,
+ 1567103746, 711928724, 3020668471, 3272380065, 1510334235,
+ 755167117,
+ },
+ {
+ 0, 421212481, 842424962, 724390851, 1684849924,
+ 2105013317, 1448781702, 1329698503, 3369699848, 3519200073,
+ 4210026634, 3824474571, 2897563404, 3048111693, 2659397006,
+ 2274893007, 1254232657, 1406739216, 2029285587, 1643069842,
+ 783210325, 934667796, 479770071, 92505238, 2182846553,
+ 2600511768, 2955803355, 2838940570, 3866582365, 4285295644,
+ 3561045983, 3445231262, 2508465314, 2359236067, 2813478432,
+ 3198777185, 4058571174, 3908292839, 3286139684, 3670389349,
+ 1566420650, 1145479147, 1869335592, 1987116393, 959540142,
+ 539646703, 185010476, 303839341, 3745920755, 3327985586,
+ 3983561841, 4100678960, 3140154359, 2721170102, 2300350837,
+ 2416418868, 396344571, 243568058, 631889529, 1018359608,
+ 1945336319, 1793607870, 1103436669, 1490954812, 4034481925,
+ 3915546180, 3259968903, 3679722694, 2484439553, 2366552896,
+ 2787371139, 3208174018, 950060301, 565965900, 177645455,
+ 328046286, 1556873225, 1171730760, 1861902987, 2011255754,
+ 3132841300, 2745199637, 2290958294, 2442530455, 3738671184,
+ 3352078609, 3974232786, 4126854035, 1919080284, 1803150877,
+ 1079293406, 1498383519, 370020952, 253043481, 607678682,
+ 1025720731, 1711106983, 2095471334, 1472923941, 1322268772,
+ 26324643, 411738082, 866634785, 717028704, 2904875439,
+ 3024081134, 2668790573, 2248782444, 3376948395, 3495106026,
+ 4219356713, 3798300520, 792689142, 908347575, 487136116,
+ 68299317, 1263779058, 1380486579, 2036719216, 1618931505,
+ 3890672638, 4278043327, 3587215740, 3435896893, 2206873338,
+ 2593195963, 2981909624, 2829542713, 998479947, 580430090,
+ 162921161, 279890824, 1609522511, 1190423566, 1842954189,
+ 1958874764, 4082766403, 3930137346, 3245109441, 3631694208,
+ 2536953671, 2385372678, 2768287173, 3155920004, 1900120602,
+ 1750776667, 1131931800, 1517083097, 355290910, 204897887,
+ 656092572, 1040194781, 3113746450, 2692952403, 2343461520,
+ 2461357009, 3723805974, 3304059991, 4022511508, 4141455061,
+ 2919742697, 3072101800, 2620513899, 2234183466, 3396041197,
+ 3547351212, 4166851439, 3779471918, 1725839073, 2143618976,
+ 1424512099, 1307796770, 45282277, 464110244, 813994343,
+ 698327078, 3838160568, 4259225593, 3606301754, 3488152955,
+ 2158586812, 2578602749, 2996767038, 2877569151, 740041904,
+ 889656817, 506086962, 120682355, 1215357364, 1366020341,
+ 2051441462, 1667084919, 3422213966, 3538019855, 4190942668,
+ 3772220557, 2945847882, 3062702859, 2644537544, 2226864521,
+ 52649286, 439905287, 823476164, 672009861, 1733269570,
+ 2119477507, 1434057408, 1281543041, 2167981343, 2552493150,
+ 3004082077, 2853541596, 3847487515, 4233048410, 3613549209,
+ 3464057816, 1239502615, 1358593622, 2077699477, 1657543892,
+ 764250643, 882293586, 532408465, 111204816, 1585378284,
+ 1197851309, 1816695150, 1968414767, 974272232, 587794345,
+ 136598634, 289367339, 2527558116, 2411481253, 2760973158,
+ 3179948583, 4073438432, 3956313505, 3237863010, 3655790371,
+ 347922877, 229101820, 646611775, 1066513022, 1892689081,
+ 1774917112, 1122387515, 1543337850, 3697634229, 3313392372,
+ 3998419255, 4148705398, 3087642289, 2702352368, 2319436851,
+ 2468674930,
+ },
+ {
+ 0, 29518391, 59036782, 38190681, 118073564,
+ 114017003, 76381362, 89069189, 236147128, 265370511,
+ 228034006, 206958561, 152762724, 148411219, 178138378,
+ 190596925, 472294256, 501532999, 530741022, 509615401,
+ 456068012, 451764635, 413917122, 426358261, 305525448,
+ 334993663, 296822438, 275991697, 356276756, 352202787,
+ 381193850, 393929805, 944588512, 965684439, 1003065998,
+ 973863097, 1061482044, 1049003019, 1019230802, 1023561829,
+ 912136024, 933002607, 903529270, 874031361, 827834244,
+ 815125939, 852716522, 856752605, 611050896, 631869351,
+ 669987326, 640506825, 593644876, 580921211, 551983394,
+ 556069653, 712553512, 733666847, 704405574, 675154545,
+ 762387700, 749958851, 787859610, 792175277, 1889177024,
+ 1901651959, 1931368878, 1927033753, 2006131996, 1985040171,
+ 1947726194, 1976933189, 2122964088, 2135668303, 2098006038,
+ 2093965857, 2038461604, 2017599123, 2047123658, 2076625661,
+ 1824272048, 1836991623, 1866005214, 1861914857, 1807058540,
+ 1786244187, 1748062722, 1777547317, 1655668488, 1668093247,
+ 1630251878, 1625932113, 1705433044, 1684323811, 1713505210,
+ 1742760333, 1222101792, 1226154263, 1263738702, 1251046777,
+ 1339974652, 1310460363, 1281013650, 1301863845, 1187289752,
+ 1191637167, 1161842422, 1149379777, 1103966788, 1074747507,
+ 1112139306, 1133218845, 1425107024, 1429406311, 1467333694,
+ 1454888457, 1408811148, 1379576507, 1350309090, 1371438805,
+ 1524775400, 1528845279, 1499917702, 1487177649, 1575719220,
+ 1546255107, 1584350554, 1605185389, 3778354048, 3774312887,
+ 3803303918, 3816007129, 3862737756, 3892238699, 3854067506,
+ 3833203973, 4012263992, 4007927823, 3970080342, 3982554209,
+ 3895452388, 3924658387, 3953866378, 3932773565, 4245928176,
+ 4241609415, 4271336606, 4283762345, 4196012076, 4225268251,
+ 4187931714, 4166823541, 4076923208, 4072833919, 4035198246,
+ 4047918865, 4094247316, 4123732899, 4153251322, 4132437965,
+ 3648544096, 3636082519, 3673983246, 3678331705, 3732010428,
+ 3753090955, 3723829714, 3694611429, 3614117080, 3601426159,
+ 3572488374, 3576541825, 3496125444, 3516976691, 3555094634,
+ 3525581405, 3311336976, 3298595879, 3336186494, 3340255305,
+ 3260503756, 3281337595, 3251864226, 3222399125, 3410866088,
+ 3398419871, 3368647622, 3372945905, 3427010420, 3448139075,
+ 3485520666, 3456284973, 2444203584, 2423127159, 2452308526,
+ 2481530905, 2527477404, 2539934891, 2502093554, 2497740997,
+ 2679949304, 2659102159, 2620920726, 2650438049, 2562027300,
+ 2574714131, 2603727690, 2599670141, 2374579504, 2353749767,
+ 2383274334, 2412743529, 2323684844, 2336421851, 2298759554,
+ 2294686645, 2207933576, 2186809023, 2149495014, 2178734801,
+ 2224278612, 2236720739, 2266437690, 2262135309, 2850214048,
+ 2820717207, 2858812622, 2879680249, 2934667388, 2938704459,
+ 2909776914, 2897069605, 2817622296, 2788420399, 2759153014,
+ 2780249921, 2700618180, 2704950259, 2742877610, 2730399645,
+ 3049550800, 3020298727, 3057690558, 3078802825, 2999835404,
+ 3004150075, 2974355298, 2961925461, 3151438440, 3121956959,
+ 3092510214, 3113327665, 3168701108, 3172786307, 3210370778,
+ 3197646061,
+ },
+ {
+ 0, 3099354981, 2852767883, 313896942, 2405603159,
+ 937357362, 627793884, 2648127673, 3316918511, 2097696650,
+ 1874714724, 3607201537, 1255587768, 4067088605, 3772741427,
+ 1482887254, 1343838111, 3903140090, 4195393300, 1118632049,
+ 3749429448, 1741137837, 1970407491, 3452858150, 2511175536,
+ 756094997, 1067759611, 2266550430, 449832999, 2725482306,
+ 2965774508, 142231497, 2687676222, 412010587, 171665333,
+ 2995192016, 793786473, 2548850444, 2237264098, 1038456711,
+ 1703315409, 3711623348, 3482275674, 1999841343, 3940814982,
+ 1381529571, 1089329165, 4166106984, 4029413537, 1217896388,
+ 1512189994, 3802027855, 2135519222, 3354724499, 3577784189,
+ 1845280792, 899665998, 2367928107, 2677414085, 657096608,
+ 3137160985, 37822588, 284462994, 2823350519, 2601801789,
+ 598228824, 824021174, 2309093331, 343330666, 2898962447,
+ 3195996129, 113467524, 1587572946, 3860600759, 4104763481,
+ 1276501820, 3519211397, 1769898208, 2076913422, 3279374443,
+ 3406630818, 1941006535, 1627703081, 3652755532, 1148164341,
+ 4241751952, 3999682686, 1457141531, 247015245, 3053797416,
+ 2763059142, 470583459, 2178658330, 963106687, 735213713,
+ 2473467892, 992409347, 2207944806, 2435792776, 697522413,
+ 3024379988, 217581361, 508405983, 2800865210, 4271038444,
+ 1177467017, 1419450215, 3962007554, 1911572667, 3377213406,
+ 3690561584, 1665525589, 1799331996, 3548628985, 3241568279,
+ 2039091058, 3831314379, 1558270126, 1314193216, 4142438437,
+ 2928380019, 372764438, 75645176, 3158189981, 568925988,
+ 2572515393, 2346768303, 861712586, 3982079547, 1441124702,
+ 1196457648, 4293663189, 1648042348, 3666298377, 3358779879,
+ 1888390786, 686661332, 2421291441, 2196002399, 978858298,
+ 2811169155, 523464422, 226935048, 3040519789, 3175145892,
+ 100435649, 390670639, 2952089162, 841119475, 2325614998,
+ 2553003640, 546822429, 2029308235, 3225988654, 3539796416,
+ 1782671013, 4153826844, 1328167289, 1570739863, 3844338162,
+ 1298864389, 4124540512, 3882013070, 1608431339, 3255406162,
+ 2058742071, 1744848601, 3501990332, 2296328682, 811816591,
+ 584513889, 2590678532, 129869501, 3204563416, 2914283062,
+ 352848211, 494030490, 2781751807, 3078325777, 264757620,
+ 2450577869, 715964072, 941166918, 2158327331, 3636881013,
+ 1618608400, 1926213374, 3396585883, 1470427426, 4011365959,
+ 4255988137, 1158766284, 1984818694, 3471935843, 3695453837,
+ 1693991400, 4180638033, 1100160564, 1395044826, 3952793279,
+ 3019491049, 189112716, 435162722, 2706139399, 1016811966,
+ 2217162459, 2526189877, 774831696, 643086745, 2666061564,
+ 2354934034, 887166583, 2838900430, 294275499, 54519365,
+ 3145957664, 3823145334, 1532818963, 1240029693, 4048895640,
+ 1820460577, 3560857924, 3331051178, 2117577167, 3598663992,
+ 1858283101, 2088143283, 3301633750, 1495127663, 3785470218,
+ 4078182116, 1269332353, 332098007, 2876706482, 3116540252,
+ 25085497, 2628386432, 605395429, 916469259, 2384220526,
+ 2254837415, 1054503362, 745528876, 2496903497, 151290352,
+ 2981684885, 2735556987, 464596510, 1137851976, 4218313005,
+ 3923506883, 1365741990, 3434129695, 1946996346, 1723425172,
+ 3724871409,
+ },
+ {
+ 0, 1029712304, 2059424608, 1201699536, 4118849216,
+ 3370159984, 2403399072, 2988497936, 812665793, 219177585,
+ 1253054625, 2010132753, 3320900865, 4170237105, 3207642721,
+ 2186319825, 1625331586, 1568718386, 438355170, 658566482,
+ 2506109250, 2818578674, 4020265506, 3535817618, 1351670851,
+ 1844508147, 709922595, 389064339, 2769320579, 2557498163,
+ 3754961379, 3803185235, 3250663172, 4238411444, 3137436772,
+ 2254525908, 876710340, 153198708, 1317132964, 1944187668,
+ 4054934725, 3436268917, 2339452837, 3054575125, 70369797,
+ 961670069, 2129760613, 1133623509, 2703341702, 2621542710,
+ 3689016294, 3867263574, 1419845190, 1774270454, 778128678,
+ 318858390, 2438067015, 2888948471, 3952189479, 3606153623,
+ 1691440519, 1504803895, 504432359, 594620247, 1492342857,
+ 1704161785, 573770537, 525542041, 2910060169, 2417219385,
+ 3618876905, 3939730521, 1753420680, 1440954936, 306397416,
+ 790849880, 2634265928, 2690882808, 3888375336, 3668168600,
+ 940822475, 91481723, 1121164459, 2142483739, 3448989963,
+ 4042473659, 3075684971, 2318603227, 140739594, 889433530,
+ 1923340138, 1338244826, 4259521226, 3229813626, 2267247018,
+ 3124975642, 2570221389, 2756861693, 3824297005, 3734113693,
+ 1823658381, 1372780605, 376603373, 722643805, 2839690380,
+ 2485261628, 3548540908, 4007806556, 1556257356, 1638052860,
+ 637716780, 459464860, 4191346895, 3300051327, 2199040943,
+ 3195181599, 206718479, 825388991, 1989285231, 1274166495,
+ 3382881038, 4106388158, 3009607790, 2382549470, 1008864718,
+ 21111934, 1189240494, 2072147742, 2984685714, 2357631266,
+ 3408323570, 4131834434, 1147541074, 2030452706, 1051084082,
+ 63335554, 2174155603, 3170292451, 4216760371, 3325460867,
+ 1947622803, 1232499747, 248909555, 867575619, 3506841360,
+ 3966111392, 2881909872, 2527485376, 612794832, 434546784,
+ 1581699760, 1663499008, 3782634705, 3692447073, 2612412337,
+ 2799048193, 351717905, 697754529, 1849071985, 1398190273,
+ 1881644950, 1296545318, 182963446, 931652934, 2242328918,
+ 3100053734, 4284967478, 3255255942, 1079497815, 2100821479,
+ 983009079, 133672583, 3050795671, 2293717799, 3474399735,
+ 4067887175, 281479188, 765927844, 1778867060, 1466397380,
+ 3846680276, 3626469220, 2676489652, 2733102084, 548881365,
+ 500656741, 1517752501, 1729575173, 3577210133, 3898068133,
+ 2952246901, 2459410373, 3910527195, 3564487019, 2480257979,
+ 2931134987, 479546907, 569730987, 1716854139, 1530213579,
+ 3647316762, 3825568426, 2745561210, 2663766474, 753206746,
+ 293940330, 1445287610, 1799716618, 2314567513, 3029685993,
+ 4080348217, 3461678473, 2088098201, 1091956777, 112560889,
+ 1003856713, 3112514712, 2229607720, 3276105720, 4263857736,
+ 1275433560, 1902492648, 918929720, 195422344, 685033439,
+ 364179055, 1377080511, 1869921551, 3713294623, 3761522863,
+ 2811507327, 2599689167, 413436958, 633644462, 1650777982,
+ 1594160846, 3978570462, 3494118254, 2548332990, 2860797966,
+ 1211387997, 1968470509, 854852413, 261368461, 3182753437,
+ 2161434413, 3346310653, 4195650637, 2017729436, 1160000044,
+ 42223868, 1071931724, 2378480988, 2963576044, 4144295484,
+ 3395602316,
+ },
+ {
+ 0, 3411858341, 1304994059, 2257875630, 2609988118,
+ 1355649459, 3596215069, 486879416, 3964895853, 655315400,
+ 2711298918, 1791488195, 2009251963, 3164476382, 973758832,
+ 4048990933, 64357019, 3364540734, 1310630800, 2235723829,
+ 2554806413, 1394316072, 3582976390, 517157411, 4018503926,
+ 618222419, 2722963965, 1762783832, 1947517664, 3209171269,
+ 970744811, 4068520014, 128714038, 3438335635, 1248109629,
+ 2167961496, 2621261600, 1466012805, 3522553387, 447296910,
+ 3959392091, 547575038, 2788632144, 1835791861, 1886307661,
+ 3140622056, 1034314822, 4143626211, 75106221, 3475428360,
+ 1236444838, 2196665603, 2682996155, 1421317662, 3525567664,
+ 427767573, 3895035328, 594892389, 2782995659, 1857943406,
+ 1941489622, 3101955187, 1047553757, 4113347960, 257428076,
+ 3288652233, 1116777319, 2311878850, 2496219258, 1603640287,
+ 3640781169, 308099796, 3809183745, 676813732, 2932025610,
+ 1704983215, 2023410199, 3016104370, 894593820, 4262377657,
+ 210634999, 3352484690, 1095150076, 2316991065, 2535410401,
+ 1547934020, 3671583722, 294336591, 3772615322, 729897279,
+ 2903845777, 1716123700, 2068629644, 2953845545, 914647431,
+ 4258839074, 150212442, 3282623743, 1161604689, 2388688372,
+ 2472889676, 1480171241, 3735940167, 368132066, 3836185911,
+ 805002898, 2842635324, 1647574937, 2134298401, 3026852996,
+ 855535146, 4188192143, 186781121, 3229539940, 1189784778,
+ 2377547631, 2427670487, 1542429810, 3715886812, 371670393,
+ 3882979244, 741170185, 2864262823, 1642462466, 2095107514,
+ 3082559007, 824732849, 4201955092, 514856152, 3589064573,
+ 1400419795, 2552522358, 2233554638, 1316849003, 3370776517,
+ 62202976, 4075001525, 968836368, 3207280574, 1954014235,
+ 1769133219, 2720925446, 616199592, 4024870413, 493229635,
+ 3594175974, 1353627464, 2616354029, 2264355925, 1303087088,
+ 3409966430, 6498043, 4046820398, 979978123, 3170710821,
+ 2007099008, 1789187640, 2717386141, 661419827, 3962610838,
+ 421269998, 3527459403, 1423225061, 2676515648, 2190300152,
+ 1238466653, 3477467891, 68755798, 4115633027, 1041448998,
+ 3095868040, 1943789869, 1860096405, 2776760880, 588673182,
+ 3897205563, 449450869, 3516317904, 1459794558, 2623431131,
+ 2170245475, 1242006214, 3432247400, 131015629, 4137259288,
+ 1036337853, 3142660115, 1879958454, 1829294862, 2790523051,
+ 549483013, 3952910752, 300424884, 3669282065, 1545650111,
+ 2541513754, 2323209378, 1092980487, 3350330793, 216870412,
+ 4256931033, 921128828, 2960342482, 2066738807, 1714085583,
+ 2910195050, 736264132, 3770592353, 306060335, 3647131530,
+ 1610005796, 2494197377, 2309971513, 1123257756, 3295149874,
+ 255536279, 4268596802, 892423655, 3013951305, 2029645036,
+ 1711070292, 2929725425, 674528607, 3815288570, 373562242,
+ 3709388839, 1535949449, 2429577516, 2379569556, 1183418929,
+ 3223189663, 188820282, 4195850735, 827017802, 3084859620,
+ 2089020225, 1636228089, 2866415708, 743340786, 3876759895,
+ 361896217, 3738094268, 1482340370, 2466671543, 2382584591,
+ 1163888810, 3284924932, 144124321, 4190215028, 849168593,
+ 3020503679, 2136336858, 1649465698, 2836138695, 798521449,
+ 3838094284,
+ },
+ {
+ 0, 2792819636, 2543784233, 837294749, 4098827283,
+ 1379413927, 1674589498, 3316072078, 871321191, 2509784531,
+ 2758827854, 34034938, 3349178996, 1641505216, 1346337629,
+ 4131942633, 1742642382, 3249117050, 4030828007, 1446413907,
+ 2475800797, 904311657, 68069876, 2725880384, 1412551337,
+ 4064729373, 3283010432, 1708771380, 2692675258, 101317902,
+ 937551763, 2442587175, 3485284764, 1774858792, 1478633653,
+ 4266992385, 1005723023, 2642744891, 2892827814, 169477906,
+ 4233263099, 1512406095, 1808623314, 3451546982, 136139752,
+ 2926205020, 2676114113, 972376437, 2825102674, 236236518,
+ 1073525883, 2576072655, 1546420545, 4200303349, 3417542760,
+ 1841601500, 2609703733, 1039917185, 202635804, 2858742184,
+ 1875103526, 3384067218, 4166835727, 1579931067, 1141601657,
+ 3799809741, 3549717584, 1977839588, 2957267306, 372464350,
+ 668680259, 2175552503, 2011446046, 3516084394, 3766168119,
+ 1175200131, 2209029901, 635180217, 338955812, 2990736784,
+ 601221559, 2242044419, 3024812190, 306049834, 3617246628,
+ 1911408144, 1074125965, 3866285881, 272279504, 3058543716,
+ 2275784441, 567459149, 3832906691, 1107462263, 1944752874,
+ 3583875422, 2343980261, 767641425, 472473036, 3126744696,
+ 2147051766, 3649987394, 3899029983, 1309766251, 3092841090,
+ 506333494, 801510315, 2310084639, 1276520081, 3932237093,
+ 3683203000, 2113813516, 3966292011, 1243601823, 2079834370,
+ 3716205238, 405271608, 3192979340, 2411259153, 701492901,
+ 3750207052, 2045810168, 1209569125, 4000285905, 734575199,
+ 2378150379, 3159862134, 438345922, 2283203314, 778166598,
+ 529136603, 3120492655, 2086260449, 3660498261, 3955679176,
+ 1303499900, 3153699989, 495890209, 744928700, 2316418568,
+ 1337360518, 3921775410, 3626602927, 2120129051, 4022892092,
+ 1237286280, 2018993941, 3726666913, 461853231, 3186645403,
+ 2350400262, 711936178, 3693557851, 2052076527, 1270360434,
+ 3989775046, 677911624, 2384402428, 3220639073, 427820757,
+ 1202443118, 3789347034, 3493118535, 1984154099, 3018127229,
+ 362020041, 612099668, 2181885408, 1950653705, 3526596285,
+ 3822816288, 1168934804, 2148251930, 645706414, 395618355,
+ 2984485767, 544559008, 2248295444, 3085590153, 295523645,
+ 3560598451, 1917673479, 1134918298, 3855773998, 328860103,
+ 3052210803, 2214924526, 577903450, 3889505748, 1101147744,
+ 1883911421, 3594338121, 3424493451, 1785369663, 1535282850,
+ 4260726038, 944946072, 2653270060, 2949491377, 163225861,
+ 4294103532, 1501944408, 1752023237, 3457862513, 196998655,
+ 2915761739, 2619532502, 978710370, 2881684293, 229902577,
+ 1012666988, 2586515928, 1603020630, 4193987810, 3356702335,
+ 1852063179, 2553040162, 1046169238, 263412747, 2848217023,
+ 1818454321, 3390333573, 4227627032, 1569420204, 60859927,
+ 2782375331, 2487203646, 843627658, 4159668740, 1368951216,
+ 1617990445, 3322386585, 810543216, 2520310724, 2815490393,
+ 27783917, 3288386659, 1652017111, 1402985802, 4125677310,
+ 1685994201, 3255382381, 4091620336, 1435902020, 2419138250,
+ 910562686, 128847843, 2715354199, 1469150398, 4058414858,
+ 3222168983, 1719234083, 2749255853, 94984985, 876691844,
+ 2453031472,
+ },
+ {
+ 0, 3433693342, 1109723005, 2391738339, 2219446010,
+ 1222643300, 3329165703, 180685081, 3555007413, 525277995,
+ 2445286600, 1567235158, 1471092047, 2600801745, 361370162,
+ 3642757804, 2092642603, 2953916853, 1050555990, 4063508168,
+ 4176560081, 878395215, 3134470316, 1987983410, 2942184094,
+ 1676945920, 3984272867, 567356797, 722740324, 3887998202,
+ 1764827929, 2778407815, 4185285206, 903635656, 3142804779,
+ 2012833205, 2101111980, 2979425330, 1058630609, 4088621903,
+ 714308067, 3862526333, 1756790430, 2753330688, 2933487385,
+ 1651734407, 3975966820, 542535930, 2244825981, 1231508451,
+ 3353891840, 188896414, 25648519, 3442302233, 1134713594,
+ 2399689316, 1445480648, 2592229462, 336416693, 3634843435,
+ 3529655858, 516441772, 2420588879, 1559052753, 698204909,
+ 3845636723, 1807271312, 2803025166, 2916600855, 1635634313,
+ 4025666410, 593021940, 4202223960, 919787974, 3093159461,
+ 1962401467, 2117261218, 2996361020, 1008193759, 4038971457,
+ 1428616134, 2576151384, 386135227, 3685348389, 3513580860,
+ 499580322, 2471098945, 1608776415, 2260985971, 1248454893,
+ 3303468814, 139259792, 42591881, 3458459159, 1085071860,
+ 2349261162, 3505103035, 474062885, 2463016902, 1583654744,
+ 1419882049, 2550902495, 377792828, 3660491170, 51297038,
+ 3483679632, 1093385331, 2374089965, 2269427188, 1273935210,
+ 3311514249, 164344343, 2890961296, 1627033870, 4000683757,
+ 585078387, 672833386, 3836780532, 1782552599, 2794821769,
+ 2142603813, 3005188795, 1032883544, 4047146438, 4227826911,
+ 928351297, 3118105506, 1970307900, 1396409818, 2677114180,
+ 287212199, 3719594553, 3614542624, 467372990, 2505346141,
+ 1509854403, 2162073199, 1282711281, 3271268626, 240228748,
+ 76845205, 3359543307, 1186043880, 2317064054, 796964081,
+ 3811226735, 1839575948, 2702160658, 2882189835, 1734392469,
+ 3924802934, 625327592, 4234522436, 818917338, 3191908409,
+ 1927981223, 2016387518, 3028656416, 973776579, 4137723485,
+ 2857232268, 1726474002, 3899187441, 616751215, 772270454,
+ 3803048424, 1814228491, 2693328533, 2041117753, 3036871847,
+ 999160644, 4146592730, 4259508931, 826864221, 3217552830,
+ 1936586016, 3606501031, 442291769, 2496909786, 1484378436,
+ 1388107869, 2652297411, 278519584, 3694387134, 85183762,
+ 3384397196, 1194773103, 2342308593, 2170143720, 1307820918,
+ 3279733909, 265733131, 2057717559, 3054258089, 948125770,
+ 4096344276, 4276898253, 843467091, 3167309488, 1885556270,
+ 2839764098, 1709792284, 3949353983, 667704161, 755585656,
+ 3785577190, 1865176325, 2743489947, 102594076, 3401021058,
+ 1144549729, 2291298815, 2186770662, 1325234296, 3228729243,
+ 215514885, 3589828009, 424832311, 2547870420, 1534552650,
+ 1370645331, 2635621325, 328688686, 3745342640, 2211456353,
+ 1333405183, 3254067740, 224338562, 127544219, 3408931589,
+ 1170156774, 2299866232, 1345666772, 2627681866, 303053225,
+ 3736746295, 3565105198, 416624816, 2522494803, 1525692365,
+ 4285207626, 868291796, 3176010551, 1910772649, 2065767088,
+ 3079346734, 956571085, 4121828691, 747507711, 3760459617,
+ 1856702594, 2717976604, 2831417605, 1684930971, 3940615800,
+ 642451174,
+ },
+ {
+ 0, 393942083, 787884166, 965557445, 1575768332,
+ 1251427663, 1931114890, 1684106697, 3151536664, 2896410203,
+ 2502855326, 2186649309, 3862229780, 4048545623, 3368213394,
+ 3753496529, 2898281073, 3149616690, 2184604407, 2504883892,
+ 4046197629, 3864463166, 3755621371, 3366006712, 387506281,
+ 6550570, 971950319, 781573292, 1257550181, 1569695014,
+ 1677892067, 1937345952, 2196865699, 2508887776, 2886183461,
+ 3145514598, 3743273903, 3362179052, 4058774313, 3868258154,
+ 958996667, 777139448, 400492605, 10755198, 1690661303,
+ 1941857780, 1244879153, 1565019506, 775012562, 961205393,
+ 13101140, 398261271, 1943900638, 1688634781, 1563146584,
+ 1246801179, 2515100362, 2190636681, 3139390028, 2892258831,
+ 3355784134, 3749586821, 3874691904, 4052225795, 3734110983,
+ 3387496260, 4033096577, 3877584834, 2206093835, 2483373640,
+ 2911402637, 3136515790, 1699389727, 1915860316, 1270647193,
+ 1556585946, 950464531, 803071056, 374397077, 19647702,
+ 1917993334, 1697207605, 1554278896, 1272937907, 800985210,
+ 952435769, 21510396, 372452543, 3381322606, 3740399405,
+ 3883715560, 4027047851, 2489758306, 2199758369, 3130039012,
+ 2917895847, 1550025124, 1259902439, 1922410786, 1710144865,
+ 26202280, 385139947, 796522542, 939715693, 3887801276,
+ 4039129087, 3377269562, 3728088953, 3126293168, 2905368307,
+ 2493602358, 2212122229, 4037264341, 3889747862, 3730172755,
+ 3375300368, 2907673305, 3124004506, 2209987167, 2495786524,
+ 1266377165, 1543533966, 1703758155, 1928748296, 379007169,
+ 32253058, 945887303, 790236164, 1716846671, 1898845196,
+ 1218652361, 1608006794, 1002000707, 750929152, 357530053,
+ 36990342, 3717046871, 3405166100, 4084959953, 3825245842,
+ 2153902939, 2535122712, 2929187805, 3119304606, 3398779454,
+ 3723384445, 3831720632, 4078468859, 2541294386, 2147616625,
+ 3113171892, 2935238647, 1900929062, 1714877541, 1606142112,
+ 1220599011, 748794154, 1004184937, 39295404, 355241455,
+ 3835986668, 4091516591, 3394415210, 3710500393, 3108557792,
+ 2922629027, 2545875814, 2160455461, 1601970420, 1208431799,
+ 1904871538, 1727077425, 43020792, 367748539, 744905086,
+ 991776061, 1214562461, 1595921630, 1720903707, 1911159896,
+ 361271697, 49513938, 998160663, 738569556, 4089209477,
+ 3838277318, 3712633347, 3392233024, 2924491657, 3106613194,
+ 2158369551, 2547846988, 3100050248, 2948339467, 2519804878,
+ 2169126797, 3844821572, 4065347079, 3420289730, 3701894785,
+ 52404560, 342144275, 770279894, 982687125, 1593045084,
+ 1233708063, 1879431386, 1736363161, 336019769, 58479994,
+ 988899775, 764050940, 1240141877, 1586496630, 1729968307,
+ 1885744368, 2950685473, 3097818978, 2166999975, 2522013668,
+ 4063474221, 3846743662, 3703937707, 3418263272, 976650731,
+ 760059304, 348170605, 62635310, 1742393575, 1889649828,
+ 1227683937, 1582820386, 2179867635, 2526361520, 2937588597,
+ 3093503798, 3691148031, 3413731004, 4076100217, 3851374138,
+ 2532754330, 2173556697, 3087067932, 2944139103, 3407516310,
+ 3697379029, 3857496592, 4070026835, 758014338, 978679233,
+ 64506116, 346250567, 1891774606, 1740186829, 1580472328,
+ 1229917259,
+ },
+ {
+ 0, 4022496062, 83218493, 3946298115, 166436986,
+ 3861498692, 220098631, 3806075769, 332873972, 4229245898,
+ 388141257, 4175494135, 440197262, 4127099824, 516501683,
+ 4044053389, 665747944, 3362581206, 593187285, 3432594155,
+ 776282514, 3246869164, 716239279, 3312622225, 880394524,
+ 3686509090, 814485793, 3746462239, 1033003366, 3528460888,
+ 963096923, 3601193573, 1331495888, 2694801646, 1269355501,
+ 2758457555, 1186374570, 2843003028, 1111716759, 2910918825,
+ 1552565028, 3007850522, 1484755737, 3082680359, 1432478558,
+ 3131279456, 1368666979, 3193329757, 1760789048, 2268195078,
+ 1812353541, 2210675003, 1628971586, 2396670332, 1710092927,
+ 2318375233, 2066006732, 2498144754, 2144408305, 2417195471,
+ 1926193846, 2634877320, 1983558283, 2583222709, 2662991776,
+ 1903717534, 2588923805, 1972223139, 2538711002, 2022952164,
+ 2477029351, 2087066841, 2372749140, 1655647338, 2308478825,
+ 1717238871, 2223433518, 1799654416, 2155034387, 1873894445,
+ 3105130056, 1456926070, 3185661557, 1378041163, 2969511474,
+ 1597852940, 3020617231, 1539874097, 2864957116, 1157737858,
+ 2922780289, 1106542015, 2737333958, 1290407416, 2816325371,
+ 1210047941, 3521578096, 1042640718, 3574781005, 986759027,
+ 3624707082, 936300340, 3707335735, 859512585, 3257943172,
+ 770846650, 3334837433, 688390023, 3420185854, 605654976,
+ 3475911875, 552361981, 4132013464, 428600998, 4072428965,
+ 494812827, 4288816610, 274747100, 4216845791, 345349857,
+ 3852387692, 173846098, 3781891409, 245988975, 3967116566,
+ 62328360, 3900749099, 121822741, 3859089665, 164061759,
+ 3807435068, 221426178, 4025395579, 2933317, 3944446278,
+ 81334904, 4124199413, 437265099, 4045904328, 518386422,
+ 4231653775, 335250097, 4174133682, 386814604, 3249244393,
+ 778691543, 3311294676, 714879978, 3359647891, 662848429,
+ 3434477742, 595039120, 3531393053, 1035903779, 3599308832,
+ 961245982, 3684132967, 877986649, 3747788890, 815846244,
+ 2841119441, 1184522735, 2913852140, 1114616274, 2696129195,
+ 1332855189, 2756082326, 1266946472, 3129952805, 1431118107,
+ 3195705880, 1371074854, 3009735263, 1554415969, 3079748194,
+ 1481855324, 2398522169, 1630855175, 2315475716, 1707159610,
+ 2266835779, 1759461501, 2213084030, 1814728768, 2636237773,
+ 1927520499, 2580814832, 1981182158, 2496293815, 2064121993,
+ 2420095882, 2147340468, 2025787041, 2541577631, 2085281436,
+ 2475210146, 1901375195, 2660681189, 1973518054, 2590184920,
+ 1801997909, 2225743211, 1872600680, 2153772374, 1652813359,
+ 2369881361, 1719025170, 2310296876, 1594986313, 2966676599,
+ 1541693300, 3022402634, 1459236659, 3107472397, 1376780046,
+ 3184366640, 1288097725, 2734990467, 1211309952, 2817619134,
+ 1160605639, 2867791097, 1104723962, 2920993988, 937561457,
+ 3626001999, 857201996, 3704993394, 1040821515, 3519792693,
+ 989625654, 3577615880, 607473029, 3421972155, 549494200,
+ 3473077894, 769584639, 3256649409, 690699714, 3337180924,
+ 273452185, 4287555495, 347692196, 4219156378, 430386403,
+ 4133832669, 491977950, 4069562336, 60542061, 3965298515,
+ 124656720, 3903616878, 175139863, 3853649705, 243645482,
+ 3779581716,
+ },
+ {
+ 0, 3247366080, 1483520449, 2581751297, 2967040898,
+ 1901571138, 3904227907, 691737987, 3133399365, 2068659845,
+ 3803142276, 589399876, 169513671, 3415493895, 1383475974,
+ 2482566342, 2935407819, 1870142219, 4137319690, 924099274,
+ 506443593, 3751897225, 1178799752, 2278412616, 339027342,
+ 3585866318, 1280941135, 2379694991, 2766951948, 1700956620,
+ 4236308429, 1024339981, 2258407383, 1192382487, 3740284438,
+ 528411094, 910556245, 4157285269, 1848198548, 2946996820,
+ 1012887186, 4258378066, 1681119059, 2780629139, 2357599504,
+ 1292419792, 3572147409, 358906641, 678054684, 3924071644,
+ 1879503581, 2978491677, 2561882270, 1497229150, 3235873119,
+ 22109855, 2460592729, 1395094937, 3401913240, 189516888,
+ 577821147, 3825075739, 2048679962, 3146956762, 3595049455,
+ 398902831, 2384764974, 1336573934, 1720805997, 2803873197,
+ 1056822188, 4285729900, 1821112490, 2902796138, 887570795,
+ 4117339819, 3696397096, 500978920, 2218668777, 1169222953,
+ 2025774372, 3106931428, 550659301, 3780950821, 3362238118,
+ 166293862, 2416645991, 1367722151, 3262987361, 66315169,
+ 2584839584, 1537170016, 1923370979, 3005911075, 717813282,
+ 3947244002, 1356109368, 2438613496, 146288633, 3375820857,
+ 3759007162, 562248314, 3093388411, 2045739963, 3927406461,
+ 731490493, 2994458300, 1945440636, 1523451135, 2604718911,
+ 44219710, 3274466046, 4263662323, 1068272947, 2790189874,
+ 1740649714, 1325080945, 2406874801, 379033776, 3608758128,
+ 1155642294, 2238671990, 479005303, 3708016055, 4097359924,
+ 901128180, 2891217397, 1843045941, 2011248031, 3060787807,
+ 797805662, 3993195422, 3342353949, 112630237, 2673147868,
+ 1591353372, 3441611994, 212601626, 2504944923, 1421914843,
+ 2113644376, 3161815192, 630660761, 3826893145, 3642224980,
+ 412692116, 2172340373, 1089836885, 1775141590, 2822790422,
+ 832715543, 4029474007, 1674842129, 2723860433, 1001957840,
+ 4197873168, 3540870035, 310623315, 2338445906, 1257178514,
+ 4051548744, 821257608, 2836464521, 1755307081, 1101318602,
+ 2150241802, 432566283, 3628511179, 1270766349, 2318435533,
+ 332587724, 3529260300, 4217841807, 988411727, 2735444302,
+ 1652903566, 1602977411, 2651169091, 132630338, 3328776322,
+ 4015131905, 786223809, 3074340032, 1991273216, 3846741958,
+ 616972294, 3173262855, 2091579847, 1435626564, 2485072772,
+ 234706309, 3430124101, 2712218736, 1613231024, 4190475697,
+ 944458353, 292577266, 3506339890, 1226630707, 2291284467,
+ 459984181, 3672380149, 1124496628, 2189994804, 2880683703,
+ 1782407543, 4091479926, 844224694, 257943739, 3469817723,
+ 1462980986, 2529005242, 3213269817, 2114471161, 3890881272,
+ 644152632, 3046902270, 1947391550, 3991973951, 746483711,
+ 88439420, 3301680572, 1563018173, 2628197501, 657826727,
+ 3871046759, 2136545894, 3201811878, 2548879397, 1449267173,
+ 3481299428, 235845156, 2650161890, 1551408418, 3315268387,
+ 68429027, 758067552, 3970035360, 1967360161, 3033356129,
+ 2311284588, 1213053100, 3517963949, 270598509, 958010606,
+ 4170500910, 1635167535, 2700636911, 855672361, 4069415401,
+ 1802256360, 2866995240, 2212099499, 1113008747, 3686091882,
+ 440112042,
+ },
+ {
+ 0, 2611301487, 3963330207, 2006897392, 50740095,
+ 2560849680, 4013794784, 1956178319, 101480190, 2645113489,
+ 3929532513, 1905435662, 84561281, 2662269422, 3912356638,
+ 1922342769, 202960380, 2545787283, 3760419683, 2072395532,
+ 253679235, 2495322860, 3810871324, 2021655667, 169122562,
+ 2444351341, 3861841309, 2106214898, 152215677, 2461527058,
+ 3844685538, 2123133581, 405920760, 2207553431, 4094313831,
+ 1873742088, 456646791, 2157096168, 4144791064, 1823027831,
+ 507358470, 2241388905, 4060492697, 1772322806, 490444409,
+ 2258557462, 4043311334, 1789215881, 338245124, 2408348267,
+ 4161972379, 1672996084, 388959611, 2357870868, 4212429796,
+ 1622269835, 304431354, 2306870421, 4263435877, 1706791434,
+ 287538053, 2324051946, 4246267162, 1723705717, 811841520,
+ 2881944479, 3696765295, 1207788800, 862293135, 2831204576,
+ 3747484176, 1157324415, 913293582, 2915732833, 3662962577,
+ 1106318334, 896137841, 2932651550, 3646055662, 1123494017,
+ 1014716940, 2816349795, 3493905555, 1273334012, 1065181555,
+ 2765630748, 3544645612, 1222882179, 980888818, 2714919069,
+ 3595350637, 1307180546, 963712909, 2731826146, 3578431762,
+ 1324336509, 676490248, 3019317351, 3295277719, 1607253752,
+ 726947703, 2968591128, 3345992168, 1556776327, 777919222,
+ 3053147801, 3261432937, 1505806342, 760750473, 3070062054,
+ 3244539670, 1522987897, 608862708, 3220163995, 3362856811,
+ 1406423812, 659339915, 3169449700, 3413582868, 1355966587,
+ 575076106, 3118709605, 3464325525, 1440228858, 557894773,
+ 3135602714, 3447411434, 1457397381, 1623683040, 4217512847,
+ 2365387135, 391757072, 1673614495, 4167309552, 2415577600,
+ 341804655, 1724586270, 4251866481, 2331019137, 290835438,
+ 1707942497, 4268256782, 2314648830, 307490961, 1826587164,
+ 4152020595, 2162433155, 457265388, 1876539747, 4101829900,
+ 2212636668, 407333779, 1792275682, 4051089549, 2263378557,
+ 491595282, 1775619997, 4067460082, 2246988034, 508239213,
+ 2029433880, 3813931127, 2496473735, 258500328, 2079362919,
+ 3763716872, 2546668024, 208559511, 2130363110, 3848244873,
+ 2462145657, 157552662, 2113730969, 3864638966, 2445764358,
+ 174205801, 1961777636, 4014675339, 2564147067, 57707284,
+ 2011718299, 3964481268, 2614361092, 7778411, 1927425818,
+ 3913769845, 2665066885, 92077546, 1910772837, 3930150922,
+ 2648673018, 108709525, 1352980496, 3405878399, 3164554895,
+ 658115296, 1403183983, 3355946752, 3214507504, 607924639,
+ 1453895406, 3440239233, 3130208369, 557218846, 1437504913,
+ 3456883198, 3113552654, 573589345, 1555838444, 3340335491,
+ 2961681267, 723707676, 1606028947, 3290383100, 3011612684,
+ 673504355, 1521500946, 3239382909, 3062619533, 758026722,
+ 1505130605, 3256038402, 3045975794, 774417053, 1217725416,
+ 3543158663, 2762906999, 1057739032, 1267939479, 3493229816,
+ 2812847624, 1007544935, 1318679830, 3577493881, 2728586121,
+ 956803046, 1302285929, 3594125830, 2711933174, 973184153,
+ 1150152212, 3743982203, 2830528651, 856898788, 1200346475,
+ 3694041348, 2880457716, 806684571, 1115789546, 3643069573,
+ 2931426933, 891243034, 1099408277, 3659722746, 2914794762,
+ 907637093,
+ },
+ {
+ 0, 3717650821, 1616688459, 3184159950, 3233376918,
+ 489665299, 2699419613, 2104690264, 1510200173, 2274691816,
+ 979330598, 3888758691, 2595928571, 1194090622, 4209380528,
+ 661706037, 3020400346, 1771143007, 3562738577, 164481556,
+ 1958661196, 2837976521, 350386439, 3379863682, 3993269687,
+ 865250354, 2388181244, 1406015865, 784146209, 4079732388,
+ 1323412074, 2474079215, 3011398645, 1860735600, 3542286014,
+ 246687547, 1942430051, 2924607718, 328963112, 3456978349,
+ 3917322392, 887832861, 2300653011, 1421341782, 700772878,
+ 4099025803, 1234716485, 2483986112, 125431087, 3673109674,
+ 1730500708, 3132326369, 3351283641, 441867836, 2812031730,
+ 2047535991, 1568292418, 2163009479, 1025936137, 3769651852,
+ 2646824148, 1079348561, 4255113631, 537475098, 3180171691,
+ 1612400686, 3721471200, 4717925, 2100624189, 2694980280,
+ 493375094, 3237910515, 3884860102, 974691139, 2278750093,
+ 1514417672, 657926224, 4204917205, 1198234907, 2600289438,
+ 160053105, 3558665972, 1775665722, 3024116671, 3375586791,
+ 346391650, 2842683564, 1962488105, 1401545756, 2384412057,
+ 869618007, 3997403346, 2469432970, 1319524111, 4083956673,
+ 788193860, 250862174, 3546612699, 1856990997, 3006903952,
+ 3461001416, 333211981, 2920678787, 1937824774, 1425017139,
+ 2305216694, 883735672, 3912918525, 2487837605, 1239398944,
+ 4095071982, 696455019, 3136584836, 1734518017, 3668494799,
+ 121507914, 2051872274, 2816200599, 437363545, 3347544796,
+ 3774328809, 1029797484, 2158697122, 1564328743, 542033279,
+ 4258798842, 1074950196, 2642717105, 2691310871, 2113731730,
+ 3224801372, 497043929, 1624461185, 3175454212, 9435850,
+ 3709412175, 4201248378, 671035391, 2587181873, 1201904308,
+ 986750188, 3880142185, 1519135143, 2266689570, 342721485,
+ 3388693064, 1949382278, 2846355203, 3570723163, 155332830,
+ 3028835344, 1763607957, 1315852448, 2482538789, 775087595,
+ 4087626862, 2396469814, 1396827059, 4002123645, 857560824,
+ 320106210, 3464673127, 1934154665, 2933785132, 3551331444,
+ 238804465, 3018961215, 1852270778, 1226292623, 2491507722,
+ 692783300, 4108177729, 2309936921, 1412959900, 3924976210,
+ 879016919, 2803091512, 2055541181, 3343875443, 450471158,
+ 1739236014, 3124525867, 133568485, 3663777376, 4245691221,
+ 545702608, 2639048222, 1088059291, 1034514883, 3762268230,
+ 1576387720, 2153979149, 501724348, 3228659001, 2109407735,
+ 2687359090, 3713981994, 13109167, 3171052385, 1620357860,
+ 1206151121, 2591211092, 666423962, 4197321503, 2271022407,
+ 1523307714, 3875649548, 982999433, 2850034278, 1953942499,
+ 3384583981, 338329256, 1767471344, 3033506165, 151375291,
+ 3566408766, 4091789579, 779425934, 2478797888, 1311354309,
+ 861580189, 4006375960, 1392910038, 2391852883, 2929327945,
+ 1930372812, 3469036034, 324244359, 1847629279, 3015068762,
+ 243015828, 3555391761, 4103744548, 688715169, 2496043375,
+ 1229996266, 874727090, 3920994103, 1417671673, 2313759356,
+ 446585235, 3339223062, 2059594968, 2807313757, 3660002053,
+ 129100416, 3128657486, 1743609803, 1084066558, 2634765179,
+ 549535669, 4250396208, 2149900392, 1571961325, 3765982499,
+ 1039043750,
+ },
+ {
+ 0, 2635063670, 3782132909, 2086741467, 430739227,
+ 2225303149, 4173482934, 1707977408, 861478454, 2924937024,
+ 3526875803, 1329085421, 720736557, 3086643291, 3415954816,
+ 1452586230, 1722956908, 4223524122, 2279405761, 450042295,
+ 2132718455, 3792785921, 2658170842, 58693292, 1441473114,
+ 3370435372, 3028674295, 696911745, 1279765825, 3511176247,
+ 2905172460, 807831706, 3445913816, 1349228974, 738901109,
+ 2969918723, 3569940419, 1237784245, 900084590, 2829701656,
+ 4265436910, 1664255896, 525574723, 2187084597, 3885099509,
+ 2057177219, 117386584, 2616249390, 2882946228, 920233410,
+ 1253605401, 3619119471, 2994391983, 796207833, 1393823490,
+ 3457937012, 2559531650, 92322804, 2044829231, 3840835417,
+ 2166609305, 472659183, 1615663412, 4249022530, 1102706673,
+ 3702920839, 2698457948, 1037619754, 1477802218, 3306854812,
+ 3111894087, 611605809, 1927342535, 4025419953, 2475568490,
+ 243387420, 1800169180, 4131620778, 2317525617, 388842247,
+ 655084445, 3120835307, 3328511792, 1533734470, 1051149446,
+ 2745738736, 3754524715, 1120297309, 340972971, 2304586973,
+ 4114354438, 1748234352, 234773168, 2431761350, 3968900637,
+ 1906278251, 2363330345, 299003487, 1840466820, 4038896370,
+ 2507210802, 142532932, 1948239007, 3910149609, 3213136159,
+ 579563625, 1592415666, 3286611140, 2787646980, 992477042,
+ 1195825833, 3662232543, 3933188933, 2002801203, 184645608,
+ 2517538462, 4089658462, 1858919720, 313391347, 2409765253,
+ 3644239219, 1144605701, 945318366, 2773977256, 3231326824,
+ 1570095902, 569697989, 3170568115, 2205413346, 511446676,
+ 1646078799, 4279421497, 2598330617, 131105167, 2075239508,
+ 3871229218, 2955604436, 757403810, 1363424633, 3427521551,
+ 2844163791, 881434553, 1223211618, 3588709140, 3854685070,
+ 2026779384, 78583587, 2577462869, 4235025557, 1633861091,
+ 486774840, 2148301134, 3600338360, 1268198606, 938871061,
+ 2868504675, 3476308643, 1379640277, 777684494, 3008718712,
+ 1310168890, 3541595724, 2943964055, 846639841, 1471879201,
+ 3400857943, 3067468940, 735723002, 2102298892, 3762382970,
+ 2619362721, 19901655, 1692534295, 4193118049, 2240594618,
+ 411247564, 681945942, 3047836192, 3385552891, 1422167693,
+ 822682701, 2886124859, 3496468704, 1298661782, 469546336,
+ 2264093718, 4203901389, 1738379451, 38812283, 2673859341,
+ 3812556502, 2117148576, 3268024339, 1606809957, 598006974,
+ 3198893512, 3680933640, 1181316734, 973624229, 2802299603,
+ 4052944421, 1822222163, 285065864, 2381456382, 3896478014,
+ 1966106696, 156323219, 2489232613, 2759337087, 964150537,
+ 1159127250, 3625517476, 3184831332, 551242258, 1555722185,
+ 3249901247, 2535537225, 170842943, 1984954084, 3946848146,
+ 2391651666, 327308324, 1877176831, 4075589769, 263086283,
+ 2460058045, 4005602406, 1942963472, 369291216, 2332888742,
+ 4151061373, 1784924683, 1022852861, 2717425547, 3717839440,
+ 1083595558, 626782694, 3092517008, 3291821387, 1497027645,
+ 1763466407, 4094934481, 2289211402, 360544636, 1890636732,
+ 3988730570, 2447251217, 215086695, 1514488465, 3343557607,
+ 3140191804, 639919946, 1139395978, 3739626748, 2726758695,
+ 1065936977,
+ },
+ {
+ 0, 3120290792, 2827399569, 293431929, 2323408227,
+ 864534155, 586863858, 2600537882, 3481914503, 1987188591,
+ 1729068310, 3740575486, 1173727716, 4228805132, 3983743093,
+ 1418249117, 1147313999, 4254680231, 3974377182, 1428157750,
+ 3458136620, 2011505092, 1721256893, 3747844181, 2347455432,
+ 839944224, 594403929, 2593536433, 26687147, 3094146371,
+ 2836498234, 283794642, 2294627998, 826205558, 541298447,
+ 2578994407, 45702141, 3141697557, 2856315500, 331624836,
+ 1196225049, 4273416689, 4023010184, 1446090848, 3442513786,
+ 1959480466, 1706436331, 3696098563, 3433538001, 1968994873,
+ 1679888448, 3722103720, 1188807858, 4280295258, 3999102243,
+ 1470541515, 53374294, 3134568126, 2879970503, 307431215,
+ 2303854645, 816436189, 567589284, 2553242188, 3405478781,
+ 1929420949, 1652411116, 3682996484, 1082596894, 4185703926,
+ 3892424591, 1375368295, 91404282, 3163122706, 2918450795,
+ 336584067, 2400113305, 922028401, 663249672, 2658384096,
+ 2392450098, 929185754, 639587747, 2682555979, 82149713,
+ 3172883129, 2892181696, 362343208, 1091578037, 4176212829,
+ 3918960932, 1349337804, 3412872662, 1922537022, 1676344391,
+ 3658557359, 1111377379, 4224032267, 3937989746, 1396912026,
+ 3359776896, 1908013928, 1623494929, 3644803833, 2377615716,
+ 877417100, 623982837, 2630542109, 130804743, 3190831087,
+ 2941083030, 381060734, 106748588, 3215393092, 2933549885,
+ 388083925, 2350956495, 903570471, 614862430, 2640172470,
+ 3386185259, 1882115523, 1632872378, 3634920530, 1135178568,
+ 4199721120, 3945775833, 1389631793, 1317531835, 4152109907,
+ 3858841898, 1610259138, 3304822232, 2097172016, 1820140617,
+ 3582394273, 2165193788, 955639764, 696815021, 2423477829,
+ 192043359, 2995356343, 2750736590, 437203750, 182808564,
+ 3005133852, 2724453989, 462947725, 2157513367, 962777471,
+ 673168134, 2447663342, 3312231283, 2090301595, 1844056802,
+ 3557935370, 1326499344, 4142603768, 3885397889, 1584245865,
+ 3326266917, 2142836173, 1858371508, 3611272284, 1279175494,
+ 4123357358, 3837270743, 1564721471, 164299426, 2955991370,
+ 2706223923, 414607579, 2209834945, 978107433, 724686416,
+ 2462715320, 2183156074, 1004243586, 715579643, 2472360723,
+ 140260361, 2980573153, 2698675608, 421617264, 1302961645,
+ 4099032581, 3845074044, 1557460884, 3352688782, 2116952934,
+ 1867729183, 3601371895, 2222754758, 1032278062, 754596439,
+ 2499928511, 234942117, 3086693709, 2793824052, 528319708,
+ 1274365761, 4061043881, 3816027856, 1518873912, 3246989858,
+ 2020800970, 1762628531, 3505670235, 3223196809, 2045103969,
+ 1754834200, 3512958704, 1247965674, 4086934018, 3806642299,
+ 1528765331, 261609486, 3060532198, 2802936223, 518697591,
+ 2246819181, 1007707781, 762121468, 2492913428, 213497176,
+ 3041029808, 2755593417, 499441441, 2261110843, 1061030867,
+ 776167850, 2545465922, 3274734047, 2060165687, 1807140942,
+ 3528266662, 1229724860, 4038575956, 3788156205, 1479636677,
+ 1222322711, 4045468159, 3764231046, 1504067694, 3265744756,
+ 2069664924, 1780612837, 3554288909, 2270357136, 1051278712,
+ 802445057, 2519698665, 221152243, 3033880603, 2779263586,
+ 475261322,
+ },
+ {
+ 0, 2926088593, 2275419491, 701019378, 3560000647,
+ 2052709654, 1402038756, 4261017717, 1930665807, 3715829470,
+ 4105419308, 1524313021, 2804077512, 155861593, 545453739,
+ 2397726522, 3861331614, 1213181711, 1636244477, 3488582252,
+ 840331801, 2625561480, 3048626042, 467584747, 2503254481,
+ 995897408, 311723186, 3170637091, 1090907478, 4016929991,
+ 3332753461, 1758288292, 390036349, 3109546732, 2426363422,
+ 1056427919, 3272488954, 1835443819, 1152258713, 3938878216,
+ 1680663602, 3393484195, 3817652561, 1306808512, 2954733749,
+ 510998820, 935169494, 2580880455, 4044899811, 1601229938,
+ 1991794816, 3637571857, 623446372, 2336332021, 2726898695,
+ 216120726, 2181814956, 744704829, 95158223, 2881711710,
+ 1446680107, 4166125498, 3516576584, 2146575065, 780072698,
+ 2148951915, 2849952665, 129384968, 4199529085, 1411853292,
+ 2112855838, 3548843663, 1567451573, 4077254692, 3670887638,
+ 1957027143, 2304517426, 657765539, 251396177, 2694091200,
+ 3361327204, 1714510325, 1341779207, 3784408214, 476611811,
+ 2986349938, 2613617024, 899690513, 3142211371, 354600634,
+ 1021997640, 2458051545, 1870338988, 3239283261, 3906682575,
+ 1186180958, 960597383, 2536053782, 3202459876, 277428597,
+ 3983589632, 1125666961, 1792074851, 3300423154, 1246892744,
+ 3829039961, 3455203243, 1671079482, 2657312335, 806080478,
+ 432241452, 3081497277, 3748049689, 1896751752, 1489409658,
+ 4138600427, 190316446, 2772397583, 2365053693, 580864876,
+ 2893360214, 35503559, 735381813, 2243795108, 2017747153,
+ 3593269568, 4293150130, 1368183843, 1560145396, 4069882981,
+ 3680356503, 1966430470, 2295112051, 648294626, 258769936,
+ 2701399425, 804156091, 2173100842, 2823706584, 103204425,
+ 4225711676, 1438101421, 2088704863, 3524758222, 3134903146,
+ 347226875, 1031468553, 2467456920, 1860935661, 3229814396,
+ 3914054286, 1193487135, 3385412645, 1738661300, 1315531078,
+ 3758225623, 502792354, 3012596019, 2589468097, 875607120,
+ 1271043721, 3853125400, 3429020650, 1644831355, 2683558414,
+ 832261023, 408158061, 3057348348, 953223622, 2528745559,
+ 3211865253, 286899508, 3974120769, 1116263632, 1799381026,
+ 3307794867, 2917509143, 59586950, 709201268, 2217549029,
+ 2043995280, 3619452161, 4269064691, 1344032866, 3740677976,
+ 1889445577, 1498812987, 4148069290, 180845535, 2762992206,
+ 2372361916, 588238637, 1921194766, 3706423967, 4112727661,
+ 1531686908, 2796705673, 148555288, 554857194, 2407195515,
+ 26248257, 2952271312, 2251333922, 676868275, 3584149702,
+ 2076793175, 1375858085, 4234771508, 2493785488, 986493953,
+ 319029491, 3178008930, 1083533591, 4009621638, 3342158964,
+ 1767759333, 3887577823, 1239362382, 1612160956, 3464433197,
+ 864482904, 2649647049, 3022443323, 441336490, 1706844275,
+ 3419730402, 3793503504, 1282724993, 2978819316, 535149925,
+ 908921239, 2554697734, 380632892, 3100077741, 2433735263,
+ 1063734222, 3265180603, 1828069930, 1161729752, 3948283721,
+ 2207997677, 770953084, 71007118, 2857626143, 1470763626,
+ 4190274555, 3490330377, 2120394392, 4035494306, 1591758899,
+ 1999168705, 3644880208, 616140069, 2328960180, 2736367686,
+ 225524183,
+ },
};
// ---------------- Private Initializer Prototypes
@@ -5189,9 +5832,10 @@
// ---------------- Initializer Implementations
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
-wuffs_crc32__ieee_hasher__check_wuffs_version(wuffs_crc32__ieee_hasher* self,
- size_t sizeof_star_self,
- uint64_t wuffs_version) {
+wuffs_crc32__ieee_hasher__initialize(wuffs_crc32__ieee_hasher* self,
+ size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags) {
if (!self) {
return wuffs_base__error__bad_receiver;
}
@@ -5202,16 +5846,39 @@
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
return wuffs_base__error__bad_wuffs_version;
}
- if (self->private_impl.magic != 0) {
- return wuffs_base__error__check_wuffs_version_not_applicable;
+
+ if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
+// The whole point of this if-check is to detect an uninitialized *self.
+// We disable the warning on GCC. Clang-5.0 does not have this warning.
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+#endif
+ if (self->private_impl.magic != 0) {
+ return wuffs_base__error__initialize_falsely_claimed_already_zeroed;
+ }
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
+ } else {
+ void* p = &(self->private_impl);
+ size_t n = sizeof(self->private_impl);
+ if ((initialize_flags &
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
+ p = self;
+ n = sizeof(*self);
+ initialize_flags |= WUFFS_INITIALIZE__ALREADY_ZEROED;
+ }
+ memset(p, 0, n);
}
+
self->private_impl.magic = WUFFS_BASE__MAGIC;
return NULL;
}
size_t //
sizeof__wuffs_crc32__ieee_hasher() {
- return sizeof((wuffs_crc32__ieee_hasher){});
+ return sizeof(wuffs_crc32__ieee_hasher);
}
// ---------------- Function Implementations
@@ -5229,7 +5896,7 @@
}
uint32_t v_s = 0;
- wuffs_base__slice_u8 v_p = {};
+ wuffs_base__slice_u8 v_p = {0};
v_s = (4294967295 ^ self->private_impl.f_state);
{
@@ -5324,82 +5991,101 @@
// ---------------- Status Codes Implementations
const char* wuffs_deflate__error__bad_huffman_code_over_subscribed =
- "?deflate: bad Huffman code (over-subscribed)";
+ "#deflate: bad Huffman code (over-subscribed)";
const char* wuffs_deflate__error__bad_huffman_code_under_subscribed =
- "?deflate: bad Huffman code (under-subscribed)";
+ "#deflate: bad Huffman code (under-subscribed)";
const char* wuffs_deflate__error__bad_huffman_code_length_count =
- "?deflate: bad Huffman code length count";
+ "#deflate: bad Huffman code length count";
const char* wuffs_deflate__error__bad_huffman_code_length_repetition =
- "?deflate: bad Huffman code length repetition";
+ "#deflate: bad Huffman code length repetition";
const char* wuffs_deflate__error__bad_huffman_code =
- "?deflate: bad Huffman code";
+ "#deflate: bad Huffman code";
const char* wuffs_deflate__error__bad_huffman_minimum_code_length =
- "?deflate: bad Huffman minimum code length";
-const char* wuffs_deflate__error__bad_block = "?deflate: bad block";
-const char* wuffs_deflate__error__bad_distance = "?deflate: bad distance";
+ "#deflate: bad Huffman minimum code length";
+const char* wuffs_deflate__error__bad_block = "#deflate: bad block";
+const char* wuffs_deflate__error__bad_distance = "#deflate: bad distance";
const char* wuffs_deflate__error__bad_distance_code_count =
- "?deflate: bad distance code count";
+ "#deflate: bad distance code count";
const char* wuffs_deflate__error__bad_literal_length_code_count =
- "?deflate: bad literal/length code count";
+ "#deflate: bad literal/length code count";
const char* wuffs_deflate__error__inconsistent_stored_block_length =
- "?deflate: inconsistent stored block length";
+ "#deflate: inconsistent stored block length";
const char* wuffs_deflate__error__missing_end_of_block_code =
- "?deflate: missing end-of-block code";
+ "#deflate: missing end-of-block code";
const char* wuffs_deflate__error__no_huffman_codes =
- "?deflate: no Huffman codes";
+ "#deflate: no Huffman codes";
const char*
wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state =
- "?deflate: internal error: inconsistent Huffman decoder state";
+ "#deflate: internal error: inconsistent Huffman decoder state";
const char* wuffs_deflate__error__internal_error_inconsistent_i_o =
- "?deflate: internal error: inconsistent I/O";
+ "#deflate: internal error: inconsistent I/O";
const char* wuffs_deflate__error__internal_error_inconsistent_distance =
- "?deflate: internal error: inconsistent distance";
+ "#deflate: internal error: inconsistent distance";
const char* wuffs_deflate__error__internal_error_inconsistent_n_bits =
- "?deflate: internal error: inconsistent n_bits";
+ "#deflate: internal error: inconsistent n_bits";
// ---------------- Private Consts
-static const uint8_t wuffs_deflate__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 //
+ wuffs_deflate__code_order[19] //
+ WUFFS_BASE__POTENTIALLY_UNUSED = {
+ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15,
};
-static const uint8_t wuffs_deflate__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,
- 12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252,
- 2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242,
- 10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250,
- 6, 134, 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246,
- 14, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190, 126, 254,
- 1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209, 49, 177, 113, 241,
- 9, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249,
- 5, 133, 69, 197, 37, 165, 101, 229, 21, 149, 85, 213, 53, 181, 117, 245,
- 13, 141, 77, 205, 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253,
- 3, 131, 67, 195, 35, 163, 99, 227, 19, 147, 83, 211, 51, 179, 115, 243,
- 11, 139, 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251,
- 7, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247,
- 15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255,
+static const uint8_t //
+ wuffs_deflate__reverse8[256] //
+ WUFFS_BASE__POTENTIALLY_UNUSED = {
+ 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, 12, 140, 76, 204, 44, 172, 108, 236,
+ 28, 156, 92, 220, 60, 188, 124, 252, 2, 130, 66, 194, 34, 162,
+ 98, 226, 18, 146, 82, 210, 50, 178, 114, 242, 10, 138, 74, 202,
+ 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250, 6, 134,
+ 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246,
+ 14, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190,
+ 126, 254, 1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209,
+ 49, 177, 113, 241, 9, 137, 73, 201, 41, 169, 105, 233, 25, 153,
+ 89, 217, 57, 185, 121, 249, 5, 133, 69, 197, 37, 165, 101, 229,
+ 21, 149, 85, 213, 53, 181, 117, 245, 13, 141, 77, 205, 45, 173,
+ 109, 237, 29, 157, 93, 221, 61, 189, 125, 253, 3, 131, 67, 195,
+ 35, 163, 99, 227, 19, 147, 83, 211, 51, 179, 115, 243, 11, 139,
+ 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251,
+ 7, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183,
+ 119, 247, 15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223,
+ 63, 191, 127, 255,
};
-static const uint32_t wuffs_deflate__lcode_magic_numbers[32] = {
- 1073741824, 1073742080, 1073742336, 1073742592, 1073742848, 1073743104,
- 1073743360, 1073743616, 1073743888, 1073744400, 1073744912, 1073745424,
- 1073745952, 1073746976, 1073748000, 1073749024, 1073750064, 1073752112,
- 1073754160, 1073756208, 1073758272, 1073762368, 1073766464, 1073770560,
- 1073774672, 1073782864, 1073791056, 1073799248, 1073807104, 134217728,
- 134217728, 134217728,
+static const uint32_t //
+ wuffs_deflate__lcode_magic_numbers[32] //
+ WUFFS_BASE__POTENTIALLY_UNUSED = {
+ 1073741824, 1073742080, 1073742336, 1073742592, 1073742848, 1073743104,
+ 1073743360, 1073743616, 1073743888, 1073744400, 1073744912, 1073745424,
+ 1073745952, 1073746976, 1073748000, 1073749024, 1073750064, 1073752112,
+ 1073754160, 1073756208, 1073758272, 1073762368, 1073766464, 1073770560,
+ 1073774672, 1073782864, 1073791056, 1073799248, 1073807104, 134217728,
+ 134217728, 134217728,
};
-static const uint32_t wuffs_deflate__dcode_magic_numbers[32] = {
- 1073741824, 1073742080, 1073742336, 1073742592, 1073742864, 1073743376,
- 1073743904, 1073744928, 1073745968, 1073748016, 1073750080, 1073754176,
- 1073758288, 1073766480, 1073774688, 1073791072, 1073807472, 1073840240,
- 1073873024, 1073938560, 1074004112, 1074135184, 1074266272, 1074528416,
- 1074790576, 1075314864, 1075839168, 1076887744, 1077936336, 1080033488,
- 134217728, 134217728,
+static const uint32_t //
+ wuffs_deflate__dcode_magic_numbers[32] //
+ WUFFS_BASE__POTENTIALLY_UNUSED = {
+ 1073741824, 1073742080, 1073742336, 1073742592, 1073742864, 1073743376,
+ 1073743904, 1073744928, 1073745968, 1073748016, 1073750080, 1073754176,
+ 1073758288, 1073766480, 1073774688, 1073791072, 1073807472, 1073840240,
+ 1073873024, 1073938560, 1074004112, 1074135184, 1074266272, 1074528416,
+ 1074790576, 1075314864, 1075839168, 1076887744, 1077936336, 1080033488,
+ 134217728, 134217728,
};
+static const uint32_t //
+ wuffs_deflate__huffs_table_size //
+ WUFFS_BASE__POTENTIALLY_UNUSED = 1024;
+
+static const uint32_t //
+ wuffs_deflate__huffs_table_mask //
+ WUFFS_BASE__POTENTIALLY_UNUSED = 1023;
+
// ---------------- Private Initializer Prototypes
// ---------------- Private Function Prototypes
@@ -5441,9 +6127,10 @@
// ---------------- Initializer Implementations
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
-wuffs_deflate__decoder__check_wuffs_version(wuffs_deflate__decoder* self,
- size_t sizeof_star_self,
- uint64_t wuffs_version) {
+wuffs_deflate__decoder__initialize(wuffs_deflate__decoder* self,
+ size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags) {
if (!self) {
return wuffs_base__error__bad_receiver;
}
@@ -5454,46 +6141,89 @@
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
return wuffs_base__error__bad_wuffs_version;
}
- if (self->private_impl.magic != 0) {
- return wuffs_base__error__check_wuffs_version_not_applicable;
+
+ if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
+// The whole point of this if-check is to detect an uninitialized *self.
+// We disable the warning on GCC. Clang-5.0 does not have this warning.
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+#endif
+ if (self->private_impl.magic != 0) {
+ return wuffs_base__error__initialize_falsely_claimed_already_zeroed;
+ }
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
+ } else {
+ void* p = &(self->private_impl);
+ size_t n = sizeof(self->private_impl);
+ if ((initialize_flags &
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
+ p = self;
+ n = sizeof(*self);
+ initialize_flags |= WUFFS_INITIALIZE__ALREADY_ZEROED;
+ }
+ memset(p, 0, n);
}
+
self->private_impl.magic = WUFFS_BASE__MAGIC;
return NULL;
}
size_t //
sizeof__wuffs_deflate__decoder() {
- return sizeof((wuffs_deflate__decoder){});
+ return sizeof(wuffs_deflate__decoder);
}
// ---------------- Function Implementations
+// -------- func deflate.decoder.workbuf_len
+
+WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 //
+wuffs_deflate__decoder__workbuf_len(const wuffs_deflate__decoder* self) {
+ if (!self) {
+ return wuffs_base__utility__make_range_ii_u64(0, 0);
+ }
+ if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
+ (self->private_impl.magic != WUFFS_BASE__DISABLED)) {
+ return wuffs_base__utility__make_range_ii_u64(0, 0);
+ }
+
+ return wuffs_base__utility__make_range_ii_u64(1, 1);
+}
+
// -------- func deflate.decoder.decode_io_writer
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_deflate__decoder__decode_io_writer(wuffs_deflate__decoder* self,
wuffs_base__io_writer a_dst,
- wuffs_base__io_reader a_src) {
+ wuffs_base__io_reader a_src,
+ wuffs_base__slice_u8 a_workbuf) {
if (!self) {
return wuffs_base__error__bad_receiver;
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return (self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
- : wuffs_base__error__check_wuffs_version_missing;
+ : wuffs_base__error__initialize_not_called;
}
+ if ((self->private_impl.active_coroutine != 0) &&
+ (self->private_impl.active_coroutine != 1)) {
+ self->private_impl.magic = WUFFS_BASE__DISABLED;
+ return wuffs_base__error__interleaved_coroutine_calls;
+ }
+ self->private_impl.active_coroutine = 0;
wuffs_base__status status = NULL;
wuffs_base__status v_status = NULL;
- wuffs_base__slice_u8 v_written = {};
+ wuffs_base__slice_u8 v_written = {0};
uint64_t v_n_copied = 0;
uint32_t v_already_full = 0;
uint8_t* iop_a_dst = NULL;
- uint8_t* io0_a_dst = NULL;
- uint8_t* io1_a_dst = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_dst);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_dst);
+ uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst.private_impl.buf) {
iop_a_dst =
a_dst.private_impl.buf->data.ptr + a_dst.private_impl.buf->meta.wi;
@@ -5509,8 +6239,7 @@
io1_a_dst = a_dst.private_impl.limit;
}
- uint32_t coro_susp_point =
- self->private_impl.c_decode_io_writer[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_io_writer[0];
if (coro_susp_point) {
}
switch (coro_susp_point) {
@@ -5521,7 +6250,7 @@
{
if (a_dst.private_impl.buf) {
a_dst.private_impl.buf->meta.wi =
- iop_a_dst - a_dst.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_dst - a_dst.private_impl.buf->data.ptr));
}
wuffs_base__status t_0 =
wuffs_deflate__decoder__decode_blocks(self, a_dst, a_src);
@@ -5541,35 +6270,25 @@
}
goto ok;
}
- v_written = ((wuffs_base__slice_u8){
- .ptr = a_dst.private_impl.mark,
- .len = (size_t)(iop_a_dst - a_dst.private_impl.mark),
- });
+ v_written = wuffs_base__make_slice_u8(
+ a_dst.private_impl.mark,
+ (size_t)(iop_a_dst - a_dst.private_impl.mark));
if (((uint64_t)(v_written.len)) >= 32768) {
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,
- }),
+ wuffs_base__make_slice_u8(self->private_data.f_history, 32768),
v_written);
self->private_impl.f_history_index = 32768;
} else {
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,
- }),
+ wuffs_base__make_slice_u8(self->private_data.f_history, 32768),
(self->private_impl.f_history_index & 32767)),
v_written);
if (v_n_copied < ((uint64_t)(v_written.len))) {
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,
- }),
+ wuffs_base__make_slice_u8(self->private_data.f_history, 32768),
v_written);
self->private_impl.f_history_index =
(((uint32_t)((v_n_copied & 32767))) + 32768);
@@ -5589,19 +6308,20 @@
goto ok;
ok:
- self->private_impl.c_decode_io_writer[0].coro_susp_point = 0;
+ self->private_impl.p_decode_io_writer[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_io_writer[0].coro_susp_point = coro_susp_point;
+ self->private_impl.p_decode_io_writer[0] = coro_susp_point;
+ self->private_impl.active_coroutine = 1;
goto exit;
exit:
if (a_dst.private_impl.buf) {
a_dst.private_impl.buf->meta.wi =
- iop_a_dst - a_dst.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_dst - a_dst.private_impl.buf->data.ptr));
}
if (wuffs_base__status__is_error(status)) {
@@ -5624,10 +6344,8 @@
wuffs_base__status v_status = NULL;
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -5640,10 +6358,9 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point =
- self->private_impl.c_decode_blocks[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_blocks[0];
if (coro_susp_point) {
- v_final = self->private_impl.c_decode_blocks[0].v_final;
+ v_final = self->private_data.s_decode_blocks[0].v_final;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -5670,7 +6387,7 @@
if (v_type == 0) {
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
status =
@@ -5698,7 +6415,7 @@
} else if (v_type == 2) {
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
status = wuffs_deflate__decoder__init_dynamic_huffman(self, a_src);
@@ -5717,7 +6434,7 @@
while (true) {
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
v_status =
wuffs_deflate__decoder__decode_huffman_fast(self, a_dst, a_src);
@@ -5734,7 +6451,7 @@
}
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
status =
@@ -5754,20 +6471,20 @@
goto ok;
ok:
- self->private_impl.c_decode_blocks[0].coro_susp_point = 0;
+ self->private_impl.p_decode_blocks[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_blocks[0].coro_susp_point = coro_susp_point;
- self->private_impl.c_decode_blocks[0].v_final = v_final;
+ self->private_impl.p_decode_blocks[0] = coro_susp_point;
+ self->private_data.s_decode_blocks[0].v_final = v_final;
goto exit;
exit:
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -5785,10 +6502,8 @@
uint32_t v_n_copied = 0;
uint8_t* iop_a_dst = NULL;
- uint8_t* io0_a_dst = NULL;
- uint8_t* io1_a_dst = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_dst);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_dst);
+ uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst.private_impl.buf) {
iop_a_dst =
a_dst.private_impl.buf->data.ptr + a_dst.private_impl.buf->meta.wi;
@@ -5804,10 +6519,8 @@
io1_a_dst = a_dst.private_impl.limit;
}
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -5820,16 +6533,16 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point =
- self->private_impl.c_decode_uncompressed[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_uncompressed[0];
if (coro_susp_point) {
- v_length = self->private_impl.c_decode_uncompressed[0].v_length;
+ v_length = self->private_data.s_decode_uncompressed[0].v_length;
}
switch (coro_susp_point) {
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)) {
+ ((self->private_impl.f_bits >> (self->private_impl.f_n_bits & 7)) !=
+ 0)) {
status = wuffs_deflate__error__internal_error_inconsistent_n_bits;
goto exit;
}
@@ -5842,7 +6555,7 @@
t_0 = wuffs_base__load_u32le(iop_a_src);
iop_a_src += 4;
} else {
- self->private_impl.c_decode_uncompressed[0].scratch = 0;
+ self->private_data.s_decode_uncompressed[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
@@ -5850,13 +6563,13 @@
goto suspend;
}
uint64_t* scratch =
- &self->private_impl.c_decode_uncompressed[0].scratch;
- uint32_t num_bits_0 = *scratch >> 56;
+ &self->private_data.s_decode_uncompressed[0].scratch;
+ uint32_t num_bits_0 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_0;
if (num_bits_0 == 24) {
- t_0 = *scratch;
+ t_0 = ((uint32_t)(*scratch));
break;
}
num_bits_0 += 8;
@@ -5889,24 +6602,24 @@
goto ok;
ok:
- self->private_impl.c_decode_uncompressed[0].coro_susp_point = 0;
+ self->private_impl.p_decode_uncompressed[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_uncompressed[0].coro_susp_point = coro_susp_point;
- self->private_impl.c_decode_uncompressed[0].v_length = v_length;
+ self->private_impl.p_decode_uncompressed[0] = coro_susp_point;
+ self->private_data.s_decode_uncompressed[0].v_length = v_length;
goto exit;
exit:
if (a_dst.private_impl.buf) {
a_dst.private_impl.buf->meta.wi =
- iop_a_dst - a_dst.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_dst - a_dst.private_impl.buf->data.ptr));
}
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -5920,23 +6633,23 @@
wuffs_base__status v_status = NULL;
while (v_i < 144) {
- self->private_impl.f_code_lengths[v_i] = 8;
+ self->private_data.f_code_lengths[v_i] = 8;
v_i += 1;
}
while (v_i < 256) {
- self->private_impl.f_code_lengths[v_i] = 9;
+ self->private_data.f_code_lengths[v_i] = 9;
v_i += 1;
}
while (v_i < 280) {
- self->private_impl.f_code_lengths[v_i] = 7;
+ self->private_data.f_code_lengths[v_i] = 7;
v_i += 1;
}
while (v_i < 288) {
- self->private_impl.f_code_lengths[v_i] = 8;
+ self->private_data.f_code_lengths[v_i] = 8;
v_i += 1;
}
while (v_i < 320) {
- self->private_impl.f_code_lengths[v_i] = 5;
+ self->private_data.f_code_lengths[v_i] = 5;
v_i += 1;
}
v_status = wuffs_deflate__decoder__init_huff(self, 0, 0, 288, 257);
@@ -5976,10 +6689,8 @@
uint32_t v_b3 = 0;
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -5992,21 +6703,20 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point =
- self->private_impl.c_init_dynamic_huffman[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_init_dynamic_huffman[0];
if (coro_susp_point) {
- v_bits = self->private_impl.c_init_dynamic_huffman[0].v_bits;
- v_n_bits = self->private_impl.c_init_dynamic_huffman[0].v_n_bits;
- v_n_lit = self->private_impl.c_init_dynamic_huffman[0].v_n_lit;
- v_n_dist = self->private_impl.c_init_dynamic_huffman[0].v_n_dist;
- v_n_clen = self->private_impl.c_init_dynamic_huffman[0].v_n_clen;
- v_i = self->private_impl.c_init_dynamic_huffman[0].v_i;
- v_mask = self->private_impl.c_init_dynamic_huffman[0].v_mask;
- v_table_entry = self->private_impl.c_init_dynamic_huffman[0].v_table_entry;
+ v_bits = self->private_data.s_init_dynamic_huffman[0].v_bits;
+ v_n_bits = self->private_data.s_init_dynamic_huffman[0].v_n_bits;
+ v_n_lit = self->private_data.s_init_dynamic_huffman[0].v_n_lit;
+ v_n_dist = self->private_data.s_init_dynamic_huffman[0].v_n_dist;
+ v_n_clen = self->private_data.s_init_dynamic_huffman[0].v_n_clen;
+ v_i = self->private_data.s_init_dynamic_huffman[0].v_i;
+ v_mask = self->private_data.s_init_dynamic_huffman[0].v_mask;
+ v_table_entry = self->private_data.s_init_dynamic_huffman[0].v_table_entry;
v_n_extra_bits =
- self->private_impl.c_init_dynamic_huffman[0].v_n_extra_bits;
- v_rep_symbol = self->private_impl.c_init_dynamic_huffman[0].v_rep_symbol;
- v_rep_count = self->private_impl.c_init_dynamic_huffman[0].v_rep_count;
+ self->private_data.s_init_dynamic_huffman[0].v_n_extra_bits;
+ v_rep_symbol = self->private_data.s_init_dynamic_huffman[0].v_rep_symbol;
+ v_rep_count = self->private_data.s_init_dynamic_huffman[0].v_rep_count;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -6056,14 +6766,14 @@
v_bits |= (v_b1 << v_n_bits);
v_n_bits += 8;
}
- self->private_impl.f_code_lengths[wuffs_deflate__code_order[v_i]] =
+ self->private_data.f_code_lengths[wuffs_deflate__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[wuffs_deflate__code_order[v_i]] = 0;
+ self->private_data.f_code_lengths[wuffs_deflate__code_order[v_i]] = 0;
v_i += 1;
}
v_status = wuffs_deflate__decoder__init_huff(self, 0, 0, 19, 4095);
@@ -6076,7 +6786,7 @@
label_0_continue:;
while (v_i < (v_n_lit + v_n_dist)) {
while (true) {
- v_table_entry = self->private_impl.f_huffs[0][(v_bits & v_mask)];
+ v_table_entry = self->private_data.f_huffs[0][(v_bits & v_mask)];
v_table_entry_n_bits = (v_table_entry & 15);
if (v_n_bits >= v_table_entry_n_bits) {
v_bits >>= v_table_entry_n_bits;
@@ -6103,7 +6813,7 @@
}
v_table_entry = ((v_table_entry >> 8) & 255);
if (v_table_entry < 16) {
- self->private_impl.f_code_lengths[v_i] = ((uint8_t)(v_table_entry));
+ self->private_data.f_code_lengths[v_i] = ((uint8_t)(v_table_entry));
v_i += 1;
goto label_0_continue;
}
@@ -6116,7 +6826,7 @@
status = wuffs_deflate__error__bad_huffman_code_length_repetition;
goto exit;
}
- v_rep_symbol = self->private_impl.f_code_lengths[(v_i - 1)];
+ v_rep_symbol = (self->private_data.f_code_lengths[(v_i - 1)] & 15);
v_rep_count = 3;
} else if (v_table_entry == 17) {
v_n_extra_bits = 3;
@@ -6152,7 +6862,7 @@
status = wuffs_deflate__error__bad_huffman_code_length_count;
goto exit;
}
- self->private_impl.f_code_lengths[v_i] = v_rep_symbol;
+ self->private_data.f_code_lengths[v_i] = v_rep_symbol;
v_i += 1;
v_rep_count -= 1;
}
@@ -6161,7 +6871,7 @@
status = wuffs_deflate__error__bad_huffman_code_length_count;
goto exit;
}
- if (self->private_impl.f_code_lengths[256] == 0) {
+ if (self->private_data.f_code_lengths[256] == 0) {
status = wuffs_deflate__error__missing_end_of_block_code;
goto exit;
}
@@ -6181,31 +6891,30 @@
goto ok;
ok:
- self->private_impl.c_init_dynamic_huffman[0].coro_susp_point = 0;
+ self->private_impl.p_init_dynamic_huffman[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_init_dynamic_huffman[0].coro_susp_point =
- coro_susp_point;
- self->private_impl.c_init_dynamic_huffman[0].v_bits = v_bits;
- self->private_impl.c_init_dynamic_huffman[0].v_n_bits = v_n_bits;
- self->private_impl.c_init_dynamic_huffman[0].v_n_lit = v_n_lit;
- self->private_impl.c_init_dynamic_huffman[0].v_n_dist = v_n_dist;
- self->private_impl.c_init_dynamic_huffman[0].v_n_clen = v_n_clen;
- self->private_impl.c_init_dynamic_huffman[0].v_i = v_i;
- self->private_impl.c_init_dynamic_huffman[0].v_mask = v_mask;
- self->private_impl.c_init_dynamic_huffman[0].v_table_entry = v_table_entry;
- self->private_impl.c_init_dynamic_huffman[0].v_n_extra_bits = v_n_extra_bits;
- self->private_impl.c_init_dynamic_huffman[0].v_rep_symbol = v_rep_symbol;
- self->private_impl.c_init_dynamic_huffman[0].v_rep_count = v_rep_count;
+ self->private_impl.p_init_dynamic_huffman[0] = coro_susp_point;
+ self->private_data.s_init_dynamic_huffman[0].v_bits = v_bits;
+ self->private_data.s_init_dynamic_huffman[0].v_n_bits = v_n_bits;
+ self->private_data.s_init_dynamic_huffman[0].v_n_lit = v_n_lit;
+ self->private_data.s_init_dynamic_huffman[0].v_n_dist = v_n_dist;
+ self->private_data.s_init_dynamic_huffman[0].v_n_clen = v_n_clen;
+ self->private_data.s_init_dynamic_huffman[0].v_i = v_i;
+ self->private_data.s_init_dynamic_huffman[0].v_mask = v_mask;
+ self->private_data.s_init_dynamic_huffman[0].v_table_entry = v_table_entry;
+ self->private_data.s_init_dynamic_huffman[0].v_n_extra_bits = v_n_extra_bits;
+ self->private_data.s_init_dynamic_huffman[0].v_rep_symbol = v_rep_symbol;
+ self->private_data.s_init_dynamic_huffman[0].v_rep_count = v_rep_count;
goto exit;
exit:
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -6219,13 +6928,13 @@
uint32_t a_n_codes0,
uint32_t a_n_codes1,
uint32_t a_base_symbol) {
- uint16_t v_counts[16] = {};
+ uint16_t v_counts[16] = {0};
uint32_t v_i = 0;
uint32_t v_remaining = 0;
- uint16_t v_offsets[16] = {};
+ uint16_t v_offsets[16] = {0};
uint32_t v_n_symbols = 0;
uint32_t v_count = 0;
- uint16_t v_symbols[320] = {};
+ uint16_t v_symbols[320] = {0};
uint32_t v_min_cl = 0;
uint32_t v_max_cl = 0;
uint32_t v_initial_high_bits = 0;
@@ -6246,10 +6955,17 @@
v_i = a_n_codes0;
while (v_i < a_n_codes1) {
- if (v_counts[self->private_impl.f_code_lengths[v_i]] >= 320) {
+ if (v_counts[(self->private_data.f_code_lengths[v_i] & 15)] >= 320) {
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
}
- v_counts[self->private_impl.f_code_lengths[v_i]] += 1;
+#if defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wconversion"
+#endif
+ v_counts[(self->private_data.f_code_lengths[v_i] & 15)] += 1;
+#if defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
v_i += 1;
}
if ((((uint32_t)(v_counts[0])) + a_n_codes0) == a_n_codes1) {
@@ -6289,13 +7005,20 @@
if (v_i < a_n_codes0) {
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
}
- if (self->private_impl.f_code_lengths[v_i] != 0) {
- if (v_offsets[self->private_impl.f_code_lengths[v_i]] >= 320) {
+ if (self->private_data.f_code_lengths[v_i] != 0) {
+ if (v_offsets[(self->private_data.f_code_lengths[v_i] & 15)] >= 320) {
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
}
- v_symbols[v_offsets[self->private_impl.f_code_lengths[v_i]]] =
+ v_symbols[v_offsets[(self->private_data.f_code_lengths[v_i] & 15)]] =
((uint16_t)((v_i - a_n_codes0)));
- v_offsets[self->private_impl.f_code_lengths[v_i]] += 1;
+#if defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wconversion"
+#endif
+ v_offsets[(self->private_data.f_code_lengths[v_i] & 15)] += 1;
+#if defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
}
v_i += 1;
}
@@ -6338,8 +7061,9 @@
if (v_max_cl < 9) {
v_initial_high_bits = (((uint32_t)(1)) << v_max_cl);
}
- v_prev_cl = ((uint32_t)(self->private_impl.f_code_lengths[(
- a_n_codes0 + ((uint32_t)(v_symbols[0])))]));
+ v_prev_cl = ((uint32_t)((self->private_data.f_code_lengths[(
+ a_n_codes0 + ((uint32_t)(v_symbols[0])))] &
+ 15)));
v_prev_redirect_key = 4294967295;
v_top = 0;
v_next_top = 512;
@@ -6350,8 +7074,9 @@
if ((a_n_codes0 + ((uint32_t)(v_symbols[v_i]))) >= 320) {
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
}
- v_cl = ((uint32_t)(self->private_impl.f_code_lengths[(
- a_n_codes0 + ((uint32_t)(v_symbols[v_i])))]));
+ v_cl = ((uint32_t)((self->private_data.f_code_lengths[(
+ a_n_codes0 + ((uint32_t)(v_symbols[v_i])))] &
+ 15)));
if (v_cl > v_prev_cl) {
v_code <<= (v_cl - v_prev_cl);
if (v_code >= 32768) {
@@ -6386,21 +7111,28 @@
v_j -= 9;
v_initial_high_bits = (((uint32_t)(1)) << v_j);
v_top = v_next_top;
- if ((v_top + (((uint32_t)(1)) << v_j)) > 1234) {
+ if ((v_top + (((uint32_t)(1)) << v_j)) > 1024) {
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
}
v_next_top = (v_top + (((uint32_t)(1)) << v_j));
v_redirect_key =
(((uint32_t)(wuffs_deflate__reverse8[(v_redirect_key >> 1)])) |
((v_redirect_key & 1) << 8));
- self->private_impl.f_huffs[a_which][v_redirect_key] =
+ self->private_data.f_huffs[a_which][v_redirect_key] =
(268435465 | (v_top << 8) | (v_j << 4));
}
}
if ((v_key >= 512) || (v_counts[v_prev_cl] <= 0)) {
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
}
+#if defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wconversion"
+#endif
v_counts[v_prev_cl] -= 1;
+#if defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
v_reversed_key = (((uint32_t)(wuffs_deflate__reverse8[(v_key >> 1)])) |
((v_key & 1) << 8));
v_reversed_key >>= (9 - v_cl);
@@ -6423,10 +7155,10 @@
v_delta = (((uint32_t)(1)) << v_cl);
while (v_high_bits >= v_delta) {
v_high_bits -= v_delta;
- if ((v_top + ((v_high_bits | v_reversed_key) & 511)) >= 1234) {
+ if ((v_top + ((v_high_bits | v_reversed_key) & 511)) >= 1024) {
return wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
}
- self->private_impl
+ self->private_data
.f_huffs[a_which][(v_top + ((v_high_bits | v_reversed_key) & 511))] =
v_value;
}
@@ -6466,10 +7198,8 @@
uint32_t v_hdist = 0;
uint8_t* iop_a_dst = NULL;
- uint8_t* io0_a_dst = NULL;
- uint8_t* io1_a_dst = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_dst);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_dst);
+ uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst.private_impl.buf) {
iop_a_dst =
a_dst.private_impl.buf->data.ptr + a_dst.private_impl.buf->meta.wi;
@@ -6485,10 +7215,8 @@
io1_a_dst = a_dst.private_impl.limit;
}
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -6502,7 +7230,7 @@
}
if ((self->private_impl.f_n_bits >= 8) ||
- ((self->private_impl.f_bits >> self->private_impl.f_n_bits) != 0)) {
+ ((self->private_impl.f_bits >> (self->private_impl.f_n_bits & 7)) != 0)) {
status = wuffs_deflate__error__internal_error_inconsistent_n_bits;
goto exit;
}
@@ -6515,21 +7243,21 @@
(((uint64_t)(io1_a_src - iop_a_src)) >= 12)) {
if (v_n_bits < 15) {
v_bits |= (((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
v_n_bits += 8;
v_bits |= (((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
v_n_bits += 8;
} else {
}
- v_table_entry = self->private_impl.f_huffs[0][(v_bits & v_lmask)];
+ v_table_entry = self->private_data.f_huffs[0][(v_bits & v_lmask)];
v_table_entry_n_bits = (v_table_entry & 15);
v_bits >>= v_table_entry_n_bits;
v_n_bits -= v_table_entry_n_bits;
if ((v_table_entry >> 31) != 0) {
(wuffs_base__store_u8be(iop_a_dst,
((uint8_t)(((v_table_entry >> 8) & 255)))),
- iop_a_dst += 1, wuffs_base__return_empty_struct());
+ iop_a_dst += 1, wuffs_base__make_empty_struct());
goto label_0_continue;
} else if ((v_table_entry >> 30) != 0) {
} else if ((v_table_entry >> 29) != 0) {
@@ -6538,29 +7266,25 @@
} else if ((v_table_entry >> 28) != 0) {
if (v_n_bits < 15) {
v_bits |= (((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
v_n_bits += 8;
v_bits |= (((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
v_n_bits += 8;
} else {
}
v_redir_top = ((v_table_entry >> 8) & 65535);
v_redir_mask = ((((uint32_t)(1)) << ((v_table_entry >> 4) & 15)) - 1);
- if ((v_redir_top + (v_bits & v_redir_mask)) >= 1234) {
- status =
- wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
- goto exit;
- }
- v_table_entry = self->private_impl
- .f_huffs[0][(v_redir_top + (v_bits & v_redir_mask))];
+ v_table_entry =
+ self->private_data
+ .f_huffs[0][((v_redir_top + (v_bits & v_redir_mask)) & 1023)];
v_table_entry_n_bits = (v_table_entry & 15);
v_bits >>= v_table_entry_n_bits;
v_n_bits -= v_table_entry_n_bits;
if ((v_table_entry >> 31) != 0) {
(wuffs_base__store_u8be(iop_a_dst,
((uint8_t)(((v_table_entry >> 8) & 255)))),
- iop_a_dst += 1, wuffs_base__return_empty_struct());
+ iop_a_dst += 1, wuffs_base__make_empty_struct());
goto label_0_continue;
} else if ((v_table_entry >> 30) != 0) {
} else if ((v_table_entry >> 29) != 0) {
@@ -6591,10 +7315,10 @@
if (v_table_entry_n_bits > 0) {
if (v_n_bits < 15) {
v_bits |= (((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
v_n_bits += 8;
v_bits |= (((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
v_n_bits += 8;
} else {
}
@@ -6609,36 +7333,32 @@
}
if (v_n_bits < 15) {
v_bits |= (((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
v_n_bits += 8;
v_bits |= (((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
v_n_bits += 8;
} else {
}
- v_table_entry = self->private_impl.f_huffs[1][(v_bits & v_dmask)];
+ v_table_entry = self->private_data.f_huffs[1][(v_bits & v_dmask)];
v_table_entry_n_bits = (v_table_entry & 15);
v_bits >>= v_table_entry_n_bits;
v_n_bits -= v_table_entry_n_bits;
if ((v_table_entry >> 28) == 1) {
if (v_n_bits < 15) {
v_bits |= (((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
v_n_bits += 8;
v_bits |= (((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
v_n_bits += 8;
} else {
}
v_redir_top = ((v_table_entry >> 8) & 65535);
v_redir_mask = ((((uint32_t)(1)) << ((v_table_entry >> 4) & 15)) - 1);
- if ((v_redir_top + (v_bits & v_redir_mask)) >= 1234) {
- status =
- wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
- goto exit;
- }
- v_table_entry = self->private_impl
- .f_huffs[1][(v_redir_top + (v_bits & v_redir_mask))];
+ v_table_entry =
+ self->private_data
+ .f_huffs[1][((v_redir_top + (v_bits & v_redir_mask)) & 1023)];
v_table_entry_n_bits = (v_table_entry & 15);
v_bits >>= v_table_entry_n_bits;
v_n_bits -= v_table_entry_n_bits;
@@ -6657,10 +7377,10 @@
v_table_entry_n_bits = ((v_table_entry >> 4) & 15);
if (v_n_bits < v_table_entry_n_bits) {
v_bits |= (((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
v_n_bits += 8;
v_bits |= (((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
v_n_bits += 8;
}
v_dist_minus_1 =
@@ -6693,10 +7413,8 @@
v_n_copied = wuffs_base__io_writer__copy_n_from_slice(
&iop_a_dst, io1_a_dst, v_hlen,
wuffs_base__slice_u8__subslice_i(
- ((wuffs_base__slice_u8){
- .ptr = self->private_impl.f_history,
- .len = 32768,
- }),
+ wuffs_base__make_slice_u8(self->private_data.f_history,
+ 32768),
(v_hdist & 32767)));
if (v_hlen <= v_n_copied) {
goto label_1_break;
@@ -6704,10 +7422,7 @@
v_hlen -= v_n_copied;
wuffs_base__io_writer__copy_n_from_slice(
&iop_a_dst, io1_a_dst, v_hlen,
- ((wuffs_base__slice_u8){
- .ptr = self->private_impl.f_history,
- .len = 32768,
- }));
+ wuffs_base__make_slice_u8(self->private_data.f_history, 32768));
goto label_1_break;
}
label_1_break:;
@@ -6731,7 +7446,7 @@
while (v_n_bits >= 8) {
v_n_bits -= 8;
if (iop_a_src > io0_a_src) {
- (iop_a_src--, wuffs_base__return_empty_struct());
+ (iop_a_src--, wuffs_base__make_empty_struct());
} else {
status = wuffs_deflate__error__internal_error_inconsistent_i_o;
goto exit;
@@ -6748,11 +7463,11 @@
exit:
if (a_dst.private_impl.buf) {
a_dst.private_impl.buf->meta.wi =
- iop_a_dst - a_dst.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_dst - a_dst.private_impl.buf->data.ptr));
}
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -6787,10 +7502,8 @@
uint32_t v_hdist = 0;
uint8_t* iop_a_dst = NULL;
- uint8_t* io0_a_dst = NULL;
- uint8_t* io1_a_dst = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_dst);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_dst);
+ uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst.private_impl.buf) {
iop_a_dst =
a_dst.private_impl.buf->data.ptr + a_dst.private_impl.buf->meta.wi;
@@ -6806,10 +7519,8 @@
io1_a_dst = a_dst.private_impl.limit;
}
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -6822,28 +7533,28 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point =
- self->private_impl.c_decode_huffman_slow[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_huffman_slow[0];
if (coro_susp_point) {
- v_bits = self->private_impl.c_decode_huffman_slow[0].v_bits;
- v_n_bits = self->private_impl.c_decode_huffman_slow[0].v_n_bits;
- v_table_entry = self->private_impl.c_decode_huffman_slow[0].v_table_entry;
+ v_bits = self->private_data.s_decode_huffman_slow[0].v_bits;
+ v_n_bits = self->private_data.s_decode_huffman_slow[0].v_n_bits;
+ v_table_entry = self->private_data.s_decode_huffman_slow[0].v_table_entry;
v_table_entry_n_bits =
- self->private_impl.c_decode_huffman_slow[0].v_table_entry_n_bits;
- v_lmask = self->private_impl.c_decode_huffman_slow[0].v_lmask;
- v_dmask = self->private_impl.c_decode_huffman_slow[0].v_dmask;
- v_redir_top = self->private_impl.c_decode_huffman_slow[0].v_redir_top;
- v_redir_mask = self->private_impl.c_decode_huffman_slow[0].v_redir_mask;
- v_length = self->private_impl.c_decode_huffman_slow[0].v_length;
- v_dist_minus_1 = self->private_impl.c_decode_huffman_slow[0].v_dist_minus_1;
- v_hlen = self->private_impl.c_decode_huffman_slow[0].v_hlen;
- v_hdist = self->private_impl.c_decode_huffman_slow[0].v_hdist;
+ self->private_data.s_decode_huffman_slow[0].v_table_entry_n_bits;
+ v_lmask = self->private_data.s_decode_huffman_slow[0].v_lmask;
+ v_dmask = self->private_data.s_decode_huffman_slow[0].v_dmask;
+ v_redir_top = self->private_data.s_decode_huffman_slow[0].v_redir_top;
+ v_redir_mask = self->private_data.s_decode_huffman_slow[0].v_redir_mask;
+ v_length = self->private_data.s_decode_huffman_slow[0].v_length;
+ v_dist_minus_1 = self->private_data.s_decode_huffman_slow[0].v_dist_minus_1;
+ v_hlen = self->private_data.s_decode_huffman_slow[0].v_hlen;
+ v_hdist = self->private_data.s_decode_huffman_slow[0].v_hdist;
}
switch (coro_susp_point) {
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)) {
+ ((self->private_impl.f_bits >> (self->private_impl.f_n_bits & 7)) !=
+ 0)) {
status = wuffs_deflate__error__internal_error_inconsistent_n_bits;
goto exit;
}
@@ -6852,10 +7563,9 @@
v_lmask = ((((uint32_t)(1)) << self->private_impl.f_n_huffs_bits[0]) - 1);
v_dmask = ((((uint32_t)(1)) << self->private_impl.f_n_huffs_bits[1]) - 1);
label_0_continue:;
- while (
- !(self->private_impl.c_decode_huffman_slow[0].coro_susp_point != 0)) {
+ while (!(self->private_impl.p_decode_huffman_slow[0] != 0)) {
while (true) {
- v_table_entry = self->private_impl.f_huffs[0][(v_bits & v_lmask)];
+ v_table_entry = self->private_data.f_huffs[0][(v_bits & v_lmask)];
v_table_entry_n_bits = (v_table_entry & 15);
if (v_n_bits >= v_table_entry_n_bits) {
v_bits >>= v_table_entry_n_bits;
@@ -6891,14 +7601,9 @@
v_redir_top = ((v_table_entry >> 8) & 65535);
v_redir_mask = ((((uint32_t)(1)) << ((v_table_entry >> 4) & 15)) - 1);
while (true) {
- if ((v_redir_top + (v_bits & v_redir_mask)) >= 1234) {
- status =
- wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
- goto exit;
- }
v_table_entry =
- self->private_impl
- .f_huffs[0][(v_redir_top + (v_bits & v_redir_mask))];
+ self->private_data
+ .f_huffs[0][((v_redir_top + (v_bits & v_redir_mask)) & 1023)];
v_table_entry_n_bits = (v_table_entry & 15);
if (v_n_bits >= v_table_entry_n_bits) {
v_bits >>= v_table_entry_n_bits;
@@ -6975,7 +7680,7 @@
v_n_bits -= v_table_entry_n_bits;
}
while (true) {
- v_table_entry = self->private_impl.f_huffs[1][(v_bits & v_dmask)];
+ v_table_entry = self->private_data.f_huffs[1][(v_bits & v_dmask)];
v_table_entry_n_bits = (v_table_entry & 15);
if (v_n_bits >= v_table_entry_n_bits) {
v_bits >>= v_table_entry_n_bits;
@@ -6999,14 +7704,9 @@
v_redir_top = ((v_table_entry >> 8) & 65535);
v_redir_mask = ((((uint32_t)(1)) << ((v_table_entry >> 4) & 15)) - 1);
while (true) {
- if ((v_redir_top + (v_bits & v_redir_mask)) >= 1234) {
- status =
- wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state;
- goto exit;
- }
v_table_entry =
- self->private_impl
- .f_huffs[1][(v_redir_top + (v_bits & v_redir_mask))];
+ self->private_data
+ .f_huffs[1][((v_redir_top + (v_bits & v_redir_mask)) & 1023)];
v_table_entry_n_bits = (v_table_entry & 15);
if (v_n_bits >= v_table_entry_n_bits) {
v_bits >>= v_table_entry_n_bits;
@@ -7081,10 +7781,8 @@
v_n_copied = wuffs_base__io_writer__copy_n_from_slice(
&iop_a_dst, io1_a_dst, v_hlen,
wuffs_base__slice_u8__subslice_i(
- ((wuffs_base__slice_u8){
- .ptr = self->private_impl.f_history,
- .len = 32768,
- }),
+ wuffs_base__make_slice_u8(self->private_data.f_history,
+ 32768),
(v_hdist & 32767)));
if (v_hlen <= v_n_copied) {
v_hlen = 0;
@@ -7106,10 +7804,8 @@
v_n_copied = wuffs_base__io_writer__copy_n_from_slice(
&iop_a_dst, io1_a_dst, v_hlen,
wuffs_base__slice_u8__subslice_i(
- ((wuffs_base__slice_u8){
- .ptr = self->private_impl.f_history,
- .len = 32768,
- }),
+ wuffs_base__make_slice_u8(self->private_data.f_history,
+ 32768),
(v_hdist & 32767)));
if (v_hlen <= v_n_copied) {
v_hlen = 0;
@@ -7143,43 +7839,44 @@
self->private_impl.f_bits = v_bits;
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)) {
+ ((self->private_impl.f_bits >> (self->private_impl.f_n_bits & 7)) !=
+ 0)) {
status = wuffs_deflate__error__internal_error_inconsistent_n_bits;
goto exit;
}
goto ok;
ok:
- self->private_impl.c_decode_huffman_slow[0].coro_susp_point = 0;
+ self->private_impl.p_decode_huffman_slow[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_huffman_slow[0].coro_susp_point = coro_susp_point;
- self->private_impl.c_decode_huffman_slow[0].v_bits = v_bits;
- self->private_impl.c_decode_huffman_slow[0].v_n_bits = v_n_bits;
- self->private_impl.c_decode_huffman_slow[0].v_table_entry = v_table_entry;
- self->private_impl.c_decode_huffman_slow[0].v_table_entry_n_bits =
+ self->private_impl.p_decode_huffman_slow[0] = coro_susp_point;
+ self->private_data.s_decode_huffman_slow[0].v_bits = v_bits;
+ self->private_data.s_decode_huffman_slow[0].v_n_bits = v_n_bits;
+ self->private_data.s_decode_huffman_slow[0].v_table_entry = v_table_entry;
+ self->private_data.s_decode_huffman_slow[0].v_table_entry_n_bits =
v_table_entry_n_bits;
- self->private_impl.c_decode_huffman_slow[0].v_lmask = v_lmask;
- self->private_impl.c_decode_huffman_slow[0].v_dmask = v_dmask;
- self->private_impl.c_decode_huffman_slow[0].v_redir_top = v_redir_top;
- self->private_impl.c_decode_huffman_slow[0].v_redir_mask = v_redir_mask;
- self->private_impl.c_decode_huffman_slow[0].v_length = v_length;
- self->private_impl.c_decode_huffman_slow[0].v_dist_minus_1 = v_dist_minus_1;
- self->private_impl.c_decode_huffman_slow[0].v_hlen = v_hlen;
- self->private_impl.c_decode_huffman_slow[0].v_hdist = v_hdist;
+ self->private_data.s_decode_huffman_slow[0].v_lmask = v_lmask;
+ self->private_data.s_decode_huffman_slow[0].v_dmask = v_dmask;
+ self->private_data.s_decode_huffman_slow[0].v_redir_top = v_redir_top;
+ self->private_data.s_decode_huffman_slow[0].v_redir_mask = v_redir_mask;
+ self->private_data.s_decode_huffman_slow[0].v_length = v_length;
+ self->private_data.s_decode_huffman_slow[0].v_dist_minus_1 = v_dist_minus_1;
+ self->private_data.s_decode_huffman_slow[0].v_hlen = v_hlen;
+ self->private_data.s_decode_huffman_slow[0].v_hdist = v_hdist;
goto exit;
exit:
if (a_dst.private_impl.buf) {
a_dst.private_impl.buf->meta.wi =
- iop_a_dst - a_dst.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_dst - a_dst.private_impl.buf->data.ptr));
}
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -7192,9 +7889,9 @@
// ---------------- Status Codes Implementations
-const char* wuffs_lzw__error__bad_code = "?lzw: bad code";
+const char* wuffs_lzw__error__bad_code = "#lzw: bad code";
const char* wuffs_lzw__error__internal_error_inconsistent_i_o =
- "?lzw: internal error: inconsistent I/O";
+ "#lzw: internal error: inconsistent I/O";
// ---------------- Private Consts
@@ -7213,9 +7910,10 @@
// ---------------- Initializer Implementations
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
-wuffs_lzw__decoder__check_wuffs_version(wuffs_lzw__decoder* self,
- size_t sizeof_star_self,
- uint64_t wuffs_version) {
+wuffs_lzw__decoder__initialize(wuffs_lzw__decoder* self,
+ size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags) {
if (!self) {
return wuffs_base__error__bad_receiver;
}
@@ -7226,16 +7924,39 @@
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
return wuffs_base__error__bad_wuffs_version;
}
- if (self->private_impl.magic != 0) {
- return wuffs_base__error__check_wuffs_version_not_applicable;
+
+ if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
+// The whole point of this if-check is to detect an uninitialized *self.
+// We disable the warning on GCC. Clang-5.0 does not have this warning.
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+#endif
+ if (self->private_impl.magic != 0) {
+ return wuffs_base__error__initialize_falsely_claimed_already_zeroed;
+ }
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
+ } else {
+ void* p = &(self->private_impl);
+ size_t n = sizeof(self->private_impl);
+ if ((initialize_flags &
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
+ p = self;
+ n = sizeof(*self);
+ initialize_flags |= WUFFS_INITIALIZE__ALREADY_ZEROED;
+ }
+ memset(p, 0, n);
}
+
self->private_impl.magic = WUFFS_BASE__MAGIC;
return NULL;
}
size_t //
sizeof__wuffs_lzw__decoder() {
- return sizeof((wuffs_lzw__decoder){});
+ return sizeof(wuffs_lzw__decoder);
}
// ---------------- Function Implementations
@@ -7245,18 +7966,33 @@
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct //
wuffs_lzw__decoder__set_literal_width(wuffs_lzw__decoder* self, uint32_t a_lw) {
if (!self) {
- return ((wuffs_base__empty_struct){});
+ return wuffs_base__make_empty_struct();
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
- return ((wuffs_base__empty_struct){});
+ return wuffs_base__make_empty_struct();
}
if (a_lw < 2 || a_lw > 8) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
- return ((wuffs_base__empty_struct){});
+ return wuffs_base__make_empty_struct();
}
- self->private_impl.f_lw = a_lw;
- return ((wuffs_base__empty_struct){});
+ self->private_impl.f_set_literal_width_arg = a_lw;
+ return wuffs_base__make_empty_struct();
+}
+
+// -------- func lzw.decoder.workbuf_len
+
+WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 //
+wuffs_lzw__decoder__workbuf_len(const wuffs_lzw__decoder* self) {
+ if (!self) {
+ return wuffs_base__utility__make_range_ii_u64(0, 0);
+ }
+ if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
+ (self->private_impl.magic != WUFFS_BASE__DISABLED)) {
+ return wuffs_base__utility__make_range_ii_u64(0, 0);
+ }
+
+ return wuffs_base__utility__make_range_ii_u64(0, 0);
}
// -------- func lzw.decoder.decode_io_writer
@@ -7264,29 +8000,36 @@
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_lzw__decoder__decode_io_writer(wuffs_lzw__decoder* self,
wuffs_base__io_writer a_dst,
- wuffs_base__io_reader a_src) {
+ wuffs_base__io_reader a_src,
+ wuffs_base__slice_u8 a_workbuf) {
if (!self) {
return wuffs_base__error__bad_receiver;
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return (self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
- : wuffs_base__error__check_wuffs_version_missing;
+ : wuffs_base__error__initialize_not_called;
}
+ if ((self->private_impl.active_coroutine != 0) &&
+ (self->private_impl.active_coroutine != 1)) {
+ self->private_impl.magic = WUFFS_BASE__DISABLED;
+ return wuffs_base__error__interleaved_coroutine_calls;
+ }
+ self->private_impl.active_coroutine = 0;
wuffs_base__status status = NULL;
uint32_t v_i = 0;
- uint32_t coro_susp_point =
- self->private_impl.c_decode_io_writer[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_io_writer[0];
if (coro_susp_point) {
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
self->private_impl.f_literal_width = 8;
- if (self->private_impl.f_lw >= 2) {
- self->private_impl.f_literal_width = self->private_impl.f_lw;
+ if (self->private_impl.f_set_literal_width_arg >= 2) {
+ self->private_impl.f_literal_width =
+ self->private_impl.f_set_literal_width_arg;
}
self->private_impl.f_clear_code =
(((uint32_t)(1)) << self->private_impl.f_literal_width);
@@ -7300,8 +8043,8 @@
self->private_impl.f_output_wi = 0;
v_i = 0;
while (v_i < self->private_impl.f_clear_code) {
- self->private_impl.f_lm1s[v_i] = 0;
- self->private_impl.f_suffixes[v_i][0] = ((uint8_t)(v_i));
+ self->private_data.f_lm1s[v_i] = 0;
+ self->private_data.f_suffixes[v_i][0] = ((uint8_t)(v_i));
v_i += 1;
}
label_0_continue:;
@@ -7333,13 +8076,14 @@
goto ok;
ok:
- self->private_impl.c_decode_io_writer[0].coro_susp_point = 0;
+ self->private_impl.p_decode_io_writer[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_io_writer[0].coro_susp_point = coro_susp_point;
+ self->private_impl.p_decode_io_writer[0] = coro_susp_point;
+ self->private_impl.active_coroutine = 1;
goto exit;
exit:
@@ -7371,10 +8115,8 @@
uint16_t v_lm1_a = 0;
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -7399,15 +8141,14 @@
if (v_n_bits < v_width) {
if (((uint64_t)(io1_a_src - iop_a_src)) >= 4) {
v_bits |= (wuffs_base__load_u32le(iop_a_src) << v_n_bits);
- (iop_a_src += ((31 - v_n_bits) >> 3),
- wuffs_base__return_empty_struct());
+ (iop_a_src += ((31 - v_n_bits) >> 3), wuffs_base__make_empty_struct());
v_n_bits |= 24;
} else if (((uint64_t)(io1_a_src - iop_a_src)) <= 0) {
self->private_impl.f_read_from_return_value = 2;
goto label_0_break;
} else {
v_bits |= (((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
v_n_bits += 8;
if (v_n_bits >= v_width) {
} else if (((uint64_t)(io1_a_src - iop_a_src)) <= 0) {
@@ -7416,7 +8157,7 @@
} else {
v_bits |=
(((uint32_t)(wuffs_base__load_u8be(iop_a_src))) << v_n_bits);
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
v_n_bits += 8;
if (v_n_bits < v_width) {
self->private_impl.f_read_from_return_value = 4;
@@ -7429,23 +8170,23 @@
v_bits >>= v_width;
v_n_bits -= v_width;
if (v_code < v_clear_code) {
- self->private_impl.f_output[v_output_wi] = ((uint8_t)(v_code));
+ self->private_data.f_output[v_output_wi] = ((uint8_t)(v_code));
v_output_wi = ((v_output_wi + 1) & 8191);
if (v_save_code <= 4095) {
- v_lm1_a = ((self->private_impl.f_lm1s[v_prev_code] + 1) & 4095);
- self->private_impl.f_lm1s[v_save_code] = v_lm1_a;
+ v_lm1_a = ((self->private_data.f_lm1s[v_prev_code] + 1) & 4095);
+ self->private_data.f_lm1s[v_save_code] = v_lm1_a;
if ((v_lm1_a % 8) != 0) {
self->private_impl.f_prefixes[v_save_code] =
self->private_impl.f_prefixes[v_prev_code];
- memcpy(self->private_impl.f_suffixes[v_save_code],
- self->private_impl.f_suffixes[v_prev_code],
- sizeof(self->private_impl.f_suffixes[v_save_code]));
- self->private_impl.f_suffixes[v_save_code][(v_lm1_a % 8)] =
+ memcpy(self->private_data.f_suffixes[v_save_code],
+ self->private_data.f_suffixes[v_prev_code],
+ sizeof(self->private_data.f_suffixes[v_save_code]));
+ self->private_data.f_suffixes[v_save_code][(v_lm1_a % 8)] =
((uint8_t)(v_code));
} else {
self->private_impl.f_prefixes[v_save_code] =
((uint16_t)(v_prev_code));
- self->private_impl.f_suffixes[v_save_code][0] = ((uint8_t)(v_code));
+ self->private_data.f_suffixes[v_save_code][0] = ((uint8_t)(v_code));
}
v_save_code += 1;
if (v_width < 12) {
@@ -7467,15 +8208,15 @@
v_c = v_prev_code;
}
v_o = ((v_output_wi +
- (((uint32_t)(self->private_impl.f_lm1s[v_c])) & 4294967288)) &
+ (((uint32_t)(self->private_data.f_lm1s[v_c])) & 4294967288)) &
8191);
v_output_wi =
- ((v_output_wi + 1 + ((uint32_t)(self->private_impl.f_lm1s[v_c]))) &
+ ((v_output_wi + 1 + ((uint32_t)(self->private_data.f_lm1s[v_c]))) &
8191);
- v_steps = (((uint32_t)(self->private_impl.f_lm1s[v_c])) >> 3);
+ v_steps = (((uint32_t)(self->private_data.f_lm1s[v_c])) >> 3);
while (true) {
- memcpy((self->private_impl.f_output) + (v_o),
- (self->private_impl.f_suffixes[v_c]), 8);
+ memcpy((self->private_data.f_output) + (v_o),
+ (self->private_data.f_suffixes[v_c]), 8);
if (v_steps <= 0) {
goto label_1_break;
}
@@ -7484,26 +8225,26 @@
v_c = ((uint32_t)(self->private_impl.f_prefixes[v_c]));
}
label_1_break:;
- v_first_byte = self->private_impl.f_suffixes[v_c][0];
+ v_first_byte = self->private_data.f_suffixes[v_c][0];
if (v_code == v_save_code) {
- self->private_impl.f_output[v_output_wi] = v_first_byte;
+ self->private_data.f_output[v_output_wi] = v_first_byte;
v_output_wi = ((v_output_wi + 1) & 8191);
}
if (v_save_code <= 4095) {
- v_lm1_b = ((self->private_impl.f_lm1s[v_prev_code] + 1) & 4095);
- self->private_impl.f_lm1s[v_save_code] = v_lm1_b;
+ v_lm1_b = ((self->private_data.f_lm1s[v_prev_code] + 1) & 4095);
+ self->private_data.f_lm1s[v_save_code] = v_lm1_b;
if ((v_lm1_b % 8) != 0) {
self->private_impl.f_prefixes[v_save_code] =
self->private_impl.f_prefixes[v_prev_code];
- memcpy(self->private_impl.f_suffixes[v_save_code],
- self->private_impl.f_suffixes[v_prev_code],
- sizeof(self->private_impl.f_suffixes[v_save_code]));
- self->private_impl.f_suffixes[v_save_code][(v_lm1_b % 8)] =
+ memcpy(self->private_data.f_suffixes[v_save_code],
+ self->private_data.f_suffixes[v_prev_code],
+ sizeof(self->private_data.f_suffixes[v_save_code]));
+ self->private_data.f_suffixes[v_save_code][(v_lm1_b % 8)] =
v_first_byte;
} else {
self->private_impl.f_prefixes[v_save_code] =
((uint16_t)(v_prev_code));
- self->private_impl.f_suffixes[v_save_code][0] =
+ self->private_data.f_suffixes[v_save_code][0] =
((uint8_t)(v_first_byte));
}
v_save_code += 1;
@@ -7526,7 +8267,7 @@
while (v_n_bits >= 8) {
v_n_bits -= 8;
if (iop_a_src > io0_a_src) {
- (iop_a_src--, wuffs_base__return_empty_struct());
+ (iop_a_src--, wuffs_base__make_empty_struct());
} else {
self->private_impl.f_read_from_return_value = 4;
goto label_2_break;
@@ -7542,10 +8283,10 @@
self->private_impl.f_output_wi = v_output_wi;
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
- return ((wuffs_base__empty_struct){});
+ return wuffs_base__make_empty_struct();
}
// -------- func lzw.decoder.write_to
@@ -7555,14 +8296,12 @@
wuffs_base__io_writer a_dst) {
wuffs_base__status status = NULL;
- wuffs_base__slice_u8 v_s = {};
+ wuffs_base__slice_u8 v_s = {0};
uint64_t v_n = 0;
uint8_t* iop_a_dst = NULL;
- uint8_t* io0_a_dst = NULL;
- uint8_t* io1_a_dst = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_dst);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_dst);
+ uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst.private_impl.buf) {
iop_a_dst =
a_dst.private_impl.buf->data.ptr + a_dst.private_impl.buf->meta.wi;
@@ -7578,7 +8317,7 @@
io1_a_dst = a_dst.private_impl.limit;
}
- uint32_t coro_susp_point = self->private_impl.c_write_to[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_write_to[0];
if (coro_susp_point) {
}
switch (coro_susp_point) {
@@ -7590,10 +8329,7 @@
goto exit;
}
v_s = wuffs_base__slice_u8__subslice_ij(
- ((wuffs_base__slice_u8){
- .ptr = self->private_impl.f_output,
- .len = 8199,
- }),
+ wuffs_base__make_slice_u8(self->private_data.f_output, 8199),
self->private_impl.f_output_ri, self->private_impl.f_output_wi);
v_n = wuffs_base__io_writer__copy_from_slice(&iop_a_dst, io1_a_dst, v_s);
if (v_n == ((uint64_t)(v_s.len))) {
@@ -7611,19 +8347,19 @@
goto ok;
ok:
- self->private_impl.c_write_to[0].coro_susp_point = 0;
+ self->private_impl.p_write_to[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_write_to[0].coro_susp_point = coro_susp_point;
+ self->private_impl.p_write_to[0] = coro_susp_point;
goto exit;
exit:
if (a_dst.private_impl.buf) {
a_dst.private_impl.buf->meta.wi =
- iop_a_dst - a_dst.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_dst - a_dst.private_impl.buf->data.ptr));
}
return status;
@@ -7634,20 +8370,17 @@
WUFFS_BASE__MAYBE_STATIC wuffs_base__slice_u8 //
wuffs_lzw__decoder__flush(wuffs_lzw__decoder* self) {
if (!self) {
- return ((wuffs_base__slice_u8){});
+ return wuffs_base__make_slice_u8(NULL, 0);
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
- return ((wuffs_base__slice_u8){});
+ return wuffs_base__make_slice_u8(NULL, 0);
}
- wuffs_base__slice_u8 v_s = {};
+ wuffs_base__slice_u8 v_s = {0};
if (self->private_impl.f_output_ri <= self->private_impl.f_output_wi) {
v_s = wuffs_base__slice_u8__subslice_ij(
- ((wuffs_base__slice_u8){
- .ptr = self->private_impl.f_output,
- .len = 8199,
- }),
+ wuffs_base__make_slice_u8(self->private_data.f_output, 8199),
self->private_impl.f_output_ri, self->private_impl.f_output_wi);
}
self->private_impl.f_output_ri = 0;
@@ -7661,33 +8394,38 @@
// ---------------- Status Codes Implementations
-const char* wuffs_gif__error__bad_block = "?gif: bad block";
-const char* wuffs_gif__error__bad_extension_label = "?gif: bad extension label";
-const char* wuffs_gif__error__bad_graphic_control = "?gif: bad graphic control";
-const char* wuffs_gif__error__bad_header = "?gif: bad header";
-const char* wuffs_gif__error__bad_literal_width = "?gif: bad literal width";
-const char* wuffs_gif__error__not_enough_pixel_data =
- "?gif: not enough pixel data";
-const char* wuffs_gif__error__too_much_pixel_data = "?gif: too much pixel data";
+const char* wuffs_gif__error__bad_block = "#gif: bad block";
+const char* wuffs_gif__error__bad_extension_label = "#gif: bad extension label";
+const char* wuffs_gif__error__bad_graphic_control = "#gif: bad graphic control";
+const char* wuffs_gif__error__bad_header = "#gif: bad header";
+const char* wuffs_gif__error__bad_literal_width = "#gif: bad literal width";
const char* wuffs_gif__error__internal_error_inconsistent_ri_wi =
- "?gif: internal error: inconsistent ri/wi";
+ "#gif: internal error: inconsistent ri/wi";
// ---------------- Private Consts
-static const uint32_t wuffs_gif__interlace_start[5] = {
- 4294967295, 1, 2, 4, 0,
+static const uint32_t //
+ wuffs_gif__interlace_start[5] //
+ WUFFS_BASE__POTENTIALLY_UNUSED = {
+ 4294967295, 1, 2, 4, 0,
};
-static const uint8_t wuffs_gif__interlace_delta[5] = {
- 1, 2, 4, 8, 8,
+static const uint8_t //
+ wuffs_gif__interlace_delta[5] //
+ WUFFS_BASE__POTENTIALLY_UNUSED = {
+ 1, 2, 4, 8, 8,
};
-static const uint8_t wuffs_gif__animexts1dot0[11] = {
- 65, 78, 73, 77, 69, 88, 84, 83, 49, 46, 48,
+static const uint8_t //
+ wuffs_gif__animexts1dot0[11] //
+ WUFFS_BASE__POTENTIALLY_UNUSED = {
+ 65, 78, 73, 77, 69, 88, 84, 83, 49, 46, 48,
};
-static const uint8_t wuffs_gif__netscape2dot0[11] = {
- 78, 69, 84, 83, 67, 65, 80, 69, 50, 46, 48,
+static const uint8_t //
+ wuffs_gif__netscape2dot0[11] //
+ WUFFS_BASE__POTENTIALLY_UNUSED = {
+ 78, 69, 84, 83, 67, 65, 80, 69, 50, 46, 48,
};
// ---------------- Private Initializer Prototypes
@@ -7752,9 +8490,10 @@
// ---------------- Initializer Implementations
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
-wuffs_gif__decoder__check_wuffs_version(wuffs_gif__decoder* self,
- size_t sizeof_star_self,
- uint64_t wuffs_version) {
+wuffs_gif__decoder__initialize(wuffs_gif__decoder* self,
+ size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags) {
if (!self) {
return wuffs_base__error__bad_receiver;
}
@@ -7765,13 +8504,36 @@
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
return wuffs_base__error__bad_wuffs_version;
}
- if (self->private_impl.magic != 0) {
- return wuffs_base__error__check_wuffs_version_not_applicable;
+
+ if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
+// The whole point of this if-check is to detect an uninitialized *self.
+// We disable the warning on GCC. Clang-5.0 does not have this warning.
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+#endif
+ if (self->private_impl.magic != 0) {
+ return wuffs_base__error__initialize_falsely_claimed_already_zeroed;
+ }
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
+ } else {
+ void* p = &(self->private_impl);
+ size_t n = sizeof(self->private_impl);
+ if ((initialize_flags &
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
+ p = self;
+ n = sizeof(*self);
+ initialize_flags |= WUFFS_INITIALIZE__ALREADY_ZEROED;
+ }
+ memset(p, 0, n);
}
+
{
- wuffs_base__status z = wuffs_lzw__decoder__check_wuffs_version(
- &self->private_impl.f_lzw, sizeof(self->private_impl.f_lzw),
- WUFFS_VERSION);
+ wuffs_base__status z = wuffs_lzw__decoder__initialize(
+ &self->private_data.f_lzw, sizeof(self->private_data.f_lzw),
+ WUFFS_VERSION, initialize_flags);
if (z) {
return z;
}
@@ -7782,7 +8544,7 @@
size_t //
sizeof__wuffs_gif__decoder() {
- return sizeof((wuffs_gif__decoder){});
+ return sizeof(wuffs_gif__decoder);
}
// ---------------- Function Implementations
@@ -7799,14 +8561,19 @@
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return (self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
- : wuffs_base__error__check_wuffs_version_missing;
+ : wuffs_base__error__initialize_not_called;
}
+ if ((self->private_impl.active_coroutine != 0) &&
+ (self->private_impl.active_coroutine != 1)) {
+ self->private_impl.magic = WUFFS_BASE__DISABLED;
+ return wuffs_base__error__interleaved_coroutine_calls;
+ }
+ self->private_impl.active_coroutine = 0;
wuffs_base__status status = NULL;
bool v_ffio = false;
- uint32_t coro_susp_point =
- self->private_impl.c_decode_image_config[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_image_config[0];
if (coro_susp_point) {
}
switch (coro_susp_point) {
@@ -7816,9 +8583,6 @@
status = wuffs_base__error__bad_call_sequence;
goto exit;
}
- (memset(&self->private_impl.f_dirty_y, 0,
- sizeof((wuffs_base__range_ie_u32){})),
- wuffs_base__return_empty_struct());
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
status = wuffs_gif__decoder__decode_header(self, a_src);
if (status) {
@@ -7841,7 +8605,7 @@
(self->private_impl.f_frame_rect_x1 == self->private_impl.f_width) &&
(self->private_impl.f_frame_rect_y1 == self->private_impl.f_height));
if (a_dst != NULL) {
- wuffs_base__image_config__initialize(
+ wuffs_base__image_config__set(
a_dst, 1191444488, 0, self->private_impl.f_width,
self->private_impl.f_height,
self->private_impl.f_frame_config_io_position, v_ffio);
@@ -7850,13 +8614,14 @@
goto ok;
ok:
- self->private_impl.c_decode_image_config[0].coro_susp_point = 0;
+ self->private_impl.p_decode_image_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_image_config[0].coro_susp_point = coro_susp_point;
+ self->private_impl.p_decode_image_config[0] = coro_susp_point;
+ self->private_impl.active_coroutine = 1;
goto exit;
exit:
@@ -7873,7 +8638,8 @@
if (!self) {
return 0;
}
- if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
+ if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
+ (self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
@@ -7890,7 +8656,8 @@
if (!self) {
return 0;
}
- if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
+ if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
+ (self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
@@ -7904,7 +8671,8 @@
if (!self) {
return 0;
}
- if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
+ if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
+ (self->private_impl.magic != WUFFS_BASE__DISABLED)) {
return 0;
}
@@ -7916,16 +8684,19 @@
WUFFS_BASE__MAYBE_STATIC wuffs_base__rect_ie_u32 //
wuffs_gif__decoder__frame_dirty_rect(const wuffs_gif__decoder* self) {
if (!self) {
- return ((wuffs_base__rect_ie_u32){});
+ return wuffs_base__utility__make_rect_ie_u32(0, 0, 0, 0);
}
- if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
- return ((wuffs_base__rect_ie_u32){});
+ if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
+ (self->private_impl.magic != WUFFS_BASE__DISABLED)) {
+ return wuffs_base__utility__make_rect_ie_u32(0, 0, 0, 0);
}
return wuffs_base__utility__make_rect_ie_u32(
- &self->private_impl.f_util, self->private_impl.f_frame_rect_x0,
+ wuffs_base__u32__min(self->private_impl.f_frame_rect_x0,
+ self->private_impl.f_width),
wuffs_base__range_ie_u32__get_min_incl(&self->private_impl.f_dirty_y),
- self->private_impl.f_frame_rect_x1,
+ wuffs_base__u32__min(self->private_impl.f_frame_rect_x1,
+ self->private_impl.f_width),
wuffs_base__range_ie_u32__get_max_excl(&self->private_impl.f_dirty_y));
}
@@ -7934,15 +8705,14 @@
WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 //
wuffs_gif__decoder__workbuf_len(const wuffs_gif__decoder* self) {
if (!self) {
- return ((wuffs_base__range_ii_u64){});
+ return wuffs_base__utility__make_range_ii_u64(0, 0);
}
- if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
- return ((wuffs_base__range_ii_u64){});
+ if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
+ (self->private_impl.magic != WUFFS_BASE__DISABLED)) {
+ return wuffs_base__utility__make_range_ii_u64(0, 0);
}
- return wuffs_base__utility__make_range_ii_u64(
- &self->private_impl.f_util, ((uint64_t)(self->private_impl.f_width)),
- ((uint64_t)(self->private_impl.f_width)));
+ return wuffs_base__utility__make_range_ii_u64(1, 1);
}
// -------- func gif.decoder.restart_frame
@@ -7957,7 +8727,7 @@
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return (self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
- : wuffs_base__error__check_wuffs_version_missing;
+ : wuffs_base__error__initialize_not_called;
}
if (self->private_impl.f_call_sequence == 0) {
@@ -7984,19 +8754,26 @@
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return (self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
- : wuffs_base__error__check_wuffs_version_missing;
+ : wuffs_base__error__initialize_not_called;
}
+ if ((self->private_impl.active_coroutine != 0) &&
+ (self->private_impl.active_coroutine != 2)) {
+ self->private_impl.magic = WUFFS_BASE__DISABLED;
+ return wuffs_base__error__interleaved_coroutine_calls;
+ }
+ self->private_impl.active_coroutine = 0;
wuffs_base__status status = NULL;
uint8_t v_blend = 0;
- uint32_t coro_susp_point =
- self->private_impl.c_decode_frame_config[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_frame_config[0];
if (coro_susp_point) {
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
+ (memset(&self->private_impl.f_dirty_y, 0, sizeof(wuffs_base__range_ie_u32)),
+ wuffs_base__make_empty_struct());
if (!self->private_impl.f_end_of_data) {
if (self->private_impl.f_call_sequence == 0) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(1);
@@ -8031,7 +8808,6 @@
wuffs_base__frame_config__update(
a_dst,
wuffs_base__utility__make_rect_ie_u32(
- &self->private_impl.f_util,
wuffs_base__u32__min(self->private_impl.f_frame_rect_x0,
self->private_impl.f_width),
wuffs_base__u32__min(self->private_impl.f_frame_rect_y0,
@@ -8040,7 +8816,7 @@
self->private_impl.f_width),
wuffs_base__u32__min(self->private_impl.f_frame_rect_y1,
self->private_impl.f_height)),
- self->private_impl.f_gc_duration,
+ ((wuffs_base__flicks)(self->private_impl.f_gc_duration)),
self->private_impl.f_num_decoded_frame_configs_value,
self->private_impl.f_frame_config_io_position, v_blend,
self->private_impl.f_gc_disposal);
@@ -8051,13 +8827,14 @@
goto ok;
ok:
- self->private_impl.c_decode_frame_config[0].coro_susp_point = 0;
+ self->private_impl.p_decode_frame_config[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_frame_config[0].coro_susp_point = coro_susp_point;
+ self->private_impl.p_decode_frame_config[0] = coro_susp_point;
+ self->private_impl.active_coroutine = 2;
goto exit;
exit:
@@ -8077,10 +8854,8 @@
uint8_t v_flags = 0;
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -8093,7 +8868,7 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point = self->private_impl.c_skip_frame[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_skip_frame[0];
if (coro_susp_point) {
}
switch (coro_susp_point) {
@@ -8109,17 +8884,18 @@
v_flags = t_0;
}
if ((v_flags & 128) != 0) {
- self->private_impl.c_skip_frame[0].scratch =
+ self->private_data.s_skip_frame[0].scratch =
(((uint32_t)(3)) << (1 + (v_flags & 7)));
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
- if (self->private_impl.c_skip_frame[0].scratch >
+ if (self->private_data.s_skip_frame[0].scratch >
((uint64_t)(io1_a_src - iop_a_src))) {
- self->private_impl.c_skip_frame[0].scratch -= io1_a_src - iop_a_src;
+ self->private_data.s_skip_frame[0].scratch -=
+ ((uint64_t)(io1_a_src - iop_a_src));
iop_a_src = io1_a_src;
status = wuffs_base__suspension__short_read;
goto suspend;
}
- iop_a_src += self->private_impl.c_skip_frame[0].scratch;
+ iop_a_src += self->private_data.s_skip_frame[0].scratch;
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
@@ -8129,7 +8905,7 @@
iop_a_src++;
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
status = wuffs_gif__decoder__skip_blocks(self, a_src);
@@ -8146,19 +8922,19 @@
goto ok;
ok:
- self->private_impl.c_skip_frame[0].coro_susp_point = 0;
+ self->private_impl.p_skip_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_skip_frame[0].coro_susp_point = coro_susp_point;
+ self->private_impl.p_skip_frame[0] = coro_susp_point;
goto exit;
exit:
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -8178,16 +8954,21 @@
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return (self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
- : wuffs_base__error__check_wuffs_version_missing;
+ : wuffs_base__error__initialize_not_called;
}
if (!a_dst) {
self->private_impl.magic = WUFFS_BASE__DISABLED;
return wuffs_base__error__bad_argument;
}
+ if ((self->private_impl.active_coroutine != 0) &&
+ (self->private_impl.active_coroutine != 3)) {
+ self->private_impl.magic = WUFFS_BASE__DISABLED;
+ return wuffs_base__error__interleaved_coroutine_calls;
+ }
+ self->private_impl.active_coroutine = 0;
wuffs_base__status status = NULL;
- uint32_t coro_susp_point =
- self->private_impl.c_decode_frame[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_frame[0];
if (coro_susp_point) {
}
switch (coro_susp_point) {
@@ -8216,13 +8997,14 @@
goto ok;
ok:
- self->private_impl.c_decode_frame[0].coro_susp_point = 0;
+ self->private_impl.p_decode_frame[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_frame[0].coro_susp_point = coro_susp_point;
+ self->private_impl.p_decode_frame[0] = coro_susp_point;
+ self->private_impl.active_coroutine = 3;
goto exit;
exit:
@@ -8242,7 +9024,7 @@
self->private_impl.f_gc_transparent_index = 0;
self->private_impl.f_gc_disposal = 0;
self->private_impl.f_gc_duration = 0;
- return ((wuffs_base__empty_struct){});
+ return wuffs_base__make_empty_struct();
}
// -------- func gif.decoder.decode_up_to_id_part1
@@ -8255,10 +9037,8 @@
uint8_t v_block_type = 0;
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -8271,8 +9051,7 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point =
- self->private_impl.c_decode_up_to_id_part1[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_up_to_id_part1[0];
if (coro_susp_point) {
}
switch (coro_susp_point) {
@@ -8283,13 +9062,14 @@
(a_src.private_impl.buf
? wuffs_base__u64__sat_add(
a_src.private_impl.buf->meta.pos,
- iop_a_src - a_src.private_impl.buf->data.ptr)
+ ((uint64_t)(iop_a_src - a_src.private_impl.buf->data.ptr)))
: 0);
} else if (self->private_impl.f_frame_config_io_position !=
(a_src.private_impl.buf
? wuffs_base__u64__sat_add(
a_src.private_impl.buf->meta.pos,
- iop_a_src - a_src.private_impl.buf->data.ptr)
+ ((uint64_t)(iop_a_src -
+ a_src.private_impl.buf->data.ptr)))
: 0)) {
status = wuffs_base__error__bad_restart;
goto exit;
@@ -8309,7 +9089,7 @@
if (v_block_type == 33) {
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
status = wuffs_gif__decoder__decode_extension(self, a_src);
@@ -8323,7 +9103,7 @@
} else if (v_block_type == 44) {
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
status = wuffs_gif__decoder__decode_id_part0(self, a_src);
@@ -8347,20 +9127,19 @@
goto ok;
ok:
- self->private_impl.c_decode_up_to_id_part1[0].coro_susp_point = 0;
+ self->private_impl.p_decode_up_to_id_part1[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_up_to_id_part1[0].coro_susp_point =
- coro_susp_point;
+ self->private_impl.p_decode_up_to_id_part1[0] = coro_susp_point;
goto exit;
exit:
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -8373,14 +9152,12 @@
wuffs_base__io_reader a_src) {
wuffs_base__status status = NULL;
- uint8_t v_c[6] = {};
+ uint8_t v_c[6] = {0};
uint32_t v_i = 0;
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -8393,11 +9170,10 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point =
- self->private_impl.c_decode_header[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_header[0];
if (coro_susp_point) {
- memcpy(v_c, self->private_impl.c_decode_header[0].v_c, sizeof(v_c));
- v_i = self->private_impl.c_decode_header[0].v_i;
+ memcpy(v_c, self->private_data.s_decode_header[0].v_c, sizeof(v_c));
+ v_i = self->private_data.s_decode_header[0].v_i;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -8422,21 +9198,21 @@
goto ok;
ok:
- self->private_impl.c_decode_header[0].coro_susp_point = 0;
+ self->private_impl.p_decode_header[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_header[0].coro_susp_point = coro_susp_point;
- memcpy(self->private_impl.c_decode_header[0].v_c, v_c, sizeof(v_c));
- self->private_impl.c_decode_header[0].v_i = v_i;
+ self->private_impl.p_decode_header[0] = coro_susp_point;
+ memcpy(self->private_data.s_decode_header[0].v_c, v_c, sizeof(v_c));
+ self->private_data.s_decode_header[0].v_i = v_i;
goto exit;
exit:
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -8455,10 +9231,8 @@
uint32_t v_argb = 0;
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -8471,12 +9245,12 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point = self->private_impl.c_decode_lsd[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_lsd[0];
if (coro_susp_point) {
- v_flags = self->private_impl.c_decode_lsd[0].v_flags;
+ v_flags = self->private_data.s_decode_lsd[0].v_flags;
v_num_palette_entries =
- self->private_impl.c_decode_lsd[0].v_num_palette_entries;
- v_i = self->private_impl.c_decode_lsd[0].v_i;
+ self->private_data.s_decode_lsd[0].v_num_palette_entries;
+ v_i = self->private_data.s_decode_lsd[0].v_i;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -8488,15 +9262,15 @@
t_0 = ((uint32_t)(wuffs_base__load_u16le(iop_a_src)));
iop_a_src += 2;
} else {
- self->private_impl.c_decode_lsd[0].scratch = 0;
+ self->private_data.s_decode_lsd[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
status = wuffs_base__suspension__short_read;
goto suspend;
}
- uint64_t* scratch = &self->private_impl.c_decode_lsd[0].scratch;
- uint32_t num_bits_0 = *scratch >> 56;
+ uint64_t* scratch = &self->private_data.s_decode_lsd[0].scratch;
+ uint32_t num_bits_0 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_0;
@@ -8517,15 +9291,15 @@
t_1 = ((uint32_t)(wuffs_base__load_u16le(iop_a_src)));
iop_a_src += 2;
} else {
- self->private_impl.c_decode_lsd[0].scratch = 0;
+ self->private_data.s_decode_lsd[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
status = wuffs_base__suspension__short_read;
goto suspend;
}
- uint64_t* scratch = &self->private_impl.c_decode_lsd[0].scratch;
- uint32_t num_bits_1 = *scratch >> 56;
+ uint64_t* scratch = &self->private_data.s_decode_lsd[0].scratch;
+ uint32_t num_bits_1 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_1;
@@ -8548,16 +9322,17 @@
uint8_t t_2 = *iop_a_src++;
v_flags = t_2;
}
- self->private_impl.c_decode_lsd[0].scratch = 2;
+ self->private_data.s_decode_lsd[0].scratch = 2;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
- if (self->private_impl.c_decode_lsd[0].scratch >
+ if (self->private_data.s_decode_lsd[0].scratch >
((uint64_t)(io1_a_src - iop_a_src))) {
- self->private_impl.c_decode_lsd[0].scratch -= io1_a_src - iop_a_src;
+ self->private_data.s_decode_lsd[0].scratch -=
+ ((uint64_t)(io1_a_src - iop_a_src));
iop_a_src = io1_a_src;
status = wuffs_base__suspension__short_read;
goto suspend;
}
- iop_a_src += self->private_impl.c_decode_lsd[0].scratch;
+ iop_a_src += self->private_data.s_decode_lsd[0].scratch;
if ((v_flags & 128) != 0) {
v_num_palette_entries = (((uint32_t)(1)) << (1 + (v_flags & 7)));
v_i = 0;
@@ -8569,15 +9344,15 @@
t_3 = ((uint32_t)(wuffs_base__load_u24be(iop_a_src)));
iop_a_src += 3;
} else {
- self->private_impl.c_decode_lsd[0].scratch = 0;
+ self->private_data.s_decode_lsd[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
status = wuffs_base__suspension__short_read;
goto suspend;
}
- uint64_t* scratch = &self->private_impl.c_decode_lsd[0].scratch;
- uint32_t num_bits_3 = *scratch & 0xFF;
+ uint64_t* scratch = &self->private_data.s_decode_lsd[0].scratch;
+ uint32_t num_bits_3 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_3);
@@ -8592,44 +9367,44 @@
v_argb = t_3;
}
v_argb |= 4278190080;
- self->private_impl.f_palettes[0][((4 * v_i) + 0)] =
+ self->private_data.f_palettes[0][((4 * v_i) + 0)] =
((uint8_t)(((v_argb >> 0) & 255)));
- self->private_impl.f_palettes[0][((4 * v_i) + 1)] =
+ self->private_data.f_palettes[0][((4 * v_i) + 1)] =
((uint8_t)(((v_argb >> 8) & 255)));
- self->private_impl.f_palettes[0][((4 * v_i) + 2)] =
+ self->private_data.f_palettes[0][((4 * v_i) + 2)] =
((uint8_t)(((v_argb >> 16) & 255)));
- self->private_impl.f_palettes[0][((4 * v_i) + 3)] =
+ self->private_data.f_palettes[0][((4 * v_i) + 3)] =
((uint8_t)(((v_argb >> 24) & 255)));
v_i += 1;
}
while (v_i < 256) {
- self->private_impl.f_palettes[0][((4 * v_i) + 0)] = 0;
- self->private_impl.f_palettes[0][((4 * v_i) + 1)] = 0;
- self->private_impl.f_palettes[0][((4 * v_i) + 2)] = 0;
- self->private_impl.f_palettes[0][((4 * v_i) + 3)] = 255;
+ self->private_data.f_palettes[0][((4 * v_i) + 0)] = 0;
+ self->private_data.f_palettes[0][((4 * v_i) + 1)] = 0;
+ self->private_data.f_palettes[0][((4 * v_i) + 2)] = 0;
+ self->private_data.f_palettes[0][((4 * v_i) + 3)] = 255;
v_i += 1;
}
}
goto ok;
ok:
- self->private_impl.c_decode_lsd[0].coro_susp_point = 0;
+ self->private_impl.p_decode_lsd[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_lsd[0].coro_susp_point = coro_susp_point;
- self->private_impl.c_decode_lsd[0].v_flags = v_flags;
- self->private_impl.c_decode_lsd[0].v_num_palette_entries =
+ self->private_impl.p_decode_lsd[0] = coro_susp_point;
+ self->private_data.s_decode_lsd[0].v_flags = v_flags;
+ self->private_data.s_decode_lsd[0].v_num_palette_entries =
v_num_palette_entries;
- self->private_impl.c_decode_lsd[0].v_i = v_i;
+ self->private_data.s_decode_lsd[0].v_i = v_i;
goto exit;
exit:
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -8645,10 +9420,8 @@
uint8_t v_label = 0;
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -8661,8 +9434,7 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point =
- self->private_impl.c_decode_extension[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_extension[0];
if (coro_susp_point) {
}
switch (coro_susp_point) {
@@ -8680,7 +9452,7 @@
if (v_label == 249) {
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
status = wuffs_gif__decoder__decode_gc(self, a_src);
@@ -8696,7 +9468,7 @@
} else if (v_label == 255) {
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
status = wuffs_gif__decoder__decode_ae(self, a_src);
@@ -8712,7 +9484,7 @@
}
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
status = wuffs_gif__decoder__skip_blocks(self, a_src);
@@ -8726,19 +9498,19 @@
goto ok;
ok:
- self->private_impl.c_decode_extension[0].coro_susp_point = 0;
+ self->private_impl.p_decode_extension[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_extension[0].coro_susp_point = coro_susp_point;
+ self->private_impl.p_decode_extension[0] = coro_susp_point;
goto exit;
exit:
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -8754,10 +9526,8 @@
uint8_t v_block_size = 0;
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -8770,8 +9540,7 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point =
- self->private_impl.c_skip_blocks[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_skip_blocks[0];
if (coro_susp_point) {
}
switch (coro_susp_point) {
@@ -8791,33 +9560,34 @@
status = NULL;
goto ok;
}
- self->private_impl.c_skip_blocks[0].scratch = ((uint32_t)(v_block_size));
+ self->private_data.s_skip_blocks[0].scratch = ((uint32_t)(v_block_size));
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
- if (self->private_impl.c_skip_blocks[0].scratch >
+ if (self->private_data.s_skip_blocks[0].scratch >
((uint64_t)(io1_a_src - iop_a_src))) {
- self->private_impl.c_skip_blocks[0].scratch -= io1_a_src - iop_a_src;
+ self->private_data.s_skip_blocks[0].scratch -=
+ ((uint64_t)(io1_a_src - iop_a_src));
iop_a_src = io1_a_src;
status = wuffs_base__suspension__short_read;
goto suspend;
}
- iop_a_src += self->private_impl.c_skip_blocks[0].scratch;
+ iop_a_src += self->private_data.s_skip_blocks[0].scratch;
}
goto ok;
ok:
- self->private_impl.c_skip_blocks[0].coro_susp_point = 0;
+ self->private_impl.p_skip_blocks[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_skip_blocks[0].coro_susp_point = coro_susp_point;
+ self->private_impl.p_skip_blocks[0] = coro_susp_point;
goto exit;
exit:
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -8836,10 +9606,8 @@
bool v_not_netscape = false;
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -8852,11 +9620,11 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point = self->private_impl.c_decode_ae[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_ae[0];
if (coro_susp_point) {
- v_block_size = self->private_impl.c_decode_ae[0].v_block_size;
- v_not_animexts = self->private_impl.c_decode_ae[0].v_not_animexts;
- v_not_netscape = self->private_impl.c_decode_ae[0].v_not_netscape;
+ v_block_size = self->private_data.s_decode_ae[0].v_block_size;
+ v_not_animexts = self->private_data.s_decode_ae[0].v_not_animexts;
+ v_not_netscape = self->private_data.s_decode_ae[0].v_not_netscape;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -8876,16 +9644,17 @@
goto ok;
}
if (v_block_size != 11) {
- self->private_impl.c_decode_ae[0].scratch = ((uint32_t)(v_block_size));
+ self->private_data.s_decode_ae[0].scratch = ((uint32_t)(v_block_size));
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
- if (self->private_impl.c_decode_ae[0].scratch >
+ if (self->private_data.s_decode_ae[0].scratch >
((uint64_t)(io1_a_src - iop_a_src))) {
- self->private_impl.c_decode_ae[0].scratch -= io1_a_src - iop_a_src;
+ self->private_data.s_decode_ae[0].scratch -=
+ ((uint64_t)(io1_a_src - iop_a_src));
iop_a_src = io1_a_src;
status = wuffs_base__suspension__short_read;
goto suspend;
}
- iop_a_src += self->private_impl.c_decode_ae[0].scratch;
+ iop_a_src += self->private_data.s_decode_ae[0].scratch;
goto label_0_break;
}
v_not_animexts = false;
@@ -8905,7 +9674,14 @@
(v_not_animexts || (v_c != wuffs_gif__animexts1dot0[v_block_size]));
v_not_netscape =
(v_not_netscape || (v_c != wuffs_gif__netscape2dot0[v_block_size]));
+#if defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wconversion"
+#endif
v_block_size += 1;
+#if defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
}
if (v_not_animexts && v_not_netscape) {
goto label_0_break;
@@ -8920,16 +9696,17 @@
v_block_size = t_2;
}
if (v_block_size != 3) {
- self->private_impl.c_decode_ae[0].scratch = ((uint32_t)(v_block_size));
+ self->private_data.s_decode_ae[0].scratch = ((uint32_t)(v_block_size));
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
- if (self->private_impl.c_decode_ae[0].scratch >
+ if (self->private_data.s_decode_ae[0].scratch >
((uint64_t)(io1_a_src - iop_a_src))) {
- self->private_impl.c_decode_ae[0].scratch -= io1_a_src - iop_a_src;
+ self->private_data.s_decode_ae[0].scratch -=
+ ((uint64_t)(io1_a_src - iop_a_src));
iop_a_src = io1_a_src;
status = wuffs_base__suspension__short_read;
goto suspend;
}
- iop_a_src += self->private_impl.c_decode_ae[0].scratch;
+ iop_a_src += self->private_data.s_decode_ae[0].scratch;
goto label_0_break;
}
{
@@ -8942,16 +9719,17 @@
v_c = t_3;
}
if (v_c != 1) {
- self->private_impl.c_decode_ae[0].scratch = 2;
+ self->private_data.s_decode_ae[0].scratch = 2;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
- if (self->private_impl.c_decode_ae[0].scratch >
+ if (self->private_data.s_decode_ae[0].scratch >
((uint64_t)(io1_a_src - iop_a_src))) {
- self->private_impl.c_decode_ae[0].scratch -= io1_a_src - iop_a_src;
+ self->private_data.s_decode_ae[0].scratch -=
+ ((uint64_t)(io1_a_src - iop_a_src));
iop_a_src = io1_a_src;
status = wuffs_base__suspension__short_read;
goto suspend;
}
- iop_a_src += self->private_impl.c_decode_ae[0].scratch;
+ iop_a_src += self->private_data.s_decode_ae[0].scratch;
goto label_0_break;
}
{
@@ -8961,15 +9739,15 @@
t_4 = ((uint32_t)(wuffs_base__load_u16le(iop_a_src)));
iop_a_src += 2;
} else {
- self->private_impl.c_decode_ae[0].scratch = 0;
+ self->private_data.s_decode_ae[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(9);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
status = wuffs_base__suspension__short_read;
goto suspend;
}
- uint64_t* scratch = &self->private_impl.c_decode_ae[0].scratch;
- uint32_t num_bits_4 = *scratch >> 56;
+ uint64_t* scratch = &self->private_data.s_decode_ae[0].scratch;
+ uint32_t num_bits_4 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_4;
@@ -8993,7 +9771,7 @@
label_0_break:;
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(10);
status = wuffs_gif__decoder__skip_blocks(self, a_src);
@@ -9007,22 +9785,22 @@
goto ok;
ok:
- self->private_impl.c_decode_ae[0].coro_susp_point = 0;
+ self->private_impl.p_decode_ae[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_ae[0].coro_susp_point = coro_susp_point;
- self->private_impl.c_decode_ae[0].v_block_size = v_block_size;
- self->private_impl.c_decode_ae[0].v_not_animexts = v_not_animexts;
- self->private_impl.c_decode_ae[0].v_not_netscape = v_not_netscape;
+ self->private_impl.p_decode_ae[0] = coro_susp_point;
+ self->private_data.s_decode_ae[0].v_block_size = v_block_size;
+ self->private_data.s_decode_ae[0].v_not_animexts = v_not_animexts;
+ self->private_data.s_decode_ae[0].v_not_netscape = v_not_netscape;
goto exit;
exit:
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -9040,10 +9818,8 @@
uint16_t v_gc_duration_centiseconds = 0;
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -9056,7 +9832,7 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point = self->private_impl.c_decode_gc[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_gc[0];
if (coro_susp_point) {
}
switch (coro_susp_point) {
@@ -9104,20 +9880,20 @@
t_2 = wuffs_base__load_u16le(iop_a_src);
iop_a_src += 2;
} else {
- self->private_impl.c_decode_gc[0].scratch = 0;
+ self->private_data.s_decode_gc[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
status = wuffs_base__suspension__short_read;
goto suspend;
}
- uint64_t* scratch = &self->private_impl.c_decode_gc[0].scratch;
- uint32_t num_bits_2 = *scratch >> 56;
+ uint64_t* scratch = &self->private_data.s_decode_gc[0].scratch;
+ uint32_t num_bits_2 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_2;
if (num_bits_2 == 8) {
- t_2 = *scratch;
+ t_2 = ((uint16_t)(*scratch));
break;
}
num_bits_2 += 8;
@@ -9154,19 +9930,19 @@
goto ok;
ok:
- self->private_impl.c_decode_gc[0].coro_susp_point = 0;
+ self->private_impl.p_decode_gc[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_gc[0].coro_susp_point = coro_susp_point;
+ self->private_impl.p_decode_gc[0] = coro_susp_point;
goto exit;
exit:
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -9180,10 +9956,8 @@
wuffs_base__status status = NULL;
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -9196,8 +9970,7 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point =
- self->private_impl.c_decode_id_part0[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_id_part0[0];
if (coro_susp_point) {
}
switch (coro_susp_point) {
@@ -9210,15 +9983,15 @@
t_0 = ((uint32_t)(wuffs_base__load_u16le(iop_a_src)));
iop_a_src += 2;
} else {
- self->private_impl.c_decode_id_part0[0].scratch = 0;
+ self->private_data.s_decode_id_part0[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
status = wuffs_base__suspension__short_read;
goto suspend;
}
- uint64_t* scratch = &self->private_impl.c_decode_id_part0[0].scratch;
- uint32_t num_bits_0 = *scratch >> 56;
+ uint64_t* scratch = &self->private_data.s_decode_id_part0[0].scratch;
+ uint32_t num_bits_0 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_0;
@@ -9239,15 +10012,15 @@
t_1 = ((uint32_t)(wuffs_base__load_u16le(iop_a_src)));
iop_a_src += 2;
} else {
- self->private_impl.c_decode_id_part0[0].scratch = 0;
+ self->private_data.s_decode_id_part0[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
status = wuffs_base__suspension__short_read;
goto suspend;
}
- uint64_t* scratch = &self->private_impl.c_decode_id_part0[0].scratch;
- uint32_t num_bits_1 = *scratch >> 56;
+ uint64_t* scratch = &self->private_data.s_decode_id_part0[0].scratch;
+ uint32_t num_bits_1 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_1;
@@ -9268,15 +10041,15 @@
t_2 = ((uint32_t)(wuffs_base__load_u16le(iop_a_src)));
iop_a_src += 2;
} else {
- self->private_impl.c_decode_id_part0[0].scratch = 0;
+ self->private_data.s_decode_id_part0[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
status = wuffs_base__suspension__short_read;
goto suspend;
}
- uint64_t* scratch = &self->private_impl.c_decode_id_part0[0].scratch;
- uint32_t num_bits_2 = *scratch >> 56;
+ uint64_t* scratch = &self->private_data.s_decode_id_part0[0].scratch;
+ uint32_t num_bits_2 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_2;
@@ -9298,15 +10071,15 @@
t_3 = ((uint32_t)(wuffs_base__load_u16le(iop_a_src)));
iop_a_src += 2;
} else {
- self->private_impl.c_decode_id_part0[0].scratch = 0;
+ self->private_data.s_decode_id_part0[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
status = wuffs_base__suspension__short_read;
goto suspend;
}
- uint64_t* scratch = &self->private_impl.c_decode_id_part0[0].scratch;
- uint32_t num_bits_3 = *scratch >> 56;
+ uint64_t* scratch = &self->private_data.s_decode_id_part0[0].scratch;
+ uint32_t num_bits_3 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_3;
@@ -9332,19 +10105,19 @@
goto ok;
ok:
- self->private_impl.c_decode_id_part0[0].coro_susp_point = 0;
+ self->private_impl.p_decode_id_part0[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_id_part0[0].coro_susp_point = coro_susp_point;
+ self->private_impl.p_decode_id_part0[0] = coro_susp_point;
goto exit;
exit:
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -9362,14 +10135,12 @@
uint32_t v_num_palette_entries = 0;
uint32_t v_i = 0;
uint32_t v_argb = 0;
- wuffs_base__slice_u8 v_dst_palette = {};
+ wuffs_base__slice_u8 v_dst_palette = {0};
uint8_t v_lw = 0;
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -9382,12 +10153,11 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point =
- self->private_impl.c_decode_id_part1[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_id_part1[0];
if (coro_susp_point) {
v_num_palette_entries =
- self->private_impl.c_decode_id_part1[0].v_num_palette_entries;
- v_i = self->private_impl.c_decode_id_part1[0].v_i;
+ self->private_data.s_decode_id_part1[0].v_num_palette_entries;
+ v_i = self->private_data.s_decode_id_part1[0].v_i;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -9418,7 +10188,7 @@
t_1 = ((uint32_t)(wuffs_base__load_u24be(iop_a_src)));
iop_a_src += 3;
} else {
- self->private_impl.c_decode_id_part1[0].scratch = 0;
+ self->private_data.s_decode_id_part1[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
@@ -9426,8 +10196,8 @@
goto suspend;
}
uint64_t* scratch =
- &self->private_impl.c_decode_id_part1[0].scratch;
- uint32_t num_bits_1 = *scratch & 0xFF;
+ &self->private_data.s_decode_id_part1[0].scratch;
+ uint32_t num_bits_1 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_1);
@@ -9442,73 +10212,60 @@
v_argb = t_1;
}
v_argb |= 4278190080;
- self->private_impl.f_palettes[1][((4 * v_i) + 0)] =
+ self->private_data.f_palettes[1][((4 * v_i) + 0)] =
((uint8_t)(((v_argb >> 0) & 255)));
- self->private_impl.f_palettes[1][((4 * v_i) + 1)] =
+ self->private_data.f_palettes[1][((4 * v_i) + 1)] =
((uint8_t)(((v_argb >> 8) & 255)));
- self->private_impl.f_palettes[1][((4 * v_i) + 2)] =
+ self->private_data.f_palettes[1][((4 * v_i) + 2)] =
((uint8_t)(((v_argb >> 16) & 255)));
- self->private_impl.f_palettes[1][((4 * v_i) + 3)] =
+ self->private_data.f_palettes[1][((4 * v_i) + 3)] =
((uint8_t)(((v_argb >> 24) & 255)));
v_i += 1;
}
while (v_i < 256) {
- self->private_impl.f_palettes[1][((4 * v_i) + 0)] = 0;
- self->private_impl.f_palettes[1][((4 * v_i) + 1)] = 0;
- self->private_impl.f_palettes[1][((4 * v_i) + 2)] = 0;
- self->private_impl.f_palettes[1][((4 * v_i) + 3)] = 255;
+ self->private_data.f_palettes[1][((4 * v_i) + 0)] = 0;
+ self->private_data.f_palettes[1][((4 * v_i) + 1)] = 0;
+ self->private_data.f_palettes[1][((4 * v_i) + 2)] = 0;
+ self->private_data.f_palettes[1][((4 * v_i) + 3)] = 255;
v_i += 1;
}
} else if (self->private_impl.f_gc_has_transparent_index) {
wuffs_base__slice_u8__copy_from_slice(
- ((wuffs_base__slice_u8){
- .ptr = self->private_impl.f_palettes[1],
- .len = 1024,
- }),
- ((wuffs_base__slice_u8){
- .ptr = self->private_impl.f_palettes[0],
- .len = 1024,
- }));
+ wuffs_base__make_slice_u8(self->private_data.f_palettes[1], 1024),
+ wuffs_base__make_slice_u8(self->private_data.f_palettes[0], 1024));
} else {
self->private_impl.f_which_palette = 0;
}
if (self->private_impl.f_gc_has_transparent_index) {
- self->private_impl.f_palettes[1][(
+ self->private_data.f_palettes[1][(
(4 * ((uint32_t)(self->private_impl.f_gc_transparent_index))) + 0)] =
0;
- self->private_impl.f_palettes[1][(
+ self->private_data.f_palettes[1][(
(4 * ((uint32_t)(self->private_impl.f_gc_transparent_index))) + 1)] =
0;
- self->private_impl.f_palettes[1][(
+ self->private_data.f_palettes[1][(
(4 * ((uint32_t)(self->private_impl.f_gc_transparent_index))) + 2)] =
0;
- self->private_impl.f_palettes[1][(
+ self->private_data.f_palettes[1][(
(4 * ((uint32_t)(self->private_impl.f_gc_transparent_index))) + 3)] =
0;
}
v_dst_palette = wuffs_base__pixel_buffer__palette(a_dst);
if (((uint64_t)(v_dst_palette.len)) == 0) {
- v_dst_palette = ((wuffs_base__slice_u8){
- .ptr = self->private_impl.f_dst_palette,
- .len = 1024,
- });
+ v_dst_palette =
+ wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024);
}
- wuffs_base__pixel_swizzler__initialize(
+ wuffs_base__pixel_swizzler__prepare(
&self->private_impl.f_swizzler,
wuffs_base__pixel_buffer__pixel_format(a_dst), v_dst_palette,
1191444488,
- ((wuffs_base__slice_u8){
- .ptr = self->private_impl
- .f_palettes[self->private_impl.f_which_palette],
- .len = 1024,
- }));
+ wuffs_base__make_slice_u8(
+ self->private_data.f_palettes[self->private_impl.f_which_palette],
+ 1024));
if (self->private_impl.f_previous_lzw_decode_ended_abruptly) {
- (memset(&self->private_impl.f_lzw, 0, sizeof((wuffs_lzw__decoder){})),
- wuffs_base__ignore_check_wuffs_version_status(
- wuffs_lzw__decoder__check_wuffs_version(
- &self->private_impl.f_lzw, sizeof((wuffs_lzw__decoder){}),
- WUFFS_VERSION)),
- wuffs_base__return_empty_struct());
+ wuffs_base__ignore_status(wuffs_lzw__decoder__initialize(
+ &self->private_data.f_lzw, sizeof(wuffs_lzw__decoder), WUFFS_VERSION,
+ 0));
}
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
@@ -9523,28 +10280,28 @@
status = wuffs_gif__error__bad_literal_width;
goto exit;
}
- wuffs_lzw__decoder__set_literal_width(&self->private_impl.f_lzw,
+ wuffs_lzw__decoder__set_literal_width(&self->private_data.f_lzw,
((uint32_t)(v_lw)));
self->private_impl.f_previous_lzw_decode_ended_abruptly = true;
goto ok;
ok:
- self->private_impl.c_decode_id_part1[0].coro_susp_point = 0;
+ self->private_impl.p_decode_id_part1[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_id_part1[0].coro_susp_point = coro_susp_point;
- self->private_impl.c_decode_id_part1[0].v_num_palette_entries =
+ self->private_impl.p_decode_id_part1[0] = coro_susp_point;
+ self->private_data.s_decode_id_part1[0].v_num_palette_entries =
v_num_palette_entries;
- self->private_impl.c_decode_id_part1[0].v_i = v_i;
+ self->private_data.s_decode_id_part1[0].v_i = v_i;
goto exit;
exit:
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -9562,23 +10319,19 @@
uint64_t v_block_size = 0;
bool v_need_block_size = false;
uint64_t v_n_compressed = 0;
- wuffs_base__slice_u8 v_compressed = {};
- wuffs_base__io_reader v_r = {};
- wuffs_base__io_buffer u_r = {};
- uint8_t* iop_v_r = NULL;
- uint8_t* io1_v_r = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(u_r);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(iop_v_r);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_v_r);
+ wuffs_base__slice_u8 v_compressed = {0};
+ wuffs_base__io_reader v_r = wuffs_base__null_io_reader();
+ wuffs_base__io_buffer u_r WUFFS_BASE__POTENTIALLY_UNUSED =
+ wuffs_base__null_io_buffer();
+ uint8_t* iop_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_v_r WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
wuffs_base__status v_lzw_status = NULL;
wuffs_base__status v_copy_status = NULL;
- wuffs_base__slice_u8 v_uncompressed = {};
+ wuffs_base__slice_u8 v_uncompressed = {0};
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -9591,13 +10344,12 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point =
- self->private_impl.c_decode_id_part2[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_id_part2[0];
if (coro_susp_point) {
- v_block_size = self->private_impl.c_decode_id_part2[0].v_block_size;
+ v_block_size = self->private_data.s_decode_id_part2[0].v_block_size;
v_need_block_size =
- self->private_impl.c_decode_id_part2[0].v_need_block_size;
- v_lzw_status = self->private_impl.c_decode_id_part2[0].v_lzw_status;
+ self->private_data.s_decode_id_part2[0].v_need_block_size;
+ v_lzw_status = self->private_data.s_decode_id_part2[0].v_lzw_status;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -9639,10 +10391,8 @@
wuffs_base__io_reader__take(&iop_a_src, io1_a_src, v_n_compressed);
wuffs_base__slice_u8__copy_from_slice(
wuffs_base__slice_u8__subslice_i(
- ((wuffs_base__slice_u8){
- .ptr = self->private_impl.f_compressed,
- .len = 4096,
- }),
+ wuffs_base__make_slice_u8(self->private_data.f_compressed,
+ 4096),
self->private_impl.f_compressed_wi),
v_compressed);
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_compressed_wi,
@@ -9656,15 +10406,10 @@
goto label_1_break;
}
v_block_size = ((uint64_t)(wuffs_base__load_u8be(iop_a_src)));
- (iop_a_src += 1, wuffs_base__return_empty_struct());
+ (iop_a_src += 1, wuffs_base__make_empty_struct());
}
label_1_break:;
- if (((uint64_t)(self->private_impl.f_width)) <
- ((uint64_t)(a_workbuf.len))) {
- a_workbuf = wuffs_base__slice_u8__subslice_j(
- a_workbuf, ((uint64_t)(self->private_impl.f_width)));
- } else if (((uint64_t)(self->private_impl.f_width)) >
- ((uint64_t)(a_workbuf.len))) {
+ if (1 > ((uint64_t)(a_workbuf.len))) {
status = wuffs_base__error__bad_workbuf_length;
goto exit;
}
@@ -9683,18 +10428,16 @@
wuffs_base__io_reader__set(
&v_r, &u_r, &iop_v_r, &io1_v_r,
wuffs_base__slice_u8__subslice_ij(
- ((wuffs_base__slice_u8){
- .ptr = self->private_impl.f_compressed,
- .len = 4096,
- }),
+ wuffs_base__make_slice_u8(self->private_data.f_compressed,
+ 4096),
self->private_impl.f_compressed_ri,
self->private_impl.f_compressed_wi));
{
- u_r.meta.ri = iop_v_r - u_r.data.ptr;
+ u_r.meta.ri = ((size_t)(iop_v_r - u_r.data.ptr));
wuffs_base__status t_1 = wuffs_lzw__decoder__decode_io_writer(
- &self->private_impl.f_lzw,
- wuffs_base__utility__null_io_writer(&self->private_impl.f_util),
- v_r);
+ &self->private_data.f_lzw,
+ wuffs_base__utility__null_io_writer(), v_r,
+ wuffs_base__utility__null_slice_u8());
iop_v_r = u_r.data.ptr + u_r.meta.ri;
v_lzw_status = t_1;
}
@@ -9705,7 +10448,7 @@
iop_v_r = o_0_iop_v_r;
io1_v_r = o_0_io1_v_r;
}
- v_uncompressed = wuffs_lzw__decoder__flush(&self->private_impl.f_lzw);
+ v_uncompressed = wuffs_lzw__decoder__flush(&self->private_data.f_lzw);
if (((uint64_t)(v_uncompressed.len)) > 0) {
v_copy_status = wuffs_gif__decoder__copy_to_image_buffer(
self, a_dst, v_uncompressed);
@@ -9717,21 +10460,21 @@
if (wuffs_base__status__is_ok(v_lzw_status)) {
self->private_impl.f_previous_lzw_decode_ended_abruptly = false;
if (v_need_block_size || (v_block_size > 0)) {
- self->private_impl.c_decode_id_part2[0].scratch =
+ self->private_data.s_decode_id_part2[0].scratch =
((uint32_t)(v_block_size));
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
- if (self->private_impl.c_decode_id_part2[0].scratch >
+ if (self->private_data.s_decode_id_part2[0].scratch >
((uint64_t)(io1_a_src - iop_a_src))) {
- self->private_impl.c_decode_id_part2[0].scratch -=
- io1_a_src - iop_a_src;
+ self->private_data.s_decode_id_part2[0].scratch -=
+ ((uint64_t)(io1_a_src - iop_a_src));
iop_a_src = io1_a_src;
status = wuffs_base__suspension__short_read;
goto suspend;
}
- iop_a_src += self->private_impl.c_decode_id_part2[0].scratch;
+ iop_a_src += self->private_data.s_decode_id_part2[0].scratch;
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(4);
status = wuffs_gif__decoder__skip_blocks(self, a_src);
@@ -9762,25 +10505,33 @@
label_0_break:;
self->private_impl.f_compressed_ri = 0;
self->private_impl.f_compressed_wi = 0;
+ if ((self->private_impl.f_dst_y < self->private_impl.f_frame_rect_y1) &&
+ (self->private_impl.f_frame_rect_x0 !=
+ self->private_impl.f_frame_rect_x1) &&
+ (self->private_impl.f_frame_rect_y0 !=
+ self->private_impl.f_frame_rect_y1)) {
+ status = wuffs_base__error__not_enough_data;
+ goto exit;
+ }
goto ok;
ok:
- self->private_impl.c_decode_id_part2[0].coro_susp_point = 0;
+ self->private_impl.p_decode_id_part2[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_id_part2[0].coro_susp_point = coro_susp_point;
- self->private_impl.c_decode_id_part2[0].v_block_size = v_block_size;
- self->private_impl.c_decode_id_part2[0].v_need_block_size = v_need_block_size;
- self->private_impl.c_decode_id_part2[0].v_lzw_status = v_lzw_status;
+ self->private_impl.p_decode_id_part2[0] = coro_susp_point;
+ self->private_data.s_decode_id_part2[0].v_block_size = v_block_size;
+ self->private_data.s_decode_id_part2[0].v_need_block_size = v_need_block_size;
+ self->private_data.s_decode_id_part2[0].v_lzw_status = v_lzw_status;
goto exit;
exit:
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
return status;
@@ -9792,13 +10543,13 @@
wuffs_gif__decoder__copy_to_image_buffer(wuffs_gif__decoder* self,
wuffs_base__pixel_buffer* a_pb,
wuffs_base__slice_u8 a_src) {
- wuffs_base__slice_u8 v_dst = {};
- wuffs_base__slice_u8 v_src = {};
+ wuffs_base__slice_u8 v_dst = {0};
+ wuffs_base__slice_u8 v_src = {0};
uint64_t v_n = 0;
uint64_t v_src_ri = 0;
uint32_t v_bytes_per_pixel = 0;
uint32_t v_pixfmt = 0;
- wuffs_base__table_u8 v_tab = {};
+ wuffs_base__table_u8 v_tab = {0};
uint64_t v_i = 0;
uint64_t v_j = 0;
@@ -9814,7 +10565,7 @@
while (v_src_ri < ((uint64_t)(a_src.len))) {
v_src = wuffs_base__slice_u8__subslice_i(a_src, v_src_ri);
if (self->private_impl.f_dst_y >= self->private_impl.f_frame_rect_y1) {
- return wuffs_gif__error__too_much_pixel_data;
+ return wuffs_base__error__too_much_data;
}
v_dst = wuffs_base__table_u8__row(v_tab, self->private_impl.f_dst_y);
v_i = (((uint64_t)(self->private_impl.f_dst_x)) *
@@ -9829,10 +10580,7 @@
}
v_n = wuffs_base__pixel_swizzler__swizzle_packed(
&self->private_impl.f_swizzler, v_dst,
- ((wuffs_base__slice_u8){
- .ptr = self->private_impl.f_dst_palette,
- .len = 1024,
- }),
+ wuffs_base__make_slice_u8(self->private_data.f_dst_palette, 1024),
v_src);
wuffs_base__u64__sat_add_indirect(&v_src_ri, v_n);
wuffs_base__u32__sat_add_indirect(&self->private_impl.f_dst_x,
@@ -9840,7 +10588,7 @@
self->private_impl.f_dirty_y = wuffs_base__range_ie_u32__unite(
&self->private_impl.f_dirty_y,
wuffs_base__utility__make_range_ie_u32(
- &self->private_impl.f_util, self->private_impl.f_dst_y,
+ self->private_impl.f_dst_y,
wuffs_base__u32__sat_add(self->private_impl.f_dst_y, 1)));
}
if (self->private_impl.f_frame_rect_x1 <= self->private_impl.f_dst_x) {
@@ -9852,7 +10600,14 @@
while (
(self->private_impl.f_interlace > 0) &&
(self->private_impl.f_dst_y >= self->private_impl.f_frame_rect_y1)) {
+#if defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wconversion"
+#endif
self->private_impl.f_interlace -= 1;
+#if defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
self->private_impl.f_dst_y = wuffs_base__u32__sat_add(
self->private_impl.f_frame_rect_y0,
wuffs_gif__interlace_start[self->private_impl.f_interlace]);
@@ -9879,7 +10634,14 @@
while (
(self->private_impl.f_interlace > 0) &&
(self->private_impl.f_dst_y >= self->private_impl.f_frame_rect_y1)) {
+#if defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wconversion"
+#endif
self->private_impl.f_interlace -= 1;
+#if defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
self->private_impl.f_dst_y = wuffs_base__u32__sat_add(
self->private_impl.f_frame_rect_y0,
wuffs_gif__interlace_start[self->private_impl.f_interlace]);
@@ -9901,11 +10663,11 @@
// ---------------- Status Codes Implementations
-const char* wuffs_gzip__error__bad_checksum = "?gzip: bad checksum";
+const char* wuffs_gzip__error__bad_checksum = "#gzip: bad checksum";
const char* wuffs_gzip__error__bad_compression_method =
- "?gzip: bad compression method";
-const char* wuffs_gzip__error__bad_encoding_flags = "?gzip: bad encoding flags";
-const char* wuffs_gzip__error__bad_header = "?gzip: bad header";
+ "#gzip: bad compression method";
+const char* wuffs_gzip__error__bad_encoding_flags = "#gzip: bad encoding flags";
+const char* wuffs_gzip__error__bad_header = "#gzip: bad header";
// ---------------- Private Consts
@@ -9916,9 +10678,10 @@
// ---------------- Initializer Implementations
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
-wuffs_gzip__decoder__check_wuffs_version(wuffs_gzip__decoder* self,
- size_t sizeof_star_self,
- uint64_t wuffs_version) {
+wuffs_gzip__decoder__initialize(wuffs_gzip__decoder* self,
+ size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags) {
if (!self) {
return wuffs_base__error__bad_receiver;
}
@@ -9929,21 +10692,44 @@
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
return wuffs_base__error__bad_wuffs_version;
}
- if (self->private_impl.magic != 0) {
- return wuffs_base__error__check_wuffs_version_not_applicable;
+
+ if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
+// The whole point of this if-check is to detect an uninitialized *self.
+// We disable the warning on GCC. Clang-5.0 does not have this warning.
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+#endif
+ if (self->private_impl.magic != 0) {
+ return wuffs_base__error__initialize_falsely_claimed_already_zeroed;
+ }
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
+ } else {
+ void* p = &(self->private_impl);
+ size_t n = sizeof(self->private_impl);
+ if ((initialize_flags &
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
+ p = self;
+ n = sizeof(*self);
+ initialize_flags |= WUFFS_INITIALIZE__ALREADY_ZEROED;
+ }
+ memset(p, 0, n);
}
+
{
- wuffs_base__status z = wuffs_deflate__decoder__check_wuffs_version(
- &self->private_impl.f_flate, sizeof(self->private_impl.f_flate),
- WUFFS_VERSION);
+ wuffs_base__status z = wuffs_crc32__ieee_hasher__initialize(
+ &self->private_data.f_checksum, sizeof(self->private_data.f_checksum),
+ WUFFS_VERSION, initialize_flags);
if (z) {
return z;
}
}
{
- wuffs_base__status z = wuffs_crc32__ieee_hasher__check_wuffs_version(
- &self->private_impl.f_checksum, sizeof(self->private_impl.f_checksum),
- WUFFS_VERSION);
+ wuffs_base__status z = wuffs_deflate__decoder__initialize(
+ &self->private_data.f_flate, sizeof(self->private_data.f_flate),
+ WUFFS_VERSION, initialize_flags);
if (z) {
return z;
}
@@ -9954,7 +10740,7 @@
size_t //
sizeof__wuffs_gzip__decoder() {
- return sizeof((wuffs_gzip__decoder){});
+ return sizeof(wuffs_gzip__decoder);
}
// ---------------- Function Implementations
@@ -9964,14 +10750,29 @@
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct //
wuffs_gzip__decoder__set_ignore_checksum(wuffs_gzip__decoder* self, bool a_ic) {
if (!self) {
- return ((wuffs_base__empty_struct){});
+ return wuffs_base__make_empty_struct();
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
- return ((wuffs_base__empty_struct){});
+ return wuffs_base__make_empty_struct();
}
self->private_impl.f_ignore_checksum = a_ic;
- return ((wuffs_base__empty_struct){});
+ return wuffs_base__make_empty_struct();
+}
+
+// -------- func gzip.decoder.workbuf_len
+
+WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 //
+wuffs_gzip__decoder__workbuf_len(const wuffs_gzip__decoder* self) {
+ if (!self) {
+ return wuffs_base__utility__make_range_ii_u64(0, 0);
+ }
+ if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
+ (self->private_impl.magic != WUFFS_BASE__DISABLED)) {
+ return wuffs_base__utility__make_range_ii_u64(0, 0);
+ }
+
+ return wuffs_base__utility__make_range_ii_u64(1, 1);
}
// -------- func gzip.decoder.decode_io_writer
@@ -9979,15 +10780,22 @@
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_gzip__decoder__decode_io_writer(wuffs_gzip__decoder* self,
wuffs_base__io_writer a_dst,
- wuffs_base__io_reader a_src) {
+ wuffs_base__io_reader a_src,
+ wuffs_base__slice_u8 a_workbuf) {
if (!self) {
return wuffs_base__error__bad_receiver;
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return (self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
- : wuffs_base__error__check_wuffs_version_missing;
+ : wuffs_base__error__initialize_not_called;
}
+ if ((self->private_impl.active_coroutine != 0) &&
+ (self->private_impl.active_coroutine != 1)) {
+ self->private_impl.magic = WUFFS_BASE__DISABLED;
+ return wuffs_base__error__interleaved_coroutine_calls;
+ }
+ self->private_impl.active_coroutine = 0;
wuffs_base__status status = NULL;
uint8_t v_c = 0;
@@ -10000,10 +10808,8 @@
uint32_t v_decoded_length_want = 0;
uint8_t* iop_a_dst = NULL;
- uint8_t* io0_a_dst = NULL;
- uint8_t* io1_a_dst = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_dst);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_dst);
+ uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst.private_impl.buf) {
iop_a_dst =
a_dst.private_impl.buf->data.ptr + a_dst.private_impl.buf->meta.wi;
@@ -10019,10 +10825,8 @@
io1_a_dst = a_dst.private_impl.limit;
}
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -10035,14 +10839,13 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point =
- self->private_impl.c_decode_io_writer[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_io_writer[0];
if (coro_susp_point) {
- v_flags = self->private_impl.c_decode_io_writer[0].v_flags;
- v_checksum_got = self->private_impl.c_decode_io_writer[0].v_checksum_got;
+ v_flags = self->private_data.s_decode_io_writer[0].v_flags;
+ v_checksum_got = self->private_data.s_decode_io_writer[0].v_checksum_got;
v_decoded_length_got =
- self->private_impl.c_decode_io_writer[0].v_decoded_length_got;
- v_checksum_want = self->private_impl.c_decode_io_writer[0].v_checksum_want;
+ self->private_data.s_decode_io_writer[0].v_decoded_length_got;
+ v_checksum_want = self->private_data.s_decode_io_writer[0].v_checksum_want;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -10095,16 +10898,17 @@
uint8_t t_3 = *iop_a_src++;
v_flags = t_3;
}
- self->private_impl.c_decode_io_writer[0].scratch = 6;
+ self->private_data.s_decode_io_writer[0].scratch = 6;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
- if (self->private_impl.c_decode_io_writer[0].scratch >
+ if (self->private_data.s_decode_io_writer[0].scratch >
((uint64_t)(io1_a_src - iop_a_src))) {
- self->private_impl.c_decode_io_writer[0].scratch -= io1_a_src - iop_a_src;
+ self->private_data.s_decode_io_writer[0].scratch -=
+ ((uint64_t)(io1_a_src - iop_a_src));
iop_a_src = io1_a_src;
status = wuffs_base__suspension__short_read;
goto suspend;
}
- iop_a_src += self->private_impl.c_decode_io_writer[0].scratch;
+ iop_a_src += self->private_data.s_decode_io_writer[0].scratch;
if ((v_flags & 4) != 0) {
{
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
@@ -10113,7 +10917,7 @@
t_4 = wuffs_base__load_u16le(iop_a_src);
iop_a_src += 2;
} else {
- self->private_impl.c_decode_io_writer[0].scratch = 0;
+ self->private_data.s_decode_io_writer[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(7);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
@@ -10121,13 +10925,13 @@
goto suspend;
}
uint64_t* scratch =
- &self->private_impl.c_decode_io_writer[0].scratch;
- uint32_t num_bits_4 = *scratch >> 56;
+ &self->private_data.s_decode_io_writer[0].scratch;
+ uint32_t num_bits_4 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_4;
if (num_bits_4 == 8) {
- t_4 = *scratch;
+ t_4 = ((uint16_t)(*scratch));
break;
}
num_bits_4 += 8;
@@ -10136,17 +10940,17 @@
}
v_xlen = t_4;
}
- self->private_impl.c_decode_io_writer[0].scratch = ((uint32_t)(v_xlen));
+ self->private_data.s_decode_io_writer[0].scratch = ((uint32_t)(v_xlen));
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(8);
- if (self->private_impl.c_decode_io_writer[0].scratch >
+ if (self->private_data.s_decode_io_writer[0].scratch >
((uint64_t)(io1_a_src - iop_a_src))) {
- self->private_impl.c_decode_io_writer[0].scratch -=
- io1_a_src - iop_a_src;
+ self->private_data.s_decode_io_writer[0].scratch -=
+ ((uint64_t)(io1_a_src - iop_a_src));
iop_a_src = io1_a_src;
status = wuffs_base__suspension__short_read;
goto suspend;
}
- iop_a_src += self->private_impl.c_decode_io_writer[0].scratch;
+ iop_a_src += self->private_data.s_decode_io_writer[0].scratch;
}
if ((v_flags & 8) != 0) {
while (true) {
@@ -10183,17 +10987,17 @@
label_1_break:;
}
if ((v_flags & 2) != 0) {
- self->private_impl.c_decode_io_writer[0].scratch = 2;
+ self->private_data.s_decode_io_writer[0].scratch = 2;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(11);
- if (self->private_impl.c_decode_io_writer[0].scratch >
+ if (self->private_data.s_decode_io_writer[0].scratch >
((uint64_t)(io1_a_src - iop_a_src))) {
- self->private_impl.c_decode_io_writer[0].scratch -=
- io1_a_src - iop_a_src;
+ self->private_data.s_decode_io_writer[0].scratch -=
+ ((uint64_t)(io1_a_src - iop_a_src));
iop_a_src = io1_a_src;
status = wuffs_base__suspension__short_read;
goto suspend;
}
- iop_a_src += self->private_impl.c_decode_io_writer[0].scratch;
+ iop_a_src += self->private_data.s_decode_io_writer[0].scratch;
}
if ((v_flags & 224) != 0) {
status = wuffs_gzip__error__bad_encoding_flags;
@@ -10204,14 +11008,14 @@
{
if (a_dst.private_impl.buf) {
a_dst.private_impl.buf->meta.wi =
- iop_a_dst - a_dst.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_dst - a_dst.private_impl.buf->data.ptr));
}
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
wuffs_base__status t_7 = wuffs_deflate__decoder__decode_io_writer(
- &self->private_impl.f_flate, a_dst, a_src);
+ &self->private_data.f_flate, a_dst, a_src, a_workbuf);
if (a_dst.private_impl.buf) {
iop_a_dst = a_dst.private_impl.buf->data.ptr +
a_dst.private_impl.buf->meta.wi;
@@ -10224,11 +11028,10 @@
}
if (!self->private_impl.f_ignore_checksum) {
v_checksum_got = wuffs_crc32__ieee_hasher__update(
- &self->private_impl.f_checksum,
- ((wuffs_base__slice_u8){
- .ptr = a_dst.private_impl.mark,
- .len = (size_t)(iop_a_dst - a_dst.private_impl.mark),
- }));
+ &self->private_data.f_checksum,
+ wuffs_base__make_slice_u8(
+ a_dst.private_impl.mark,
+ (size_t)(iop_a_dst - a_dst.private_impl.mark)));
v_decoded_length_got += ((uint32_t)(
(((uint64_t)(iop_a_dst - a_dst.private_impl.mark)) & 4294967295)));
}
@@ -10246,20 +11049,20 @@
t_8 = wuffs_base__load_u32le(iop_a_src);
iop_a_src += 4;
} else {
- self->private_impl.c_decode_io_writer[0].scratch = 0;
+ self->private_data.s_decode_io_writer[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(14);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
status = wuffs_base__suspension__short_read;
goto suspend;
}
- uint64_t* scratch = &self->private_impl.c_decode_io_writer[0].scratch;
- uint32_t num_bits_8 = *scratch >> 56;
+ uint64_t* scratch = &self->private_data.s_decode_io_writer[0].scratch;
+ uint32_t num_bits_8 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_8;
if (num_bits_8 == 24) {
- t_8 = *scratch;
+ t_8 = ((uint32_t)(*scratch));
break;
}
num_bits_8 += 8;
@@ -10275,20 +11078,20 @@
t_9 = wuffs_base__load_u32le(iop_a_src);
iop_a_src += 4;
} else {
- self->private_impl.c_decode_io_writer[0].scratch = 0;
+ self->private_data.s_decode_io_writer[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(16);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
status = wuffs_base__suspension__short_read;
goto suspend;
}
- uint64_t* scratch = &self->private_impl.c_decode_io_writer[0].scratch;
- uint32_t num_bits_9 = *scratch >> 56;
+ uint64_t* scratch = &self->private_data.s_decode_io_writer[0].scratch;
+ uint32_t num_bits_9 = ((uint32_t)(*scratch >> 56));
*scratch <<= 8;
*scratch >>= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << num_bits_9;
if (num_bits_9 == 24) {
- t_9 = *scratch;
+ t_9 = ((uint32_t)(*scratch));
break;
}
num_bits_9 += 8;
@@ -10306,28 +11109,29 @@
goto ok;
ok:
- self->private_impl.c_decode_io_writer[0].coro_susp_point = 0;
+ self->private_impl.p_decode_io_writer[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_io_writer[0].coro_susp_point = coro_susp_point;
- self->private_impl.c_decode_io_writer[0].v_flags = v_flags;
- self->private_impl.c_decode_io_writer[0].v_checksum_got = v_checksum_got;
- self->private_impl.c_decode_io_writer[0].v_decoded_length_got =
+ self->private_impl.p_decode_io_writer[0] = coro_susp_point;
+ self->private_impl.active_coroutine = 1;
+ self->private_data.s_decode_io_writer[0].v_flags = v_flags;
+ self->private_data.s_decode_io_writer[0].v_checksum_got = v_checksum_got;
+ self->private_data.s_decode_io_writer[0].v_decoded_length_got =
v_decoded_length_got;
- self->private_impl.c_decode_io_writer[0].v_checksum_want = v_checksum_want;
+ self->private_data.s_decode_io_writer[0].v_checksum_want = v_checksum_want;
goto exit;
exit:
if (a_dst.private_impl.buf) {
a_dst.private_impl.buf->meta.wi =
- iop_a_dst - a_dst.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_dst - a_dst.private_impl.buf->data.ptr));
}
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
if (wuffs_base__status__is_error(status)) {
@@ -10343,14 +11147,14 @@
// ---------------- Status Codes Implementations
-const char* wuffs_zlib__error__bad_checksum = "?zlib: bad checksum";
+const char* wuffs_zlib__error__bad_checksum = "#zlib: bad checksum";
const char* wuffs_zlib__error__bad_compression_method =
- "?zlib: bad compression method";
+ "#zlib: bad compression method";
const char* wuffs_zlib__error__bad_compression_window_size =
- "?zlib: bad compression window size";
-const char* wuffs_zlib__error__bad_parity_check = "?zlib: bad parity check";
+ "#zlib: bad compression window size";
+const char* wuffs_zlib__error__bad_parity_check = "#zlib: bad parity check";
const char* wuffs_zlib__error__todo_unsupported_preset_dictionary =
- "?zlib: TODO: unsupported preset dictionary";
+ "#zlib: TODO: unsupported preset dictionary";
// ---------------- Private Consts
@@ -10361,9 +11165,10 @@
// ---------------- Initializer Implementations
wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //
-wuffs_zlib__decoder__check_wuffs_version(wuffs_zlib__decoder* self,
- size_t sizeof_star_self,
- uint64_t wuffs_version) {
+wuffs_zlib__decoder__initialize(wuffs_zlib__decoder* self,
+ size_t sizeof_star_self,
+ uint64_t wuffs_version,
+ uint32_t initialize_flags) {
if (!self) {
return wuffs_base__error__bad_receiver;
}
@@ -10374,21 +11179,44 @@
(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {
return wuffs_base__error__bad_wuffs_version;
}
- if (self->private_impl.magic != 0) {
- return wuffs_base__error__check_wuffs_version_not_applicable;
+
+ if ((initialize_flags & WUFFS_INITIALIZE__ALREADY_ZEROED) != 0) {
+// The whole point of this if-check is to detect an uninitialized *self.
+// We disable the warning on GCC. Clang-5.0 does not have this warning.
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+#endif
+ if (self->private_impl.magic != 0) {
+ return wuffs_base__error__initialize_falsely_claimed_already_zeroed;
+ }
+#if !defined(__clang__) && defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
+ } else {
+ void* p = &(self->private_impl);
+ size_t n = sizeof(self->private_impl);
+ if ((initialize_flags &
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED) == 0) {
+ p = self;
+ n = sizeof(*self);
+ initialize_flags |= WUFFS_INITIALIZE__ALREADY_ZEROED;
+ }
+ memset(p, 0, n);
}
+
{
- wuffs_base__status z = wuffs_deflate__decoder__check_wuffs_version(
- &self->private_impl.f_flate, sizeof(self->private_impl.f_flate),
- WUFFS_VERSION);
+ wuffs_base__status z = wuffs_adler32__hasher__initialize(
+ &self->private_data.f_checksum, sizeof(self->private_data.f_checksum),
+ WUFFS_VERSION, initialize_flags);
if (z) {
return z;
}
}
{
- wuffs_base__status z = wuffs_adler32__hasher__check_wuffs_version(
- &self->private_impl.f_checksum, sizeof(self->private_impl.f_checksum),
- WUFFS_VERSION);
+ wuffs_base__status z = wuffs_deflate__decoder__initialize(
+ &self->private_data.f_flate, sizeof(self->private_data.f_flate),
+ WUFFS_VERSION, initialize_flags);
if (z) {
return z;
}
@@ -10399,7 +11227,7 @@
size_t //
sizeof__wuffs_zlib__decoder() {
- return sizeof((wuffs_zlib__decoder){});
+ return sizeof(wuffs_zlib__decoder);
}
// ---------------- Function Implementations
@@ -10409,14 +11237,29 @@
WUFFS_BASE__MAYBE_STATIC wuffs_base__empty_struct //
wuffs_zlib__decoder__set_ignore_checksum(wuffs_zlib__decoder* self, bool a_ic) {
if (!self) {
- return ((wuffs_base__empty_struct){});
+ return wuffs_base__make_empty_struct();
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
- return ((wuffs_base__empty_struct){});
+ return wuffs_base__make_empty_struct();
}
self->private_impl.f_ignore_checksum = a_ic;
- return ((wuffs_base__empty_struct){});
+ return wuffs_base__make_empty_struct();
+}
+
+// -------- func zlib.decoder.workbuf_len
+
+WUFFS_BASE__MAYBE_STATIC wuffs_base__range_ii_u64 //
+wuffs_zlib__decoder__workbuf_len(const wuffs_zlib__decoder* self) {
+ if (!self) {
+ return wuffs_base__utility__make_range_ii_u64(0, 0);
+ }
+ if ((self->private_impl.magic != WUFFS_BASE__MAGIC) &&
+ (self->private_impl.magic != WUFFS_BASE__DISABLED)) {
+ return wuffs_base__utility__make_range_ii_u64(0, 0);
+ }
+
+ return wuffs_base__utility__make_range_ii_u64(1, 1);
}
// -------- func zlib.decoder.decode_io_writer
@@ -10424,15 +11267,22 @@
WUFFS_BASE__MAYBE_STATIC wuffs_base__status //
wuffs_zlib__decoder__decode_io_writer(wuffs_zlib__decoder* self,
wuffs_base__io_writer a_dst,
- wuffs_base__io_reader a_src) {
+ wuffs_base__io_reader a_src,
+ wuffs_base__slice_u8 a_workbuf) {
if (!self) {
return wuffs_base__error__bad_receiver;
}
if (self->private_impl.magic != WUFFS_BASE__MAGIC) {
return (self->private_impl.magic == WUFFS_BASE__DISABLED)
? wuffs_base__error__disabled_by_previous_error
- : wuffs_base__error__check_wuffs_version_missing;
+ : wuffs_base__error__initialize_not_called;
}
+ if ((self->private_impl.active_coroutine != 0) &&
+ (self->private_impl.active_coroutine != 1)) {
+ self->private_impl.magic = WUFFS_BASE__DISABLED;
+ return wuffs_base__error__interleaved_coroutine_calls;
+ }
+ self->private_impl.active_coroutine = 0;
wuffs_base__status status = NULL;
uint16_t v_x = 0;
@@ -10441,10 +11291,8 @@
uint32_t v_checksum_want = 0;
uint8_t* iop_a_dst = NULL;
- uint8_t* io0_a_dst = NULL;
- uint8_t* io1_a_dst = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_dst);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_dst);
+ uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_dst.private_impl.buf) {
iop_a_dst =
a_dst.private_impl.buf->data.ptr + a_dst.private_impl.buf->meta.wi;
@@ -10460,10 +11308,8 @@
io1_a_dst = a_dst.private_impl.limit;
}
uint8_t* iop_a_src = NULL;
- uint8_t* io0_a_src = NULL;
- uint8_t* io1_a_src = NULL;
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io0_a_src);
- WUFFS_BASE__IGNORE_POTENTIALLY_UNUSED_VARIABLE(io1_a_src);
+ uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
+ uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
if (a_src.private_impl.buf) {
iop_a_src =
a_src.private_impl.buf->data.ptr + a_src.private_impl.buf->meta.ri;
@@ -10476,10 +11322,9 @@
io1_a_src = a_src.private_impl.limit;
}
- uint32_t coro_susp_point =
- self->private_impl.c_decode_io_writer[0].coro_susp_point;
+ uint32_t coro_susp_point = self->private_impl.p_decode_io_writer[0];
if (coro_susp_point) {
- v_checksum_got = self->private_impl.c_decode_io_writer[0].v_checksum_got;
+ v_checksum_got = self->private_data.s_decode_io_writer[0].v_checksum_got;
}
switch (coro_susp_point) {
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
@@ -10491,20 +11336,20 @@
t_0 = wuffs_base__load_u16be(iop_a_src);
iop_a_src += 2;
} else {
- self->private_impl.c_decode_io_writer[0].scratch = 0;
+ self->private_data.s_decode_io_writer[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(2);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
status = wuffs_base__suspension__short_read;
goto suspend;
}
- uint64_t* scratch = &self->private_impl.c_decode_io_writer[0].scratch;
- uint32_t num_bits_0 = *scratch & 0xFF;
+ uint64_t* scratch = &self->private_data.s_decode_io_writer[0].scratch;
+ uint32_t num_bits_0 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_0);
if (num_bits_0 == 8) {
- t_0 = *scratch >> 48;
+ t_0 = ((uint16_t)(*scratch >> 48));
break;
}
num_bits_0 += 8;
@@ -10534,14 +11379,14 @@
{
if (a_dst.private_impl.buf) {
a_dst.private_impl.buf->meta.wi =
- iop_a_dst - a_dst.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_dst - a_dst.private_impl.buf->data.ptr));
}
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
wuffs_base__status t_1 = wuffs_deflate__decoder__decode_io_writer(
- &self->private_impl.f_flate, a_dst, a_src);
+ &self->private_data.f_flate, a_dst, a_src, a_workbuf);
if (a_dst.private_impl.buf) {
iop_a_dst = a_dst.private_impl.buf->data.ptr +
a_dst.private_impl.buf->meta.wi;
@@ -10554,11 +11399,10 @@
}
if (!self->private_impl.f_ignore_checksum) {
v_checksum_got = wuffs_adler32__hasher__update(
- &self->private_impl.f_checksum,
- ((wuffs_base__slice_u8){
- .ptr = a_dst.private_impl.mark,
- .len = (size_t)(iop_a_dst - a_dst.private_impl.mark),
- }));
+ &self->private_data.f_checksum,
+ wuffs_base__make_slice_u8(
+ a_dst.private_impl.mark,
+ (size_t)(iop_a_dst - a_dst.private_impl.mark)));
}
if (wuffs_base__status__is_ok(v_status)) {
goto label_0_break;
@@ -10574,20 +11418,20 @@
t_2 = wuffs_base__load_u32be(iop_a_src);
iop_a_src += 4;
} else {
- self->private_impl.c_decode_io_writer[0].scratch = 0;
+ self->private_data.s_decode_io_writer[0].scratch = 0;
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(5);
while (true) {
if (WUFFS_BASE__UNLIKELY(iop_a_src == io1_a_src)) {
status = wuffs_base__suspension__short_read;
goto suspend;
}
- uint64_t* scratch = &self->private_impl.c_decode_io_writer[0].scratch;
- uint32_t num_bits_2 = *scratch & 0xFF;
+ uint64_t* scratch = &self->private_data.s_decode_io_writer[0].scratch;
+ uint32_t num_bits_2 = ((uint32_t)(*scratch & 0xFF));
*scratch >>= 8;
*scratch <<= 8;
*scratch |= ((uint64_t)(*iop_a_src++)) << (56 - num_bits_2);
if (num_bits_2 == 24) {
- t_2 = *scratch >> 32;
+ t_2 = ((uint32_t)(*scratch >> 32));
break;
}
num_bits_2 += 8;
@@ -10604,24 +11448,25 @@
goto ok;
ok:
- self->private_impl.c_decode_io_writer[0].coro_susp_point = 0;
+ self->private_impl.p_decode_io_writer[0] = 0;
goto exit;
}
goto suspend;
suspend:
- self->private_impl.c_decode_io_writer[0].coro_susp_point = coro_susp_point;
- self->private_impl.c_decode_io_writer[0].v_checksum_got = v_checksum_got;
+ self->private_impl.p_decode_io_writer[0] = coro_susp_point;
+ self->private_impl.active_coroutine = 1;
+ self->private_data.s_decode_io_writer[0].v_checksum_got = v_checksum_got;
goto exit;
exit:
if (a_dst.private_impl.buf) {
a_dst.private_impl.buf->meta.wi =
- iop_a_dst - a_dst.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_dst - a_dst.private_impl.buf->data.ptr));
}
if (a_src.private_impl.buf) {
a_src.private_impl.buf->meta.ri =
- iop_a_src - a_src.private_impl.buf->data.ptr;
+ ((size_t)(iop_a_src - a_src.private_impl.buf->data.ptr));
}
if (wuffs_base__status__is_error(status)) {
diff --git a/script/adler32-standalone.c b/script/adler32-standalone.c
index 712d8c9..29de1c0 100644
--- a/script/adler32-standalone.c
+++ b/script/adler32-standalone.c
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// ----------------
+
// This file contains a hand-written C implementation of the Adler32 hash
// function, based on the code generated by the Wuffs std/zlib implementation.
// Its purpose is to benchmark different compilers, or different versions of
diff --git a/script/bench-c-deflate-fragmentation.c b/script/bench-c-deflate-fragmentation.c
index 99ab4da..c49aa9a 100644
--- a/script/bench-c-deflate-fragmentation.c
+++ b/script/bench-c-deflate-fragmentation.c
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// ----------------
+
// This file contains a hand-written C benchmark of different strategies for
// decoding PNG data.
//
@@ -110,6 +112,14 @@
size_t idat_splits[MAX_IDAT_CHUNKS + 1] = {0};
uint32_t num_idat_chunks = 0;
+#define WORK_BUFFER_SIZE WUFFS_ZLIB__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE
+#if WORK_BUFFER_SIZE > 0
+uint8_t work_buffer[WORK_BUFFER_SIZE];
+#else
+// Not all C/C++ compilers support 0-length arrays.
+uint8_t work_buffer[1];
+#endif
+
uint32_t width = 0;
uint32_t height = 0;
uint64_t bytes_per_pixel = 0;
@@ -216,9 +226,9 @@
}
const char* decode_once(bool frag_dst, bool frag_idat) {
- wuffs_zlib__decoder dec = ((wuffs_zlib__decoder){});
+ wuffs_zlib__decoder dec;
const char* status =
- wuffs_zlib__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION);
+ wuffs_zlib__decoder__initialize(&dec, sizeof dec, WUFFS_VERSION, 0);
if (status) {
return status;
}
@@ -257,7 +267,11 @@
while (true) {
status =
- wuffs_zlib__decoder__decode_io_writer(&dec, dst_writer, idat_reader);
+ wuffs_zlib__decoder__decode_io_writer(&dec, dst_writer, idat_reader,
+ ((wuffs_base__slice_u8){
+ .ptr = work_buffer,
+ .len = WORK_BUFFER_SIZE,
+ }));
if (!status) {
break;
diff --git a/script/bench-rust-gif-dot-rs/src/main.rs b/script/bench-rust-gif-dot-rs/src/main.rs
index cb56c81..2eef3c1 100644
--- a/script/bench-rust-gif-dot-rs/src/main.rs
+++ b/script/bench-rust-gif-dot-rs/src/main.rs
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// ----------------
+
// This program exercises the Rust GIF decoder at
// https://github.com/Geal/gif.rs
//
diff --git a/script/bench-rust-gif/src/main.rs b/script/bench-rust-gif/src/main.rs
index b49e4c0..ec6bfb2 100644
--- a/script/bench-rust-gif/src/main.rs
+++ b/script/bench-rust-gif/src/main.rs
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// ----------------
+
// This program exercises the Rust GIF decoder at
// https://github.com/PistonDevelopers/image-gif
//
diff --git a/script/checksum.go b/script/checksum.go
index 03b218c..93a9760 100644
--- a/script/checksum.go
+++ b/script/checksum.go
@@ -48,11 +48,11 @@
flag.Parse()
if *pi {
- const digits = "3.1415926535897932384626433832795028841971693993751058209749445"
- if len(digits) != 63 {
+ const digits = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170"
+ if len(digits) != 99 {
panic("bad len(digits)")
}
- for i := 0; i < 64; i++ {
+ for i := 0; i < 100; i++ {
if err := do(strings.NewReader(digits[:i])); err != nil {
return err
}
diff --git a/script/make-artificial.go b/script/make-artificial.go
index 8cadd94..d436b99 100644
--- a/script/make-artificial.go
+++ b/script/make-artificial.go
@@ -308,6 +308,16 @@
return stateDeflateFixedHuffman, nil
}
+ if line == "len 3 distCode 31" {
+ lCode, lExtra, lNExtra := deflateEncodeLength(3)
+ g.stream.writeLCode(lCode)
+ g.stream.writeBits(lExtra, lNExtra)
+ dCode, dExtra, dNExtra := uint32(31), uint32(0), uint32(0)
+ g.stream.writeBits(reverse(dCode, 5), 5)
+ g.stream.writeBits(dExtra, dNExtra)
+ return stateDeflateFixedHuffman, nil
+ }
+
if l, d, ok := deflateParseLenDist(line); ok {
lCode, lExtra, lNExtra := deflateEncodeLength(l)
g.stream.writeLCode(lCode)
diff --git a/script/mmap-ring-buffer.c b/script/mmap-ring-buffer.c
new file mode 100644
index 0000000..d80538b
--- /dev/null
+++ b/script/mmap-ring-buffer.c
@@ -0,0 +1,133 @@
+// Copyright 2019 The Wuffs Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// ----------------
+
+// This program demonstrates mmap'ing a ring-buffer's N bytes of physical
+// memory three times, to be a contiguous block of 3*N bytes. The three
+// pointers (base + 0*N + i), (base + 1*N + i) and (base + 2*N + i), which are
+// different addresses in virtual memory, all alias the same physical address.
+//
+// Reading or writing a chunk of length M <= N is therefore a simple memcpy,
+// without having to explicitly wrap around the ring-buffer boundaries.
+//
+// This is similar to the technique discussed in
+// https://lo.calho.st/quick-hacks/employing-black-magic-in-the-linux-page-table/
+//
+// This program differs from that web page's discussion by mapping the physical
+// memory three times, not just two. This lets us read or write, implicitly
+// wrapping, both forwards (after the middle mapping's end) and backwards
+// (before the middle mapping's start). That web page only considers forwards
+// reads or writes. Backwards reads are useful when decoding a Lempel-Ziv style
+// compression format, copying from history (recently decoded bytes).
+//
+// Its output should be:
+//
+// middle[-8] == 0x00 == 0x00 == middle[131064]
+// middle[-7] == 0x00 == 0x00 == middle[131065]
+// middle[-6] == 0x00 == 0x00 == middle[131066]
+// middle[-5] == 0x00 == 0x00 == middle[131067]
+// middle[-4] == 0x00 == 0x00 == middle[131068]
+// middle[-3] == 0x00 == 0x00 == middle[131069]
+// middle[-2] == 0x20 == 0x20 == middle[131070]
+// middle[-1] == 0x21 == 0x21 == middle[131071]
+// middle[ 0] == 0x22 == 0x22 == middle[131072]
+// middle[ 1] == 0x23 == 0x23 == middle[131073]
+// middle[ 2] == 0x12 == 0x12 == middle[131074]
+// middle[ 3] == 0x13 == 0x13 == middle[131075]
+// middle[ 4] == 0x30 == 0x30 == middle[131076]
+// middle[ 5] == 0x31 == 0x31 == middle[131077]
+// middle[ 6] == 0x32 == 0x32 == middle[131078]
+// middle[ 7] == 0x17 == 0x17 == middle[131079]
+
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+// We should be able to do:
+//
+// #include <sys/memfd.h>
+//
+// to get the memfd_create function signature, but memfd_create is relatively
+// recent. For some reason, this #include hits "No such file or directory" on
+// Ubuntu 18.04 (linux 4.15, glibc 2.27), and there's also been problems on
+// Debian systems. Instead, we explicitly define our own memfd_create.
+static int my_memfd_create(const char* name, unsigned int flags) {
+ return syscall(__NR_memfd_create, name, flags);
+}
+
+#define N (128 * 1024)
+
+void* make_ring_buffer() {
+ int page_size = getpagesize();
+ if ((N < page_size) || (page_size <= 0) || ((N % page_size) != 0)) {
+ return NULL;
+ }
+
+ int memfd = my_memfd_create("ring", 0);
+ if (memfd == -1) {
+ return NULL;
+ }
+ if (ftruncate(memfd, N) == -1) {
+ return NULL;
+ }
+
+ // Have the kernel find a contiguous range of unused address space.
+ void* base = mmap(NULL, 3 * N, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+ if (base == MAP_FAILED) {
+ return NULL;
+ }
+
+ // Map that "ring" file 3 times, filling that range exactly.
+ for (int i = 0; i < 3; i++) {
+ void* p = mmap(base + (i * N), N, PROT_READ | PROT_WRITE,
+ MAP_FIXED | MAP_SHARED, memfd, 0);
+ if (p == MAP_FAILED) {
+ return NULL;
+ }
+ }
+
+ close(memfd);
+ return base;
+}
+
+int main(int argc, char** argv) {
+ uint8_t* base = make_ring_buffer();
+ if (!base) {
+ fprintf(stderr, "could not make ring buffer\n");
+ return 1;
+ }
+
+ for (int i = 0; i < 8; i++) {
+ base[i] = 0x10 + i;
+ }
+
+ memcpy(base + N - 2, "\x20\x21\x22\x23", 4);
+
+ base[(0 * N) + 4] = 0x30;
+ base[(1 * N) + 5] = 0x31;
+ base[(2 * N) + 6] = 0x32;
+
+ uint8_t* middle = base + N;
+ for (int i = -8; i < 8; i++) {
+ int j = N + i;
+ printf("middle[%2d] == 0x%02X == 0x%02X == middle[%6d]\n", i,
+ middle[i], middle[j], j);
+ }
+
+ return 0;
+}
diff --git a/script/wuffs-deflate-decoder-decode-huffman.c b/script/wuffs-deflate-decoder-decode-huffman.c
index 7868a00..25cd052 100644
--- a/script/wuffs-deflate-decoder-decode-huffman.c
+++ b/script/wuffs-deflate-decoder-decode-huffman.c
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// ----------------
+
// This file contains a hand-written C implementation of
// release/c/wuffs-unsupported-snapshot.c's generated
// wuffs_deflate__decoder__decode_huffman_fast function.
@@ -23,9 +25,9 @@
// To repeat, substituting in this C implementation is NOT SAFE, and may result
// in buffer overflows. This code exists only to aid optimization of the (safe)
// std/deflate/*.wuffs code and the Wuffs compiler's code generation.
-//
+
// ----------------
-//
+
// Having said that, to generate the benchmark numbers with this hand-written C
// implementation, edit release/c/wuffs-unsupported-snapshot.c and find the
// lines that say
@@ -147,13 +149,16 @@
uint32_t magic;
uint32_t f_bits;
uint32_t f_n_bits;
- uint32_t f_huffs[2][1234];
- uint32_t f_n_huffs_bits[2];
- uint8_t f_history[32768];
uint32_t f_history_index;
- uint8_t f_code_lengths[320];
+ uint32_t f_n_huffs_bits[2];
bool f_end_of_block;
} private_impl;
+ struct {
+ // 1024 is huffs_table_size in std/deflate/decode_deflate.wuffs.
+ uint32_t f_huffs[2][1024];
+ uint8_t f_history[32768];
+ uint8_t f_code_lengths[320];
+ } private_data;
} wuffs_deflate__decoder;
const char* wuffs_base__error__bad_argument = "?base: bad argument";
@@ -308,7 +313,7 @@
#endif
// Decode an lcode symbol from H-L.
- uint32_t table_entry = self->private_impl.f_huffs[0][bits & lmask];
+ uint32_t table_entry = self->private_data.f_huffs[0][bits & lmask];
while (true) {
uint32_t n = table_entry & 0x0F;
bits >>= n;
@@ -334,7 +339,7 @@
}
uint32_t top = (table_entry >> 8) & 0xFFFF;
uint32_t mask = MASK((table_entry >> 4) & 0x0F);
- table_entry = self->private_impl.f_huffs[0][top + (bits & mask)];
+ table_entry = self->private_data.f_huffs[0][top + (bits & mask)];
}
// length = base_number_minus_3 + 3 + extra_bits.
@@ -365,7 +370,7 @@
#endif
// Decode a dcode symbol from H-D.
- table_entry = self->private_impl.f_huffs[1][bits & dmask];
+ table_entry = self->private_data.f_huffs[1][bits & dmask];
while (true) {
uint32_t n = table_entry & 0x0F;
bits >>= n;
@@ -381,7 +386,7 @@
}
uint32_t top = (table_entry >> 8) & 0xFFFF;
uint32_t mask = MASK((table_entry >> 4) & 0x0F);
- table_entry = self->private_impl.f_huffs[1][top + (bits & mask)];
+ table_entry = self->private_data.f_huffs[1][top + (bits & mask)];
}
// dist_minus_1 = base_number_minus_1 + extra_bits.
@@ -427,13 +432,13 @@
(self->private_impl.f_history_index - hdist) & 0x7FFF;
uint32_t available = 0x8000 - history_index;
uint32_t n_copied = (hlen < available) ? hlen : available;
- memmove(pdst, self->private_impl.f_history + history_index, n_copied);
+ memmove(pdst, self->private_data.f_history + history_index, n_copied);
pdst += n_copied;
// Copy from the left edge of the f_history array.
if (hlen > n_copied) {
hlen -= n_copied;
- memmove(pdst, self->private_impl.f_history, hlen);
+ memmove(pdst, self->private_data.f_history, hlen);
pdst += hlen;
}
diff --git a/std/adler32/README.md b/std/adler32/README.md
index 72a7eb1..e92d01c 100644
--- a/std/adler32/README.md
+++ b/std/adler32/README.md
@@ -1,5 +1,100 @@
-# Adler32
+# Adler-32
-Adler32 is a checksum algorithm that hashes byte sequences to 32 bit values.
+Adler-32 is a checksum algorithm that hashes byte sequences to 32 bit values.
+It is named after its inventor, Mark Adler, who also co-invented the Gzip and
+Zlib compressed file formats. Amongst other differences, Gzip uses CRC-32 as
+its checksum and Zlib uses Adler-32.
-TODO: a worked example.
+The algorithm, described in [RFC 1950](https://www.ietf.org/rfc/rfc1950.txt),
+is simple. Conceptually, there are two unsigned integers `s1` and `s2` of
+infinite precision, initialized to `0` and `1`. These two accumulators are
+updated for every input byte `src[i]`. At the end of the loop, `s1` is `1` plus
+the sum of all source bytes and `s2` is the sum of all (intermediate and final)
+`s1` values:
+
+ var s1 = 1;
+ var s2 = 0;
+ for_each i in_the_range_of src {
+ s1 = s1 + src[i];
+ s2 = s2 + s1;
+ }
+ return ((s2 % 65521) << 16) | (s1 % 65521);
+
+The final `uint32_t` hash value is composed of two 16-bit values: `(s1 %
+65521)` in the low 16 bits and `(s2 % 65521)` in the high 16 bits. `65521` is
+the largest prime number less than `(1 << 16)`.
+
+Infinite precision arithmetic requires arbitrarily large amounts of memory. In
+practice, computing the Adler-32 hash instead uses a `uint32_t` typed `s1` and
+`s2`, modifying the algorithm to be concious of overflow inside the loop:
+
+ uint32_t s1 = 1;
+ uint32_t s2 = 0;
+ for_each i in_the_range_of src {
+ s1 = (s1 + src[i]) % 65521;
+ s2 = (s2 + s1) % 65521;
+ }
+ return (s2 << 16) | s1;
+
+The loop can be split into two levels, so that the relatively expensive modulo
+operation can be hoisted out of the inner loop:
+
+ uint32_t s1 = 1;
+ uint32_t s2 = 0;
+ for_each_sub_slice s of_length_up_to M partitioning src {
+ for_each i in_the_range_of s {
+ s1 = s1 + s[i];
+ s2 = s2 + s1;
+ }
+ s1 = s1 % 65521;
+ s2 = s2 % 65521;
+ }
+ return (s2 << 16) | s1;
+
+We just need to find the largest `M` such that the inner loop cannot overflow.
+The worst case scenario is that `s1` and `s2` both start the inner loop at
+`65520` and every subsequent `src[i]` byte equals `0xFF`. A simple
+[computation](https://play.golang.org/p/wdx6BPDs2-R) finds that the largest
+non-overflowing `M` is 5552.
+
+In a happy coincidence, 5552 is an exact multiple of 16, which often works well
+with loop unrolling and with SIMD alignment.
+
+
+## Comparison with CRC-32
+
+Adler-32 is a very simple hashing algorithm. While its output is nominally a
+`uint32_t` value, it isn't uniformly distributed across the entire `uint32_t`
+range. The `[65521, 65535]` range of each 16-bit half of an Adler-32 checksum
+is never touched.
+
+While neither Adler-32 or CRC-32 are cryptographic hash functions, there is
+still a stark difference in the patterns (or lack of) in their hash values of
+the `N`-byte string consisting entirely of zeroes, as [this Go
+program](https://play.golang.org/p/SkPVp0tBnDl) shows:
+
+ N Adler-32 CRC-32 Input
+ 0 0x00000001 0x00000000 ""
+ 1 0x00010001 0xD202EF8D "\x00"
+ 2 0x00020001 0x41D912FF "\x00\x00"
+ 3 0x00030001 0xFF41D912 "\x00\x00\x00"
+ 4 0x00040001 0x2144DF1C "\x00\x00\x00\x00"
+ 5 0x00050001 0xC622F71D "\x00\x00\x00\x00\x00"
+ 6 0x00060001 0xB1C2A1A3 "\x00\x00\x00\x00\x00\x00"
+ 7 0x00070001 0x9D6CDF7E "\x00\x00\x00\x00\x00\x00\x00"
+
+Adler-32 is a simpler algorithm than CRC-32. At the time Adler-32 was invented,
+it had noticably higher throughput. With modern SIMD implementations, that
+performance difference has largely disappeared.
+
+
+# Worked Example
+
+A worked example for calculating the Adler-32 hash of the three byte input
+"Hi\n", starting from the initial state `(s1 = 1)` and `(s2 = 0)`:
+
+ src[i] ((s2 << 16) | s1)
+ ---- 0x00000001
+ 0x48 0x00490049
+ 0x69 0x00FB00B2
+ 0x0A 0x01B700BC
diff --git a/std/adler32/common_adler32.wuffs b/std/adler32/common_adler32.wuffs
index 7114f82..30e1939 100644
--- a/std/adler32/common_adler32.wuffs
+++ b/std/adler32/common_adler32.wuffs
@@ -20,7 +20,7 @@
pub func hasher.update!(x slice base.u8) base.u32 {
// The Adler-32 checksum's magic 65521 and 5552 numbers are discussed in
- // RFC 1950.
+ // this package's README.md.
var s1 base.u32
var s2 base.u32
diff --git a/std/deflate/decode_deflate.wuffs b/std/deflate/decode_deflate.wuffs
index 4244b84..a91e9b7 100644
--- a/std/deflate/decode_deflate.wuffs
+++ b/std/deflate/decode_deflate.wuffs
@@ -12,24 +12,28 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-pub status "?bad Huffman code (over-subscribed)"
-pub status "?bad Huffman code (under-subscribed)"
-pub status "?bad Huffman code length count"
-pub status "?bad Huffman code length repetition"
-pub status "?bad Huffman code"
-pub status "?bad Huffman minimum code length"
-pub status "?bad block"
-pub status "?bad distance"
-pub status "?bad distance code count"
-pub status "?bad literal/length code count"
-pub status "?inconsistent stored block length"
-pub status "?missing end-of-block code"
-pub status "?no Huffman codes"
+pub status "#bad Huffman code (over-subscribed)"
+pub status "#bad Huffman code (under-subscribed)"
+pub status "#bad Huffman code length count"
+pub status "#bad Huffman code length repetition"
+pub status "#bad Huffman code"
+pub status "#bad Huffman minimum code length"
+pub status "#bad block"
+pub status "#bad distance"
+pub status "#bad distance code count"
+pub status "#bad literal/length code count"
+pub status "#inconsistent stored block length"
+pub status "#missing end-of-block code"
+pub status "#no Huffman codes"
-pri status "?internal error: inconsistent Huffman decoder state"
-pri status "?internal error: inconsistent I/O"
-pri status "?internal error: inconsistent distance"
-pri status "?internal error: inconsistent n_bits"
+pri status "#internal error: inconsistent Huffman decoder state"
+pri status "#internal error: inconsistent I/O"
+pri status "#internal error: inconsistent distance"
+pri status "#internal error: inconsistent n_bits"
+
+// TODO: replace the placeholder 1 value with either 0 or (32768 + 512),
+// depending on whether we'll move decoder.history into the workbuf.
+pub const decoder_workbuf_len_max_incl_worst_case base.u64 = 1
// The next two tables were created by script/print-deflate-magic-numbers.go.
//
@@ -53,11 +57,29 @@
0x401000B0, 0x401800B0, 0x402000C0, 0x403000C0, 0x404000D0, 0x406000D0, 0x08000000, 0x08000000,
]
+// TODO: replace the magic "big enough" 1024 with something more principled,
+// perhaps discovered via an exhaustive search.
+pri const huffs_table_size base.u32 = 1024
+pri const huffs_table_mask base.u32 = 1023
+
pub struct decoder?(
// These fields yield src's bits in Least Significant Bits order.
bits base.u32,
n_bits base.u32,
+ // history_index indexes the history array, defined below.
+ history_index base.u32,
+
+ // n_huffs_bits is discussed in the huffs field comment.
+ n_huffs_bits array[2] base.u32[..9],
+
+ // end_of_block is whether decode_huffman_xxx saw an end-of-block code.
+ //
+ // TODO: can decode_huffman_xxx signal this in band instead of out of band?
+ end_of_block base.bool,
+
+ util base.utility,
+)(
// huffs and n_huffs_bits are the lookup tables for Huffman decodings.
//
// There are up to 2 Huffman decoders active at any one time. As per this
@@ -88,11 +110,7 @@
// - bits 3 .. 0 are the number of decoder.bits to consume.
//
// Exactly one of the eight bits 31-24 should be set.
- //
- // TODO: replace the magic "big enough" 1234 with something more
- // principled, perhaps discovered via an exhaustive search.
- huffs array[2] array[1234] base.u32,
- n_huffs_bits array[2] base.u32[..9],
+ huffs array[2] array[huffs_table_size] base.u32,
// history holds up to the last 32KiB of decoded output, if the decoding
// was incomplete (e.g. due to a short read or write). RFC 1951 (DEFLATE)
@@ -105,22 +123,22 @@
//
// history[history_index & 0x7FFF] is where the next byte of decoded output
// will be written.
- history array[0x8000] base.u8, // 32 KiB.
- history_index base.u32,
+ history array[0x8000] base.u8, // 32 KiB.
// code_lengths is used to pass out-of-band data to init_huff.
//
// code_lengths[args.n_codes0 + i] holds the number of bits in the i'th
// code.
- code_lengths array[320] base.u8[..15],
-
- // end_of_block is whether decode_huffman_xxx saw an end-of-block code.
- //
- // TODO: can decode_huffman_xxx signal this in band instead of out of band?
- end_of_block base.bool,
+ code_lengths array[320] base.u8,
)
-pub func decoder.decode_io_writer?(dst base.io_writer, src base.io_reader) {
+pub func decoder.workbuf_len() base.range_ii_u64 {
+ return this.util.make_range_ii_u64(
+ min_incl:decoder_workbuf_len_max_incl_worst_case,
+ max_incl:decoder_workbuf_len_max_incl_worst_case)
+}
+
+pub func decoder.decode_io_writer?(dst base.io_writer, src base.io_reader, workbuf slice base.u8) {
var status base.status
var written slice base.u8
var n_copied base.u64
@@ -173,7 +191,7 @@
this.history_index = (this.history_index & 0x7FFF) + ((n_copied & 0x7FFF) as base.u32) + already_full
}
}
- yield status
+ yield? status
}
}
@@ -213,7 +231,7 @@
} else if type == 2 {
this.init_dynamic_huffman?(src:args.src)
} else {
- return "?bad block"
+ return "#bad block"
}
this.end_of_block = false
@@ -242,15 +260,15 @@
// TODO: make this "if" into a function invariant?
//
// Ditto for decode_huffman_slow and decode_huffman_fast.
- if (this.n_bits >= 8) or ((this.bits >> (this.n_bits & 7)) != 0) {
- return "?internal error: inconsistent n_bits"
+ if (this.n_bits >= 8) or ((this.bits >> (this.n_bits & 7)) <> 0) {
+ return "#internal error: inconsistent n_bits"
}
this.n_bits = 0
this.bits = 0
length = args.src.read_u32le?()
- if (length.low_bits(n:16) + length.high_bits(n:16)) != 0xFFFF {
- return "?inconsistent stored block length"
+ if (length.low_bits(n:16) + length.high_bits(n:16)) <> 0xFFFF {
+ return "#inconsistent stored block length"
}
length = length.low_bits(n:16)
while true {
@@ -260,9 +278,9 @@
}
length -= n_copied
if args.dst.available() == 0 {
- yield base."$short write"
+ yield? base."$short write"
} else {
- yield base."$short read"
+ yield? base."$short read"
}
}
}
@@ -335,12 +353,12 @@
}
n_lit = bits.low_bits(n:5) + 257
if n_lit > 286 {
- return "?bad literal/length code count"
+ return "#bad literal/length code count"
}
bits >>= 5
n_dist = bits.low_bits(n:5) + 1
if n_dist > 30 {
- return "?bad distance code count"
+ return "#bad distance code count"
}
bits >>= 5
n_clen = bits.low_bits(n:4) + 4
@@ -374,7 +392,7 @@
}
// Decode the code lengths for the next two Huffman tables.
- mask = ((1 as base.u32) << this.n_huffs_bits[0]) - 1
+ mask = ((1 as base.u32) << (this.n_huffs_bits[0])) - 1
i = 0
while i < (n_lit + n_dist) {
assert i < (288 + 32) via "a < (b + c): a < (b0 + c0); b0 <= b; c0 <= c"(b0:n_lit, c0:n_dist)
@@ -397,8 +415,8 @@
}
// For H-CL, there should be no redirections and all symbols should be
// literals.
- if (table_entry >> 24) != 0x80 {
- return "?internal error: inconsistent Huffman decoder state"
+ if (table_entry >> 24) <> 0x80 {
+ return "#internal error: inconsistent Huffman decoder state"
}
table_entry = (table_entry >> 8) & 0xFF
@@ -416,9 +434,9 @@
if table_entry == 16 {
n_extra_bits = 2
if i <= 0 {
- return "?bad Huffman code length repetition"
+ return "#bad Huffman code length repetition"
}
- rep_symbol = this.code_lengths[i - 1]
+ rep_symbol = this.code_lengths[i - 1] & 15
rep_count = 3
assert rep_count <= 11
} else if table_entry == 17 {
@@ -432,7 +450,7 @@
rep_count = 11
assert rep_count <= 11
} else {
- return "?internal error: inconsistent Huffman decoder state"
+ return "#internal error: inconsistent Huffman decoder state"
}
while n_bits < n_extra_bits,
inv i < 320,
@@ -451,7 +469,7 @@
while rep_count > 0 {
// TODO: hoist this check up one level?
if i >= (n_lit + n_dist) {
- return "?bad Huffman code length count"
+ return "#bad Huffman code length count"
}
assert i < (288 + 32) via "a < (b + c): a < (b0 + c0); b0 <= b; c0 <= c"(b0:n_lit, c0:n_dist)
this.code_lengths[i] = rep_symbol
@@ -460,11 +478,11 @@
}
}
- if i != (n_lit + n_dist) {
- return "?bad Huffman code length count"
+ if i <> (n_lit + n_dist) {
+ return "#bad Huffman code length count"
}
if this.code_lengths[256] == 0 {
- return "?missing end-of-block code"
+ return "#missing end-of-block code"
}
status = this.init_huff!(which:0, n_codes0:0, n_codes1:n_lit, base_symbol:257)
@@ -495,8 +513,8 @@
var initial_high_bits base.u32
var prev_cl base.u32[..15]
var prev_redirect_key base.u32
- var top base.u32[..1234]
- var next_top base.u32[..1234]
+ var top base.u32[..huffs_table_size]
+ var next_top base.u32[..huffs_table_size]
var code base.u32
var key base.u32
var value base.u32
@@ -546,14 +564,14 @@
assert i < 320 via "a < b: a < c; c <= b"(c:args.n_codes1)
// TODO: this if should be unnecessary. Have some way to assert that,
// for all j, counts[j] <= i, and thus counts[j]++ will not overflow.
- if counts[this.code_lengths[i]] >= 320 {
- return "?internal error: inconsistent Huffman decoder state"
+ if counts[this.code_lengths[i] & 15] >= 320 {
+ return "#internal error: inconsistent Huffman decoder state"
}
- counts[this.code_lengths[i]] += 1
+ counts[this.code_lengths[i] & 15] += 1
i += 1
}
if ((counts[0] as base.u32) + args.n_codes0) == args.n_codes1 {
- return "?no Huffman codes"
+ return "#no Huffman codes"
}
// Check that the Huffman code completely covers all possible input bits.
@@ -561,19 +579,19 @@
i = 1
while i <= 15 {
if remaining > (1 << 30) {
- return "?internal error: inconsistent Huffman decoder state"
+ return "#internal error: inconsistent Huffman decoder state"
}
// Each iteration doubles the number of possible remaining codes.
remaining <<= 1
if remaining < (counts[i] as base.u32) {
- return "?bad Huffman code (over-subscribed)"
+ return "#bad Huffman code (over-subscribed)"
}
remaining -= counts[i] as base.u32
i += 1
}
- if remaining != 0 {
+ if remaining <> 0 {
// TODO: when is a degenerate Huffman table valid?
- return "?bad Huffman code (under-subscribed)"
+ return "#bad Huffman code (under-subscribed)"
}
// Calculate offsets and n_symbols.
@@ -593,7 +611,7 @@
offsets[i] = n_symbols as base.u16
count = counts[i] as base.u32
if n_symbols > (320 - count) {
- return "?internal error: inconsistent Huffman decoder state"
+ return "#internal error: inconsistent Huffman decoder state"
}
assert (n_symbols + count) <= 320 via "(a + b) <= c: a <= (c - b)"()
// TODO: change this to n_symbols += count, once the proof engine's
@@ -602,7 +620,7 @@
i += 1
}
if n_symbols > 288 {
- return "?internal error: inconsistent Huffman decoder state"
+ return "#internal error: inconsistent Huffman decoder state"
}
// Calculate symbols.
@@ -630,14 +648,14 @@
assert i < 320 via "a < b: a < c; c <= b"(c:args.n_codes1)
// TODO: this if check should be unnecessary.
if i < args.n_codes0 {
- return "?internal error: inconsistent Huffman decoder state"
+ return "#internal error: inconsistent Huffman decoder state"
}
- if this.code_lengths[i] != 0 {
- if offsets[this.code_lengths[i]] >= 320 {
- return "?internal error: inconsistent Huffman decoder state"
+ if this.code_lengths[i] <> 0 {
+ if offsets[this.code_lengths[i] & 15] >= 320 {
+ return "#internal error: inconsistent Huffman decoder state"
}
- symbols[offsets[this.code_lengths[i]]] = (i - args.n_codes0) as base.u16
- offsets[this.code_lengths[i]] += 1
+ symbols[offsets[this.code_lengths[i] & 15]] = (i - args.n_codes0) as base.u16
+ offsets[this.code_lengths[i] & 15] += 1
}
i += 1
}
@@ -651,11 +669,11 @@
while true,
inv n_symbols <= 288,
{
- if counts[min_cl] != 0 {
+ if counts[min_cl] <> 0 {
break
}
if min_cl >= 9 {
- return "?bad Huffman minimum code length"
+ return "#bad Huffman minimum code length"
}
min_cl += 1
}
@@ -663,12 +681,12 @@
while true,
inv n_symbols <= 288,
{
- if counts[max_cl] != 0 {
+ if counts[max_cl] <> 0 {
break
}
if max_cl <= 1 {
// TODO: when is a degenerate Huffman table valid?
- return "?no Huffman codes"
+ return "#no Huffman codes"
}
max_cl -= 1
}
@@ -692,18 +710,18 @@
// - this.huffs[0][0b01111] = 0x80000305 (literal, symbols[8]=0x03, code_length=5)
// - this.huffs[0][0b11111] = 0x80001805 (literal, symbols[9]=0x18, code_length=5)
i = 0
- if (n_symbols != (offsets[max_cl] as base.u32)) or (n_symbols != (offsets[15] as base.u32)) {
- return "?internal error: inconsistent Huffman decoder state"
+ if (n_symbols <> (offsets[max_cl] as base.u32)) or (n_symbols <> (offsets[15] as base.u32)) {
+ return "#internal error: inconsistent Huffman decoder state"
}
if (args.n_codes0 + (symbols[0] as base.u32)) >= 320 {
- return "?internal error: inconsistent Huffman decoder state"
+ return "#internal error: inconsistent Huffman decoder state"
}
initial_high_bits = 1 << 9
if max_cl < 9 {
initial_high_bits = (1 as base.u32) << max_cl
}
- prev_cl = this.code_lengths[args.n_codes0 + (symbols[0] as base.u32)] as base.u32
+ prev_cl = (this.code_lengths[args.n_codes0 + (symbols[0] as base.u32)] & 15) as base.u32
prev_redirect_key = 0xFFFFFFFF
top = 0
next_top = 512
@@ -716,13 +734,13 @@
inv n_symbols <= 288,
{
if (args.n_codes0 + (symbols[i] as base.u32)) >= 320 {
- return "?internal error: inconsistent Huffman decoder state"
+ return "#internal error: inconsistent Huffman decoder state"
}
- cl = this.code_lengths[args.n_codes0 + (symbols[i] as base.u32)] as base.u32
+ cl = (this.code_lengths[args.n_codes0 + (symbols[i] as base.u32)] & 15) as base.u32
if cl > prev_cl {
code <<= cl - prev_cl
if code >= (1 << 15) {
- return "?internal error: inconsistent Huffman decoder state"
+ return "#internal error: inconsistent Huffman decoder state"
}
}
// For the remainder of this loop body, prev_cl is the original code
@@ -736,7 +754,7 @@
redirect_key = (key >> cl) & 511
key = key.low_bits(n:cl)
- if prev_redirect_key != redirect_key {
+ if prev_redirect_key <> redirect_key {
prev_redirect_key = redirect_key
// Calculate the number of bits needed for the 2nd level table.
@@ -755,21 +773,22 @@
}
remaining -= counts[j] as base.u32
if remaining > (1 << 30) {
- return "?internal error: inconsistent Huffman decoder state"
+ return "#internal error: inconsistent Huffman decoder state"
}
remaining <<= 1
j += 1
}
if (j <= 9) or (15 < j) {
- return "?internal error: inconsistent Huffman decoder state"
+ return "#internal error: inconsistent Huffman decoder state"
}
j -= 9
initial_high_bits = (1 as base.u32) << j
top = next_top
- if (top + ((1 as base.u32) << j)) > 1234 {
- return "?internal error: inconsistent Huffman decoder state"
+ if (top + ((1 as base.u32) << j)) > huffs_table_size {
+ return "#internal error: inconsistent Huffman decoder state"
}
+ assert (top + ((1 as base.u32) << j)) <= 1024 via "a <= b: a <= c; c <= b"(c:huffs_table_size)
next_top = top + ((1 as base.u32) << j)
redirect_key = (reverse8[redirect_key >> 1] as base.u32) | ((redirect_key & 1) << 8)
@@ -777,7 +796,7 @@
}
}
if (key >= (1 << 9)) or (counts[prev_cl] <= 0) {
- return "?internal error: inconsistent Huffman decoder state"
+ return "#internal error: inconsistent Huffman decoder state"
}
counts[prev_cl] -= 1
@@ -800,7 +819,7 @@
value = dcode_magic_numbers[symbol & 31] | cl
}
} else {
- return "?internal error: inconsistent Huffman decoder state"
+ return "#internal error: inconsistent Huffman decoder state"
}
// The table uses log2(initial_high_bits) bits, but reversed_key only
@@ -814,9 +833,10 @@
inv n_symbols <= 288,
{
high_bits -= delta
- if (top + ((high_bits | reversed_key) & 511)) >= 1234 {
- return "?internal error: inconsistent Huffman decoder state"
+ if (top + ((high_bits | reversed_key) & 511)) >= huffs_table_size {
+ return "#internal error: inconsistent Huffman decoder state"
}
+ assert (top + ((high_bits | reversed_key) & 511)) < 1024 via "a < b: a < c; c <= b"(c:huffs_table_size)
this.huffs[args.which][top + ((high_bits | reversed_key) & 511)] = value
}
@@ -827,7 +847,7 @@
assert i < 288 via "a < b: a < c; c <= b"(c:n_symbols)
code += 1
if code >= (1 << 15) {
- return "?internal error: inconsistent Huffman decoder state"
+ return "#internal error: inconsistent Huffman decoder state"
}
}
return ok
diff --git a/std/deflate/decode_huffman_fast.wuffs b/std/deflate/decode_huffman_fast.wuffs
index e9ee4d0..d98af1c 100644
--- a/std/deflate/decode_huffman_fast.wuffs
+++ b/std/deflate/decode_huffman_fast.wuffs
@@ -34,8 +34,8 @@
var hlen base.u32[..0x7FFF]
var hdist base.u32
- if (this.n_bits >= 8) or ((this.bits >> (this.n_bits & 7)) != 0) {
- return "?internal error: inconsistent n_bits"
+ if (this.n_bits >= 8) or ((this.bits >> (this.n_bits & 7)) <> 0) {
+ return "#internal error: inconsistent n_bits"
}
bits = this.bits
@@ -97,18 +97,18 @@
bits >>= table_entry_n_bits
n_bits -= table_entry_n_bits
- if (table_entry >> 31) != 0 {
+ if (table_entry >> 31) <> 0 {
// Literal.
args.dst.write_fast_u8!(x:((table_entry >> 8) & 0xFF) as base.u8)
continue:loop
- } else if (table_entry >> 30) != 0 {
+ } else if (table_entry >> 30) <> 0 {
// No-op; code continues past the if-else chain.
assert args.src.available() >= 8
- } else if (table_entry >> 29) != 0 {
+ } else if (table_entry >> 29) <> 0 {
// End of block.
this.end_of_block = true
break:loop
- } else if (table_entry >> 28) != 0 {
+ } else if (table_entry >> 28) <> 0 {
// Redirect.
// Ensure that we have at least 15 bits of input.
@@ -130,39 +130,36 @@
redir_top = (table_entry >> 8) & 0xFFFF
redir_mask = ((1 as base.u32) << ((table_entry >> 4) & 0x0F)) - 1
- if (redir_top + (bits & redir_mask)) >= 1234 {
- return "?internal error: inconsistent Huffman decoder state"
- }
- table_entry = this.huffs[0][redir_top + (bits & redir_mask)]
+ table_entry = this.huffs[0][(redir_top + (bits & redir_mask)) & huffs_table_mask]
table_entry_n_bits = table_entry & 0x0F
bits >>= table_entry_n_bits
n_bits -= table_entry_n_bits
- if (table_entry >> 31) != 0 {
+ if (table_entry >> 31) <> 0 {
// Literal.
args.dst.write_fast_u8!(x:((table_entry >> 8) & 0xFF) as base.u8)
continue:loop
- } else if (table_entry >> 30) != 0 {
+ } else if (table_entry >> 30) <> 0 {
// No-op; code continues past the if-else chain.
- } else if (table_entry >> 29) != 0 {
+ } else if (table_entry >> 29) <> 0 {
// End of block.
this.end_of_block = true
break:loop
- } else if (table_entry >> 28) != 0 {
- return "?internal error: inconsistent Huffman decoder state"
- } else if (table_entry >> 27) != 0 {
- return "?bad Huffman code"
+ } else if (table_entry >> 28) <> 0 {
+ return "#internal error: inconsistent Huffman decoder state"
+ } else if (table_entry >> 27) <> 0 {
+ return "#bad Huffman code"
} else {
- return "?internal error: inconsistent Huffman decoder state"
+ return "#internal error: inconsistent Huffman decoder state"
}
// Once again, redundant but explicit assertions.
assert args.src.available() >= 8
- } else if (table_entry >> 27) != 0 {
- return "?bad Huffman code"
+ } else if (table_entry >> 27) <> 0 {
+ return "#bad Huffman code"
} else {
- return "?internal error: inconsistent Huffman decoder state"
+ return "#internal error: inconsistent Huffman decoder state"
}
// length = base_number_minus_3 + 3 + extra_bits.
@@ -243,10 +240,7 @@
redir_top = (table_entry >> 8) & 0xFFFF
redir_mask = ((1 as base.u32) << ((table_entry >> 4) & 0x0F)) - 1
- if (redir_top + (bits & redir_mask)) >= 1234 {
- return "?internal error: inconsistent Huffman decoder state"
- }
- table_entry = this.huffs[1][redir_top + (bits & redir_mask)]
+ table_entry = this.huffs[1][(redir_top + (bits & redir_mask)) & huffs_table_mask]
table_entry_n_bits = table_entry & 0x0F
bits >>= table_entry_n_bits
n_bits -= table_entry_n_bits
@@ -255,11 +249,11 @@
}
// For H-D, all symbols should be base_number + extra_bits.
- if (table_entry >> 24) != 0x40 {
+ if (table_entry >> 24) <> 0x40 {
if (table_entry >> 24) == 0x08 {
- return "?bad Huffman code"
+ return "#bad Huffman code"
}
- return "?internal error: inconsistent Huffman decoder state"
+ return "#internal error: inconsistent Huffman decoder state"
}
// dist_minus_1 = base_number_minus_1 + extra_bits.
@@ -314,7 +308,7 @@
length = 0
}
if this.history_index < hdist {
- return "?bad distance"
+ return "#bad distance"
}
// Re-purpose the hdist variable as the this.history index to
// start copying from.
@@ -352,7 +346,7 @@
}
if ((dist_minus_1 + 1) as base.u64) > args.dst.since_mark().length() {
- return "?internal error: inconsistent distance"
+ return "#internal error: inconsistent distance"
}
}
// Once again, redundant but explicit assertions.
@@ -387,14 +381,14 @@
if args.src.can_undo_byte() {
args.src.undo_byte!()
} else {
- return "?internal error: inconsistent I/O"
+ return "#internal error: inconsistent I/O"
}
}
this.bits = bits & (((1 as base.u32) << n_bits) - 1)
this.n_bits = n_bits
- if (this.n_bits >= 8) or ((this.bits >> this.n_bits) != 0) {
- return "?internal error: inconsistent n_bits"
+ if (this.n_bits >= 8) or ((this.bits >> this.n_bits) <> 0) {
+ return "#internal error: inconsistent n_bits"
}
}
diff --git a/std/deflate/decode_huffman_slow.wuffs b/std/deflate/decode_huffman_slow.wuffs
index fd3fcc5..2fb085f 100644
--- a/std/deflate/decode_huffman_slow.wuffs
+++ b/std/deflate/decode_huffman_slow.wuffs
@@ -38,8 +38,8 @@
// 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 & 7)) != 0) {
- return "?internal error: inconsistent n_bits"
+ if (this.n_bits >= 8) or ((this.bits >> (this.n_bits & 7)) <> 0) {
+ return "#internal error: inconsistent n_bits"
}
bits = this.bits
@@ -64,25 +64,22 @@
n_bits += 8
}
- if (table_entry >> 31) != 0 {
+ if (table_entry >> 31) <> 0 {
// Literal.
args.dst.write_u8?(x:((table_entry >> 8) & 0xFF) as base.u8)
continue:loop
- } else if (table_entry >> 30) != 0 {
+ } else if (table_entry >> 30) <> 0 {
// No-op; code continues past the if-else chain.
- } else if (table_entry >> 29) != 0 {
+ } else if (table_entry >> 29) <> 0 {
// End of block.
this.end_of_block = true
break:loop
- } else if (table_entry >> 28) != 0 {
+ } else if (table_entry >> 28) <> 0 {
// Redirect.
redir_top = (table_entry >> 8) & 0xFFFF
redir_mask = ((1 as base.u32) << ((table_entry >> 4) & 0x0F)) - 1
while true {
- if (redir_top + (bits & redir_mask)) >= 1234 {
- return "?internal error: inconsistent Huffman decoder state"
- }
- table_entry = this.huffs[0][redir_top + (bits & redir_mask)]
+ table_entry = this.huffs[0][(redir_top + (bits & redir_mask)) & huffs_table_mask]
table_entry_n_bits = table_entry & 0x0F
if n_bits >= table_entry_n_bits {
bits >>= table_entry_n_bits
@@ -95,28 +92,28 @@
n_bits += 8
}
- if (table_entry >> 31) != 0 {
+ if (table_entry >> 31) <> 0 {
// Literal.
args.dst.write_u8?(x:((table_entry >> 8) & 0xFF) as base.u8)
continue:loop
- } else if (table_entry >> 30) != 0 {
+ } else if (table_entry >> 30) <> 0 {
// No-op; code continues past the if-else chain.
- } else if (table_entry >> 29) != 0 {
+ } else if (table_entry >> 29) <> 0 {
// End of block.
this.end_of_block = true
break:loop
- } else if (table_entry >> 28) != 0 {
- return "?internal error: inconsistent Huffman decoder state"
- } else if (table_entry >> 27) != 0 {
- return "?bad Huffman code"
+ } else if (table_entry >> 28) <> 0 {
+ return "#internal error: inconsistent Huffman decoder state"
+ } else if (table_entry >> 27) <> 0 {
+ return "#bad Huffman code"
} else {
- return "?internal error: inconsistent Huffman decoder state"
+ return "#internal error: inconsistent Huffman decoder state"
}
- } else if (table_entry >> 27) != 0 {
- return "?bad Huffman code"
+ } else if (table_entry >> 27) <> 0 {
+ return "#bad Huffman code"
} else {
- return "?internal error: inconsistent Huffman decoder state"
+ return "#internal error: inconsistent Huffman decoder state"
}
// length = base_number_minus_3 + 3 + extra_bits.
@@ -160,10 +157,7 @@
redir_top = (table_entry >> 8) & 0xFFFF
redir_mask = ((1 as base.u32) << ((table_entry >> 4) & 0x0F)) - 1
while true {
- if (redir_top + (bits & redir_mask)) >= 1234 {
- return "?internal error: inconsistent Huffman decoder state"
- }
- table_entry = this.huffs[1][redir_top + (bits & redir_mask)]
+ table_entry = this.huffs[1][(redir_top + (bits & redir_mask)) & huffs_table_mask]
table_entry_n_bits = table_entry & 0x0F
if n_bits >= table_entry_n_bits {
bits >>= table_entry_n_bits
@@ -178,11 +172,11 @@
}
// For H-D, all symbols should be base_number + extra_bits.
- if (table_entry >> 24) != 0x40 {
+ if (table_entry >> 24) <> 0x40 {
if (table_entry >> 24) == 0x08 {
- return "?bad Huffman code"
+ return "#bad Huffman code"
}
- return "?internal error: inconsistent Huffman decoder state"
+ return "#internal error: inconsistent Huffman decoder state"
}
// dist_minus_1 = base_number_minus_1 + extra_bits.
@@ -224,7 +218,7 @@
length = 0
}
if this.history_index < hdist {
- return "?bad distance"
+ return "#bad distance"
}
// Re-purpose the hdist variable as the this.history index to
// start copying from.
@@ -246,7 +240,7 @@
break
}
}
- yield base."$short write"
+ yield? base."$short write"
}
// Copy from the start of this.history, if we wrapped around.
if hlen > 0 {
@@ -259,7 +253,7 @@
}
hlen -= n_copied
hdist ~mod+= n_copied
- yield base."$short write"
+ yield? base."$short write"
}
}
@@ -276,7 +270,7 @@
break
}
length -= n_copied
- yield base."$short write"
+ yield? base."$short write"
}
}
@@ -285,7 +279,7 @@
this.bits = bits
this.n_bits = n_bits
- if (this.n_bits >= 8) or ((this.bits >> (this.n_bits & 7)) != 0) {
- return "?internal error: inconsistent n_bits"
+ if (this.n_bits >= 8) or ((this.bits >> (this.n_bits & 7)) <> 0) {
+ return "#internal error: inconsistent n_bits"
}
}
diff --git a/std/gif/decode_gif.wuffs b/std/gif/decode_gif.wuffs
index 8e2812c..38b8271 100644
--- a/std/gif/decode_gif.wuffs
+++ b/std/gif/decode_gif.wuffs
@@ -14,15 +14,18 @@
use "std/lzw"
-pub status "?bad block"
-pub status "?bad extension label"
-pub status "?bad graphic control"
-pub status "?bad header"
-pub status "?bad literal width"
-pub status "?not enough pixel data"
-pub status "?too much pixel data"
+pub status "#bad block"
+pub status "#bad extension label"
+pub status "#bad graphic control"
+pub status "#bad header"
+pub status "#bad literal width"
-pri status "?internal error: inconsistent ri/wi"
+pri status "#internal error: inconsistent ri/wi"
+
+// TODO: replace the placeholder 1 value with either 0 or 0xFFFF (plus
+// lzw.decoder_workbuf_len_max_incl_worst_case), depending on whether we'll
+// need a per-pixel-row workbuf.
+pub const decoder_workbuf_len_max_incl_worst_case base.u64 = 1
// See the spec appendix E "Interlaced Images" on page 29. The first element
// represents either that the frame was non-interlaced, or that all interlace
@@ -107,27 +110,29 @@
dst_y base.u32,
dirty_y base.range_ie_u32,
+ // Indexes into the compressed array, defined below.
compressed_ri base.u64,
compressed_wi base.u64,
- compressed array[4096] base.u8,
+
+ swizzler base.pixel_swizzler,
+ util base.utility,
+)(
+ compressed array[4096] base.u8,
// palettes[0] and palettes[1] are the Global and Local Color Table.
palettes array[2] array[4 * 256] base.u8,
// dst_palette is the swizzled color table.
dst_palette array[4 * 256] base.u8,
- swizzler base.pixel_swizzler,
- util base.utility,
- lzw lzw.decoder,
+ lzw lzw.decoder,
)
pub func decoder.decode_image_config?(dst nptr base.image_config, src base.io_reader) {
var ffio base.bool
if this.call_sequence >= 1 {
- return base."?bad call sequence"
+ return base."#bad call sequence"
}
- this.dirty_y.reset!()
this.decode_header?(src:args.src)
this.decode_lsd?(src:args.src)
@@ -141,7 +146,7 @@
(this.frame_rect_x1 == this.width) and
(this.frame_rect_y1 == this.height)
- if args.dst != nullptr {
+ if args.dst <> nullptr {
// TODO: a Wuffs (not just C) name for the
// WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY magic pixfmt constant.
args.dst.set!(
@@ -172,22 +177,28 @@
}
pub func decoder.frame_dirty_rect() base.rect_ie_u32 {
+ // TODO: intersect this with the frame_rect? In theory, that should be
+ // unnecessary, and could hide bugs, but it'd be a cheap way to ensure that
+ // the dirty_rect is inside the frame_rect.
+ //
+ // Note that this method is pure, so it cannot set a sticky error bit if
+ // the dirty_rect is too big.
return this.util.make_rect_ie_u32(
- min_incl_x:this.frame_rect_x0,
+ min_incl_x:this.frame_rect_x0.min(x:this.width),
min_incl_y:this.dirty_y.get_min_incl(),
- max_excl_x:this.frame_rect_x1,
+ max_excl_x:this.frame_rect_x1.min(x:this.width),
max_excl_y:this.dirty_y.get_max_excl())
}
pub func decoder.workbuf_len() base.range_ii_u64 {
return this.util.make_range_ii_u64(
- min_incl:this.width as base.u64,
- max_incl:this.width as base.u64)
+ min_incl:decoder_workbuf_len_max_incl_worst_case,
+ max_incl:decoder_workbuf_len_max_incl_worst_case)
}
pub func decoder.restart_frame!(index base.u64, io_position base.u64) base.status {
if this.call_sequence == 0 {
- return base."?bad call sequence"
+ return base."#bad call sequence"
}
this.end_of_data = false
this.restarted = true
@@ -201,10 +212,12 @@
pub func decoder.decode_frame_config?(dst nptr base.frame_config, src base.io_reader) {
var blend base.u8
+ this.dirty_y.reset!()
+
if not this.end_of_data {
if this.call_sequence == 0 {
this.decode_image_config?(dst:nullptr, src:args.src)
- } else if this.call_sequence != 1 {
+ } else if this.call_sequence <> 1 {
if this.call_sequence == 2 {
this.skip_frame?(src:args.src)
}
@@ -215,7 +228,7 @@
// This is a new "if", not an "else", because the calls above can modify
// this.end_of_data.
if this.end_of_data {
- return base."~end of data"
+ return base."@end of data"
}
blend = 0
@@ -223,7 +236,7 @@
blend = 2 // 2 is WUFFS_BASE__ANIMATION_BLEND__OPAQUE.
}
- if args.dst != nullptr {
+ if args.dst <> nullptr {
args.dst.update!(bounds:this.util.make_rect_ie_u32(
min_incl_x:this.frame_rect_x0.min(x:this.width),
min_incl_y:this.frame_rect_y0.min(x:this.height),
@@ -245,7 +258,7 @@
// Skip the optional Local Color Table, 3 bytes (RGB) per entry.
flags = args.src.read_u8?()
- if (flags & 0x80) != 0 {
+ if (flags & 0x80) <> 0 {
args.src.skip?(n:(3 as base.u32) << (1 + (flags & 0x07)))
}
// Skip the literal width.
@@ -259,7 +272,7 @@
// TODO: honor args.opts.
pub func decoder.decode_frame?(dst ptr base.pixel_buffer, src base.io_reader, workbuf slice base.u8, opts nptr base.decode_frame_options) {
- if this.call_sequence != 2 {
+ if this.call_sequence <> 2 {
this.decode_frame_config?(dst:nullptr, src:args.src)
}
this.decode_id_part1?(dst:args.dst, src:args.src)
@@ -285,8 +298,8 @@
if not this.restarted {
this.frame_config_io_position = args.src.position()
- } else if this.frame_config_io_position != args.src.position() {
- return base."?bad restart"
+ } else if this.frame_config_io_position <> args.src.position() {
+ return base."#bad restart"
} else {
this.restarted = false
}
@@ -302,7 +315,7 @@
this.end_of_data = true
break
} else {
- return "?bad block"
+ return "#bad block"
}
}
}
@@ -318,9 +331,9 @@
c[i] = args.src.read_u8?()
i += 1
}
- if (c[0] != 0x47) or (c[1] != 0x49) or (c[2] != 0x46) or (c[3] != 0x38) or
- ((c[4] != 0x37) and (c[4] != 0x39)) or (c[5] != 0x61) {
- return "?bad header"
+ if (c[0] <> 0x47) or (c[1] <> 0x49) or (c[2] <> 0x46) or (c[3] <> 0x38) or
+ ((c[4] <> 0x37) and (c[4] <> 0x39)) or (c[5] <> 0x61) {
+ return "#bad header"
}
}
@@ -340,7 +353,7 @@
args.src.skip?(n:2)
// Read the optional Global Color Table.
- if (flags & 0x80) != 0 {
+ if (flags & 0x80) <> 0 {
num_palette_entries = (1 as base.u32) << (1 + (flags & 0x07))
i = 0
while i < num_palette_entries {
@@ -431,7 +444,7 @@
// as per:
// - http://www.vurdalakov.net/misc/gif/animexts-looping-application-extension
// - http://www.vurdalakov.net/misc/gif/netscape-looping-application-extension
- if block_size != 11 {
+ if block_size <> 11 {
args.src.skip?(n:block_size as base.u32)
break
}
@@ -440,8 +453,8 @@
block_size = 0 // Re-purpose the block_size variable as a counter.
while block_size < 11 {
c = args.src.read_u8?()
- not_animexts = not_animexts or (c != animexts1dot0[block_size])
- not_netscape = not_netscape or (c != netscape2dot0[block_size])
+ not_animexts = not_animexts or (c <> animexts1dot0[block_size])
+ not_netscape = not_netscape or (c <> netscape2dot0[block_size])
block_size += 1
}
if not_animexts and not_netscape {
@@ -451,12 +464,12 @@
// Those 11 bytes should be followed by 0x03, 0x01 and then the loop
// count.
block_size = args.src.read_u8?()
- if block_size != 3 {
+ if block_size <> 3 {
args.src.skip?(n:block_size as base.u32)
break
}
c = args.src.read_u8?()
- if c != 0x01 {
+ if c <> 0x01 {
args.src.skip?(n:2)
break
}
@@ -489,15 +502,15 @@
var gc_duration_centiseconds base.u16
if this.seen_graphic_control {
- return "?bad graphic control"
+ return "#bad graphic control"
}
c = args.src.read_u8?()
- if c != 4 {
- return "?bad graphic control"
+ if c <> 4 {
+ return "#bad graphic control"
}
flags = args.src.read_u8?()
- this.gc_has_transparent_index = (flags & 0x01) != 0
+ this.gc_has_transparent_index = (flags & 0x01) <> 0
// Convert the disposal method from GIF's wire format to Wuffs constants.
//
@@ -523,8 +536,8 @@
this.gc_transparent_index = args.src.read_u8?()
c = args.src.read_u8?()
- if c != 0 {
- return "?bad graphic control"
+ if c <> 0 {
+ return "#bad graphic control"
}
this.seen_graphic_control = true
}
@@ -571,7 +584,7 @@
var lw base.u8
flags = args.src.read_u8?()
- if (flags & 0x40) != 0 {
+ if (flags & 0x40) <> 0 {
this.interlace = 4
} else {
this.interlace = 0
@@ -579,7 +592,7 @@
// Read the optional Local Color Table.
this.which_palette = 1
- if (flags & 0x80) != 0 {
+ if (flags & 0x80) <> 0 {
num_palette_entries = (1 as base.u32) << (1 + (flags & 0x07))
i = 0
while i < num_palette_entries {
@@ -650,7 +663,7 @@
lw = args.src.read_u8?()
if (lw < 2) or (8 < lw) {
- return "?bad literal width"
+ return "#bad literal width"
}
this.lzw.set_literal_width!(lw:lw as base.u32)
@@ -677,7 +690,7 @@
break
}
while args.src.available() == 0 {
- yield base."$short read"
+ yield? base."$short read"
}
if this.compressed_ri == this.compressed_wi {
@@ -704,18 +717,17 @@
args.src.skip_fast!(actual:1, worst_case:1)
}
- if (this.width as base.u64) < args.workbuf.length() {
- args.workbuf = args.workbuf[:this.width as base.u64]
- } else if (this.width as base.u64) > args.workbuf.length() {
- return base."?bad workbuf length"
+ if decoder_workbuf_len_max_incl_worst_case > args.workbuf.length() {
+ return base."#bad workbuf length"
}
while:inner true {
if (this.compressed_ri > this.compressed_wi) or (this.compressed_wi > 4096) {
- return "?internal error: inconsistent ri/wi"
+ return "#internal error: inconsistent ri/wi"
}
io_bind (io:r, data:this.compressed[this.compressed_ri:this.compressed_wi]) {
- lzw_status =? this.lzw.decode_io_writer?(dst:this.util.null_io_writer(), src:r)
+ lzw_status =? this.lzw.decode_io_writer?(
+ dst:this.util.null_io_writer(), src:r, workbuf:this.util.null_slice_u8())
this.compressed_ri ~sat+= r.since_mark().length()
}
@@ -749,7 +761,11 @@
this.compressed_ri = 0
this.compressed_wi = 0
- // TODO: check for "not enough pixel data".
+ if (this.dst_y < this.frame_rect_y1) and
+ (this.frame_rect_x0 <> this.frame_rect_x1) and
+ (this.frame_rect_y0 <> this.frame_rect_y1) {
+ return base."#not enough data"
+ }
}
pri func decoder.copy_to_image_buffer!(pb ptr base.pixel_buffer, src slice base.u8) base.status {
@@ -779,7 +795,7 @@
src = args.src[src_ri:]
if this.dst_y >= this.frame_rect_y1 {
- return "?too much pixel data"
+ return base."#too much data"
}
// First, copy from src to that part of the frame rect that is inside
@@ -817,7 +833,7 @@
if args.src.length() == src_ri {
break
} else if args.src.length() < src_ri {
- return "?internal error: inconsistent ri/wi"
+ return "#internal error: inconsistent ri/wi"
}
// Second, skip over src for that part of the frame rect that is
@@ -840,8 +856,8 @@
continue
}
- if src_ri != args.src.length() {
- return "?internal error: inconsistent ri/wi"
+ if src_ri <> args.src.length() {
+ return "#internal error: inconsistent ri/wi"
}
break
}
diff --git a/std/gzip/decode_gzip.wuffs b/std/gzip/decode_gzip.wuffs
index 7c44b5c..297b191 100644
--- a/std/gzip/decode_gzip.wuffs
+++ b/std/gzip/decode_gzip.wuffs
@@ -15,22 +15,34 @@
use "std/crc32"
use "std/deflate"
-pub status "?bad checksum"
-pub status "?bad compression method"
-pub status "?bad encoding flags"
-pub status "?bad header"
+pub status "#bad checksum"
+pub status "#bad compression method"
+pub status "#bad encoding flags"
+pub status "#bad header"
+
+// TODO: reference deflate.decoder_workbuf_len_max_incl_worst_case.
+pub const decoder_workbuf_len_max_incl_worst_case base.u64 = 1
pub struct decoder?(
- flate deflate.decoder,
- checksum crc32.ieee_hasher,
ignore_checksum base.bool,
+ checksum crc32.ieee_hasher,
+
+ flate deflate.decoder,
+
+ util base.utility,
)
pub func decoder.set_ignore_checksum!(ic base.bool) {
this.ignore_checksum = args.ic
}
-pub func decoder.decode_io_writer?(dst base.io_writer, src base.io_reader) {
+pub func decoder.workbuf_len() base.range_ii_u64 {
+ return this.util.make_range_ii_u64(
+ min_incl:decoder_workbuf_len_max_incl_worst_case,
+ max_incl:decoder_workbuf_len_max_incl_worst_case)
+}
+
+pub func decoder.decode_io_writer?(dst base.io_writer, src base.io_reader, workbuf slice base.u8) {
var c base.u8
var flags base.u8
var xlen base.u16
@@ -42,23 +54,23 @@
// Read the header.
c = args.src.read_u8?()
- if c != 0x1F {
- return "?bad header"
+ if c <> 0x1F {
+ return "#bad header"
}
c = args.src.read_u8?()
- if c != 0x8B {
- return "?bad header"
+ if c <> 0x8B {
+ return "#bad header"
}
c = args.src.read_u8?()
- if c != 0x08 {
- return "?bad compression method"
+ if c <> 0x08 {
+ return "#bad compression method"
}
flags = args.src.read_u8?()
// TODO: API for returning the header's MTIME field.
args.src.skip?(n:6)
// Handle FEXTRA.
- if (flags & 0x04) != 0 {
+ if (flags & 0x04) <> 0 {
xlen = args.src.read_u16le?()
args.src.skip?(n:xlen as base.u32)
}
@@ -68,7 +80,7 @@
// TODO: API for returning the header's FNAME field. This might require
// converting ISO 8859-1 to UTF-8. We may also want to cap the UTF-8
// filename length to NAME_MAX, which is 255.
- if (flags & 0x08) != 0 {
+ if (flags & 0x08) <> 0 {
while true {
c = args.src.read_u8?()
if c == 0 {
@@ -78,7 +90,7 @@
}
// Handle FCOMMENT.
- if (flags & 0x10) != 0 {
+ if (flags & 0x10) <> 0 {
while true {
c = args.src.read_u8?()
if c == 0 {
@@ -88,19 +100,19 @@
}
// Handle FHCRC.
- if (flags & 0x02) != 0 {
+ if (flags & 0x02) <> 0 {
args.src.skip?(n:2)
}
// Reserved flags bits must be zero.
- if (flags & 0xE0) != 0 {
- return "?bad encoding flags"
+ if (flags & 0xE0) <> 0 {
+ return "#bad encoding flags"
}
// Decode and checksum the DEFLATE-encoded payload.
while true {
args.dst.set_mark!()
- status =? this.flate.decode_io_writer?(dst:args.dst, src:args.src)
+ status =? this.flate.decode_io_writer?(dst:args.dst, src:args.src, workbuf:args.workbuf)
if not this.ignore_checksum {
checksum_got = this.checksum.update!(x:args.dst.since_mark())
decoded_length_got ~mod+= ((args.dst.since_mark().length() & 0xFFFFFFFF) as base.u32)
@@ -108,12 +120,12 @@
if status.is_ok() {
break
}
- yield status
+ yield? status
}
checksum_want = args.src.read_u32le?()
decoded_length_want = args.src.read_u32le?()
if (not this.ignore_checksum) and
- ((checksum_got != checksum_want) or (decoded_length_got != decoded_length_want)) {
- return "?bad checksum"
+ ((checksum_got <> checksum_want) or (decoded_length_got <> decoded_length_want)) {
+ return "#bad checksum"
}
}
diff --git a/std/lzw/decode_lzw.wuffs b/std/lzw/decode_lzw.wuffs
index 1543ef0..7f3698c 100644
--- a/std/lzw/decode_lzw.wuffs
+++ b/std/lzw/decode_lzw.wuffs
@@ -12,15 +12,26 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-pub status "?bad code"
+pub status "#bad code"
-pri status "?internal error: inconsistent I/O"
+pri status "#internal error: inconsistent I/O"
+
+// TODO: move bulk data buffers like decoder.suffixes or decoder.output into
+// the workbuf? The first attempt at this was a performance regression for
+// decoding all but the smallest GIFs. See these git commits for numbers:
+// - 49627b4 Flatten the lzw.decoder.suffixes array
+// - f877fb2 Use the workbuf instead of lzw.decoder.suffixes
+// - 85be5b9 Delete the obsolete lzw.decoder.suffixes array
+// and the roll back has combined numbers:
+// - 3056a84 Roll back 3 recent lzw.decoder.suffixes commits
+pub const decoder_workbuf_len_max_incl_worst_case base.u64 = 0
pub struct decoder?(
- // The value passed to set_literal_width. This lw field is copied to the
- // literal_width field at the start of the decode method. During that
- // method, calling set_literal_width will change lw but not literal_width.
- lw base.u32[..8],
+ // set_literal_width_arg is the saved argument passed to set_literal_width.
+ // This field is copied to the literal_width field at the start of
+ // decode_io_writer. During that method, calling set_literal_width will
+ // change set_literal_width_arg but not literal_width.
+ set_literal_width_arg base.u32[..8],
// read_from state that does not change during a decode call.
literal_width base.u32[..8],
@@ -43,11 +54,15 @@
read_from_return_value base.u32,
// read_from per-code state.
- suffixes array[4096] array[8] base.u8,
prefixes array[4096] base.u16[..4095],
+
+ util base.utility,
+)(
+ // read_from per-code state.
+ suffixes array[4096] array[8] base.u8,
// lm1s is the "length minus 1"s of the values for the implicit key-value
// table in this decoder. See std/lzw/README.md for more detail.
- lm1s array[4096] base.u16[..4095],
+ lm1s array[4096] base.u16,
// output[output_ri:output_wi] is the buffered output, connecting read_from
// with write_to and flush.
@@ -55,16 +70,20 @@
)
pub func decoder.set_literal_width!(lw base.u32[2..8]) {
- this.lw = args.lw
+ this.set_literal_width_arg = args.lw
}
-pub func decoder.decode_io_writer?(dst base.io_writer, src base.io_reader) {
+pub func decoder.workbuf_len() base.range_ii_u64 {
+ return this.util.make_range_ii_u64(min_incl:0, max_incl:0)
+}
+
+pub func decoder.decode_io_writer?(dst base.io_writer, src base.io_reader, workbuf slice base.u8) {
var i base.u32[..8191]
// Initialize read_from state.
this.literal_width = 8
- if this.lw >= 2 {
- this.literal_width = this.lw
+ if this.set_literal_width_arg >= 2 {
+ this.literal_width = this.set_literal_width_arg
}
this.clear_code = (1 as base.u32) << this.literal_width
this.end_code = this.clear_code + 1
@@ -95,11 +114,11 @@
} else if this.read_from_return_value == 1 {
continue
} else if this.read_from_return_value == 2 {
- yield base."$short read"
+ yield? base."$short read"
} else if this.read_from_return_value == 3 {
- return "?bad code"
+ return "#bad code"
} else {
- return "?internal error: inconsistent I/O"
+ return "#internal error: inconsistent I/O"
}
}
}
@@ -182,10 +201,10 @@
this.output[output_wi] = code as base.u8
output_wi = (output_wi + 1) & 8191
if save_code <= 4095 {
- lm1_a = (this.lm1s[prev_code] + 1) & 4095
+ lm1_a = (this.lm1s[prev_code] ~mod+ 1) & 4095
this.lm1s[save_code] = lm1_a
- if (lm1_a % 8) != 0 {
+ if (lm1_a % 8) <> 0 {
this.prefixes[save_code] = this.prefixes[prev_code]
this.suffixes[save_code] = this.suffixes[prev_code]
this.suffixes[save_code][lm1_a % 8] = code as base.u8
@@ -255,10 +274,10 @@
}
if save_code <= 4095 {
- lm1_b = (this.lm1s[prev_code] + 1) & 4095
+ lm1_b = (this.lm1s[prev_code] ~mod+ 1) & 4095
this.lm1s[save_code] = lm1_b
- if (lm1_b % 8) != 0 {
+ if (lm1_b % 8) <> 0 {
this.prefixes[save_code] = this.prefixes[prev_code]
this.suffixes[save_code] = this.suffixes[prev_code]
this.suffixes[save_code][lm1_b % 8] = first_byte
@@ -291,7 +310,7 @@
// Rewind args.src, if we're not in "$short read" and we've read too many
// bits.
- if this.read_from_return_value != 2 {
+ if this.read_from_return_value <> 2 {
while n_bits >= 8 {
n_bits -= 8
if args.src.can_undo_byte() {
@@ -317,7 +336,7 @@
while this.output_wi > 0 {
if this.output_ri > this.output_wi {
- return "?internal error: inconsistent I/O"
+ return "#internal error: inconsistent I/O"
}
s = this.output[this.output_ri:this.output_wi]
n = args.dst.copy_from_slice!(s:s)
@@ -327,7 +346,7 @@
return ok
}
this.output_ri = (this.output_ri ~mod+ ((n & 0xFFFFFFFF) as base.u32)) & 8191
- yield base."$short write"
+ yield? base."$short write"
}
}
diff --git a/std/zlib/decode_zlib.wuffs b/std/zlib/decode_zlib.wuffs
index f6d09e0..b7b5817 100644
--- a/std/zlib/decode_zlib.wuffs
+++ b/std/zlib/decode_zlib.wuffs
@@ -15,57 +15,69 @@
use "std/adler32"
use "std/deflate"
-pub status "?bad checksum"
-pub status "?bad compression method"
-pub status "?bad compression window size"
-pub status "?bad parity check"
+pub status "#bad checksum"
+pub status "#bad compression method"
+pub status "#bad compression window size"
+pub status "#bad parity check"
-pri status "?TODO: unsupported preset dictionary"
+pri status "#TODO: unsupported preset dictionary"
+
+// TODO: reference deflate.decoder_workbuf_len_max_incl_worst_case.
+pub const decoder_workbuf_len_max_incl_worst_case base.u64 = 1
pub struct decoder?(
- flate deflate.decoder,
- checksum adler32.hasher,
ignore_checksum base.bool,
+ checksum adler32.hasher,
+
+ flate deflate.decoder,
+
+ util base.utility,
)
pub func decoder.set_ignore_checksum!(ic base.bool) {
this.ignore_checksum = args.ic
}
-pub func decoder.decode_io_writer?(dst base.io_writer, src base.io_reader) {
+pub func decoder.workbuf_len() base.range_ii_u64 {
+ return this.util.make_range_ii_u64(
+ min_incl:decoder_workbuf_len_max_incl_worst_case,
+ max_incl:decoder_workbuf_len_max_incl_worst_case)
+}
+
+pub func decoder.decode_io_writer?(dst base.io_writer, src base.io_reader, workbuf slice base.u8) {
var x base.u16
var checksum_got base.u32
var status base.status
var checksum_want base.u32
x = args.src.read_u16be?()
- if ((x >> 8) & 0x0F) != 0x08 {
- return "?bad compression method"
+ if ((x >> 8) & 0x0F) <> 0x08 {
+ return "#bad compression method"
}
if (x >> 12) > 0x07 {
- return "?bad compression window size"
+ return "#bad compression window size"
}
- if (x & 0x20) != 0 {
- return "?TODO: unsupported preset dictionary"
+ if (x & 0x20) <> 0 {
+ return "#TODO: unsupported preset dictionary"
}
- if (x % 31) != 0 {
- return "?bad parity check"
+ if (x % 31) <> 0 {
+ return "#bad parity check"
}
// Decode and checksum the DEFLATE-encoded payload.
while true {
args.dst.set_mark!()
- status =? this.flate.decode_io_writer?(dst:args.dst, src:args.src)
+ status =? this.flate.decode_io_writer?(dst:args.dst, src:args.src, workbuf:args.workbuf)
if not this.ignore_checksum {
checksum_got = this.checksum.update!(x:args.dst.since_mark())
}
if status.is_ok() {
break
}
- yield status
+ yield? status
}
checksum_want = args.src.read_u32be?()
- if (not this.ignore_checksum) and (checksum_got != checksum_want) {
- return "?bad checksum"
+ if (not this.ignore_checksum) and (checksum_got <> checksum_want) {
+ return "#bad checksum"
}
}
diff --git a/test/c/mimiclib/deflate-gzip-zlib.c b/test/c/mimiclib/deflate-gzip-zlib.c
index 635eb1e..9b9c0c3 100644
--- a/test/c/mimiclib/deflate-gzip-zlib.c
+++ b/test/c/mimiclib/deflate-gzip-zlib.c
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// ----------------
+
// Uncomment this line to test and bench miniz instead of zlib-the-library.
// #define WUFFS_MIMICLIB_USE_MINIZ_INSTEAD_OF_ZLIB 1
@@ -20,6 +22,7 @@
const char* mimic_bench_adler32(wuffs_base__io_buffer* dst,
wuffs_base__io_buffer* src,
+ uint32_t wuffs_initialize_flags,
uint64_t wlimit,
uint64_t rlimit) {
return "miniz does not independently compute Adler32";
@@ -27,6 +30,7 @@
const char* mimic_bench_crc32_ieee(wuffs_base__io_buffer* dst,
wuffs_base__io_buffer* src,
+ uint32_t wuffs_initialize_flags,
uint64_t wlimit,
uint64_t rlimit) {
return "miniz does not implement CRC32/IEEE";
@@ -34,6 +38,7 @@
const char* mimic_deflate_zlib_decode(wuffs_base__io_buffer* dst,
wuffs_base__io_buffer* src,
+ uint32_t wuffs_initialize_flags,
uint64_t wlimit,
uint64_t rlimit,
bool deflate_instead_of_zlib) {
@@ -85,6 +90,7 @@
const char* mimic_bench_adler32(wuffs_base__io_buffer* dst,
wuffs_base__io_buffer* src,
+ uint32_t wuffs_initialize_flags,
uint64_t wlimit,
uint64_t rlimit) {
global_mimiclib_deflate_unused_u32 = 0;
@@ -105,6 +111,7 @@
const char* mimic_bench_crc32_ieee(wuffs_base__io_buffer* dst,
wuffs_base__io_buffer* src,
+ uint32_t wuffs_initialize_flags,
uint64_t wlimit,
uint64_t rlimit) {
global_mimiclib_deflate_unused_u32 = 0;
@@ -200,6 +207,9 @@
if (i_err == Z_STREAM_END) {
break;
+ } else if (i_err == Z_DATA_ERROR) {
+ ret = "inflate failed (data error)";
+ goto cleanup1;
} else if (i_err != Z_OK) {
ret = "inflate failed";
goto cleanup1;
@@ -218,6 +228,7 @@
const char* mimic_deflate_decode(wuffs_base__io_buffer* dst,
wuffs_base__io_buffer* src,
+ uint32_t wuffs_initialize_flags,
uint64_t wlimit,
uint64_t rlimit) {
return mimic_deflate_gzip_zlib_decode(dst, src, wlimit, rlimit,
@@ -226,6 +237,7 @@
const char* mimic_gzip_decode(wuffs_base__io_buffer* dst,
wuffs_base__io_buffer* src,
+ uint32_t wuffs_initialize_flags,
uint64_t wlimit,
uint64_t rlimit) {
return mimic_deflate_gzip_zlib_decode(dst, src, wlimit, rlimit,
@@ -234,6 +246,7 @@
const char* mimic_zlib_decode(wuffs_base__io_buffer* dst,
wuffs_base__io_buffer* src,
+ uint32_t wuffs_initialize_flags,
uint64_t wlimit,
uint64_t rlimit) {
return mimic_deflate_gzip_zlib_decode(dst, src, wlimit, rlimit,
diff --git a/test/c/mimiclib/gif.c b/test/c/mimiclib/gif.c
index f9caed4..3e190fd 100644
--- a/test/c/mimiclib/gif.c
+++ b/test/c/mimiclib/gif.c
@@ -30,6 +30,7 @@
}
const char* mimic_gif_decode(wuffs_base__io_buffer* dst,
+ uint32_t wuffs_initialize_flags,
wuffs_base__pixel_format pixfmt,
wuffs_base__io_buffer* src) {
const char* ret = NULL;
diff --git a/test/c/std/adler32.c b/test/c/std/adler32.c
index 2b085b7..9e509a9 100644
--- a/test/c/std/adler32.c
+++ b/test/c/std/adler32.c
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// ----------------
+
/*
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
@@ -127,11 +129,12 @@
int j;
for (j = 0; j < 2; j++) {
- wuffs_adler32__hasher checksum = ((wuffs_adler32__hasher){});
- status = wuffs_adler32__hasher__check_wuffs_version(
- &checksum, sizeof checksum, WUFFS_VERSION);
+ wuffs_adler32__hasher checksum;
+ status = wuffs_adler32__hasher__initialize(
+ &checksum, sizeof checksum, WUFFS_VERSION,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
- RETURN_FAIL("check_wuffs_version: \"%s\"", status);
+ RETURN_FAIL("initialize: \"%s\"", status);
}
uint32_t got = 0;
@@ -165,15 +168,17 @@
CHECK_FOCUS(__func__);
const char* digits =
- "3.1415926535897932384626433832795028841971693993751058209749445";
- if (strlen(digits) != 63) {
- RETURN_FAIL("strlen(digits): got %d, want 63", (int)(strlen(digits)));
+ "3."
+ "141592653589793238462643383279502884197169399375105820974944592307816406"
+ "2862089986280348253421170";
+ if (strlen(digits) != 99) {
+ RETURN_FAIL("strlen(digits): got %d, want 99", (int)(strlen(digits)));
}
// The want values are determined by script/checksum.go.
//
// wants[i] is the checksum of the first i bytes of the digits string.
- uint32_t wants[64] = {
+ uint32_t wants[100] = {
0x00000001, 0x00340034, 0x00960062, 0x01290093, 0x01F000C7, 0x02E800F8,
0x0415012D, 0x057B0166, 0x07130198, 0x08E101CE, 0x0AE40203, 0x0D1A0236,
0x0F85026B, 0x122802A3, 0x150402DC, 0x18170313, 0x1B63034C, 0x1EE2037F,
@@ -184,16 +189,23 @@
0xB8E508A2, 0xC1BD08D8, 0xCACE0911, 0xD4120944, 0xDD8F097D, 0xE74509B6,
0xF12E09E9, 0xFB4E0A20, 0x05B20A55, 0x10380A86, 0x1AEE0AB6, 0x25D90AEB,
0x30FC0B23, 0x3C510B55, 0x47D60B85, 0x53940BBE, 0x5F890BF5, 0x6BB20C29,
- 0x78140C62, 0x84AA0C96, 0x91740CCA, 0x9E730CFF,
+ 0x78140C62, 0x84AA0C96, 0x91740CCA, 0x9E730CFF, 0xABAB0D38, 0xB9150D6A,
+ 0xC6B20D9D, 0xD47F0DCD, 0xE2830E04, 0xF0BF0E3C, 0xFF2C0E6D, 0x0DDE0EA3,
+ 0x1CB50ED7, 0x2BBC0F07, 0x3AF90F3D, 0x4A680F6F, 0x5A0F0FA7, 0x69EC0FDD,
+ 0x79FB100F, 0x8A3A103F, 0x9AB11077, 0xAB6110B0, 0xBC4A10E9, 0xCD6B1121,
+ 0xDEC21157, 0xF04B1189, 0x021B11C1, 0x140C11F1, 0x26301224, 0x38881258,
+ 0x4B181290, 0x5DDA12C2, 0x70D112F7, 0x83FB132A, 0x9759135E, 0xAAE91390,
+ 0xBEAA13C1, 0xD29C13F2, 0xE6C51429, 0xFB1E1459,
};
int i;
- for (i = 0; i < 64; i++) {
- wuffs_adler32__hasher checksum = ((wuffs_adler32__hasher){});
- const char* status = wuffs_adler32__hasher__check_wuffs_version(
- &checksum, sizeof checksum, WUFFS_VERSION);
+ for (i = 0; i < 100; i++) {
+ wuffs_adler32__hasher checksum;
+ const char* status = wuffs_adler32__hasher__initialize(
+ &checksum, sizeof checksum, WUFFS_VERSION,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
- RETURN_FAIL("check_wuffs_version: \"%s\"", status);
+ RETURN_FAIL("initialize: \"%s\"", status);
}
uint32_t got =
wuffs_adler32__hasher__update(&checksum, ((wuffs_base__slice_u8){
@@ -214,15 +226,16 @@
const char* wuffs_bench_adler32(wuffs_base__io_buffer* dst,
wuffs_base__io_buffer* src,
+ uint32_t wuffs_initialize_flags,
uint64_t wlimit,
uint64_t rlimit) {
uint64_t len = src->meta.wi - src->meta.ri;
if (rlimit) {
len = wuffs_base__u64__min(len, rlimit);
}
- wuffs_adler32__hasher checksum = ((wuffs_adler32__hasher){});
- const char* status = wuffs_adler32__hasher__check_wuffs_version(
- &checksum, sizeof checksum, WUFFS_VERSION);
+ wuffs_adler32__hasher checksum;
+ const char* status = wuffs_adler32__hasher__initialize(
+ &checksum, sizeof checksum, WUFFS_VERSION, wuffs_initialize_flags);
if (status) {
return status;
}
@@ -237,14 +250,18 @@
const char* bench_wuffs_adler32_10k() {
CHECK_FOCUS(__func__);
- return do_bench_io_buffers(wuffs_bench_adler32, tc_src, &adler32_midsummer_gt,
- 0, 0, 1500);
+ return do_bench_io_buffers(
+ wuffs_bench_adler32,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED, tc_src,
+ &adler32_midsummer_gt, 0, 0, 1500);
}
const char* bench_wuffs_adler32_100k() {
CHECK_FOCUS(__func__);
- return do_bench_io_buffers(wuffs_bench_adler32, tc_src, &adler32_pi_gt, 0, 0,
- 150);
+ return do_bench_io_buffers(
+ wuffs_bench_adler32,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED, tc_src,
+ &adler32_pi_gt, 0, 0, 150);
}
// ---------------- Mimic Benches
@@ -253,14 +270,14 @@
const char* bench_mimic_adler32_10k() {
CHECK_FOCUS(__func__);
- return do_bench_io_buffers(mimic_bench_adler32, tc_src, &adler32_midsummer_gt,
- 0, 0, 1500);
+ return do_bench_io_buffers(mimic_bench_adler32, 0, tc_src,
+ &adler32_midsummer_gt, 0, 0, 1500);
}
const char* bench_mimic_adler32_100k() {
CHECK_FOCUS(__func__);
- return do_bench_io_buffers(mimic_bench_adler32, tc_src, &adler32_pi_gt, 0, 0,
- 150);
+ return do_bench_io_buffers(mimic_bench_adler32, 0, tc_src, &adler32_pi_gt, 0,
+ 0, 150);
}
#endif // WUFFS_MIMIC
diff --git a/test/c/std/crc32.c b/test/c/std/crc32.c
index 5ea1d3c..b2c395d 100644
--- a/test/c/std/crc32.c
+++ b/test/c/std/crc32.c
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// ----------------
+
/*
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
@@ -127,11 +129,12 @@
int j;
for (j = 0; j < 2; j++) {
- wuffs_crc32__ieee_hasher checksum = ((wuffs_crc32__ieee_hasher){});
- status = wuffs_crc32__ieee_hasher__check_wuffs_version(
- &checksum, sizeof checksum, WUFFS_VERSION);
+ wuffs_crc32__ieee_hasher checksum;
+ status = wuffs_crc32__ieee_hasher__initialize(
+ &checksum, sizeof checksum, WUFFS_VERSION,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
- RETURN_FAIL("check_wuffs_version: \"%s\"", status);
+ RETURN_FAIL("initialize: \"%s\"", status);
}
uint32_t got = 0;
@@ -163,15 +166,17 @@
const char* do_test_xxxxx_crc32_ieee_pi(bool mimic) {
const char* digits =
- "3.1415926535897932384626433832795028841971693993751058209749445";
- if (strlen(digits) != 63) {
- RETURN_FAIL("strlen(digits): got %d, want 63", (int)(strlen(digits)));
+ "3."
+ "141592653589793238462643383279502884197169399375105820974944592307816406"
+ "2862089986280348253421170";
+ if (strlen(digits) != 99) {
+ RETURN_FAIL("strlen(digits): got %d, want 99", (int)(strlen(digits)));
}
// The want values are determined by script/checksum.go.
//
// wants[i] is the checksum of the first i bytes of the digits string.
- uint32_t wants[64] = {
+ uint32_t wants[100] = {
0x00000000, 0x6DD28E9B, 0x69647A00, 0x83B58BCD, 0x16E010BE, 0xAF13912C,
0xB6C654DC, 0x02D43F2E, 0xC60167FD, 0xDE72F5D2, 0xECB2EAA3, 0x22E1CE23,
0x26F4BB12, 0x099FD2E0, 0x2D041A2F, 0xC14373C1, 0x61A5D6D0, 0xEB60F999,
@@ -182,11 +187,17 @@
0x63623EDF, 0x0BB7D76F, 0x5001AC9B, 0x0A5FC5FB, 0xA76213D4, 0x0C1E135B,
0x916718F4, 0xD0FE1B9F, 0xE4D15B60, 0xCE8A5FB4, 0x381922EB, 0xB351097C,
0xA3003B0D, 0x64C7C28B, 0x8ED5424B, 0x6C872ADF, 0x7CBF02ED, 0x2D713AFF,
- 0xA028F932, 0x3BC16241, 0xF256AB5C, 0xE69E60DA,
+ 0xA028F932, 0x3BC16241, 0xF256AB5C, 0xE69E60DA, 0xEBE7C22F, 0xB1EF6496,
+ 0x740F578E, 0xFEAF7E51, 0x762D849E, 0xEDC1C4D4, 0x028F38BE, 0x31636BA7,
+ 0xBB354E18, 0xE70C7239, 0x425AFE6E, 0xB09DA8AC, 0x25D02578, 0x4343533F,
+ 0xACF0D063, 0x20CC1F13, 0x7E9EDAD2, 0xE5A44AA7, 0xC550F584, 0x101040DF,
+ 0x0BC4A511, 0x706E5A5A, 0x71CE81A3, 0xBB75E3F2, 0x3EDA6848, 0x8B8F08F2,
+ 0xA9384B2B, 0xB6C07F06, 0x6D644EE4, 0xCAD8CCB4, 0x3F70B461, 0x205F9F77,
+ 0x4D9D54B7, 0xD69454CC, 0xF8BB504D, 0xFC4E595C,
};
int i;
- for (i = 0; i < 64; i++) {
+ for (i = 0; i < 100; i++) {
uint32_t got;
wuffs_base__slice_u8 data = ((wuffs_base__slice_u8){
.ptr = (uint8_t*)(digits),
@@ -210,11 +221,12 @@
got ^= 0xFFFFFFFF;
} else {
- wuffs_crc32__ieee_hasher checksum = ((wuffs_crc32__ieee_hasher){});
- const char* status = wuffs_crc32__ieee_hasher__check_wuffs_version(
- &checksum, sizeof checksum, WUFFS_VERSION);
+ wuffs_crc32__ieee_hasher checksum;
+ const char* status = wuffs_crc32__ieee_hasher__initialize(
+ &checksum, sizeof checksum, WUFFS_VERSION,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
- RETURN_FAIL("check_wuffs_version: \"%s\"", status);
+ RETURN_FAIL("initialize: \"%s\"", status);
}
got = wuffs_crc32__ieee_hasher__update(&checksum, data);
}
@@ -249,15 +261,16 @@
const char* wuffs_bench_crc32_ieee(wuffs_base__io_buffer* dst,
wuffs_base__io_buffer* src,
+ uint32_t wuffs_initialize_flags,
uint64_t wlimit,
uint64_t rlimit) {
uint64_t len = src->meta.wi - src->meta.ri;
if (rlimit) {
len = wuffs_base__u64__min(len, rlimit);
}
- wuffs_crc32__ieee_hasher checksum = ((wuffs_crc32__ieee_hasher){});
- const char* status = wuffs_crc32__ieee_hasher__check_wuffs_version(
- &checksum, sizeof checksum, WUFFS_VERSION);
+ wuffs_crc32__ieee_hasher checksum;
+ const char* status = wuffs_crc32__ieee_hasher__initialize(
+ &checksum, sizeof checksum, WUFFS_VERSION, wuffs_initialize_flags);
if (status) {
return status;
}
@@ -272,14 +285,18 @@
const char* bench_wuffs_crc32_ieee_10k() {
CHECK_FOCUS(__func__);
- return do_bench_io_buffers(wuffs_bench_crc32_ieee, tc_src,
- &crc32_midsummer_gt, 0, 0, 1500);
+ return do_bench_io_buffers(
+ wuffs_bench_crc32_ieee,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED, tc_src,
+ &crc32_midsummer_gt, 0, 0, 1500);
}
const char* bench_wuffs_crc32_ieee_100k() {
CHECK_FOCUS(__func__);
- return do_bench_io_buffers(wuffs_bench_crc32_ieee, tc_src, &crc32_pi_gt, 0, 0,
- 150);
+ return do_bench_io_buffers(
+ wuffs_bench_crc32_ieee,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED, tc_src,
+ &crc32_pi_gt, 0, 0, 150);
}
// ---------------- Mimic Benches
@@ -288,14 +305,14 @@
const char* bench_mimic_crc32_ieee_10k() {
CHECK_FOCUS(__func__);
- return do_bench_io_buffers(mimic_bench_crc32_ieee, tc_src,
+ return do_bench_io_buffers(mimic_bench_crc32_ieee, 0, tc_src,
&crc32_midsummer_gt, 0, 0, 1500);
}
const char* bench_mimic_crc32_ieee_100k() {
CHECK_FOCUS(__func__);
- return do_bench_io_buffers(mimic_bench_crc32_ieee, tc_src, &crc32_pi_gt, 0, 0,
- 150);
+ return do_bench_io_buffers(mimic_bench_crc32_ieee, 0, tc_src, &crc32_pi_gt, 0,
+ 0, 150);
}
#endif // WUFFS_MIMIC
diff --git a/test/c/std/deflate.c b/test/c/std/deflate.c
index 3f340c2..b011709 100644
--- a/test/c/std/deflate.c
+++ b/test/c/std/deflate.c
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// ----------------
+
/*
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
@@ -98,6 +100,13 @@
"deflate-distance-32768.deflate",
};
+golden_test deflate_deflate_distance_code_31_gt = {
+ .want_filename = "test/data/artificial/0.bytes",
+ .src_filename =
+ "test/data/artificial/"
+ "deflate-distance-code-31.deflate",
+};
+
golden_test deflate_midsummer_gt = {
.want_filename = "test/data/midsummer.txt", //
.src_filename = "test/data/midsummer.txt.gz", //
@@ -128,13 +137,14 @@
const char* wuffs_deflate_decode(wuffs_base__io_buffer* dst,
wuffs_base__io_buffer* src,
+ uint32_t wuffs_initialize_flags,
uint64_t wlimit,
uint64_t rlimit) {
- wuffs_deflate__decoder dec = ((wuffs_deflate__decoder){});
- const char* status = wuffs_deflate__decoder__check_wuffs_version(
- &dec, sizeof dec, WUFFS_VERSION);
+ wuffs_deflate__decoder dec;
+ const char* status = wuffs_deflate__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION, wuffs_initialize_flags);
if (status) {
- RETURN_FAIL("check_wuffs_version: \"%s\"", status);
+ RETURN_FAIL("initialize: \"%s\"", status);
}
while (true) {
@@ -147,8 +157,8 @@
set_reader_limit(&src_reader, rlimit);
}
- status =
- wuffs_deflate__decoder__decode_io_writer(&dec, dst_writer, src_reader);
+ status = wuffs_deflate__decoder__decode_io_writer(
+ &dec, dst_writer, src_reader, global_work_slice);
if ((wlimit && (status == wuffs_base__suspension__short_write)) ||
(rlimit && (status == wuffs_base__suspension__short_read))) {
@@ -175,6 +185,17 @@
&deflate_deflate_distance_32768_gt, 0, 0);
}
+const char* test_wuffs_deflate_decode_deflate_distance_code_31() {
+ CHECK_FOCUS(__func__);
+ const char* got = do_test_io_buffers(
+ wuffs_deflate_decode, &deflate_deflate_distance_code_31_gt, 0, 0);
+ if (got != wuffs_deflate__error__bad_huffman_code) {
+ RETURN_FAIL("got \"%s\", want \"%s\"", got,
+ wuffs_deflate__error__bad_huffman_code);
+ }
+ return NULL;
+}
+
const char* test_wuffs_deflate_decode_midsummer() {
CHECK_FOCUS(__func__);
return do_test_io_buffers(wuffs_deflate_decode, &deflate_midsummer_gt, 0, 0);
@@ -246,24 +267,25 @@
}
got.meta.wi = 0;
- wuffs_deflate__decoder dec = ((wuffs_deflate__decoder){});
- status = wuffs_deflate__decoder__check_wuffs_version(&dec, sizeof dec,
- WUFFS_VERSION);
+ wuffs_deflate__decoder dec;
+ status = wuffs_deflate__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
- RETURN_FAIL("check_wuffs_version: \"%s\"", status);
+ RETURN_FAIL("initialize: \"%s\"", status);
}
src.meta.closed = false;
src.meta.ri = gt->src_offset0;
src.meta.wi = split;
- const char* z0 =
- wuffs_deflate__decoder__decode_io_writer(&dec, dst_writer, src_reader);
+ const char* z0 = wuffs_deflate__decoder__decode_io_writer(
+ &dec, dst_writer, src_reader, global_work_slice);
src.meta.closed = true;
src.meta.ri = split;
src.meta.wi = gt->src_offset1;
- const char* z1 =
- wuffs_deflate__decoder__decode_io_writer(&dec, dst_writer, src_reader);
+ const char* z1 = wuffs_deflate__decoder__decode_io_writer(
+ &dec, dst_writer, src_reader, global_work_slice);
if (z0 != wuffs_base__suspension__short_read) {
RETURN_FAIL("i=%d: z0: got \"%s\", want \"%s\"", i, z0,
@@ -304,8 +326,8 @@
set_writer_limit(&dst_writer, limit);
- const char* got_z =
- wuffs_deflate__decoder__decode_io_writer(dec, dst_writer, src_reader);
+ const char* got_z = wuffs_deflate__decoder__decode_io_writer(
+ dec, dst_writer, src_reader, global_work_slice);
if (got_z != want_z) {
RETURN_FAIL("i=%d: starting_history_index=0x%04" PRIX32
": decode status: got \"%s\", want \"%s\"",
@@ -341,11 +363,12 @@
const int full_history_size = 0x8000;
int i;
for (i = -2; i <= +2; i++) {
- wuffs_deflate__decoder dec = ((wuffs_deflate__decoder){});
- status = wuffs_deflate__decoder__check_wuffs_version(&dec, sizeof dec,
- WUFFS_VERSION);
+ wuffs_deflate__decoder dec;
+ status = wuffs_deflate__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
- RETURN_FAIL("check_wuffs_version: \"%s\"", status);
+ RETURN_FAIL("initialize: \"%s\"", status);
}
status = do_test_wuffs_deflate_history(
@@ -366,7 +389,7 @@
wuffs_base__io_buffer history_got = ((wuffs_base__io_buffer){
.data = ((wuffs_base__slice_u8){
- .ptr = dec.private_impl.f_history,
+ .ptr = dec.private_data.f_history,
.len = full_history_size,
}),
});
@@ -419,11 +442,14 @@
const char* fragment = "3.14";
const uint32_t fragment_length = 4;
- wuffs_deflate__decoder dec = ((wuffs_deflate__decoder){});
- status = wuffs_deflate__decoder__check_wuffs_version(&dec, sizeof dec,
- WUFFS_VERSION);
+ wuffs_deflate__decoder dec;
+ memset(&(dec.private_data.f_history), 0,
+ sizeof(dec.private_data.f_history));
+ status = wuffs_deflate__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
- RETURN_FAIL("check_wuffs_version: \"%s\"", status);
+ RETURN_FAIL("initialize: \"%s\"", status);
}
status = do_test_wuffs_deflate_history(
@@ -448,7 +474,7 @@
int j;
for (j = -2; j < (int)(fragment_length) + 2; j++) {
uint32_t index = (starting_history_index + j) & 0x7FFF;
- uint8_t got = dec.private_impl.f_history[index];
+ uint8_t got = dec.private_data.f_history[index];
uint8_t want = (0 <= j && j < fragment_length) ? fragment[j] : 0;
if (got != want) {
RETURN_FAIL("i=%d: starting_history_index=0x%04" PRIX32
@@ -506,29 +532,31 @@
// 1st is the key in the first level table (9 bits).
// 2nd is the key in the second level table (variable bits).
- wuffs_deflate__decoder dec = ((wuffs_deflate__decoder){});
- const char* status = wuffs_deflate__decoder__check_wuffs_version(
- &dec, sizeof dec, WUFFS_VERSION);
+ wuffs_deflate__decoder dec;
+ const char* status = wuffs_deflate__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
- RETURN_FAIL("check_wuffs_version: \"%s\"", status);
+ RETURN_FAIL("initialize: \"%s\"", status);
}
+ memset(&(dec.private_data.f_huffs), 0, sizeof(dec.private_data.f_huffs));
int i;
int n = 0;
- dec.private_impl.f_code_lengths[n++] = 1;
- dec.private_impl.f_code_lengths[n++] = 2;
- dec.private_impl.f_code_lengths[n++] = 3;
- dec.private_impl.f_code_lengths[n++] = 4;
- dec.private_impl.f_code_lengths[n++] = 5;
- dec.private_impl.f_code_lengths[n++] = 6;
- dec.private_impl.f_code_lengths[n++] = 7;
- dec.private_impl.f_code_lengths[n++] = 9;
- dec.private_impl.f_code_lengths[n++] = 10;
+ dec.private_data.f_code_lengths[n++] = 1;
+ dec.private_data.f_code_lengths[n++] = 2;
+ dec.private_data.f_code_lengths[n++] = 3;
+ dec.private_data.f_code_lengths[n++] = 4;
+ dec.private_data.f_code_lengths[n++] = 5;
+ dec.private_data.f_code_lengths[n++] = 6;
+ dec.private_data.f_code_lengths[n++] = 7;
+ dec.private_data.f_code_lengths[n++] = 9;
+ dec.private_data.f_code_lengths[n++] = 10;
for (i = 0; i < 19; i++) {
- dec.private_impl.f_code_lengths[n++] = 12;
+ dec.private_data.f_code_lengths[n++] = 12;
}
- dec.private_impl.f_code_lengths[n++] = 13;
- dec.private_impl.f_code_lengths[n++] = 13;
+ dec.private_data.f_code_lengths[n++] = 13;
+ dec.private_data.f_code_lengths[n++] = 13;
status = wuffs_deflate__decoder__init_huff(&dec, 0, 0, n, 257);
if (status) {
@@ -538,10 +566,10 @@
// There is one 1st-level table (9 bits), and three 2nd-level tables (3, 3
// and 4 bits). f_huffs[0]'s elements should be non-zero for those tables and
// should be zero outside of those tables.
- const int n_f_huffs = sizeof(dec.private_impl.f_huffs[0]) /
- sizeof(dec.private_impl.f_huffs[0][0]);
+ const int n_f_huffs = sizeof(dec.private_data.f_huffs[0]) /
+ sizeof(dec.private_data.f_huffs[0][0]);
for (i = 0; i < n_f_huffs; i++) {
- bool got = dec.private_impl.f_huffs[0][i] == 0;
+ bool got = dec.private_data.f_huffs[0][i] == 0;
bool want = i >= (1 << 9) + (1 << 3) + (1 << 3) + (1 << 4);
if (got != want) {
RETURN_FAIL("huffs[0][%d] == 0: got %d, want %d", i, got, want);
@@ -554,19 +582,19 @@
// - 0b111111111 (0x01FF) to the table offset 528 (0x0210), a 4-bit table.
uint32_t got;
uint32_t want;
- got = dec.private_impl.f_huffs[0][0x017F];
+ got = dec.private_data.f_huffs[0][0x017F];
want = 0x10020039;
if (got != want) {
RETURN_FAIL("huffs[0][0x017F]: got 0x%08" PRIX32 ", want 0x%08" PRIX32, got,
want);
}
- got = dec.private_impl.f_huffs[0][0x00FF];
+ got = dec.private_data.f_huffs[0][0x00FF];
want = 0x10020839;
if (got != want) {
RETURN_FAIL("huffs[0][0x00FF]: got 0x%08" PRIX32 ", want 0x%08" PRIX32, got,
want);
}
- got = dec.private_impl.f_huffs[0][0x01FF];
+ got = dec.private_data.f_huffs[0][0x01FF];
want = 0x10021049;
if (got != want) {
RETURN_FAIL("huffs[0][0x01FF]: got 0x%08" PRIX32 ", want 0x%08" PRIX32, got,
@@ -579,7 +607,7 @@
0x80000801, 0x80000A03, 0x80000801, 0x80000C03,
};
for (i = 0; i < 8; i++) {
- got = dec.private_impl.f_huffs[0][0x0200 + i];
+ got = dec.private_data.f_huffs[0][0x0200 + i];
want = wants[i];
if (got != want) {
RETURN_FAIL("huffs[0][0x%04" PRIX32 "]: got 0x%08" PRIX32
@@ -611,6 +639,17 @@
&deflate_deflate_distance_32768_gt, 0, 0);
}
+const char* test_mimic_deflate_decode_deflate_distance_code_31() {
+ CHECK_FOCUS(__func__);
+ const char* got = do_test_io_buffers(
+ mimic_deflate_decode, &deflate_deflate_distance_code_31_gt, 0, 0);
+ const char* want = "inflate failed (data error)";
+ if ((got != want) && ((got == NULL) || (want == NULL) || strcmp(got, want))) {
+ RETURN_FAIL("got \"%s\", want \"%s\"", got, want);
+ }
+ return NULL;
+}
+
const char* test_mimic_deflate_decode_midsummer() {
CHECK_FOCUS(__func__);
return do_test_io_buffers(mimic_deflate_decode, &deflate_midsummer_gt, 0, 0);
@@ -641,28 +680,50 @@
// ---------------- Deflate Benches
-const char* bench_wuffs_deflate_decode_1k() {
+const char* bench_wuffs_deflate_decode_1k_full_init() {
CHECK_FOCUS(__func__);
- return do_bench_io_buffers(wuffs_deflate_decode, tc_dst, &deflate_romeo_gt, 0,
- 0, 2000);
+ return do_bench_io_buffers(wuffs_deflate_decode,
+ WUFFS_INITIALIZE__DEFAULT_OPTIONS, tc_dst,
+ &deflate_romeo_gt, 0, 0, 2000);
}
-const char* bench_wuffs_deflate_decode_10k() {
+const char* bench_wuffs_deflate_decode_1k_part_init() {
CHECK_FOCUS(__func__);
- return do_bench_io_buffers(wuffs_deflate_decode, tc_dst,
+ return do_bench_io_buffers(
+ wuffs_deflate_decode,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED, tc_dst,
+ &deflate_romeo_gt, 0, 0, 2000);
+}
+
+const char* bench_wuffs_deflate_decode_10k_full_init() {
+ CHECK_FOCUS(__func__);
+ return do_bench_io_buffers(wuffs_deflate_decode,
+ WUFFS_INITIALIZE__DEFAULT_OPTIONS, tc_dst,
&deflate_midsummer_gt, 0, 0, 300);
}
+const char* bench_wuffs_deflate_decode_10k_part_init() {
+ CHECK_FOCUS(__func__);
+ return do_bench_io_buffers(
+ wuffs_deflate_decode,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED, tc_dst,
+ &deflate_midsummer_gt, 0, 0, 300);
+}
+
const char* bench_wuffs_deflate_decode_100k_just_one_read() {
CHECK_FOCUS(__func__);
- return do_bench_io_buffers(wuffs_deflate_decode, tc_dst, &deflate_pi_gt, 0, 0,
- 30);
+ return do_bench_io_buffers(
+ wuffs_deflate_decode,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED, tc_dst,
+ &deflate_pi_gt, 0, 0, 30);
}
const char* bench_wuffs_deflate_decode_100k_many_big_reads() {
CHECK_FOCUS(__func__);
- return do_bench_io_buffers(wuffs_deflate_decode, tc_dst, &deflate_pi_gt, 0,
- 4096, 30);
+ return do_bench_io_buffers(
+ wuffs_deflate_decode,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED, tc_dst,
+ &deflate_pi_gt, 0, 4096, 30);
}
// ---------------- Mimic Benches
@@ -671,25 +732,25 @@
const char* bench_mimic_deflate_decode_1k() {
CHECK_FOCUS(__func__);
- return do_bench_io_buffers(mimic_deflate_decode, tc_dst, &deflate_romeo_gt, 0,
- 0, 2000);
+ return do_bench_io_buffers(mimic_deflate_decode, 0, tc_dst, &deflate_romeo_gt,
+ 0, 0, 2000);
}
const char* bench_mimic_deflate_decode_10k() {
CHECK_FOCUS(__func__);
- return do_bench_io_buffers(mimic_deflate_decode, tc_dst,
+ return do_bench_io_buffers(mimic_deflate_decode, 0, tc_dst,
&deflate_midsummer_gt, 0, 0, 300);
}
const char* bench_mimic_deflate_decode_100k_just_one_read() {
CHECK_FOCUS(__func__);
- return do_bench_io_buffers(mimic_deflate_decode, tc_dst, &deflate_pi_gt, 0, 0,
- 30);
+ return do_bench_io_buffers(mimic_deflate_decode, 0, tc_dst, &deflate_pi_gt, 0,
+ 0, 30);
}
const char* bench_mimic_deflate_decode_100k_many_big_reads() {
CHECK_FOCUS(__func__);
- return do_bench_io_buffers(mimic_deflate_decode, tc_dst, &deflate_pi_gt, 0,
+ return do_bench_io_buffers(mimic_deflate_decode, 0, tc_dst, &deflate_pi_gt, 0,
4096, 30);
}
@@ -703,6 +764,7 @@
test_wuffs_deflate_decode_256_bytes, //
test_wuffs_deflate_decode_deflate_backref_crosses_blocks, //
test_wuffs_deflate_decode_deflate_distance_32768, //
+ test_wuffs_deflate_decode_deflate_distance_code_31, //
test_wuffs_deflate_decode_midsummer, //
test_wuffs_deflate_decode_pi_just_one_read, //
test_wuffs_deflate_decode_pi_many_big_reads, //
@@ -720,6 +782,7 @@
test_mimic_deflate_decode_256_bytes, //
test_mimic_deflate_decode_deflate_backref_crosses_blocks, //
test_mimic_deflate_decode_deflate_distance_32768, //
+ test_mimic_deflate_decode_deflate_distance_code_31, //
test_mimic_deflate_decode_midsummer, //
test_mimic_deflate_decode_pi_just_one_read, //
test_mimic_deflate_decode_pi_many_big_reads, //
@@ -734,8 +797,10 @@
// The empty comments forces clang-format to place one element per line.
proc benches[] = {
- bench_wuffs_deflate_decode_1k, //
- bench_wuffs_deflate_decode_10k, //
+ bench_wuffs_deflate_decode_1k_full_init, //
+ bench_wuffs_deflate_decode_1k_part_init, //
+ bench_wuffs_deflate_decode_10k_full_init, //
+ bench_wuffs_deflate_decode_10k_part_init, //
bench_wuffs_deflate_decode_100k_just_one_read, //
bench_wuffs_deflate_decode_100k_many_big_reads, //
diff --git a/test/c/std/gif.c b/test/c/std/gif.c
index 6e04759..6ed3277 100644
--- a/test/c/std/gif.c
+++ b/test/c/std/gif.c
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// ----------------
+
/*
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
@@ -82,9 +84,10 @@
const char* test_basic_bad_sizeof_receiver() {
CHECK_FOCUS(__func__);
- wuffs_gif__decoder dec = ((wuffs_gif__decoder){});
- const char* status =
- wuffs_gif__decoder__check_wuffs_version(&dec, 0, WUFFS_VERSION);
+ wuffs_gif__decoder dec;
+ const char* status = wuffs_gif__decoder__initialize(
+ &dec, 0, WUFFS_VERSION,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status != wuffs_base__error__bad_sizeof_receiver) {
RETURN_FAIL("decode_image_config: got \"%s\", want \"%s\"", status,
wuffs_base__error__bad_sizeof_receiver);
@@ -94,9 +97,10 @@
const char* test_basic_bad_wuffs_version() {
CHECK_FOCUS(__func__);
- wuffs_gif__decoder dec = ((wuffs_gif__decoder){});
- const char* status = wuffs_gif__decoder__check_wuffs_version(
- &dec, sizeof dec, WUFFS_VERSION ^ 0x123456789ABC);
+ wuffs_gif__decoder dec;
+ const char* status = wuffs_gif__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION ^ 0x123456789ABC,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status != wuffs_base__error__bad_wuffs_version) {
RETURN_FAIL("decode_image_config: got \"%s\", want \"%s\"", status,
wuffs_base__error__bad_wuffs_version);
@@ -104,15 +108,15 @@
return NULL;
}
-const char* test_basic_check_wuffs_version_not_called() {
+const char* test_basic_initialize_not_called() {
CHECK_FOCUS(__func__);
wuffs_gif__decoder dec = ((wuffs_gif__decoder){});
wuffs_base__image_config ic = ((wuffs_base__image_config){});
wuffs_base__io_reader src = ((wuffs_base__io_reader){});
const char* status = wuffs_gif__decoder__decode_image_config(&dec, &ic, src);
- if (status != wuffs_base__error__check_wuffs_version_missing) {
+ if (status != wuffs_base__error__initialize_not_called) {
RETURN_FAIL("decode_image_config: got \"%s\", want \"%s\"", status,
- wuffs_base__error__check_wuffs_version_missing);
+ wuffs_base__error__initialize_not_called);
}
return NULL;
}
@@ -137,7 +141,7 @@
const char* test_basic_status_strings() {
CHECK_FOCUS(__func__);
const char* s1 = wuffs_base__error__bad_wuffs_version;
- const char* t1 = "?base: bad wuffs version";
+ const char* t1 = "#base: bad wuffs version";
if (strcmp(s1, t1)) {
RETURN_FAIL("got \"%s\", want \"%s\"", s1, t1);
}
@@ -147,7 +151,7 @@
RETURN_FAIL("got \"%s\", want \"%s\"", s2, t2);
}
const char* s3 = wuffs_gif__error__bad_header;
- const char* t3 = "?gif: bad header";
+ const char* t3 = "#gif: bad header";
if (strcmp(s3, t3)) {
RETURN_FAIL("got \"%s\", want \"%s\"", s3, t3);
}
@@ -159,7 +163,7 @@
// The function call here is from "std/gif" but the argument is from
// "std/lzw". The former package depends on the latter.
const char* s0 = wuffs_lzw__error__bad_code;
- const char* t0 = "?lzw: bad code";
+ const char* t0 = "#lzw: bad code";
if (strcmp(s0, t0)) {
RETURN_FAIL("got \"%s\", want \"%s\"", s0, t0);
}
@@ -168,19 +172,20 @@
const char* test_basic_sub_struct_initializer() {
CHECK_FOCUS(__func__);
- wuffs_gif__decoder dec = ((wuffs_gif__decoder){});
- const char* status =
- wuffs_gif__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION);
+ wuffs_gif__decoder dec;
+ const char* status = wuffs_gif__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
- RETURN_FAIL("check_wuffs_version: \"%s\"", status);
+ RETURN_FAIL("initialize: \"%s\"", status);
}
if (dec.private_impl.magic != WUFFS_BASE__MAGIC) {
RETURN_FAIL("outer magic: got %" PRIu32 ", want %" PRIu32 "",
dec.private_impl.magic, WUFFS_BASE__MAGIC);
}
- if (dec.private_impl.f_lzw.private_impl.magic != WUFFS_BASE__MAGIC) {
+ if (dec.private_data.f_lzw.private_impl.magic != WUFFS_BASE__MAGIC) {
RETURN_FAIL("inner magic: got %" PRIu32 ", want %" PRIu32,
- dec.private_impl.f_lzw.private_impl.magic, WUFFS_BASE__MAGIC);
+ dec.private_data.f_lzw.private_impl.magic, WUFFS_BASE__MAGIC);
}
return NULL;
}
@@ -188,11 +193,12 @@
// ---------------- GIF Tests
const char* wuffs_gif_decode(wuffs_base__io_buffer* dst,
+ uint32_t wuffs_initialize_flags,
wuffs_base__pixel_format pixfmt,
wuffs_base__io_buffer* src) {
- wuffs_gif__decoder dec = ((wuffs_gif__decoder){});
- const char* status =
- wuffs_gif__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION);
+ wuffs_gif__decoder dec;
+ const char* status = wuffs_gif__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION, wuffs_initialize_flags);
if (status) {
return status;
}
@@ -257,11 +263,12 @@
return status;
}
- wuffs_gif__decoder dec = ((wuffs_gif__decoder){});
- status =
- wuffs_gif__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION);
+ wuffs_gif__decoder dec;
+ status = wuffs_gif__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
- RETURN_FAIL("check_wuffs_version: \"%s\"", status);
+ RETURN_FAIL("initialize: \"%s\"", status);
}
wuffs_base__frame_config fc = ((wuffs_base__frame_config){});
@@ -309,8 +316,8 @@
}
}
- if (wuffs_gif__decoder__workbuf_len(&dec).min_incl != 160) {
- RETURN_FAIL("workbuf_len: got %" PRIu64 ", want 160",
+ if (wuffs_gif__decoder__workbuf_len(&dec).min_incl != 1) {
+ RETURN_FAIL("workbuf_len: got %" PRIu64 ", want 1",
wuffs_gif__decoder__workbuf_len(&dec).min_incl);
}
@@ -460,6 +467,48 @@
return NULL;
}
+const char* do_test_wuffs_gif_decode_expecting(wuffs_base__io_buffer src,
+ const char* want_status,
+ bool want_dirty_rect_is_empty) {
+ wuffs_gif__decoder dec;
+ const char* status = wuffs_gif__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
+ if (status) {
+ RETURN_FAIL("initialize: \"%s\"", status);
+ }
+
+ wuffs_base__image_config ic = ((wuffs_base__image_config){});
+ wuffs_base__io_reader src_reader = wuffs_base__io_buffer__reader(&src);
+
+ status = wuffs_gif__decoder__decode_image_config(&dec, &ic, src_reader);
+ if (status) {
+ RETURN_FAIL("decode_image_config: got \"%s\"", status);
+ }
+
+ wuffs_base__pixel_buffer pb = ((wuffs_base__pixel_buffer){});
+ status = wuffs_base__pixel_buffer__set_from_slice(&pb, &ic.pixcfg,
+ global_pixel_slice);
+ if (status) {
+ RETURN_FAIL("set_from_slice: \"%s\"", status);
+ }
+
+ status = wuffs_gif__decoder__decode_frame(&dec, &pb, src_reader,
+ global_work_slice, NULL);
+ if (status != want_status) {
+ RETURN_FAIL("decode_frame: got \"%s\", want \"%s\"", status, want_status);
+ }
+
+ wuffs_base__rect_ie_u32 r = wuffs_gif__decoder__frame_dirty_rect(&dec);
+ bool dirty_rect_is_empty = wuffs_base__rect_ie_u32__is_empty(&r);
+ if (dirty_rect_is_empty != want_dirty_rect_is_empty) {
+ RETURN_FAIL("dirty_rect.is_empty: got %s, want %s",
+ dirty_rect_is_empty ? "true" : "false",
+ want_dirty_rect_is_empty ? "true" : "false");
+ }
+ return NULL;
+}
+
const char* test_wuffs_gif_call_interleaved() {
CHECK_FOCUS(__func__);
@@ -472,11 +521,12 @@
return status;
}
- wuffs_gif__decoder dec = ((wuffs_gif__decoder){});
- status =
- wuffs_gif__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION);
+ wuffs_gif__decoder dec;
+ status = wuffs_gif__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
- RETURN_FAIL("check_wuffs_version: \"%s\"", status);
+ RETURN_FAIL("initialize: \"%s\"", status);
}
{
@@ -519,11 +569,12 @@
return status;
}
- wuffs_gif__decoder dec = ((wuffs_gif__decoder){});
- status =
- wuffs_gif__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION);
+ wuffs_gif__decoder dec;
+ status = wuffs_gif__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
- RETURN_FAIL("check_wuffs_version: \"%s\"", status);
+ RETURN_FAIL("initialize: \"%s\"", status);
}
wuffs_base__io_reader src_reader = wuffs_base__io_buffer__reader(&src);
@@ -555,11 +606,12 @@
return status;
}
- wuffs_gif__decoder dec = ((wuffs_gif__decoder){});
- status =
- wuffs_gif__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION);
+ wuffs_gif__decoder dec;
+ status = wuffs_gif__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
- RETURN_FAIL("check_wuffs_version: \"%s\"", status);
+ RETURN_FAIL("initialize: \"%s\"", status);
}
wuffs_base__image_config ic = ((wuffs_base__image_config){});
@@ -609,6 +661,13 @@
if (status) {
RETURN_FAIL("decode_frame #%" PRIu32 ": got \"%s\"", i, status);
}
+
+ wuffs_base__rect_ie_u32 frame_rect = wuffs_base__frame_config__bounds(&fc);
+ wuffs_base__rect_ie_u32 dirty_rect =
+ wuffs_gif__decoder__frame_dirty_rect(&dec);
+ if (!wuffs_base__rect_ie_u32__contains_rect(&frame_rect, dirty_rect)) {
+ RETURN_FAIL("internal error: frame_rect does not contain dirty_rect");
+ }
}
// There should be no more frames, no matter how many times we call
@@ -672,11 +731,12 @@
return status;
}
- wuffs_gif__decoder dec = ((wuffs_gif__decoder){});
- status =
- wuffs_gif__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION);
+ wuffs_gif__decoder dec;
+ status = wuffs_gif__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
- RETURN_FAIL("check_wuffs_version: \"%s\"", status);
+ RETURN_FAIL("initialize: \"%s\"", status);
}
wuffs_base__image_config ic = ((wuffs_base__image_config){});
wuffs_base__io_reader src_reader = wuffs_base__io_buffer__reader(&src);
@@ -728,8 +788,8 @@
uint32_t i;
for (i = 0; true; i++) {
+ wuffs_base__frame_config fc = ((wuffs_base__frame_config){});
{
- wuffs_base__frame_config fc = ((wuffs_base__frame_config){});
status = wuffs_gif__decoder__decode_frame_config(&dec, &fc, src_reader);
if (i == WUFFS_TESTLIB_ARRAY_SIZE(want_frame_config_bounds)) {
if (status != wuffs_base__warning__end_of_data) {
@@ -769,6 +829,14 @@
RETURN_FAIL("decode_frame #%" PRIu32 ": got \"%s\"", i, status);
}
+ wuffs_base__rect_ie_u32 frame_rect =
+ wuffs_base__frame_config__bounds(&fc);
+ wuffs_base__rect_ie_u32 dirty_rect =
+ wuffs_gif__decoder__frame_dirty_rect(&dec);
+ if (!wuffs_base__rect_ie_u32__contains_rect(&frame_rect, dirty_rect)) {
+ RETURN_FAIL("internal error: frame_rect does not contain dirty_rect");
+ }
+
char got[(width * height) + 1];
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
@@ -844,11 +912,12 @@
return status;
}
- wuffs_gif__decoder dec = ((wuffs_gif__decoder){});
- status =
- wuffs_gif__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION);
+ wuffs_gif__decoder dec;
+ status = wuffs_gif__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
- RETURN_FAIL("check_wuffs_version: \"%s\"", status);
+ RETURN_FAIL("initialize: \"%s\"", status);
}
wuffs_base__image_config ic = ((wuffs_base__image_config){});
wuffs_base__io_reader src_reader = wuffs_base__io_buffer__reader(&src);
@@ -879,41 +948,8 @@
}
src.meta.wi -= 2;
- wuffs_gif__decoder dec = ((wuffs_gif__decoder){});
- status =
- wuffs_gif__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION);
- if (status) {
- RETURN_FAIL("check_wuffs_version: \"%s\"", status);
- }
-
- wuffs_base__image_config ic = ((wuffs_base__image_config){});
- wuffs_base__io_reader src_reader = wuffs_base__io_buffer__reader(&src);
-
- status = wuffs_gif__decoder__decode_image_config(&dec, &ic, src_reader);
- if (status) {
- RETURN_FAIL("decode_image_config: got \"%s\"", status);
- }
-
- wuffs_base__pixel_buffer pb = ((wuffs_base__pixel_buffer){});
- status = wuffs_base__pixel_buffer__set_from_slice(&pb, &ic.pixcfg,
- global_pixel_slice);
- if (status) {
- RETURN_FAIL("set_from_slice: \"%s\"", status);
- }
-
- status = wuffs_gif__decoder__decode_frame(&dec, &pb, src_reader,
- global_work_slice, NULL);
- if (status != wuffs_base__suspension__short_read) {
- RETURN_FAIL("decode_frame: got \"%s\"", status);
- }
-
- // Even we though we haven't seen the 0x00 end-of-block, we should still have
- // some pixel data.
- wuffs_base__rect_ie_u32 r = wuffs_gif__decoder__frame_dirty_rect(&dec);
- if (wuffs_base__rect_ie_u32__is_empty(&r)) {
- RETURN_FAIL("dirty_rect: got empty, want non-empty");
- }
- return NULL;
+ return do_test_wuffs_gif_decode_expecting(
+ src, wuffs_base__suspension__short_read, false);
}
const char* test_wuffs_gif_decode_multiple_loop_counts() {
@@ -927,11 +963,12 @@
return status;
}
- wuffs_gif__decoder dec = ((wuffs_gif__decoder){});
- status =
- wuffs_gif__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION);
+ wuffs_gif__decoder dec;
+ status = wuffs_gif__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
- RETURN_FAIL("check_wuffs_version: \"%s\"", status);
+ RETURN_FAIL("initialize: \"%s\"", status);
}
wuffs_base__image_config ic = ((wuffs_base__image_config){});
wuffs_base__io_reader src_reader = wuffs_base__io_buffer__reader(&src);
@@ -982,6 +1019,57 @@
return NULL;
}
+const char* test_wuffs_gif_decode_pixel_data_none() {
+ CHECK_FOCUS(__func__);
+
+ wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
+ .data = global_src_slice,
+ });
+
+ const char* status =
+ read_file(&src, "test/data/artificial/gif-pixel-data-none.gif");
+ if (status) {
+ return status;
+ }
+
+ return do_test_wuffs_gif_decode_expecting(
+ src, wuffs_base__error__not_enough_data, true);
+}
+
+const char* test_wuffs_gif_decode_pixel_data_not_enough() {
+ CHECK_FOCUS(__func__);
+
+ wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
+ .data = global_src_slice,
+ });
+
+ const char* status =
+ read_file(&src, "test/data/artificial/gif-pixel-data-not-enough.gif");
+ if (status) {
+ return status;
+ }
+
+ return do_test_wuffs_gif_decode_expecting(
+ src, wuffs_base__error__not_enough_data, false);
+}
+
+const char* test_wuffs_gif_decode_pixel_data_too_much() {
+ CHECK_FOCUS(__func__);
+
+ wuffs_base__io_buffer src = ((wuffs_base__io_buffer){
+ .data = global_src_slice,
+ });
+
+ const char* status =
+ read_file(&src, "test/data/artificial/gif-pixel-data-too-much.gif");
+ if (status) {
+ return status;
+ }
+
+ return do_test_wuffs_gif_decode_expecting(
+ src, wuffs_base__error__too_much_data, false);
+}
+
const char* test_wuffs_gif_frame_dirty_rect() {
CHECK_FOCUS(__func__);
@@ -994,11 +1082,12 @@
return status;
}
- wuffs_gif__decoder dec = ((wuffs_gif__decoder){});
- status =
- wuffs_gif__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION);
+ wuffs_gif__decoder dec;
+ status = wuffs_gif__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
- RETURN_FAIL("check_wuffs_version: \"%s\"", status);
+ RETURN_FAIL("initialize: \"%s\"", status);
}
wuffs_base__image_config ic = ((wuffs_base__image_config){});
@@ -1058,11 +1147,12 @@
return status;
}
- wuffs_gif__decoder dec = ((wuffs_gif__decoder){});
- status =
- wuffs_gif__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION);
+ wuffs_gif__decoder dec;
+ status = wuffs_gif__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
- RETURN_FAIL("check_wuffs_version: \"%s\"", status);
+ RETURN_FAIL("initialize: \"%s\"", status);
}
wuffs_base__io_reader src_reader = wuffs_base__io_buffer__reader(&src);
@@ -1139,11 +1229,12 @@
return status;
}
- wuffs_gif__decoder dec = ((wuffs_gif__decoder){});
- status =
- wuffs_gif__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION);
+ wuffs_gif__decoder dec;
+ status = wuffs_gif__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
- RETURN_FAIL("check_wuffs_version: \"%s\"", status);
+ RETURN_FAIL("initialize: \"%s\"", status);
}
wuffs_base__io_reader src_reader = wuffs_base__io_buffer__reader(&src);
@@ -1311,7 +1402,7 @@
.data = global_got_slice,
});
status = wuffs_gif_decode(
- &got, WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY, &src);
+ &got, 0, WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY, &src);
if (status) {
return status;
}
@@ -1321,7 +1412,7 @@
.data = global_want_slice,
});
status = mimic_gif_decode(
- &want, WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY, &src);
+ &want, 0, WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY, &src);
if (status) {
return status;
}
@@ -1408,8 +1499,10 @@
const char* do_bench_gif_decode(
const char* (*decode_func)(wuffs_base__io_buffer*,
+ uint32_t wuffs_initialize_flags,
wuffs_base__pixel_format,
wuffs_base__io_buffer*),
+ uint32_t wuffs_initialize_flags,
const char* filename,
wuffs_base__pixel_format pixfmt,
uint64_t iters_unscaled) {
@@ -1432,7 +1525,7 @@
for (i = 0; i < iters; i++) {
got.meta.wi = 0;
src.meta.ri = 0;
- status = decode_func(&got, pixfmt, &src);
+ status = decode_func(&got, wuffs_initialize_flags, pixfmt, &src);
if (status) {
return status;
}
@@ -1444,63 +1537,88 @@
const char* bench_wuffs_gif_decode_1k_bw() {
CHECK_FOCUS(__func__);
- return do_bench_gif_decode(wuffs_gif_decode, "test/data/pjw-thumbnail.gif",
- WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY,
- 2000);
+ return do_bench_gif_decode(
+ wuffs_gif_decode, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
+ "test/data/pjw-thumbnail.gif",
+ WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY, 2000);
}
-const char* bench_wuffs_gif_decode_1k_color() {
+const char* bench_wuffs_gif_decode_1k_color_full_init() {
CHECK_FOCUS(__func__);
return do_bench_gif_decode(
- wuffs_gif_decode, "test/data/hippopotamus.regular.gif",
+ wuffs_gif_decode, WUFFS_INITIALIZE__DEFAULT_OPTIONS,
+ "test/data/hippopotamus.regular.gif",
+ WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY, 1000);
+}
+
+const char* bench_wuffs_gif_decode_1k_color_part_init() {
+ CHECK_FOCUS(__func__);
+ return do_bench_gif_decode(
+ wuffs_gif_decode, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
+ "test/data/hippopotamus.regular.gif",
WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY, 1000);
}
const char* bench_wuffs_gif_decode_10k_bgra() {
CHECK_FOCUS(__func__);
- return do_bench_gif_decode(wuffs_gif_decode, "test/data/hat.gif",
- WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL, 100);
+ return do_bench_gif_decode(
+ wuffs_gif_decode, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
+ "test/data/hat.gif", WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL, 100);
}
const char* bench_wuffs_gif_decode_10k_indexed() {
CHECK_FOCUS(__func__);
- return do_bench_gif_decode(wuffs_gif_decode, "test/data/hat.gif",
- WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY,
- 100);
+ return do_bench_gif_decode(
+ wuffs_gif_decode, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
+ "test/data/hat.gif", WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY, 100);
}
const char* bench_wuffs_gif_decode_20k() {
CHECK_FOCUS(__func__);
- return do_bench_gif_decode(wuffs_gif_decode, "test/data/bricks-gray.gif",
- WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY,
- 50);
+ return do_bench_gif_decode(
+ wuffs_gif_decode, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
+ "test/data/bricks-gray.gif",
+ WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY, 50);
}
const char* bench_wuffs_gif_decode_100k_artificial() {
CHECK_FOCUS(__func__);
return do_bench_gif_decode(
- wuffs_gif_decode, "test/data/hibiscus.primitive.gif",
+ wuffs_gif_decode, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
+ "test/data/hibiscus.primitive.gif",
WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY, 15);
}
const char* bench_wuffs_gif_decode_100k_realistic() {
CHECK_FOCUS(__func__);
- return do_bench_gif_decode(wuffs_gif_decode, "test/data/hibiscus.regular.gif",
- WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY,
- 10);
+ return do_bench_gif_decode(
+ wuffs_gif_decode, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
+ "test/data/hibiscus.regular.gif",
+ WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY, 10);
}
-const char* bench_wuffs_gif_decode_1000k() {
+const char* bench_wuffs_gif_decode_1000k_full_init() {
CHECK_FOCUS(__func__);
- return do_bench_gif_decode(wuffs_gif_decode, "test/data/harvesters.gif",
+ return do_bench_gif_decode(wuffs_gif_decode,
+ WUFFS_INITIALIZE__DEFAULT_OPTIONS,
+ "test/data/harvesters.gif",
WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY, 1);
}
+const char* bench_wuffs_gif_decode_1000k_part_init() {
+ CHECK_FOCUS(__func__);
+ return do_bench_gif_decode(
+ wuffs_gif_decode, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
+ "test/data/harvesters.gif",
+ WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY, 1);
+}
+
const char* bench_wuffs_gif_decode_anim_screencap() {
CHECK_FOCUS(__func__);
- return do_bench_gif_decode(wuffs_gif_decode,
- "test/data/gifplayer-muybridge.gif",
- WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY, 1);
+ return do_bench_gif_decode(
+ wuffs_gif_decode, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
+ "test/data/gifplayer-muybridge.gif",
+ WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY, 1);
}
// ---------------- Mimic Benches
@@ -1509,7 +1627,7 @@
const char* bench_mimic_gif_decode_1k_bw() {
CHECK_FOCUS(__func__);
- return do_bench_gif_decode(mimic_gif_decode, "test/data/pjw-thumbnail.gif",
+ return do_bench_gif_decode(mimic_gif_decode, 0, "test/data/pjw-thumbnail.gif",
WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY,
2000);
}
@@ -1517,20 +1635,20 @@
const char* bench_mimic_gif_decode_1k_color() {
CHECK_FOCUS(__func__);
return do_bench_gif_decode(
- mimic_gif_decode, "test/data/hippopotamus.regular.gif",
+ mimic_gif_decode, 0, "test/data/hippopotamus.regular.gif",
WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY, 1000);
}
const char* bench_mimic_gif_decode_10k_indexed() {
CHECK_FOCUS(__func__);
- return do_bench_gif_decode(mimic_gif_decode, "test/data/hat.gif",
+ return do_bench_gif_decode(mimic_gif_decode, 0, "test/data/hat.gif",
WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY,
100);
}
const char* bench_mimic_gif_decode_20k() {
CHECK_FOCUS(__func__);
- return do_bench_gif_decode(mimic_gif_decode, "test/data/bricks-gray.gif",
+ return do_bench_gif_decode(mimic_gif_decode, 0, "test/data/bricks-gray.gif",
WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY,
50);
}
@@ -1538,26 +1656,26 @@
const char* bench_mimic_gif_decode_100k_artificial() {
CHECK_FOCUS(__func__);
return do_bench_gif_decode(
- mimic_gif_decode, "test/data/hibiscus.primitive.gif",
+ mimic_gif_decode, 0, "test/data/hibiscus.primitive.gif",
WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY, 15);
}
const char* bench_mimic_gif_decode_100k_realistic() {
CHECK_FOCUS(__func__);
- return do_bench_gif_decode(mimic_gif_decode, "test/data/hibiscus.regular.gif",
- WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY,
- 10);
+ return do_bench_gif_decode(
+ mimic_gif_decode, 0, "test/data/hibiscus.regular.gif",
+ WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY, 10);
}
const char* bench_mimic_gif_decode_1000k() {
CHECK_FOCUS(__func__);
- return do_bench_gif_decode(mimic_gif_decode, "test/data/harvesters.gif",
+ return do_bench_gif_decode(mimic_gif_decode, 0, "test/data/harvesters.gif",
WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY, 1);
}
const char* bench_mimic_gif_decode_anim_screencap() {
CHECK_FOCUS(__func__);
- return do_bench_gif_decode(mimic_gif_decode,
+ return do_bench_gif_decode(mimic_gif_decode, 0,
"test/data/gifplayer-muybridge.gif",
WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY, 1);
}
@@ -1572,14 +1690,14 @@
// These basic tests are really testing the Wuffs compiler. They aren't
// specific to the std/gif code, but putting them here is as good as any
// other place.
- test_basic_bad_receiver, //
- test_basic_bad_sizeof_receiver, //
- test_basic_bad_wuffs_version, //
- test_basic_check_wuffs_version_not_called, //
- test_basic_status_is_error, //
- test_basic_status_strings, //
- test_basic_status_used_package, //
- test_basic_sub_struct_initializer, //
+ test_basic_bad_receiver, //
+ test_basic_bad_sizeof_receiver, //
+ test_basic_bad_wuffs_version, //
+ test_basic_initialize_not_called, //
+ test_basic_status_is_error, //
+ test_basic_status_strings, //
+ test_basic_status_used_package, //
+ test_basic_sub_struct_initializer, //
test_wuffs_gif_call_interleaved, //
test_wuffs_gif_call_sequence, //
@@ -1595,6 +1713,9 @@
test_wuffs_gif_decode_input_is_a_png, //
test_wuffs_gif_decode_missing_two_src_bytes, //
test_wuffs_gif_decode_multiple_loop_counts, //
+ test_wuffs_gif_decode_pixel_data_none, //
+ test_wuffs_gif_decode_pixel_data_not_enough, //
+ test_wuffs_gif_decode_pixel_data_too_much, //
test_wuffs_gif_frame_dirty_rect, //
test_wuffs_gif_num_decoded_frame_configs, //
test_wuffs_gif_num_decoded_frames, //
@@ -1625,15 +1746,17 @@
// The empty comments forces clang-format to place one element per line.
proc benches[] = {
- bench_wuffs_gif_decode_1k_bw, //
- bench_wuffs_gif_decode_1k_color, //
- bench_wuffs_gif_decode_10k_bgra, //
- bench_wuffs_gif_decode_10k_indexed, //
- bench_wuffs_gif_decode_20k, //
- bench_wuffs_gif_decode_100k_artificial, //
- bench_wuffs_gif_decode_100k_realistic, //
- bench_wuffs_gif_decode_1000k, //
- bench_wuffs_gif_decode_anim_screencap, //
+ bench_wuffs_gif_decode_1k_bw, //
+ bench_wuffs_gif_decode_1k_color_full_init, //
+ bench_wuffs_gif_decode_1k_color_part_init, //
+ bench_wuffs_gif_decode_10k_bgra, //
+ bench_wuffs_gif_decode_10k_indexed, //
+ bench_wuffs_gif_decode_20k, //
+ bench_wuffs_gif_decode_100k_artificial, //
+ bench_wuffs_gif_decode_100k_realistic, //
+ bench_wuffs_gif_decode_1000k_full_init, //
+ bench_wuffs_gif_decode_1000k_part_init, //
+ bench_wuffs_gif_decode_anim_screencap, //
#ifdef WUFFS_MIMIC
diff --git a/test/c/std/gzip.c b/test/c/std/gzip.c
index 9dfbca7..830d605 100644
--- a/test/c/std/gzip.c
+++ b/test/c/std/gzip.c
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// ----------------
+
/*
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
@@ -83,11 +85,12 @@
const char* wuffs_gzip_decode(wuffs_base__io_buffer* dst,
wuffs_base__io_buffer* src,
+ uint32_t wuffs_initialize_flags,
uint64_t wlimit,
uint64_t rlimit) {
- wuffs_gzip__decoder dec = ((wuffs_gzip__decoder){});
- const char* status =
- wuffs_gzip__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION);
+ wuffs_gzip__decoder dec;
+ const char* status = wuffs_gzip__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION, wuffs_initialize_flags);
if (status) {
return status;
}
@@ -102,8 +105,8 @@
set_reader_limit(&src_reader, rlimit);
}
- status =
- wuffs_gzip__decoder__decode_io_writer(&dec, dst_writer, src_reader);
+ status = wuffs_gzip__decoder__decode_io_writer(&dec, dst_writer, src_reader,
+ global_work_slice);
if ((wlimit && (status == wuffs_base__suspension__short_write)) ||
(rlimit && (status == wuffs_base__suspension__short_read))) {
@@ -137,11 +140,12 @@
int end_limit;
for (end_limit = 0; end_limit < 10; end_limit++) {
- wuffs_gzip__decoder dec = ((wuffs_gzip__decoder){});
- status = wuffs_gzip__decoder__check_wuffs_version(&dec, sizeof dec,
- WUFFS_VERSION);
+ wuffs_gzip__decoder dec;
+ status = wuffs_gzip__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
- RETURN_FAIL("check_wuffs_version: \"%s\"", status);
+ RETURN_FAIL("initialize: \"%s\"", status);
}
wuffs_gzip__decoder__set_ignore_checksum(&dec, ignore_checksum);
got.meta.wi = 0;
@@ -169,8 +173,8 @@
: NULL;
}
- const char* got_z =
- wuffs_gzip__decoder__decode_io_writer(&dec, got_writer, src_reader);
+ const char* got_z = wuffs_gzip__decoder__decode_io_writer(
+ &dec, got_writer, src_reader, global_work_slice);
if (got_z != want_z) {
RETURN_FAIL("end_limit=%d: got \"%s\", want \"%s\"", end_limit, got_z,
want_z);
@@ -230,13 +234,16 @@
const char* bench_wuffs_gzip_decode_10k() {
CHECK_FOCUS(__func__);
- return do_bench_io_buffers(wuffs_gzip_decode, tc_dst, &gzip_midsummer_gt, 0,
- 0, 300);
+ return do_bench_io_buffers(
+ wuffs_gzip_decode, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
+ tc_dst, &gzip_midsummer_gt, 0, 0, 300);
}
const char* bench_wuffs_gzip_decode_100k() {
CHECK_FOCUS(__func__);
- return do_bench_io_buffers(wuffs_gzip_decode, tc_dst, &gzip_pi_gt, 0, 0, 30);
+ return do_bench_io_buffers(
+ wuffs_gzip_decode, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
+ tc_dst, &gzip_pi_gt, 0, 0, 30);
}
// ---------------- Mimic Benches
@@ -245,13 +252,14 @@
const char* bench_mimic_gzip_decode_10k() {
CHECK_FOCUS(__func__);
- return do_bench_io_buffers(mimic_gzip_decode, tc_dst, &gzip_midsummer_gt, 0,
- 0, 300);
+ return do_bench_io_buffers(mimic_gzip_decode, 0, tc_dst, &gzip_midsummer_gt,
+ 0, 0, 300);
}
const char* bench_mimic_gzip_decode_100k() {
CHECK_FOCUS(__func__);
- return do_bench_io_buffers(mimic_gzip_decode, tc_dst, &gzip_pi_gt, 0, 0, 30);
+ return do_bench_io_buffers(mimic_gzip_decode, 0, tc_dst, &gzip_pi_gt, 0, 0,
+ 30);
}
#endif // WUFFS_MIMIC
diff --git a/test/c/std/lzw.c b/test/c/std/lzw.c
index 9d18ffd..6b800a7 100644
--- a/test/c/std/lzw.c
+++ b/test/c/std/lzw.c
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// ----------------
+
/*
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
@@ -105,11 +107,12 @@
(int)(want_size));
}
- wuffs_lzw__decoder dec = ((wuffs_lzw__decoder){});
- status =
- wuffs_lzw__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION);
+ wuffs_lzw__decoder dec;
+ status = wuffs_lzw__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
- RETURN_FAIL("check_wuffs_version: \"%s\"", status);
+ RETURN_FAIL("initialize: \"%s\"", status);
}
wuffs_lzw__decoder__set_literal_width(&dec, literal_width);
int num_iters = 0;
@@ -126,7 +129,8 @@
size_t old_wi = got.meta.wi;
size_t old_ri = src.meta.ri;
- status = wuffs_lzw__decoder__decode_io_writer(&dec, got_writer, src_reader);
+ status = wuffs_lzw__decoder__decode_io_writer(&dec, got_writer, src_reader,
+ global_work_slice);
if (!status) {
if (src.meta.ri != src.meta.wi) {
RETURN_FAIL("decode returned \"ok\" but src was not exhausted");
@@ -221,17 +225,18 @@
src.data.ptr[2] = 0x43;
src.data.ptr[3] = 0xFF;
- wuffs_lzw__decoder dec = ((wuffs_lzw__decoder){});
- const char* status =
- wuffs_lzw__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION);
+ wuffs_lzw__decoder dec;
+ const char* status = wuffs_lzw__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
- RETURN_FAIL("check_wuffs_version: \"%s\"", status);
+ RETURN_FAIL("initialize: \"%s\"", status);
}
wuffs_lzw__decoder__set_literal_width(&dec, 7);
status = wuffs_lzw__decoder__decode_io_writer(
&dec, wuffs_base__io_buffer__writer(&got),
- wuffs_base__io_buffer__reader(&src));
+ wuffs_base__io_buffer__reader(&src), global_work_slice);
if (status != wuffs_lzw__error__bad_code) {
RETURN_FAIL("decode: \"%s\"", status);
}
@@ -265,17 +270,18 @@
src.data.ptr[0] = 0x01;
src.data.ptr[1] = 0x01;
- wuffs_lzw__decoder dec = ((wuffs_lzw__decoder){});
- const char* status =
- wuffs_lzw__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION);
+ wuffs_lzw__decoder dec;
+ const char* status = wuffs_lzw__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
- RETURN_FAIL("check_wuffs_version: \"%s\"", status);
+ RETURN_FAIL("initialize: \"%s\"", status);
}
wuffs_lzw__decoder__set_literal_width(&dec, 8);
status = wuffs_lzw__decoder__decode_io_writer(
&dec, wuffs_base__io_buffer__writer(&got),
- wuffs_base__io_buffer__reader(&src));
+ wuffs_base__io_buffer__reader(&src), global_work_slice);
if (status) {
RETURN_FAIL("decode: \"%s\"", status);
}
@@ -322,13 +328,15 @@
for (i = 0; i < iters; i++) {
got.meta.wi = 0;
src.meta.ri = 1; // Skip the literal width.
- wuffs_lzw__decoder dec = ((wuffs_lzw__decoder){});
- status = wuffs_lzw__decoder__check_wuffs_version(&dec, sizeof dec,
- WUFFS_VERSION);
+ wuffs_lzw__decoder dec;
+ status = wuffs_lzw__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
- RETURN_FAIL("check_wuffs_version: \"%s\"", status);
+ RETURN_FAIL("initialize: \"%s\"", status);
}
- status = wuffs_lzw__decoder__decode_io_writer(&dec, got_writer, src_reader);
+ status = wuffs_lzw__decoder__decode_io_writer(&dec, got_writer, src_reader,
+ global_work_slice);
if (status) {
RETURN_FAIL("decode: \"%s\"", status);
}
diff --git a/test/c/std/zlib.c b/test/c/std/zlib.c
index 252a4fe..726d4a4 100644
--- a/test/c/std/zlib.c
+++ b/test/c/std/zlib.c
@@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// ----------------
+
/*
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
@@ -83,11 +85,12 @@
const char* wuffs_zlib_decode(wuffs_base__io_buffer* dst,
wuffs_base__io_buffer* src,
+ uint32_t wuffs_initialize_flags,
uint64_t wlimit,
uint64_t rlimit) {
- wuffs_zlib__decoder dec = ((wuffs_zlib__decoder){});
- const char* status =
- wuffs_zlib__decoder__check_wuffs_version(&dec, sizeof dec, WUFFS_VERSION);
+ wuffs_zlib__decoder dec;
+ const char* status = wuffs_zlib__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION, wuffs_initialize_flags);
if (status) {
return status;
}
@@ -102,8 +105,8 @@
set_reader_limit(&src_reader, rlimit);
}
- status =
- wuffs_zlib__decoder__decode_io_writer(&dec, dst_writer, src_reader);
+ status = wuffs_zlib__decoder__decode_io_writer(&dec, dst_writer, src_reader,
+ global_work_slice);
if ((wlimit && (status == wuffs_base__suspension__short_write)) ||
(rlimit && (status == wuffs_base__suspension__short_read))) {
@@ -136,11 +139,12 @@
int end_limit;
for (end_limit = 0; end_limit < 10; end_limit++) {
- wuffs_zlib__decoder dec = ((wuffs_zlib__decoder){});
- status = wuffs_zlib__decoder__check_wuffs_version(&dec, sizeof dec,
- WUFFS_VERSION);
+ wuffs_zlib__decoder dec;
+ status = wuffs_zlib__decoder__initialize(
+ &dec, sizeof dec, WUFFS_VERSION,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED);
if (status) {
- RETURN_FAIL("check_wuffs_version: \"%s\"", status);
+ RETURN_FAIL("initialize: \"%s\"", status);
}
wuffs_zlib__decoder__set_ignore_checksum(&dec, ignore_checksum);
got.meta.wi = 0;
@@ -168,8 +172,8 @@
: NULL;
}
- const char* got_z =
- wuffs_zlib__decoder__decode_io_writer(&dec, got_writer, src_reader);
+ const char* got_z = wuffs_zlib__decoder__decode_io_writer(
+ &dec, got_writer, src_reader, global_work_slice);
if (got_z != want_z) {
RETURN_FAIL("end_limit=%d: got \"%s\", want \"%s\"", end_limit, got_z,
want_z);
@@ -229,13 +233,16 @@
const char* bench_wuffs_zlib_decode_10k() {
CHECK_FOCUS(__func__);
- return do_bench_io_buffers(wuffs_zlib_decode, tc_dst, &zlib_midsummer_gt, 0,
- 0, 300);
+ return do_bench_io_buffers(
+ wuffs_zlib_decode, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
+ tc_dst, &zlib_midsummer_gt, 0, 0, 300);
}
const char* bench_wuffs_zlib_decode_100k() {
CHECK_FOCUS(__func__);
- return do_bench_io_buffers(wuffs_zlib_decode, tc_dst, &zlib_pi_gt, 0, 0, 30);
+ return do_bench_io_buffers(
+ wuffs_zlib_decode, WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
+ tc_dst, &zlib_pi_gt, 0, 0, 30);
}
// ---------------- Mimic Benches
@@ -244,13 +251,14 @@
const char* bench_mimic_zlib_decode_10k() {
CHECK_FOCUS(__func__);
- return do_bench_io_buffers(mimic_zlib_decode, tc_dst, &zlib_midsummer_gt, 0,
- 0, 300);
+ return do_bench_io_buffers(mimic_zlib_decode, 0, tc_dst, &zlib_midsummer_gt,
+ 0, 0, 300);
}
const char* bench_mimic_zlib_decode_100k() {
CHECK_FOCUS(__func__);
- return do_bench_io_buffers(mimic_zlib_decode, tc_dst, &zlib_pi_gt, 0, 0, 30);
+ return do_bench_io_buffers(mimic_zlib_decode, 0, tc_dst, &zlib_pi_gt, 0, 0,
+ 30);
}
#endif // WUFFS_MIMIC
diff --git a/test/c/testlib/testlib.c b/test/c/testlib/testlib.c
index 3bfc79e..a6b17d3 100644
--- a/test/c/testlib/testlib.c
+++ b/test/c/testlib/testlib.c
@@ -586,8 +586,10 @@
const char* proc_io_buffers(const char* (*codec_func)(wuffs_base__io_buffer*,
wuffs_base__io_buffer*,
+ uint32_t,
uint64_t,
uint64_t),
+ uint32_t wuffs_initialize_flags,
throughput_counter tc,
golden_test* gt,
uint64_t wlimit,
@@ -638,7 +640,8 @@
for (i = 0; i < iters; i++) {
got.meta.wi = 0;
src.meta.ri = gt->src_offset0;
- const char* status = codec_func(&got, &src, wlimit, rlimit);
+ const char* status =
+ codec_func(&got, &src, wuffs_initialize_flags, wlimit, rlimit);
if (status) {
return status;
}
@@ -672,25 +675,30 @@
const char* do_bench_io_buffers(
const char* (*codec_func)(wuffs_base__io_buffer*,
wuffs_base__io_buffer*,
+ uint32_t,
uint64_t,
uint64_t),
+ uint32_t wuffs_initialize_flags,
throughput_counter tc,
golden_test* gt,
uint64_t wlimit,
uint64_t rlimit,
uint64_t iters_unscaled) {
- return proc_io_buffers(codec_func, tc, gt, wlimit, rlimit,
- iters_unscaled * iterscale, true);
+ return proc_io_buffers(codec_func, wuffs_initialize_flags, tc, gt, wlimit,
+ rlimit, iters_unscaled * iterscale, true);
}
const char* do_test_io_buffers(const char* (*codec_func)(wuffs_base__io_buffer*,
wuffs_base__io_buffer*,
+ uint32_t,
uint64_t,
uint64_t),
golden_test* gt,
uint64_t wlimit,
uint64_t rlimit) {
- return proc_io_buffers(codec_func, tc_neither, gt, wlimit, rlimit, 1, false);
+ return proc_io_buffers(codec_func,
+ WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED,
+ tc_neither, gt, wlimit, rlimit, 1, false);
}
#endif // WUFFS_INCLUDE_GUARD
diff --git a/test/data/README.md b/test/data/README.md
index 3487b64..b188b3f 100644
--- a/test/data/README.md
+++ b/test/data/README.md
@@ -28,6 +28,9 @@
bricks-\* are various encodings of an original photo by Nigel Tao
<nigeltao@golang.org>.
+crude-flag.\* is an original animation by Nigel Tao
+<nigeltao@golang.org>. See the `lib/nie` documentation.
+
gifplayer-muybridge.gif is an original animation by Nigel Tao
<nigeltao@golang.org>.
diff --git a/test/data/artificial/0.bytes b/test/data/artificial/0.bytes
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/data/artificial/0.bytes
diff --git a/test/data/artificial/deflate-backref-crosses-blocks.deflate.commentary.txt b/test/data/artificial/deflate-backref-crosses-blocks.deflate.commentary.txt
index 677d463..9aa9ca6 100644
--- a/test/data/artificial/deflate-backref-crosses-blocks.deflate.commentary.txt
+++ b/test/data/artificial/deflate-backref-crosses-blocks.deflate.commentary.txt
@@ -19,9 +19,7 @@
000009 0x0009 . 0x03 0b_...._.011 Fixed Huffman block, final
000009 0x0009 . 0x03 0b_0000_0... lcode: 257 length: 3
000010 0x000A B 0x42 0b_...._..10
-
000010 0x000A B 0x42 0b_.100_00.. dcode: 1 distance: 2
-
000010 0x000A B 0x42 0b_0..._.... lcode: 256 end of block
000011 0x000B . 0x00 0b_..00_0000
diff --git a/test/data/artificial/deflate-distance-code-31.deflate b/test/data/artificial/deflate-distance-code-31.deflate
new file mode 100644
index 0000000..1eea2ba
--- /dev/null
+++ b/test/data/artificial/deflate-distance-code-31.deflate
@@ -0,0 +1 @@
+~
\ No newline at end of file
diff --git a/test/data/artificial/deflate-distance-code-31.deflate.commentary.txt b/test/data/artificial/deflate-distance-code-31.deflate.commentary.txt
new file mode 100644
index 0000000..f8cf33e
--- /dev/null
+++ b/test/data/artificial/deflate-distance-code-31.deflate.commentary.txt
@@ -0,0 +1,8 @@
+Running deflate-distance-code-31.deflate through script/print-bits.go and
+adding commentary:
+
+ offset xoffset ASCII hex binary
+ 000000 0x0000 . 0x03 0b_...._.011 Fixed Huffman block, final
+ 000000 0x0000 . 0x03 0b_0000_0... lcode: 257 length: 3
+ 000001 0x0001 ~ 0x7E 0b_...._..10
+ 000001 0x0001 ~ 0x7E 0b_.111_11.. dcode: 31 INVALID
diff --git a/test/data/artificial/deflate-distance-code-31.deflate.make-artificial.txt b/test/data/artificial/deflate-distance-code-31.deflate.make-artificial.txt
new file mode 100644
index 0000000..d04c69f
--- /dev/null
+++ b/test/data/artificial/deflate-distance-code-31.deflate.make-artificial.txt
@@ -0,0 +1,19 @@
+# Feed this file to script/make-artificial.go
+
+make deflate
+
+# RFC 1951 section 3.2.6 says that for fixed Huffman codes, "distance codes
+# 30-31 will never actually occur in the compressed data", and likewise for
+# literal/length values 286-287.
+#
+# This dates from a more innocent time, before widespread concerns about
+# malicious actors deliberately supplying invalid input to probe for security
+# vulnerabilities. Upon encountering such input, a robust decoder shouldn't
+# enter an internally inconsistent state.
+#
+# In terms of the Wuffs implementation (and error message convention), we
+# should return an error, as it is indeed invalid input, but we shouldn't
+# return an "internal error".
+blockFixedHuffman (final) {
+ len 3 distCode 31
+}
diff --git a/test/data/artificial/gif-pixel-data-none.gif b/test/data/artificial/gif-pixel-data-none.gif
new file mode 100644
index 0000000..0227f9d
--- /dev/null
+++ b/test/data/artificial/gif-pixel-data-none.gif
Binary files differ
diff --git a/test/data/artificial/gif-pixel-data-none.gif.make-artificial.txt b/test/data/artificial/gif-pixel-data-none.gif.make-artificial.txt
new file mode 100644
index 0000000..9dc0eef
--- /dev/null
+++ b/test/data/artificial/gif-pixel-data-none.gif.make-artificial.txt
@@ -0,0 +1,23 @@
+# Feed this file to script/make-artificial.go
+
+make gif
+
+header
+
+image {
+ imageWidthHeight 2 2
+ palette {
+ 0x00 0x00 0xFF
+ 0x11 0x00 0xFF
+ 0x22 0x00 0xFF
+ 0x33 0x00 0xFF
+ }
+}
+
+frame {
+ frameLeftTopWidthHeight 0 0 2 2
+}
+# The frame is 4 pixels, but we don't supply any.
+lzw 2
+
+trailer
diff --git a/test/data/artificial/gif-pixel-data-not-enough.gif b/test/data/artificial/gif-pixel-data-not-enough.gif
new file mode 100644
index 0000000..016857f
--- /dev/null
+++ b/test/data/artificial/gif-pixel-data-not-enough.gif
Binary files differ
diff --git a/test/data/artificial/gif-pixel-data-not-enough.gif.make-artificial.txt b/test/data/artificial/gif-pixel-data-not-enough.gif.make-artificial.txt
new file mode 100644
index 0000000..adc7dde
--- /dev/null
+++ b/test/data/artificial/gif-pixel-data-not-enough.gif.make-artificial.txt
@@ -0,0 +1,23 @@
+# Feed this file to script/make-artificial.go
+
+make gif
+
+header
+
+image {
+ imageWidthHeight 2 2
+ palette {
+ 0x00 0x00 0xFF
+ 0x11 0x00 0xFF
+ 0x22 0x00 0xFF
+ 0x33 0x00 0xFF
+ }
+}
+
+frame {
+ frameLeftTopWidthHeight 0 0 2 2
+}
+# The frame is 4 pixels, but we only supply 1.
+lzw 2 0x00
+
+trailer
diff --git a/test/data/artificial/gif-pixel-data-too-much.gif b/test/data/artificial/gif-pixel-data-too-much.gif
new file mode 100644
index 0000000..573ec88
--- /dev/null
+++ b/test/data/artificial/gif-pixel-data-too-much.gif
Binary files differ
diff --git a/test/data/artificial/gif-pixel-data-too-much.gif.make-artificial.txt b/test/data/artificial/gif-pixel-data-too-much.gif.make-artificial.txt
new file mode 100644
index 0000000..5f02c1b
--- /dev/null
+++ b/test/data/artificial/gif-pixel-data-too-much.gif.make-artificial.txt
@@ -0,0 +1,23 @@
+# Feed this file to script/make-artificial.go
+
+make gif
+
+header
+
+image {
+ imageWidthHeight 2 2
+ palette {
+ 0x00 0x00 0xFF
+ 0x11 0x00 0xFF
+ 0x22 0x00 0xFF
+ 0x33 0x00 0xFF
+ }
+}
+
+frame {
+ frameLeftTopWidthHeight 0 0 2 2
+}
+# The frame is 4 pixels, but we supply 5.
+lzw 2 0x00 0x00 0x00 0x00 0x00
+
+trailer
diff --git a/test/data/crude-flag.nia b/test/data/crude-flag.nia
new file mode 100644
index 0000000..64d2f7d
--- /dev/null
+++ b/test/data/crude-flag.nia
Binary files differ
diff --git a/test/data/crude-flag.nie b/test/data/crude-flag.nie
new file mode 100644
index 0000000..d216d22
--- /dev/null
+++ b/test/data/crude-flag.nie
Binary files differ
diff --git a/test/data/crude-flag.nii b/test/data/crude-flag.nii
new file mode 100644
index 0000000..301ff46
--- /dev/null
+++ b/test/data/crude-flag.nii
Binary files differ