diff --git a/cmd/wuffs-c/internal/cgen/base/base-impl.c b/cmd/wuffs-c/internal/cgen/base/all-impl.c similarity index 90% rename from cmd/wuffs-c/internal/cgen/base/base-impl.c rename to cmd/wuffs-c/internal/cgen/base/all-impl.c index 97459a70..20dd253e 100644 --- a/cmd/wuffs-c/internal/cgen/base/base-impl.c +++ b/cmd/wuffs-c/internal/cgen/base/all-impl.c @@ -1,6 +1,6 @@ // After editing this file, run "go generate" in the parent directory. -// Copyright 2018 The Wuffs Authors. +// 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. @@ -24,12 +24,34 @@ // !! WUFFS MONOLITHIC RELEASE DISCARDS EVERYTHING ABOVE. -// !! INSERT base-public.h. +// !! INSERT base/copyright + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// !! INSERT base/all-public.h. + +#ifdef __cplusplus +} // extern "C" +#endif // WUFFS C HEADER ENDS HERE. #ifdef WUFFS_IMPLEMENTATION -// !! INSERT base-private.h. +#ifdef __cplusplus +extern "C" { +#endif + +// !! INSERT base/all-private.h. + +#ifdef __cplusplus +} // extern "C" +#endif #if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__BASE) diff --git a/cmd/wuffs-c/internal/cgen/base/base-private.h b/cmd/wuffs-c/internal/cgen/base/core-private.h similarity index 53% rename from cmd/wuffs-c/internal/cgen/base/base-private.h rename to cmd/wuffs-c/internal/cgen/base/core-private.h index 561d0650..585984bb 100644 --- a/cmd/wuffs-c/internal/cgen/base/base-private.h +++ b/cmd/wuffs-c/internal/cgen/base/core-private.h @@ -14,10 +14,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#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( @@ -428,336 +424,3 @@ wuffs_base__table_u8__row(wuffs_base__table_u8 t, uint32_t y) { } return ((wuffs_base__slice_u8){}); } - -// ---------------- 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; -} - -// ---------------- 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, - }); -} - -// ---------------- I/O - -static inline bool // -wuffs_base__io_buffer__is_valid(wuffs_base__io_buffer buf) { - return (buf.data.ptr || (buf.data.len == 0)) && - (buf.data.len >= buf.meta.wi) && (buf.meta.wi >= buf.meta.ri); -} - -// TODO: wuffs_base__io_reader__is_eof is no longer used by Wuffs per se, but -// it might be handy to programs that use Wuffs. Either delete it, or promote -// it to the public API. -// -// If making this function public (i.e. moving it to base-header.h), it also -// needs to allow NULL (i.e. implicit, callee-calculated) mark/limit. - -static inline bool // -wuffs_base__io_reader__is_eof(wuffs_base__io_reader o) { - wuffs_base__io_buffer* buf = o.private_impl.buf; - return buf && buf->meta.closed && - (buf->data.ptr + buf->meta.wi == o.private_impl.limit); -} - -static inline bool // -wuffs_base__io_reader__is_valid(wuffs_base__io_reader o) { - wuffs_base__io_buffer* buf = o.private_impl.buf; - // Note: if making this function public (i.e. moving it to base-header.h), it - // also needs to allow NULL (i.e. implicit, callee-calculated) mark/limit. - return buf ? ((buf->data.ptr <= o.private_impl.mark) && - (o.private_impl.mark <= o.private_impl.limit) && - (o.private_impl.limit <= buf->data.ptr + buf->data.len)) - : ((o.private_impl.mark == NULL) && - (o.private_impl.limit == NULL)); -} - -static inline bool // -wuffs_base__io_writer__is_valid(wuffs_base__io_writer o) { - wuffs_base__io_buffer* buf = o.private_impl.buf; - // Note: if making this function public (i.e. moving it to base-header.h), it - // also needs to allow NULL (i.e. implicit, callee-calculated) mark/limit. - return buf ? ((buf->data.ptr <= o.private_impl.mark) && - (o.private_impl.mark <= o.private_impl.limit) && - (o.private_impl.limit <= buf->data.ptr + buf->data.len)) - : ((o.private_impl.mark == NULL) && - (o.private_impl.limit == NULL)); -} - -static inline uint32_t // -wuffs_base__io_writer__copy_n_from_history(uint8_t** ptr_ptr, - uint8_t* start, - uint8_t* end, - uint32_t length, - uint32_t distance) { - if (!distance) { - return 0; - } - uint8_t* ptr = *ptr_ptr; - if ((size_t)(ptr - start) < (size_t)(distance)) { - return 0; - } - start = ptr - distance; - size_t n = end - ptr; - if ((size_t)(length) > n) { - length = n; - } else { - n = 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 - // function implementation shouldn't overfit to that one format. Perhaps the - // copy_n_from_history Wuffs method should also take an unroll hint argument, - // and the cgen can look if that argument is the constant expression '3'. - // - // See also wuffs_base__io_writer__copy_n_from_history_fast below. - // - // Alternatively, or additionally, have a sloppy_copy_n_from_history method - // that copies 8 bytes at a time, possibly writing more than length bytes? - for (; n >= 3; n -= 3) { - *ptr++ = *start++; - *ptr++ = *start++; - *ptr++ = *start++; - } - for (; n; n--) { - *ptr++ = *start++; - } - *ptr_ptr = ptr; - return length; -} - -// wuffs_base__io_writer__copy_n_from_history_fast is like the -// wuffs_base__io_writer__copy_n_from_history function above, but has stronger -// pre-conditions. The caller needs to prove that: -// - distance > 0 -// - distance <= (*ptr_ptr - start) -// - length <= (end - *ptr_ptr) -static inline uint32_t // -wuffs_base__io_writer__copy_n_from_history_fast(uint8_t** ptr_ptr, - uint8_t* start, - uint8_t* end, - uint32_t length, - uint32_t distance) { - uint8_t* ptr = *ptr_ptr; - start = ptr - distance; - uint32_t n = length; - for (; n >= 3; n -= 3) { - *ptr++ = *start++; - *ptr++ = *start++; - *ptr++ = *start++; - } - for (; n; n--) { - *ptr++ = *start++; - } - *ptr_ptr = ptr; - return length; -} - -static inline uint32_t // -wuffs_base__io_writer__copy_n_from_reader(uint8_t** ptr_ioptr_w, - uint8_t* iobounds1_w, - uint32_t length, - uint8_t** ptr_ioptr_r, - uint8_t* iobounds1_r) { - uint8_t* ioptr_w = *ptr_ioptr_w; - size_t n = length; - if (n > ((size_t)(iobounds1_w - ioptr_w))) { - n = iobounds1_w - ioptr_w; - } - uint8_t* ioptr_r = *ptr_ioptr_r; - if (n > ((size_t)(iobounds1_r - ioptr_r))) { - n = iobounds1_r - ioptr_r; - } - if (n > 0) { - memmove(ioptr_w, ioptr_r, n); - *ptr_ioptr_w += n; - *ptr_ioptr_r += n; - } - return n; -} - -static inline uint64_t // -wuffs_base__io_writer__copy_from_slice(uint8_t** ptr_ioptr_w, - uint8_t* iobounds1_w, - wuffs_base__slice_u8 src) { - uint8_t* ioptr_w = *ptr_ioptr_w; - size_t n = src.len; - if (n > ((size_t)(iobounds1_w - ioptr_w))) { - n = iobounds1_w - ioptr_w; - } - if (n > 0) { - memmove(ioptr_w, src.ptr, n); - *ptr_ioptr_w += n; - } - return n; -} - -static inline uint32_t // -wuffs_base__io_writer__copy_n_from_slice(uint8_t** ptr_ioptr_w, - uint8_t* iobounds1_w, - uint32_t length, - wuffs_base__slice_u8 src) { - uint8_t* ioptr_w = *ptr_ioptr_w; - size_t n = src.len; - if (n > length) { - n = length; - } - if (n > ((size_t)(iobounds1_w - ioptr_w))) { - n = iobounds1_w - ioptr_w; - } - if (n > 0) { - memmove(ioptr_w, src.ptr, n); - *ptr_ioptr_w += n; - } - return n; -} - -static inline wuffs_base__empty_struct // -wuffs_base__io_reader__set_limit(wuffs_base__io_reader* o, - uint8_t* ioptr_r, - uint64_t limit) { - if (o && (((size_t)(o->private_impl.limit - ioptr_r)) > limit)) { - o->private_impl.limit = ioptr_r + limit; - } - return ((wuffs_base__empty_struct){}); -} - -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){}); -} - -static inline wuffs_base__empty_struct // -wuffs_base__io_writer__set(wuffs_base__io_writer* o, - wuffs_base__io_buffer* b, - uint8_t** ioptr1_ptr, - uint8_t** ioptr2_ptr, - wuffs_base__slice_u8 s) { - b->data.ptr = s.ptr; - b->data.len = s.len; - b->meta.wi = 0; - b->meta.ri = 0; - b->meta.pos = 0; - b->meta.closed = false; - - o->private_impl.buf = b; - o->private_impl.mark = s.ptr; - o->private_impl.limit = s.ptr + s.len; - *ioptr1_ptr = s.ptr; - *ioptr2_ptr = s.ptr + s.len; - return ((wuffs_base__empty_struct){}); -} - -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){}); -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/cmd/wuffs-c/internal/cgen/base/core-public.h b/cmd/wuffs-c/internal/cgen/base/core-public.h new file mode 100644 index 00000000..72aa23af --- /dev/null +++ b/cmd/wuffs-c/internal/cgen/base/core-public.h @@ -0,0 +1,335 @@ +// 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. + +// Wuffs assumes that: +// - converting a uint32_t to a size_t will never overflow. +// - converting a size_t to a uint64_t will never overflow. +#ifdef __WORDSIZE +#if (__WORDSIZE != 32) && (__WORDSIZE != 64) +#error "Wuffs requires a word size of either 32 or 64 bits" +#endif +#endif + +// WUFFS_VERSION is the major.minor.patch version, as per https://semver.org/, +// as a uint64_t. The major number is the high 32 bits. The minor number is the +// middle 16 bits. The patch number is the low 16 bits. The version extension +// (such as "", "beta" or "rc.1") is part of the string representation (such as +// "1.2.3-beta") but not the uint64_t representation. +// +// All three of major, minor and patch being zero means that this is a +// work-in-progress version, not a release version, and has no backwards or +// forwards compatibility guarantees. +// +// !! Some code generation programs can override WUFFS_VERSION. +#define WUFFS_VERSION ((uint64_t)0) +#define WUFFS_VERSION_MAJOR ((uint64_t)0) +#define WUFFS_VERSION_MINOR ((uint64_t)0) +#define WUFFS_VERSION_PATCH ((uint64_t)0) +#define WUFFS_VERSION_EXTENSION "" +#define WUFFS_VERSION_STRING "0.0.0" + +// Define WUFFS_CONFIG__STATIC_FUNCTIONS to make all of Wuffs' functions have +// static storage. The motivation is discussed in the "ALLOW STATIC +// IMPLEMENTATION" section of +// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt +#ifdef WUFFS_CONFIG__STATIC_FUNCTIONS +#define WUFFS_BASE__MAYBE_STATIC static +#else +#define WUFFS_BASE__MAYBE_STATIC +#endif + +// Clang also defines "__GNUC__". +#if defined(__GNUC__) +#define WUFFS_BASE__WARN_UNUSED_RESULT __attribute__((warn_unused_result)) +#else +#define WUFFS_BASE__WARN_UNUSED_RESULT +#endif + +// 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()". +typedef struct { + // private_impl is a placeholder field. It isn't explicitly used, except that + // without it, the sizeof a struct with no fields can differ across C/C++ + // compilers, and it is undefined behavior in C99. For example, gcc says that + // the sizeof an empty struct is 0, and g++ says that it is 1. This leads to + // ABI incompatibility if a Wuffs .c file is processed by one compiler and + // its .h file with another compiler. + // + // Instead, we explicitly insert an otherwise unused field, so that the + // sizeof this struct is always 1. + uint8_t private_impl; +} wuffs_base__empty_struct; + +// wuffs_base__utility is a placeholder receiver type. It enables what Java +// calls static methods, as opposed to regular methods. +typedef struct { + // private_impl is a placeholder field. It isn't explicitly used, except that + // without it, the sizeof a struct with no fields can differ across C/C++ + // compilers, and it is undefined behavior in C99. For example, gcc says that + // the sizeof an empty struct is 0, and g++ says that it is 1. This leads to + // ABI incompatibility if a Wuffs .c file is processed by one compiler and + // its .h file with another compiler. + // + // Instead, we explicitly insert an otherwise unused field, so that the + // sizeof this struct is always 1. + uint8_t private_impl; +} wuffs_base__utility; + +// -------- + +// A status is either NULL (meaning OK) or a string message. That message is +// human-readable, for programmers, but it is not for end users. It is not +// localized, and does not contain additional contextual information such as a +// source filename. +// +// Status strings are statically allocated and should never be free'd. They can +// be compared by the == operator and not just by strcmp. +// +// Statuses come in four categories: +// - OK: the request was completed, successfully. +// - Warnings: the request was completed, unsuccessfully. +// - Suspensions: the request was not completed, but can be re-tried. +// - Errors: the request was not completed, permanently. +// +// When a function returns an incomplete status, a suspension means that that +// function should be called again within a new context, such as after flushing +// or re-filling an I/O buffer. An error means that an irrecoverable failure +// state was reached. +typedef const char* wuffs_base__status; + +// !! INSERT wuffs_base__status names. + +static inline bool // +wuffs_base__status__is_complete(wuffs_base__status z) { + return (z == NULL) || ((*z != '$') && (*z != '?')); +} + +static inline bool // +wuffs_base__status__is_error(wuffs_base__status z) { + return z && (*z == '?'); +} + +static inline bool // +wuffs_base__status__is_ok(wuffs_base__status z) { + return z == NULL; +} + +static inline bool // +wuffs_base__status__is_suspension(wuffs_base__status z) { + return z && (*z == '$'); +} + +static inline bool // +wuffs_base__status__is_warning(wuffs_base__status z) { + return z && (*z != '$') && (*z != '?'); +} + +// -------- + +// Flicks are a unit of time. One flick (frame-tick) is 1 / 705_600_000 of a +// second. See https://github.com/OculusVR/Flicks +typedef int64_t wuffs_base__flicks; + +#define WUFFS_BASE__FLICKS_PER_SECOND ((uint64_t)705600000) +#define WUFFS_BASE__FLICKS_PER_MILLISECOND ((uint64_t)705600) + +// ---------------- Numeric Types + +static inline uint8_t // +wuffs_base__u8__min(uint8_t x, uint8_t y) { + return x < y ? x : y; +} + +static inline uint8_t // +wuffs_base__u8__max(uint8_t x, uint8_t y) { + return x > y ? x : y; +} + +static inline uint16_t // +wuffs_base__u16__min(uint16_t x, uint16_t y) { + return x < y ? x : y; +} + +static inline uint16_t // +wuffs_base__u16__max(uint16_t x, uint16_t y) { + return x > y ? x : y; +} + +static inline uint32_t // +wuffs_base__u32__min(uint32_t x, uint32_t y) { + return x < y ? x : y; +} + +static inline uint32_t // +wuffs_base__u32__max(uint32_t x, uint32_t y) { + return x > y ? x : y; +} + +static inline uint64_t // +wuffs_base__u64__min(uint64_t x, uint64_t y) { + return x < y ? x : y; +} + +static inline uint64_t // +wuffs_base__u64__max(uint64_t x, uint64_t y) { + return x > y ? x : y; +} + +// -------- + +// Saturating arithmetic (sat_add, sat_sub) branchless bit-twiddling algorithms +// are per https://locklessinc.com/articles/sat_arithmetic/ +// +// It is important that the underlying types are unsigned integers, as signed +// integer arithmetic overflow is undefined behavior in C. + +static inline uint8_t // +wuffs_base__u8__sat_add(uint8_t x, uint8_t y) { + uint8_t res = x + y; + res |= -(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); + 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); + 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); + 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); + 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); + 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); + 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); + return res; +} + +// ---------------- Slices and Tables + +// WUFFS_BASE__SLICE is a 1-dimensional buffer. +// +// len measures a number of elements, not necessarily a size in bytes. +// +// A value with all fields NULL or zero is a valid, empty slice. +#define WUFFS_BASE__SLICE(T) \ + struct { \ + T* ptr; \ + size_t len; \ + } + +// WUFFS_BASE__TABLE is a 2-dimensional buffer. +// +// width height, and stride measure a number of elements, not necessarily a +// size in bytes. +// +// A value with all fields NULL or zero is a valid, empty table. +#define WUFFS_BASE__TABLE(T) \ + struct { \ + T* ptr; \ + size_t width; \ + size_t height; \ + size_t stride; \ + } + +typedef WUFFS_BASE__SLICE(uint8_t) wuffs_base__slice_u8; +typedef WUFFS_BASE__SLICE(uint16_t) wuffs_base__slice_u16; +typedef WUFFS_BASE__SLICE(uint32_t) wuffs_base__slice_u32; +typedef WUFFS_BASE__SLICE(uint64_t) wuffs_base__slice_u64; + +typedef WUFFS_BASE__TABLE(uint8_t) wuffs_base__table_u8; +typedef WUFFS_BASE__TABLE(uint16_t) wuffs_base__table_u16; +typedef WUFFS_BASE__TABLE(uint32_t) wuffs_base__table_u32; +typedef WUFFS_BASE__TABLE(uint64_t) wuffs_base__table_u64; + +// 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__slice_u8){}); +} + +// wuffs_base__slice_u8__subslice_j returns s[:j]. +// +// It returns an empty slice if j is out of bounds. +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__slice_u8){}); +} + +// wuffs_base__slice_u8__subslice_ij returns s[i:j]. +// +// It returns an empty slice if i or j is out of bounds. +static inline wuffs_base__slice_u8 // +wuffs_base__slice_u8__subslice_ij(wuffs_base__slice_u8 s, + uint64_t i, + uint64_t j) { + if ((i <= j) && (j <= SIZE_MAX) && (j <= s.len)) { + return ((wuffs_base__slice_u8){ + .ptr = s.ptr + i, + .len = j - i, + }); + } + return ((wuffs_base__slice_u8){}); +} diff --git a/cmd/wuffs-c/internal/cgen/base/image-private.h b/cmd/wuffs-c/internal/cgen/base/image-private.h new file mode 100644 index 00000000..2da99eb6 --- /dev/null +++ b/cmd/wuffs-c/internal/cgen/base/image-private.h @@ -0,0 +1,17 @@ +// 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. + +// ---------------- Images diff --git a/cmd/wuffs-c/internal/cgen/base/image-public.h b/cmd/wuffs-c/internal/cgen/base/image-public.h index 75c5cb8e..fed0191c 100644 --- a/cmd/wuffs-c/internal/cgen/base/image-public.h +++ b/cmd/wuffs-c/internal/cgen/base/image-public.h @@ -14,10 +14,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifdef __cplusplus -extern "C" { -#endif - // ---------------- Images // wuffs_base__color_u32_argb_premul is an 8 bit per channel premultiplied @@ -904,7 +900,3 @@ typedef struct { #ifdef __cplusplus #endif // __cplusplus - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/cmd/wuffs-c/internal/cgen/base/io-private.h b/cmd/wuffs-c/internal/cgen/base/io-private.h new file mode 100644 index 00000000..46173d6b --- /dev/null +++ b/cmd/wuffs-c/internal/cgen/base/io-private.h @@ -0,0 +1,232 @@ +// 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. + +// ---------------- I/O + +static inline bool // +wuffs_base__io_buffer__is_valid(wuffs_base__io_buffer buf) { + return (buf.data.ptr || (buf.data.len == 0)) && + (buf.data.len >= buf.meta.wi) && (buf.meta.wi >= buf.meta.ri); +} + +// TODO: wuffs_base__io_reader__is_eof is no longer used by Wuffs per se, but +// it might be handy to programs that use Wuffs. Either delete it, or promote +// it to the public API. +// +// If making this function public (i.e. moving it to base-header.h), it also +// needs to allow NULL (i.e. implicit, callee-calculated) mark/limit. + +static inline bool // +wuffs_base__io_reader__is_eof(wuffs_base__io_reader o) { + wuffs_base__io_buffer* buf = o.private_impl.buf; + return buf && buf->meta.closed && + (buf->data.ptr + buf->meta.wi == o.private_impl.limit); +} + +static inline bool // +wuffs_base__io_reader__is_valid(wuffs_base__io_reader o) { + wuffs_base__io_buffer* buf = o.private_impl.buf; + // Note: if making this function public (i.e. moving it to base-header.h), it + // also needs to allow NULL (i.e. implicit, callee-calculated) mark/limit. + return buf ? ((buf->data.ptr <= o.private_impl.mark) && + (o.private_impl.mark <= o.private_impl.limit) && + (o.private_impl.limit <= buf->data.ptr + buf->data.len)) + : ((o.private_impl.mark == NULL) && + (o.private_impl.limit == NULL)); +} + +static inline bool // +wuffs_base__io_writer__is_valid(wuffs_base__io_writer o) { + wuffs_base__io_buffer* buf = o.private_impl.buf; + // Note: if making this function public (i.e. moving it to base-header.h), it + // also needs to allow NULL (i.e. implicit, callee-calculated) mark/limit. + return buf ? ((buf->data.ptr <= o.private_impl.mark) && + (o.private_impl.mark <= o.private_impl.limit) && + (o.private_impl.limit <= buf->data.ptr + buf->data.len)) + : ((o.private_impl.mark == NULL) && + (o.private_impl.limit == NULL)); +} + +static inline uint32_t // +wuffs_base__io_writer__copy_n_from_history(uint8_t** ptr_ptr, + uint8_t* start, + uint8_t* end, + uint32_t length, + uint32_t distance) { + if (!distance) { + return 0; + } + uint8_t* ptr = *ptr_ptr; + if ((size_t)(ptr - start) < (size_t)(distance)) { + return 0; + } + start = ptr - distance; + size_t n = end - ptr; + if ((size_t)(length) > n) { + length = n; + } else { + n = 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 + // function implementation shouldn't overfit to that one format. Perhaps the + // copy_n_from_history Wuffs method should also take an unroll hint argument, + // and the cgen can look if that argument is the constant expression '3'. + // + // See also wuffs_base__io_writer__copy_n_from_history_fast below. + // + // Alternatively, or additionally, have a sloppy_copy_n_from_history method + // that copies 8 bytes at a time, possibly writing more than length bytes? + for (; n >= 3; n -= 3) { + *ptr++ = *start++; + *ptr++ = *start++; + *ptr++ = *start++; + } + for (; n; n--) { + *ptr++ = *start++; + } + *ptr_ptr = ptr; + return length; +} + +// wuffs_base__io_writer__copy_n_from_history_fast is like the +// wuffs_base__io_writer__copy_n_from_history function above, but has stronger +// pre-conditions. The caller needs to prove that: +// - distance > 0 +// - distance <= (*ptr_ptr - start) +// - length <= (end - *ptr_ptr) +static inline uint32_t // +wuffs_base__io_writer__copy_n_from_history_fast(uint8_t** ptr_ptr, + uint8_t* start, + uint8_t* end, + uint32_t length, + uint32_t distance) { + uint8_t* ptr = *ptr_ptr; + start = ptr - distance; + uint32_t n = length; + for (; n >= 3; n -= 3) { + *ptr++ = *start++; + *ptr++ = *start++; + *ptr++ = *start++; + } + for (; n; n--) { + *ptr++ = *start++; + } + *ptr_ptr = ptr; + return length; +} + +static inline uint32_t // +wuffs_base__io_writer__copy_n_from_reader(uint8_t** ptr_ioptr_w, + uint8_t* iobounds1_w, + uint32_t length, + uint8_t** ptr_ioptr_r, + uint8_t* iobounds1_r) { + uint8_t* ioptr_w = *ptr_ioptr_w; + size_t n = length; + if (n > ((size_t)(iobounds1_w - ioptr_w))) { + n = iobounds1_w - ioptr_w; + } + uint8_t* ioptr_r = *ptr_ioptr_r; + if (n > ((size_t)(iobounds1_r - ioptr_r))) { + n = iobounds1_r - ioptr_r; + } + if (n > 0) { + memmove(ioptr_w, ioptr_r, n); + *ptr_ioptr_w += n; + *ptr_ioptr_r += n; + } + return n; +} + +static inline uint64_t // +wuffs_base__io_writer__copy_from_slice(uint8_t** ptr_ioptr_w, + uint8_t* iobounds1_w, + wuffs_base__slice_u8 src) { + uint8_t* ioptr_w = *ptr_ioptr_w; + size_t n = src.len; + if (n > ((size_t)(iobounds1_w - ioptr_w))) { + n = iobounds1_w - ioptr_w; + } + if (n > 0) { + memmove(ioptr_w, src.ptr, n); + *ptr_ioptr_w += n; + } + return n; +} + +static inline uint32_t // +wuffs_base__io_writer__copy_n_from_slice(uint8_t** ptr_ioptr_w, + uint8_t* iobounds1_w, + uint32_t length, + wuffs_base__slice_u8 src) { + uint8_t* ioptr_w = *ptr_ioptr_w; + size_t n = src.len; + if (n > length) { + n = length; + } + if (n > ((size_t)(iobounds1_w - ioptr_w))) { + n = iobounds1_w - ioptr_w; + } + if (n > 0) { + memmove(ioptr_w, src.ptr, n); + *ptr_ioptr_w += n; + } + return n; +} + +static inline wuffs_base__empty_struct // +wuffs_base__io_reader__set_limit(wuffs_base__io_reader* o, + uint8_t* ioptr_r, + uint64_t limit) { + if (o && (((size_t)(o->private_impl.limit - ioptr_r)) > limit)) { + o->private_impl.limit = ioptr_r + limit; + } + return ((wuffs_base__empty_struct){}); +} + +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){}); +} + +static inline wuffs_base__empty_struct // +wuffs_base__io_writer__set(wuffs_base__io_writer* o, + wuffs_base__io_buffer* b, + uint8_t** ioptr1_ptr, + uint8_t** ioptr2_ptr, + wuffs_base__slice_u8 s) { + b->data.ptr = s.ptr; + b->data.len = s.len; + b->meta.wi = 0; + b->meta.ri = 0; + b->meta.pos = 0; + b->meta.closed = false; + + o->private_impl.buf = b; + o->private_impl.mark = s.ptr; + o->private_impl.limit = s.ptr + s.len; + *ioptr1_ptr = s.ptr; + *ioptr2_ptr = s.ptr + s.len; + return ((wuffs_base__empty_struct){}); +} + +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){}); +} diff --git a/cmd/wuffs-c/internal/cgen/base/io-public.h b/cmd/wuffs-c/internal/cgen/base/io-public.h new file mode 100644 index 00000000..a87a7c09 --- /dev/null +++ b/cmd/wuffs-c/internal/cgen/base/io-public.h @@ -0,0 +1,141 @@ +// 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. + +// ---------------- I/O + +struct wuffs_base__io_buffer__struct; + +typedef struct { + // Do not access the private_impl's fields directly. There is no API/ABI + // compatibility or safety guarantee if you do so. + struct { + struct wuffs_base__io_buffer__struct* buf; + // The bounds values are typically NULL, when created by the Wuffs public + // API. NULL means that the callee substitutes the implicit bounds derived + // from buf. + uint8_t* mark; + uint8_t* limit; + } private_impl; +} wuffs_base__io_reader; + +typedef struct { + // Do not access the private_impl's fields directly. There is no API/ABI + // compatibility or safety guarantee if you do so. + struct { + struct wuffs_base__io_buffer__struct* buf; + // The bounds values are typically NULL, when created by the Wuffs public + // API. NULL means that the callee substitutes the implicit bounds derived + // from buf. + uint8_t* mark; + uint8_t* limit; + } private_impl; +} wuffs_base__io_writer; + +// wuffs_base__io_buffer_meta is the metadata for a wuffs_base__io_buffer's +// data. +typedef struct { + size_t wi; // Write index. Invariant: wi <= len. + size_t ri; // Read index. Invariant: ri <= wi. + uint64_t pos; // Position of the buffer start relative to the stream start. + bool closed; // No further writes are expected. +} wuffs_base__io_buffer_meta; + +// wuffs_base__io_buffer is a 1-dimensional buffer (a pointer and length) plus +// additional metadata. +// +// A value with all fields zero is a valid, empty buffer. +typedef struct wuffs_base__io_buffer__struct { + wuffs_base__slice_u8 data; + wuffs_base__io_buffer_meta meta; + +#ifdef __cplusplus + inline void compact(); + inline wuffs_base__io_reader reader(); + inline wuffs_base__io_writer writer(); + inline uint64_t reader_io_position(); + inline uint64_t writer_io_position(); +#endif // __cplusplus + +} wuffs_base__io_buffer; + +// wuffs_base__io_buffer__compact moves any written but unread bytes to the +// start of the buffer. +static inline void // +wuffs_base__io_buffer__compact(wuffs_base__io_buffer* buf) { + if (!buf || (buf->meta.ri == 0)) { + return; + } + buf->meta.pos = wuffs_base__u64__sat_add(buf->meta.pos, buf->meta.ri); + size_t n = buf->meta.wi - buf->meta.ri; + if (n != 0) { + memmove(buf->data.ptr, buf->data.ptr + buf->meta.ri, n); + } + buf->meta.wi = n; + buf->meta.ri = 0; +} + +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){}); + ret.private_impl.buf = buf; + 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){}); + ret.private_impl.buf = buf; + return ret; +} + +static inline uint64_t // +wuffs_base__io_buffer__reader_io_position(wuffs_base__io_buffer* buf) { + return buf ? wuffs_base__u64__sat_add(buf->meta.pos, buf->meta.ri) : 0; +} + +static inline uint64_t // +wuffs_base__io_buffer__writer_io_position(wuffs_base__io_buffer* buf) { + return buf ? wuffs_base__u64__sat_add(buf->meta.pos, buf->meta.wi) : 0; +} + +#ifdef __cplusplus + +inline void // +wuffs_base__io_buffer__struct::compact() { + wuffs_base__io_buffer__compact(this); +} + +inline wuffs_base__io_reader // +wuffs_base__io_buffer__struct::reader() { + return wuffs_base__io_buffer__reader(this); +} + +inline wuffs_base__io_writer // +wuffs_base__io_buffer__struct::writer() { + return wuffs_base__io_buffer__writer(this); +} + +inline uint64_t // +wuffs_base__io_buffer__struct::reader_io_position() { + return wuffs_base__io_buffer__reader_io_position(this); +} + +inline uint64_t // +wuffs_base__io_buffer__struct::writer_io_position() { + return wuffs_base__io_buffer__writer_io_position(this); +} + +#endif // __cplusplus diff --git a/cmd/wuffs-c/internal/cgen/base/memory-private.h b/cmd/wuffs-c/internal/cgen/base/memory-private.h new file mode 100644 index 00000000..ceeb6758 --- /dev/null +++ b/cmd/wuffs-c/internal/cgen/base/memory-private.h @@ -0,0 +1,17 @@ +// 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. + +// ---------------- Memory Allocation diff --git a/cmd/wuffs-c/internal/cgen/base/memory-public.h b/cmd/wuffs-c/internal/cgen/base/memory-public.h new file mode 100644 index 00000000..fbf0e058 --- /dev/null +++ b/cmd/wuffs-c/internal/cgen/base/memory-public.h @@ -0,0 +1,86 @@ +// 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. + +// ---------------- Memory Allocation + +// The memory allocation related functions in this section aren't used by Wuffs +// per se, but they may be helpful to the code that uses Wuffs. + +// wuffs_base__malloc_slice_uxx wraps calling a malloc-like function, except +// that it takes a uint64_t number of elements instead of a size_t size in +// bytes, and it returns a slice (a pointer and a length) instead of just a +// pointer. +// +// You can pass the C stdlib's malloc as the malloc_func. +// +// It returns an empty slice (containing a NULL ptr field) if (num_uxx * +// sizeof(uintxx_t)) would overflow SIZE_MAX. + +static inline wuffs_base__slice_u8 // +wuffs_base__malloc_slice_u8(void* (*malloc_func)(size_t), uint64_t num_u8) { + 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__slice_u8){}); +} + +static inline wuffs_base__slice_u16 // +wuffs_base__malloc_slice_u16(void* (*malloc_func)(size_t), uint64_t num_u16) { + 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__slice_u16){}); +} + +static inline wuffs_base__slice_u32 // +wuffs_base__malloc_slice_u32(void* (*malloc_func)(size_t), uint64_t num_u32) { + 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__slice_u32){}); +} + +static inline wuffs_base__slice_u64 // +wuffs_base__malloc_slice_u64(void* (*malloc_func)(size_t), uint64_t num_u64) { + 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__slice_u64){}); +} diff --git a/cmd/wuffs-c/internal/cgen/base/range-private.h b/cmd/wuffs-c/internal/cgen/base/range-private.h new file mode 100644 index 00000000..be89f521 --- /dev/null +++ b/cmd/wuffs-c/internal/cgen/base/range-private.h @@ -0,0 +1,127 @@ +// 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; +} + +// ---------------- 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/base/base-public.h b/cmd/wuffs-c/internal/cgen/base/range-public.h similarity index 57% rename from cmd/wuffs-c/internal/cgen/base/base-public.h rename to cmd/wuffs-c/internal/cgen/base/range-public.h index 6f242b86..2071d9cb 100644 --- a/cmd/wuffs-c/internal/cgen/base/base-public.h +++ b/cmd/wuffs-c/internal/cgen/base/range-public.h @@ -14,334 +14,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -// Wuffs assumes that: -// - converting a uint32_t to a size_t will never overflow. -// - converting a size_t to a uint64_t will never overflow. -#ifdef __WORDSIZE -#if (__WORDSIZE != 32) && (__WORDSIZE != 64) -#error "Wuffs requires a word size of either 32 or 64 bits" -#endif -#endif - -// WUFFS_VERSION is the major.minor.patch version, as per https://semver.org/, -// as a uint64_t. The major number is the high 32 bits. The minor number is the -// middle 16 bits. The patch number is the low 16 bits. The version extension -// (such as "", "beta" or "rc.1") is part of the string representation (such as -// "1.2.3-beta") but not the uint64_t representation. -// -// All three of major, minor and patch being zero means that this is a -// work-in-progress version, not a release version, and has no backwards or -// forwards compatibility guarantees. -// -// !! Some code generation programs can override WUFFS_VERSION. -#define WUFFS_VERSION ((uint64_t)0) -#define WUFFS_VERSION_MAJOR ((uint64_t)0) -#define WUFFS_VERSION_MINOR ((uint64_t)0) -#define WUFFS_VERSION_PATCH ((uint64_t)0) -#define WUFFS_VERSION_EXTENSION "" -#define WUFFS_VERSION_STRING "0.0.0" - -// Define WUFFS_CONFIG__STATIC_FUNCTIONS to make all of Wuffs' functions have -// static storage. The motivation is discussed in the "ALLOW STATIC -// IMPLEMENTATION" section of -// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt -#ifdef WUFFS_CONFIG__STATIC_FUNCTIONS -#define WUFFS_BASE__MAYBE_STATIC static -#else -#define WUFFS_BASE__MAYBE_STATIC -#endif - -// Clang also defines "__GNUC__". -#if defined(__GNUC__) -#define WUFFS_BASE__WARN_UNUSED_RESULT __attribute__((warn_unused_result)) -#else -#define WUFFS_BASE__WARN_UNUSED_RESULT -#endif - -// 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()". -typedef struct { - // private_impl is a placeholder field. It isn't explicitly used, except that - // without it, the sizeof a struct with no fields can differ across C/C++ - // compilers, and it is undefined behavior in C99. For example, gcc says that - // the sizeof an empty struct is 0, and g++ says that it is 1. This leads to - // ABI incompatibility if a Wuffs .c file is processed by one compiler and - // its .h file with another compiler. - // - // Instead, we explicitly insert an otherwise unused field, so that the - // sizeof this struct is always 1. - uint8_t private_impl; -} wuffs_base__empty_struct; - -// wuffs_base__utility is a placeholder receiver type. It enables what Java -// calls static methods, as opposed to regular methods. -typedef struct { - // private_impl is a placeholder field. It isn't explicitly used, except that - // without it, the sizeof a struct with no fields can differ across C/C++ - // compilers, and it is undefined behavior in C99. For example, gcc says that - // the sizeof an empty struct is 0, and g++ says that it is 1. This leads to - // ABI incompatibility if a Wuffs .c file is processed by one compiler and - // its .h file with another compiler. - // - // Instead, we explicitly insert an otherwise unused field, so that the - // sizeof this struct is always 1. - uint8_t private_impl; -} wuffs_base__utility; - -// -------- - -// A status is either NULL (meaning OK) or a string message. That message is -// human-readable, for programmers, but it is not for end users. It is not -// localized, and does not contain additional contextual information such as a -// source filename. -// -// Status strings are statically allocated and should never be free'd. They can -// be compared by the == operator and not just by strcmp. -// -// Statuses come in four categories: -// - OK: the request was completed, successfully. -// - Warnings: the request was completed, unsuccessfully. -// - Suspensions: the request was not completed, but can be re-tried. -// - Errors: the request was not completed, permanently. -// -// When a function returns an incomplete status, a suspension means that that -// function should be called again within a new context, such as after flushing -// or re-filling an I/O buffer. An error means that an irrecoverable failure -// state was reached. -typedef const char* wuffs_base__status; - -// !! INSERT wuffs_base__status names. - -static inline bool // -wuffs_base__status__is_complete(wuffs_base__status z) { - return (z == NULL) || ((*z != '$') && (*z != '?')); -} - -static inline bool // -wuffs_base__status__is_error(wuffs_base__status z) { - return z && (*z == '?'); -} - -static inline bool // -wuffs_base__status__is_ok(wuffs_base__status z) { - return z == NULL; -} - -static inline bool // -wuffs_base__status__is_suspension(wuffs_base__status z) { - return z && (*z == '$'); -} - -static inline bool // -wuffs_base__status__is_warning(wuffs_base__status z) { - return z && (*z != '$') && (*z != '?'); -} - -// -------- - -// Flicks are a unit of time. One flick (frame-tick) is 1 / 705_600_000 of a -// second. See https://github.com/OculusVR/Flicks -typedef int64_t wuffs_base__flicks; - -#define WUFFS_BASE__FLICKS_PER_SECOND ((uint64_t)705600000) -#define WUFFS_BASE__FLICKS_PER_MILLISECOND ((uint64_t)705600) - -// ---------------- Numeric Types - -static inline uint8_t // -wuffs_base__u8__min(uint8_t x, uint8_t y) { - return x < y ? x : y; -} - -static inline uint8_t // -wuffs_base__u8__max(uint8_t x, uint8_t y) { - return x > y ? x : y; -} - -static inline uint16_t // -wuffs_base__u16__min(uint16_t x, uint16_t y) { - return x < y ? x : y; -} - -static inline uint16_t // -wuffs_base__u16__max(uint16_t x, uint16_t y) { - return x > y ? x : y; -} - -static inline uint32_t // -wuffs_base__u32__min(uint32_t x, uint32_t y) { - return x < y ? x : y; -} - -static inline uint32_t // -wuffs_base__u32__max(uint32_t x, uint32_t y) { - return x > y ? x : y; -} - -static inline uint64_t // -wuffs_base__u64__min(uint64_t x, uint64_t y) { - return x < y ? x : y; -} - -static inline uint64_t // -wuffs_base__u64__max(uint64_t x, uint64_t y) { - return x > y ? x : y; -} - -// -------- - -// Saturating arithmetic (sat_add, sat_sub) branchless bit-twiddling algorithms -// are per https://locklessinc.com/articles/sat_arithmetic/ -// -// It is important that the underlying types are unsigned integers, as signed -// integer arithmetic overflow is undefined behavior in C. - -static inline uint8_t // -wuffs_base__u8__sat_add(uint8_t x, uint8_t y) { - uint8_t res = x + y; - res |= -(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); - 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); - 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); - 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); - 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); - 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); - 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); - return res; -} - -// ---------------- Slices and Tables - -// WUFFS_BASE__SLICE is a 1-dimensional buffer. -// -// len measures a number of elements, not necessarily a size in bytes. -// -// A value with all fields NULL or zero is a valid, empty slice. -#define WUFFS_BASE__SLICE(T) \ - struct { \ - T* ptr; \ - size_t len; \ - } - -// WUFFS_BASE__TABLE is a 2-dimensional buffer. -// -// width height, and stride measure a number of elements, not necessarily a -// size in bytes. -// -// A value with all fields NULL or zero is a valid, empty table. -#define WUFFS_BASE__TABLE(T) \ - struct { \ - T* ptr; \ - size_t width; \ - size_t height; \ - size_t stride; \ - } - -typedef WUFFS_BASE__SLICE(uint8_t) wuffs_base__slice_u8; -typedef WUFFS_BASE__SLICE(uint16_t) wuffs_base__slice_u16; -typedef WUFFS_BASE__SLICE(uint32_t) wuffs_base__slice_u32; -typedef WUFFS_BASE__SLICE(uint64_t) wuffs_base__slice_u64; - -typedef WUFFS_BASE__TABLE(uint8_t) wuffs_base__table_u8; -typedef WUFFS_BASE__TABLE(uint16_t) wuffs_base__table_u16; -typedef WUFFS_BASE__TABLE(uint32_t) wuffs_base__table_u32; -typedef WUFFS_BASE__TABLE(uint64_t) wuffs_base__table_u64; - -// 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__slice_u8){}); -} - -// wuffs_base__slice_u8__subslice_j returns s[:j]. -// -// It returns an empty slice if j is out of bounds. -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__slice_u8){}); -} - -// wuffs_base__slice_u8__subslice_ij returns s[i:j]. -// -// It returns an empty slice if i or j is out of bounds. -static inline wuffs_base__slice_u8 // -wuffs_base__slice_u8__subslice_ij(wuffs_base__slice_u8 s, - uint64_t i, - uint64_t j) { - if ((i <= j) && (j <= SIZE_MAX) && (j <= s.len)) { - return ((wuffs_base__slice_u8){ - .ptr = s.ptr + i, - .len = j - i, - }); - } - return ((wuffs_base__slice_u8){}); -} - // ---------------- Ranges and Rects // Ranges are either inclusive ("range_ii") or exclusive ("range_ie") on the @@ -991,204 +663,3 @@ wuffs_base__rect_ie_u32::height() { } #endif // __cplusplus - -// ---------------- I/O - -struct wuffs_base__io_buffer__struct; - -typedef struct { - // Do not access the private_impl's fields directly. There is no API/ABI - // compatibility or safety guarantee if you do so. - struct { - struct wuffs_base__io_buffer__struct* buf; - // The bounds values are typically NULL, when created by the Wuffs public - // API. NULL means that the callee substitutes the implicit bounds derived - // from buf. - uint8_t* mark; - uint8_t* limit; - } private_impl; -} wuffs_base__io_reader; - -typedef struct { - // Do not access the private_impl's fields directly. There is no API/ABI - // compatibility or safety guarantee if you do so. - struct { - struct wuffs_base__io_buffer__struct* buf; - // The bounds values are typically NULL, when created by the Wuffs public - // API. NULL means that the callee substitutes the implicit bounds derived - // from buf. - uint8_t* mark; - uint8_t* limit; - } private_impl; -} wuffs_base__io_writer; - -// wuffs_base__io_buffer_meta is the metadata for a wuffs_base__io_buffer's -// data. -typedef struct { - size_t wi; // Write index. Invariant: wi <= len. - size_t ri; // Read index. Invariant: ri <= wi. - uint64_t pos; // Position of the buffer start relative to the stream start. - bool closed; // No further writes are expected. -} wuffs_base__io_buffer_meta; - -// wuffs_base__io_buffer is a 1-dimensional buffer (a pointer and length) plus -// additional metadata. -// -// A value with all fields zero is a valid, empty buffer. -typedef struct wuffs_base__io_buffer__struct { - wuffs_base__slice_u8 data; - wuffs_base__io_buffer_meta meta; - -#ifdef __cplusplus - inline void compact(); - inline wuffs_base__io_reader reader(); - inline wuffs_base__io_writer writer(); - inline uint64_t reader_io_position(); - inline uint64_t writer_io_position(); -#endif // __cplusplus - -} wuffs_base__io_buffer; - -// wuffs_base__io_buffer__compact moves any written but unread bytes to the -// start of the buffer. -static inline void // -wuffs_base__io_buffer__compact(wuffs_base__io_buffer* buf) { - if (!buf || (buf->meta.ri == 0)) { - return; - } - buf->meta.pos = wuffs_base__u64__sat_add(buf->meta.pos, buf->meta.ri); - size_t n = buf->meta.wi - buf->meta.ri; - if (n != 0) { - memmove(buf->data.ptr, buf->data.ptr + buf->meta.ri, n); - } - buf->meta.wi = n; - buf->meta.ri = 0; -} - -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){}); - ret.private_impl.buf = buf; - 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){}); - ret.private_impl.buf = buf; - return ret; -} - -static inline uint64_t // -wuffs_base__io_buffer__reader_io_position(wuffs_base__io_buffer* buf) { - return buf ? wuffs_base__u64__sat_add(buf->meta.pos, buf->meta.ri) : 0; -} - -static inline uint64_t // -wuffs_base__io_buffer__writer_io_position(wuffs_base__io_buffer* buf) { - return buf ? wuffs_base__u64__sat_add(buf->meta.pos, buf->meta.wi) : 0; -} - -#ifdef __cplusplus - -inline void // -wuffs_base__io_buffer__struct::compact() { - wuffs_base__io_buffer__compact(this); -} - -inline wuffs_base__io_reader // -wuffs_base__io_buffer__struct::reader() { - return wuffs_base__io_buffer__reader(this); -} - -inline wuffs_base__io_writer // -wuffs_base__io_buffer__struct::writer() { - return wuffs_base__io_buffer__writer(this); -} - -inline uint64_t // -wuffs_base__io_buffer__struct::reader_io_position() { - return wuffs_base__io_buffer__reader_io_position(this); -} - -inline uint64_t // -wuffs_base__io_buffer__struct::writer_io_position() { - return wuffs_base__io_buffer__writer_io_position(this); -} - -#endif // __cplusplus - -// ---------------- Memory Allocation - -// The memory allocation related functions in this section aren't used by Wuffs -// per se, but they may be helpful to the code that uses Wuffs. - -// wuffs_base__malloc_slice_uxx wraps calling a malloc-like function, except -// that it takes a uint64_t number of elements instead of a size_t size in -// bytes, and it returns a slice (a pointer and a length) instead of just a -// pointer. -// -// You can pass the C stdlib's malloc as the malloc_func. -// -// It returns an empty slice (containing a NULL ptr field) if (num_uxx * -// sizeof(uintxx_t)) would overflow SIZE_MAX. - -static inline wuffs_base__slice_u8 // -wuffs_base__malloc_slice_u8(void* (*malloc_func)(size_t), uint64_t num_u8) { - 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__slice_u8){}); -} - -static inline wuffs_base__slice_u16 // -wuffs_base__malloc_slice_u16(void* (*malloc_func)(size_t), uint64_t num_u16) { - 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__slice_u16){}); -} - -static inline wuffs_base__slice_u32 // -wuffs_base__malloc_slice_u32(void* (*malloc_func)(size_t), uint64_t num_u32) { - 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__slice_u32){}); -} - -static inline wuffs_base__slice_u64 // -wuffs_base__malloc_slice_u64(void* (*malloc_func)(size_t), uint64_t num_u64) { - 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__slice_u64){}); -} - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/cmd/wuffs-c/internal/cgen/cgen.go b/cmd/wuffs-c/internal/cgen/cgen.go index adacd4b8..1bae140d 100644 --- a/cmd/wuffs-c/internal/cgen/cgen.go +++ b/cmd/wuffs-c/internal/cgen/cgen.go @@ -110,9 +110,10 @@ func Do(args []string) error { return nil, fmt.Errorf("base package shouldn't have any .wuffs files") } buf := make(buffer, 0, 128*1024) - if err := expandBangBangInsert(&buf, baseBaseImplC, map[string]func(*buffer) error{ - "// !! INSERT base-private.h.\n": insertBasePrivateH, - "// !! INSERT base-public.h.\n": insertBasePublicH, + if err := expandBangBangInsert(&buf, baseAllImplC, map[string]func(*buffer) error{ + "// !! INSERT base/all-private.h.\n": insertBaseAllPrivateH, + "// !! INSERT base/all-public.h.\n": insertBaseAllPublicH, + "// !! INSERT base/copyright\n": insertBaseCopyright, "// !! INSERT wuffs_base__status strings.\n": func(b *buffer) error { for _, z := range builtin.Statuses { msg, _ := t.Unescape(z) @@ -241,13 +242,22 @@ func expandBangBangInsert(b *buffer, s string, m map[string]func(*buffer) error) return nil } -func insertBasePrivateH(buf *buffer) error { - buf.writes(baseBasePrivateH) +func insertBaseAllPrivateH(buf *buffer) error { + buf.writes(baseCorePrivateH) + buf.writeb('\n') + buf.writes(baseRangePrivateH) + buf.writeb('\n') + buf.writes(baseIOPrivateH) + buf.writeb('\n') + buf.writes(baseMemoryPrivateH) + buf.writeb('\n') + buf.writes(baseImagePrivateH) + buf.writeb('\n') return nil } -func insertBasePublicH(buf *buffer) error { - if err := expandBangBangInsert(buf, baseBasePublicH, map[string]func(*buffer) error{ +func insertBaseAllPublicH(buf *buffer) error { + if err := expandBangBangInsert(buf, baseCorePublicH, map[string]func(*buffer) error{ "// !! INSERT wuffs_base__status names.\n": func(b *buffer) error { for _, z := range builtin.Statuses { msg, _ := t.Unescape(z) @@ -267,10 +277,22 @@ func insertBasePublicH(buf *buffer) error { }); err != nil { return err } + buf.writeb('\n') + buf.writes(baseRangePublicH) + buf.writeb('\n') + buf.writes(baseIOPublicH) + buf.writeb('\n') + buf.writes(baseMemoryPublicH) buf.writeb('\n') buf.writes(baseImagePublicH) + buf.writeb('\n') + return nil +} +func insertBaseCopyright(buf *buffer) error { + buf.writes(baseCopyright) + buf.writeb('\n') return nil } diff --git a/cmd/wuffs-c/internal/cgen/data.go b/cmd/wuffs-c/internal/cgen/data.go index 03b4aacf..12d1fe60 100644 --- a/cmd/wuffs-c/internal/cgen/data.go +++ b/cmd/wuffs-c/internal/cgen/data.go @@ -16,70 +16,18 @@ package cgen -const baseBasePublicH = "" + - "// Copyright 2017 The Wuffs Authors.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n#include \n#include \n#include \n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n// 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 v" + - "ersion, 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 version extension\n// (such as \"\", \"beta\" or \"rc.1\") is part of the string representation (such as\n// \"1.2.3-beta\") but not the uint64_t representation.\n//\n// All three of major, minor and patch being zero means that this is a\n// work-in-progress version, not a release version, and has no backwards or\n// forwards compatibility guarantees.\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_EXTENSION \"\"\n#define WUFFS_VERSION_STRING \"0.0.0\"\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.githubuserconte" + - "nt.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 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 = 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\n" + - "" + - "// ---------------- 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\n" + - "" + - "// ---------------- 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\n" + - "" + - "// ---------------- 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\n#ifdef __cplusplus\n} // extern \"C\"\n#endif\n" + +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 \n#include \n#include \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#ifdef __cplusplus\n} // extern \"C\"\n#endif\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, 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#endif // !defined(WUFFS_CONFIG__MODULES) ||\n // defi" + + "ned(WUFFS_CONFIG__MODULE__BASE)\n\n#endif // WUFFS_IMPLEMENTATION\n\n// !! WUFFS MONOLITHIC RELEASE DISCARDS EVERYTHING BELOW.\n\n#endif // WUFFS_INCLUDE_GUARD__BASE\n" + "" -const baseBasePrivateH = "" + - "// 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#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#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 i" + - "s 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_BASE__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#d" + - "efine 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__UNLIKE" + - "LY(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" + +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" + @@ -97,35 +45,45 @@ const baseBasePrivateH = "" + "// ---------------- 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,\n// length) where length is the minimum of dst.len and src.len.\n//\n// Passing a wuffs_base__slice_u8 with all fields NULL or zero (a valid, empty\n// slice) is valid and results in a no-op.\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 lengt" + "h = dst.len < src.len ? dst.len : src.len;\n if (length > 0) {\n memmove(dst.ptr, src.ptr, length);\n }\n return length;\n}\n\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\n" + - "" + - "// ---------------- 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" + - "" + - "// ---------------- 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_incl,\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\n" + - "" + - "// ---------------- 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_ptr,\n uint8_t* start,\n uint8_t* end,\n uint32_t length,\n uint32_t distance) {\n if (!distance) {\n return 0;\n }\n uint8_t* ptr = *ptr_ptr;\n if ((size_t)(ptr - start) < (size_t)(distance)) {\n return 0;\n }\n start = ptr - distance;\n size_t n = end - ptr;\n if ((size_t)(length) > n) {\n length = n;\n } else {\n n = length;\n }\n // TODO: unrolling by 3 seems best for the std/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, ha" + - "ve 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 *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n }\n for (; n; n--) {\n *ptr++ = *start++;\n }\n *ptr_ptr = ptr;\n return length;\n}\n\n// wuffs_base__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_ptr - start)\n// - length <= (end - *ptr_ptr)\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n_from_history_fast(uint8_t** ptr_ptr,\n uint8_t* start,\n uint8_t* end,\n uint32_t length,\n uint32_t distance) {\n uint8_t* ptr = *ptr_ptr;\n start = ptr - distance;\n uint32_t n = length;\n fo" + - "r (; n >= 3; n -= 3) {\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n }\n for (; n; n--) {\n *ptr++ = *start++;\n }\n *ptr_ptr = ptr;\n return length;\n}\n\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n_from_reader(uint8_t** ptr_ioptr_w,\n uint8_t* iobounds1_w,\n uint32_t length,\n uint8_t** ptr_ioptr_r,\n uint8_t* iobounds1_r) {\n uint8_t* ioptr_w = *ptr_ioptr_w;\n size_t n = length;\n if (n > ((size_t)(iobounds1_w - ioptr_w))) {\n n = iobounds1_w - ioptr_w;\n }\n uint8_t* ioptr_r = *ptr_ioptr_r;\n if (n > ((size_t)(iobounds1_r - ioptr_r))) {\n n = iobounds1_r - ioptr_r;\n }\n if (n > 0) {\n memmove(ioptr_w, ioptr_r, n);\n *ptr_ioptr_w += n;\n *ptr_ioptr_r += n;\n }\n return n;\n}\n\nstatic inline uint64_t //\nwuffs_base__io_writer__copy_from_slice(uint8_t** ptr_ioptr_w,\n u" + - "int8_t* iobounds1_w,\n wuffs_base__slice_u8 src) {\n uint8_t* ioptr_w = *ptr_ioptr_w;\n size_t n = src.len;\n if (n > ((size_t)(iobounds1_w - ioptr_w))) {\n n = iobounds1_w - ioptr_w;\n }\n if (n > 0) {\n memmove(ioptr_w, src.ptr, n);\n *ptr_ioptr_w += n;\n }\n return n;\n}\n\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n_from_slice(uint8_t** ptr_ioptr_w,\n uint8_t* iobounds1_w,\n uint32_t length,\n wuffs_base__slice_u8 src) {\n uint8_t* ioptr_w = *ptr_ioptr_w;\n size_t n = src.len;\n if (n > length) {\n n = length;\n }\n if (n > ((size_t)(iobounds1_w - ioptr_w))) {\n n = iobounds1_w - ioptr_w;\n }\n if (n > 0) {\n memmove(ioptr_w, src.ptr, n);\n *ptr_ioptr_w += n;\n }\n return n;\n}\n\nstatic inline wuffs_base__empty_struct //\nwuffs_base__io_reader__set_limit(wuffs_base__io_reader* o,\n uint8_t* ioptr_r,\n " + - " uint64_t limit) {\n if (o && (((size_t)(o->private_impl.limit - ioptr_r)) > limit)) {\n o->private_impl.limit = ioptr_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__empty_struct //\nwuffs_base__io_writer__set(wuffs_base__io_writer* o,\n wuffs_base__io_buffer* b,\n uint8_t** ioptr1_ptr,\n uint8_t** ioptr2_ptr,\n wuffs_base__slice_u8 s) {\n b->data.ptr = s.ptr;\n b->data.len = s.len;\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 = s.ptr;\n o->private_impl.limit = s.ptr + s.len;\n *ioptr1_ptr = s.ptr;\n *ioptr2_ptr = s.ptr + s.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#ifdef __cplusplus\n} // extern \"C\"\n#endif\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 baseBaseImplC = "" + - "// Copyright 2018 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#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-public.h.\n\n// WUFFS C HEADER ENDS HERE.\n#ifdef WUFFS_IMPLEMENTATION\n\n// !! INSERT base-private.h.\n\n#if !defined(WUFFS_CONFIG__MODULES) || de" + - "fined(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, 0x000000000000000F, 0x000000000000001F,\n 0x00000000" + - "0000003F, 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 0x003FFFFF" + - "FFFFFFFF, 0x007FFFFFFFFFFFFF, 0x00FFFFFFFFFFFFFF,\n 0x01FFFFFFFFFFFFFF, 0x03FFFFFFFFFFFFFF, 0x07FFFFFFFFFFFFFF,\n 0x0FFFFFFFFFFFFFFF, 0x1FFFFFFFFFFFFFFF, 0x3FFFFFFFFFFFFFFF,\n 0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF,\n};\n\n// !! INSERT wuffs_base__status strings.\n\n#endif // !defined(WUFFS_CONFIG__MODULES) ||\n // defined(WUFFS_CONFIG__MODULE__BASE)\n\n#endif // WUFFS_IMPLEMENTATION\n\n// !! WUFFS MONOLITHIC RELEASE DISCARDS EVERYTHING BELOW.\n\n#endif // WUFFS_INCLUDE_GUARD__BASE\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 version extension\n// (such as \"\", \"beta\" or \"rc.1\") is part of the string representation (such as\n// \"1.2.3-beta\") but not the uint64_t representation.\n//\n// All three of major, minor and patch being zero means that this is a\n// work-in-progress version, not a release version, and has no backwards or\n// forwards compatibility guarantees.\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_EXTENSION \"\"\n#define WUFFS_VERSION_STRING \"0.0.0\"\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 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 com" + + "piler 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 = "" + - "// 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#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n" + - "" + "// ---------------- 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// - bits 27 .. 26 are reserved.\n// - bits 25 .. 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" + @@ -171,5 +129,67 @@ const baseImagePublicH = "" + "r__bad_argument_length_too_short;\n }\n b->pixcfg = *pixcfg;\n wuffs_base__table_u8* tab = &b->private_impl.planes[0];\n tab->ptr = ptr;\n tab->width = pixcfg->private_impl.width;\n tab->height = pixcfg->private_impl.height;\n tab->stride = pixcfg->private_impl.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__slice_u8){\n .ptr = tab->ptr,\n .len = 1024,\n });\n }\n }\n return ((wuffs_base__slice_u8){});\n}\n\nstatic inline wuffs_base__table_u8 //\nwuffs_base__pixel_buffer__plane(wuffs_base__pixel_buffer* b, uint32_t p) {\n re" + "turn (b && (p < WUFFS_BASE__PIXEL_FORMAT__NUM_PLANES_MAX))\n ? b->private_impl.planes[p]\n : ((wuffs_base__table_u8){});\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__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#ifdef __cplusplus\n} // extern \"C\"\n#endif\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" + + "" + +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_ptr,\n uint8_t* start,\n uint8_t* end,\n uint32_t length,\n uint32_t distance) {\n if (!distance) {\n return 0;\n }\n uint8_t* ptr = *ptr_ptr;\n if ((size_t)(ptr - start) < (size_t)(distance)) {\n return 0;\n }\n start = ptr - distance;\n size_t n = end - ptr;\n if ((size_t)(length) > n) {\n length = n;\n } else {\n n = length;\n }\n // TODO: unrolling by 3 seems best for the std/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, ha" + + "ve 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 *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n }\n for (; n; n--) {\n *ptr++ = *start++;\n }\n *ptr_ptr = ptr;\n return length;\n}\n\n// wuffs_base__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_ptr - start)\n// - length <= (end - *ptr_ptr)\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n_from_history_fast(uint8_t** ptr_ptr,\n uint8_t* start,\n uint8_t* end,\n uint32_t length,\n uint32_t distance) {\n uint8_t* ptr = *ptr_ptr;\n start = ptr - distance;\n uint32_t n = length;\n fo" + + "r (; n >= 3; n -= 3) {\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n }\n for (; n; n--) {\n *ptr++ = *start++;\n }\n *ptr_ptr = ptr;\n return length;\n}\n\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n_from_reader(uint8_t** ptr_ioptr_w,\n uint8_t* iobounds1_w,\n uint32_t length,\n uint8_t** ptr_ioptr_r,\n uint8_t* iobounds1_r) {\n uint8_t* ioptr_w = *ptr_ioptr_w;\n size_t n = length;\n if (n > ((size_t)(iobounds1_w - ioptr_w))) {\n n = iobounds1_w - ioptr_w;\n }\n uint8_t* ioptr_r = *ptr_ioptr_r;\n if (n > ((size_t)(iobounds1_r - ioptr_r))) {\n n = iobounds1_r - ioptr_r;\n }\n if (n > 0) {\n memmove(ioptr_w, ioptr_r, n);\n *ptr_ioptr_w += n;\n *ptr_ioptr_r += n;\n }\n return n;\n}\n\nstatic inline uint64_t //\nwuffs_base__io_writer__copy_from_slice(uint8_t** ptr_ioptr_w,\n u" + + "int8_t* iobounds1_w,\n wuffs_base__slice_u8 src) {\n uint8_t* ioptr_w = *ptr_ioptr_w;\n size_t n = src.len;\n if (n > ((size_t)(iobounds1_w - ioptr_w))) {\n n = iobounds1_w - ioptr_w;\n }\n if (n > 0) {\n memmove(ioptr_w, src.ptr, n);\n *ptr_ioptr_w += n;\n }\n return n;\n}\n\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n_from_slice(uint8_t** ptr_ioptr_w,\n uint8_t* iobounds1_w,\n uint32_t length,\n wuffs_base__slice_u8 src) {\n uint8_t* ioptr_w = *ptr_ioptr_w;\n size_t n = src.len;\n if (n > length) {\n n = length;\n }\n if (n > ((size_t)(iobounds1_w - ioptr_w))) {\n n = iobounds1_w - ioptr_w;\n }\n if (n > 0) {\n memmove(ioptr_w, src.ptr, n);\n *ptr_ioptr_w += n;\n }\n return n;\n}\n\nstatic inline wuffs_base__empty_struct //\nwuffs_base__io_reader__set_limit(wuffs_base__io_reader* o,\n uint8_t* ioptr_r,\n " + + " uint64_t limit) {\n if (o && (((size_t)(o->private_impl.limit - ioptr_r)) > limit)) {\n o->private_impl.limit = ioptr_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__empty_struct //\nwuffs_base__io_writer__set(wuffs_base__io_writer* o,\n wuffs_base__io_buffer* b,\n uint8_t** ioptr1_ptr,\n uint8_t** ioptr2_ptr,\n wuffs_base__slice_u8 s) {\n b->data.ptr = s.ptr;\n b->data.len = s.len;\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 = s.ptr;\n o->private_impl.limit = s.ptr + s.len;\n *ioptr1_ptr = s.ptr;\n *ioptr2_ptr = s.ptr + s.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" + + "" + +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" + + "" + + "// ---------------- 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_incl,\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/internal/cgen/gen.go b/cmd/wuffs-c/internal/cgen/gen.go index eb42cae1..530f2c17 100644 --- a/cmd/wuffs-c/internal/cgen/gen.go +++ b/cmd/wuffs-c/internal/cgen/gen.go @@ -73,30 +73,54 @@ func genBase(out *bytes.Buffer) error { files := []struct { filename, varname string }{ - {"base/base-public.h", "baseBasePublicH"}, - {"base/base-private.h", "baseBasePrivateH"}, - {"base/base-impl.c", "baseBaseImplC"}, + {"base/all-impl.c", "baseAllImplC"}, + {"base/core-private.h", "baseCorePrivateH"}, + {"base/core-public.h", "baseCorePublicH"}, + {"base/memory-private.h", "baseMemoryPrivateH"}, + {"base/memory-public.h", "baseMemoryPublicH"}, + {"base/image-private.h", "baseImagePrivateH"}, {"base/image-public.h", "baseImagePublicH"}, + {"base/io-private.h", "baseIOPrivateH"}, + {"base/io-public.h", "baseIOPublicH"}, + {"base/range-private.h", "baseRangePrivateH"}, + {"base/range-public.h", "baseRangePublicH"}, } + prefixAfterEditing := []byte("// After editing this file,") + prefixCopyright := []byte("// Copyright ") + copyright := []byte(nil) + for _, f := range files { in, err := ioutil.ReadFile(f.filename) if err != nil { return err } - const afterEditing = "// After editing this file," - if !bytes.HasPrefix(in, []byte(afterEditing)) { - return fmt.Errorf("%s's contents do not start with %q", f.filename, afterEditing) + if !bytes.HasPrefix(in, prefixAfterEditing) { + return fmt.Errorf("%s's contents do not start with %q", f.filename, prefixAfterEditing) } if i := bytes.Index(in, []byte("\n\n")); i >= 0 { in = in[i+2:] } + if !bytes.HasPrefix(in, prefixCopyright) { + return fmt.Errorf("%s's contents do not start with %q", f.filename, prefixCopyright) + } + if i := bytes.Index(in, []byte("\n\n")); i >= 0 { + if len(copyright) == 0 { + copyright = in[:i+2] + } + in = in[i+2:] + } + fmt.Fprintf(out, "const %s = \"\" +\n", f.varname) writeStringConst(out, in) out.WriteString("\"\"\n\n") } + + fmt.Fprintf(out, "const baseCopyright = \"\" +\n") + writeStringConst(out, copyright) + out.WriteString("\"\"\n\n") return nil } diff --git a/release/c/wuffs-unsupported-snapshot.h b/release/c/wuffs-unsupported-snapshot.h index a4bcc146..5d46ed65 100644 --- a/release/c/wuffs-unsupported-snapshot.h +++ b/release/c/wuffs-unsupported-snapshot.h @@ -1211,28 +1211,6 @@ wuffs_base__malloc_slice_u64(void* (*malloc_func)(size_t), uint64_t num_u64) { return ((wuffs_base__slice_u64){}); } -#ifdef __cplusplus -} // extern "C" -#endif - -// 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. - -#ifdef __cplusplus -extern "C" { -#endif - // ---------------- Images // wuffs_base__color_u32_argb_premul is an 8 bit per channel premultiplied @@ -3003,20 +2981,6 @@ struct wuffs_zlib__decoder__struct { // WUFFS C HEADER ENDS HERE. #ifdef WUFFS_IMPLEMENTATION -// 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. - #ifdef __cplusplus extern "C" { #endif @@ -3761,6 +3725,10 @@ wuffs_base__io_writer__set_mark(wuffs_base__io_writer* o, uint8_t* mark) { return ((wuffs_base__empty_struct){}); } + // ---------------- Memory Allocation + + // ---------------- Images + #ifdef __cplusplus } // extern "C" #endif