# define LZ4LIB_API __declspec(dllimport) /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
# define LZ4LIB_API __declspec(dllimport) LZ4LIB_VISIBILITY /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
#define LZ4_DECOMPRESS_INPLACE_BUFFER_SIZE(decompressedSize) ((decompressedSize) + LZ4_DECOMPRESS_INPLACE_MARGIN(decompressedSize)) /**< note: presumes that compressedSize < decompressedSize. note2: margin is overestimated a bit, since it could use compressedSize instead */
#ifndef LZ4_DISTANCE_MAX /* history window size; can be user-defined at compile time */
# define LZ4_DISTANCE_MAX 65535 /* set to maximum value by default */
#endif
#define LZ4_COMPRESS_INPLACE_MARGIN (LZ4_DISTANCE_MAX + 32) /* LZ4_DISTANCE_MAX can be safely replaced by srcSize when it's smaller */
#define LZ4_COMPRESS_INPLACE_BUFFER_SIZE(maxCompressedSize) ((maxCompressedSize) + LZ4_COMPRESS_INPLACE_MARGIN) /**< maxCompressedSize is generally LZ4_COMPRESSBOUND(inputSize), but can be set to any lower value, with the risk that compression can fail (return code 0(zero)) */
/* Should the alignment test prove unreliable, for some reason,
* it can be disabled by setting LZ4_ALIGN_TEST to 0 */
#ifndef LZ4_ALIGN_TEST /* can be externally provided */
# define LZ4_ALIGN_TEST 1
#endif
/*-************************************
/*-************************************
* Memory routines
* Memory routines
**************************************/
**************************************/
#include <stdlib.h> /* malloc, calloc, free */
#ifdef LZ4_USER_MEMORY_FUNCTIONS
#define ALLOCATOR(n,s) calloc(n,s)
/* memory management functions can be customized by user project.
#define FREEMEM free
* Below functions must exist somewhere in the Project
* and be available at link time */
void*LZ4_malloc(size_ts);
void*LZ4_calloc(size_tn,size_ts);
voidLZ4_free(void*p);
# define ALLOC(s) LZ4_malloc(s)
# define ALLOC_AND_ZERO(s) LZ4_calloc(1,s)
# define FREEMEM(p) LZ4_free(p)
#else
# include <stdlib.h> /* malloc, calloc, free */
# define ALLOC(s) malloc(s)
# define ALLOC_AND_ZERO(s) calloc(1,s)
# define FREEMEM(p) free(p)
#endif
#include <string.h> /* memset, memcpy */
#include <string.h> /* memset, memcpy */
#define MEM_INIT memset
#define MEM_INIT(p,v,s) memset((p),(v),(s))
/*-************************************
* Common Constants
**************************************/
#define MINMATCH 4
#define WILDCOPYLENGTH 8
#define LASTLITERALS 5 /* see ../doc/lz4_Block_format.md#parsing-restrictions */
#define MFLIMIT 12 /* see ../doc/lz4_Block_format.md#parsing-restrictions */
#define MATCH_SAFEGUARD_DISTANCE ((2*WILDCOPYLENGTH) - MINMATCH) /* ensure it's possible to write 2 x wildcopyLength without overflowing output buffer */
#define FASTLOOP_SAFE_DISTANCE 64
staticconstintLZ4_minLength=(MFLIMIT+1);
#define KB *(1 <<10)
#define MB *(1 <<20)
#define GB *(1U<<30)
#define LZ4_DISTANCE_ABSOLUTE_MAX 65535
#if (LZ4_DISTANCE_MAX > LZ4_DISTANCE_ABSOLUTE_MAX) /* max supported by LZ4 format */
# error "LZ4_DISTANCE_MAX is too big : must be <= 65535"
#endif
#define ML_BITS 4
#define ML_MASK ((1U<<ML_BITS)-1)
#define RUN_BITS (8-ML_BITS)
#define RUN_MASK ((1U<<RUN_BITS)-1)
/*-************************************
* Error detection
**************************************/
#if defined(LZ4_DEBUG) && (LZ4_DEBUG>=1)
# include <assert.h>
#else
# ifndef assert
# define assert(condition) ((void)0)
# endif
#endif
#define LZ4_STATIC_ASSERT(c) { enum { LZ4_static_assert = 1/(int)(!!(c)) }; } /* use after variable declarations */
constU32dictDelta=(dictDirective==usingDictCtx)?startIndex-dictCtx->currentOffset:0;/* make indexes in dictCtx comparable with index in current context */
return0;/* cannot compress within `dst` budget. Stored indexes in hash table are nonetheless fine */
}
if((outputDirective==fillOutput)&&
(unlikely(op+(litLength+240)/255/* litlen */+litLength/* literals */+2/* offset */+1/* token */+MFLIMIT-MINMATCH/* min last literals so last match is <= end - MFLIMIT */>olimit))){
op--;
goto_last_literals;
}
if(litLength>=RUN_MASK){
if(litLength>=RUN_MASK){
intlen=(int)litLength-RUN_MASK;
intlen=(int)(litLength-RUN_MASK);
*token=(RUN_MASK<<ML_BITS);
*token=(RUN_MASK<<ML_BITS);
for(;len>=255;len-=255)*op++=255;
for(;len>=255;len-=255)*op++=255;
*op++=(BYTE)len;
*op++=(BYTE)len;
...
@@ -581,37 +1039,87 @@ LZ4_FORCE_INLINE int LZ4_compress_generic(
...
@@ -581,37 +1039,87 @@ LZ4_FORCE_INLINE int LZ4_compress_generic(
LZ4_STATIC_ASSERT(LZ4_STREAMDECODESIZE>=sizeof(LZ4_streamDecode_t_internal));/* A compilation error here means LZ4_STREAMDECODESIZE is not large enough */