aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYann Collet <Cyan4973@users.noreply.github.com>2022-08-05 21:36:57 +0200
committerGitHub <noreply@github.com>2022-08-05 21:36:57 +0200
commitca26930a91e5b1d47d725b1043e1f5282fd18aaf (patch)
treeba818aeea6d8442544783c4b8fe1fde46fd6b737
parentf7b1f6b7420822255b09acdd1b82848b12e1cda1 (diff)
parent9173ca37d793a6cbb1e5a8657d8e6ebafc53230c (diff)
downloadlz4-ca26930a91e5b1d47d725b1043e1f5282fd18aaf.tar.gz
Merge pull request #1124 from t-mat/compile-time-purge-memalloc-func
Introduce LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION
-rw-r--r--lib/lz4.c14
-rw-r--r--lib/lz4hc.c2
2 files changed, 15 insertions, 1 deletions
diff --git a/lib/lz4.c b/lib/lz4.c
index de0194fe..5fae0029 100644
--- a/lib/lz4.c
+++ b/lib/lz4.c
@@ -188,7 +188,11 @@
/*-************************************
* Memory routines
**************************************/
-#ifdef LZ4_USER_MEMORY_FUNCTIONS
+#if defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
+# define ALLOC(s) lz4_error_memory_allocation_is_disabled
+# define ALLOC_AND_ZERO(s) lz4_error_memory_allocation_is_disabled
+# define FREEMEM(p) lz4_error_memory_allocation_is_disabled
+#elif defined(LZ4_USER_MEMORY_FUNCTIONS)
/* memory management functions can be customized by user project.
* Below functions must exist somewhere in the Project
* and be available at link time */
@@ -1453,6 +1457,7 @@ int LZ4_compress_destSize(const char* src, char* dst, int* srcSizePtr, int targe
* Streaming functions
********************************/
+#if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
LZ4_stream_t* LZ4_createStream(void)
{
LZ4_stream_t* const lz4s = (LZ4_stream_t*)ALLOC(sizeof(LZ4_stream_t));
@@ -1462,6 +1467,7 @@ LZ4_stream_t* LZ4_createStream(void)
LZ4_initStream(lz4s, sizeof(*lz4s));
return lz4s;
}
+#endif
static size_t LZ4_stream_t_alignment(void)
{
@@ -1495,6 +1501,7 @@ void LZ4_resetStream_fast(LZ4_stream_t* ctx) {
LZ4_prepareTable(&(ctx->internal_donotuse), 0, byU32);
}
+#if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
int LZ4_freeStream (LZ4_stream_t* LZ4_stream)
{
if (!LZ4_stream) return 0; /* support free on NULL */
@@ -1502,6 +1509,7 @@ int LZ4_freeStream (LZ4_stream_t* LZ4_stream)
FREEMEM(LZ4_stream);
return (0);
}
+#endif
#define HASH_UNIT sizeof(reg_t)
@@ -2425,6 +2433,7 @@ int LZ4_decompress_safe_doubleDict(const char* source, char* dest, int compresse
/*===== streaming decompression functions =====*/
+#if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
LZ4_streamDecode_t* LZ4_createStreamDecode(void)
{
LZ4_STATIC_ASSERT(sizeof(LZ4_streamDecode_t) >= sizeof(LZ4_streamDecode_t_internal));
@@ -2437,6 +2446,7 @@ int LZ4_freeStreamDecode (LZ4_streamDecode_t* LZ4_stream)
FREEMEM(LZ4_stream);
return 0;
}
+#endif
/*! LZ4_setStreamDecode() :
* Use this function to instruct where to find the dictionary.
@@ -2670,11 +2680,13 @@ int LZ4_resetStreamState(void* state, char* inputBuffer)
return 0;
}
+#if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
void* LZ4_create (char* inputBuffer)
{
(void)inputBuffer;
return LZ4_createStream();
}
+#endif
char* LZ4_slideInputBuffer (void* state)
{
diff --git a/lib/lz4hc.c b/lib/lz4hc.c
index e854cb44..4771ef8f 100644
--- a/lib/lz4hc.c
+++ b/lib/lz4hc.c
@@ -988,6 +988,7 @@ int LZ4_compress_HC_destSize(void* state, const char* source, char* dest, int* s
* Streaming Functions
**************************************/
/* allocation */
+#if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
LZ4_streamHC_t* LZ4_createStreamHC(void)
{
LZ4_streamHC_t* const state =
@@ -1004,6 +1005,7 @@ int LZ4_freeStreamHC (LZ4_streamHC_t* LZ4_streamHCPtr)
FREEMEM(LZ4_streamHCPtr);
return 0;
}
+#endif
LZ4_streamHC_t* LZ4_initStreamHC (void* buffer, size_t size)