mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 08:55:11 +01:00
Change cgen's limit from a count to a pointer.
This commit is contained in:
1 parent
3485950a3f
commit
aa396e7992
12 files changed
+298
-278
No files matched your search
@@ -274,37 +274,65 @@ static inline uint32_t puffs_base__writer1__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 Puffs code, the reader1 and writer1's private_impl fields (including
|
||||
// limit and mark) are NULL. Otherwise, some internal assumptions break down.
|
||||
// For example, the limit field is represented as a pointer, even though
|
||||
// conceptually it is a count, but that pointer-to-count correspondence becomes
|
||||
// invalid if a buffer is re-used (e.g. on resuming a coroutine).
|
||||
//
|
||||
// Admittedly, some of the Puffs test code calls these methods, but that test
|
||||
// code is still Puffs code, not user code. Other Puffs test code modifies
|
||||
// private_impl fields directly.
|
||||
|
||||
static inline puffs_base__empty_struct puffs_base__reader1__limit(
|
||||
puffs_base__reader1* r,
|
||||
puffs_base__reader1* o,
|
||||
uint8_t* ptr,
|
||||
uint64_t limit) {
|
||||
if (!r->use_limitt || (r->limitt > limit)) {
|
||||
r->limitt = limit;
|
||||
r->use_limitt = true;
|
||||
if (!o->buf) {
|
||||
o->private_impl.limit = NULL;
|
||||
} else {
|
||||
uint64_t len = o->buf->wi - o->buf->ri;
|
||||
if (limit > len) {
|
||||
limit = len;
|
||||
}
|
||||
if (!o->private_impl.limit || (limit < (o->private_impl.limit - ptr))) {
|
||||
o->private_impl.limit = ptr + limit;
|
||||
}
|
||||
}
|
||||
return ((puffs_base__empty_struct){});
|
||||
}
|
||||
|
||||
static inline puffs_base__empty_struct puffs_base__reader1__mark(
|
||||
puffs_base__reader1* r,
|
||||
puffs_base__reader1* o,
|
||||
uint8_t* mark) {
|
||||
r->private_impl.mark = mark;
|
||||
o->private_impl.mark = mark;
|
||||
return ((puffs_base__empty_struct){});
|
||||
}
|
||||
|
||||
static inline puffs_base__empty_struct puffs_base__writer1__limit(
|
||||
puffs_base__writer1* w,
|
||||
puffs_base__writer1* o,
|
||||
uint8_t* ptr,
|
||||
uint64_t limit) {
|
||||
if (!w->use_limitt || (w->limitt > limit)) {
|
||||
w->limitt = limit;
|
||||
w->use_limitt = true;
|
||||
if (!o->buf) {
|
||||
o->private_impl.limit = NULL;
|
||||
} else {
|
||||
uint64_t len = o->buf->len - o->buf->wi;
|
||||
if (limit > len) {
|
||||
limit = len;
|
||||
}
|
||||
if (!o->private_impl.limit || (limit < (o->private_impl.limit - ptr))) {
|
||||
o->private_impl.limit = ptr + limit;
|
||||
}
|
||||
}
|
||||
return ((puffs_base__empty_struct){});
|
||||
}
|
||||
|
||||
static inline puffs_base__empty_struct puffs_base__writer1__mark(
|
||||
puffs_base__writer1* w,
|
||||
puffs_base__writer1* o,
|
||||
uint8_t* mark) {
|
||||
w->private_impl.mark = mark;
|
||||
o->private_impl.mark = mark;
|
||||
return ((puffs_base__empty_struct){});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user