Skip to content

Commit

Permalink
plugin/lz4: Remove use of deprecated items
Browse files Browse the repository at this point in the history
lz4 1.7.0 deprecated a handful of the compression functions and all of
the lz4f configuration enums. Update all usages to the new function
names or enums and add macros that convert the new name to the old name
when compiling against older versions. Remove
squash_lz4_compress_buffer_unsafe since all of the functions used were
deprecated and the replacements are the functions used by
squash_lz4_compress_buffer.
  • Loading branch information
n3world authored and nemequ committed Feb 23, 2017
1 parent 541b9ad commit f7e6320
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
27 changes: 18 additions & 9 deletions plugins/lz4/squash-lz4.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
#include <lz4.h>
#include <lz4hc.h>

#if LZ4_VERSION_NUMBER < 10700
#define LZ4_compress_default LZ4_compress_limitedOutput
#define LZ4_compress_HC LZ4_compressHC2_limitedOutput
#endif

enum SquashLZ4OptIndex {
SQUASH_LZ4_OPT_LEVEL = 0
};
Expand Down Expand Up @@ -148,22 +153,22 @@ squash_lz4_compress_buffer (SquashCodec* codec,
int lz4_r;

if (level == 7) {
lz4_r = LZ4_compress_limitedOutput ((char*) uncompressed,
(char*) compressed,
(int) uncompressed_size,
(int) *compressed_size);
lz4_r = LZ4_compress_default ((char*) uncompressed,
(char*) compressed,
(int) uncompressed_size,
(int) *compressed_size);
} else if (level < 7) {
lz4_r = LZ4_compress_fast ((const char*) uncompressed,
(char*) compressed,
(int) uncompressed_size,
(int) *compressed_size,
squash_lz4_level_to_fast_mode (level));
} else if (level < 17) {
lz4_r = LZ4_compressHC2_limitedOutput ((char*) uncompressed,
(char*) compressed,
(int) uncompressed_size,
(int) *compressed_size,
squash_lz4_level_to_hc_level (level));
lz4_r = LZ4_compress_HC ((char*) uncompressed,
(char*) compressed,
(int) uncompressed_size,
(int) *compressed_size,
squash_lz4_level_to_hc_level (level));
} else {
HEDLEY_UNREACHABLE();
}
Expand All @@ -178,6 +183,7 @@ squash_lz4_compress_buffer (SquashCodec* codec,
return HEDLEY_UNLIKELY(lz4_r == 0) ? squash_error (SQUASH_BUFFER_FULL) : SQUASH_OK;
}

#if LZ4_VERSION_NUMBER < 10700
static SquashStatus
squash_lz4_compress_buffer_unsafe (SquashCodec* codec,
size_t* compressed_size,
Expand Down Expand Up @@ -223,6 +229,7 @@ squash_lz4_compress_buffer_unsafe (SquashCodec* codec,

return (lz4_r == 0) ? SQUASH_BUFFER_FULL : SQUASH_OK;
}
#endif

SquashStatus
squash_plugin_init_codec (SquashCodec* codec, SquashCodecImpl* impl) {
Expand All @@ -233,7 +240,9 @@ squash_plugin_init_codec (SquashCodec* codec, SquashCodecImpl* impl) {
impl->get_max_compressed_size = squash_lz4_get_max_compressed_size;
impl->decompress_buffer = squash_lz4_decompress_buffer;
impl->compress_buffer = squash_lz4_compress_buffer;
#if LZ4_VERSION_NUMBER < 10700
impl->compress_buffer_unsafe = squash_lz4_compress_buffer_unsafe;
#endif
} else {
return squash_plugin_init_lz4f (codec, impl);
}
Expand Down
15 changes: 11 additions & 4 deletions plugins/lz4/squash-lz4f.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
# include <lz4frame.h>
#endif

#if LZ4_VERSION_NUMBER < 10700
#define LZ4F_max64KB max64KB
#define LZ4F_blockLinked blockLinked
#define LZ4F_contentChecksumEnabled contentChecksumEnabled
#define LZ4F_noContentChecksum noContentChecksum
#endif

SquashStatus squash_plugin_init_lz4f (SquashCodec* codec, SquashCodecImpl* impl);

#define SQUASH_LZ4F_DICT_SIZE ((size_t) 65536)
Expand Down Expand Up @@ -177,10 +184,10 @@ squash_lz4f_stream_new (SquashCodec* codec, SquashStreamType stream_type, Squash
stream->data.comp.prefs = (LZ4F_preferences_t) {
{
(LZ4F_blockSizeID_t) squash_options_get_int_at (options, codec, SQUASH_LZ4F_OPT_BLOCK_SIZE),
blockLinked,
LZ4F_blockLinked,
squash_options_get_bool_at (options, codec, SQUASH_LZ4F_OPT_CHECKSUM) ?
contentChecksumEnabled :
noContentChecksum,
LZ4F_contentChecksumEnabled :
LZ4F_noContentChecksum,
},
squash_options_get_int_at (options, codec, SQUASH_LZ4F_OPT_LEVEL)
};
Expand Down Expand Up @@ -446,7 +453,7 @@ squash_lz4f_process_stream (SquashStream* stream, SquashOperation operation) {
static size_t
squash_lz4f_get_max_compressed_size (SquashCodec* codec, size_t uncompressed_size) {
static const LZ4F_preferences_t prefs = {
{ max64KB, blockLinked, contentChecksumEnabled, },
{ LZ4F_max64KB, LZ4F_blockLinked, LZ4F_contentChecksumEnabled, },
0, 0,
};

Expand Down

0 comments on commit f7e6320

Please sign in to comment.