Skip to content

Commit

Permalink
XS_Tie_Hash_NamedCapture_STORE should always croak on invalid paramet…
Browse files Browse the repository at this point in the history
…ers.

Previously, it would return undef instead of calling Perl_croak_no_modify() if
PL_localizing was true. However, that case can never be reached. PL_localizing
is set non-zero for

1: Perl_mg_localize and PL_save_scalar, for the duration of executing the local
2: Perl_leave_scope for the duration of unwinding the local

However, XS_Tie_Hash_NamedCapture_STORE can't be reached in either case, with
PL_curpm NULL (or otherwise invalid) || !SvROK(ST(0)).

Case 1 would be the call to save_helem_flags() in pp_helem. However, this is
only reached if preeminent is TRUE, which will only hold if hv_exists_ent()
has already returned TRUE, which will only be possible if PL_curpm and ST(0)
are valid.

Case 2 would be the case SAVEt_HELEM in Perl_leave_scope(). However, this
case is only reached as part of the unwinding from Case 1 above, so again
PL_curpm and ST(0) will be valid, for this dynamic scope.

This commit is the patch proposed in RT ##77610. It does not resolve all issues
in that ticket.

Currently C<local $1> is legal - it's a runtime no-op, which neither errors
*nor* resets $1 to undef. Clearly C<local $+{k}> is inconsistent with this,
(as it errors at scope exit for all cases, and additionally errors at local
time if $+{k} exists) but I consider it not worth fixing until we decide
whether C<local $1>'s current behaviour is a "bug" or a "feature".
  • Loading branch information
nwc10 committed Oct 12, 2010
1 parent 8abccac commit f84ff04
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions universal.c
Expand Up @@ -1307,10 +1307,7 @@ XS(XS_Tie_Hash_NamedCapture_STORE)
rx = PL_curpm ? PM_GETRE(PL_curpm) : NULL;

if (!rx || !SvROK(ST(0))) {
if (!PL_localizing)
Perl_croak_no_modify(aTHX);
else
XSRETURN_UNDEF;
Perl_croak_no_modify(aTHX);
}

SP -= items;
Expand Down

0 comments on commit f84ff04

Please sign in to comment.