XZ Utils 5.3.5beta
Data Structures | Macros | Typedefs | Functions | Variables
common.h File Reference

Definitions common to the whole liblzma library. 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
 

Macros

#define LZMA_API_EXPORT
 
#define LZMA_API(type)   LZMA_API_EXPORT type LZMA_API_CALL
 
#define lzma_has_attribute(attr)   0
 
#define likely(expr)   (expr)
 
#define unlikely(expr)   (expr)
 
#define LZMA_BUFFER_SIZE   4096
 Size of temporary buffers needed in some filters. More...
 
#define LZMA_THREADS_MAX   16384
 
#define LZMA_MEMUSAGE_BASE   (UINT64_C(1) << 15)
 
#define LZMA_FILTER_RESERVED_START   (LZMA_VLI_C(1) << 62)
 
#define LZMA_SUPPORTED_FLAGS
 
#define LZMA_ACTION_MAX   ((unsigned int)(LZMA_FULL_BARRIER))
 Largest valid lzma_action value as unsigned integer. More...
 
#define LZMA_TIMED_OUT   LZMA_RET_INTERNAL1
 
#define LZMA_INDEX_DETECTED   LZMA_RET_INTERNAL2
 
#define LZMA_NEXT_CODER_INIT
 Macro to initialize lzma_next_coder structure. More...
 
#define return_if_error(expr)
 Return if expression doesn't evaluate to LZMA_OK. More...
 
#define lzma_next_coder_init(func, next, allocator)
 
#define lzma_next_strm_init(func, strm, ...)
 

Typedefs

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, const lzma_allocator *allocator, const lzma_filter_info *filters)
 Type of a function used to initialize a filter encoder or decoder. More...
 
typedef lzma_ret(* lzma_code_function) (void *coder, const 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) (void *coder, const lzma_allocator *allocator)
 Type of a function to free the memory allocated for the coder. More...
 

Functions

void * lzma_alloc (size_t size, const lzma_allocator *allocator) lzma_attribute((__malloc__)) lzma_attr_alloc_size(1)
 Allocates memory. More...
 
void * lzma_attribute ((__malloc__)) lzma_attr_alloc_size(1) lzma_alloc_zero(size_t size
 
void lzma_free (void *ptr, const lzma_allocator *allocator)
 Frees memory. More...
 
lzma_ret lzma_strm_init (lzma_stream *strm)
 
lzma_ret lzma_next_filter_init (lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters)
 
lzma_ret lzma_next_filter_update (lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter *reversed_filters)
 
void lzma_next_end (lzma_next_coder *next, const 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)
 

Variables

void const lzma_allocatorallocator
 

Detailed Description

Definitions common to the whole liblzma library.

Macro Definition Documentation

◆ LZMA_BUFFER_SIZE

#define LZMA_BUFFER_SIZE   4096

Size of temporary buffers needed in some filters.

◆ LZMA_THREADS_MAX

#define LZMA_THREADS_MAX   16384

Maximum number of worker threads within one multithreaded component. The limit exists solely to make it simpler to prevent integer overflows when allocating structures etc. This should be big enough for now... the code won't scale anywhere close to this number anyway.

◆ LZMA_MEMUSAGE_BASE

#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.

◆ LZMA_FILTER_RESERVED_START

#define LZMA_FILTER_RESERVED_START   (LZMA_VLI_C(1) << 62)

Start of internal Filter ID space. These IDs must never be used in Streams.

◆ LZMA_SUPPORTED_FLAGS

#define LZMA_SUPPORTED_FLAGS
Value:
#define LZMA_TELL_ANY_CHECK
Definition: container.h:575
#define LZMA_IGNORE_CHECK
Definition: container.h:599
#define LZMA_CONCATENATED
Definition: container.h:616
#define LZMA_FAIL_FAST
Definition: container.h:645
#define LZMA_TELL_NO_CHECK
Definition: container.h:558
#define LZMA_TELL_UNSUPPORTED_CHECK
Definition: container.h:567

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

◆ LZMA_ACTION_MAX

#define LZMA_ACTION_MAX   ((unsigned int)(LZMA_FULL_BARRIER))

Largest valid lzma_action value as unsigned integer.

◆ LZMA_TIMED_OUT

#define LZMA_TIMED_OUT   LZMA_RET_INTERNAL1

Special return value (lzma_ret) to indicate that a timeout was reached and lzma_code() must not return LZMA_BUF_ERROR. This is converted to LZMA_OK in lzma_code().

◆ LZMA_INDEX_DETECTED

#define LZMA_INDEX_DETECTED   LZMA_RET_INTERNAL2

Special return value (lzma_ret) for use in stream_decoder_mt.c to indicate Index was detected instead of a Block Header.

◆ LZMA_NEXT_CODER_INIT

#define LZMA_NEXT_CODER_INIT
Value:
.coder = NULL, \
.init = (uintptr_t)(NULL), \
.code = NULL, \
.end = NULL, \
.get_progress = NULL, \
.get_check = NULL, \
.memconfig = NULL, \
.update = NULL, \
.set_out_limit = NULL, \
}
Hold data and function pointers of the next filter in the chain.
Definition: common.h:195
#define LZMA_VLI_UNKNOWN
VLI value to denote that the value is unknown.
Definition: vli.h:39

Macro to initialize lzma_next_coder structure.

◆ return_if_error

#define return_if_error (   expr)
Value:
do { \
const lzma_ret ret_ = (expr); \
if (ret_ != LZMA_OK) \
return ret_; \
} while (0)
lzma_ret
Return values used by several functions in liblzma.
Definition: base.h:57
@ LZMA_OK
Operation completed successfully.
Definition: base.h:58

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.

◆ lzma_next_coder_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.

◆ lzma_next_strm_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)
static lzma_stream strm
Stream used to communicate with liblzma.
Definition: coder.c:33
lzma_ret lzma_strm_init(lzma_stream *strm)
Definition: common.c:170

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.

Typedef Documentation

◆ lzma_init_function

typedef lzma_ret(* lzma_init_function) (lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters)

Type of a function used to initialize a filter encoder or decoder.

◆ lzma_code_function

typedef lzma_ret(* lzma_code_function) (void *coder, const 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.

◆ lzma_end_function

typedef void(* lzma_end_function) (void *coder, const lzma_allocator *allocator)

Type of a function to free the memory allocated for the coder.

Function Documentation

◆ lzma_alloc()

void * lzma_alloc ( size_t  size,
const lzma_allocator allocator 
)

Allocates memory.

Referenced by lzma_strm_init().

◆ lzma_attribute()

void * lzma_attribute ( (__malloc__)  )

Allocates memory and zeroes it (like calloc()). This can be faster than lzma_alloc() + memzero() while being backward compatible with custom allocators.

◆ lzma_free()

void lzma_free ( void *  ptr,
const lzma_allocator allocator 
)

Frees memory.

Referenced by lzma_end().

◆ lzma_strm_init()

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_MEM_ERROR, LZMA_NEXT_CODER_INIT, LZMA_PROG_ERROR, lzma_internal_s::next, and strm.

◆ lzma_next_filter_init()

lzma_ret lzma_next_filter_init ( lzma_next_coder next,
const 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.

◆ lzma_next_filter_update()

lzma_ret lzma_next_filter_update ( lzma_next_coder next,
const 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.

◆ lzma_next_end()

void lzma_next_end ( lzma_next_coder next,
const lzma_allocator allocator 
)

Frees the memory allocated for next->coder either using next->end or, if next->end is NULL, using lzma_free.

Referenced by lzma_end().

◆ lzma_bufcpy()

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.

Referenced by dict_write(), and fill_temp().