Skip to content

Commit

Permalink
Allow returning of temps and ro’s from lv subs
Browse files Browse the repository at this point in the history
This commit removes the restriction on returning temps and read-only
scalars from lvalue subs that occurs when the sub returns implicitly
(with no ‘return’ statement; ‘return’ has never had that restriction).

It does not actually help pure-Perl lvalue subs much yet, as op.c
still enforces lvalue syntax on the last statement.

But this should fix bug #71172, allowing XS lvalue subs to work under
the debugger.
  • Loading branch information
Father Chrysostomos committed May 31, 2011
1 parent f6a9f8a commit b724cc1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
21 changes: 2 additions & 19 deletions pp_hot.c
Expand Up @@ -2725,27 +2725,10 @@ PP(pp_leavesublv)
MARK = newsp + 1;
EXTEND_MORTAL(1);
if (MARK == SP) {
/* Temporaries are bad unless they happen to have set magic
* attached, such as the elements of a tied hash or array */
if ((SvFLAGS(TOPs) & (SVs_TEMP | SVs_PADTMP) ||
(SvFLAGS(TOPs) & (SVf_READONLY | SVf_FAKE))
== SVf_READONLY
) &&
!SvSMAGICAL(TOPs)) {
LEAVE;
cxstack_ix--;
POPSUB(cx,sv);
PL_curpm = newpm;
LEAVESUB(sv);
DIE(aTHX_ "Can't return %s from lvalue subroutine",
SvREADONLY(TOPs) ? (TOPs == &PL_sv_undef) ? "undef"
: "a readonly value" : "a temporary");
}
else { /* Can be a localized value
* subject to deletion. */
/* Can be a localized value
* subject to deletion. */
PL_tmps_stack[++PL_tmps_ix] = *mark;
SvREFCNT_inc_void(*mark);
}
}
else { /* Should not happen? */
LEAVE;
Expand Down
4 changes: 2 additions & 2 deletions t/op/sub_lval.t
Expand Up @@ -218,7 +218,7 @@ eval <<'EOE' or $_ = $@;
1;
EOE

like($_, qr/Can't return undef from lvalue subroutine/);
like($_, qr/Modification of a read-only value attempted/);

sub lv10 : lvalue {}

Expand All @@ -238,7 +238,7 @@ eval <<'EOE' or $_ = $@;
1;
EOE

like($_, qr/Can't return undef from lvalue subroutine/);
like($_, qr/Modification of a read-only value attempted/);

$_ = undef;
eval <<'EOE' or $_ = $@;
Expand Down

0 comments on commit b724cc1

Please sign in to comment.