summaryrefslogtreecommitdiff
path: root/ext/compressors/lz4/lz4_compress.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/compressors/lz4/lz4_compress.c')
-rw-r--r--ext/compressors/lz4/lz4_compress.c41
1 files changed, 31 insertions, 10 deletions
diff --git a/ext/compressors/lz4/lz4_compress.c b/ext/compressors/lz4/lz4_compress.c
index 062307b721a..35159d0fa76 100644
--- a/ext/compressors/lz4/lz4_compress.c
+++ b/ext/compressors/lz4/lz4_compress.c
@@ -26,13 +26,15 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
-#include <wt_internal.h>
-
#include <lz4.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
+#include <wiredtiger_config.h>
+#include <wiredtiger.h>
+#include <wiredtiger_ext.h>
+
/* Local compressor structure. */
typedef struct {
WT_COMPRESSOR compressor; /* Must come first */
@@ -62,6 +64,22 @@ typedef struct {
uint32_t unused; /* Guaranteed to be 0 */
} LZ4_PREFIX;
+#ifdef WORDS_BIGENDIAN
+/*
+ * lz4_bswap32 --
+ * 32-bit unsigned little-endian to/from big-endian value.
+ */
+static inline uint32_t
+lz4_bswap32(uint32_t v)
+{
+ return (
+ ((v << 24) & 0xff000000) |
+ ((v << 8) & 0x00ff0000) |
+ ((v >> 8) & 0x0000ff00) |
+ ((v >> 24) & 0x000000ff)
+ );
+}
+
/*
* lz4_prefix_swap --
* The additional information is written in little-endian format, handle
@@ -70,15 +88,12 @@ typedef struct {
static inline void
lz4_prefix_swap(LZ4_PREFIX *prefix)
{
-#ifdef WORDS_BIGENDIAN
- prefix->compressed_len = __wt_bswap32(prefix->compressed_len);
- prefix->uncompressed_len = __wt_bswap32(prefix->uncompressed_len);
- prefix->useful_len = __wt_bswap32(prefix->useful_len);
- prefix->unused = __wt_bswap32(prefix->unused);
-#else
- WT_UNUSED(prefix);
-#endif
+ prefix->compressed_len = lz4_bswap32(prefix->compressed_len);
+ prefix->uncompressed_len = lz4_bswap32(prefix->uncompressed_len);
+ prefix->useful_len = lz4_bswap32(prefix->useful_len);
+ prefix->unused = lz4_bswap32(prefix->unused);
}
+#endif
/*
* lz4_error --
@@ -127,7 +142,9 @@ lz4_compress(WT_COMPRESSOR *compressor, WT_SESSION *session,
prefix.uncompressed_len = (uint32_t)src_len;
prefix.useful_len = (uint32_t)src_len;
prefix.unused = 0;
+#ifdef WORDS_BIGENDIAN
lz4_prefix_swap(&prefix);
+#endif
memcpy(dst, &prefix, sizeof(LZ4_PREFIX));
*result_lenp = (size_t)lz4_len + sizeof(LZ4_PREFIX);
@@ -163,7 +180,9 @@ lz4_decompress(WT_COMPRESSOR *compressor, WT_SESSION *session,
* decompressed bytes to return from the start of the source buffer.
*/
memcpy(&prefix, src, sizeof(LZ4_PREFIX));
+#ifdef WORDS_BIGENDIAN
lz4_prefix_swap(&prefix);
+#endif
/*
* Decompress, starting after the prefix bytes. Use safe decompression:
@@ -278,7 +297,9 @@ lz4_compress_raw(WT_COMPRESSOR *compressor, WT_SESSION *session,
prefix.uncompressed_len = (uint32_t)sourceSize;
prefix.useful_len = offsets[slot];
prefix.unused = 0;
+#ifdef WORDS_BIGENDIAN
lz4_prefix_swap(&prefix);
+#endif
memcpy(dst, &prefix, sizeof(LZ4_PREFIX));
*result_slotsp = slot;