This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #114020, #90018, #53186] Make given alias $_
[perl5.git] / pp_ctl.c
index ca953ad..cb549fa 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -4273,8 +4273,15 @@ PP(pp_entergiven)
     ENTER_with_name("given");
     SAVETMPS;
 
-    SAVECLEARSV(PAD_SVl(PL_op->op_targ));
-    sv_setsv_mg(PAD_SV(PL_op->op_targ), POPs);
+    if (PL_op->op_targ) {
+       SAVEPADSVANDMORTALIZE(PL_op->op_targ);
+       SvREFCNT_dec(PAD_SVl(PL_op->op_targ));
+       PAD_SVl(PL_op->op_targ) = SvREFCNT_inc_NN(POPs);
+    }
+    else {
+       SAVE_DEFSV;
+       DEFSV_set(POPs);
+    }
 
     PUSHBLOCK(cx, CXt_GIVEN, SP);
     PUSHGIVEN(cx);