aboutsummaryrefslogtreecommitdiff
path: root/src/liblzma/common
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2008-09-27 19:09:21 +0300
committerLasse Collin <lasse.collin@tukaani.org>2008-09-27 19:09:21 +0300
commit1dcecfb09b55157b8653d747963069c8bed74f04 (patch)
tree81fa1f1e8bf6871981970ca826d897db6f33527b /src/liblzma/common
parentAdded 7z2lzma.bash. (diff)
downloadxz-1dcecfb09b55157b8653d747963069c8bed74f04.tar.xz
Some API changes, bug fixes, cleanups etc.
Diffstat (limited to 'src/liblzma/common')
-rw-r--r--src/liblzma/common/alignment.c7
-rw-r--r--src/liblzma/common/alone_decoder.c11
-rw-r--r--src/liblzma/common/alone_encoder.c9
-rw-r--r--src/liblzma/common/chunk_size.c2
-rw-r--r--src/liblzma/common/easy.c20
-rw-r--r--src/liblzma/common/filter_common.c4
-rw-r--r--src/liblzma/common/filter_decoder.c4
-rw-r--r--src/liblzma/common/filter_encoder.c4
-rw-r--r--src/liblzma/common/init_encoder.c2
9 files changed, 33 insertions, 30 deletions
diff --git a/src/liblzma/common/alignment.c b/src/liblzma/common/alignment.c
index cfd515e6..ff38062e 100644
--- a/src/liblzma/common/alignment.c
+++ b/src/liblzma/common/alignment.c
@@ -50,10 +50,9 @@ lzma_alignment_input(const lzma_filter *filters, uint32_t guess)
case LZMA_FILTER_IA64:
return 16;
- case LZMA_FILTER_LZMA: {
+ case LZMA_FILTER_LZMA1: {
const lzma_options_lzma *lzma = filters[i].options;
- return 1 << MAX(lzma->pos_bits,
- lzma->literal_pos_bits);
+ return 1 << MAX(lzma->pb, lzma->lp);
}
default:
@@ -91,7 +90,7 @@ lzma_alignment_output(const lzma_filter *filters, uint32_t guess)
filters[i].options))->alignment;
case LZMA_FILTER_X86:
- case LZMA_FILTER_LZMA:
+ case LZMA_FILTER_LZMA1:
return 1;
case LZMA_FILTER_ARMTHUMB:
diff --git a/src/liblzma/common/alone_decoder.c b/src/liblzma/common/alone_decoder.c
index 45cb54e5..7ff29289 100644
--- a/src/liblzma/common/alone_decoder.c
+++ b/src/liblzma/common/alone_decoder.c
@@ -68,12 +68,11 @@ alone_decode(lzma_coder *coder,
break;
case SEQ_DICTIONARY_SIZE:
- coder->options.dictionary_size
+ coder->options.dict_size
|= (size_t)(in[*in_pos]) << (coder->pos * 8);
if (++coder->pos == 4) {
- if (coder->options.dictionary_size
- > LZMA_DICTIONARY_SIZE_MAX)
+ if (coder->options.dict_size > (UINT32_C(1) << 30))
return LZMA_FORMAT_ERROR;
// A hack to ditch tons of false positives: We allow
@@ -81,7 +80,7 @@ alone_decode(lzma_coder *coder,
// LZMA_Alone created only files with 2^n, but accepts
// any dictionary size. If someone complains, this
// will be reconsidered.
- uint32_t d = coder->options.dictionary_size - 1;
+ uint32_t d = coder->options.dict_size - 1;
d |= d >> 2;
d |= d >> 3;
d |= d >> 4;
@@ -89,7 +88,7 @@ alone_decode(lzma_coder *coder,
d |= d >> 16;
++d;
- if (d != coder->options.dictionary_size)
+ if (d != coder->options.dict_size)
return LZMA_FORMAT_ERROR;
coder->pos = 0;
@@ -199,7 +198,7 @@ lzma_alone_decoder_init(lzma_next_coder *next, lzma_allocator *allocator,
next->coder->sequence = SEQ_PROPERTIES;
next->coder->pos = 0;
- next->coder->options.dictionary_size = 0;
+ next->coder->options.dict_size = 0;
next->coder->uncompressed_size = 0;
next->coder->memlimit = memlimit;
diff --git a/src/liblzma/common/alone_encoder.c b/src/liblzma/common/alone_encoder.c
index 7fb11570..41fb6162 100644
--- a/src/liblzma/common/alone_encoder.c
+++ b/src/liblzma/common/alone_encoder.c
@@ -106,9 +106,10 @@ alone_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
if (lzma_lzma_lclppb_encode(options, next->coder->header))
return LZMA_PROG_ERROR;
- // - Dictionary size (4 bytes)
- if (options->dictionary_size < LZMA_DICTIONARY_SIZE_MIN
- || options->dictionary_size > LZMA_DICTIONARY_SIZE_MAX)
+ // - Dictionary size (4 bytes); limit to 1 GiB since that's what
+ // LZMA SDK currently does for encoding.
+ if (options->dict_size < LZMA_DICT_SIZE_MIN
+ || options->dict_size > (UINT32_C(1) << 30))
return LZMA_PROG_ERROR;
// Round up to to the next 2^n or 2^n + 2^(n - 1) depending on which
@@ -118,7 +119,7 @@ alone_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
//
// FIXME Maybe LZMA_Alone needs some lower limit for maximum
// dictionary size? Must check decoders from old LZMA SDK version.
- uint32_t d = options->dictionary_size - 1;
+ uint32_t d = options->dict_size - 1;
d |= d >> 2;
d |= d >> 3;
d |= d >> 4;
diff --git a/src/liblzma/common/chunk_size.c b/src/liblzma/common/chunk_size.c
index 74d4a6f4..33276b28 100644
--- a/src/liblzma/common/chunk_size.c
+++ b/src/liblzma/common/chunk_size.c
@@ -55,7 +55,7 @@ lzma_chunk_size(const lzma_options_filter *filters)
// splitting the data in smaller blocks.
break;
- case LZMA_FILTER_LZMA:
+ case LZMA_FILTER_LZMA1:
// The block sizes of the possible next filters in
// the chain are irrelevant after the LZMA filter.
return ((lzma_options_lzma *)(filters->options))
diff --git a/src/liblzma/common/easy.c b/src/liblzma/common/easy.c
index 7446bc79..d5e19525 100644
--- a/src/liblzma/common/easy.c
+++ b/src/liblzma/common/easy.c
@@ -23,6 +23,9 @@
struct lzma_coder_s {
lzma_next_coder stream_encoder;
+ /// Options for LZMA2
+ lzma_options_lzma opt_lzma;
+
/// We need to keep the filters array available in case
/// LZMA_FULL_FLUSH is used.
lzma_filter filters[5];
@@ -30,7 +33,7 @@ struct lzma_coder_s {
static bool
-easy_set_filters(lzma_filter *filters, uint32_t level)
+easy_set_filters(lzma_coder *coder, uint32_t level)
{
bool error = false;
@@ -40,9 +43,10 @@ easy_set_filters(lzma_filter *filters, uint32_t level)
#ifdef HAVE_ENCODER_LZMA2
} else if (level <= 9) {
- filters[0].id = LZMA_FILTER_LZMA2;
- filters[0].options = (void *)(&lzma_preset_lzma[level - 1]);
- filters[1].id = LZMA_VLI_UNKNOWN;
+ error = lzma_lzma_preset(&coder->opt_lzma, level - 1);
+ coder->filters[0].id = LZMA_FILTER_LZMA2;
+ coder->filters[0].options = &coder->opt_lzma;
+ coder->filters[1].id = LZMA_VLI_UNKNOWN;
#endif
} else {
@@ -91,7 +95,7 @@ easy_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
next->coder->stream_encoder = LZMA_NEXT_CODER_INIT;
}
- if (easy_set_filters(next->coder->filters, level))
+ if (easy_set_filters(next->coder, level))
return LZMA_OPTIONS_ERROR;
return lzma_stream_encoder_init(&next->coder->stream_encoder,
@@ -116,9 +120,9 @@ lzma_easy_encoder(lzma_stream *strm, lzma_easy_level level)
extern LZMA_API uint64_t
lzma_easy_memory_usage(lzma_easy_level level)
{
- lzma_filter filters[5];
- if (easy_set_filters(filters, level))
+ lzma_coder coder;
+ if (easy_set_filters(&coder, level))
return UINT32_MAX;
- return lzma_memusage_encoder(filters);
+ return lzma_memusage_encoder(coder.filters);
}
diff --git a/src/liblzma/common/filter_common.c b/src/liblzma/common/filter_common.c
index 7097ce51..71ceeca0 100644
--- a/src/liblzma/common/filter_common.c
+++ b/src/liblzma/common/filter_common.c
@@ -38,9 +38,9 @@ static const struct {
bool changes_size;
} features[] = {
-#if defined (HAVE_ENCODER_LZMA) || defined(HAVE_DECODER_LZMA)
+#if defined (HAVE_ENCODER_LZMA1) || defined(HAVE_DECODER_LZMA1)
{
- .id = LZMA_FILTER_LZMA,
+ .id = LZMA_FILTER_LZMA1,
.non_last_ok = false,
.last_ok = true,
.changes_size = true,
diff --git a/src/liblzma/common/filter_decoder.c b/src/liblzma/common/filter_decoder.c
index 8b7e532f..241b272d 100644
--- a/src/liblzma/common/filter_decoder.c
+++ b/src/liblzma/common/filter_decoder.c
@@ -51,9 +51,9 @@ typedef struct {
static const lzma_filter_decoder decoders[] = {
-#ifdef HAVE_DECODER_LZMA
+#ifdef HAVE_DECODER_LZMA1
{
- .id = LZMA_FILTER_LZMA,
+ .id = LZMA_FILTER_LZMA1,
.init = &lzma_lzma_decoder_init,
.memusage = &lzma_lzma_decoder_memusage,
.props_decode = &lzma_lzma_props_decode,
diff --git a/src/liblzma/common/filter_encoder.c b/src/liblzma/common/filter_encoder.c
index 550d5483..a839fe70 100644
--- a/src/liblzma/common/filter_encoder.c
+++ b/src/liblzma/common/filter_encoder.c
@@ -62,9 +62,9 @@ typedef struct {
static const lzma_filter_encoder encoders[] = {
-#ifdef HAVE_ENCODER_LZMA
+#ifdef HAVE_ENCODER_LZMA1
{
- .id = LZMA_FILTER_LZMA,
+ .id = LZMA_FILTER_LZMA1,
.init = &lzma_lzma_encoder_init,
.memusage = &lzma_lzma_encoder_memusage,
.chunk_size = NULL, // FIXME
diff --git a/src/liblzma/common/init_encoder.c b/src/liblzma/common/init_encoder.c
index c5f12a91..1130e6b8 100644
--- a/src/liblzma/common/init_encoder.c
+++ b/src/liblzma/common/init_encoder.c
@@ -31,7 +31,7 @@ lzma_init_encoder(void)
lzma_init_check();
-#if defined(HAVE_SMALL) && defined(HAVE_ENCODER_LZMA)
+#if defined(HAVE_SMALL) && defined(HAVE_ENCODER_LZMA1)
lzma_rc_init();
#endif