From f9624e400f638e149f67f13b1894ebf7047d6782 Mon Sep 17 00:00:00 2001 From: Enno Boland Date: Sat, 22 Jul 2023 19:28:34 +0200 Subject: [PATCH] extractor: make buffer an object variable --- include/sqsh_extract_private.h | 12 +++++++----- lib/extract/extract_manager.c | 5 +++-- lib/extract/extractor.c | 9 ++++++--- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/include/sqsh_extract_private.h b/include/sqsh_extract_private.h index fbc3e3b52..f53334809 100644 --- a/include/sqsh_extract_private.h +++ b/include/sqsh_extract_private.h @@ -91,6 +91,7 @@ struct SqshExtractor { /** * @privatesection */ + struct SqshBuffer *buffer; const struct SqshExtractorImpl *impl; size_t block_size; }; @@ -101,29 +102,30 @@ struct SqshExtractor { * @brief Initializes a extractor context. * * @param[out] extractor The context to initialize. + * @param[out] buffer The buffer to store the decompressed data. * @param[in] algorithm_id The id of the compression algorithm to use. * @param[in] block_size The block size to use for the extraction. * * @return 0 on success, a negative value on error. */ SQSH_NO_UNUSED int sqsh__extractor_init( - struct SqshExtractor *extractor, int algorithm_id, size_t block_size); + struct SqshExtractor *extractor, struct SqshBuffer *buffer, + int algorithm_id, size_t block_size); /** * @internal * @memberof SqshExtractor * @brief Decompresses data to a buffer. * - * @param[in] extractor The extractor context to use. - * @param[out] buffer The buffer to store the decompressed data. + * @param[in] extractor The extractor context to use. * @param[in] compressed The compressed data to decompress. * @param[in] compressed_size The size of the compressed data. * * @return 0 on success, a negative value on error. */ SQSH_NO_UNUSED int sqsh__extractor_to_buffer( - const struct SqshExtractor *extractor, struct SqshBuffer *buffer, - const uint8_t *compressed, const size_t compressed_size); + const struct SqshExtractor *extractor, const uint8_t *compressed, + const size_t compressed_size); /** * @internal diff --git a/lib/extract/extract_manager.c b/lib/extract/extract_manager.c index 9c67c1b20..13c1510c0 100644 --- a/lib/extract/extract_manager.c +++ b/lib/extract/extract_manager.c @@ -155,12 +155,13 @@ sqsh__extract_manager_uncompress( } const uint8_t *data = sqsh__map_reader_data(reader); - rv = sqsh__extractor_init(&extractor, compression_id, block_size); + rv = sqsh__extractor_init( + &extractor, &buffer, compression_id, block_size); if (rv < 0) { goto out; } - rv = sqsh__extractor_to_buffer(&extractor, &buffer, data, size); + rv = sqsh__extractor_to_buffer(&extractor, data, size); if (rv < 0) { sqsh__buffer_cleanup(&buffer); goto out; diff --git a/lib/extract/extractor.c b/lib/extract/extractor.c index ac2bf7b0b..7b69f2dfb 100644 --- a/lib/extract/extractor.c +++ b/lib/extract/extractor.c @@ -62,26 +62,29 @@ extractor_by_id(int id) { int sqsh__extractor_init( - struct SqshExtractor *extractor, int algorithm_id, size_t block_size) { + struct SqshExtractor *extractor, struct SqshBuffer *buffer, + int algorithm_id, size_t block_size) { const struct SqshExtractorImpl *impl = extractor_by_id(algorithm_id); if (impl == NULL) { return -SQSH_ERROR_COMPRESSION_UNSUPPORTED; } extractor->impl = impl; extractor->block_size = block_size; + extractor->buffer = buffer; return 0; } int sqsh__extractor_to_buffer( - const struct SqshExtractor *extractor, struct SqshBuffer *buffer, - const uint8_t *compressed, const size_t compressed_size) { + const struct SqshExtractor *extractor, const uint8_t *compressed, + const size_t compressed_size) { int rv = 0; size_t max_size = extractor->block_size; size_t size = 0; uint8_t *decompressed = NULL; const struct SqshExtractorImpl *impl = extractor->impl; sqsh__extractor_context_t extractor_context = {0}; + struct SqshBuffer *buffer = extractor->buffer; rv = sqsh__buffer_add_capacity(buffer, &decompressed, max_size); if (rv < 0) {