diff --git a/cmd/wuffs-c/internal/cgen/base-header.h b/cmd/wuffs-c/internal/cgen/base-header.h index 16beda64..7b8e5419 100644 --- a/cmd/wuffs-c/internal/cgen/base-header.h +++ b/cmd/wuffs-c/internal/cgen/base-header.h @@ -568,6 +568,9 @@ typedef struct { // compatibility or safety guarantee if you do so. struct { wuffs_base__io_buffer* 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* bounds[2]; wuffs_base__io_limit limit; } private_impl; @@ -578,6 +581,9 @@ typedef struct { // compatibility or safety guarantee if you do so. struct { wuffs_base__io_buffer* 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* bounds[2]; wuffs_base__io_limit limit; } private_impl; @@ -586,22 +592,14 @@ typedef struct { 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){}); - if (buf) { - ret.private_impl.buf = buf; - ret.private_impl.bounds[0] = buf->ptr + buf->ri; - ret.private_impl.bounds[1] = buf->ptr + buf->wi; - } + 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){}); - if (buf) { - ret.private_impl.buf = buf; - ret.private_impl.bounds[0] = buf->ptr + buf->wi; - ret.private_impl.bounds[1] = buf->ptr + buf->len; - } + ret.private_impl.buf = buf; return ret; } diff --git a/cmd/wuffs-c/internal/cgen/base-impl.h b/cmd/wuffs-c/internal/cgen/base-impl.h index be50c9fc..9b6fad55 100644 --- a/cmd/wuffs-c/internal/cgen/base-impl.h +++ b/cmd/wuffs-c/internal/cgen/base-impl.h @@ -239,6 +239,8 @@ static inline bool wuffs_base__io_buffer__is_valid(wuffs_base__io_buffer buf) { 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) bounds. return buf ? ((buf->ptr <= o.private_impl.bounds[0]) && (o.private_impl.bounds[0] <= o.private_impl.bounds[1]) && (o.private_impl.bounds[1] <= buf->ptr + buf->len)) @@ -248,6 +250,8 @@ static inline bool wuffs_base__io_reader__is_valid(wuffs_base__io_reader o) { 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) bounds. return buf ? ((buf->ptr <= o.private_impl.bounds[0]) && (o.private_impl.bounds[0] <= o.private_impl.bounds[1]) && (o.private_impl.bounds[1] <= buf->ptr + buf->len)) diff --git a/cmd/wuffs-c/internal/cgen/data.go b/cmd/wuffs-c/internal/cgen/data.go index ca9bd5e0..0bbb3899 100644 --- a/cmd/wuffs-c/internal/cgen/data.go +++ b/cmd/wuffs-c/internal/cgen/data.go @@ -51,8 +51,8 @@ const baseHeader = "" + "in_inclusive_x, s.min_inclusive_x);\n r.min_inclusive_y =\n wuffs_base__u32__min(r.min_inclusive_y, s.min_inclusive_y);\n r.max_exclusive_x =\n wuffs_base__u32__max(r.max_exclusive_x, s.max_exclusive_x);\n r.max_exclusive_y =\n wuffs_base__u32__max(r.max_exclusive_y, s.max_exclusive_y);\n return r;\n}\n\nstatic inline uint32_t wuffs_base__rect_ie_u32__width(\n wuffs_base__rect_ie_u32 r) {\n return wuffs_base__u32__sat_sub(r.max_exclusive_x, r.min_inclusive_x);\n}\n\nstatic inline uint32_t wuffs_base__rect_ie_u32__height(\n wuffs_base__rect_ie_u32 r) {\n return wuffs_base__u32__sat_sub(r.max_exclusive_y, r.min_inclusive_y);\n}\n\n" + "" + "// ---------------- I/O\n\n// wuffs_base__io_buffer is a 1-dimensional buffer (a pointer and length), plus\n// additional indexes into that buffer, plus an opened / closed flag.\n//\n// A value with all fields NULL or zero is a valid, empty buffer.\ntypedef struct {\n uint8_t* ptr; // Pointer.\n size_t len; // Length.\n size_t wi; // Write index. Invariant: wi <= len.\n size_t ri; // Read index. Invariant: ri <= wi.\n bool closed; // No further writes are expected.\n} wuffs_base__io_buffer;\n\n// wuffs_base__io_limit provides a limited view of a 1-dimensional byte stream:\n// its first N bytes. That N can be greater than a buffer's current read or\n// write capacity. N decreases naturally over time as bytes are read from or\n// written to the stream.\n//\n// A value with all fields NULL or zero is a valid, unlimited view.\ntypedef struct wuffs_base__io_limit {\n uint64_t* ptr_to_len; // Pointer to N.\n struct wuffs_base__io_limit* next; // Linked list of limits.\n} wuffs_base__io_limit;\n\ntypedef" + - " struct {\n // Do not access the private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n wuffs_base__io_buffer* buf;\n uint8_t* bounds[2];\n wuffs_base__io_limit 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 wuffs_base__io_buffer* buf;\n uint8_t* bounds[2];\n wuffs_base__io_limit limit;\n } private_impl;\n} wuffs_base__io_writer;\n\nstatic inline wuffs_base__io_reader wuffs_base__io_buffer__reader(\n wuffs_base__io_buffer* buf) {\n wuffs_base__io_reader ret = ((wuffs_base__io_reader){});\n if (buf) {\n ret.private_impl.buf = buf;\n ret.private_impl.bounds[0] = buf->ptr + buf->ri;\n ret.private_impl.bounds[1] = buf->ptr + buf->wi;\n }\n return ret;\n}\n\nstatic inline wuffs_base__io_writer wuffs_base__io_buffer__writer(\n wuffs_base__io_buffer* buf) {\n wuffs_base__io_write" + - "r ret = ((wuffs_base__io_writer){});\n if (buf) {\n ret.private_impl.buf = buf;\n ret.private_impl.bounds[0] = buf->ptr + buf->wi;\n ret.private_impl.bounds[1] = buf->ptr + buf->len;\n }\n return ret;\n}\n\n" + + " struct {\n // Do not access the private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n wuffs_base__io_buffer* 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* bounds[2];\n wuffs_base__io_limit 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 wuffs_base__io_buffer* 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* bounds[2];\n wuffs_base__io_limit limit;\n } private_impl;\n} wuffs_base__io_writer;\n\nstatic inline wuffs_base__io_reader wuffs_base__io_buffer__reader(\n wuffs_base__io_buffer* buf) {\n wuff" + + "s_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 wuffs_base__io_buffer__writer(\n 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\n" + "" + "// ---------------- Images\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// - bit 23 indicates big-endian/MSB-first (as opposed to little/LSB).\n// - bit 22 indicates floating point (as opposed to integer).\n// - bits 21 .. 20 are the number of planes, minus 1. Zero means packed.\n// - bits 19 .. 16 encodes the number of bits (depth) in an index value.\n// Zero means direct, not palette-indexed.\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 channel.\n// - bits 3 .. 0 encodes the number of bits (depth) in the 0th channel.\n//\n// The bit fields of a wuffs_base" + "__pixel_format are not independent. For\n// example, the number of planes should not be greater than the number of\n// channels. Similarly, bits 15..4 are unused (and should be zero) if bits\n// 31..24 (color and transparency) together imply only 1 channel (gray, no\n// alpha) and floating point samples should mean a bit depth of 16, 32 or 64.\n//\n// Formats hold between 1 and 4 channels. For example: Y (1 channel: gray), YA\n// (2 channels: gray and alpha), BGR (3 channels: blue, green, red) or CMYK (4\n// channels: cyan, magenta, yellow, black).\n//\n// For direct formats with N > 1 channels, those channels can be laid out in\n// either 1 (packed) or N (planar) planes. For example, RGBA data is usually\n// packed, but YUV data is usually planar, due to chroma subsampling (for\n// details, see the wuffs_base__pixel_subsampling type). For indexed formats,\n// the palette (always 256 × 4 bytes) holds up to 4 packed bytes of color data\n// per index value, and there is only 1 plane (for the index). The distance\n// between s" + @@ -92,12 +92,13 @@ const baseImpl = "" + "" + "// --------\n\nstatic inline void wuffs_base__u8__sat_add_indirect(uint8_t* x, uint8_t y) {\n *x = wuffs_base__u8__sat_add(*x, y);\n}\n\nstatic inline void wuffs_base__u8__sat_sub_indirect(uint8_t* x, uint8_t y) {\n *x = wuffs_base__u8__sat_sub(*x, y);\n}\n\nstatic inline void wuffs_base__u16__sat_add_indirect(uint16_t* x, uint16_t y) {\n *x = wuffs_base__u16__sat_add(*x, y);\n}\n\nstatic inline void wuffs_base__u16__sat_sub_indirect(uint16_t* x, uint16_t y) {\n *x = wuffs_base__u16__sat_sub(*x, y);\n}\n\nstatic inline void wuffs_base__u32__sat_add_indirect(uint32_t* x, uint32_t y) {\n *x = wuffs_base__u32__sat_add(*x, y);\n}\n\nstatic inline void wuffs_base__u32__sat_sub_indirect(uint32_t* x, uint32_t y) {\n *x = wuffs_base__u32__sat_sub(*x, y);\n}\n\nstatic inline void wuffs_base__u64__sat_add_indirect(uint64_t* x, uint64_t y) {\n *x = wuffs_base__u64__sat_add(*x, y);\n}\n\nstatic inline void wuffs_base__u64__sat_sub_indirect(uint64_t* x, uint64_t y) {\n *x = wuffs_base__u64__sat_sub(*x, y);\n}\n\n" + "" + - "// ---------------- I/O\n\nstatic inline bool wuffs_base__io_buffer__is_valid(wuffs_base__io_buffer buf) {\n return (buf.ptr || (buf.len == 0)) && (buf.len >= buf.wi) &&\n (buf.wi >= buf.ri);\n}\n\nstatic inline bool wuffs_base__io_reader__is_valid(wuffs_base__io_reader o) {\n wuffs_base__io_buffer* buf = o.private_impl.buf;\n return buf ? ((buf->ptr <= o.private_impl.bounds[0]) &&\n (o.private_impl.bounds[0] <= o.private_impl.bounds[1]) &&\n (o.private_impl.bounds[1] <= buf->ptr + buf->len))\n : ((o.private_impl.bounds[0] == NULL) &&\n (o.private_impl.bounds[1] == NULL));\n}\n\nstatic inline bool wuffs_base__io_writer__is_valid(wuffs_base__io_writer o) {\n wuffs_base__io_buffer* buf = o.private_impl.buf;\n return buf ? ((buf->ptr <= o.private_impl.bounds[0]) &&\n (o.private_impl.bounds[0] <= o.private_impl.bounds[1]) &&\n (o.private_impl.bounds[1] <= buf->ptr + buf->len))\n : ((o.private_impl.bounds[0] == NULL) &&\n " + - " (o.private_impl.bounds[1] == NULL));\n}\n\nstatic inline uint32_t wuffs_base__io_writer__copy_from_history32(\n uint8_t** ptr_ptr,\n uint8_t* start,\n uint8_t* end,\n uint32_t distance,\n uint32_t length) {\n 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_from_history32 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_from_history32__bco below.\n //\n // Alternatively, or additionally, have a sloppy_copy_from_history3" + - "2 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_from_history32__bco is a Bounds Check Optimized\n// version of the wuffs_base__io_writer__copy_from_history32 function above.\n// The caller needs to prove that:\n// - distance > 0\n// - distance <= (*ptr_ptr - start)\n// - length <= (end - *ptr_ptr)\nstatic inline uint32_t wuffs_base__io_writer__copy_from_history32__bco(\n uint8_t** ptr_ptr,\n uint8_t* start,\n uint8_t* end,\n uint32_t distance,\n uint32_t length) {\n uint8_t* ptr = *ptr_ptr;\n start = ptr - distance;\n uint32_t n = length;\n for (; n >= 3; n -= 3) {\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n }\n for (; n; n--) {\n *ptr++ = *start++;\n }\n *ptr_ptr = ptr;\n return length;\n}\n\nstatic inline uint32_t wuff" + - "s_base__io_writer__copy_from_reader32(\n uint8_t** ptr_wptr,\n uint8_t* wend,\n uint8_t** ptr_rptr,\n uint8_t* rend,\n uint32_t length) {\n uint8_t* wptr = *ptr_wptr;\n size_t n = length;\n if (n > wend - wptr) {\n n = wend - wptr;\n }\n uint8_t* rptr = *ptr_rptr;\n if (n > rend - rptr) {\n n = rend - rptr;\n }\n if (n > 0) {\n memmove(wptr, rptr, n);\n *ptr_wptr += n;\n *ptr_rptr += n;\n }\n return n;\n}\n\nstatic inline uint64_t wuffs_base__io_writer__copy_from_slice(\n uint8_t** ptr_wptr,\n uint8_t* wend,\n wuffs_base__slice_u8 src) {\n uint8_t* wptr = *ptr_wptr;\n size_t n = src.len;\n if (n > wend - wptr) {\n n = wend - wptr;\n }\n if (n > 0) {\n memmove(wptr, src.ptr, n);\n *ptr_wptr += n;\n }\n return n;\n}\n\nstatic inline uint32_t wuffs_base__io_writer__copy_from_slice32(\n uint8_t** ptr_wptr,\n uint8_t* wend,\n wuffs_base__slice_u8 src,\n uint32_t length) {\n uint8_t* wptr = *ptr_wptr;\n size_t n = src.len;\n if (n > length) {\n n = length;\n }\n if (n > wend - wp" + - "tr) {\n n = wend - wptr;\n }\n if (n > 0) {\n memmove(wptr, src.ptr, n);\n *ptr_wptr += n;\n }\n return n;\n}\n\n// TODO: delete.\nstatic inline wuffs_base__io_reader wuffs_base__io_reader__limit(\n wuffs_base__io_reader* o,\n uint64_t* ptr_to_len) {\n wuffs_base__io_reader ret = *o;\n ret.private_impl.limit.ptr_to_len = ptr_to_len;\n ret.private_impl.limit.next = &o->private_impl.limit;\n return ret;\n}\n\nstatic inline wuffs_base__empty_struct wuffs_base__io_reader__set_limit(\n wuffs_base__io_reader* o,\n uint64_t limit) {\n if (o && o->private_impl.buf) {\n uint8_t* p = o->private_impl.buf->ptr + o->private_impl.buf->ri;\n if ((o->private_impl.bounds[1] - p) > limit) {\n o->private_impl.bounds[1] = p + limit;\n }\n }\n return ((wuffs_base__empty_struct){});\n}\n\nstatic inline wuffs_base__empty_struct\nwuffs_base__io_reader__set_limit_internal(wuffs_base__io_reader* o,\n uint64_t limit,\n size_t ri_override) {\n i" + - "f (o && o->private_impl.buf) {\n uint8_t* p = o->private_impl.buf->ptr + ri_override;\n if ((o->private_impl.bounds[1] - p) > limit) {\n o->private_impl.bounds[1] = p + limit;\n }\n }\n return ((wuffs_base__empty_struct){});\n}\n\nstatic inline wuffs_base__empty_struct wuffs_base__io_reader__mark(\n wuffs_base__io_reader* o,\n uint8_t* mark) {\n o->private_impl.bounds[0] = mark;\n return ((wuffs_base__empty_struct){});\n}\n\nstatic inline wuffs_base__empty_struct wuffs_base__io_writer__set_limit(\n wuffs_base__io_writer* o,\n uint64_t limit) {\n if (o && o->private_impl.buf) {\n uint8_t* p = o->private_impl.buf->ptr + o->private_impl.buf->wi;\n if ((o->private_impl.bounds[1] - p) > limit) {\n o->private_impl.bounds[1] = p + limit;\n }\n }\n return ((wuffs_base__empty_struct){});\n}\n\nstatic inline wuffs_base__empty_struct wuffs_base__io_writer__mark(\n wuffs_base__io_writer* o,\n uint8_t* mark) {\n o->private_impl.bounds[0] = mark;\n return ((wuffs_base__empty_struct){});\n}\n" + + "// ---------------- I/O\n\nstatic inline bool wuffs_base__io_buffer__is_valid(wuffs_base__io_buffer buf) {\n return (buf.ptr || (buf.len == 0)) && (buf.len >= buf.wi) &&\n (buf.wi >= buf.ri);\n}\n\nstatic inline bool wuffs_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) bounds.\n return buf ? ((buf->ptr <= o.private_impl.bounds[0]) &&\n (o.private_impl.bounds[0] <= o.private_impl.bounds[1]) &&\n (o.private_impl.bounds[1] <= buf->ptr + buf->len))\n : ((o.private_impl.bounds[0] == NULL) &&\n (o.private_impl.bounds[1] == NULL));\n}\n\nstatic inline bool wuffs_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) bounds.\n return buf ? ((buf->ptr <= o.private_impl.bounds[0]) &&\n (o.private_impl.bounds[0] <= o.private_impl.bounds[1]) &&\n (o.private_impl.bounds[1] <= buf->ptr + buf->len))\n : ((o.private_impl.bounds[0] == NULL) &&\n (o.private_impl.bounds[1] == NULL));\n}\n\nstatic inline uint32_t wuffs_base__io_writer__copy_from_history32(\n uint8_t** ptr_ptr,\n uint8_t* start,\n uint8_t* end,\n uint32_t distance,\n uint32_t length) {\n 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 th" + + "e\n // copy_from_history32 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_from_history32__bco below.\n //\n // Alternatively, or additionally, have a sloppy_copy_from_history32 method\n // that copies 8 bytes at a time, possibly writing more than length bytes?\n for (; n >= 3; n -= 3) {\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n }\n for (; n; n--) {\n *ptr++ = *start++;\n }\n *ptr_ptr = ptr;\n return length;\n}\n\n// wuffs_base__io_writer__copy_from_history32__bco is a Bounds Check Optimized\n// version of the wuffs_base__io_writer__copy_from_history32 function above.\n// The caller needs to prove that:\n// - distance > 0\n// - distance <= (*ptr_ptr - start)\n// - length <= (end - *ptr_ptr)\nstatic inline uint32_t wuffs_base__io_writer__copy_from_history32__bco(\n uint8_t** ptr_ptr,\n uint8_t* start,\n uint8_t* end,\n uint32_t distance,\n " + + "uint32_t length) {\n uint8_t* ptr = *ptr_ptr;\n start = ptr - distance;\n uint32_t n = length;\n for (; n >= 3; n -= 3) {\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n }\n for (; n; n--) {\n *ptr++ = *start++;\n }\n *ptr_ptr = ptr;\n return length;\n}\n\nstatic inline uint32_t wuffs_base__io_writer__copy_from_reader32(\n uint8_t** ptr_wptr,\n uint8_t* wend,\n uint8_t** ptr_rptr,\n uint8_t* rend,\n uint32_t length) {\n uint8_t* wptr = *ptr_wptr;\n size_t n = length;\n if (n > wend - wptr) {\n n = wend - wptr;\n }\n uint8_t* rptr = *ptr_rptr;\n if (n > rend - rptr) {\n n = rend - rptr;\n }\n if (n > 0) {\n memmove(wptr, rptr, n);\n *ptr_wptr += n;\n *ptr_rptr += n;\n }\n return n;\n}\n\nstatic inline uint64_t wuffs_base__io_writer__copy_from_slice(\n uint8_t** ptr_wptr,\n uint8_t* wend,\n wuffs_base__slice_u8 src) {\n uint8_t* wptr = *ptr_wptr;\n size_t n = src.len;\n if (n > wend - wptr) {\n n = wend - wptr;\n }\n if (n > 0) {\n memmove(wptr, src.ptr, n);\n " + + "*ptr_wptr += n;\n }\n return n;\n}\n\nstatic inline uint32_t wuffs_base__io_writer__copy_from_slice32(\n uint8_t** ptr_wptr,\n uint8_t* wend,\n wuffs_base__slice_u8 src,\n uint32_t length) {\n uint8_t* wptr = *ptr_wptr;\n size_t n = src.len;\n if (n > length) {\n n = length;\n }\n if (n > wend - wptr) {\n n = wend - wptr;\n }\n if (n > 0) {\n memmove(wptr, src.ptr, n);\n *ptr_wptr += n;\n }\n return n;\n}\n\n// TODO: delete.\nstatic inline wuffs_base__io_reader wuffs_base__io_reader__limit(\n wuffs_base__io_reader* o,\n uint64_t* ptr_to_len) {\n wuffs_base__io_reader ret = *o;\n ret.private_impl.limit.ptr_to_len = ptr_to_len;\n ret.private_impl.limit.next = &o->private_impl.limit;\n return ret;\n}\n\nstatic inline wuffs_base__empty_struct wuffs_base__io_reader__set_limit(\n wuffs_base__io_reader* o,\n uint64_t limit) {\n if (o && o->private_impl.buf) {\n uint8_t* p = o->private_impl.buf->ptr + o->private_impl.buf->ri;\n if ((o->private_impl.bounds[1] - p) > limit) {\n o->private_impl.bou" + + "nds[1] = p + limit;\n }\n }\n return ((wuffs_base__empty_struct){});\n}\n\nstatic inline wuffs_base__empty_struct\nwuffs_base__io_reader__set_limit_internal(wuffs_base__io_reader* o,\n uint64_t limit,\n size_t ri_override) {\n if (o && o->private_impl.buf) {\n uint8_t* p = o->private_impl.buf->ptr + ri_override;\n if ((o->private_impl.bounds[1] - p) > limit) {\n o->private_impl.bounds[1] = p + limit;\n }\n }\n return ((wuffs_base__empty_struct){});\n}\n\nstatic inline wuffs_base__empty_struct wuffs_base__io_reader__mark(\n wuffs_base__io_reader* o,\n uint8_t* mark) {\n o->private_impl.bounds[0] = mark;\n return ((wuffs_base__empty_struct){});\n}\n\nstatic inline wuffs_base__empty_struct wuffs_base__io_writer__set_limit(\n wuffs_base__io_writer* o,\n uint64_t limit) {\n if (o && o->private_impl.buf) {\n uint8_t* p = o->private_impl.buf->ptr + o->private_impl.buf->wi;\n if ((o->private_impl.bounds[1] - p) > limit) {\n " + + " o->private_impl.bounds[1] = p + limit;\n }\n }\n return ((wuffs_base__empty_struct){});\n}\n\nstatic inline wuffs_base__empty_struct wuffs_base__io_writer__mark(\n wuffs_base__io_writer* o,\n uint8_t* mark) {\n o->private_impl.bounds[0] = mark;\n return ((wuffs_base__empty_struct){});\n}\n" + "" type template_args_short_read struct { diff --git a/gen/c/std/adler32.c b/gen/c/std/adler32.c index 58e975c7..03c073bd 100644 --- a/gen/c/std/adler32.c +++ b/gen/c/std/adler32.c @@ -571,6 +571,9 @@ typedef struct { // compatibility or safety guarantee if you do so. struct { wuffs_base__io_buffer* 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* bounds[2]; wuffs_base__io_limit limit; } private_impl; @@ -581,6 +584,9 @@ typedef struct { // compatibility or safety guarantee if you do so. struct { wuffs_base__io_buffer* 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* bounds[2]; wuffs_base__io_limit limit; } private_impl; @@ -589,22 +595,14 @@ typedef struct { 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){}); - if (buf) { - ret.private_impl.buf = buf; - ret.private_impl.bounds[0] = buf->ptr + buf->ri; - ret.private_impl.bounds[1] = buf->ptr + buf->wi; - } + 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){}); - if (buf) { - ret.private_impl.buf = buf; - ret.private_impl.bounds[0] = buf->ptr + buf->wi; - ret.private_impl.bounds[1] = buf->ptr + buf->len; - } + ret.private_impl.buf = buf; return ret; } @@ -1366,6 +1364,8 @@ static inline bool wuffs_base__io_buffer__is_valid(wuffs_base__io_buffer buf) { 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) bounds. return buf ? ((buf->ptr <= o.private_impl.bounds[0]) && (o.private_impl.bounds[0] <= o.private_impl.bounds[1]) && (o.private_impl.bounds[1] <= buf->ptr + buf->len)) @@ -1375,6 +1375,8 @@ static inline bool wuffs_base__io_reader__is_valid(wuffs_base__io_reader o) { 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) bounds. return buf ? ((buf->ptr <= o.private_impl.bounds[0]) && (o.private_impl.bounds[0] <= o.private_impl.bounds[1]) && (o.private_impl.bounds[1] <= buf->ptr + buf->len)) diff --git a/gen/c/std/crc32.c b/gen/c/std/crc32.c index 1d27ddad..eb1d2641 100644 --- a/gen/c/std/crc32.c +++ b/gen/c/std/crc32.c @@ -571,6 +571,9 @@ typedef struct { // compatibility or safety guarantee if you do so. struct { wuffs_base__io_buffer* 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* bounds[2]; wuffs_base__io_limit limit; } private_impl; @@ -581,6 +584,9 @@ typedef struct { // compatibility or safety guarantee if you do so. struct { wuffs_base__io_buffer* 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* bounds[2]; wuffs_base__io_limit limit; } private_impl; @@ -589,22 +595,14 @@ typedef struct { 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){}); - if (buf) { - ret.private_impl.buf = buf; - ret.private_impl.bounds[0] = buf->ptr + buf->ri; - ret.private_impl.bounds[1] = buf->ptr + buf->wi; - } + 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){}); - if (buf) { - ret.private_impl.buf = buf; - ret.private_impl.bounds[0] = buf->ptr + buf->wi; - ret.private_impl.bounds[1] = buf->ptr + buf->len; - } + ret.private_impl.buf = buf; return ret; } @@ -1365,6 +1363,8 @@ static inline bool wuffs_base__io_buffer__is_valid(wuffs_base__io_buffer buf) { 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) bounds. return buf ? ((buf->ptr <= o.private_impl.bounds[0]) && (o.private_impl.bounds[0] <= o.private_impl.bounds[1]) && (o.private_impl.bounds[1] <= buf->ptr + buf->len)) @@ -1374,6 +1374,8 @@ static inline bool wuffs_base__io_reader__is_valid(wuffs_base__io_reader o) { 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) bounds. return buf ? ((buf->ptr <= o.private_impl.bounds[0]) && (o.private_impl.bounds[0] <= o.private_impl.bounds[1]) && (o.private_impl.bounds[1] <= buf->ptr + buf->len)) diff --git a/gen/c/std/deflate.c b/gen/c/std/deflate.c index 1b818662..7f529a22 100644 --- a/gen/c/std/deflate.c +++ b/gen/c/std/deflate.c @@ -571,6 +571,9 @@ typedef struct { // compatibility or safety guarantee if you do so. struct { wuffs_base__io_buffer* 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* bounds[2]; wuffs_base__io_limit limit; } private_impl; @@ -581,6 +584,9 @@ typedef struct { // compatibility or safety guarantee if you do so. struct { wuffs_base__io_buffer* 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* bounds[2]; wuffs_base__io_limit limit; } private_impl; @@ -589,22 +595,14 @@ typedef struct { 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){}); - if (buf) { - ret.private_impl.buf = buf; - ret.private_impl.bounds[0] = buf->ptr + buf->ri; - ret.private_impl.bounds[1] = buf->ptr + buf->wi; - } + 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){}); - if (buf) { - ret.private_impl.buf = buf; - ret.private_impl.bounds[0] = buf->ptr + buf->wi; - ret.private_impl.bounds[1] = buf->ptr + buf->len; - } + ret.private_impl.buf = buf; return ret; } @@ -1457,6 +1455,8 @@ static inline bool wuffs_base__io_buffer__is_valid(wuffs_base__io_buffer buf) { 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) bounds. return buf ? ((buf->ptr <= o.private_impl.bounds[0]) && (o.private_impl.bounds[0] <= o.private_impl.bounds[1]) && (o.private_impl.bounds[1] <= buf->ptr + buf->len)) @@ -1466,6 +1466,8 @@ static inline bool wuffs_base__io_reader__is_valid(wuffs_base__io_reader o) { 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) bounds. return buf ? ((buf->ptr <= o.private_impl.bounds[0]) && (o.private_impl.bounds[0] <= o.private_impl.bounds[1]) && (o.private_impl.bounds[1] <= buf->ptr + buf->len)) diff --git a/gen/c/std/gif.c b/gen/c/std/gif.c index 338c5c26..b1137841 100644 --- a/gen/c/std/gif.c +++ b/gen/c/std/gif.c @@ -571,6 +571,9 @@ typedef struct { // compatibility or safety guarantee if you do so. struct { wuffs_base__io_buffer* 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* bounds[2]; wuffs_base__io_limit limit; } private_impl; @@ -581,6 +584,9 @@ typedef struct { // compatibility or safety guarantee if you do so. struct { wuffs_base__io_buffer* 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* bounds[2]; wuffs_base__io_limit limit; } private_impl; @@ -589,22 +595,14 @@ typedef struct { 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){}); - if (buf) { - ret.private_impl.buf = buf; - ret.private_impl.bounds[0] = buf->ptr + buf->ri; - ret.private_impl.bounds[1] = buf->ptr + buf->wi; - } + 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){}); - if (buf) { - ret.private_impl.buf = buf; - ret.private_impl.bounds[0] = buf->ptr + buf->wi; - ret.private_impl.bounds[1] = buf->ptr + buf->len; - } + ret.private_impl.buf = buf; return ret; } @@ -1473,6 +1471,8 @@ static inline bool wuffs_base__io_buffer__is_valid(wuffs_base__io_buffer buf) { 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) bounds. return buf ? ((buf->ptr <= o.private_impl.bounds[0]) && (o.private_impl.bounds[0] <= o.private_impl.bounds[1]) && (o.private_impl.bounds[1] <= buf->ptr + buf->len)) @@ -1482,6 +1482,8 @@ static inline bool wuffs_base__io_reader__is_valid(wuffs_base__io_reader o) { 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) bounds. return buf ? ((buf->ptr <= o.private_impl.bounds[0]) && (o.private_impl.bounds[0] <= o.private_impl.bounds[1]) && (o.private_impl.bounds[1] <= buf->ptr + buf->len)) diff --git a/gen/c/std/gzip.c b/gen/c/std/gzip.c index 289963b4..65019df7 100644 --- a/gen/c/std/gzip.c +++ b/gen/c/std/gzip.c @@ -571,6 +571,9 @@ typedef struct { // compatibility or safety guarantee if you do so. struct { wuffs_base__io_buffer* 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* bounds[2]; wuffs_base__io_limit limit; } private_impl; @@ -581,6 +584,9 @@ typedef struct { // compatibility or safety guarantee if you do so. struct { wuffs_base__io_buffer* 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* bounds[2]; wuffs_base__io_limit limit; } private_impl; @@ -589,22 +595,14 @@ typedef struct { 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){}); - if (buf) { - ret.private_impl.buf = buf; - ret.private_impl.bounds[0] = buf->ptr + buf->ri; - ret.private_impl.bounds[1] = buf->ptr + buf->wi; - } + 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){}); - if (buf) { - ret.private_impl.buf = buf; - ret.private_impl.bounds[0] = buf->ptr + buf->wi; - ret.private_impl.bounds[1] = buf->ptr + buf->len; - } + ret.private_impl.buf = buf; return ret; } @@ -1661,6 +1659,8 @@ static inline bool wuffs_base__io_buffer__is_valid(wuffs_base__io_buffer buf) { 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) bounds. return buf ? ((buf->ptr <= o.private_impl.bounds[0]) && (o.private_impl.bounds[0] <= o.private_impl.bounds[1]) && (o.private_impl.bounds[1] <= buf->ptr + buf->len)) @@ -1670,6 +1670,8 @@ static inline bool wuffs_base__io_reader__is_valid(wuffs_base__io_reader o) { 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) bounds. return buf ? ((buf->ptr <= o.private_impl.bounds[0]) && (o.private_impl.bounds[0] <= o.private_impl.bounds[1]) && (o.private_impl.bounds[1] <= buf->ptr + buf->len)) diff --git a/gen/c/std/zlib.c b/gen/c/std/zlib.c index c4fb0c0a..f8a15a61 100644 --- a/gen/c/std/zlib.c +++ b/gen/c/std/zlib.c @@ -571,6 +571,9 @@ typedef struct { // compatibility or safety guarantee if you do so. struct { wuffs_base__io_buffer* 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* bounds[2]; wuffs_base__io_limit limit; } private_impl; @@ -581,6 +584,9 @@ typedef struct { // compatibility or safety guarantee if you do so. struct { wuffs_base__io_buffer* 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* bounds[2]; wuffs_base__io_limit limit; } private_impl; @@ -589,22 +595,14 @@ typedef struct { 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){}); - if (buf) { - ret.private_impl.buf = buf; - ret.private_impl.bounds[0] = buf->ptr + buf->ri; - ret.private_impl.bounds[1] = buf->ptr + buf->wi; - } + 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){}); - if (buf) { - ret.private_impl.buf = buf; - ret.private_impl.bounds[0] = buf->ptr + buf->wi; - ret.private_impl.bounds[1] = buf->ptr + buf->len; - } + ret.private_impl.buf = buf; return ret; } @@ -1661,6 +1659,8 @@ static inline bool wuffs_base__io_buffer__is_valid(wuffs_base__io_buffer buf) { 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) bounds. return buf ? ((buf->ptr <= o.private_impl.bounds[0]) && (o.private_impl.bounds[0] <= o.private_impl.bounds[1]) && (o.private_impl.bounds[1] <= buf->ptr + buf->len)) @@ -1670,6 +1670,8 @@ static inline bool wuffs_base__io_reader__is_valid(wuffs_base__io_reader o) { 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) bounds. return buf ? ((buf->ptr <= o.private_impl.bounds[0]) && (o.private_impl.bounds[0] <= o.private_impl.bounds[1]) && (o.private_impl.bounds[1] <= buf->ptr + buf->len)) diff --git a/gen/h/std/adler32.h b/gen/h/std/adler32.h index 243e76d4..389a2370 100644 --- a/gen/h/std/adler32.h +++ b/gen/h/std/adler32.h @@ -571,6 +571,9 @@ typedef struct { // compatibility or safety guarantee if you do so. struct { wuffs_base__io_buffer* 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* bounds[2]; wuffs_base__io_limit limit; } private_impl; @@ -581,6 +584,9 @@ typedef struct { // compatibility or safety guarantee if you do so. struct { wuffs_base__io_buffer* 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* bounds[2]; wuffs_base__io_limit limit; } private_impl; @@ -589,22 +595,14 @@ typedef struct { 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){}); - if (buf) { - ret.private_impl.buf = buf; - ret.private_impl.bounds[0] = buf->ptr + buf->ri; - ret.private_impl.bounds[1] = buf->ptr + buf->wi; - } + 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){}); - if (buf) { - ret.private_impl.buf = buf; - ret.private_impl.bounds[0] = buf->ptr + buf->wi; - ret.private_impl.bounds[1] = buf->ptr + buf->len; - } + ret.private_impl.buf = buf; return ret; } diff --git a/gen/h/std/crc32.h b/gen/h/std/crc32.h index 8569cecd..2ccd90b6 100644 --- a/gen/h/std/crc32.h +++ b/gen/h/std/crc32.h @@ -571,6 +571,9 @@ typedef struct { // compatibility or safety guarantee if you do so. struct { wuffs_base__io_buffer* 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* bounds[2]; wuffs_base__io_limit limit; } private_impl; @@ -581,6 +584,9 @@ typedef struct { // compatibility or safety guarantee if you do so. struct { wuffs_base__io_buffer* 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* bounds[2]; wuffs_base__io_limit limit; } private_impl; @@ -589,22 +595,14 @@ typedef struct { 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){}); - if (buf) { - ret.private_impl.buf = buf; - ret.private_impl.bounds[0] = buf->ptr + buf->ri; - ret.private_impl.bounds[1] = buf->ptr + buf->wi; - } + 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){}); - if (buf) { - ret.private_impl.buf = buf; - ret.private_impl.bounds[0] = buf->ptr + buf->wi; - ret.private_impl.bounds[1] = buf->ptr + buf->len; - } + ret.private_impl.buf = buf; return ret; } diff --git a/gen/h/std/deflate.h b/gen/h/std/deflate.h index f3002578..9fa26835 100644 --- a/gen/h/std/deflate.h +++ b/gen/h/std/deflate.h @@ -571,6 +571,9 @@ typedef struct { // compatibility or safety guarantee if you do so. struct { wuffs_base__io_buffer* 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* bounds[2]; wuffs_base__io_limit limit; } private_impl; @@ -581,6 +584,9 @@ typedef struct { // compatibility or safety guarantee if you do so. struct { wuffs_base__io_buffer* 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* bounds[2]; wuffs_base__io_limit limit; } private_impl; @@ -589,22 +595,14 @@ typedef struct { 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){}); - if (buf) { - ret.private_impl.buf = buf; - ret.private_impl.bounds[0] = buf->ptr + buf->ri; - ret.private_impl.bounds[1] = buf->ptr + buf->wi; - } + 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){}); - if (buf) { - ret.private_impl.buf = buf; - ret.private_impl.bounds[0] = buf->ptr + buf->wi; - ret.private_impl.bounds[1] = buf->ptr + buf->len; - } + ret.private_impl.buf = buf; return ret; } diff --git a/gen/h/std/gif.h b/gen/h/std/gif.h index 8901b1c0..55ae6759 100644 --- a/gen/h/std/gif.h +++ b/gen/h/std/gif.h @@ -571,6 +571,9 @@ typedef struct { // compatibility or safety guarantee if you do so. struct { wuffs_base__io_buffer* 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* bounds[2]; wuffs_base__io_limit limit; } private_impl; @@ -581,6 +584,9 @@ typedef struct { // compatibility or safety guarantee if you do so. struct { wuffs_base__io_buffer* 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* bounds[2]; wuffs_base__io_limit limit; } private_impl; @@ -589,22 +595,14 @@ typedef struct { 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){}); - if (buf) { - ret.private_impl.buf = buf; - ret.private_impl.bounds[0] = buf->ptr + buf->ri; - ret.private_impl.bounds[1] = buf->ptr + buf->wi; - } + 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){}); - if (buf) { - ret.private_impl.buf = buf; - ret.private_impl.bounds[0] = buf->ptr + buf->wi; - ret.private_impl.bounds[1] = buf->ptr + buf->len; - } + ret.private_impl.buf = buf; return ret; } diff --git a/gen/h/std/gzip.h b/gen/h/std/gzip.h index 93f14bb0..a8fc9f57 100644 --- a/gen/h/std/gzip.h +++ b/gen/h/std/gzip.h @@ -571,6 +571,9 @@ typedef struct { // compatibility or safety guarantee if you do so. struct { wuffs_base__io_buffer* 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* bounds[2]; wuffs_base__io_limit limit; } private_impl; @@ -581,6 +584,9 @@ typedef struct { // compatibility or safety guarantee if you do so. struct { wuffs_base__io_buffer* 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* bounds[2]; wuffs_base__io_limit limit; } private_impl; @@ -589,22 +595,14 @@ typedef struct { 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){}); - if (buf) { - ret.private_impl.buf = buf; - ret.private_impl.bounds[0] = buf->ptr + buf->ri; - ret.private_impl.bounds[1] = buf->ptr + buf->wi; - } + 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){}); - if (buf) { - ret.private_impl.buf = buf; - ret.private_impl.bounds[0] = buf->ptr + buf->wi; - ret.private_impl.bounds[1] = buf->ptr + buf->len; - } + ret.private_impl.buf = buf; return ret; } diff --git a/gen/h/std/zlib.h b/gen/h/std/zlib.h index 2393c683..79db4070 100644 --- a/gen/h/std/zlib.h +++ b/gen/h/std/zlib.h @@ -571,6 +571,9 @@ typedef struct { // compatibility or safety guarantee if you do so. struct { wuffs_base__io_buffer* 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* bounds[2]; wuffs_base__io_limit limit; } private_impl; @@ -581,6 +584,9 @@ typedef struct { // compatibility or safety guarantee if you do so. struct { wuffs_base__io_buffer* 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* bounds[2]; wuffs_base__io_limit limit; } private_impl; @@ -589,22 +595,14 @@ typedef struct { 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){}); - if (buf) { - ret.private_impl.buf = buf; - ret.private_impl.bounds[0] = buf->ptr + buf->ri; - ret.private_impl.bounds[1] = buf->ptr + buf->wi; - } + 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){}); - if (buf) { - ret.private_impl.buf = buf; - ret.private_impl.bounds[0] = buf->ptr + buf->wi; - ret.private_impl.bounds[1] = buf->ptr + buf->len; - } + ret.private_impl.buf = buf; return ret; }