Skip to content

Commit

Permalink
[Fix](memory) Fix allocator.h compiling failed on mac. (#38562)
Browse files Browse the repository at this point in the history
Fix allocator.h compiling failed on mac which introduced by #37234.
  • Loading branch information
kaka11chen authored Jul 31, 2024
1 parent 4c22f2c commit cd8348d
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion be/src/vec/common/allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@
#if defined(USE_JEMALLOC)
#include <jemalloc/jemalloc.h>
#endif // defined(USE_JEMALLOC)

#ifdef __APPLE__
#include <malloc/malloc.h>
#define GET_MALLOC_SIZE(ptr) malloc_size(ptr)
#else
#include <malloc.h>
#define GET_MALLOC_SIZE(ptr) malloc_usable_size(ptr)
#endif
#include <stdint.h>
#include <string.h>

Expand Down Expand Up @@ -64,6 +71,14 @@
#define MAP_ANONYMOUS MAP_ANON
#endif

#ifndef __THROW
#if __cplusplus
#define __THROW noexcept
#else
#define __THROW
#endif
#endif

static constexpr size_t MMAP_MIN_ALIGNMENT = 4096;
static constexpr size_t MALLOC_MIN_ALIGNMENT = 8;

Expand Down Expand Up @@ -106,7 +121,7 @@ class ORCMemoryAllocator {

static constexpr bool need_record_actual_size() { return true; }

static size_t allocated_size(void* ptr) { return malloc_usable_size(ptr); }
static size_t allocated_size(void* ptr) { return GET_MALLOC_SIZE(ptr); }

static int posix_memalign(void** ptr, size_t alignment, size_t size) __THROW {
return ::posix_memalign(ptr, alignment, size);
Expand Down

0 comments on commit cd8348d

Please sign in to comment.