diff options
author | Keith Bostic <keith@wiredtiger.com> | 2016-01-28 04:19:17 -0500 |
---|---|---|
committer | Keith Bostic <keith@wiredtiger.com> | 2016-01-28 04:19:17 -0500 |
commit | 1d0447e18a6707aaefdfa978712048940b0df071 (patch) | |
tree | 1dcb180c0d51440c5f6da3f3033b9dabbad6bf08 /ext | |
parent | 61e169250870c0d45feb6e4b9ca4559fd414c463 (diff) | |
download | mongo-1d0447e18a6707aaefdfa978712048940b0df071.tar.gz |
WT-60: big endian support
Add lz4 and snappy compression support.
Diffstat (limited to 'ext')
-rw-r--r-- | ext/compressors/lz4/lz4_compress.c | 31 | ||||
-rw-r--r-- | ext/compressors/snappy/snappy_compress.c | 34 |
2 files changed, 38 insertions, 27 deletions
diff --git a/ext/compressors/lz4/lz4_compress.c b/ext/compressors/lz4/lz4_compress.c index d070dc3fb79..38c76fe9bb8 100644 --- a/ext/compressors/lz4/lz4_compress.c +++ b/ext/compressors/lz4/lz4_compress.c @@ -31,17 +31,7 @@ #include <stdlib.h> #include <string.h> -#include <wiredtiger.h> -#include <wiredtiger_ext.h> - -/* - * We need to include the configuration file to detect whether this extension - * is being built into the WiredTiger library. - */ -#include "wiredtiger_config.h" -#ifdef _MSC_VER -#define inline __inline -#endif +#include <wt_internal.h> /* Local compressor structure. */ typedef struct { @@ -73,6 +63,22 @@ typedef struct { } LZ4_PREFIX; /* + * lz4_prefix_swap -- + * The additional information is written in little-endian format, handle + * the the conversion. + */ +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); +#endif +} + +/* * lz4_error -- * Output an error message, and return a standard error code. */ @@ -119,6 +125,7 @@ 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; + lz4_prefix_swap(&prefix); memcpy(dst, &prefix, sizeof(LZ4_PREFIX)); *result_lenp = (size_t)lz4_len + sizeof(LZ4_PREFIX); @@ -154,6 +161,7 @@ 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)); + lz4_prefix_swap(&prefix); /* * Decompress, starting after the prefix bytes. Use safe decompression: @@ -268,6 +276,7 @@ lz4_compress_raw(WT_COMPRESSOR *compressor, WT_SESSION *session, prefix.uncompressed_len = (uint32_t)sourceSize; prefix.useful_len = offsets[slot]; prefix.unused = 0; + lz4_prefix_swap(&prefix); memcpy(dst, &prefix, sizeof(LZ4_PREFIX)); *result_slotsp = slot; diff --git a/ext/compressors/snappy/snappy_compress.c b/ext/compressors/snappy/snappy_compress.c index b5a347fce81..3a7477817af 100644 --- a/ext/compressors/snappy/snappy_compress.c +++ b/ext/compressors/snappy/snappy_compress.c @@ -31,14 +31,7 @@ #include <stdlib.h> #include <string.h> -#include <wiredtiger.h> -#include <wiredtiger_ext.h> - -/* - * We need to include the configuration file to detect whether this extension - * is being built into the WiredTiger library. - */ -#include "wiredtiger_config.h" +#include <wt_internal.h> /* Local compressor structure. */ typedef struct { @@ -103,16 +96,22 @@ wt_snappy_compress(WT_COMPRESSOR *compressor, WT_SESSION *session, snret = snappy_compress((char *)src, src_len, snapbuf, &snaplen); if (snret == SNAPPY_OK) { - /* - * On decompression, snappy requires the exact compressed byte - * count (the current value of snaplen). WiredTiger does not - * preserve that value, so save snaplen at the beginning of the - * destination buffer. - */ if (snaplen + sizeof(size_t) < src_len) { - *(size_t *)dst = snaplen; *result_lenp = snaplen + sizeof(size_t); *compression_failed = 0; + + /* + * On decompression, snappy requires an exact compressed + * byte count (the current value of snaplen). WiredTiger + * does not preserve that value, so save snaplen at the + * beginning of the destination buffer. + * + * Store the value in little-endian format. + */ +#ifdef WORDS_BIGENDIAN + snaplen = __wt_bswap64(snaplen); +#endif + *(size_t *)dst = snaplen; } else /* The compressor failed to produce a smaller result. */ *compression_failed = 1; @@ -137,8 +136,11 @@ wt_snappy_decompress(WT_COMPRESSOR *compressor, WT_SESSION *session, wt_api = ((SNAPPY_COMPRESSOR *)compressor)->wt_api; - /* retrieve the saved length */ + /* Retrieve the saved length, converting endian-ness as necessary. */ snaplen = *(size_t *)src; +#ifdef WORDS_BIGENDIAN + snaplen = __wt_bswap64(snaplen); +#endif if (snaplen + sizeof(size_t) > src_len) { (void)wt_api->err_printf(wt_api, session, |