diff options
author | Yann Collet <Cyan4973@users.noreply.github.com> | 2016-11-12 00:54:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-12 00:54:51 (GMT) |
commit | e528a82f012eb3e5d29fd455c00a88f39613be30 (patch) | |
tree | 05b051553f8936fbb2d35b053dfed54401be01a3 /lib/lz4.h | |
parent | 3d456bdf2a72aa617a66eb32e5c7a54f7cd5cb0c (diff) | |
parent | 85aeb0e4bb9c0b8dd6f6caa00ac2d9c7a4452660 (diff) | |
download | lz4-e528a82f012eb3e5d29fd455c00a88f39613be30.zip lz4-e528a82f012eb3e5d29fd455c00a88f39613be30.tar.gz lz4-e528a82f012eb3e5d29fd455c00a88f39613be30.tar.bz2 |
Merge pull request #267 from terrelln/strict-aliasing
Expose internal types to remove strict aliasing
Diffstat (limited to 'lib/lz4.h')
-rw-r--r-- | lib/lz4.h | 70 |
1 files changed, 68 insertions, 2 deletions
@@ -39,6 +39,12 @@ extern "C" { #endif +/*^*************************** +* Includes +*****************************/ +#include <stddef.h> /* size_t */ + + /** Introduction @@ -106,6 +112,56 @@ LZ4LIB_API const char* LZ4_versionString (void); /*-************************************ + * Private definitions + ************************************** + * Do not use these definitions. + * They are exposed to allow static allocation of `LZ4_stream_t` and `LZ4_streamDecode_t`. + * If you use these definitions in your code, it will break when you upgrade LZ4 to a new version. +**************************************/ +#define LZ4_HASHLOG (LZ4_MEMORY_USAGE-2) +#define LZ4_HASHTABLESIZE (1 << LZ4_MEMORY_USAGE) +#define LZ4_HASH_SIZE_U32 (1 << LZ4_HASHLOG) /* required as macro for static allocation */ + +#if defined(__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) +#include <stdint.h> + +typedef struct { + uint32_t hashTable[LZ4_HASH_SIZE_U32]; + uint32_t currentOffset; + uint32_t initCheck; + const uint8_t* dictionary; + uint8_t* bufferStart; /* obsolete, used for slideInputBuffer */ + uint32_t dictSize; +} LZ4_stream_t_internal; + +typedef struct { + const uint8_t* externalDict; + size_t extDictSize; + const uint8_t* prefixEnd; + size_t prefixSize; +} LZ4_streamDecode_t_internal; + +#else + +typedef struct { + unsigned int hashTable[LZ4_HASH_SIZE_U32]; + unsigned int currentOffset; + unsigned int initCheck; + const unsigned char* dictionary; + unsigned char* bufferStart; /* obsolete, used for slideInputBuffer */ + unsigned int dictSize; +} LZ4_stream_t_internal; + +typedef struct { + const unsigned char* externalDict; + size_t extDictSize; + const unsigned char* prefixEnd; + size_t prefixSize; +} LZ4_streamDecode_t_internal; + +#endif + +/*-************************************ * Simple Functions **************************************/ /*! LZ4_compress_default() : @@ -229,7 +285,12 @@ LZ4LIB_API int LZ4_decompress_safe_partial (const char* source, char* dest, int * note : only allocated directly the structure if you are statically linking LZ4 * If you are using liblz4 as a DLL, please use below construction methods instead. */ -typedef struct { long long table[LZ4_STREAMSIZE_U64]; } LZ4_stream_t; +typedef struct { + union { + long long table[LZ4_STREAMSIZE_U64]; + LZ4_stream_t_internal internal_donotuse; + }; +} LZ4_stream_t; /*! LZ4_resetStream() : * Use this function to init an allocated `LZ4_stream_t` structure @@ -278,7 +339,12 @@ LZ4LIB_API int LZ4_saveDict (LZ4_stream_t* streamPtr, char* safeBuffer, int dict #define LZ4_STREAMDECODESIZE_U64 4 #define LZ4_STREAMDECODESIZE (LZ4_STREAMDECODESIZE_U64 * sizeof(unsigned long long)) -typedef struct { unsigned long long table[LZ4_STREAMDECODESIZE_U64]; } LZ4_streamDecode_t; +typedef struct { + union { + unsigned long long table[LZ4_STREAMDECODESIZE_U64]; + LZ4_streamDecode_t_internal internal_donotuse; + }; +} LZ4_streamDecode_t; /*! * LZ4_streamDecode_t * information structure to track an LZ4 stream. |