This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #122556] Make undef $s free refs forthwith
authorFather Chrysostomos <sprout@cpan.org>
Thu, 28 Aug 2014 13:22:04 +0000 (06:22 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 28 Aug 2014 13:22:20 +0000 (06:22 -0700)
pp.c
t/op/undef.t

diff --git a/pp.c b/pp.c
index 9b8dd90..f86e276 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -972,7 +972,8 @@ PP(pp_undef)
     if (!sv)
        RETPUSHUNDEF;
 
-    SV_CHECK_THINKFIRST_COW_DROP(sv);
+    if (SvTHINKFIRST(sv))
+       sv_force_normal_flags(sv, SV_COW_DROP_PV|SV_IMMEDIATE_UNREF);
 
     switch (SvTYPE(sv)) {
     case SVt_NULL:
index 366c3d2..ddef596 100644 (file)
@@ -10,7 +10,7 @@ use strict;
 
 use vars qw(@ary %ary %hash);
 
-plan 73;
+plan 74;
 
 ok !defined($a);
 
@@ -128,6 +128,23 @@ for (z,z) {
 }
 is $_[0], $_[1], 'undef constants preserve identity';
 
+# [perl #122556]
+my $messages;
+package Thingie;
+DESTROY { $messages .= 'destroyed ' }
+package main;
+sub body {
+    sub {
+        my $t = bless [], 'Thingie';
+        undef $t;
+    }->(), $messages .= 'after ';
+
+    return;
+}
+body();
+is $messages, 'destroyed after ', 'undef $scalar frees refs immediately';
+
+
 # this will segfault if it fails
 
 sub PVBM () { 'foo' }