[svn:parrot] r39056 - in branches/tt_696: include/parrot src

whiteknight at svn.parrot.org whiteknight at svn.parrot.org
Fri May 22 22:01:05 UTC 2009


Author: whiteknight
Date: Fri May 22 22:01:04 2009
New Revision: 39056
URL: https://trac.parrot.org/parrot/changeset/39056

Log:
[tt_696] add logic to Parrot_oo_clone_object to allow an optional destination PMC to be supplied, instead of creating a new one. This allows the function to act like reuse_pmc, but to dtrt

Modified:
   branches/tt_696/include/parrot/oo.h
   branches/tt_696/src/oo.c

Modified: branches/tt_696/include/parrot/oo.h
==============================================================================
--- branches/tt_696/include/parrot/oo.h	Fri May 22 21:54:22 2009	(r39055)
+++ branches/tt_696/include/parrot/oo.h	Fri May 22 22:01:04 2009	(r39056)
@@ -135,7 +135,7 @@
 PARROT_WARN_UNUSED_RESULT
 PMC * Parrot_oo_clone_object(PARROT_INTERP,
     ARGIN(PMC * pmc),
-    ARGIN_NULLOK(PMC * to))
+    ARGIN_NULLOK(PMC * dest))
         __attribute__nonnull__(1)
         __attribute__nonnull__(2);
 

Modified: branches/tt_696/src/oo.c
==============================================================================
--- branches/tt_696/src/oo.c	Fri May 22 21:54:22 2009	(r39055)
+++ branches/tt_696/src/oo.c	Fri May 22 22:01:04 2009	(r39056)
@@ -251,7 +251,7 @@
 
 /*
 
-=item C<PMC * Parrot_oo_clone_object(PARROT_INTERP, PMC * pmc, PMC * to)>
+=item C<PMC * Parrot_oo_clone_object(PARROT_INTERP, PMC * pmc, PMC * dest)>
 
 =cut
 
@@ -261,7 +261,7 @@
 PARROT_WARN_UNUSED_RESULT
 PMC *
 Parrot_oo_clone_object(PARROT_INTERP, ARGIN(PMC * pmc),
-    ARGIN_NULLOK(PMC * to))
+    ARGIN_NULLOK(PMC * dest))
 {
     Parrot_Object_attributes * const obj = PARROT_OBJECT(pmc);
     Parrot_Class_attributes  * const _class    = PARROT_CLASS(obj->_class);
@@ -270,7 +270,14 @@
     Parrot_Object_attributes * cloned_guts;
     INTVAL i, num_attrs;
 
-    cloned = pmc_new_noinit(interp, enum_class_Object);
+    if(!PMC_IS_NULL(dest)) {
+        dest->vtable = pmc->vtable;
+        if(!dest->pmc_ext)
+            Parrot_gc_add_pmc_ext(interp, dest);
+        cloned = dest;
+    }
+    else
+        cloned = pmc_new_noinit(interp, enum_class_Object);
 
     /* Set custom GC mark and destroy on the object. */
     PObj_custom_mark_SET(cloned);


More information about the parrot-commits mailing list