]> wimlib.net Git - wimlib/commitdiff
Call wimlib_global_init() when creating compressors and decompressors
authorEric Biggers <ebiggers3@gmail.com>
Sat, 18 Mar 2023 07:17:54 +0000 (00:17 -0700)
committerEric Biggers <ebiggers3@gmail.com>
Sat, 18 Mar 2023 07:17:54 +0000 (00:17 -0700)
All nontrivial API functions are supposed to call wimlib_global_init().
wimlib_create_compressor() and wimlib_create_decompressor() did not.
Make them do so, so that CPU feature detection can be moved to
wimlib_global_init().

src/compress.c
src/decompress.c

index 1b0d2c9f9aff5d0f04b1537bda5f264b3c9efd89..bced555e7f8a3863666311329d0d6c791f3a18b0 100644 (file)
@@ -122,6 +122,11 @@ wimlib_create_compressor(enum wimlib_compression_type ctype,
 {
        bool destructive;
        struct wimlib_compressor *c;
+       int ret;
+
+       ret = wimlib_global_init(0);
+       if (ret)
+               return ret;
 
        destructive = (compression_level & WIMLIB_COMPRESSOR_FLAG_DESTRUCTIVE);
        compression_level &= ~WIMLIB_COMPRESSOR_FLAG_DESTRUCTIVE;
@@ -146,8 +151,6 @@ wimlib_create_compressor(enum wimlib_compression_type ctype,
        c->ctype = ctype;
        c->max_block_size = max_block_size;
        if (c->ops->create_compressor) {
-               int ret;
-
                if (compression_level == 0)
                        compression_level = default_compression_levels[ctype];
                if (compression_level == 0)
index f255ea92fd503906cd8a6d73480cde25b8c3adeb..974483c3ef016f600c724e171fe8f60452b6e972 100644 (file)
@@ -56,6 +56,11 @@ wimlib_create_decompressor(enum wimlib_compression_type ctype,
                           struct wimlib_decompressor **dec_ret)
 {
        struct wimlib_decompressor *dec;
+       int ret;
+
+       ret = wimlib_global_init(0);
+       if (ret)
+               return ret;
 
        if (!decompressor_ctype_valid(ctype))
                return WIMLIB_ERR_INVALID_COMPRESSION_TYPE;
@@ -73,8 +78,6 @@ wimlib_create_decompressor(enum wimlib_compression_type ctype,
        dec->max_block_size = max_block_size;
        dec->private = NULL;
        if (dec->ops->create_decompressor) {
-               int ret;
-
                ret = dec->ops->create_decompressor(max_block_size,
                                                    &dec->private);
                if (ret) {