Remove wuffs_base__io_{reader,writer} mark field

This commit is contained in:
Nigel Tao committed 2018-04-28 09:58:45 +10:00
1 parent d0ffe6fe6a
commit d3342e7b4a
18 files changed
+120 -237

No files matched your search

-2
View File
@@ -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;
+4 -17
View File
@@ -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){});
}
+6 -7
View File
@@ -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 {
+11 -11
View File
@@ -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) {