/* :nodoc: */ static VALUE enumerator_init_copy(VALUE obj, VALUE orig) { struct enumerator *ptr0, *ptr1; if (!OBJ_INIT_COPY(obj, orig)) return obj; ptr0 = enumerator_ptr(orig); if (ptr0->fib) { /* Fibers cannot be copied */ rb_raise(rb_eTypeError, "can't copy execution context"); } TypedData_Get_Struct(obj, struct enumerator, &enumerator_data_type, ptr1); if (!ptr1) { rb_raise(rb_eArgError, "unallocated enumerator"); } ptr1->obj = ptr0->obj; ptr1->meth = ptr0->meth; ptr1->args = ptr0->args; ptr1->fib = 0; ptr1->lookahead = Qundef; ptr1->feedvalue = Qundef; ptr1->size = ptr0->size; ptr1->size_fn = ptr0->size_fn; return obj; }
/* :nodoc: */ VALUE rb_struct_init_copy(VALUE copy, VALUE s) { if (!OBJ_INIT_COPY(copy, s)) return copy; if (RSTRUCT_LEN(copy) != RSTRUCT_LEN(s)) { rb_raise(rb_eTypeError, "struct size mismatch"); } MEMCPY(RSTRUCT_PTR(copy), RSTRUCT_PTR(s), VALUE, RSTRUCT_LEN(copy)); return copy; }
static VALUE lp_init_copy(VALUE dst, VALUE src) { struct wrapped_object *psrc = lp_ptr(src), *pdst; if (!OBJ_INIT_COPY(dst, src)) return dst; TypedData_Get_Struct(dst, struct wrapped_object, &wrapped_object_data_type, pdst); if (!pdst) rb_raise(rb_eArgError, "unallocated proxy"); lp_cpy(pdst, psrc); return dst; }
/* :nodoc: */ VALUE rb_struct_init_copy(VALUE copy, VALUE s) { long i, len; if (!OBJ_INIT_COPY(copy, s)) return copy; if (RSTRUCT_LEN(copy) != RSTRUCT_LEN(s)) { rb_raise(rb_eTypeError, "struct size mismatch"); } for (i=0, len=RSTRUCT_LEN(copy); i<len; i++) { RSTRUCT_SET(copy, i, RSTRUCT_GET(s, i)); } return copy; }
/* :nodoc: */ VALUE rb_mod_init_copy(VALUE clone, VALUE orig) { if (RB_TYPE_P(clone, T_CLASS)) { class_init_copy_check(clone, orig); } if (!OBJ_INIT_COPY(clone, orig)) return clone; if (!FL_TEST(CLASS_OF(clone), FL_SINGLETON)) { RBASIC_SET_CLASS(clone, rb_singleton_class_clone(orig)); rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone); } RCLASS_SET_SUPER(clone, RCLASS_SUPER(orig)); RCLASS_EXT(clone)->allocator = RCLASS_EXT(orig)->allocator; if (RCLASS_IV_TBL(orig)) { st_data_t id; if (RCLASS_IV_TBL(clone)) { st_free_table(RCLASS_IV_TBL(clone)); } RCLASS_IV_TBL(clone) = rb_st_copy(clone, RCLASS_IV_TBL(orig)); CONST_ID(id, "__tmp_classpath__"); st_delete(RCLASS_IV_TBL(clone), &id, 0); CONST_ID(id, "__classpath__"); st_delete(RCLASS_IV_TBL(clone), &id, 0); CONST_ID(id, "__classid__"); st_delete(RCLASS_IV_TBL(clone), &id, 0); } if (RCLASS_CONST_TBL(orig)) { struct clone_const_arg arg; if (RCLASS_CONST_TBL(clone)) { rb_free_const_table(RCLASS_CONST_TBL(clone)); } RCLASS_CONST_TBL(clone) = st_init_numtable(); arg.klass = clone; arg.tbl = RCLASS_CONST_TBL(clone); st_foreach(RCLASS_CONST_TBL(orig), clone_const_i, (st_data_t)&arg); } if (RCLASS_M_TBL(orig)) { if (RCLASS_M_TBL_WRAPPER(clone)) { rb_free_m_tbl_wrapper(RCLASS_M_TBL_WRAPPER(clone)); } RCLASS_M_TBL_INIT(clone); st_foreach(RCLASS_M_TBL(orig), clone_method_i, (st_data_t)clone); } return clone; }
/* :nodoc: */ static VALUE generator_init_copy(VALUE obj, VALUE orig) { struct generator *ptr0, *ptr1; if (!OBJ_INIT_COPY(obj, orig)) return obj; ptr0 = generator_ptr(orig); TypedData_Get_Struct(obj, struct generator, &generator_data_type, ptr1); if (!ptr1) { rb_raise(rb_eArgError, "unallocated generator"); } ptr1->proc = ptr0->proc; return obj; }