Skip to content

Commit eed1af7

Browse files
committed
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.
1 parent b4e0969 commit eed1af7

34 files changed

+166
-627
lines changed

doc/changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The LICENSE has changed from a single license (Apache 2) to a dual license
1010
- Added `base.optional_u63`.
1111
- Added `base.hasher_bitvec256`.
1212
- Added `base.hasher_u64`.
13-
- Added `compact_retaining` and `history_retain_length`.
13+
- Added `compact_retaining` and `dst_history_retain_length`.
1414
- Added `example/toy-aux-image`.
1515
- Added `get_quirk(key: u32) u64`.
1616
- Added `hasher_u32` `update!` and `checksum_u32` methods.

doc/std/compression-decoders.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ APIs](https://github.com/google/wuffs/issues/73), after Wuffs v0.2 is released.
2525

2626
In Wuffs syntax, the `base.io_transformer` methods are:
2727

28+
- `dst_history_retain_length() u64`
2829
- `get_quirk(key: u32) u64`
29-
- `history_retain_length() u64`
3030
- `set_quirk!(key: u32, value: u64) status`
3131
- `transform_io?(dst: io_writer, src: io_reader, workbuf: slice u8)`
3232
- `workbuf_len() range_ii_u64`

doc/std/image-decoders.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ In Wuffs syntax, the `base.image_decoder` methods are:
111111
- `decode_image_config?(dst: nptr image_config, src: io_reader)`
112112
- `frame_dirty_rect() rect_ie_u32`
113113
- `get_quirk(key: u32) u64`
114-
- `history_retain_length() u64`
115114
- `num_animation_loops() u32`
116115
- `num_decoded_frame_configs() u64`
117116
- `num_decoded_frames() u64`

example/bzcat/bzcat.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,20 @@ main1(int argc, char** argv) {
191191
wuffs_base__make_slice_u8(g_work_buffer_array,
192192
WORK_BUFFER_ARRAY_SIZE));
193193

194-
if (dst.meta.wi) {
194+
if (dst.meta.ri < dst.meta.wi) {
195195
// TODO: handle EINTR and other write errors; see "man 2 write".
196196
const int stdout_fd = 1;
197-
ignore_return_value(write(stdout_fd, g_dst_buffer_array, dst.meta.wi));
197+
ignore_return_value(write(stdout_fd, g_dst_buffer_array + dst.meta.ri,
198+
dst.meta.wi - dst.meta.ri));
198199
dst.meta.ri = dst.meta.wi;
199-
wuffs_base__io_buffer__compact(&dst);
200+
201+
wuffs_base__optional_u63 hrl =
202+
wuffs_bzip2__decoder__dst_history_retain_length(&dec);
203+
wuffs_base__io_buffer__compact_retaining(
204+
&dst, wuffs_base__optional_u63__value_or(&hrl, UINT64_MAX));
205+
if (dst.meta.wi == dst.data.len) {
206+
return "main: unsupported history length (a.k.a. dictionary size)";
207+
}
200208
}
201209

202210
if (status.repr == wuffs_base__suspension__short_read) {
@@ -208,13 +216,7 @@ main1(int argc, char** argv) {
208216
return wuffs_base__status__message(&status);
209217
}
210218

211-
wuffs_base__optional_u63 hrl =
212-
wuffs_bzip2__decoder__history_retain_length(&dec);
213-
wuffs_base__io_buffer__compact_retaining(
214-
&src, wuffs_base__optional_u63__value_or(&hrl, UINT64_MAX));
215-
if (src.meta.wi == src.data.len) {
216-
return "main: internal error: no I/O progress possible";
217-
}
219+
wuffs_base__io_buffer__compact(&src);
218220
}
219221
}
220222

example/convert-to-nia/convert-to-nia.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,11 @@ static void //
251251
ignore_return_value(int ignored) {}
252252

253253
const char* //
254-
read_more_src(wuffs_base__optional_u63 history_retain_length) {
254+
read_more_src() {
255255
if (g_src.meta.closed) {
256256
return "main: unexpected end of file";
257257
}
258-
if (wuffs_base__optional_u63__has_value(&history_retain_length)) {
259-
wuffs_base__io_buffer__compact_retaining(
260-
&g_src, wuffs_base__optional_u63__value(&history_retain_length));
261-
}
258+
wuffs_base__io_buffer__compact(&g_src);
262259
if (g_src.meta.wi == g_src.data.len) {
263260
return "main: internal error: no I/O progress possible";
264261
}
@@ -287,7 +284,7 @@ load_image_type() {
287284
(wuffs_base__io_buffer__reader_length(&g_src) == g_src.data.len)) {
288285
break;
289286
}
290-
TRY(read_more_src(wuffs_base__make_optional_u63(true, 0)));
287+
TRY(read_more_src());
291288
}
292289
return NULL;
293290
}
@@ -412,7 +409,7 @@ advance_for_redirect() {
412409
break;
413410
}
414411
g_src.meta.ri = g_src.meta.wi;
415-
TRY(read_more_src(wuffs_base__make_optional_u63(true, 0)));
412+
TRY(read_more_src());
416413
}
417414
return NULL;
418415
}
@@ -439,8 +436,7 @@ load_image_config() {
439436
} else if (status.repr != wuffs_base__suspension__short_read) {
440437
return wuffs_base__status__message(&status);
441438
}
442-
TRY(read_more_src(
443-
wuffs_base__image_decoder__history_retain_length(g_image_decoder)));
439+
TRY(read_more_src());
444440
}
445441

