From: Nicholas Clark <nick@ccl4.org>
Date: Wed, 20 May 2009 14:17:19 +0000 (+0200)
Subject: Perl_magic_clearsig() needs to remove magic, else delete $SIG{INT} returns undef
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=179c85a2d774d3be8975d7f80a3ae831be6dc4cd;p=p5sagit%2Fp5-mst-13.2.git

Perl_magic_clearsig() needs to remove magic, else delete $SIG{INT} returns undef
instead of the now-removed INT handler.
---

diff --git a/mg.c b/mg.c
index 54679f8..025061f 100644
--- a/mg.c
+++ b/mg.c
@@ -1328,7 +1328,8 @@ Perl_magic_clearsig(pTHX_ SV *sv, MAGIC *mg)
 #endif
 	}
     }
-    return 0;
+
+    return sv_unmagic(sv, mg->mg_type);
 }
 
 Signal_t
diff --git a/t/op/magic.t b/t/op/magic.t
index f8d0e24..a2608f6 100755
--- a/t/op/magic.t
+++ b/t/op/magic.t
@@ -11,8 +11,7 @@ BEGIN {
 use warnings;
 use Config;
 
-
-plan (tests => 59);
+plan (tests => 79);
 
 $Is_MSWin32  = $^O eq 'MSWin32';
 $Is_NetWare  = $^O eq 'NetWare';
@@ -470,3 +469,28 @@ SKIP: {
     is $@, '', 'Assign a shared key to a magic hash';
     $@ and print "# $@";
 }
+
+# Tests for Perl_magic_clearsig
+foreach my $sig (qw(__WARN__ INT)) {
+    $SIG{$sig} = lc $sig;
+    is $SIG{$sig}, 'main::' . lc $sig, "Can assign to $sig";
+    is delete $SIG{$sig}, 'main::' . lc $sig, "Can delete from $sig";
+    is $SIG{$sig}, undef, "$sig is now gone";
+    is delete $SIG{$sig}, undef, "$sig remains gone";
+}
+
+# And now one which doesn't exist;
+{
+    no warnings 'signal';
+    $SIG{HUNGRY} = 'mmm, pie';
+}
+is $SIG{HUNGRY}, 'mmm, pie', 'Can assign to HUNGRY';
+is delete $SIG{HUNGRY}, 'mmm, pie', 'Can delete from HUNGRY';
+is $SIG{HUNGRY}, undef, "HUNGRY is now gone";
+is delete $SIG{HUNGRY}, undef, "HUNGRY remains gone";
+
+# Test deleting signals that we never set
+foreach my $sig (qw(__DIE__ _BOGUS_HOOK PIPE THIRSTY)) {
+    is $SIG{$sig}, undef, "$sig is not present";
+    is delete $SIG{$sig}, undef, "delete of $sig returns undef";
+}