Permalink
Browse files

Kill autovivification in Fixed/ResizablePMCArray.

  • Loading branch information...
1 parent 05fd57c commit 45f9597b5dbbe3659fa043e3e49e0439b752bd0f @nolanlum committed Dec 31, 2010
Showing with 46 additions and 8 deletions.
  1. +38 −8 src/pmc/fixedpmcarray.pmc
  2. +8 −0 t/pmc/fixedpmcarray.t
View
46 src/pmc/fixedpmcarray.pmc
@@ -28,6 +28,15 @@ never be set for user arrays.
/* HEADERIZER HFILE: none */
/* HEADERIZER BEGIN: static */
+/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
+
+PARROT_DOES_NOT_RETURN
+static void cannot_autovivify_nested(PARROT_INTERP)
+ __attribute__nonnull__(1);
+
+#define ASSERT_ARGS_cannot_autovivify_nested __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp))
+/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: static */
pmclass FixedPMCArray auto_attrs provides array {
@@ -352,8 +361,9 @@ Returns the PMC value of the element at index C<*key>.
box = SELF.get_pmc_keyed_int(k);
- if (box == NULL)
- box = Parrot_pmc_new(INTERP, enum_class_Undef);
+ /* TT #1561, return NULL early if we must autovivify. */
+ if (PMC_IS_NULL(box))
+ return PMCNULL;
return VTABLE_get_pmc_keyed(INTERP, box, nextkey);
}
@@ -493,9 +503,8 @@ C<value>.
else {
PMC *box = SELF.get_pmc_keyed_int(k);
- /* TT #1295: autovivify an Array and insert it in SELF */
- if (!box)
- box = Parrot_pmc_new(INTERP, SELF.type());
+ if (PMC_IS_NULL(box))
+ cannot_autovivify_nested(INTERP);
VTABLE_set_number_keyed(INTERP, box, nextkey, value);
}
@@ -581,9 +590,8 @@ Sets the PMC at index C<key> to C<value>.
else {
PMC *box = SELF.get_pmc_keyed_int(k);
- /* TT #1295: autovivify an Array and insert it in SELF */
- if (!box)
- box = Parrot_pmc_new(INTERP, SELF.type());
+ if (PMC_IS_NULL(box))
+ cannot_autovivify_nested(INTERP);
VTABLE_set_pmc_keyed(INTERP, box, nextkey, value);
}
@@ -781,6 +789,28 @@ Mark the array.
}
+/*
+
+=back
+
+=head1 Auxiliar functions
+
+=over 4
+
+=item C<static void cannot_autovivify_nested(PARROT_INTERP)>
+
+*/
+
+PARROT_DOES_NOT_RETURN
+static void
+cannot_autovivify_nested(PARROT_INTERP)
+{
+ ASSERT_ARGS(cannot_autovivify_nested)
+ Parrot_ex_throw_from_c_args(interp, NULL,
+ EXCEPTION_INVALID_OPERATION,
+ "Cannot autovivify nested arrays");
+}
+
/*
View
8 t/pmc/fixedpmcarray.t
@@ -235,6 +235,14 @@ out-of-bounds test. Checks INT and PMC keys.
elem_out_string = matrix[0;0]
is(elem_out_string,128)
+ throws_substring(<<'CODE', 'Cannot autovivify nested arrays', 'Autovivification of nested arrays fails')
+ .sub main
+ $P0 = new ['FixedPMCArray']
+ $P0 = 1
+ $P0[0;0] = 1.2
+ .end
+CODE
+
.end
.sub test_equality

0 comments on commit 45f9597

Please sign in to comment.