mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 16:55:11 +01:00
Prepare for implicit io_{reader,writer} bounds
This commit is contained in:
1 parent
8984662d36
commit
628c283192
15 files changed
+141
-138
No files matched your search
+12
-10
@@ -571,6 +571,9 @@ typedef struct {
|
||||
// compatibility or safety guarantee if you do so.
|
||||
struct {
|
||||
wuffs_base__io_buffer* buf;
|
||||
// The bounds values are typically NULL, when created by the Wuffs public
|
||||
// API. NULL means that the callee substitutes the implicit bounds derived
|
||||
// from buf.
|
||||
uint8_t* bounds[2];
|
||||
wuffs_base__io_limit limit;
|
||||
} private_impl;
|
||||
@@ -581,6 +584,9 @@ typedef struct {
|
||||
// compatibility or safety guarantee if you do so.
|
||||
struct {
|
||||
wuffs_base__io_buffer* buf;
|
||||
// The bounds values are typically NULL, when created by the Wuffs public
|
||||
// API. NULL means that the callee substitutes the implicit bounds derived
|
||||
// from buf.
|
||||
uint8_t* bounds[2];
|
||||
wuffs_base__io_limit limit;
|
||||
} private_impl;
|
||||
@@ -589,22 +595,14 @@ typedef struct {
|
||||
static inline wuffs_base__io_reader wuffs_base__io_buffer__reader(
|
||||
wuffs_base__io_buffer* buf) {
|
||||
wuffs_base__io_reader ret = ((wuffs_base__io_reader){});
|
||||
if (buf) {
|
||||
ret.private_impl.buf = buf;
|
||||
ret.private_impl.bounds[0] = buf->ptr + buf->ri;
|
||||
ret.private_impl.bounds[1] = buf->ptr + buf->wi;
|
||||
}
|
||||
ret.private_impl.buf = buf;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline wuffs_base__io_writer wuffs_base__io_buffer__writer(
|
||||
wuffs_base__io_buffer* buf) {
|
||||
wuffs_base__io_writer ret = ((wuffs_base__io_writer){});
|
||||
if (buf) {
|
||||
ret.private_impl.buf = buf;
|
||||
ret.private_impl.bounds[0] = buf->ptr + buf->wi;
|
||||
ret.private_impl.bounds[1] = buf->ptr + buf->len;
|
||||
}
|
||||
ret.private_impl.buf = buf;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1661,6 +1659,8 @@ static inline bool wuffs_base__io_buffer__is_valid(wuffs_base__io_buffer buf) {
|
||||
|
||||
static inline bool wuffs_base__io_reader__is_valid(wuffs_base__io_reader o) {
|
||||
wuffs_base__io_buffer* buf = o.private_impl.buf;
|
||||
// Note: if making this function public (i.e. moving it to base-header.h), it
|
||||
// also needs to allow NULL (i.e. implicit, callee-calculated) bounds.
|
||||
return buf ? ((buf->ptr <= o.private_impl.bounds[0]) &&
|
||||
(o.private_impl.bounds[0] <= o.private_impl.bounds[1]) &&
|
||||
(o.private_impl.bounds[1] <= buf->ptr + buf->len))
|
||||
@@ -1670,6 +1670,8 @@ static inline bool wuffs_base__io_reader__is_valid(wuffs_base__io_reader o) {
|
||||
|
||||
static inline bool wuffs_base__io_writer__is_valid(wuffs_base__io_writer o) {
|
||||
wuffs_base__io_buffer* buf = o.private_impl.buf;
|
||||
// Note: if making this function public (i.e. moving it to base-header.h), it
|
||||
// also needs to allow NULL (i.e. implicit, callee-calculated) bounds.
|
||||
return buf ? ((buf->ptr <= o.private_impl.bounds[0]) &&
|
||||
(o.private_impl.bounds[0] <= o.private_impl.bounds[1]) &&
|
||||
(o.private_impl.bounds[1] <= buf->ptr + buf->len))
|
||||
|
||||
Reference in new issue
Block a user