mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-23 16:52:18 +01:00
Rename buf1, reader1, etc to io_buffer, io_reader
Also remove the unused Buf1, Buf2 and Usize tokens.
This commit is contained in:
1 parent
82a48796c8
commit
97aab37462
46 files changed
+823
-847
No files matched your search
+45
-47
@@ -99,9 +99,7 @@ typedef struct {
|
||||
|
||||
// ---------------- I/O
|
||||
|
||||
// TODO: rename buf1 to io_buffer, writer1 to io_writer, etc.
|
||||
|
||||
// wuffs_base__buf1 is a 1-dimensional buffer (a pointer and length), plus
|
||||
// wuffs_base__io_buffer is a 1-dimensional buffer (a pointer and length), plus
|
||||
// additional indexes into that buffer, plus an opened / closed flag.
|
||||
//
|
||||
// A value with all fields NULL or zero is a valid, empty buffer.
|
||||
@@ -111,44 +109,44 @@ typedef struct {
|
||||
size_t wi; // Write index. Invariant: wi <= len.
|
||||
size_t ri; // Read index. Invariant: ri <= wi.
|
||||
bool closed; // No further writes are expected.
|
||||
} wuffs_base__buf1;
|
||||
} wuffs_base__io_buffer;
|
||||
|
||||
// wuffs_base__limit1 provides a limited view of a 1-dimensional byte stream:
|
||||
// wuffs_base__io_limit provides a limited view of a 1-dimensional byte stream:
|
||||
// its first N bytes. That N can be greater than a buffer's current read or
|
||||
// write capacity. N decreases naturally over time as bytes are read from or
|
||||
// written to the stream.
|
||||
//
|
||||
// A value with all fields NULL or zero is a valid, unlimited view.
|
||||
typedef struct wuffs_base__limit1 {
|
||||
uint64_t* ptr_to_len; // Pointer to N.
|
||||
struct wuffs_base__limit1* next; // Linked list of limits.
|
||||
} wuffs_base__limit1;
|
||||
typedef struct wuffs_base__io_limit {
|
||||
uint64_t* ptr_to_len; // Pointer to N.
|
||||
struct wuffs_base__io_limit* next; // Linked list of limits.
|
||||
} wuffs_base__io_limit;
|
||||
|
||||
typedef struct {
|
||||
// TODO: move buf into private_impl? As it is, it looks like users can modify
|
||||
// the buf field to point to a different buffer, which can turn the limit and
|
||||
// mark fields into dangling pointers.
|
||||
wuffs_base__buf1* buf;
|
||||
wuffs_base__io_buffer* buf;
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
// compatibility or safety guarantee if you do so.
|
||||
struct {
|
||||
wuffs_base__limit1 limit;
|
||||
wuffs_base__io_limit limit;
|
||||
uint8_t* mark;
|
||||
} private_impl;
|
||||
} wuffs_base__reader1;
|
||||
} wuffs_base__io_reader;
|
||||
|
||||
typedef struct {
|
||||
// TODO: move buf into private_impl? As it is, it looks like users can modify
|
||||
// the buf field to point to a different buffer, which can turn the limit and
|
||||
// mark fields into dangling pointers.
|
||||
wuffs_base__buf1* buf;
|
||||
wuffs_base__io_buffer* buf;
|
||||
// Do not access the private_impl's fields directly. There is no API/ABI
|
||||
// compatibility or safety guarantee if you do so.
|
||||
struct {
|
||||
wuffs_base__limit1 limit;
|
||||
wuffs_base__io_limit limit;
|
||||
uint8_t* mark;
|
||||
} private_impl;
|
||||
} wuffs_base__writer1;
|
||||
} wuffs_base__io_writer;
|
||||
|
||||
// ---------------- Images
|
||||
|
||||
@@ -749,8 +747,8 @@ void wuffs_deflate__decoder__initialize(wuffs_deflate__decoder* self,
|
||||
|
||||
wuffs_deflate__status wuffs_deflate__decoder__decode(
|
||||
wuffs_deflate__decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src);
|
||||
wuffs_base__io_writer a_dst,
|
||||
wuffs_base__io_reader a_src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
@@ -870,8 +868,8 @@ void wuffs_zlib__decoder__set_ignore_checksum(wuffs_zlib__decoder* self,
|
||||
bool a_ic);
|
||||
|
||||
wuffs_zlib__status wuffs_zlib__decoder__decode(wuffs_zlib__decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src);
|
||||
wuffs_base__io_writer a_dst,
|
||||
wuffs_base__io_reader a_src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
@@ -1070,9 +1068,9 @@ static inline uint64_t wuffs_base__slice_u8__copy_from_slice(
|
||||
return length;
|
||||
}
|
||||
|
||||
static inline uint32_t wuffs_base__writer1__copy_from_history32(
|
||||
static inline uint32_t wuffs_base__io_writer__copy_from_history32(
|
||||
uint8_t** ptr_ptr,
|
||||
uint8_t* start, // May be NULL, meaning an unmarked writer1.
|
||||
uint8_t* start, // May be NULL, meaning an unmarked io_writer.
|
||||
uint8_t* end,
|
||||
uint32_t distance,
|
||||
uint32_t length) {
|
||||
@@ -1096,7 +1094,7 @@ static inline uint32_t wuffs_base__writer1__copy_from_history32(
|
||||
// copy_from_history32 Wuffs method should also take an unroll hint argument,
|
||||
// and the cgen can look if that argument is the constant expression '3'.
|
||||
//
|
||||
// See also wuffs_base__writer1__copy_from_history32__bco below.
|
||||
// See also wuffs_base__io_writer__copy_from_history32__bco below.
|
||||
//
|
||||
// Alternatively, or additionally, have a sloppy_copy_from_history32 method
|
||||
// that copies 8 bytes at a time, possibly writing more than length bytes?
|
||||
@@ -1112,14 +1110,14 @@ static inline uint32_t wuffs_base__writer1__copy_from_history32(
|
||||
return length;
|
||||
}
|
||||
|
||||
// wuffs_base__writer1__copy_from_history32__bco is a Bounds Check Optimized
|
||||
// version of the wuffs_base__writer1__copy_from_history32 function above. The
|
||||
// caller needs to prove that:
|
||||
// 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)
|
||||
static inline uint32_t wuffs_base__writer1__copy_from_history32__bco(
|
||||
static inline uint32_t wuffs_base__io_writer__copy_from_history32__bco(
|
||||
uint8_t** ptr_ptr,
|
||||
uint8_t* start,
|
||||
uint8_t* end,
|
||||
@@ -1140,7 +1138,7 @@ static inline uint32_t wuffs_base__writer1__copy_from_history32__bco(
|
||||
return length;
|
||||
}
|
||||
|
||||
static inline uint32_t wuffs_base__writer1__copy_from_reader32(
|
||||
static inline uint32_t wuffs_base__io_writer__copy_from_reader32(
|
||||
uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
uint8_t** ptr_rptr,
|
||||
@@ -1163,7 +1161,7 @@ static inline uint32_t wuffs_base__writer1__copy_from_reader32(
|
||||
return n;
|
||||
}
|
||||
|
||||
static inline uint64_t wuffs_base__writer1__copy_from_slice(
|
||||
static inline uint64_t wuffs_base__io_writer__copy_from_slice(
|
||||
uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
wuffs_base__slice_u8 src) {
|
||||
@@ -1179,7 +1177,7 @@ static inline uint64_t wuffs_base__writer1__copy_from_slice(
|
||||
return n;
|
||||
}
|
||||
|
||||
static inline uint32_t wuffs_base__writer1__copy_from_slice32(
|
||||
static inline uint32_t wuffs_base__io_writer__copy_from_slice32(
|
||||
uint8_t** ptr_wptr,
|
||||
uint8_t* wend,
|
||||
wuffs_base__slice_u8 src,
|
||||
@@ -1201,7 +1199,7 @@ static inline uint32_t wuffs_base__writer1__copy_from_slice32(
|
||||
|
||||
// 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 reader1 and writer1's private_impl fields (including
|
||||
// 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
|
||||
@@ -1211,26 +1209,26 @@ static inline uint32_t wuffs_base__writer1__copy_from_slice32(
|
||||
// code is still Wuffs code, not user code. Other Wuffs test code modifies
|
||||
// private_impl fields directly.
|
||||
|
||||
static inline wuffs_base__reader1 wuffs_base__reader1__limit(
|
||||
wuffs_base__reader1* o,
|
||||
static inline wuffs_base__io_reader wuffs_base__io_reader__limit(
|
||||
wuffs_base__io_reader* o,
|
||||
uint64_t* ptr_to_len) {
|
||||
wuffs_base__reader1 ret = *o;
|
||||
wuffs_base__io_reader ret = *o;
|
||||
ret.private_impl.limit.ptr_to_len = ptr_to_len;
|
||||
ret.private_impl.limit.next = &o->private_impl.limit;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline wuffs_base__empty_struct wuffs_base__reader1__mark(
|
||||
wuffs_base__reader1* o,
|
||||
static inline wuffs_base__empty_struct wuffs_base__io_reader__mark(
|
||||
wuffs_base__io_reader* o,
|
||||
uint8_t* mark) {
|
||||
o->private_impl.mark = mark;
|
||||
return ((wuffs_base__empty_struct){});
|
||||
}
|
||||
|
||||
// TODO: static inline wuffs_base__writer1 wuffs_base__writer1__limit()
|
||||
// TODO: static inline wuffs_base__io_writer wuffs_base__io_writer__limit()
|
||||
|
||||
static inline wuffs_base__empty_struct wuffs_base__writer1__mark(
|
||||
wuffs_base__writer1* o,
|
||||
static inline wuffs_base__empty_struct wuffs_base__io_writer__mark(
|
||||
wuffs_base__io_writer* o,
|
||||
uint8_t* mark) {
|
||||
o->private_impl.mark = mark;
|
||||
return ((wuffs_base__empty_struct){});
|
||||
@@ -1357,8 +1355,8 @@ void wuffs_zlib__decoder__set_ignore_checksum(wuffs_zlib__decoder* self,
|
||||
}
|
||||
|
||||
wuffs_zlib__status wuffs_zlib__decoder__decode(wuffs_zlib__decoder* self,
|
||||
wuffs_base__writer1 a_dst,
|
||||
wuffs_base__reader1 a_src) {
|
||||
wuffs_base__io_writer a_dst,
|
||||
wuffs_base__io_reader a_src) {
|
||||
if (!self) {
|
||||
return WUFFS_ZLIB__ERROR_BAD_RECEIVER;
|
||||
}
|
||||
@@ -1384,7 +1382,7 @@ wuffs_zlib__status wuffs_zlib__decoder__decode(wuffs_zlib__decoder* self,
|
||||
b_wend_dst = b_wptr_dst;
|
||||
if (!a_dst.buf->closed) {
|
||||
uint64_t len = a_dst.buf->len - a_dst.buf->wi;
|
||||
wuffs_base__limit1* lim;
|
||||
wuffs_base__io_limit* lim;
|
||||
for (lim = &a_dst.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -1400,7 +1398,7 @@ wuffs_zlib__status wuffs_zlib__decoder__decode(wuffs_zlib__decoder* self,
|
||||
b_rptr_src = a_src.buf->ptr + a_src.buf->ri;
|
||||
b_rstart_src = b_rptr_src;
|
||||
uint64_t len = a_src.buf->wi - a_src.buf->ri;
|
||||
wuffs_base__limit1* lim;
|
||||
wuffs_base__io_limit* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len && (len > *lim->ptr_to_len)) {
|
||||
len = *lim->ptr_to_len;
|
||||
@@ -1466,13 +1464,13 @@ wuffs_zlib__status wuffs_zlib__decoder__decode(wuffs_zlib__decoder* self,
|
||||
}
|
||||
v_checksum_got = 0;
|
||||
while (true) {
|
||||
wuffs_base__writer1__mark(&a_dst, b_wptr_dst);
|
||||
wuffs_base__io_writer__mark(&a_dst, b_wptr_dst);
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(3);
|
||||
if (a_dst.buf) {
|
||||
size_t n = b_wptr_dst - (a_dst.buf->ptr + a_dst.buf->wi);
|
||||
a_dst.buf->wi += n;
|
||||
wuffs_base__limit1* lim;
|
||||
wuffs_base__io_limit* lim;
|
||||
for (lim = &a_dst.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
@@ -1482,7 +1480,7 @@ wuffs_zlib__status wuffs_zlib__decoder__decode(wuffs_zlib__decoder* self,
|
||||
if (a_src.buf) {
|
||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||
a_src.buf->ri += n;
|
||||
wuffs_base__limit1* lim;
|
||||
wuffs_base__io_limit* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
@@ -1569,7 +1567,7 @@ exit:
|
||||
if (a_dst.buf) {
|
||||
size_t n = b_wptr_dst - (a_dst.buf->ptr + a_dst.buf->wi);
|
||||
a_dst.buf->wi += n;
|
||||
wuffs_base__limit1* lim;
|
||||
wuffs_base__io_limit* lim;
|
||||
for (lim = &a_dst.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
@@ -1581,7 +1579,7 @@ exit:
|
||||
if (a_src.buf) {
|
||||
size_t n = b_rptr_src - (a_src.buf->ptr + a_src.buf->ri);
|
||||
a_src.buf->ri += n;
|
||||
wuffs_base__limit1* lim;
|
||||
wuffs_base__io_limit* lim;
|
||||
for (lim = &a_src.private_impl.limit; lim; lim = lim->next) {
|
||||
if (lim->ptr_to_len) {
|
||||
*lim->ptr_to_len -= n;
|
||||
|
||||
Reference in new issue
Block a user