mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Rename I/O bounds fields to mark and limit
This commit is contained in:
1 parent
6236e7205f
commit
4e7ef5fb88
7 files changed
+250
-241
No files matched your search
@@ -527,35 +527,38 @@ wuffs_base__io_buffer__is_valid(wuffs_base__io_buffer buf) {
|
||||
// TODO: wuffs_base__io_reader__is_eof is no longer used by Wuffs per se, but
|
||||
// it might be handy to programs that use Wuffs. Either delete it, or promote
|
||||
// it to the public API.
|
||||
//
|
||||
// If making this function public (i.e. moving it to base-header.h), it also
|
||||
// needs to allow NULL (i.e. implicit, callee-calculated) mark/limit.
|
||||
|
||||
static inline bool //
|
||||
wuffs_base__io_reader__is_eof(wuffs_base__io_reader o) {
|
||||
wuffs_base__io_buffer* buf = o.private_impl.buf;
|
||||
return buf && buf->closed && (buf->ptr + buf->wi == o.private_impl.bounds[1]);
|
||||
return buf && buf->closed && (buf->ptr + buf->wi == o.private_impl.limit);
|
||||
}
|
||||
|
||||
static inline bool //
|
||||
wuffs_base__io_reader__is_valid(wuffs_base__io_reader o) {
|
||||
wuffs_base__io_buffer* buf = o.private_impl.buf;
|
||||
// Note: if making this function public (i.e. moving it to base-header.h), it
|
||||
// also needs to allow NULL (i.e. implicit, callee-calculated) 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))
|
||||
: ((o.private_impl.bounds[0] == NULL) &&
|
||||
(o.private_impl.bounds[1] == NULL));
|
||||
// also needs to allow NULL (i.e. implicit, callee-calculated) mark/limit.
|
||||
return buf ? ((buf->ptr <= o.private_impl.mark) &&
|
||||
(o.private_impl.mark <= o.private_impl.limit) &&
|
||||
(o.private_impl.limit <= buf->ptr + buf->len))
|
||||
: ((o.private_impl.mark == NULL) &&
|
||||
(o.private_impl.limit == NULL));
|
||||
}
|
||||
|
||||
static inline bool //
|
||||
wuffs_base__io_writer__is_valid(wuffs_base__io_writer o) {
|
||||
wuffs_base__io_buffer* buf = o.private_impl.buf;
|
||||
// Note: if making this function public (i.e. moving it to base-header.h), it
|
||||
// also needs to allow NULL (i.e. implicit, callee-calculated) 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))
|
||||
: ((o.private_impl.bounds[0] == NULL) &&
|
||||
(o.private_impl.bounds[1] == NULL));
|
||||
// also needs to allow NULL (i.e. implicit, callee-calculated) mark/limit.
|
||||
return buf ? ((buf->ptr <= o.private_impl.mark) &&
|
||||
(o.private_impl.mark <= o.private_impl.limit) &&
|
||||
(o.private_impl.limit <= buf->ptr + buf->len))
|
||||
: ((o.private_impl.mark == NULL) &&
|
||||
(o.private_impl.limit == NULL));
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
@@ -690,15 +693,15 @@ static inline wuffs_base__empty_struct //
|
||||
wuffs_base__io_reader__set_limit(wuffs_base__io_reader* o,
|
||||
uint8_t* ioptr_r,
|
||||
uint64_t limit) {
|
||||
if (o && (((size_t)(o->private_impl.bounds[1] - ioptr_r)) > limit)) {
|
||||
o->private_impl.bounds[1] = ioptr_r + limit;
|
||||
if (o && (((size_t)(o->private_impl.limit - ioptr_r)) > limit)) {
|
||||
o->private_impl.limit = ioptr_r + limit;
|
||||
}
|
||||
return ((wuffs_base__empty_struct){});
|
||||
}
|
||||
|
||||
static inline wuffs_base__empty_struct //
|
||||
wuffs_base__io_reader__set_mark(wuffs_base__io_reader* o, uint8_t* mark) {
|
||||
o->private_impl.bounds[0] = mark;
|
||||
o->private_impl.mark = mark;
|
||||
return ((wuffs_base__empty_struct){});
|
||||
}
|
||||
|
||||
@@ -714,8 +717,8 @@ wuffs_base__io_writer__set(wuffs_base__io_writer* o,
|
||||
b->ri = 0;
|
||||
b->closed = false;
|
||||
o->private_impl.buf = b;
|
||||
o->private_impl.bounds[0] = s.ptr;
|
||||
o->private_impl.bounds[1] = s.ptr + s.len;
|
||||
o->private_impl.mark = s.ptr;
|
||||
o->private_impl.limit = s.ptr + s.len;
|
||||
*ioptr1_ptr = s.ptr;
|
||||
*ioptr2_ptr = s.ptr + s.len;
|
||||
return ((wuffs_base__empty_struct){});
|
||||
@@ -723,7 +726,7 @@ wuffs_base__io_writer__set(wuffs_base__io_writer* o,
|
||||
|
||||
static inline wuffs_base__empty_struct //
|
||||
wuffs_base__io_writer__set_mark(wuffs_base__io_writer* o, uint8_t* mark) {
|
||||
o->private_impl.bounds[0] = mark;
|
||||
o->private_impl.mark = mark;
|
||||
return ((wuffs_base__empty_struct){});
|
||||
}
|
||||
|
||||
|
||||
@@ -971,7 +971,8 @@ typedef struct {
|
||||
// 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];
|
||||
uint8_t* mark;
|
||||
uint8_t* limit;
|
||||
} private_impl;
|
||||
} wuffs_base__io_reader;
|
||||
|
||||
@@ -983,7 +984,8 @@ typedef struct {
|
||||
// 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];
|
||||
uint8_t* mark;
|
||||
uint8_t* limit;
|
||||
} private_impl;
|
||||
} wuffs_base__io_writer;
|
||||
|
||||
|
||||
@@ -133,8 +133,8 @@ func (g *gen) writeBuiltinIOReader(b *buffer, recv *a.Expr, method t.ID, args []
|
||||
|
||||
case t.IDSinceMark:
|
||||
b.printf("((wuffs_base__slice_u8){ "+
|
||||
".ptr = %ssrc.private_impl.bounds[0], "+
|
||||
".len = (size_t)(iop_a_src - %ssrc.private_impl.bounds[0]), })",
|
||||
".ptr = %ssrc.private_impl.mark, "+
|
||||
".len = (size_t)(iop_a_src - %ssrc.private_impl.mark), })",
|
||||
aPrefix, aPrefix)
|
||||
return nil
|
||||
|
||||
@@ -172,7 +172,7 @@ func (g *gen) writeBuiltinIOWriter(b *buffer, recv *a.Expr, method t.ID, args []
|
||||
suffix = "_fast"
|
||||
}
|
||||
b.printf("wuffs_base__io_writer__copy_n_from_history%s("+
|
||||
"&iop_a_dst, %sdst.private_impl.bounds[0], io1_a_dst",
|
||||
"&iop_a_dst, %sdst.private_impl.mark, io1_a_dst",
|
||||
suffix, aPrefix)
|
||||
for _, o := range args {
|
||||
b.writeb(',')
|
||||
@@ -201,7 +201,7 @@ func (g *gen) writeBuiltinIOWriter(b *buffer, recv *a.Expr, method t.ID, args []
|
||||
return g.writeArgs(b, args, rp, depth)
|
||||
|
||||
case t.IDSetMark:
|
||||
// TODO: is a private_impl.bounds[0] the right representation? What
|
||||
// TODO: is a private_impl.mark 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?
|
||||
@@ -210,8 +210,8 @@ func (g *gen) writeBuiltinIOWriter(b *buffer, recv *a.Expr, method t.ID, args []
|
||||
|
||||
case t.IDSinceMark:
|
||||
b.printf("((wuffs_base__slice_u8){ "+
|
||||
".ptr = %sdst.private_impl.bounds[0], "+
|
||||
".len = (size_t)(iop_a_dst - %sdst.private_impl.bounds[0]), })",
|
||||
".ptr = %sdst.private_impl.mark, "+
|
||||
".len = (size_t)(iop_a_dst - %sdst.private_impl.mark), })",
|
||||
aPrefix, aPrefix)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -65,9 +65,9 @@ const baseBasePublicH = "" +
|
||||
"e uint32_t //\nwuffs_base__rect_ie_u32__width(wuffs_base__rect_ie_u32* r) {\n return wuffs_base__u32__sat_sub(r->max_excl_x, r->min_incl_x);\n}\n\nstatic inline uint32_t //\nwuffs_base__rect_ie_u32__height(wuffs_base__rect_ie_u32* r) {\n return wuffs_base__u32__sat_sub(r->max_excl_y, r->min_incl_y);\n}\n\n#ifdef __cplusplus\n\ninline bool //\nwuffs_base__rect_ie_u32::is_empty() {\n return wuffs_base__rect_ie_u32__is_empty(this);\n}\n\ninline bool //\nwuffs_base__rect_ie_u32::equals(wuffs_base__rect_ie_u32 s) {\n return wuffs_base__rect_ie_u32__equals(this, s);\n}\n\ninline bool //\nwuffs_base__rect_ie_u32::contains(uint32_t x, uint32_t y) {\n return wuffs_base__rect_ie_u32__contains(this, x, y);\n}\n\ninline wuffs_base__rect_ie_u32 //\nwuffs_base__rect_ie_u32::intersect(wuffs_base__rect_ie_u32 s) {\n return wuffs_base__rect_ie_u32__intersect(this, s);\n}\n\ninline wuffs_base__rect_ie_u32 //\nwuffs_base__rect_ie_u32::unite(wuffs_base__rect_ie_u32 s) {\n return wuffs_base__rect_ie_u32__unite(this, s);\n}\n\ninline uint32_t //\nwuffs_" +
|
||||
"base__rect_ie_u32::width() {\n return wuffs_base__rect_ie_u32__width(this);\n}\n\ninline uint32_t //\nwuffs_base__rect_ie_u32::height() {\n return wuffs_base__rect_ie_u32__height(this);\n}\n\n#endif // __cplusplus\n\n" +
|
||||
"" +
|
||||
"// ---------------- I/O\n\nstruct wuffs_base__io_buffer__struct;\n\ntypedef struct {\n // Do not access the private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n struct wuffs_base__io_buffer__struct* buf;\n // The bounds values are typically NULL, when created by the Wuffs public\n // API. NULL means that the callee substitutes the implicit bounds derived\n // from buf.\n uint8_t* bounds[2];\n } private_impl;\n} wuffs_base__io_reader;\n\ntypedef struct {\n // Do not access the private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n struct wuffs_base__io_buffer__struct* buf;\n // The bounds values are typically NULL, when created by the Wuffs public\n // API. NULL means that the callee substitutes the implicit bounds derived\n // from buf.\n uint8_t* bounds[2];\n } private_impl;\n} wuffs_base__io_writer;\n\n// wuffs_base__io_buffer is a 1-dimensional buffer (a pointer and leng" +
|
||||
"th), 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 wuffs_base__io_buffer__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\n#ifdef __cplusplus\n inline void compact();\n inline wuffs_base__io_reader reader();\n inline wuffs_base__io_writer writer();\n#endif // __cplusplus\n\n} wuffs_base__io_buffer;\n\n// wuffs_base__io_buffer__compact moves any written but unread bytes to the\n// start of the buffer.\nstatic inline void //\nwuffs_base__io_buffer__compact(wuffs_base__io_buffer* buf) {\n if (!buf || (buf->ri == 0)) {\n return;\n }\n size_t n = buf->wi - buf->ri;\n if (n != 0) {\n memmove(buf->ptr, buf->ptr + buf->ri, n);\n }\n buf->wi = n;\n buf->ri = 0;\n}\n\nstatic inline wuffs_base__io_reader //\nwuffs_base__io_buffer__reader(" +
|
||||
"wuffs_base__io_buffer* buf) {\n wuffs_base__io_reader ret = ((wuffs_base__io_reader){});\n ret.private_impl.buf = buf;\n return ret;\n}\n\nstatic inline wuffs_base__io_writer //\nwuffs_base__io_buffer__writer(wuffs_base__io_buffer* buf) {\n wuffs_base__io_writer ret = ((wuffs_base__io_writer){});\n ret.private_impl.buf = buf;\n return ret;\n}\n\n#ifdef __cplusplus\n\ninline void //\nwuffs_base__io_buffer__struct::compact() {\n wuffs_base__io_buffer__compact(this);\n}\n\ninline wuffs_base__io_reader //\nwuffs_base__io_buffer__struct::reader() {\n return wuffs_base__io_buffer__reader(this);\n}\n\ninline wuffs_base__io_writer //\nwuffs_base__io_buffer__struct::writer() {\n return wuffs_base__io_buffer__writer(this);\n}\n\n#endif // __cplusplus\n\n#ifdef __cplusplus\n} // extern \"C\"\n#endif\n" +
|
||||
"// ---------------- I/O\n\nstruct wuffs_base__io_buffer__struct;\n\ntypedef struct {\n // Do not access the private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n struct wuffs_base__io_buffer__struct* buf;\n // The bounds values are typically NULL, when created by the Wuffs public\n // API. NULL means that the callee substitutes the implicit bounds derived\n // from buf.\n uint8_t* mark;\n uint8_t* limit;\n } private_impl;\n} wuffs_base__io_reader;\n\ntypedef struct {\n // Do not access the private_impl's fields directly. There is no API/ABI\n // compatibility or safety guarantee if you do so.\n struct {\n struct wuffs_base__io_buffer__struct* buf;\n // The bounds values are typically NULL, when created by the Wuffs public\n // API. NULL means that the callee substitutes the implicit bounds derived\n // from buf.\n uint8_t* mark;\n uint8_t* limit;\n } private_impl;\n} wuffs_base__io_writer;\n\n// wuffs_base__io_buffer is a 1-dimensio" +
|
||||
"nal 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 wuffs_base__io_buffer__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\n#ifdef __cplusplus\n inline void compact();\n inline wuffs_base__io_reader reader();\n inline wuffs_base__io_writer writer();\n#endif // __cplusplus\n\n} wuffs_base__io_buffer;\n\n// wuffs_base__io_buffer__compact moves any written but unread bytes to the\n// start of the buffer.\nstatic inline void //\nwuffs_base__io_buffer__compact(wuffs_base__io_buffer* buf) {\n if (!buf || (buf->ri == 0)) {\n return;\n }\n size_t n = buf->wi - buf->ri;\n if (n != 0) {\n memmove(buf->ptr, buf->ptr + buf->ri, n);\n }\n buf->wi = n;\n buf->ri = 0;\n}\n\nstatic inline wuffs_base__io_reader //\n" +
|
||||
"wuffs_base__io_buffer__reader(wuffs_base__io_buffer* buf) {\n wuffs_base__io_reader ret = ((wuffs_base__io_reader){});\n ret.private_impl.buf = buf;\n return ret;\n}\n\nstatic inline wuffs_base__io_writer //\nwuffs_base__io_buffer__writer(wuffs_base__io_buffer* buf) {\n wuffs_base__io_writer ret = ((wuffs_base__io_writer){});\n ret.private_impl.buf = buf;\n return ret;\n}\n\n#ifdef __cplusplus\n\ninline void //\nwuffs_base__io_buffer__struct::compact() {\n wuffs_base__io_buffer__compact(this);\n}\n\ninline wuffs_base__io_reader //\nwuffs_base__io_buffer__struct::reader() {\n return wuffs_base__io_buffer__reader(this);\n}\n\ninline wuffs_base__io_writer //\nwuffs_base__io_buffer__struct::writer() {\n return wuffs_base__io_buffer__writer(this);\n}\n\n#endif // __cplusplus\n\n#ifdef __cplusplus\n} // extern \"C\"\n#endif\n" +
|
||||
""
|
||||
|
||||
const baseBasePrivateH = "" +
|
||||
@@ -97,14 +97,14 @@ const baseBasePrivateH = "" +
|
||||
"\n}\n\nstatic inline wuffs_base__range_ie_u64 //\nwuffs_base__utility__make_range_ie_u64(wuffs_base__utility* ignored,\n uint64_t min_incl,\n uint64_t max_excl) {\n return ((wuffs_base__range_ie_u64){\n .min_incl = min_incl,\n .max_excl = max_excl,\n });\n}\n\nstatic inline wuffs_base__rect_ii_u32 //\nwuffs_base__utility__make_rect_ii_u32(wuffs_base__utility* ignored,\n uint32_t min_incl_x,\n uint32_t min_incl_y,\n uint32_t max_incl_x,\n uint32_t max_incl_y) {\n return ((wuffs_base__rect_ii_u32){\n .min_incl_x = min_incl_x,\n .min_incl_y = min_incl_y,\n .max_incl_x = max_incl_x,\n .max_incl_y = max_incl_y,\n });\n}\n\nstatic inline wuffs_base__rect_ie_u32 //\nwuffs_base__utility__make_rect_ie_u32(wuffs_base__utility* ignored,\n uint32_t min_incl" +
|
||||
"_x,\n uint32_t min_incl_y,\n uint32_t max_excl_x,\n uint32_t max_excl_y) {\n return ((wuffs_base__rect_ie_u32){\n .min_incl_x = min_incl_x,\n .min_incl_y = min_incl_y,\n .max_excl_x = max_excl_x,\n .max_excl_y = max_excl_y,\n });\n}\n\n" +
|
||||
"" +
|
||||
"// ---------------- I/O\n\nstatic inline bool //\nwuffs_base__io_buffer__is_valid(wuffs_base__io_buffer buf) {\n return (buf.ptr || (buf.len == 0)) && (buf.len >= buf.wi) &&\n (buf.wi >= buf.ri);\n}\n\n// TODO: wuffs_base__io_reader__is_eof is no longer used by Wuffs per se, but\n// it might be handy to programs that use Wuffs. Either delete it, or promote\n// it to the public API.\n\nstatic inline bool //\nwuffs_base__io_reader__is_eof(wuffs_base__io_reader o) {\n wuffs_base__io_buffer* buf = o.private_impl.buf;\n return buf && buf->closed && (buf->ptr + buf->wi == o.private_impl.bounds[1]);\n}\n\nstatic inline bool //\nwuffs_base__io_reader__is_valid(wuffs_base__io_reader o) {\n wuffs_base__io_buffer* buf = o.private_impl.buf;\n // Note: if making this function public (i.e. moving it to base-header.h), it\n // also needs to allow NULL (i.e. implicit, callee-calculated) 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 //\nwuffs_base__io_writer__is_valid(wuffs_base__io_writer o) {\n wuffs_base__io_buffer* buf = o.private_impl.buf;\n // Note: if making this function public (i.e. moving it to base-header.h), it\n // also needs to allow NULL (i.e. implicit, callee-calculated) 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 //\nwuffs_base__io_writer__copy_n_from_history(uint8_t** ptr_ptr,\n uint8_t* start,\n uint8_t* end,\n uint32_t " +
|
||||
"length,\n uint32_t distance) {\n if (!distance) {\n return 0;\n }\n uint8_t* ptr = *ptr_ptr;\n if ((size_t)(ptr - start) < (size_t)(distance)) {\n return 0;\n }\n start = ptr - distance;\n size_t n = end - ptr;\n if ((size_t)(length) > n) {\n length = n;\n } else {\n n = length;\n }\n // TODO: unrolling by 3 seems best for the std/deflate benchmarks, but that\n // is mostly because 3 is the minimum length for the deflate format. This\n // function implementation shouldn't overfit to that one format. Perhaps the\n // copy_n_from_history Wuffs method should also take an unroll hint argument,\n // and the cgen can look if that argument is the constant expression '3'.\n //\n // See also wuffs_base__io_writer__copy_n_from_history_fast below.\n //\n // Alternatively, or additionally, have a sloppy_copy_n_from_history method\n // that copies 8 bytes at a time, possibly writing more than length bytes?\n for (; n >= 3; n -= 3) {\n *ptr++ = *start++;\n *ptr++ = *star" +
|
||||
"t++;\n *ptr++ = *start++;\n }\n for (; n; n--) {\n *ptr++ = *start++;\n }\n *ptr_ptr = ptr;\n return length;\n}\n\n// wuffs_base__io_writer__copy_n_from_history_fast is like the\n// wuffs_base__io_writer__copy_n_from_history function above, but has stronger\n// pre-conditions. The caller needs to prove that:\n// - distance > 0\n// - distance <= (*ptr_ptr - start)\n// - length <= (end - *ptr_ptr)\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n_from_history_fast(uint8_t** ptr_ptr,\n uint8_t* start,\n uint8_t* end,\n uint32_t length,\n uint32_t distance) {\n uint8_t* ptr = *ptr_ptr;\n start = ptr - distance;\n uint32_t n = length;\n 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\nstat" +
|
||||
"ic inline uint32_t //\nwuffs_base__io_writer__copy_n_from_reader(uint8_t** ptr_ioptr_w,\n uint8_t* iobounds1_w,\n uint32_t length,\n uint8_t** ptr_ioptr_r,\n uint8_t* iobounds1_r) {\n uint8_t* ioptr_w = *ptr_ioptr_w;\n size_t n = length;\n if (n > ((size_t)(iobounds1_w - ioptr_w))) {\n n = iobounds1_w - ioptr_w;\n }\n uint8_t* ioptr_r = *ptr_ioptr_r;\n if (n > ((size_t)(iobounds1_r - ioptr_r))) {\n n = iobounds1_r - ioptr_r;\n }\n if (n > 0) {\n memmove(ioptr_w, ioptr_r, n);\n *ptr_ioptr_w += n;\n *ptr_ioptr_r += n;\n }\n return n;\n}\n\nstatic inline uint64_t //\nwuffs_base__io_writer__copy_from_slice(uint8_t** ptr_ioptr_w,\n uint8_t* iobounds1_w,\n wuffs_base__slice_u8 src) {\n uint8_t* ioptr_w = *ptr_ioptr_w;\n size_t n = src.len;\n if (n > ((size_t)(iobounds1_w - ioptr" +
|
||||
"_w))) {\n n = iobounds1_w - ioptr_w;\n }\n if (n > 0) {\n memmove(ioptr_w, src.ptr, n);\n *ptr_ioptr_w += n;\n }\n return n;\n}\n\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n_from_slice(uint8_t** ptr_ioptr_w,\n uint8_t* iobounds1_w,\n uint32_t length,\n wuffs_base__slice_u8 src) {\n uint8_t* ioptr_w = *ptr_ioptr_w;\n size_t n = src.len;\n if (n > length) {\n n = length;\n }\n if (n > ((size_t)(iobounds1_w - ioptr_w))) {\n n = iobounds1_w - ioptr_w;\n }\n if (n > 0) {\n memmove(ioptr_w, src.ptr, n);\n *ptr_ioptr_w += n;\n }\n return n;\n}\n\nstatic inline wuffs_base__empty_struct //\nwuffs_base__io_reader__set_limit(wuffs_base__io_reader* o,\n uint8_t* ioptr_r,\n uint64_t limit) {\n if (o && (((size_t)(o->private_impl.bounds[1] - ioptr_r)) > limit)) {\n o->private_impl.bounds[1] = ioptr_r + limit;\n }\n return (" +
|
||||
"(wuffs_base__empty_struct){});\n}\n\nstatic inline wuffs_base__empty_struct //\nwuffs_base__io_reader__set_mark(wuffs_base__io_reader* o, uint8_t* mark) {\n o->private_impl.bounds[0] = mark;\n return ((wuffs_base__empty_struct){});\n}\n\nstatic inline wuffs_base__empty_struct //\nwuffs_base__io_writer__set(wuffs_base__io_writer* o,\n wuffs_base__io_buffer* b,\n uint8_t** ioptr1_ptr,\n uint8_t** ioptr2_ptr,\n wuffs_base__slice_u8 s) {\n b->ptr = s.ptr;\n b->len = s.len;\n b->wi = 0;\n b->ri = 0;\n b->closed = false;\n o->private_impl.buf = b;\n o->private_impl.bounds[0] = s.ptr;\n o->private_impl.bounds[1] = s.ptr + s.len;\n *ioptr1_ptr = s.ptr;\n *ioptr2_ptr = s.ptr + s.len;\n return ((wuffs_base__empty_struct){});\n}\n\nstatic inline wuffs_base__empty_struct //\nwuffs_base__io_writer__set_mark(wuffs_base__io_writer* o, uint8_t* mark) {\n o->private_impl.bounds[0] = mark;\n return ((wuffs_base__empty_struct){});\n}\n\n#ifd" +
|
||||
"ef __cplusplus\n} // extern \"C\"\n#endif\n\n#endif // WUFFS_INCLUDE_GUARD__BASE_PRIVATE\n" +
|
||||
"// ---------------- I/O\n\nstatic inline bool //\nwuffs_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\n// TODO: wuffs_base__io_reader__is_eof is no longer used by Wuffs per se, but\n// it might be handy to programs that use Wuffs. Either delete it, or promote\n// it to the public API.\n//\n// If making this function public (i.e. moving it to base-header.h), it also\n// needs to allow NULL (i.e. implicit, callee-calculated) mark/limit.\n\nstatic inline bool //\nwuffs_base__io_reader__is_eof(wuffs_base__io_reader o) {\n wuffs_base__io_buffer* buf = o.private_impl.buf;\n return buf && buf->closed && (buf->ptr + buf->wi == o.private_impl.limit);\n}\n\nstatic inline bool //\nwuffs_base__io_reader__is_valid(wuffs_base__io_reader o) {\n wuffs_base__io_buffer* buf = o.private_impl.buf;\n // Note: if making this function public (i.e. moving it to base-header.h), it\n // also needs to allow NULL (i.e. implicit, callee-calculated)" +
|
||||
" mark/limit.\n return buf ? ((buf->ptr <= o.private_impl.mark) &&\n (o.private_impl.mark <= o.private_impl.limit) &&\n (o.private_impl.limit <= buf->ptr + buf->len))\n : ((o.private_impl.mark == NULL) &&\n (o.private_impl.limit == NULL));\n}\n\nstatic inline bool //\nwuffs_base__io_writer__is_valid(wuffs_base__io_writer o) {\n wuffs_base__io_buffer* buf = o.private_impl.buf;\n // Note: if making this function public (i.e. moving it to base-header.h), it\n // also needs to allow NULL (i.e. implicit, callee-calculated) mark/limit.\n return buf ? ((buf->ptr <= o.private_impl.mark) &&\n (o.private_impl.mark <= o.private_impl.limit) &&\n (o.private_impl.limit <= buf->ptr + buf->len))\n : ((o.private_impl.mark == NULL) &&\n (o.private_impl.limit == NULL));\n}\n\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n_from_history(uint8_t** ptr_ptr,\n uint8_t* start,\n " +
|
||||
" uint8_t* end,\n uint32_t length,\n uint32_t distance) {\n if (!distance) {\n return 0;\n }\n uint8_t* ptr = *ptr_ptr;\n if ((size_t)(ptr - start) < (size_t)(distance)) {\n return 0;\n }\n start = ptr - distance;\n size_t n = end - ptr;\n if ((size_t)(length) > n) {\n length = n;\n } else {\n n = length;\n }\n // TODO: unrolling by 3 seems best for the std/deflate benchmarks, but that\n // is mostly because 3 is the minimum length for the deflate format. This\n // function implementation shouldn't overfit to that one format. Perhaps the\n // copy_n_from_history Wuffs method should also take an unroll hint argument,\n // and the cgen can look if that argument is the constant expression '3'.\n //\n // See also wuffs_base__io_writer__copy_n_from_history_fast below.\n //\n // Alternatively, or additionally, have a sloppy_copy_n_from_history method\n // that copies 8 bytes at a time, possibly " +
|
||||
"writing more than length bytes?\n for (; n >= 3; n -= 3) {\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *start++;\n }\n for (; n; n--) {\n *ptr++ = *start++;\n }\n *ptr_ptr = ptr;\n return length;\n}\n\n// wuffs_base__io_writer__copy_n_from_history_fast is like the\n// wuffs_base__io_writer__copy_n_from_history function above, but has stronger\n// pre-conditions. The caller needs to prove that:\n// - distance > 0\n// - distance <= (*ptr_ptr - start)\n// - length <= (end - *ptr_ptr)\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n_from_history_fast(uint8_t** ptr_ptr,\n uint8_t* start,\n uint8_t* end,\n uint32_t length,\n uint32_t distance) {\n uint8_t* ptr = *ptr_ptr;\n start = ptr - distance;\n uint32_t n = length;\n for (; n >= 3; n -= 3) {\n *ptr++ = *start++;\n *ptr++ = *start++;\n *ptr++ = *s" +
|
||||
"tart++;\n }\n for (; n; n--) {\n *ptr++ = *start++;\n }\n *ptr_ptr = ptr;\n return length;\n}\n\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n_from_reader(uint8_t** ptr_ioptr_w,\n uint8_t* iobounds1_w,\n uint32_t length,\n uint8_t** ptr_ioptr_r,\n uint8_t* iobounds1_r) {\n uint8_t* ioptr_w = *ptr_ioptr_w;\n size_t n = length;\n if (n > ((size_t)(iobounds1_w - ioptr_w))) {\n n = iobounds1_w - ioptr_w;\n }\n uint8_t* ioptr_r = *ptr_ioptr_r;\n if (n > ((size_t)(iobounds1_r - ioptr_r))) {\n n = iobounds1_r - ioptr_r;\n }\n if (n > 0) {\n memmove(ioptr_w, ioptr_r, n);\n *ptr_ioptr_w += n;\n *ptr_ioptr_r += n;\n }\n return n;\n}\n\nstatic inline uint64_t //\nwuffs_base__io_writer__copy_from_slice(uint8_t** ptr_ioptr_w,\n uint8_t* iobounds1_w,\n wuffs_base__slice_u8 src" +
|
||||
") {\n uint8_t* ioptr_w = *ptr_ioptr_w;\n size_t n = src.len;\n if (n > ((size_t)(iobounds1_w - ioptr_w))) {\n n = iobounds1_w - ioptr_w;\n }\n if (n > 0) {\n memmove(ioptr_w, src.ptr, n);\n *ptr_ioptr_w += n;\n }\n return n;\n}\n\nstatic inline uint32_t //\nwuffs_base__io_writer__copy_n_from_slice(uint8_t** ptr_ioptr_w,\n uint8_t* iobounds1_w,\n uint32_t length,\n wuffs_base__slice_u8 src) {\n uint8_t* ioptr_w = *ptr_ioptr_w;\n size_t n = src.len;\n if (n > length) {\n n = length;\n }\n if (n > ((size_t)(iobounds1_w - ioptr_w))) {\n n = iobounds1_w - ioptr_w;\n }\n if (n > 0) {\n memmove(ioptr_w, src.ptr, n);\n *ptr_ioptr_w += n;\n }\n return n;\n}\n\nstatic inline wuffs_base__empty_struct //\nwuffs_base__io_reader__set_limit(wuffs_base__io_reader* o,\n uint8_t* ioptr_r,\n uint64_t limit) {\n if (o && (((size_t)(o->private_im" +
|
||||
"pl.limit - ioptr_r)) > limit)) {\n o->private_impl.limit = ioptr_r + limit;\n }\n return ((wuffs_base__empty_struct){});\n}\n\nstatic inline wuffs_base__empty_struct //\nwuffs_base__io_reader__set_mark(wuffs_base__io_reader* o, uint8_t* mark) {\n o->private_impl.mark = mark;\n return ((wuffs_base__empty_struct){});\n}\n\nstatic inline wuffs_base__empty_struct //\nwuffs_base__io_writer__set(wuffs_base__io_writer* o,\n wuffs_base__io_buffer* b,\n uint8_t** ioptr1_ptr,\n uint8_t** ioptr2_ptr,\n wuffs_base__slice_u8 s) {\n b->ptr = s.ptr;\n b->len = s.len;\n b->wi = 0;\n b->ri = 0;\n b->closed = false;\n o->private_impl.buf = b;\n o->private_impl.mark = s.ptr;\n o->private_impl.limit = s.ptr + s.len;\n *ioptr1_ptr = s.ptr;\n *ioptr2_ptr = s.ptr + s.len;\n return ((wuffs_base__empty_struct){});\n}\n\nstatic inline wuffs_base__empty_struct //\nwuffs_base__io_writer__set_mark(wuffs_base__io_writer* o, uint8_t* mark) {\n o->p" +
|
||||
"rivate_impl.mark = mark;\n return ((wuffs_base__empty_struct){});\n}\n\n#ifdef __cplusplus\n} // extern \"C\"\n#endif\n\n#endif // WUFFS_INCLUDE_GUARD__BASE_PRIVATE\n" +
|
||||
""
|
||||
|
||||
const baseBaseImplC = "" +
|
||||
|
||||
@@ -121,20 +121,20 @@ func (g *gen) writeLoadDerivedVar(b *buffer, hack string, prefix string, name t.
|
||||
iopPrefix, preName, preName, preName, i0)
|
||||
|
||||
if header {
|
||||
b.printf("if (!%s.private_impl.bounds[0]) {", preName)
|
||||
b.printf("%s.private_impl.bounds[0] = %s%s;", preName, iopPrefix, preName)
|
||||
b.printf("%s.private_impl.bounds[1] = %s.private_impl.buf->ptr + %s.private_impl.buf->%s;",
|
||||
b.printf("if (!%s.private_impl.mark) {", preName)
|
||||
b.printf("%s.private_impl.mark = %s%s;", preName, iopPrefix, preName)
|
||||
b.printf("%s.private_impl.limit = %s.private_impl.buf->ptr + %s.private_impl.buf->%s;",
|
||||
preName, preName, preName, i1)
|
||||
b.printf("}\n")
|
||||
|
||||
if typ.QID()[1] == t.IDIOWriter {
|
||||
b.printf("if (%s.private_impl.buf->closed) {", preName)
|
||||
b.printf("%s.private_impl.bounds[1] = %s%s;", preName, iopPrefix, preName)
|
||||
b.printf("%s.private_impl.limit = %s%s;", preName, iopPrefix, preName)
|
||||
b.printf("}\n")
|
||||
}
|
||||
|
||||
b.printf("%s%s = %s.private_impl.bounds[0];", io0Prefix, preName, preName)
|
||||
b.printf("%s%s = %s.private_impl.bounds[1];", io1Prefix, preName, preName)
|
||||
b.printf("%s%s = %s.private_impl.mark;", io0Prefix, preName, preName)
|
||||
b.printf("%s%s = %s.private_impl.limit;", io1Prefix, preName, preName)
|
||||
}
|
||||
|
||||
b.printf("}\n")
|
||||
|
||||
Reference in new issue
Block a user