aboutsummaryrefslogtreecommitdiff
path: root/src/liblzma/common/common.h
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2009-11-14 18:59:19 +0200
committerLasse Collin <lasse.collin@tukaani.org>2009-11-14 18:59:19 +0200
commit418d64a32e8144210f98a810738fed5a897e8367 (patch)
treee3dce06dfd250fd659d922aaed914f6cc93cd2c8 /src/liblzma/common/common.h
parentFix wrong function name in the previous commit. (diff)
downloadxz-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 'src/liblzma/common/common.h')
-rw-r--r--src/liblzma/common/common.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/liblzma/common/common.h b/src/liblzma/common/common.h
index 81f51421..6551e39f 100644
--- a/src/liblzma/common/common.h
+++ b/src/liblzma/common/common.h
@@ -109,6 +109,10 @@ typedef void (*lzma_end_function)(
/// an array of lzma_filter_info structures. This array is used with
/// lzma_next_filter_init to initialize the filter chain.
struct lzma_filter_info_s {
+ /// Filter ID. This is used only by the encoder
+ /// with lzma_filters_update().
+ lzma_vli id;
+
/// Pointer to function used to initialize the filter.
/// This is NULL to indicate end of array.
lzma_init_function init;
@@ -123,6 +127,10 @@ struct lzma_next_coder_s {
/// Pointer to coder-specific data
lzma_coder *coder;
+ /// Filter ID. This is LZMA_VLI_UNKNOWN when this structure doesn't
+ /// point to a filter coder.
+ lzma_vli id;
+
/// "Pointer" to init function. This is never called here.
/// We need only to detect if we are initializing a coder
/// that was allocated earlier. See lzma_next_coder_init and
@@ -145,6 +153,12 @@ struct lzma_next_coder_s {
/// If new_memlimit == 0, the limit is not changed.
lzma_ret (*memconfig)(lzma_coder *coder, uint64_t *memusage,
uint64_t *old_memlimit, uint64_t new_memlimit);
+
+ /// Update the filter-specific options or the whole filter chain
+ /// in the encoder.
+ lzma_ret (*update)(lzma_coder *coder, lzma_allocator *allocator,
+ const lzma_filter *filters,
+ const lzma_filter *reversed_filters);
};
@@ -153,10 +167,12 @@ struct lzma_next_coder_s {
(lzma_next_coder){ \
.coder = NULL, \
.init = (uintptr_t)(NULL), \
+ .id = LZMA_VLI_UNKNOWN, \
.code = NULL, \
.end = NULL, \
.get_check = NULL, \
.memconfig = NULL, \
+ .update = NULL, \
}
@@ -212,6 +228,12 @@ extern lzma_ret lzma_strm_init(lzma_stream *strm);
extern lzma_ret lzma_next_filter_init(lzma_next_coder *next,
lzma_allocator *allocator, const lzma_filter_info *filters);
+/// Update the next filter in the chain, if any. This checks that
+/// the application is not trying to change the Filter IDs.
+extern lzma_ret lzma_next_filter_update(
+ lzma_next_coder *next, lzma_allocator *allocator,
+ const lzma_filter *reversed_filters);
+
/// Frees the memory allocated for next->coder either using next->end or,
/// if next->end is NULL, using lzma_free.
extern void lzma_next_end(lzma_next_coder *next, lzma_allocator *allocator);