void rb_prepend_module(VALUE klass, VALUE module) { void rb_vm_check_redefinition_by_prepend(VALUE klass); VALUE origin; int changed = 0; rb_frozen_class_p(klass); Check_Type(module, T_MODULE); OBJ_INFECT(klass, module); origin = RCLASS_ORIGIN(klass); if (origin == klass) { origin = class_alloc(T_ICLASS, klass); OBJ_WB_UNPROTECT(origin); /* TODO: conservertive shading. Need more survery. */ RCLASS_SET_SUPER(origin, RCLASS_SUPER(klass)); RCLASS_SET_SUPER(klass, origin); RCLASS_ORIGIN(klass) = origin; RCLASS_M_TBL_WRAPPER(origin) = RCLASS_M_TBL_WRAPPER(klass); RCLASS_M_TBL_INIT(klass); st_foreach(RCLASS_M_TBL(origin), move_refined_method, (st_data_t) RCLASS_M_TBL(klass)); } changed = include_modules_at(klass, klass, module); if (changed < 0) rb_raise(rb_eArgError, "cyclic prepend detected"); if (changed) { rb_vm_check_redefinition_by_prepend(klass); } }
void rb_prepend_module(VALUE klass, VALUE module) { void rb_vm_check_redefinition_by_prepend(VALUE klass); VALUE origin; int changed = 0; rb_frozen_class_p(klass); Check_Type(module, T_MODULE); OBJ_INFECT(klass, module); origin = RCLASS_ORIGIN(klass); if (origin == klass) { origin = class_alloc(T_ICLASS, klass); RCLASS_SET_SUPER(origin, RCLASS_SUPER(klass)); RCLASS_SET_SUPER(klass, origin); RCLASS_ORIGIN(klass) = origin; RCLASS_M_TBL(origin) = RCLASS_M_TBL(klass); RCLASS_M_TBL(klass) = st_init_numtable(); st_foreach(RCLASS_M_TBL(origin), move_refined_method, (st_data_t) RCLASS_M_TBL(klass)); } changed = include_modules_at(klass, klass, module); if (changed < 0) rb_raise(rb_eArgError, "cyclic prepend detected"); if (changed) { rb_clear_cache(); rb_vm_check_redefinition_by_prepend(klass); } }