summaryrefslogtreecommitdiffstats
path: root/lib/lz4.c
diff options
context:
space:
mode:
authorYann Collet <cyan@fb.com>2020-11-09 05:17:32 (GMT)
committerYann Collet <cyan@fb.com>2020-11-09 05:17:32 (GMT)
commit52646e8d7517b9b399d3e3719c65816afdc833ab (patch)
treea75a37e6fa5abbb87e721dbfa17755ac7984a9a8 /lib/lz4.c
parentbe634559e3b6bb7bce77cc83ec2080b2bfb6c844 (diff)
downloadlz4-52646e8d7517b9b399d3e3719c65816afdc833ab.zip
lz4-52646e8d7517b9b399d3e3719c65816afdc833ab.tar.gz
lz4-52646e8d7517b9b399d3e3719c65816afdc833ab.tar.bz2
first proposal for LZ4_USER_MEMORY_FUNCTIONS
makes it possible to replace at link time malloc, calloc and free by user-provided functions which must be named LZ4_malloc(), LZ4_calloc() and LZ4_free(). answer #937
Diffstat (limited to 'lib/lz4.c')
-rw-r--r--lib/lz4.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/lz4.c b/lib/lz4.c
index 427673e..a8cc420 100644
--- a/lib/lz4.c
+++ b/lib/lz4.c
@@ -188,10 +188,23 @@
/*-************************************
* Memory routines
**************************************/
-#include <stdlib.h> /* malloc, calloc, free */
-#define ALLOC(s) malloc(s)
-#define ALLOC_AND_ZERO(s) calloc(1,s)
-#define FREEMEM(p) free(p)
+#ifdef 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 */
+void* LZ4_malloc(size_t s);
+void* LZ4_calloc(size_t s);
+void LZ4_free(void* p);
+# define ALLOC(s) LZ4_malloc(s)
+# define ALLOC_AND_ZERO(s) LZ4_calloc(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 */
#define MEM_INIT(p,v,s) memset((p),(v),(s))