summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Zhu <[email protected]>2024-03-19 17:15:41 -0400
committerPeter Zhu <[email protected]>2024-03-20 10:27:41 -0400
commite07441f05fa05300c2578d4fb4158ff144dc1159 (patch)
tree86f8463e477981f559a0aa71410f4aa1a4d09243
parent6ecee4ec311424e88cd6b6d77e67d709cfcf8421 (diff)
Make rb_aligned_malloc private
It is not used anywhere else.
-rw-r--r--gc.c68
-rw-r--r--internal/gc.h4
2 files changed, 34 insertions, 38 deletions
diff --git a/gc.c b/gc.c
index b6ce6f5f15..3715822d44 100644
--- a/gc.c
+++ b/gc.c
@@ -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)
{
@@ -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)
{
diff --git a/internal/gc.h b/internal/gc.h
index bf248bc002..f86af26594 100644
--- a/internal/gc.h
+++ b/internal/gc.h
@@ -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);