Skip to content

Commit

Permalink
Make rb_aligned_malloc private
Browse files Browse the repository at this point in the history
It is not used anywhere else.
  • Loading branch information
peterzhu2118 committed Mar 20, 2024
1 parent 6ecee4e commit e07441f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 38 deletions.
68 changes: 34 additions & 34 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2104,6 +2104,40 @@ heap_page_free(rb_objspace_t *objspace, struct heap_page *page)
free(page);
}

static void *
rb_aligned_malloc(size_t alignment, size_t size)
{
/* alignment must be a power of 2 */
GC_ASSERT(((alignment - 1) & alignment) == 0);
GC_ASSERT(alignment % sizeof(void*) == 0);

void *res;

#if defined __MINGW32__
res = __mingw_aligned_malloc(size, alignment);
#elif defined _WIN32
void *_aligned_malloc(size_t, size_t);
res = _aligned_malloc(size, alignment);
#elif defined(HAVE_POSIX_MEMALIGN)
if (posix_memalign(&res, alignment, size) != 0) {
return NULL;
}
#elif defined(HAVE_MEMALIGN)
res = memalign(alignment, size);
#else
char* aligned;
res = malloc(alignment + size + sizeof(void*));
aligned = (char*)res + alignment + sizeof(void*);
aligned -= ((VALUE)aligned & (alignment - 1));
((void**)aligned)[-1] = res;
res = (void*)aligned;
#endif

GC_ASSERT((uintptr_t)res % alignment == 0);

return res;
}

static void
heap_pages_free_unused_pages(rb_objspace_t *objspace)
{
Expand Down Expand Up @@ -11630,40 +11664,6 @@ rb_memerror(void)
EC_JUMP_TAG(ec, TAG_RAISE);
}

void *
rb_aligned_malloc(size_t alignment, size_t size)
{
/* alignment must be a power of 2 */
GC_ASSERT(((alignment - 1) & alignment) == 0);
GC_ASSERT(alignment % sizeof(void*) == 0);

void *res;

#if defined __MINGW32__
res = __mingw_aligned_malloc(size, alignment);
#elif defined _WIN32
void *_aligned_malloc(size_t, size_t);
res = _aligned_malloc(size, alignment);
#elif defined(HAVE_POSIX_MEMALIGN)
if (posix_memalign(&res, alignment, size) != 0) {
return NULL;
}
#elif defined(HAVE_MEMALIGN)
res = memalign(alignment, size);
#else
char* aligned;
res = malloc(alignment + size + sizeof(void*));
aligned = (char*)res + alignment + sizeof(void*);
aligned -= ((VALUE)aligned & (alignment - 1));
((void**)aligned)[-1] = res;
res = (void*)aligned;
#endif

GC_ASSERT((uintptr_t)res % alignment == 0);

return res;
}

static void
rb_aligned_free(void *ptr, size_t size)
{
Expand Down
4 changes: 0 additions & 4 deletions internal/gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,6 @@ VALUE rb_objspace_gc_enable(struct rb_objspace *);
VALUE rb_objspace_gc_disable(struct rb_objspace *);
void ruby_gc_set_params(void);
void rb_copy_wb_protected_attribute(VALUE dest, VALUE obj);
#if __has_attribute(alloc_align)
__attribute__((__alloc_align__(1)))
#endif
RUBY_ATTR_MALLOC void *rb_aligned_malloc(size_t, size_t) RUBY_ATTR_ALLOC_SIZE((2));
size_t rb_size_mul_or_raise(size_t, size_t, VALUE); /* used in compile.c */
size_t rb_size_mul_add_or_raise(size_t, size_t, size_t, VALUE); /* used in iseq.h */
size_t rb_malloc_grow_capa(size_t current_capacity, size_t type_size);
Expand Down

0 comments on commit e07441f

Please sign in to comment.