From 157b27cfdcdb01215cacfa3d16b2252f3eb889bd Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Wed, 25 Dec 2013 08:34:36 -0600 Subject: [PATCH] Add deprecated compression/decompression functions Don't want to increase the shared library version number as there are no other incompatibilities. --- Makefile.am | 1 + include/wimlib.h | 73 ++++++++++++++++++++++++++------------ src/compat.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 143 insertions(+), 22 deletions(-) create mode 100644 src/compat.c diff --git a/Makefile.am b/Makefile.am index 4ebcf64b..dbbdff64 100644 --- a/Makefile.am +++ b/Makefile.am @@ -20,6 +20,7 @@ libwim_la_LDFLAGS = -version-info 11:0:2 $(WINDOWS_LDFLAGS) libwim_la_SOURCES = \ src/add_image.c \ src/capture_common.c \ + src/compat.c \ src/compress.c \ src/compress_common.c \ src/compress_parallel.c \ diff --git a/include/wimlib.h b/include/wimlib.h index 2245a372..ab1b78b2 100644 --- a/include/wimlib.h +++ b/include/wimlib.h @@ -3760,8 +3760,6 @@ wimlib_write_to_fd(WIMStruct *wim, struct wimlib_compressor_params_header { /** Size of the parameters, in bytes. */ uint32_t size; - - uint32_t reserved; }; /** Header for decompression parameters to pass to wimlib_create_decompressor() @@ -3769,8 +3767,6 @@ struct wimlib_compressor_params_header { struct wimlib_decompressor_params_header { /** Size of the parameters, in bytes. */ uint32_t size; - - uint32_t reserved; }; /** LZX compression parameters that can optionally be passed to @@ -3866,11 +3862,7 @@ struct wimlib_compressor; /** Opaque decompressor handle. */ struct wimlib_decompressor; -/** @} */ - /** - * @ingroup G_compression - * * Set the default compression parameters for the specified compression type. * This will affect both explicit and wimlib-internal calls to * wimlib_create_compressor(). @@ -3894,8 +3886,6 @@ wimlib_set_default_compressor_params(enum wimlib_compression_type ctype, const struct wimlib_compressor_params_header *params); /** - * @ingroup G_compression - * * Allocate a compressor for the specified compression type using the specified * parameters. * @@ -3931,8 +3921,6 @@ wimlib_create_compressor(enum wimlib_compression_type ctype, struct wimlib_compressor **compressor_ret); /** - * @ingroup G_compression - * * Losslessly compress a block of data using a compressor previously created * with wimlib_create_compressor(). * @@ -3957,8 +3945,6 @@ wimlib_compress(const void *uncompressed_data, size_t uncompressed_size, struct wimlib_compressor *compressor); /** - * @ingroup G_compression - * * Free a compressor previously allocated with wimlib_create_compressor(). * * @param compressor @@ -3968,8 +3954,6 @@ extern void wimlib_free_compressor(struct wimlib_compressor *compressor); /** - * @ingroup G_compression - * * Set the default decompression parameters for the specified compression type. * This will affect both explicit and wimlib-internal calls to * wimlib_create_decompressor(). @@ -3993,8 +3977,6 @@ wimlib_set_default_decompressor_params(enum wimlib_compression_type ctype, const struct wimlib_decompressor_params_header *params); /** - * @ingroup G_compression - * * Allocate a decompressor for the specified compression type using the * specified parameters. * @@ -4029,8 +4011,6 @@ wimlib_create_decompressor(enum wimlib_compression_type ctype, struct wimlib_decompressor **decompressor_ret); /** - * @ingroup G_compression - * * Decompress a block of data using a decompressor previously created with * wimlib_create_decompressor(). * @@ -4053,8 +4033,6 @@ wimlib_decompress(const void *compressed_data, size_t compressed_size, struct wimlib_decompressor *decompressor); /** - * @ingroup G_compression - * * Free a decompressor previously allocated with wimlib_create_decompressor(). * * @param decompressor @@ -4064,6 +4042,57 @@ extern void wimlib_free_decompressor(struct wimlib_decompressor *decompressor); +struct wimlib_lzx_params_old; +struct wimlib_lzx_context_old; + +/** Deprecated; do not use. */ +extern int +wimlib_lzx_set_default_params(const struct wimlib_lzx_params_old *params) + _wimlib_deprecated; + +/** Deprecated; do not use. */ +extern int +wimlib_lzx_alloc_context(const struct wimlib_lzx_params_old *params, + struct wimlib_lzx_context_old **ctx_pp) + _wimlib_deprecated; + +/** Deprecated; do not use. */ +extern void +wimlib_lzx_free_context(struct wimlib_lzx_context_old *ctx) + _wimlib_deprecated; + +/** Deprecated; do not use. */ +extern unsigned +wimlib_lzx_compress2(const void *udata, unsigned ulen, void *cdata, + struct wimlib_lzx_context_old *ctx) + _wimlib_deprecated; + +/** Deprecated; do not use. */ +extern unsigned +wimlib_lzx_compress(const void *udata, unsigned ulen, void *cdata) + _wimlib_deprecated; + +/** Deprecated; do not use. */ +extern unsigned +wimlib_xpress_compress(const void *udata, unsigned ulen, void *cdata) + _wimlib_deprecated; + +/** Deprecated; do not use. */ +extern int +wimlib_lzx_decompress(const void *cdata, unsigned clen, + void *udata, unsigned ulen) + _wimlib_deprecated; + +/** Deprecated; do not use. */ +extern int +wimlib_xpress_decompress(const void *cdata, unsigned clen, + void *udata, unsigned ulen) + _wimlib_deprecated; + +/** @} */ + + + #ifdef __cplusplus } #endif diff --git a/src/compat.c b/src/compat.c new file mode 100644 index 00000000..2de1c359 --- /dev/null +++ b/src/compat.c @@ -0,0 +1,91 @@ +/* TODO: Deprecated stuff to delete when shared library version is bumped up */ + +#include "wimlib.h" +#include "wimlib/compiler.h" + +WIMLIBAPI int +wimlib_lzx_set_default_params(const struct wimlib_lzx_params_old *params) +{ + return wimlib_set_default_compressor_params(WIMLIB_COMPRESSION_TYPE_LZX, + (const struct wimlib_compressor_params_header*)params); +} + +WIMLIBAPI int +wimlib_lzx_alloc_context(const struct wimlib_lzx_params_old *params, + struct wimlib_lzx_context_old **ctx_pp) +{ + wimlib_lzx_free_context(*ctx_pp); + *ctx_pp = NULL; + return wimlib_create_compressor(WIMLIB_COMPRESSION_TYPE_LZX, + 32768, + (const struct wimlib_compressor_params_header*)params, + (struct wimlib_compressor**)ctx_pp); +} + +WIMLIBAPI void +wimlib_lzx_free_context(struct wimlib_lzx_context_old *ctx) +{ + wimlib_free_compressor((struct wimlib_compressor*)ctx); +} + +WIMLIBAPI unsigned +wimlib_lzx_compress2(const void *udata, unsigned ulen, void *cdata, + struct wimlib_lzx_context_old *ctx) +{ + return wimlib_compress(udata, ulen, cdata, ulen - 1, + (struct wimlib_compressor*)ctx); +} + +static unsigned +do_compress(const void *udata, unsigned ulen, void *cdata, int ctype) +{ + struct wimlib_compressor *c; + unsigned clen; + + if (wimlib_create_compressor(ctype, 32768, NULL, &c)) + return -1; + clen = wimlib_compress(udata, ulen, cdata, ulen - 1, c); + wimlib_free_compressor(c); + return clen; +} + +WIMLIBAPI unsigned +wimlib_lzx_compress(const void *udata, unsigned ulen, void *cdata) +{ + return do_compress(udata, ulen, cdata, WIMLIB_COMPRESSION_TYPE_LZX); +} + +WIMLIBAPI unsigned +wimlib_xpress_compress(const void *udata, unsigned ulen, void *cdata) +{ + return do_compress(udata, ulen, cdata, WIMLIB_COMPRESSION_TYPE_XPRESS); +} + +static int +do_decompress(const void *cdata, unsigned clen, + void *udata, unsigned ulen, int ctype) +{ + int ret; + struct wimlib_decompressor *dec; + + if (wimlib_create_decompressor(ctype, 32768, NULL, &dec)) + return -1; + ret = wimlib_decompress(cdata, clen, udata, ulen, dec); + wimlib_free_decompressor(dec); + return ret; +} + +WIMLIBAPI int +wimlib_lzx_decompress(const void *cdata, unsigned clen, + void *udata, unsigned ulen) +{ + return do_decompress(cdata, clen, udata, ulen, WIMLIB_COMPRESSION_TYPE_LZX); +} + + +WIMLIBAPI int +wimlib_xpress_decompress(const void *cdata, unsigned clen, + void *udata, unsigned ulen) +{ + return do_decompress(cdata, clen, udata, ulen, WIMLIB_COMPRESSION_TYPE_XPRESS); +} -- 2.43.0