base: rename history_retain_length

It was renamed to dst_history_retain_length.

It also was removed from image_decoders and token_decoders. It only
applies to io_transformers, as retaining history applies to the
destination (not source) IO buffer.

Also adjust example/bzcat and example/zcat to apply the history retain
length to the dst (not src) buffer.
This commit is contained in:
Nigel Tao committed 2023-12-17 12:26:08 +11:00
1 parent b4e09690a7
commit eed1af7bee
34 files changed
+179 -640

No files matched your search

+6 -6
View File
@@ -108,7 +108,7 @@ Input::BringsItsOwnIOBuffer() {
FileInput::FileInput(FILE* f) : m_f(f) {}
std::string //
FileInput::CopyIn(IOBuffer* dst, uint64_t history_retain_length) {
FileInput::CopyIn(IOBuffer* dst) {
if (!m_f) {
return "wuffs_aux::sync_io::FileInput: nullptr file";
} else if (!dst) {
@@ -116,7 +116,7 @@ FileInput::CopyIn(IOBuffer* dst, uint64_t history_retain_length) {
} else if (dst->meta.closed) {
return "wuffs_aux::sync_io::FileInput: end of file";
} else {
dst->compact_retaining(history_retain_length);
dst->compact();
size_t n = fread(dst->writer_pointer(), 1, dst->writer_length(), m_f);
dst->meta.wi += n;
dst->meta.closed = feof(m_f);
@@ -144,7 +144,7 @@ MemoryInput::BringsItsOwnIOBuffer() {
}
std::string //
MemoryInput::CopyIn(IOBuffer* dst, uint64_t history_retain_length) {
MemoryInput::CopyIn(IOBuffer* dst) {
if (!dst) {
return "wuffs_aux::sync_io::MemoryInput: nullptr IOBuffer";
} else if (dst->meta.closed) {
@@ -154,7 +154,7 @@ MemoryInput::CopyIn(IOBuffer* dst, uint64_t history_retain_length) {
// to it.
return "wuffs_aux::sync_io::MemoryInput: overlapping buffers";
} else {
dst->compact_retaining(history_retain_length);
dst->compact();
size_t nd = dst->writer_length();
size_t ns = m_io.reader_length();
size_t n = (nd < ns) ? nd : ns;
@@ -209,7 +209,7 @@ AdvanceIOBufferTo(const ErrorMessages& error_messages,
if (!input.BringsItsOwnIOBuffer()) {
io_buf.compact();
}
std::string error_message = input.CopyIn(&io_buf, 0);
std::string error_message = input.CopyIn(&io_buf);
if (!error_message.empty()) {
return error_message;
}
@@ -292,7 +292,7 @@ HandleMetadata(
} else if (!input.BringsItsOwnIOBuffer()) {
io_buf.compact();
}
std::string error_message = input.CopyIn(&io_buf, 0);
std::string error_message = input.CopyIn(&io_buf);
if (!error_message.empty()) {
return error_message;
}
+3 -3
View File
@@ -96,7 +96,7 @@ class Input {
virtual ~Input();
virtual IOBuffer* BringsItsOwnIOBuffer();
virtual std::string CopyIn(IOBuffer* dst, uint64_t history_retain_length) = 0;
virtual std::string CopyIn(IOBuffer* dst) = 0;
};
// --------
@@ -108,7 +108,7 @@ class FileInput : public Input {
public:
FileInput(FILE* f);
virtual std::string CopyIn(IOBuffer* dst, uint64_t history_retain_length);
virtual std::string CopyIn(IOBuffer* dst);
private:
FILE* m_f;
@@ -129,7 +129,7 @@ class MemoryInput : public Input {
MemoryInput(const uint8_t* ptr, size_t len);
virtual IOBuffer* BringsItsOwnIOBuffer();
virtual std::string CopyIn(IOBuffer* dst, uint64_t history_retain_length);
virtual std::string CopyIn(IOBuffer* dst);
private:
IOBuffer m_io;
+2 -4
View File
@@ -111,16 +111,14 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
"wuffs_aux::DecodeCbor: internal error: io_buf is closed";
goto done;
}
io_buf->compact_retaining(
dec->history_retain_length().value_or(UINT64_MAX));
io_buf->compact();
if (io_buf->meta.wi >= io_buf->data.len) {
ret_error_message =
"wuffs_aux::DecodeCbor: internal error: io_buf is full";
goto done;
}
cursor_index = io_buf->meta.ri;
io_error_message = input.CopyIn(
io_buf, dec->history_retain_length().value_or(UINT64_MAX));
io_error_message = input.CopyIn(io_buf);
} else {
ret_error_message = tok_status.message();
goto done;
+5 -11
View File
@@ -340,7 +340,7 @@ redirect:
fourcc = 0;
break;
}
std::string error_message = input.CopyIn(&io_buf, 0);
std::string error_message = input.CopyIn(&io_buf);
if (!error_message.empty()) {
return DecodeImageResult(std::move(error_message));
}
@@ -436,9 +436,7 @@ redirect:
} else if (io_buf.meta.closed) {
return DecodeImageResult(DecodeImage_UnexpectedEndOfFile);
} else {
std::string error_message = input.CopyIn(
&io_buf,
image_decoder->history_retain_length().value_or(UINT64_MAX));
std::string error_message = input.CopyIn(&io_buf);
if (!error_message.empty()) {
return DecodeImageResult(std::move(error_message));
}
@@ -520,8 +518,7 @@ redirect:
} else if (io_buf.meta.closed) {
return DecodeImageResult(DecodeImage_UnexpectedEndOfFile);
} else {
std::string error_message = input.CopyIn(
&io_buf, image_decoder->history_retain_length().value_or(UINT64_MAX));
std::string error_message = input.CopyIn(&io_buf);
if (!error_message.empty()) {
return DecodeImageResult(std::move(error_message));
}
@@ -550,8 +547,7 @@ redirect:
message = DecodeImage_UnexpectedEndOfFile;
break;
} else {
std::string error_message = input.CopyIn(
&io_buf, image_decoder->history_retain_length().value_or(UINT64_MAX));
std::string error_message = input.CopyIn(&io_buf);
if (!error_message.empty()) {
message = std::move(error_message);
break;
@@ -579,9 +575,7 @@ redirect:
} else if (io_buf.meta.closed) {
return DecodeImageResult(DecodeImage_UnexpectedEndOfFile);
} else {
std::string error_message = input.CopyIn(
&io_buf,
image_decoder->history_retain_length().value_or(UINT64_MAX));
std::string error_message = input.CopyIn(&io_buf);
if (!error_message.empty()) {
return DecodeImageResult(std::move(error_message));
}
+2 -4
View File
@@ -73,16 +73,14 @@ DecodeJsonArgJsonPointer::DefaultValue() {
"wuffs_aux::DecodeJson: internal error: io_buf is closed"; \
goto done; \
} \
io_buf->compact_retaining( \
dec->history_retain_length().value_or(UINT64_MAX)); \
io_buf->compact(); \
if (io_buf->meta.wi >= io_buf->data.len) { \
ret_error_message = \
"wuffs_aux::DecodeJson: internal error: io_buf is full"; \
goto done; \
} \
cursor_index = io_buf->meta.ri; \
io_error_message = input.CopyIn( \
io_buf, dec->history_retain_length().value_or(UINT64_MAX)); \
io_error_message = input.CopyIn(io_buf); \
} else { \
ret_error_message = tok_status.message(); \
goto done; \