Common functions needed in many places in liblzma. More...
#include "sysdefs.h"
#include "mythread.h"
#include "tuklib_integer.h"
#include "lzma.h"
Data Structures | |
struct | lzma_filter_info_s |
struct | lzma_next_coder_s |
Hold data and function pointers of the next filter in the chain. More... | |
struct | lzma_internal_s |
Defines | |
#define | LZMA_API_EXPORT |
#define | LZMA_API(type) LZMA_API_EXPORT type LZMA_API_CALL |
#define | likely(expr) (expr) |
#define | unlikely(expr) (expr) |
#define | LZMA_BUFFER_SIZE 4096 |
Size of temporary buffers needed in some filters. | |
#define | LZMA_MEMUSAGE_BASE (UINT64_C(1) << 15) |
#define | LZMA_FILTER_RESERVED_START (LZMA_VLI_C(1) << 62) |
#define | LZMA_SUPPORTED_FLAGS |
#define | LZMA_NEXT_CODER_INIT |
Macro to initialize lzma_next_coder structure. | |
#define | return_if_error(expr) |
Return if expression doesn't evaluate to LZMA_OK. | |
#define | lzma_next_coder_init(func, next, allocator) |
#define | lzma_next_strm_init(func, strm,...) |
Typedefs | |
typedef struct lzma_coder_s | lzma_coder |
typedef struct lzma_next_coder_s | lzma_next_coder |
typedef struct lzma_filter_info_s | lzma_filter_info |
typedef lzma_ret(* | lzma_init_function )(lzma_next_coder *next, lzma_allocator *allocator, const lzma_filter_info *filters) |
Type of a function used to initialize a filter encoder or decoder. | |
typedef lzma_ret(* | lzma_code_function )(lzma_coder *coder, lzma_allocator *allocator, const uint8_t *restrict in, size_t *restrict in_pos, size_t in_size, uint8_t *restrict out, size_t *restrict out_pos, size_t out_size, lzma_action action) |
typedef void(* | lzma_end_function )(lzma_coder *coder, lzma_allocator *allocator) |
Type of a function to free the memory allocated for the coder. | |
Functions | |
void * | lzma_alloc (size_t size, lzma_allocator *allocator) lzma_attribute((malloc)) |
Allocates memory. | |
void | lzma_free (void *ptr, lzma_allocator *allocator) |
Frees memory. | |
lzma_ret | lzma_strm_init (lzma_stream *strm) |
lzma_ret | lzma_next_filter_init (lzma_next_coder *next, lzma_allocator *allocator, const lzma_filter_info *filters) |
lzma_ret | lzma_next_filter_update (lzma_next_coder *next, lzma_allocator *allocator, const lzma_filter *reversed_filters) |
void | lzma_next_end (lzma_next_coder *next, lzma_allocator *allocator) |
size_t | lzma_bufcpy (const uint8_t *restrict in, size_t *restrict in_pos, size_t in_size, uint8_t *restrict out, size_t *restrict out_pos, size_t out_size) |
Common functions needed in many places in liblzma.
Definitions common to the whole liblzma library.
#define LZMA_BUFFER_SIZE 4096 |
Size of temporary buffers needed in some filters.
#define LZMA_MEMUSAGE_BASE (UINT64_C(1) << 15) |
Starting value for memory usage estimates. Instead of calculating size of _every_ structure and taking into account malloc() overhead etc., we add a base size to all memory usage estimates. It's not very accurate but should be easily good enough.
Referenced by lzma_memlimit_set().
#define LZMA_FILTER_RESERVED_START (LZMA_VLI_C(1) << 62) |
Start of internal Filter ID space. These IDs must never be used in Streams.
Referenced by lzma_filter_flags_decode(), lzma_filter_flags_encode(), and lzma_filter_flags_size().
#define LZMA_SUPPORTED_FLAGS |
( LZMA_TELL_NO_CHECK \ | LZMA_TELL_UNSUPPORTED_CHECK \ | LZMA_TELL_ANY_CHECK \ | LZMA_CONCATENATED )
Supported flags that can be passed to lzma_stream_decoder() or lzma_auto_decoder().
#define LZMA_NEXT_CODER_INIT |
(lzma_next_coder){ \ .coder = NULL, \ .init = (uintptr_t)(NULL), \ .id = LZMA_VLI_UNKNOWN, \ .code = NULL, \ .end = NULL, \ .get_check = NULL, \ .memconfig = NULL, \ .update = NULL, \ }
Macro to initialize lzma_next_coder structure.
#define return_if_error | ( | expr | ) |
Return if expression doesn't evaluate to LZMA_OK.
There are several situations where we want to return immediately with the value of expr if it isn't LZMA_OK. This macro shortens the code a little.
Referenced by lzma_block_buffer_encode(), lzma_block_header_decode(), lzma_block_header_encode(), lzma_block_header_size(), lzma_decoder_init(), lzma_filter_flags_decode(), lzma_filter_flags_encode(), lzma_filter_flags_size(), lzma_index_buffer_decode(), lzma_index_hash_append(), lzma_index_hash_decode(), lzma_index_stream_flags(), lzma_raw_buffer_decode(), lzma_raw_buffer_encode(), and lzma_stream_buffer_encode().
#define lzma_next_coder_init | ( | func, | ||
next, | ||||
allocator | ||||
) |
do { \ if ((uintptr_t)(func) != (next)->init) \ lzma_next_end(next, allocator); \ (next)->init = (uintptr_t)(func); \ } while (0)
If next isn't already initialized, free the previous coder. Then mark that next is _possibly_ initialized for the coder using this macro. "Possibly" means that if e.g. allocation of next->coder fails, the structure isn't actually initialized for this coder, but leaving next->init to func is still OK.
Referenced by lzma_next_filter_init().
#define lzma_next_strm_init | ( | func, | ||
strm, | ||||
... | ||||
) |
do { \ return_if_error(lzma_strm_init(strm)); \ const lzma_ret ret_ = func(&(strm)->internal->next, \ (strm)->allocator, __VA_ARGS__); \ if (ret_ != LZMA_OK) { \ lzma_end(strm); \ return ret_; \ } \ } while (0)
Initializes lzma_strm and calls func() to initialize strm->internal->next. (The function being called will use lzma_next_coder_init()). If initialization fails, memory that wasn't freed by func() is freed along strm->internal.
Referenced by lzma_alone_decoder(), lzma_alone_encoder(), lzma_auto_decoder(), lzma_block_decoder(), lzma_block_encoder(), lzma_index_decoder(), lzma_index_encoder(), lzma_raw_decoder(), lzma_raw_encoder(), lzma_stream_decoder(), and lzma_stream_encoder().
typedef struct lzma_coder_s lzma_coder |
Type of encoder/decoder specific data; the actual structure is defined differently in different coders.
typedef lzma_ret(* lzma_init_function)(lzma_next_coder *next, lzma_allocator *allocator, const lzma_filter_info *filters) |
Type of a function used to initialize a filter encoder or decoder.
typedef lzma_ret(* lzma_code_function)(lzma_coder *coder, lzma_allocator *allocator, const uint8_t *restrict in, size_t *restrict in_pos, size_t in_size, uint8_t *restrict out, size_t *restrict out_pos, size_t out_size, lzma_action action) |
Type of a function to do some kind of coding work (filters, Stream, Block encoders/decoders etc.). Some special coders use don't use both input and output buffers, but for simplicity they still use this same function prototype.
typedef void(* lzma_end_function)(lzma_coder *coder, lzma_allocator *allocator) |
Type of a function to free the memory allocated for the coder.
void* lzma_alloc | ( | size_t | size, | |
lzma_allocator * | allocator | |||
) |
Allocates memory.
Referenced by index_dup_stream(), index_stream_init(), lzma_filters_copy(), lzma_index_append(), lzma_index_hash_init(), and lzma_strm_init().
void lzma_free | ( | void * | ptr, | |
lzma_allocator * | allocator | |||
) |
Frees memory.
References lzma_allocator::free, and lzma_allocator::opaque.
lzma_ret lzma_strm_init | ( | lzma_stream * | strm | ) |
Allocates strm->internal if it is NULL, and initializes *strm and strm->internal. This function is only called via lzma_next_strm_init macro.
References lzma_stream::allocator, lzma_internal_s::allow_buf_error, lzma_stream::internal, lzma_alloc(), lzma_internal_s::next, lzma_internal_s::sequence, lzma_internal_s::supported_actions, lzma_stream::total_in, and lzma_stream::total_out.
lzma_ret lzma_next_filter_init | ( | lzma_next_coder * | next, | |
lzma_allocator * | allocator, | |||
const lzma_filter_info * | filters | |||
) |
Initializes the next filter in the chain, if any. This takes care of freeing the memory of previously initialized filter if it is different than the filter being initialized now. This way the actual filter initialization functions don't need to use lzma_next_coder_init macro.
References lzma_filter_info_s::id, lzma_next_coder_s::id, lzma_filter_info_s::init, lzma_next_coder_init, and LZMA_OK.
lzma_ret lzma_next_filter_update | ( | lzma_next_coder * | next, | |
lzma_allocator * | allocator, | |||
const lzma_filter * | reversed_filters | |||
) |
Update the next filter in the chain, if any. This checks that the application is not trying to change the Filter IDs.
References lzma_next_coder_s::coder, lzma_next_coder_s::id, LZMA_VLI_UNKNOWN, and lzma_next_coder_s::update.
void lzma_next_end | ( | lzma_next_coder * | next, | |
lzma_allocator * | allocator | |||
) |
Frees the memory allocated for next->coder either using next->end or, if next->end is NULL, using lzma_free.
References lzma_next_coder_s::coder, lzma_next_coder_s::end, and lzma_next_coder_s::init.
size_t lzma_bufcpy | ( | const uint8_t *restrict | in, | |
size_t *restrict | in_pos, | |||
size_t | in_size, | |||
uint8_t *restrict | out, | |||
size_t *restrict | out_pos, | |||
size_t | out_size | |||
) |
Copy as much data as possible from in[] to out[] and update *in_pos and *out_pos accordingly. Returns the number of bytes copied.