446442
// Read the dimensions.
@@ -639,8 +635,7 @@ convert_frames() {
639635
} else if (dfc_status.repr != wuffs_base__suspension__short_read) {
640636
return wuffs_base__status__message(&dfc_status);
641637
}
642-
TRY(read_more_src(
643-
wuffs_base__image_decoder__history_retain_length(g_image_decoder)));
638+
TRY(read_more_src());
644639
}
645640

646641
wuffs_base__flicks duration =
@@ -682,8 +677,7 @@ convert_frames() {
682677
if (df_status.repr != wuffs_base__suspension__short_read) {
683678
break;
684679
}
685-
decode_frame_io_error_message = read_more_src(
686-
wuffs_base__image_decoder__history_retain_length(g_image_decoder));
680+
decode_frame_io_error_message = read_more_src();
687681
if (decode_frame_io_error_message != NULL) {
688682
// Neuter the "short read" df_status so that convert_frames returns the
689683
// I/O error message instead.

example/jsonptr/jsonptr.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -997,11 +997,11 @@ static void //
997997
ignore_return_value(int ignored) {}
998998

999999
const char* //
1000-
read_src(uint64_t history_retain_length) {
1000+
read_src() {
10011001
if (g_src.meta.closed) {
10021002
return "main: internal error: read requested on a closed source";
10031003
}
1004-
g_src.compact_retaining(history_retain_length);
1004+
g_src.compact();
10051005
if (g_src.meta.wi >= g_src.data.len) {
10061006
return "main: g_src buffer is full";
10071007
}
@@ -1394,7 +1394,7 @@ main1(int argc, char** argv) {
13941394
}
13951395
// Check that we've exhausted the input.
13961396
if ((g_src.meta.ri == g_src.meta.wi) && !g_src.meta.closed) {
1397-
TRY(read_src(g_dec.history_retain_length().value_or(UINT64_MAX)));
1397+
TRY(read_src());
13981398
}
13991399
if ((g_src.meta.ri < g_src.meta.wi) || !g_src.meta.closed) {
14001400
return "main: valid JSON followed by further (unexpected) data";
@@ -1405,7 +1405,7 @@ main1(int argc, char** argv) {
14051405
if (g_cursor_index != g_src.meta.ri) {
14061406
return "main: internal error: inconsistent g_src indexes";
14071407
}
1408-
TRY(read_src(g_dec.history_retain_length().value_or(UINT64_MAX)));
1408+
TRY(read_src());
14091409
g_cursor_index = g_src.meta.ri;
14101410
} else if (status.repr == wuffs_base__suspension__short_write) {
14111411
g_tok.compact();

example/sdl-imageviewer/sdl-imageviewer.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,15 @@ class Wuffs_Load_RW_Input : public wuffs_aux::sync_io::Input {
189189

190190
private:
191191
std::string //
192-
CopyIn(wuffs_aux::IOBuffer* dst, uint64_t history_retain_length) override {
192+
CopyIn(wuffs_aux::IOBuffer* dst) override {
193193
if (!m_rw) {
194194
return "Wuffs_Load_RW_Input: NULL SDL_RWops";
195195
} else if (!dst) {
196196
return "Wuffs_Load_RW_Input: NULL IOBuffer";
197197
} else if (dst->meta.closed) {
198198
return "Wuffs_Load_RW_Input: end of file";
199199
}
200-
dst->compact_retaining(history_retain_length);
200+
dst->compact();
201201
if (dst->writer_length() == 0) {
202202
return "Wuffs_Load_RW_Input: full IOBuffer";
203203
}

example/zcat/zcat.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,20 @@ main1(int argc, char** argv) {
193193
wuffs_base__make_slice_u8(g_work_buffer_array,
194194
WORK_BUFFER_ARRAY_SIZE));
195195

196-
if (dst.meta.wi) {
196+
if (dst.meta.ri < dst.meta.wi) {
197197
// TODO: handle EINTR and other write errors; see "man 2 write".
198198
const int stdout_fd = 1;
199-
ignore_return_value(write(stdout_fd, g_dst_buffer_array, dst.meta.wi));
199+
ignore_return_value(write(stdout_fd, g_dst_buffer_array + dst.meta.ri,
200+
dst.meta.wi - dst.meta.ri));
200201
dst.meta.ri = dst.meta.wi;
201-
wuffs_base__io_buffer__compact(&dst);
202+
203+
wuffs_base__optional_u63 hrl =
204+
wuffs_gzip__decoder__dst_history_retain_length(&dec);
205+
wuffs_base__io_buffer__compact_retaining(
206+
&dst, wuffs_base__optional_u63__value_or(&hrl, UINT64_MAX));
207+
if (dst.meta.wi == dst.data.len) {
208+
return "main: unsupported history length (a.k.a. dictionary size)";
209+
}
202210
}
203211

204212
if (status.repr == wuffs_base__suspension__short_read) {
@@ -210,13 +218,7 @@ main1(int argc, char** argv) {
210218
return wuffs_base__status__message(&status);
211219
}
212220

213-
wuffs_base__optional_u63 hrl =
214-
wuffs_gzip__decoder__history_retain_length(&dec);
215-
wuffs_base__io_buffer__compact_retaining(
216-
&src, wuffs_base__optional_u63__value_or(&hrl, UINT64_MAX));
217-
if (src.meta.wi == src.data.len) {
218-
return "main: internal error: no I/O progress possible";
219-
}
221+
wuffs_base__io_buffer__compact(&src);
220222
}
221223
}
222224

internal/cgen/auxiliary/base.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,15 @@ Input::BringsItsOwnIOBuffer() {
108108
FileInput::FileInput(FILE* f) : m_f(f) {}
109109

110110
std::string //
111-
FileInput::CopyIn(IOBuffer* dst, uint64_t history_retain_length) {
111+
FileInput::CopyIn(IOBuffer* dst) {
112112
if (!m_f) {
113113
return "wuffs_aux::sync_io::FileInput: nullptr file";
114114
} else if (!dst) {
115115
return "wuffs_aux::sync_io::FileInput: nullptr IOBuffer";
116116
} else if (dst->meta.closed) {
117117
return "wuffs_aux::sync_io::FileInput: end of file";
118118
} else {
119-
dst->compact_retaining(history_retain_length);
119+
dst->compact();
120120
size_t n = fread(dst->writer_pointer(), 1, dst->writer_length(), m_f);
121121
dst->meta.wi += n;
122122
dst->meta.closed = feof(m_f);
@@ -144,7 +144,7 @@ MemoryInput::BringsItsOwnIOBuffer() {
144144
}
145145

146146
std::string //
147-
MemoryInput::CopyIn(IOBuffer* dst, uint64_t history_retain_length) {
147+
MemoryInput::CopyIn(IOBuffer* dst) {
148148
if (!dst) {
149149
return "wuffs_aux::sync_io::MemoryInput: nullptr IOBuffer";
150150
} else if (dst->meta.closed) {
@@ -154,7 +154,7 @@ MemoryInput::CopyIn(IOBuffer* dst, uint64_t history_retain_length) {
154154
// to it.
155155
return "wuffs_aux::sync_io::MemoryInput: overlapping buffers";
156156
} else {
157-
dst->compact_retaining(history_retain_length);
157+
dst->compact();
158158
size_t nd = dst->writer_length();
159159
size_t ns = m_io.reader_length();
160160
size_t n = (nd < ns) ? nd : ns;
@@ -209,7 +209,7 @@ AdvanceIOBufferTo(const ErrorMessages& error_messages,
209209
if (!input.BringsItsOwnIOBuffer()) {
210210
io_buf.compact();
211211
}
212-
std::string error_message = input.CopyIn(&io_buf, 0);
212+
std::string error_message = input.CopyIn(&io_buf);
213213
if (!error_message.empty()) {
214214
return error_message;
215215
}
@@ -292,7 +292,7 @@ HandleMetadata(
292292
} else if (!input.BringsItsOwnIOBuffer()) {
293293
io_buf.compact();
294294
}
295-
std::string error_message = input.CopyIn(&io_buf, 0);
295+
std::string error_message = input.CopyIn(&io_buf);
296296
if (!error_message.empty()) {
297297
return error_message;
298298
}

internal/cgen/auxiliary/base.hh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class Input {
9696
virtual ~Input();
9797

9898
virtual IOBuffer* BringsItsOwnIOBuffer();
99-
virtual std::string CopyIn(IOBuffer* dst, uint64_t history_retain_length) = 0;
99+
virtual std::string CopyIn(IOBuffer* dst) = 0;
100100
};
101101

102102
// --------
@@ -108,7 +108,7 @@ class FileInput : public Input {
108108
public:
109109
FileInput(FILE* f);
110110

111-
virtual std::string CopyIn(IOBuffer* dst, uint64_t history_retain_length);
111+
virtual std::string CopyIn(IOBuffer* dst);
112112

113113
private:
114114
FILE* m_f;
@@ -129,7 +129,7 @@ class MemoryInput : public Input {
129129
MemoryInput(const uint8_t* ptr, size_t len);
130130

131131
virtual IOBuffer* BringsItsOwnIOBuffer();
132-
virtual std::string CopyIn(IOBuffer* dst, uint64_t history_retain_length);
132+
virtual std::string CopyIn(IOBuffer* dst);
133133

134134
private:
135135
IOBuffer m_io;

0 commit comments

Comments
 (0)