From acd0a933ad5beacaafeb89025b2e60802e993e43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ste=CC=81phane=20Nicolet?= Date: Tue, 9 Jul 2024 00:48:40 +0200 Subject: [PATCH] Fix compilation on Apple MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Always use the posix function posix_memalign() as aligned memory allocator on Apple computers. This should allow to compile Stockfish out of the box on all versions of Mac OS X. Patch tested on the following systems (apart from the CI) : • Mac OS 10.9.6 (arch x86-64-sse41-popcnt) with gcc-10 • Mac OS 10.13.6 (arch x86-64-bmi2) with gcc-10, gcc-14 and clang-11 • Mac OS 14.1.1 (arch apple-silicon) with clang-15 closes https://github.com/official-stockfish/Stockfish/pull/5462 No functional change --- src/memory.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/memory.cpp b/src/memory.cpp index 565b39b2..1769a661 100644 --- a/src/memory.cpp +++ b/src/memory.cpp @@ -68,12 +68,12 @@ namespace Stockfish { // does not guarantee the availability of aligned_alloc(). Memory allocated with // std_aligned_alloc() must be freed with std_aligned_free(). void* std_aligned_alloc(size_t alignment, size_t size) { - // Apple requires 10.15, which is enforced in the makefile -#if defined(_ISOC11_SOURCE) || defined(__APPLE__) +#if defined(_ISOC11_SOURCE) return aligned_alloc(alignment, size); #elif defined(POSIXALIGNEDALLOC) - void* mem; - return posix_memalign(&mem, alignment, size) ? nullptr : mem; + void* mem = nullptr; + posix_memalign(&mem, alignment, size); + return mem; #elif defined(_WIN32) && !defined(_M_ARM) && !defined(_M_ARM64) return _mm_malloc(size, alignment); #elif defined(_WIN32)