From 4c2ae6e2adb40c39276cac860658495f9fa7d967 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Thu, 9 Apr 2026 11:48:57 -0700 Subject: Always ensure room in rb_obj_embedded_size Although the issue only occurred on debug builds, we should always be requesting a size large enough to fit the object when it expands to the heap, rather than just hoping the GC provides enough room. --- internal/object.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/object.h b/internal/object.h index 3cf58d55d9..99aa1f524b 100644 --- a/internal/object.h +++ b/internal/object.h @@ -64,9 +64,9 @@ RBASIC_SET_CLASS(VALUE obj, VALUE klass) static inline size_t rb_obj_embedded_size(uint32_t fields_count) { -#if (defined(RACTOR_CHECK_MODE) && RACTOR_CHECK_MODE) || (defined(GC_DEBUG) && GC_DEBUG) - if (fields_count < 1) fields_count = 1; -#endif - return offsetof(struct RObject, as.ary) + (sizeof(VALUE) * fields_count); + size_t size = offsetof(struct RObject, as.ary) + (sizeof(VALUE) * fields_count); + // Ensure enough room for the heap pointer if this expands + if (size < sizeof(struct RObject)) size = sizeof(struct RObject); + return size; } #endif /* INTERNAL_OBJECT_H */ -- cgit v1.2.3