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

Add support for Mac OS < 10.15 #889

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions src/core.c
Original file line number Diff line number Diff line change
@@ -158,6 +158,21 @@ void b2SetAllocator( b2AllocFcn* allocFcn, b2FreeFcn* freeFcn )
// Use 32 byte alignment for everything. Works with 256bit SIMD.
#define B2_ALIGNMENT 32

// handle missing aligned_alloc on macOS versions before 10.15
#if defined ( B2_PLATFORM_MACOS )
__attribute__((weak_import)) void *aligned_alloc(size_t alignment, size_t size);
void* (*aligned_alloc_ptr)() = &aligned_alloc;
void *aligned_alloc_macos_lt_10_15(size_t alignment, size_t size) {
void* ptr = NULL;
if ( posix_memalign( &ptr, alignment, size ) != 0 )
{
// allocation failed, exit the application
exit( EXIT_FAILURE );
}
return ptr;
}
#endif

void* b2Alloc( int size )
{
if ( size == 0 )
@@ -192,6 +207,8 @@ void* b2Alloc( int size )
// allocation failed, exit the application
exit( EXIT_FAILURE );
}
#elif defined( B2_PLATFORM_MACOS )
void* ptr = aligned_alloc_ptr ? aligned_alloc( B2_ALIGNMENT, size32 ) : aligned_alloc_macos_lt_10_15( B2_ALIGNMENT, size32 );
#else
void* ptr = aligned_alloc( B2_ALIGNMENT, size32 );
#endif