diff --git a/cmd/wuffs-c/internal/cgen/base-header.h b/cmd/wuffs-c/internal/cgen/base-header.h index b027b977..fe03da1a 100644 --- a/cmd/wuffs-c/internal/cgen/base-header.h +++ b/cmd/wuffs-c/internal/cgen/base-header.h @@ -535,7 +535,6 @@ typedef struct { wuffs_base__io_buffer* buf; uint8_t* bounds[2]; wuffs_base__io_limit limit; - uint8_t* mark; } private_impl; } wuffs_base__io_reader; @@ -546,7 +545,6 @@ typedef struct { wuffs_base__io_buffer* buf; uint8_t* bounds[2]; wuffs_base__io_limit limit; - uint8_t* mark; } private_impl; } wuffs_base__io_writer; diff --git a/cmd/wuffs-c/internal/cgen/base-impl.h b/cmd/wuffs-c/internal/cgen/base-impl.h index 669f93b1..30bb375c 100644 --- a/cmd/wuffs-c/internal/cgen/base-impl.h +++ b/cmd/wuffs-c/internal/cgen/base-impl.h @@ -257,11 +257,11 @@ static inline bool wuffs_base__io_writer__is_valid(wuffs_base__io_writer o) { static inline uint32_t wuffs_base__io_writer__copy_from_history32( uint8_t** ptr_ptr, - uint8_t* start, // May be NULL, meaning an unmarked io_writer. + uint8_t* start, uint8_t* end, uint32_t distance, uint32_t length) { - if (!start || !distance) { + if (!distance) { return 0; } uint8_t* ptr = *ptr_ptr; @@ -300,7 +300,6 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32( // wuffs_base__io_writer__copy_from_history32__bco is a Bounds Check Optimized // version of the wuffs_base__io_writer__copy_from_history32 function above. // The caller needs to prove that: -// - start != NULL // - distance > 0 // - distance <= (*ptr_ptr - start) // - length <= (end - *ptr_ptr) @@ -384,18 +383,6 @@ static inline uint32_t wuffs_base__io_writer__copy_from_slice32( return n; } -// Note that the *__limit and *__mark methods are private (in base-impl.h) not -// public (in base-header.h). We assume that, at the boundary between user code -// and Wuffs code, the io_reader and io_writer's private_impl fields (including -// limit and mark) are NULL. Otherwise, some internal assumptions break down. -// For example, limits could be represented as pointers, even though -// conceptually they are counts, but that pointer-to-count correspondence -// becomes invalid if a buffer is re-used (e.g. on resuming a coroutine). -// -// Admittedly, some of the Wuffs test code calls these methods, but that test -// code is still Wuffs code, not user code. Other Wuffs test code modifies -// private_impl fields directly. - static inline wuffs_base__io_reader wuffs_base__io_reader__limit( wuffs_base__io_reader* o, uint64_t* ptr_to_len) { @@ -408,7 +395,7 @@ static inline wuffs_base__io_reader wuffs_base__io_reader__limit( static inline wuffs_base__empty_struct wuffs_base__io_reader__mark( wuffs_base__io_reader* o, uint8_t* mark) { - o->private_impl.mark = mark; + o->private_impl.bounds[0] = mark; return ((wuffs_base__empty_struct){}); } @@ -417,6 +404,6 @@ static inline wuffs_base__empty_struct wuffs_base__io_reader__mark( static inline wuffs_base__empty_struct wuffs_base__io_writer__mark( wuffs_base__io_writer* o, uint8_t* mark) { - o->private_impl.mark = mark; + o->private_impl.bounds[0] = mark; return ((wuffs_base__empty_struct){}); } diff --git a/cmd/wuffs-c/internal/cgen/data.go b/cmd/wuffs-c/internal/cgen/data.go index 0a5217b8..4af0f2b9 100644 --- a/cmd/wuffs-c/internal/cgen/data.go +++ b/cmd/wuffs-c/internal/cgen/data.go @@ -49,8 +49,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 uint8_t* mark;\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 uint8_t* mark;\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_writer 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 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" + "" + "// ---------------- 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" + @@ -91,11 +91,10 @@ 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, // May be NULL, meaning an unmarked io_writer.\n uint8_t* end,\n uint32_t distance,\n uint32_t length) {\n if (!start || !distance) {\n return 0;\n }\n uint8_t* ptr = *ptr_ptr;\n if ((size_t)(ptr - start) < (size_t)(distance)) {\n return 0;\n }\n start = ptr - distance;\n size_t n = end - ptr;\n if ((size_t)(length) > n) {\n length = n;\n } else {\n n = length;\n }\n // TODO: unrolling by 3 seems best for the std/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 // Altern" + - "atively, 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// - start != NULL\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// Note that the *__limit and *__mark methods are private (in base-impl.h) not\n// public (in base-header.h). We assume that, at the boundary between user code\n// and Wuffs code, the io_reader and io_writer's private_impl fields (including\n// limit and mark) are NULL. Otherwise, some internal assumptions break down.\n// For example, limits could be represented as pointers, even though\n// conceptually they are counts, but that pointer-to-count correspondence\n// becomes invalid if a buffer is re-used (e.g. on resuming a coroutine).\n//\n// Admittedly, some of the Wuffs test code calls these methods, but that test\n// code is still Wuffs code, not user code. Other Wuffs test code modifies\n// private_impl fields directly.\n\nstatic inline wuffs_base__io_reader wuffs_base__io_reader__limit(\n wuffs_base__io_reader* o,\n uin" + - "t64_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__mark(\n wuffs_base__io_reader* o,\n uint8_t* mark) {\n o->private_impl.mark = mark;\n return ((wuffs_base__empty_struct){});\n}\n\n// TODO: static inline wuffs_base__io_writer wuffs_base__io_writer__limit()\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.mark = mark;\n return ((wuffs_base__empty_struct){});\n}\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\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__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\n// TODO: static inline wuffs_base__io_writer wuffs_base__io_writer__limit()\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/cmd/wuffs-c/internal/cgen/expr.go b/cmd/wuffs-c/internal/cgen/expr.go index b14ace7e..d10a10e7 100644 --- a/cmd/wuffs-c/internal/cgen/expr.go +++ b/cmd/wuffs-c/internal/cgen/expr.go @@ -167,8 +167,8 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare } if isInSrc(g.tm, n, t.IDSinceMark, 0) { b.printf("((wuffs_base__slice_u8){ "+ - ".ptr = %ssrc.private_impl.mark, "+ - ".len = %ssrc.private_impl.mark ? (size_t)(%srptr_src - %ssrc.private_impl.mark) : 0, })", + ".ptr = %ssrc.private_impl.bounds[0], "+ + ".len = %ssrc.private_impl.bounds[0] ? (size_t)(%srptr_src - %ssrc.private_impl.bounds[0]) : 0, })", aPrefix, aPrefix, bPrefix, aPrefix) return nil } @@ -177,8 +177,8 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare return fmt.Errorf(`TODO: cgen an "in.dst.limit" expression`) } if isInDst(g.tm, n, t.IDMark, 0) { - // TODO: is a private_impl.mark the right representation? What if - // the function is passed a (ptr io_writer) instead of a + // TODO: is a private_impl.bounds[0] the right representation? What + // if the function is passed a (ptr io_writer) instead of a // (io_writer)? Do we still want to have that mark live outside of // the function scope? b.printf("wuffs_base__io_writer__mark(&%sdst, %swptr_dst)", aPrefix, bPrefix) @@ -191,12 +191,12 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare // benchmark numbers improve. len0, len1 := "", "" if true || !n.BoundsCheckOptimized() { - len0 = aPrefix + "dst.private_impl.mark ?" + len0 = aPrefix + "dst.private_impl.bounds[0] ?" len1 = ": 0" } b.printf("((wuffs_base__slice_u8){ "+ - ".ptr = %sdst.private_impl.mark, "+ - ".len = %s (size_t)(%swptr_dst - %sdst.private_impl.mark) %s, })", + ".ptr = %sdst.private_impl.bounds[0], "+ + ".len = %s (size_t)(%swptr_dst - %sdst.private_impl.bounds[0]) %s, })", aPrefix, len0, bPrefix, aPrefix, len1) return nil } @@ -204,7 +204,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare if pp == parenthesesMandatory { b.writeb('(') } - b.printf("%sdst.private_impl.mark != NULL", aPrefix) + b.printf("%sdst.private_impl.bounds[0] != NULL", aPrefix) if pp == parenthesesMandatory { b.writeb(')') } @@ -228,7 +228,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare bco = "__bco" } b.printf("wuffs_base__io_writer__copy_from_history32%s("+ - "&%swptr_dst, %sdst.private_impl.mark , %swend_dst", + "&%swptr_dst, %sdst.private_impl.bounds[0] , %swend_dst", bco, bPrefix, aPrefix, bPrefix) for _, o := range n.Args() { b.writeb(',') @@ -348,8 +348,8 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare if isThatMethod(g.tm, n, t.IDSinceMark, 0) { // TODO: don't hard-code v_r or b_rptr_src. b.printf("((wuffs_base__slice_u8){ " + - ".ptr = v_r.private_impl.mark, " + - ".len = v_r.private_impl.mark ? (size_t)(b_rptr_src - v_r.private_impl.mark) : 0, })") + ".ptr = v_r.private_impl.bounds[0], " + + ".len = v_r.private_impl.bounds[0] ? (size_t)(b_rptr_src - v_r.private_impl.bounds[0]) : 0, })") return nil } if isThatMethod(g.tm, n, g.tm.ByName("initialize"), 5) { diff --git a/gen/c/std/adler32.c b/gen/c/std/adler32.c index 00ce8bad..9da9e711 100644 --- a/gen/c/std/adler32.c +++ b/gen/c/std/adler32.c @@ -538,7 +538,6 @@ typedef struct { wuffs_base__io_buffer* buf; uint8_t* bounds[2]; wuffs_base__io_limit limit; - uint8_t* mark; } private_impl; } wuffs_base__io_reader; @@ -549,7 +548,6 @@ typedef struct { wuffs_base__io_buffer* buf; uint8_t* bounds[2]; wuffs_base__io_limit limit; - uint8_t* mark; } private_impl; } wuffs_base__io_writer; @@ -1351,11 +1349,11 @@ static inline bool wuffs_base__io_writer__is_valid(wuffs_base__io_writer o) { static inline uint32_t wuffs_base__io_writer__copy_from_history32( uint8_t** ptr_ptr, - uint8_t* start, // May be NULL, meaning an unmarked io_writer. + uint8_t* start, uint8_t* end, uint32_t distance, uint32_t length) { - if (!start || !distance) { + if (!distance) { return 0; } uint8_t* ptr = *ptr_ptr; @@ -1394,7 +1392,6 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32( // wuffs_base__io_writer__copy_from_history32__bco is a Bounds Check Optimized // version of the wuffs_base__io_writer__copy_from_history32 function above. // The caller needs to prove that: -// - start != NULL // - distance > 0 // - distance <= (*ptr_ptr - start) // - length <= (end - *ptr_ptr) @@ -1478,18 +1475,6 @@ static inline uint32_t wuffs_base__io_writer__copy_from_slice32( return n; } -// Note that the *__limit and *__mark methods are private (in base-impl.h) not -// public (in base-header.h). We assume that, at the boundary between user code -// and Wuffs code, the io_reader and io_writer's private_impl fields (including -// limit and mark) are NULL. Otherwise, some internal assumptions break down. -// For example, limits could be represented as pointers, even though -// conceptually they are counts, but that pointer-to-count correspondence -// becomes invalid if a buffer is re-used (e.g. on resuming a coroutine). -// -// Admittedly, some of the Wuffs test code calls these methods, but that test -// code is still Wuffs code, not user code. Other Wuffs test code modifies -// private_impl fields directly. - static inline wuffs_base__io_reader wuffs_base__io_reader__limit( wuffs_base__io_reader* o, uint64_t* ptr_to_len) { @@ -1502,7 +1487,7 @@ static inline wuffs_base__io_reader wuffs_base__io_reader__limit( static inline wuffs_base__empty_struct wuffs_base__io_reader__mark( wuffs_base__io_reader* o, uint8_t* mark) { - o->private_impl.mark = mark; + o->private_impl.bounds[0] = mark; return ((wuffs_base__empty_struct){}); } @@ -1511,7 +1496,7 @@ static inline wuffs_base__empty_struct wuffs_base__io_reader__mark( static inline wuffs_base__empty_struct wuffs_base__io_writer__mark( wuffs_base__io_writer* o, uint8_t* mark) { - o->private_impl.mark = mark; + o->private_impl.bounds[0] = mark; return ((wuffs_base__empty_struct){}); } diff --git a/gen/c/std/crc32.c b/gen/c/std/crc32.c index b3986b4d..73d9fcc3 100644 --- a/gen/c/std/crc32.c +++ b/gen/c/std/crc32.c @@ -538,7 +538,6 @@ typedef struct { wuffs_base__io_buffer* buf; uint8_t* bounds[2]; wuffs_base__io_limit limit; - uint8_t* mark; } private_impl; } wuffs_base__io_reader; @@ -549,7 +548,6 @@ typedef struct { wuffs_base__io_buffer* buf; uint8_t* bounds[2]; wuffs_base__io_limit limit; - uint8_t* mark; } private_impl; } wuffs_base__io_writer; @@ -1350,11 +1348,11 @@ static inline bool wuffs_base__io_writer__is_valid(wuffs_base__io_writer o) { static inline uint32_t wuffs_base__io_writer__copy_from_history32( uint8_t** ptr_ptr, - uint8_t* start, // May be NULL, meaning an unmarked io_writer. + uint8_t* start, uint8_t* end, uint32_t distance, uint32_t length) { - if (!start || !distance) { + if (!distance) { return 0; } uint8_t* ptr = *ptr_ptr; @@ -1393,7 +1391,6 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32( // wuffs_base__io_writer__copy_from_history32__bco is a Bounds Check Optimized // version of the wuffs_base__io_writer__copy_from_history32 function above. // The caller needs to prove that: -// - start != NULL // - distance > 0 // - distance <= (*ptr_ptr - start) // - length <= (end - *ptr_ptr) @@ -1477,18 +1474,6 @@ static inline uint32_t wuffs_base__io_writer__copy_from_slice32( return n; } -// Note that the *__limit and *__mark methods are private (in base-impl.h) not -// public (in base-header.h). We assume that, at the boundary between user code -// and Wuffs code, the io_reader and io_writer's private_impl fields (including -// limit and mark) are NULL. Otherwise, some internal assumptions break down. -// For example, limits could be represented as pointers, even though -// conceptually they are counts, but that pointer-to-count correspondence -// becomes invalid if a buffer is re-used (e.g. on resuming a coroutine). -// -// Admittedly, some of the Wuffs test code calls these methods, but that test -// code is still Wuffs code, not user code. Other Wuffs test code modifies -// private_impl fields directly. - static inline wuffs_base__io_reader wuffs_base__io_reader__limit( wuffs_base__io_reader* o, uint64_t* ptr_to_len) { @@ -1501,7 +1486,7 @@ static inline wuffs_base__io_reader wuffs_base__io_reader__limit( static inline wuffs_base__empty_struct wuffs_base__io_reader__mark( wuffs_base__io_reader* o, uint8_t* mark) { - o->private_impl.mark = mark; + o->private_impl.bounds[0] = mark; return ((wuffs_base__empty_struct){}); } @@ -1510,7 +1495,7 @@ static inline wuffs_base__empty_struct wuffs_base__io_reader__mark( static inline wuffs_base__empty_struct wuffs_base__io_writer__mark( wuffs_base__io_writer* o, uint8_t* mark) { - o->private_impl.mark = mark; + o->private_impl.bounds[0] = mark; return ((wuffs_base__empty_struct){}); } diff --git a/gen/c/std/deflate.c b/gen/c/std/deflate.c index 5bf3dd9d..a196c483 100644 --- a/gen/c/std/deflate.c +++ b/gen/c/std/deflate.c @@ -538,7 +538,6 @@ typedef struct { wuffs_base__io_buffer* buf; uint8_t* bounds[2]; wuffs_base__io_limit limit; - uint8_t* mark; } private_impl; } wuffs_base__io_reader; @@ -549,7 +548,6 @@ typedef struct { wuffs_base__io_buffer* buf; uint8_t* bounds[2]; wuffs_base__io_limit limit; - uint8_t* mark; } private_impl; } wuffs_base__io_writer; @@ -1442,11 +1440,11 @@ static inline bool wuffs_base__io_writer__is_valid(wuffs_base__io_writer o) { static inline uint32_t wuffs_base__io_writer__copy_from_history32( uint8_t** ptr_ptr, - uint8_t* start, // May be NULL, meaning an unmarked io_writer. + uint8_t* start, uint8_t* end, uint32_t distance, uint32_t length) { - if (!start || !distance) { + if (!distance) { return 0; } uint8_t* ptr = *ptr_ptr; @@ -1485,7 +1483,6 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32( // wuffs_base__io_writer__copy_from_history32__bco is a Bounds Check Optimized // version of the wuffs_base__io_writer__copy_from_history32 function above. // The caller needs to prove that: -// - start != NULL // - distance > 0 // - distance <= (*ptr_ptr - start) // - length <= (end - *ptr_ptr) @@ -1569,18 +1566,6 @@ static inline uint32_t wuffs_base__io_writer__copy_from_slice32( return n; } -// Note that the *__limit and *__mark methods are private (in base-impl.h) not -// public (in base-header.h). We assume that, at the boundary between user code -// and Wuffs code, the io_reader and io_writer's private_impl fields (including -// limit and mark) are NULL. Otherwise, some internal assumptions break down. -// For example, limits could be represented as pointers, even though -// conceptually they are counts, but that pointer-to-count correspondence -// becomes invalid if a buffer is re-used (e.g. on resuming a coroutine). -// -// Admittedly, some of the Wuffs test code calls these methods, but that test -// code is still Wuffs code, not user code. Other Wuffs test code modifies -// private_impl fields directly. - static inline wuffs_base__io_reader wuffs_base__io_reader__limit( wuffs_base__io_reader* o, uint64_t* ptr_to_len) { @@ -1593,7 +1578,7 @@ static inline wuffs_base__io_reader wuffs_base__io_reader__limit( static inline wuffs_base__empty_struct wuffs_base__io_reader__mark( wuffs_base__io_reader* o, uint8_t* mark) { - o->private_impl.mark = mark; + o->private_impl.bounds[0] = mark; return ((wuffs_base__empty_struct){}); } @@ -1602,7 +1587,7 @@ static inline wuffs_base__empty_struct wuffs_base__io_reader__mark( static inline wuffs_base__empty_struct wuffs_base__io_writer__mark( wuffs_base__io_writer* o, uint8_t* mark) { - o->private_impl.mark = mark; + o->private_impl.bounds[0] = mark; return ((wuffs_base__empty_struct){}); } @@ -1850,9 +1835,9 @@ wuffs_deflate__status wuffs_deflate__decoder__decode( goto exit; } v_written = ((wuffs_base__slice_u8){ - .ptr = a_dst.private_impl.mark, - .len = a_dst.private_impl.mark - ? (size_t)(b_wptr_dst - a_dst.private_impl.mark) + .ptr = a_dst.private_impl.bounds[0], + .len = a_dst.private_impl.bounds[0] + ? (size_t)(b_wptr_dst - a_dst.private_impl.bounds[0]) : 0, }); if (((uint64_t)(v_written.len)) >= 32768) { @@ -2954,7 +2939,7 @@ static wuffs_deflate__status wuffs_deflate__decoder__decode_huffman_fast( b_rend_src = b_rptr_src + len; } - if (!(a_dst.private_impl.mark != NULL)) { + if (!(a_dst.private_impl.bounds[0] != NULL)) { status = WUFFS_DEFLATE__ERROR_BAD_ARGUMENT; goto exit; } @@ -3155,25 +3140,25 @@ label_0_continue:; v_n_copied = 0; while (true) { if (((uint64_t)((v_dist_minus_1 + 1))) > - ((uint64_t)( - ((wuffs_base__slice_u8){ - .ptr = a_dst.private_impl.mark, - .len = a_dst.private_impl.mark - ? (size_t)(b_wptr_dst - a_dst.private_impl.mark) - : 0, - }) - .len))) { + ((uint64_t)(((wuffs_base__slice_u8){ + .ptr = a_dst.private_impl.bounds[0], + .len = a_dst.private_impl.bounds[0] + ? (size_t)(b_wptr_dst - + a_dst.private_impl.bounds[0]) + : 0, + }) + .len))) { v_hlen = 0; v_hdist = ((uint32_t)(( ((uint64_t)((v_dist_minus_1 + 1))) - - ((uint64_t)( - ((wuffs_base__slice_u8){ - .ptr = a_dst.private_impl.mark, - .len = a_dst.private_impl.mark - ? (size_t)(b_wptr_dst - a_dst.private_impl.mark) - : 0, - }) - .len))))); + ((uint64_t)(((wuffs_base__slice_u8){ + .ptr = a_dst.private_impl.bounds[0], + .len = a_dst.private_impl.bounds[0] + ? (size_t)(b_wptr_dst - + a_dst.private_impl.bounds[0]) + : 0, + }) + .len))))); if (v_length > v_hdist) { v_length -= v_hdist; v_hlen = v_hdist; @@ -3215,21 +3200,21 @@ label_0_continue:; goto label_0_continue; } if (((uint64_t)((v_dist_minus_1 + 1))) > - ((uint64_t)( - ((wuffs_base__slice_u8){ - .ptr = a_dst.private_impl.mark, - .len = a_dst.private_impl.mark - ? (size_t)(b_wptr_dst - a_dst.private_impl.mark) - : 0, - }) - .len))) { + ((uint64_t)(((wuffs_base__slice_u8){ + .ptr = a_dst.private_impl.bounds[0], + .len = a_dst.private_impl.bounds[0] + ? (size_t)(b_wptr_dst - + a_dst.private_impl.bounds[0]) + : 0, + }) + .len))) { status = WUFFS_DEFLATE__ERROR_INTERNAL_ERROR_INCONSISTENT_DISTANCE; goto exit; } } wuffs_base__io_writer__copy_from_history32__bco( - &b_wptr_dst, a_dst.private_impl.mark, b_wend_dst, v_dist_minus_1 + 1, - v_length); + &b_wptr_dst, a_dst.private_impl.bounds[0], b_wend_dst, + v_dist_minus_1 + 1, v_length); goto label_2_break; } label_2_break:; @@ -3564,25 +3549,26 @@ static wuffs_deflate__status wuffs_deflate__decoder__decode_huffman_slow( v_n_copied = 0; while (true) { if (((uint64_t)((v_dist_minus_1 + 1))) > - ((uint64_t)( - ((wuffs_base__slice_u8){ - .ptr = a_dst.private_impl.mark, - .len = a_dst.private_impl.mark - ? (size_t)(b_wptr_dst - a_dst.private_impl.mark) - : 0, - }) - .len))) { + ((uint64_t)(((wuffs_base__slice_u8){ + .ptr = a_dst.private_impl.bounds[0], + .len = a_dst.private_impl.bounds[0] + ? (size_t)(b_wptr_dst - + a_dst.private_impl.bounds[0]) + : 0, + }) + .len))) { v_hlen = 0; v_hdist = ((uint32_t)( (((uint64_t)((v_dist_minus_1 + 1))) - - ((uint64_t)(((wuffs_base__slice_u8){ - .ptr = a_dst.private_impl.mark, - .len = a_dst.private_impl.mark - ? (size_t)(b_wptr_dst - - a_dst.private_impl.mark) - : 0, - }) - .len))))); + ((uint64_t)( + ((wuffs_base__slice_u8){ + .ptr = a_dst.private_impl.bounds[0], + .len = a_dst.private_impl.bounds[0] + ? (size_t)(b_wptr_dst - + a_dst.private_impl.bounds[0]) + : 0, + }) + .len))))); if (v_length > v_hdist) { v_length -= v_hdist; v_hlen = v_hdist; @@ -3643,7 +3629,7 @@ static wuffs_deflate__status wuffs_deflate__decoder__decode_huffman_slow( } } v_n_copied = wuffs_base__io_writer__copy_from_history32( - &b_wptr_dst, a_dst.private_impl.mark, b_wend_dst, + &b_wptr_dst, a_dst.private_impl.bounds[0], b_wend_dst, v_dist_minus_1 + 1, v_length); if (v_length <= v_n_copied) { v_length = 0; diff --git a/gen/c/std/gif.c b/gen/c/std/gif.c index 7b66ad59..8ef4b29e 100644 --- a/gen/c/std/gif.c +++ b/gen/c/std/gif.c @@ -538,7 +538,6 @@ typedef struct { wuffs_base__io_buffer* buf; uint8_t* bounds[2]; wuffs_base__io_limit limit; - uint8_t* mark; } private_impl; } wuffs_base__io_reader; @@ -549,7 +548,6 @@ typedef struct { wuffs_base__io_buffer* buf; uint8_t* bounds[2]; wuffs_base__io_limit limit; - uint8_t* mark; } private_impl; } wuffs_base__io_writer; @@ -1460,11 +1458,11 @@ static inline bool wuffs_base__io_writer__is_valid(wuffs_base__io_writer o) { static inline uint32_t wuffs_base__io_writer__copy_from_history32( uint8_t** ptr_ptr, - uint8_t* start, // May be NULL, meaning an unmarked io_writer. + uint8_t* start, uint8_t* end, uint32_t distance, uint32_t length) { - if (!start || !distance) { + if (!distance) { return 0; } uint8_t* ptr = *ptr_ptr; @@ -1503,7 +1501,6 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32( // wuffs_base__io_writer__copy_from_history32__bco is a Bounds Check Optimized // version of the wuffs_base__io_writer__copy_from_history32 function above. // The caller needs to prove that: -// - start != NULL // - distance > 0 // - distance <= (*ptr_ptr - start) // - length <= (end - *ptr_ptr) @@ -1587,18 +1584,6 @@ static inline uint32_t wuffs_base__io_writer__copy_from_slice32( return n; } -// Note that the *__limit and *__mark methods are private (in base-impl.h) not -// public (in base-header.h). We assume that, at the boundary between user code -// and Wuffs code, the io_reader and io_writer's private_impl fields (including -// limit and mark) are NULL. Otherwise, some internal assumptions break down. -// For example, limits could be represented as pointers, even though -// conceptually they are counts, but that pointer-to-count correspondence -// becomes invalid if a buffer is re-used (e.g. on resuming a coroutine). -// -// Admittedly, some of the Wuffs test code calls these methods, but that test -// code is still Wuffs code, not user code. Other Wuffs test code modifies -// private_impl fields directly. - static inline wuffs_base__io_reader wuffs_base__io_reader__limit( wuffs_base__io_reader* o, uint64_t* ptr_to_len) { @@ -1611,7 +1596,7 @@ static inline wuffs_base__io_reader wuffs_base__io_reader__limit( static inline wuffs_base__empty_struct wuffs_base__io_reader__mark( wuffs_base__io_reader* o, uint8_t* mark) { - o->private_impl.mark = mark; + o->private_impl.bounds[0] = mark; return ((wuffs_base__empty_struct){}); } @@ -1620,7 +1605,7 @@ static inline wuffs_base__empty_struct wuffs_base__io_reader__mark( static inline wuffs_base__empty_struct wuffs_base__io_writer__mark( wuffs_base__io_writer* o, uint8_t* mark) { - o->private_impl.mark = mark; + o->private_impl.bounds[0] = mark; return ((wuffs_base__empty_struct){}); } @@ -3001,22 +2986,22 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id( goto label_1_break; } if (v_block_size < - ((uint64_t)( - ((wuffs_base__slice_u8){ - .ptr = v_r.private_impl.mark, - .len = v_r.private_impl.mark - ? (size_t)(b_rptr_src - v_r.private_impl.mark) - : 0, - }) - .len))) { + ((uint64_t)(((wuffs_base__slice_u8){ + .ptr = v_r.private_impl.bounds[0], + .len = v_r.private_impl.bounds[0] + ? (size_t)(b_rptr_src - + v_r.private_impl.bounds[0]) + : 0, + }) + .len))) { status = WUFFS_GIF__ERROR_INTERNAL_ERROR_INCONSISTENT_LIMITED_READ; goto exit; } v_block_size -= ((uint64_t)( ((wuffs_base__slice_u8){ - .ptr = v_r.private_impl.mark, - .len = v_r.private_impl.mark - ? (size_t)(b_rptr_src - v_r.private_impl.mark) + .ptr = v_r.private_impl.bounds[0], + .len = v_r.private_impl.bounds[0] + ? (size_t)(b_rptr_src - v_r.private_impl.bounds[0]) : 0, }) .len)); diff --git a/gen/c/std/gzip.c b/gen/c/std/gzip.c index a816c929..0be2b035 100644 --- a/gen/c/std/gzip.c +++ b/gen/c/std/gzip.c @@ -538,7 +538,6 @@ typedef struct { wuffs_base__io_buffer* buf; uint8_t* bounds[2]; wuffs_base__io_limit limit; - uint8_t* mark; } private_impl; } wuffs_base__io_reader; @@ -549,7 +548,6 @@ typedef struct { wuffs_base__io_buffer* buf; uint8_t* bounds[2]; wuffs_base__io_limit limit; - uint8_t* mark; } private_impl; } wuffs_base__io_writer; @@ -1646,11 +1644,11 @@ static inline bool wuffs_base__io_writer__is_valid(wuffs_base__io_writer o) { static inline uint32_t wuffs_base__io_writer__copy_from_history32( uint8_t** ptr_ptr, - uint8_t* start, // May be NULL, meaning an unmarked io_writer. + uint8_t* start, uint8_t* end, uint32_t distance, uint32_t length) { - if (!start || !distance) { + if (!distance) { return 0; } uint8_t* ptr = *ptr_ptr; @@ -1689,7 +1687,6 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32( // wuffs_base__io_writer__copy_from_history32__bco is a Bounds Check Optimized // version of the wuffs_base__io_writer__copy_from_history32 function above. // The caller needs to prove that: -// - start != NULL // - distance > 0 // - distance <= (*ptr_ptr - start) // - length <= (end - *ptr_ptr) @@ -1773,18 +1770,6 @@ static inline uint32_t wuffs_base__io_writer__copy_from_slice32( return n; } -// Note that the *__limit and *__mark methods are private (in base-impl.h) not -// public (in base-header.h). We assume that, at the boundary between user code -// and Wuffs code, the io_reader and io_writer's private_impl fields (including -// limit and mark) are NULL. Otherwise, some internal assumptions break down. -// For example, limits could be represented as pointers, even though -// conceptually they are counts, but that pointer-to-count correspondence -// becomes invalid if a buffer is re-used (e.g. on resuming a coroutine). -// -// Admittedly, some of the Wuffs test code calls these methods, but that test -// code is still Wuffs code, not user code. Other Wuffs test code modifies -// private_impl fields directly. - static inline wuffs_base__io_reader wuffs_base__io_reader__limit( wuffs_base__io_reader* o, uint64_t* ptr_to_len) { @@ -1797,7 +1782,7 @@ static inline wuffs_base__io_reader wuffs_base__io_reader__limit( static inline wuffs_base__empty_struct wuffs_base__io_reader__mark( wuffs_base__io_reader* o, uint8_t* mark) { - o->private_impl.mark = mark; + o->private_impl.bounds[0] = mark; return ((wuffs_base__empty_struct){}); } @@ -1806,7 +1791,7 @@ static inline wuffs_base__empty_struct wuffs_base__io_reader__mark( static inline wuffs_base__empty_struct wuffs_base__io_writer__mark( wuffs_base__io_writer* o, uint8_t* mark) { - o->private_impl.mark = mark; + o->private_impl.bounds[0] = mark; return ((wuffs_base__empty_struct){}); } @@ -2154,20 +2139,20 @@ wuffs_gzip__status wuffs_gzip__decoder__decode(wuffs_gzip__decoder* self, v_checksum_got = wuffs_crc32__ieee_hasher__update( &self->private_impl.f_checksum, ((wuffs_base__slice_u8){ - .ptr = a_dst.private_impl.mark, - .len = a_dst.private_impl.mark - ? (size_t)(b_wptr_dst - a_dst.private_impl.mark) + .ptr = a_dst.private_impl.bounds[0], + .len = a_dst.private_impl.bounds[0] + ? (size_t)(b_wptr_dst - a_dst.private_impl.bounds[0]) : 0, })); v_decoded_length_got += ((uint32_t)(( - ((uint64_t)( - ((wuffs_base__slice_u8){ - .ptr = a_dst.private_impl.mark, - .len = a_dst.private_impl.mark - ? (size_t)(b_wptr_dst - a_dst.private_impl.mark) - : 0, - }) - .len)) & + ((uint64_t)(((wuffs_base__slice_u8){ + .ptr = a_dst.private_impl.bounds[0], + .len = a_dst.private_impl.bounds[0] + ? (size_t)(b_wptr_dst - + a_dst.private_impl.bounds[0]) + : 0, + }) + .len)) & 4294967295))); } if (v_z == 0) { diff --git a/gen/c/std/zlib.c b/gen/c/std/zlib.c index 389bf4f4..0eb1d221 100644 --- a/gen/c/std/zlib.c +++ b/gen/c/std/zlib.c @@ -538,7 +538,6 @@ typedef struct { wuffs_base__io_buffer* buf; uint8_t* bounds[2]; wuffs_base__io_limit limit; - uint8_t* mark; } private_impl; } wuffs_base__io_reader; @@ -549,7 +548,6 @@ typedef struct { wuffs_base__io_buffer* buf; uint8_t* bounds[2]; wuffs_base__io_limit limit; - uint8_t* mark; } private_impl; } wuffs_base__io_writer; @@ -1646,11 +1644,11 @@ static inline bool wuffs_base__io_writer__is_valid(wuffs_base__io_writer o) { static inline uint32_t wuffs_base__io_writer__copy_from_history32( uint8_t** ptr_ptr, - uint8_t* start, // May be NULL, meaning an unmarked io_writer. + uint8_t* start, uint8_t* end, uint32_t distance, uint32_t length) { - if (!start || !distance) { + if (!distance) { return 0; } uint8_t* ptr = *ptr_ptr; @@ -1689,7 +1687,6 @@ static inline uint32_t wuffs_base__io_writer__copy_from_history32( // wuffs_base__io_writer__copy_from_history32__bco is a Bounds Check Optimized // version of the wuffs_base__io_writer__copy_from_history32 function above. // The caller needs to prove that: -// - start != NULL // - distance > 0 // - distance <= (*ptr_ptr - start) // - length <= (end - *ptr_ptr) @@ -1773,18 +1770,6 @@ static inline uint32_t wuffs_base__io_writer__copy_from_slice32( return n; } -// Note that the *__limit and *__mark methods are private (in base-impl.h) not -// public (in base-header.h). We assume that, at the boundary between user code -// and Wuffs code, the io_reader and io_writer's private_impl fields (including -// limit and mark) are NULL. Otherwise, some internal assumptions break down. -// For example, limits could be represented as pointers, even though -// conceptually they are counts, but that pointer-to-count correspondence -// becomes invalid if a buffer is re-used (e.g. on resuming a coroutine). -// -// Admittedly, some of the Wuffs test code calls these methods, but that test -// code is still Wuffs code, not user code. Other Wuffs test code modifies -// private_impl fields directly. - static inline wuffs_base__io_reader wuffs_base__io_reader__limit( wuffs_base__io_reader* o, uint64_t* ptr_to_len) { @@ -1797,7 +1782,7 @@ static inline wuffs_base__io_reader wuffs_base__io_reader__limit( static inline wuffs_base__empty_struct wuffs_base__io_reader__mark( wuffs_base__io_reader* o, uint8_t* mark) { - o->private_impl.mark = mark; + o->private_impl.bounds[0] = mark; return ((wuffs_base__empty_struct){}); } @@ -1806,7 +1791,7 @@ static inline wuffs_base__empty_struct wuffs_base__io_reader__mark( static inline wuffs_base__empty_struct wuffs_base__io_writer__mark( wuffs_base__io_writer* o, uint8_t* mark) { - o->private_impl.mark = mark; + o->private_impl.bounds[0] = mark; return ((wuffs_base__empty_struct){}); } @@ -2057,9 +2042,9 @@ wuffs_zlib__status wuffs_zlib__decoder__decode(wuffs_zlib__decoder* self, v_checksum_got = wuffs_adler32__hasher__update( &self->private_impl.f_checksum, ((wuffs_base__slice_u8){ - .ptr = a_dst.private_impl.mark, - .len = a_dst.private_impl.mark - ? (size_t)(b_wptr_dst - a_dst.private_impl.mark) + .ptr = a_dst.private_impl.bounds[0], + .len = a_dst.private_impl.bounds[0] + ? (size_t)(b_wptr_dst - a_dst.private_impl.bounds[0]) : 0, })); } diff --git a/gen/h/std/adler32.h b/gen/h/std/adler32.h index a3667814..fc7b7a07 100644 --- a/gen/h/std/adler32.h +++ b/gen/h/std/adler32.h @@ -538,7 +538,6 @@ typedef struct { wuffs_base__io_buffer* buf; uint8_t* bounds[2]; wuffs_base__io_limit limit; - uint8_t* mark; } private_impl; } wuffs_base__io_reader; @@ -549,7 +548,6 @@ typedef struct { wuffs_base__io_buffer* buf; uint8_t* bounds[2]; wuffs_base__io_limit limit; - uint8_t* mark; } private_impl; } wuffs_base__io_writer; diff --git a/gen/h/std/crc32.h b/gen/h/std/crc32.h index 2d867c2d..3511b101 100644 --- a/gen/h/std/crc32.h +++ b/gen/h/std/crc32.h @@ -538,7 +538,6 @@ typedef struct { wuffs_base__io_buffer* buf; uint8_t* bounds[2]; wuffs_base__io_limit limit; - uint8_t* mark; } private_impl; } wuffs_base__io_reader; @@ -549,7 +548,6 @@ typedef struct { wuffs_base__io_buffer* buf; uint8_t* bounds[2]; wuffs_base__io_limit limit; - uint8_t* mark; } private_impl; } wuffs_base__io_writer; diff --git a/gen/h/std/deflate.h b/gen/h/std/deflate.h index 2654822a..150e3801 100644 --- a/gen/h/std/deflate.h +++ b/gen/h/std/deflate.h @@ -538,7 +538,6 @@ typedef struct { wuffs_base__io_buffer* buf; uint8_t* bounds[2]; wuffs_base__io_limit limit; - uint8_t* mark; } private_impl; } wuffs_base__io_reader; @@ -549,7 +548,6 @@ typedef struct { wuffs_base__io_buffer* buf; uint8_t* bounds[2]; wuffs_base__io_limit limit; - uint8_t* mark; } private_impl; } wuffs_base__io_writer; diff --git a/gen/h/std/gif.h b/gen/h/std/gif.h index 2f783726..0d462b6e 100644 --- a/gen/h/std/gif.h +++ b/gen/h/std/gif.h @@ -538,7 +538,6 @@ typedef struct { wuffs_base__io_buffer* buf; uint8_t* bounds[2]; wuffs_base__io_limit limit; - uint8_t* mark; } private_impl; } wuffs_base__io_reader; @@ -549,7 +548,6 @@ typedef struct { wuffs_base__io_buffer* buf; uint8_t* bounds[2]; wuffs_base__io_limit limit; - uint8_t* mark; } private_impl; } wuffs_base__io_writer; diff --git a/gen/h/std/gzip.h b/gen/h/std/gzip.h index eeaf3f1e..5b80aa9e 100644 --- a/gen/h/std/gzip.h +++ b/gen/h/std/gzip.h @@ -538,7 +538,6 @@ typedef struct { wuffs_base__io_buffer* buf; uint8_t* bounds[2]; wuffs_base__io_limit limit; - uint8_t* mark; } private_impl; } wuffs_base__io_reader; @@ -549,7 +548,6 @@ typedef struct { wuffs_base__io_buffer* buf; uint8_t* bounds[2]; wuffs_base__io_limit limit; - uint8_t* mark; } private_impl; } wuffs_base__io_writer; diff --git a/gen/h/std/zlib.h b/gen/h/std/zlib.h index a10d4252..2c7cc461 100644 --- a/gen/h/std/zlib.h +++ b/gen/h/std/zlib.h @@ -538,7 +538,6 @@ typedef struct { wuffs_base__io_buffer* buf; uint8_t* bounds[2]; wuffs_base__io_limit limit; - uint8_t* mark; } private_impl; } wuffs_base__io_reader; @@ -549,7 +548,6 @@ typedef struct { wuffs_base__io_buffer* buf; uint8_t* bounds[2]; wuffs_base__io_limit limit; - uint8_t* mark; } private_impl; } wuffs_base__io_writer; diff --git a/lang/check/optimize.go b/lang/check/optimize.go index 6d5b7742..cd542c92 100644 --- a/lang/check/optimize.go +++ b/lang/check/optimize.go @@ -81,7 +81,7 @@ func (q *checker) optimizeNonSuspendible(n *a.Expr) error { // optimizeCopyFromHistory32 checks if the code generator can call the Bounds // Check Optimized version of CopyFromHistory32. As per cgen/base-impl.h, the // conditions are: -// - start != NULL +// - start != NULL // TODO: obsolete. // - distance > 0 // - distance <= (*ptr_ptr - start) // - length <= (end - *ptr_ptr) diff --git a/lang/token/list.go b/lang/token/list.go index fb86f8dc..23d5fa5c 100644 --- a/lang/token/list.go +++ b/lang/token/list.go @@ -412,7 +412,7 @@ const ( IDLowBits = ID(0xCE) IDHighBits = ID(0xCF) IDUnreadU8 = ID(0xD0) - IDIsMarked = ID(0xD1) + IDIsMarked = ID(0xD1) // TODO: obsolete; delete. ) var builtInsByID = [nBuiltInIDs]string{