New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
%SIG not properly local-ized #8049
Comments
From mb29450@suttles.sca.sfbay.sun.comThis is a bug report for perl from mb29450@suttles.sca.sfbay.sun.com, The construct The program perl -e 'print scalar keys %SIG,"\n"; local %SIG = %SIG; print scalar keys %SIG, "\n"' 49 instead of (something like) 49 as it should. For comparison, another "magic" hash, %ENV, does not have the same problem. perl -e 'print scalar keys %ENV,"\n"; local %ENV = %ENV; print scalar keys %ENV, "\n"' Flags: Site configuration information for perl v5.8.6: Configured by mb29450 at Wed Dec 8 21:44:47 PST 2004. Summary of my perl5 (revision 5 version 8 subversion 6) configuration: Locally applied patches: @INC for perl v5.8.6: Environment for perl v5.8.6: |
From @smpeters
I added Devel::Peek to see more of what's going on. I'm guessing the if ((mg->mg_flags & MGf_COPY) && vtbl->svt_copy) { steve@kirk:~/perl-current$ perl -MDevel::Peek -le'print scalar keys 0 |
The RT System itself - Status changed from 'new' to 'open' |
From @iabynOn Sat, Sep 03, 2005 at 09:44:44PM -0700, Steve Peters via RT wrote:
No, that's only where the magic type adds its own magic copy functions, -- |
From rick@bort.ca
Please look at the following patch. I really don't understand what -- Inline Patchdiff -pruN perl-current/hv.c perl-current-dev/hv.c
--- perl-current/hv.c 2005-08-30 05:37:41.000000000 -0400
+++ perl-current-dev/hv.c 2005-09-08 08:31:28.458708179 -0400
@@ -861,7 +861,6 @@ S_hv_magic_check(pTHX_ HV *hv, bool *nee
*needs_copy = TRUE;
switch (mg->mg_type) {
case PERL_MAGIC_tied:
- case PERL_MAGIC_sig:
*needs_store = FALSE;
return; /* We've set all there is to set. */
}
diff -pruN perl-current/t/op/local.t perl-current-dev/t/op/local.t
--- perl-current/t/op/local.t 2005-09-08 03:50:38.000000000 -0400
+++ perl-current-dev/t/op/local.t 2005-09-08 08:30:03.296126706 -0400
@@ -4,7 +4,7 @@ BEGIN {
chdir 't' if -d 't';
require './test.pl';
}
-plan tests => 79;
+plan tests => 85;
sub foo {
local($a, $b) = @_;
@@ -93,6 +93,11 @@ ok(!defined $a[0]);
shift @a;
}
is($a[0].$a[1], "Xb");
+{
+ my $d = "@a";
+ local @a = @a;
+ is("@a", $d);
+}
%h = ('a' => 1, 'b' => 2, 'c' => 3);
{
@@ -105,6 +110,11 @@ is($a[0].$a[1], "Xb");
}
is($h{'a'}, 1);
is($h{'b'}, 2);
+{
+ my $d = join("\n", map { "$_=>$h{$_}" } sort keys %h);
+ local %h = %h;
+ is(join("\n", map { "$_=>$h{$_}" } sort keys %h), $d);
+}
is($h{'c'}, 3);
# check for scope leakage
@@ -146,6 +156,11 @@ tie @a, 'TA';
is($a[1], 'b');
is($a[2], 'c');
ok(!defined $a[0]);
+{
+ my $d = "@a";
+ local @a = @a;
+ is("@a", $d);
+}
{
package TH;
@@ -155,6 +170,8 @@ ok(!defined $a[0]);
sub EXISTS { print "# EXISTS [@_]\n"; exists $_[0]->{$_[1]}; }
sub DELETE { print "# DELETE [@_]\n"; delete $_[0]->{$_[1]}; }
sub CLEAR { print "# CLEAR [@_]\n"; %{$_[0]} = (); }
+ sub FIRSTKEY { print "# FIRSTKEY [@_]\n"; keys %{$_[0]}; each %{$_[0]} }
+ sub NEXTKEY { print "# NEXTKEY [@_]\n"; each %{$_[0]} }
}
# see if localization works on tied hashes
@@ -177,6 +194,12 @@ is($h{'c'}, 3);
# local() should preserve the existenceness of tied hash elements
ok(! exists $h{'y'});
ok(! exists $h{'z'});
+TODO: {
+ todo_skip("Localize entire tied hash");
+ my $d = join("\n", map { "$_=>$h{$_}" } sort keys %h);
+ local %h = %h;
+ is(join("\n", map { "$_=>$h{$_}" } sort keys %h), $d);
+}
@a = ('a', 'b', 'c');
{
@@ -203,6 +226,11 @@ $SIG{__WARN__} = $SIG{INT};
is($SIG{TERM}, 'main::foo');
is($SIG{INT}, \&foo);
is($SIG{__WARN__}, \&foo);
+{
+ my $d = join("\n", map { "$_=>$SIG{$_}" } sort keys %SIG);
+ local %SIG = %SIG;
+ is(join("\n", map { "$_=>$SIG{$_}" } sort keys %SIG), $d);
+}
# and for %ENV
@@ -225,6 +253,11 @@ is($ENV{_Z_}, 'c');
# local() should preserve the existenceness of %ENV elements
ok(! exists $ENV{_A_});
ok(! exists $ENV{_B_});
+{
+ my $d = join("\n", map { "$_=>$ENV{$_}" } sort keys %ENV);
+ local %ENV = %ENV;
+ is(join("\n", map { "$_=>$ENV{$_}" } sort keys %ENV), $d);
+}
# does implicit localization in foreach skip magic?
|
@rgs - Status changed from 'open' to 'resolved' |
From @rgsRick Delaney wrote:
Thanks, applied as #25515 (although I made the hv.c chunk a bit nicer.) |
Migrated from rt.perl.org#36733 (status was 'resolved')
Searchable as RT36733$
The text was updated successfully, but these errors were encountered: