Allow returning of temps and ro’s from lv subs
authorFather Chrysostomos <sprout@cpan.org>
Tue, 31 May 2011 03:43:03 +0000 (20:43 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 31 May 2011 03:43:03 +0000 (20:43 -0700)
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.

pp_hot.c
t/op/sub_lval.t

index 04de368..9730af7 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -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;
index c87b484..6aa516b 100644 (file)
@@ -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 {}
 
@@ -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 $_ = $@;