summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Collet <Cyan4973@users.noreply.github.com>2018-11-16 19:14:46 (GMT)
committerGitHub <noreply@github.com>2018-11-16 19:14:46 (GMT)
commit6686e7597cdf28149a78dcde1efbd91e2323a495 (patch)
tree58267c9b4e70850c36a69cda1c13e87cdc2a59e9
parent1b819bfd633ae285df2dfe1b0589e1ec064f2873 (diff)
parenta7e8d394c0c76d952e3f02f6f33a1fc60be94de6 (diff)
downloadlz4-6686e7597cdf28149a78dcde1efbd91e2323a495.zip
lz4-6686e7597cdf28149a78dcde1efbd91e2323a495.tar.gz
lz4-6686e7597cdf28149a78dcde1efbd91e2323a495.tar.bz2
Merge pull request #600 from antinucleon/bootcamp
Enable amalgamation of lz4hc.c and lz4.c
-rw-r--r--lib/lz4.c15
-rw-r--r--lib/lz4hc.c29
-rw-r--r--tests/Makefile8
3 files changed, 36 insertions, 16 deletions
diff --git a/lib/lz4.c b/lib/lz4.c
index 1521aa2..dd9edcc 100644
--- a/lib/lz4.c
+++ b/lib/lz4.c
@@ -32,6 +32,13 @@
- LZ4 source repository : https://github.com/lz4/lz4
*/
+/*
+ * LZ4_SRC_INCLUDED:
+ * Amalgamation flag, whether lz4.c is included
+ */
+#ifndef LZ4_SRC_INCLUDED
+# define LZ4_SRC_INCLUDED 1
+#endif
/*-************************************
* Tuning parameters
@@ -455,7 +462,13 @@ static const U32 LZ4_skipTrigger = 6; /* Increase this value ==> compression ru
/*-************************************
* Local Structures and types
**************************************/
-typedef enum { notLimited = 0, limitedOutput = 1, fillOutput = 2 } limitedOutput_directive;
+typedef enum {
+ noLimit = 0,
+ notLimited = 1,
+ limitedOutput = 2,
+ fillOutput = 3,
+ limitedDestSize = 4
+} limitedOutput_directive;
typedef enum { clearedTable = 0, byPtr, byU32, byU16 } tableType_t;
/**
diff --git a/lib/lz4hc.c b/lib/lz4hc.c
index d4180e3..56c8f47 100644
--- a/lib/lz4hc.c
+++ b/lib/lz4hc.c
@@ -61,9 +61,21 @@
# pragma clang diagnostic ignored "-Wunused-function"
#endif
+/*=== Enums ===*/
+typedef enum { noDictCtx, usingDictCtxHc } dictCtx_directive;
+#ifndef LZ4_SRC_INCLUDED
+typedef enum {
+ noLimit = 0,
+ limitedOutput = 1,
+ limitedDestSize = 2
+} limitedOutput_directive;
+#endif
+
+
#define LZ4_COMMONDEFS_ONLY
+#ifndef LZ4_SRC_INCLUDED
#include "lz4.c" /* LZ4_count, constants, mem */
-
+#endif
/*=== Constants ===*/
#define OPTIMAL_ML (int)((ML_MASK-1)+MINMATCH)
@@ -79,9 +91,6 @@
static U32 LZ4HC_hashPtr(const void* ptr) { return HASH_FUNCTION(LZ4_read32(ptr)); }
-/*=== Enums ===*/
-typedef enum { noDictCtx, usingDictCtx } dictCtx_directive;
-
/**************************************
* HC Compression
@@ -346,7 +355,7 @@ LZ4HC_InsertAndGetWiderMatch (
} /* while ((matchIndex>=lowestMatchIndex) && (nbAttempts)) */
- if (dict == usingDictCtx && nbAttempts && ipIndex - lowestMatchIndex < MAX_DISTANCE) {
+ if (dict == usingDictCtxHc && nbAttempts && ipIndex - lowestMatchIndex < MAX_DISTANCE) {
size_t const dictEndOffset = dictCtx->end - dictCtx->base;
U32 dictMatchIndex = dictCtx->hashTable[LZ4HC_hashPtr(ip)];
assert(dictEndOffset <= 1 GB);
@@ -394,14 +403,6 @@ int LZ4HC_InsertAndFindBestMatch(LZ4HC_CCtx_internal* const hc4, /* Index tabl
return LZ4HC_InsertAndGetWiderMatch(hc4, ip, ip, iLimit, MINMATCH-1, matchpos, &uselessPtr, maxNbAttempts, patternAnalysis, 0 /*chainSwap*/, dict, favorCompressionRatio);
}
-
-
-typedef enum {
- noLimit = 0,
- limitedOutput = 1,
- limitedDestSize = 2
-} limitedOutput_directive;
-
/* LZ4HC_encodeSequence() :
* @return : 0 if ok,
* 1 if buffer issue detected */
@@ -800,7 +801,7 @@ static int LZ4HC_compress_generic_dictCtx (
ctx->compressionLevel = (short)cLevel;
return LZ4HC_compress_generic_noDictCtx(ctx, src, dst, srcSizePtr, dstCapacity, cLevel, limit);
} else {
- return LZ4HC_compress_generic_internal(ctx, src, dst, srcSizePtr, dstCapacity, cLevel, limit, usingDictCtx);
+ return LZ4HC_compress_generic_internal(ctx, src, dst, srcSizePtr, dstCapacity, cLevel, limit, usingDictCtxHc);
}
}
diff --git a/tests/Makefile b/tests/Makefile
index 989ef85..24dc581 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -152,11 +152,17 @@ endif
DD:=dd
-test: test-lz4 test-lz4c test-frametest test-fullbench test-fuzzer test-install
+test: test-lz4 test-lz4c test-frametest test-fullbench test-fuzzer test-install test-amalgamation
test32: CFLAGS+=-m32
test32: test
+test-amalgamation: $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c
+ cat $(LZ4DIR)/lz4.c > lz4_all.c
+ cat $(LZ4DIR)/lz4hc.c >> lz4_all.c
+ $(CC) -I$(LZ4DIR) -c lz4_all.c
+ $(RM) lz4_all.c
+
test-install: lz4 lib liblz4.pc
lz4_root=.. ./test_install.sh