From: Nathan Moinvaziri Date: Tue, 28 Jan 2020 06:10:49 +0000 (-0800) Subject: Support aligned alloc/free functions for Windows and define them only if MZ_ZALLOC... X-Git-Tag: 1.9.9-b1~367 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=98666ba14a3a9a1f927dbc56090cbc7816c19504;p=thirdparty%2Fzlib-ng.git Support aligned alloc/free functions for Windows and define them only if MZ_ZALLOC is not defined. --- diff --git a/zutil.c b/zutil.c index e2da87f9d..8e2e66444 100644 --- a/zutil.c +++ b/zutil.c @@ -10,9 +10,6 @@ #ifdef WITH_GZFILEOP # include "gzguts.h" #endif -#ifndef UNALIGNED_OK -# include -#endif const char * const zng_errmsg[10] = { (const char *)"need dictionary", /* Z_NEED_DICT 2 */ @@ -111,10 +108,22 @@ const char * ZEXPORT PREFIX(zError)(int err) { #ifndef MY_ZCALLOC /* Any system without a special alloc function */ -void ZLIB_INTERNAL *zng_calloc(void *opaque, unsigned items, unsigned size) { +#ifndef UNALIGNED_OK +# include +# if defined(_WIN32) +# define zng_align_alloc(align, size) _aligned_malloc(size, align) +# define zng_align_free(ptr) _aligned_free(ptr) +# else +# define zng_align_alloc memalign +# define zng_align_free(ptr) free(ptr) +# endif +#endif + +void ZLIB_INTERNAL *zng_calloc(void *opaque, unsigned items, unsigned size) +{ (void)opaque; #ifndef UNALIGNED_OK - return memalign(16, items * size); + return zng_align_alloc(16, items * size); #else return sizeof(unsigned int) > 2 ? (void *)malloc(items * size) : (void *)calloc(items, size); @@ -123,7 +132,11 @@ void ZLIB_INTERNAL *zng_calloc(void *opaque, unsigned items, unsigned size) { void ZLIB_INTERNAL zng_cfree(void *opaque, void *ptr) { (void)opaque; +#ifndef UNALIGNED_OK + zng_align_free(ptr); +#else free(ptr); +#endif } #endif /* MY_ZCALLOC */