Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allocator.cpp: fix for macOS where aligned_alloc may not be supported #593

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Lib/Allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
#include <cstdlib>
#include <limits>

#ifdef __APPLE__
#include <AvailabilityMacros.h>
#endif

#ifndef INDIVIDUAL_ALLOCATIONS
Lib::SmallObjectAllocator Lib::GLOBAL_SMALL_OBJECT_ALLOCATOR;
#endif
Expand All @@ -47,8 +51,11 @@ void *operator new(size_t size, std::align_val_t align_val) {
throw std::bad_alloc();
ALLOCATED += size;
{
// aligned_alloc is not supported prior to macOS 10.13
#if !defined(__APPLE__) || (defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED >= 101300)
if(void *ptr = std::aligned_alloc(align, size))
return ptr;
#endif

// we might be here because `aligned_alloc` is finicky (Apple, looking at you)
// so try again with `malloc` and hope for good alignment
Expand Down