From 36f49eb2b48d855fd168bf5371c9932e35c8029b Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Wed, 11 Dec 2024 14:32:43 -0800 Subject: [PATCH] Fix compilation with MALLOC_ALLOCATED_SIZE Previously compilation failed with -DMALLOC_ALLOCATED_SIZE=1 Co-authored-by: Matthew Draper --- gc/default/default.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/gc/default/default.c b/gc/default/default.c index aabf48f66c..9f4e9fd6e5 100644 --- a/gc/default/default.c +++ b/gc/default/default.c @@ -8037,9 +8037,9 @@ objspace_malloc_increase_body(rb_objspace_t *objspace, void *mem, size_t new_siz } else { size_t dec_size = old_size - new_size; - size_t allocated_size = objspace->malloc_params.allocated_size; #if MALLOC_ALLOCATED_SIZE_CHECK + size_t allocated_size = objspace->malloc_params.allocated_size; if (allocated_size < dec_size) { rb_bug("objspace_malloc_increase: underflow malloc_params.allocated_size."); } @@ -9286,7 +9286,8 @@ rb_gc_impl_objspace_free(void *objspace_ptr) static VALUE gc_malloc_allocated_size(VALUE self) { - return UINT2NUM(rb_objspace.malloc_params.allocated_size); + rb_objspace_t *objspace = (rb_objspace_t *)rb_gc_get_objspace(); + return ULL2NUM(objspace->malloc_params.allocated_size); } /* @@ -9301,7 +9302,8 @@ gc_malloc_allocated_size(VALUE self) static VALUE gc_malloc_allocations(VALUE self) { - return UINT2NUM(rb_objspace.malloc_params.allocations); + rb_objspace_t *objspace = (rb_objspace_t *)rb_gc_get_objspace(); + return ULL2NUM(objspace->malloc_params.allocations); } #endif