diff options
author | Lasse Collin <lasse.collin@tukaani.org> | 2008-06-19 16:35:08 +0300 |
---|---|---|
committer | Lasse Collin <lasse.collin@tukaani.org> | 2008-06-19 16:35:08 +0300 |
commit | 0809c46534fa5664fe35d9e98d95e87312ed130e (patch) | |
tree | 6923ece40819c97cdd786dfdb01a7904043b1026 /src/liblzma/lzma/lzma_literal.c | |
parent | Comments (diff) | |
download | xz-0809c46534fa5664fe35d9e98d95e87312ed130e.tar.xz |
Add limit of lc + lp <= 4. Now we can allocate the
literal coder as part of the main LZMA encoder or
decoder structure.
Make the LZMA decoder to rely on the current internal API
to free the allocated memory in case an error occurs.
Diffstat (limited to 'src/liblzma/lzma/lzma_literal.c')
-rw-r--r-- | src/liblzma/lzma/lzma_literal.c | 39 |
1 files changed, 8 insertions, 31 deletions
diff --git a/src/liblzma/lzma/lzma_literal.c b/src/liblzma/lzma/lzma_literal.c index 8f650fbf..3611a1f7 100644 --- a/src/liblzma/lzma/lzma_literal.c +++ b/src/liblzma/lzma/lzma_literal.c @@ -22,7 +22,7 @@ extern lzma_ret -lzma_literal_init(lzma_literal_coder **coder, lzma_allocator *allocator, +lzma_literal_init(lzma_literal_coder *coder, uint32_t literal_context_bits, uint32_t literal_pos_bits) { // Verify that arguments are sane. @@ -34,41 +34,18 @@ lzma_literal_init(lzma_literal_coder **coder, lzma_allocator *allocator, const uint32_t states = literal_states( literal_pos_bits, literal_context_bits); - // Allocate a new literal coder, if needed. - if (*coder == NULL || (**coder).literal_context_bits - != literal_context_bits - || (**coder).literal_pos_bits != literal_pos_bits) { - // Free the old coder, if any. - lzma_free(*coder, allocator); + // Store the new settings. + coder->literal_context_bits = literal_context_bits; + coder->literal_pos_bits = literal_pos_bits; - // Allocate a new one. - *coder = lzma_alloc(sizeof(lzma_literal_coder) - + states * LIT_SIZE * sizeof(probability), - allocator); - if (*coder == NULL) - return LZMA_MEM_ERROR; - - // Store the new settings. - (**coder).literal_context_bits = literal_context_bits; - (**coder).literal_pos_bits = literal_pos_bits; - - // Calculate also the literal_pos_mask. It's not changed - // anywhere else than here. - (**coder).literal_pos_mask = (1 << literal_pos_bits) - 1; - } + // Calculate also the literal_pos_mask. It's not changed + // anywhere else than here. + coder->literal_pos_mask = (1 << literal_pos_bits) - 1; // Reset the literal coder. for (uint32_t i = 0; i < states; ++i) for (uint32_t j = 0; j < LIT_SIZE; ++j) - bit_reset((**coder).coders[i][j]); + bit_reset(coder->coders[i][j]); return LZMA_OK; } - - -extern void -lzma_literal_end(lzma_literal_coder **coder, lzma_allocator *allocator) -{ - lzma_free(*coder, allocator); - *coder = NULL; -} |