src/liblzma/common/common.h File Reference

Common functions needed in many places in liblzma. More...

#include "../../common/sysdefs.h"
#include "../../common/mythread.h"
#include "../../common/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_FILTER_SUBBLOCK_HELPER   LZMA_VLI_C(0x7000000000000001)
#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)
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)


Detailed Description

Common functions needed in many places in liblzma.

Definitions common to the whole liblzma library.


Define Documentation

#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 accont malloc() overhead etc. we add a base size to all memory usage estimates. It's not very accurate but should be easily good enough.

#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_API().

#define LZMA_FILTER_SUBBLOCK_HELPER   LZMA_VLI_C(0x7000000000000001)

Internal helper filter used by Subblock decoder. It is mapped to an otherwise invalid Filter ID, which is impossible to get from any input file (even if malicious file).

#define LZMA_SUPPORTED_FLAGS

Value:

Supported flags that can be passed to lzma_stream_decoder() or lzma_auto_decoder().

#define LZMA_NEXT_CODER_INIT

Value:

(lzma_next_coder){ \
                .coder = NULL, \
                .init = (uintptr_t)(NULL), \
                .code = NULL, \
                .end = NULL, \
                .get_check = NULL, \
                .memconfig = NULL, \
        }
Macro to initialize lzma_next_coder structure.

Referenced by LZMA_API(), lzma_next_end(), and lzma_strm_init().

#define return_if_error ( expr   ) 

Value:

do { \
        const lzma_ret ret_ = (expr); \
        if (ret_ != LZMA_OK) \
                return ret_; \
} while (0)
Return if expression doesn't evaluate to LZMA_OK.

There are several situations where we want to return immediatelly with the value of expr if it isn't LZMA_OK. This macro shortens the code a little.

Referenced by LZMA_API(), and lzma_decoder_init().

#define lzma_next_coder_init ( func,
next,
allocator   ) 

Value:

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,
...   ) 

Value:

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_API().


Typedef Documentation

typedef struct lzma_coder_s lzma_coder

Type of encoder/decoder specific data; the actual structure is defined differently in different coders.

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.


Function Documentation

void* lzma_alloc ( size_t  size,
lzma_allocator allocator 
)

Allocates memory.

Referenced by index_append_real(), lzma_strm_init(), and subblock_data_size().

void lzma_free ( void *  ptr,
lzma_allocator allocator 
)

Frees memory.

References 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_stream::internal, lzma_alloc(), LZMA_FINISH, LZMA_FULL_FLUSH, LZMA_MEM_ERROR, LZMA_NEXT_CODER_INIT, LZMA_OK, LZMA_PROG_ERROR, LZMA_RUN, LZMA_SYNC_FLUSH, 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::init, lzma_next_coder_init, and LZMA_OK.

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, lzma_next_coder_s::init, and LZMA_NEXT_CODER_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.


Generated on Wed May 25 10:35:41 2011 for XZ Utils by  doxygen 1.5.5