From 7341b0146557bccd783484b279569b530c888a14 Mon Sep 17 00:00:00 2001 From: Matt Valentine-House Date: Tue, 26 Jan 2021 16:29:09 +0000 Subject: [PATCH] Add RCLASS_ALLOCATOR Macro --- class.c | 8 ++++---- internal/class.h | 1 + vm_method.c | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/class.c b/class.c index 22f1208179..2a18eabd12 100644 --- a/class.c +++ b/class.c @@ -188,7 +188,7 @@ class_alloc(VALUE flags, VALUE klass) RCLASS_SET_ORIGIN((VALUE)obj, (VALUE)obj); RCLASS_SERIAL(obj) = rb_next_class_serial(); RB_OBJ_WRITE(obj, &RCLASS_REFINED_CLASS(obj), Qnil); - RCLASS_EXT(obj)->allocator = 0; + RCLASS_ALLOCATOR(obj) = 0; return (VALUE)obj; } @@ -372,7 +372,7 @@ rb_mod_init_copy(VALUE clone, VALUE orig) RBASIC_SET_CLASS(clone, rb_singleton_class_clone(orig)); rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone); } - RCLASS_EXT(clone)->allocator = RCLASS_EXT(orig)->allocator; + RCLASS_ALLOCATOR(clone) = RCLASS_ALLOCATOR(orig); copy_tables(clone, orig); if (RCLASS_M_TBL(orig)) { struct clone_method_arg arg; @@ -409,7 +409,7 @@ rb_mod_init_copy(VALUE clone, VALUE orig) RCLASS_M_TBL(clone_p) = RCLASS_M_TBL(p); RCLASS_CONST_TBL(clone_p) = RCLASS_CONST_TBL(p); RCLASS_IV_TBL(clone_p) = RCLASS_IV_TBL(p); - RCLASS_EXT(clone_p)->allocator = RCLASS_EXT(p)->allocator; + RCLASS_ALLOCATOR(clone_p) = RCLASS_ALLOCATOR(p); if (RB_TYPE_P(clone, T_CLASS)) { RCLASS_SET_INCLUDER(clone_p, clone); } @@ -492,7 +492,7 @@ rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach) } RCLASS_SET_SUPER(clone, RCLASS_SUPER(klass)); - RCLASS_EXT(clone)->allocator = RCLASS_EXT(klass)->allocator; + RCLASS_ALLOCATOR(clone) = RCLASS_ALLOCATOR(klass); if (RCLASS_IV_TBL(klass)) { rb_iv_tbl_copy(clone, klass); } diff --git a/internal/class.h b/internal/class.h index 1697ae1276..b05e264ef3 100644 --- a/internal/class.h +++ b/internal/class.h @@ -94,6 +94,7 @@ typedef struct rb_classext_struct rb_classext_t; #define RCLASS_INCLUDER(c) (RCLASS_EXT(c)->includer) #define RCLASS_PARENT_SUBCLASSES(c) (RCLASS_EXT(c)->parent_subclasses) #define RCLASS_MODULE_SUBCLASSES(c) (RCLASS_EXT(c)->module_subclasses) +#define RCLASS_ALLOCATOR(c) (RCLASS_EXT(c)->allocator) #define RICLASS_IS_ORIGIN FL_USER5 #define RCLASS_CLONED FL_USER6 diff --git a/vm_method.c b/vm_method.c index 0064488db7..19852b0951 100644 --- a/vm_method.c +++ b/vm_method.c @@ -941,7 +941,7 @@ void rb_define_alloc_func(VALUE klass, VALUE (*func)(VALUE)) { Check_Type(klass, T_CLASS); - RCLASS_EXT(klass)->allocator = func; + RCLASS_ALLOCATOR(klass) = func; } void @@ -956,7 +956,7 @@ rb_get_alloc_func(VALUE klass) Check_Type(klass, T_CLASS); for (; klass; klass = RCLASS_SUPER(klass)) { - rb_alloc_func_t allocator = RCLASS_EXT(klass)->allocator; + rb_alloc_func_t allocator = RCLASS_ALLOCATOR(klass); if (allocator == UNDEF_ALLOC_FUNC) break; if (allocator) return allocator; }