Open p5pRT opened 22 years ago
# local() doesn't seem to work correctly with $^W in Perl 5.6.1
# Run this program to see.
# -Jim Avera jima@simplex.com 8/15/2002
use strict;
#------ this works ------
use vars '$XX';
$XX = 1;
die "BUG: XX is off" unless $XX;
{ local($XX) = $XX;
die "BUG: XX is off" unless $XX;
}
die "BUG: XX is off" unless $XX;
#------ this doesn't work ------
$^W = 1;
die "BUG: warn is off" unless $^W;
{ local($^W) = $^W;
die "BUG: warn is off" unless $^W; # dies here in Win32 Perl 5.6.1
}
die "BUG: warn is off" unless $^W; # dies here in Solaris Perl 5.6.1
print "Test passed.\n";
Confirmed in 5.8.0 and 5.8.1 RC2.
@schwern - Status changed from 'new' to 'open'
On Tue Jul 15 23:16:04 2003\, schwern wrote:
Confirmed in 5.8.0 and 5.8.1 RC2.
This is still present in 5.14.2 and blead\, but a small update: The original bug report says that Solaris behaved differently\, failing on the final die. Now it's the same same place as Linux/Windows\, on
{ local($^W) = $^W; die "BUG: warn is off5" unless $^W; }
On Sat Apr 28 02:11:01 2012\, Hugmeir wrote:
On Tue Jul 15 23:16:04 2003\, schwern wrote:
Confirmed in 5.8.0 and 5.8.1 RC2.
This is still present in 5.14.2 and blead\, but a small update: The original bug report says that Solaris behaved differently\,
Knowing how this is implemented\, I think it was misdiagnosed.
failing on the final die. Now it's the same same place as Linux/Windows\, on
{ local($^W) = $^W; die "BUG: warn is off5" unless $^W; }
Usually\, local($foo) creates a new $foo in *foo{SCALAR}\, copies the magic to it\, and then calls set-magic on it. This allows a plain local($^W); to work.
local($foo) = $foo works because the $foo on the RHS (which is executed first) is the original $foo; i.e.\, a completely different scalar.
For magical variables things gang agley\, because the local($^W) on the LHS is a separate operator from assignment and sets $^W to undef befor the assignment happens. Since both $^W’s have magic that writes to the same underlying structures\, the assignment has no affect.
This is similar to bug #104118\, but a little different; but I think it’s the same code that would need adjustment.
--
Father Chrysostomos
On Sat Apr 28 13:56:58 2012\, sprout wrote:
On Sat Apr 28 02:11:01 2012\, Hugmeir wrote:
On Tue Jul 15 23:16:04 2003\, schwern wrote:
Confirmed in 5.8.0 and 5.8.1 RC2.
This is still present in 5.14.2 and blead\, but a small update: The original bug report says that Solaris behaved differently\,
Knowing how this is implemented\, I think it was misdiagnosed.
failing on the final die. Now it's the same same place as Linux/Windows\, on
{ local($^W) = $^W; die "BUG: warn is off5" unless $^W; }
Usually\, local($foo) creates a new $foo in *foo{SCALAR}\, copies the magic to it\, and then calls set-magic on it. This allows a plain local($^W); to work.
local($foo) = $foo works because the $foo on the RHS (which is executed first) is the original $foo; i.e.\, a completely different scalar.
For magical variables things gang agley\, because the local($^W) on the LHS is a separate operator from assignment and sets $^W to undef befor the assignment happens. Since both $^W’s have magic that writes to the same underlying structures\, the assignment has no affect.
I forgot to mention that local($hash{elem}) in lvalue context is special-cased to work\, for the sake of %SIG. There are various /* XXX - FIXME - see #60360 */ comments sprinkled here and there.
--
Father Chrysostomos
% perl -wle '$? = 123; print "before: $?"; local $? = $?; print "after: $?"'
before: 123
after: 0
% perl -wle '$? = 123; print "before: $?"; local $? = $? + 0; print "after: $?"'
before: 123
after: 123
I would have expected the first version to output "after: 123" instead of resetting $? to 0. Oh wait, it's actually worse than I thought:
% perl -wle '$? = 123; print "before: $?"; { local $? = $?; print "after: $?"; } print "finally: $?"'
before: 123
after: 0
finally: 0
i.e. the reset isn't even localized; it straight up clobbers $?.
This bug interacts badly with END blocks:
% perl -e 'exit 123; END { local $? = $?; }'; echo $?
0
instead of the expected:
% perl -e 'exit 123; END { local $? = $? + 0; }'; echo $?
123
Also affects Windows and cygwin\, so it's not OS specific.
The RT System itself - Status changed from 'new' to 'open'
@ikegami - Status changed from 'open' to 'new'
Migrated from rt.perl.org#16235 (status was 'open')
Searchable as RT16235$