Skip to content

Commit

Permalink
Fix NULL PMC accesses in various cases where we have empty blocks. Re…
Browse files Browse the repository at this point in the history
…solves RT#61034.
  • Loading branch information
jnthn committed Feb 13, 2009
1 parent 3e1a5e8 commit 9a5c690
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/parser/actions.pm
Expand Up @@ -332,12 +332,19 @@ method pblock($/) {
));
}
}
## If block has no statements, need to return an undef (so we don't
## get a null PMC access) if it's a lambda (in the non-lambda case,
## it may be a Hash composer).
if $<lambda> {
prevent_null_return($block);
}
make $block;
}

method xblock($/) {
my $pblock := $( $<pblock> );
$pblock.blocktype('immediate');
prevent_null_return($pblock);
my $past := PAST::Op.new(
$( $<EXPR> ), $pblock,
:pasttype('if'),
Expand Down Expand Up @@ -2972,6 +2979,18 @@ sub process_smartmatch($lhs, $rhs) {
}
}


# Gives a block an undef to return if it has no statements, to prevent Null
# PMCs being handed back.
sub prevent_null_return($block) {
if +@($block[1]) == 0 {
$block[1].push(PAST::Op.new(
:pasttype('call'),
:name('undef')
));
}
}

# Local Variables:
# mode: cperl
# cperl-indent-level: 4
Expand Down

0 comments on commit 9a5c690

Please sign in to comment.