diff options
author | Lasse Collin <lasse.collin@tukaani.org> | 2009-11-14 18:59:19 +0200 |
---|---|---|
committer | Lasse Collin <lasse.collin@tukaani.org> | 2009-11-14 18:59:19 +0200 |
commit | 418d64a32e8144210f98a810738fed5a897e8367 (patch) | |
tree | e3dce06dfd250fd659d922aaed914f6cc93cd2c8 /src/liblzma/common/common.c | |
parent | Fix wrong function name in the previous commit. (diff) | |
download | xz-418d64a32e8144210f98a810738fed5a897e8367.tar.xz |
Fix a design error in liblzma API.
Originally the idea was that using LZMA_FULL_FLUSH
with Stream encoder would read the filter chain
from the same array that was used to intialize the
Stream encoder. Since most apps wouldn't use
LZMA_FULL_FLUSH, most apps wouldn't need to keep
the filter chain available after initializing the
Stream encoder. However, due to my mistake, it
actually required keeping the array always available.
Since setting the new filter chain via the array
used at initialization time is not a nice way to do
it for a couple of reasons, this commit ditches it
and introduces lzma_filters_update(). This new function
replaces also the "persistent" flag used by LZMA2
(and to-be-designed Subblock filter), which was also
an ugly thing to do.
Thanks to Alexey Tourbin for reminding me about the problem
that Stream encoder used to require keeping the filter
chain allocated.
Diffstat (limited to '')
-rw-r--r-- | src/liblzma/common/common.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/liblzma/common/common.c b/src/liblzma/common/common.c index 3bdf3252..edce90cd 100644 --- a/src/liblzma/common/common.c +++ b/src/liblzma/common/common.c @@ -92,12 +92,30 @@ lzma_next_filter_init(lzma_next_coder *next, lzma_allocator *allocator, const lzma_filter_info *filters) { lzma_next_coder_init(filters[0].init, next, allocator); - + next->id = filters[0].id; return filters[0].init == NULL ? LZMA_OK : filters[0].init(next, allocator, filters); } +extern lzma_ret +lzma_next_filter_update(lzma_next_coder *next, lzma_allocator *allocator, + const lzma_filter *reversed_filters) +{ + // Check that the application isn't trying to change the Filter ID. + // End of filters is indicated with LZMA_VLI_UNKNOWN in both + // reversed_filters[0].id and next->id. + if (reversed_filters[0].id != next->id) + return LZMA_PROG_ERROR; + + if (reversed_filters[0].id == LZMA_VLI_UNKNOWN) + return LZMA_OK; + + assert(next->update != NULL); + return next->update(next->coder, allocator, NULL, reversed_filters); +} + + extern void lzma_next_end(lzma_next_coder *next, lzma_allocator *allocator) { |