develooper Front page | perl.cvs.parrot | Postings from January 2009

[svn:parrot] r35179 - branches/rvar2/src/pmc

From:
jonathan
Date:
January 7, 2009 14:41
Subject:
[svn:parrot] r35179 - branches/rvar2/src/pmc
Message ID:
20090107224103.55FE3CB9F9@x12.develooper.com
Author: jonathan
Date: Wed Jan  7 14:41:02 2009
New Revision: 35179

Modified:
   branches/rvar2/src/pmc/role.pmc

Log:
[core] Roles need shallow copying fix for inspect_str that pmichaud++ did for classes.

Modified: branches/rvar2/src/pmc/role.pmc
==============================================================================
--- branches/rvar2/src/pmc/role.pmc	(original)
+++ branches/rvar2/src/pmc/role.pmc	Wed Jan  7 14:41:02 2009
@@ -431,7 +431,20 @@
         }
 
         /* Clone and return. */
-        return PMC_IS_NULL(found) ? PMCNULL : VTABLE_clone(interp, found);
+        if (PMC_IS_NULL(found)) { return PMCNULL; }
+        if (found->vtable->base_type == enum_class_Hash) {
+            /* for Hash return values, create and return a shallow 
+             * clone because the VTABLE_clone does a deep clone */
+            PMC * const hash = pmc_new(interp, enum_class_Hash);
+            PMC * const iter = VTABLE_get_iter(interp, found);
+            while (VTABLE_get_bool(interp, iter)) {
+                STRING * key = VTABLE_shift_string(interp, iter);
+                PMC * value  = VTABLE_get_pmc_keyed_str(interp, found, key);
+                VTABLE_set_pmc_keyed_str(interp, hash, key, value);
+            }
+            return hash;
+        }
+        return VTABLE_clone(interp, found);
     }
 
 



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About