diff options
author | Yann Collet <cyan@fb.com> | 2020-11-09 05:17:32 (GMT) |
---|---|---|
committer | Yann Collet <cyan@fb.com> | 2020-11-09 05:17:32 (GMT) |
commit | 52646e8d7517b9b399d3e3719c65816afdc833ab (patch) | |
tree | a75a37e6fa5abbb87e721dbfa17755ac7984a9a8 /lib/lz4.c | |
parent | be634559e3b6bb7bce77cc83ec2080b2bfb6c844 (diff) | |
download | lz4-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.c | 21 |
1 files changed, 17 insertions, 4 deletions
@@ -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)) |