Author: pmichaud
Date: Sun Jan  4 14:34:07 2009
New Revision: 34942

Modified:
   branches/rvar/src/pmc/class.pmc

Log:
[oo]:  inspect_str on class objects returns shallow-copy hashes


Modified: branches/rvar/src/pmc/class.pmc
==============================================================================
--- branches/rvar/src/pmc/class.pmc     (original)
+++ branches/rvar/src/pmc/class.pmc     Sun Jan  4 14:34:07 2009
@@ -922,8 +922,21 @@
             Parrot_ex_throw_from_c_args(interp, NULL, 
EXCEPTION_INVALID_OPERATION,
                 "Unknown introspection value '%S'", what);
 
-        /* Clone and return. */
-        return PMC_IS_NULL(found) ? PMCNULL : VTABLE_clone(interp, found);
+        /* return found value */
+        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);
     }
 
 /*

Reply via email to