Author: pmichaud
Date: Fri Jan 9 07:30:41 2009
New Revision: 35308
Modified:
trunk/src/pmc/class.pmc
trunk/src/pmc/codestring.pmc
trunk/src/pmc/role.pmc
trunk/src/pmc/sub.pmc
trunk/t/pmc/codestring.t
Log:
[core]: Changes to core merged from rvar2 branch.
Modified: trunk/src/pmc/class.pmc
==============================================================================
--- trunk/src/pmc/class.pmc (original)
+++ trunk/src/pmc/class.pmc Fri Jan 9 07:30:41 2009
@@ -923,8 +923,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);
}
/*
Modified: trunk/src/pmc/codestring.pmc
==============================================================================
--- trunk/src/pmc/codestring.pmc (original)
+++ trunk/src/pmc/codestring.pmc Fri Jan 9 07:30:41 2009
@@ -214,31 +214,32 @@
STRING *semi = CONST_STRING(INTERP, ";");
STRING *close_bracket = CONST_STRING(INTERP, "]");
STRING *s_array = CONST_STRING(INTERP, "array");
- STRING *prefix = open_bracket;
- STRING *out = CONST_STRING(INTERP, "");
+ STRING *prefix = NULL;
+ STRING *out = open_bracket;
INTVAL elements, index;
elements = VTABLE_elements(INTERP, args);
for (index = 0; index < elements; index++) {
PMC *P0 = VTABLE_get_pmc_keyed_int(INTERP, args, index);
- if (VTABLE_does(interp, P0, s_array)) {
+ if (PMC_IS_NULL(P0)) continue;
+ else if (VTABLE_does(interp, P0, s_array)) {
INTVAL elements2, index2;
elements2 = VTABLE_elements(INTERP, P0);
for (index2 = 0; index2 < elements2; index2++) {
STRING *S0 = VTABLE_get_string_keyed_int(INTERP, P0, index2);
- out = string_append(INTERP, out, prefix);
(STRING *S0) = PCCINVOKE(INTERP, SELF, "escape", STRING *S0);
- out = string_append(INTERP, out, S0);
- prefix = semi;
+ if (prefix) out = string_append(INTERP, out, prefix);
+ out = string_append(INTERP, out, S0);
+ prefix = semi;
}
}
else {
STRING *S0 = VTABLE_get_string_keyed_int(INTERP, args, index);
- out = string_append(INTERP, out, prefix);
(STRING *S0) = PCCINVOKE(INTERP, SELF, "escape", STRING *S0);
- out = string_append(INTERP, out, S0);
- prefix = semi;
+ if (prefix) out = string_append(INTERP, out, prefix);
+ out = string_append(INTERP, out, S0);
+ prefix = semi;
}
}
Modified: trunk/src/pmc/role.pmc
==============================================================================
--- trunk/src/pmc/role.pmc (original)
+++ trunk/src/pmc/role.pmc Fri Jan 9 07:30:41 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);
}
Modified: trunk/src/pmc/sub.pmc
==============================================================================
--- trunk/src/pmc/sub.pmc (original)
+++ trunk/src/pmc/sub.pmc Fri Jan 9 07:30:41 2009
@@ -385,7 +385,8 @@
PMC_struct_val(ret) = sub;
PMC_pmc_val(ret) = NULL;
memcpy(sub, PMC_sub(SELF), sizeof (Parrot_sub));
- sub->name = string_copy(INTERP, sub->name);
+ if (sub->name != NULL)
+ sub->name = string_copy(INTERP, sub->name);
if (sub->ctx)
Parrot_context_ref(INTERP, sub->ctx);
Modified: trunk/t/pmc/codestring.t
==============================================================================
--- trunk/t/pmc/codestring.t (original)
+++ trunk/t/pmc/codestring.t Fri Jan 9 07:30:41 2009
@@ -19,7 +19,7 @@
.sub main :main
.include 'include/test_more.pir'
- plan(17)
+ plan(20)
create_codestring()
calls_to_unique()
@@ -139,16 +139,24 @@
.local pmc code
code = new ['CodeString']
$S0 = code.'key'('abc')
- is($S0, '["abc"]', "unnested namespace key ok")
+ is($S0, '["abc"]', "unnested namespace key")
$S0 = code.'key'('abc', 'def')
- is($S0, '["abc";"def"]', "nested namespace key ok")
+ is($S0, '["abc";"def"]', "nested namespace key")
$P0 = split ' ', unicode:"abc def T\xe9st"
$S0 = code.'key'($P0 :flat)
- is($S0, '["abc";"def";unicode:"T\x{e9}st"]', "flattened nested unicode ns
key ok")
+ is($S0, '["abc";"def";unicode:"T\x{e9}st"]', "flattened nested unicode ns
key")
$S0 = code.'key'($P0)
- is($S0, '["abc";"def";unicode:"T\x{e9}st"]', "nested unicode ns key ok")
+ is($S0, '["abc";"def";unicode:"T\x{e9}st"]', "nested unicode ns key")
$S0 = code.'key'('_perl6', $P0)
- is($S0, '["_perl6";"abc";"def";unicode:"T\x{e9}st"]', "big ns key ok")
+ is($S0, '["_perl6";"abc";"def";unicode:"T\x{e9}st"]', "big ns key")
+ $S0 = code.'key'('')
+ is($S0, '[""]', "empty string namespace")
+ $P0 = new 'ResizablePMCArray'
+ $S0 = code.'key'($P0)
+ is($S0, '[]', "empty array namespace")
+ null $P0
+ $S0 = code.'key'($P0)
+ is($S0, '[]', "null PMC namespace")
.end
.sub first_char_repl_regression