This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #92290, #92406] Returning a pad var from lv sub
[perl5.git] / pp_hot.c
index cd556f3..8d02826 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -2802,7 +2802,9 @@ PP(pp_leavesublv)
                        sv_2mortal(*MARK);
                }
                else
-                   *MARK = TOPs;
+                   *MARK = SvTEMP(TOPs)
+                             ? TOPs
+                             : sv_2mortal(SvREFCNT_inc_simple_NN(TOPs));
            }
            else {
                MEXTEND(MARK, 0);
@@ -2810,6 +2812,13 @@ PP(pp_leavesublv)
            }
            SP = MARK;
        }
+       else if (gimme == G_ARRAY) {
+         rvalue_array:
+           for (MARK = newsp + 1; MARK <= SP; MARK++) {
+               if (!SvTEMP(*MARK))
+                   *MARK = sv_2mortal(SvREFCNT_inc_simple_NN(*MARK));
+           }
+       }
     }
 
     if (CxLVAL(cx) & OPpENTERSUB_DEREF) {
@@ -2829,7 +2838,6 @@ PP(pp_leavesublv)
        }
     }
 
-  rvalue_array:
     PUTBACK;
 
     LEAVE;