mirror of
https://git.tukaani.org/xz.git
synced 2024-04-04 12:36:23 +02:00
liblzma: Add new API function lzma_filters_free().
This is small but convenient and should have been added a long time ago.
This commit is contained in:
parent
ae1f8a723d
commit
d090164517
4 changed files with 49 additions and 0 deletions
|
@ -124,6 +124,27 @@ extern LZMA_API(lzma_ret) lzma_filters_copy(
|
|||
lzma_nothrow lzma_attr_warn_unused_result;
|
||||
|
||||
|
||||
/**
|
||||
* \brief Free the options in the array of lzma_filter structures
|
||||
*
|
||||
* This frees the filter chain options. The filters array itself is not freed.
|
||||
*
|
||||
* The filters array must have at most LZMA_FILTERS_MAX + 1 elements
|
||||
* including the terminating element which must have .id = LZMA_VLI_UNKNOWN.
|
||||
* For all elements before the terminating element:
|
||||
* - options will be freed using the given lzma_allocator or,
|
||||
* if allocator is NULL, using free().
|
||||
* - options will be set to NULL.
|
||||
* - id will be set to LZMA_VLI_UNKNOWN.
|
||||
*
|
||||
* If filters is NULL, this does nothing but remember that this never frees
|
||||
* the filters array itself.
|
||||
*/
|
||||
extern LZMA_API(void) lzma_filters_free(
|
||||
lzma_filter *filters, const lzma_allocator *allocator)
|
||||
lzma_nothrow;
|
||||
|
||||
|
||||
/**
|
||||
* \brief Calculate approximate memory requirements for raw encoder
|
||||
*
|
||||
|
|
|
@ -205,6 +205,32 @@ error:
|
|||
}
|
||||
|
||||
|
||||
extern LZMA_API(void)
|
||||
lzma_filters_free(lzma_filter *filters, const lzma_allocator *allocator)
|
||||
{
|
||||
if (filters == NULL)
|
||||
return;
|
||||
|
||||
for (size_t i = 0; filters[i].id != LZMA_VLI_UNKNOWN; ++i) {
|
||||
if (i == LZMA_FILTERS_MAX) {
|
||||
// The API says that LZMA_FILTERS_MAX + 1 is the
|
||||
// maximum allowed size including the terminating
|
||||
// element. Thus, we should never get here but in
|
||||
// case there is a bug and we do anyway, don't go
|
||||
// past the (probable) end of the array.
|
||||
assert(0);
|
||||
break;
|
||||
}
|
||||
|
||||
lzma_free(filters[i].options, allocator);
|
||||
filters[i].options = NULL;
|
||||
filters[i].id = LZMA_VLI_UNKNOWN;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
static lzma_ret
|
||||
validate_chain(const lzma_filter *filters, size_t *count)
|
||||
{
|
||||
|
|
|
@ -114,4 +114,5 @@ global:
|
|||
lzma_file_info_decoder;
|
||||
lzma_stream_decoder_mt;
|
||||
lzma_lzip_decoder;
|
||||
lzma_filters_free;
|
||||
} XZ_5.2;
|
||||
|
|
|
@ -129,4 +129,5 @@ global:
|
|||
lzma_file_info_decoder;
|
||||
lzma_stream_decoder_mt;
|
||||
lzma_lzip_decoder;
|
||||
lzma_filters_free;
|
||||
} XZ_5.2;
|
||||
|
|
Loading…
Reference in a new issue