]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Prefer HAVE_ALIGNED_ALLOC when available in zng_alloc
authorNathan Moinvaziri <nathan@nathanm.com>
Thu, 4 Jan 2024 22:32:06 +0000 (14:32 -0800)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Wed, 7 Feb 2024 18:16:28 +0000 (19:16 +0100)
Added some more helpful comments for people who come across this code.

zutil_p.h

index caec91d50d364c887d5b430d156ff0084377cc11..bc6f9698d261ae7d65a8a51d181f4d94a3f03f32 100644 (file)
--- a/zutil_p.h
+++ b/zutil_p.h
 
 /* Function to allocate 16 or 64-byte aligned memory */
 static inline void *zng_alloc(size_t size) {
-#ifdef HAVE_POSIX_MEMALIGN
+#ifdef HAVE_ALIGNED_ALLOC
+    return (void *)aligned_alloc(64, size);  /* Defined in C11 */
+#elif defined(HAVE_POSIX_MEMALIGN)
     void *ptr;
     return posix_memalign(&ptr, 64, size) ? NULL : ptr;
 #elif defined(_WIN32)
     return (void *)_aligned_malloc(size, 64);
 #elif defined(__APPLE__)
-    return (void *)malloc(size);     /* MacOS always aligns to 16 bytes */
-#elif defined(HAVE_ALIGNED_ALLOC)
-    return (void *)aligned_alloc(64, size);
+    /* Fallback for when posix_memalign and aligned_alloc are not available.
+     * On macOS, it always aligns to 16 bytes. */
+    return (void *)malloc(size);
 #else
     return (void *)memalign(64, size);
 #endif