Skip to content

Commit

Permalink
Utility: HELLO APPLE.
Browse files Browse the repository at this point in the history
  • Loading branch information
mosra committed Mar 22, 2021
1 parent d318345 commit e583e62
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Corrade/Utility/Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@
#include "Corrade/Utility/visibility.h"

#ifdef CORRADE_TARGET_UNIX
#ifdef CORRADE_TARGET_APPLE
#include <stdlib.h>
#else
#include <malloc.h>
#endif
#elif defined(CORRADE_TARGET_WINDOWS)
/* <malloc.h> as well, but I don't want to include all the nasty shit */
extern "C" void* __cdecl _aligned_malloc(size_t, size_t);
Expand Down Expand Up @@ -219,10 +223,12 @@ template<class T, std::size_t alignment> Containers::Array<T> allocateAligned(Co
which seems weird and confusing. Handle that explicitly instead. */
if(!size) return {};

/* aligned_alloc() needs _ISOC11_SOURCE, let's hope it just works. If you
get a compilation error here, please complain -- in that case I need to
switch to posix_memalign(). */
return Containers::Array<T>{static_cast<T*>(aligned_alloc(alignment, size*sizeof(T))), size, Implementation::alignedDeleter<T>};
/* I would use aligned_alloc() but then there's APPLE who comes and says
NO. And on top of everything they DARE to have posix_memalign() in a
different header. */
void* data{};
CORRADE_INTERNAL_ASSERT_OUTPUT(posix_memalign(&data, alignment, size*sizeof(T)) == 0);
return Containers::Array<T>{static_cast<T*>(data), size, Implementation::alignedDeleter<T>};

/* Windows */
#elif defined(CORRADE_TARGET_WINDOWS)
Expand Down

0 comments on commit e583e62

Please sign in to comment.