]> wimlib.net Git - wimlib/blobdiff - src/xpress-decompress.c
Generalized support for referencing resources in external WIMs
[wimlib] / src / xpress-decompress.c
index 6756b159465d13e72ce5b071ce3531df7c74ef20..e9aec1361bee7ed61664053995e63c37d09f462f 100644 (file)
  * extra symbol is there or not.
  */
 
-#include "util.h"
-#include "xpress.h"
-#include "wimlib.h"
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
 
+#include "wimlib.h"
+#include "wimlib/assert.h"
 #define XPRESS_DECOMP
-#include "decompress.h"
+#include "wimlib/decompress.h"
+#include "wimlib/util.h"
+#include "wimlib/xpress.h"
 
 /*
  * Decodes a symbol @huffsym that begins an XPRESS match.
@@ -93,8 +97,8 @@
  */
 static int
 xpress_decode_match(unsigned huffsym, unsigned window_pos,
-                   unsigned window_len, u8 window[],
-                   struct input_bitstream *istream)
+                   unsigned window_len, u8 window[restrict],
+                   struct input_bitstream * restrict istream)
 {
        unsigned match_len;
        unsigned match_offset;
@@ -107,7 +111,7 @@ xpress_decode_match(unsigned huffsym, unsigned window_pos,
        unsigned i;
 
        ret = bitstream_read_bits(istream, offset_bsr, &match_offset);
-       if (ret != 0)
+       if (ret)
                return ret;
        match_offset |= (1 << offset_bsr);
 
@@ -143,13 +147,13 @@ xpress_decode_match(unsigned huffsym, unsigned window_pos,
        match_src = match_dest - match_offset;
 
        if (window_pos + match_len > window_len) {
-               ERROR("XPRESS decompression error: match of length %u "
+               DEBUG("XPRESS decompression error: match of length %u "
                      "bytes overflows window", match_len);
                return -1;
        }
 
        if (match_src < window) {
-               ERROR("XPRESS decompression error: match of length %u bytes "
+               DEBUG("XPRESS decompression error: match of length %u bytes "
                      "references data before window (match_offset = %u, "
                      "window_pos = %u)", match_len, match_offset, window_pos);
                return -1;
@@ -164,11 +168,11 @@ xpress_decode_match(unsigned huffsym, unsigned window_pos,
 /* Decodes the Huffman-encoded matches and literal bytes in a block of
  * XPRESS-encoded data. */
 static int
-xpress_decompress_block(struct input_bitstream *istream,
-                       u8 uncompressed_data[],
+xpress_decompress_block(struct input_bitstream * restrict istream,
+                       u8 uncompressed_data[restrict],
                        unsigned uncompressed_len,
-                       const u8 lens[],
-                       const u16 decode_table[])
+                       const u8 lens[restrict],
+                       const u16 decode_table[restrict])
 {
        unsigned curpos;
        unsigned huffsym;
@@ -200,20 +204,21 @@ xpress_decompress_block(struct input_bitstream *istream,
 }
 
 
-/* Documented in wimlib.h */
+/* API function documented in wimlib.h  */
 WIMLIBAPI int
-wimlib_xpress_decompress(const void *__compressed_data, unsigned compressed_len,
-                        void *uncompressed_data, unsigned uncompressed_len)
+wimlib_xpress_decompress(const void * restrict _compressed_data, unsigned compressed_len,
+                        void * restrict uncompressed_data, unsigned uncompressed_len)
 {
        u8 lens[XPRESS_NUM_SYMBOLS];
-       u16 decode_table[(1 << XPRESS_TABLEBITS) + 2 * XPRESS_NUM_SYMBOLS];
+       u16 decode_table[(1 << XPRESS_TABLEBITS) + 2 * XPRESS_NUM_SYMBOLS]
+                       _aligned_attribute(DECODE_TABLE_ALIGNMENT);
        struct input_bitstream istream;
        u8 *lens_p;
        const u8 *compressed_data;
        unsigned i;
        int ret;
 
-       compressed_data = __compressed_data;
+       compressed_data = _compressed_data;
        lens_p = lens;
 
        DEBUG2("compressed_len = %d, uncompressed_len = %d",
@@ -224,7 +229,7 @@ wimlib_xpress_decompress(const void *__compressed_data, unsigned compressed_len,
         * in the first 256 bytes of the compressed data.
         */
        if (compressed_len < XPRESS_NUM_SYMBOLS / 2) {
-               ERROR("xpress_decompress(): Compressed length too short!");
+               DEBUG("xpress_decompress(): Compressed length too short!");
                return -1;
        }