Skip to content

Commit

Permalink
Kill autovivification in Fixed/ResizablePMCArray.
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanlum committed Dec 31, 2010
1 parent 05fd57c commit 45f9597
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
46 changes: 38 additions & 8 deletions src/pmc/fixedpmcarray.pmc
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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");
}


/*

Expand Down
8 changes: 8 additions & 0 deletions t/pmc/fixedpmcarray.t
Expand Up @@ -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
Expand Down

0 comments on commit 45f9597

Please sign in to comment.