Prepare for implicit io_{reader,writer} bounds

This commit is contained in:
Nigel Tao committed 2018-05-02 15:49:13 +10:00
1 parent 8984662d36
commit 628c283192
15 files changed
+141 -138

No files matched your search

+12 -10
View File
@@ -571,6 +571,9 @@ typedef struct {
// compatibility or safety guarantee if you do so.
struct {
wuffs_base__io_buffer* buf;
// The bounds values are typically NULL, when created by the Wuffs public
// API. NULL means that the callee substitutes the implicit bounds derived
// from buf.
uint8_t* bounds[2];
wuffs_base__io_limit limit;
} private_impl;
@@ -581,6 +584,9 @@ typedef struct {
// compatibility or safety guarantee if you do so.
struct {
wuffs_base__io_buffer* buf;
// The bounds values are typically NULL, when created by the Wuffs public
// API. NULL means that the callee substitutes the implicit bounds derived
// from buf.
uint8_t* bounds[2];
wuffs_base__io_limit limit;
} private_impl;
@@ -589,22 +595,14 @@ typedef struct {
static inline wuffs_base__io_reader wuffs_base__io_buffer__reader(
wuffs_base__io_buffer* buf) {
wuffs_base__io_reader ret = ((wuffs_base__io_reader){});
if (buf) {
ret.private_impl.buf = buf;
ret.private_impl.bounds[0] = buf->ptr + buf->ri;
ret.private_impl.bounds[1] = buf->ptr + buf->wi;
}
ret.private_impl.buf = buf;
return ret;
}
static inline wuffs_base__io_writer wuffs_base__io_buffer__writer(
wuffs_base__io_buffer* buf) {
wuffs_base__io_writer ret = ((wuffs_base__io_writer){});
if (buf) {
ret.private_impl.buf = buf;
ret.private_impl.bounds[0] = buf->ptr + buf->wi;
ret.private_impl.bounds[1] = buf->ptr + buf->len;
}
ret.private_impl.buf = buf;
return ret;
}
@@ -1366,6 +1364,8 @@ static inline bool wuffs_base__io_buffer__is_valid(wuffs_base__io_buffer buf) {
static inline bool wuffs_base__io_reader__is_valid(wuffs_base__io_reader o) {
wuffs_base__io_buffer* buf = o.private_impl.buf;
// Note: if making this function public (i.e. moving it to base-header.h), it
// also needs to allow NULL (i.e. implicit, callee-calculated) bounds.
return buf ? ((buf->ptr <= o.private_impl.bounds[0]) &&
(o.private_impl.bounds[0] <= o.private_impl.bounds[1]) &&
(o.private_impl.bounds[1] <= buf->ptr + buf->len))
@@ -1375,6 +1375,8 @@ static inline bool wuffs_base__io_reader__is_valid(wuffs_base__io_reader o) {
static inline bool wuffs_base__io_writer__is_valid(wuffs_base__io_writer o) {
wuffs_base__io_buffer* buf = o.private_impl.buf;
// Note: if making this function public (i.e. moving it to base-header.h), it
// also needs to allow NULL (i.e. implicit, callee-calculated) bounds.
return buf ? ((buf->ptr <= o.private_impl.bounds[0]) &&
(o.private_impl.bounds[0] <= o.private_impl.bounds[1]) &&
(o.private_impl.bounds[1] <= buf->ptr + buf->len))
+12 -10
View File
@@ -571,6 +571,9 @@ typedef struct {
// compatibility or safety guarantee if you do so.
struct {
wuffs_base__io_buffer* buf;
// The bounds values are typically NULL, when created by the Wuffs public
// API. NULL means that the callee substitutes the implicit bounds derived
// from buf.
uint8_t* bounds[2];
wuffs_base__io_limit limit;
} private_impl;
@@ -581,6 +584,9 @@ typedef struct {
// compatibility or safety guarantee if you do so.
struct {
wuffs_base__io_buffer* buf;
// The bounds values are typically NULL, when created by the Wuffs public
// API. NULL means that the callee substitutes the implicit bounds derived
// from buf.
uint8_t* bounds[2];
wuffs_base__io_limit limit;
} private_impl;
@@ -589,22 +595,14 @@ typedef struct {
static inline wuffs_base__io_reader wuffs_base__io_buffer__reader(
wuffs_base__io_buffer* buf) {
wuffs_base__io_reader ret = ((wuffs_base__io_reader){});
if (buf) {
ret.private_impl.buf = buf;
ret.private_impl.bounds[0] = buf->ptr + buf->ri;
ret.private_impl.bounds[1] = buf->ptr + buf->wi;
}
ret.private_impl.buf = buf;
return ret;
}
static inline wuffs_base__io_writer wuffs_base__io_buffer__writer(
wuffs_base__io_buffer* buf) {
wuffs_base__io_writer ret = ((wuffs_base__io_writer){});
if (buf) {
ret.private_impl.buf = buf;
ret.private_impl.bounds[0] = buf->ptr + buf->wi;
ret.private_impl.bounds[1] = buf->ptr + buf->len;
}
ret.private_impl.buf = buf;
return ret;
}
@@ -1365,6 +1363,8 @@ static inline bool wuffs_base__io_buffer__is_valid(wuffs_base__io_buffer buf) {
static inline bool wuffs_base__io_reader__is_valid(wuffs_base__io_reader o) {
wuffs_base__io_buffer* buf = o.private_impl.buf;
// Note: if making this function public (i.e. moving it to base-header.h), it
// also needs to allow NULL (i.e. implicit, callee-calculated) bounds.
return buf ? ((buf->ptr <= o.private_impl.bounds[0]) &&
(o.private_impl.bounds[0] <= o.private_impl.bounds[1]) &&
(o.private_impl.bounds[1] <= buf->ptr + buf->len))
@@ -1374,6 +1374,8 @@ static inline bool wuffs_base__io_reader__is_valid(wuffs_base__io_reader o) {
static inline bool wuffs_base__io_writer__is_valid(wuffs_base__io_writer o) {
wuffs_base__io_buffer* buf = o.private_impl.buf;
// Note: if making this function public (i.e. moving it to base-header.h), it
// also needs to allow NULL (i.e. implicit, callee-calculated) bounds.
return buf ? ((buf->ptr <= o.private_impl.bounds[0]) &&
(o.private_impl.bounds[0] <= o.private_impl.bounds[1]) &&
(o.private_impl.bounds[1] <= buf->ptr + buf->len))
+12 -10
View File
@@ -571,6 +571,9 @@ typedef struct {
// compatibility or safety guarantee if you do so.
struct {
wuffs_base__io_buffer* buf;
// The bounds values are typically NULL, when created by the Wuffs public
// API. NULL means that the callee substitutes the implicit bounds derived
// from buf.
uint8_t* bounds[2];
wuffs_base__io_limit limit;
} private_impl;
@@ -581,6 +584,9 @@ typedef struct {
// compatibility or safety guarantee if you do so.
struct {
wuffs_base__io_buffer* buf;
// The bounds values are typically NULL, when created by the Wuffs public
// API. NULL means that the callee substitutes the implicit bounds derived
// from buf.
uint8_t* bounds[2];
wuffs_base__io_limit limit;
} private_impl;
@@ -589,22 +595,14 @@ typedef struct {
static inline wuffs_base__io_reader wuffs_base__io_buffer__reader(
wuffs_base__io_buffer* buf) {
wuffs_base__io_reader ret = ((wuffs_base__io_reader){});
if (buf) {
ret.private_impl.buf = buf;
ret.private_impl.bounds[0] = buf->ptr + buf->ri;
ret.private_impl.bounds[1] = buf->ptr + buf->wi;
}
ret.private_impl.buf = buf;
return ret;
}
static inline wuffs_base__io_writer wuffs_base__io_buffer__writer(
wuffs_base__io_buffer* buf) {
wuffs_base__io_writer ret = ((wuffs_base__io_writer){});
if (buf) {
ret.private_impl.buf = buf;
ret.private_impl.bounds[0] = buf->ptr + buf->wi;
ret.private_impl.bounds[1] = buf->ptr + buf->len;
}
ret.private_impl.buf = buf;
return ret;
}
@@ -1457,6 +1455,8 @@ static inline bool wuffs_base__io_buffer__is_valid(wuffs_base__io_buffer buf) {
static inline bool wuffs_base__io_reader__is_valid(wuffs_base__io_reader o) {
wuffs_base__io_buffer* buf = o.private_impl.buf;
// Note: if making this function public (i.e. moving it to base-header.h), it
// also needs to allow NULL (i.e. implicit, callee-calculated) bounds.
return buf ? ((buf->ptr <= o.private_impl.bounds[0]) &&
(o.private_impl.bounds[0] <= o.private_impl.bounds[1]) &&
(o.private_impl.bounds[1] <= buf->ptr + buf->len))
@@ -1466,6 +1466,8 @@ static inline bool wuffs_base__io_reader__is_valid(wuffs_base__io_reader o) {
static inline bool wuffs_base__io_writer__is_valid(wuffs_base__io_writer o) {
wuffs_base__io_buffer* buf = o.private_impl.buf;
// Note: if making this function public (i.e. moving it to base-header.h), it
// also needs to allow NULL (i.e. implicit, callee-calculated) bounds.
return buf ? ((buf->ptr <= o.private_impl.bounds[0]) &&
(o.private_impl.bounds[0] <= o.private_impl.bounds[1]) &&
(o.private_impl.bounds[1] <= buf->ptr + buf->len))
+12 -10
View File
@@ -571,6 +571,9 @@ typedef struct {
// compatibility or safety guarantee if you do so.
struct {
wuffs_base__io_buffer* buf;
// The bounds values are typically NULL, when created by the Wuffs public
// API. NULL means that the callee substitutes the implicit bounds derived
// from buf.
uint8_t* bounds[2];
wuffs_base__io_limit limit;
} private_impl;
@@ -581,6 +584,9 @@ typedef struct {
// compatibility or safety guarantee if you do so.
struct {
wuffs_base__io_buffer* buf;
// The bounds values are typically NULL, when created by the Wuffs public
// API. NULL means that the callee substitutes the implicit bounds derived
// from buf.
uint8_t* bounds[2];
wuffs_base__io_limit limit;
} private_impl;
@@ -589,22 +595,14 @@ typedef struct {
static inline wuffs_base__io_reader wuffs_base__io_buffer__reader(
wuffs_base__io_buffer* buf) {
wuffs_base__io_reader ret = ((wuffs_base__io_reader){});
if (buf) {
ret.private_impl.buf = buf;
ret.private_impl.bounds[0] = buf->ptr + buf->ri;
ret.private_impl.bounds[1] = buf->ptr + buf->wi;
}
ret.private_impl.buf = buf;
return ret;
}
static inline wuffs_base__io_writer wuffs_base__io_buffer__writer(
wuffs_base__io_buffer* buf) {
wuffs_base__io_writer ret = ((wuffs_base__io_writer){});
if (buf) {
ret.private_impl.buf = buf;
ret.private_impl.bounds[0] = buf->ptr + buf->wi;
ret.private_impl.bounds[1] = buf->ptr + buf->len;
}
ret.private_impl.buf = buf;
return ret;
}
@@ -1473,6 +1471,8 @@ static inline bool wuffs_base__io_buffer__is_valid(wuffs_base__io_buffer buf) {
static inline bool wuffs_base__io_reader__is_valid(wuffs_base__io_reader o) {
wuffs_base__io_buffer* buf = o.private_impl.buf;
// Note: if making this function public (i.e. moving it to base-header.h), it
// also needs to allow NULL (i.e. implicit, callee-calculated) bounds.
return buf ? ((buf->ptr <= o.private_impl.bounds[0]) &&
(o.private_impl.bounds[0] <= o.private_impl.bounds[1]) &&
(o.private_impl.bounds[1] <= buf->ptr + buf->len))
@@ -1482,6 +1482,8 @@ static inline bool wuffs_base__io_reader__is_valid(wuffs_base__io_reader o) {
static inline bool wuffs_base__io_writer__is_valid(wuffs_base__io_writer o) {
wuffs_base__io_buffer* buf = o.private_impl.buf;
// Note: if making this function public (i.e. moving it to base-header.h), it
// also needs to allow NULL (i.e. implicit, callee-calculated) bounds.
return buf ? ((buf->ptr <= o.private_impl.bounds[0]) &&
(o.private_impl.bounds[0] <= o.private_impl.bounds[1]) &&
(o.private_impl.bounds[1] <= buf->ptr + buf->len))
+12 -10
View File
@@ -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))
+12 -10
View File
@@ -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))