PARROT_WARN_UNUSED_RESULT PARROT_CANNOT_RETURN_NULL PMC * blizkost_wrap_sv(BLIZKOST_NEXUS, SV *sv) { dBNPERL; dBNINTERP; PMC *wrapper = Parrot_pmc_new_noinit(interp, pmc_type(interp, string_from_literal(interp, "P5Scalar"))); PObj_custom_mark_SET(wrapper); PObj_custom_destroy_SET(wrapper); SETATTR_P5Scalar_nexus(interp, wrapper, nexus); SETATTR_P5Scalar_sv(interp, wrapper, SvREFCNT_inc(sv)); return wrapper; }
PARROT_CANNOT_RETURN_NULL PMC * Parrot_oo_clone_object(PARROT_INTERP, ARGIN(PMC *pmc), ARGMOD_NULLOK(PMC *dest)) { ASSERT_ARGS(Parrot_oo_clone_object) Parrot_Object_attributes *obj = PARROT_OBJECT(pmc); Parrot_Object_attributes *cloned_guts; Parrot_Class_attributes *_class; PMC *cloned; INTVAL num_classes; INTVAL i, num_attrs; if (!PMC_IS_NULL(dest)) { cloned = dest; } else { cloned = Parrot_pmc_new_noinit(interp, enum_class_Object); } _class = PARROT_CLASS(obj->_class); PARROT_ASSERT(_class); num_classes = VTABLE_elements(interp, _class->all_parents); /* Set custom GC mark and destroy on the object. */ PObj_custom_mark_SET(cloned); PObj_custom_destroy_SET(cloned); /* Flag that it is an object */ PObj_is_object_SET(cloned); /* Now clone attributes list.class. */ cloned_guts = (Parrot_Object_attributes *) PMC_data(cloned); cloned_guts->_class = obj->_class; cloned_guts->attrib_store = VTABLE_clone(interp, obj->attrib_store); num_attrs = VTABLE_elements(interp, cloned_guts->attrib_store); for (i = 0; i < num_attrs; ++i) { PMC * const to_clone = VTABLE_get_pmc_keyed_int(interp, cloned_guts->attrib_store, i); if (!PMC_IS_NULL(to_clone)) { VTABLE_set_pmc_keyed_int(interp, cloned_guts->attrib_store, i, VTABLE_clone(interp, to_clone)); } } /* Some of the attributes may have been the PMCs providing storage for any * PMCs we inherited from; also need to clone those. */ if (CLASS_has_alien_parents_TEST(obj->_class)) { int j; /* Locate any PMC parents. */ for (j = 0; j < num_classes; ++j) { PMC * const cur_class = VTABLE_get_pmc_keyed_int(interp, _class->all_parents, j); if (cur_class->vtable->base_type == enum_class_PMCProxy) { /* Clone this PMC too. */ STRING * const proxy = CONST_STRING(interp, "proxy"); VTABLE_set_attr_keyed(interp, cloned, cur_class, proxy, VTABLE_clone(interp, VTABLE_get_attr_keyed(interp, cloned, cur_class, proxy))); } } } /* And we have ourselves a clone. */ return cloned; }