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
$! localisation broken by ref #13244
Comments
From zefram@fysh.orgCreated by zefram@fysh.orgRan into this while tweaking Carp's localisation of $!:
$! is getting squashed to 0 despite Perl Info
|
From victor@vsespb.rualso:
similar issue (but with $1, which should be auto-localized): On Mon Sep 09 12:28:08 2013, zefram@fysh.org wrote:
-Wl,-rpath,/home/zefram/usr/perl/perl_install/perl-5.18.1-i64-f52/lib/5.18.1/x86_64-linux-thread-multi/CORE'
gnu/bin:/home/zefram/pub/common/bin:/usr/bin:/bin:/usr/local/bin:/usr/games
|
The RT System itself - Status changed from 'new' to 'open' |
From @ikegamiOn Mon, Sep 9, 2013 at 3:36 PM, Victor Efimov via RT <
I think you meant $ perl -le 'sub aa { local $!; I'm not sure that's a problem. You're modifying the arg, and the arg is the |
From zefram@fysh.orgVictor Efimov via RT wrote:
Not much similarity there. That's about an argument $1 surprisingly The breakage doesn't require ref(). If 'my $a = shift' is put in place of -zefram |
From victor@vsespb.ruactually my example above contain typo: "perl -le 'sub aa { local $x;
|
From Eirik-Berg.Hanssen@allverden.noOn Mon, Sep 9, 2013 at 9:36 PM, Victor Efimov via RT <
and: perl -le 'sub aa { local $/; but: # oops ... Eirik |
From @cpansproutOn Mon Sep 09 13:28:01 2013, zefram@fysh.org wrote:
No doubt it’s get-magic that triggers it. This is probably related to -- Father Chrysostomos |
From @LeontOn Mon, Sep 9, 2013 at 9:28 PM, Zefram <perlbug-followup@perl.org> wrote:
Also: perl -le 'sub aa { local
I don't quite understand what's going on here… Leon |
From @epaIs this not another of those bugs that would all be squashed if magic So when you call foo($!), foo gets its own scalar whose initial value is (An alternative would be for a read-only reference to be passed, so the -- |
From @LeontOn Tue, Sep 10, 2013 at 3:04 PM, Ed Avis <eda@waniasset.com> wrote:
This bug has nothing to do with either ref or function calling. It Leon |
From @epaSorry, please excuse me for banging that drum inappropriately. ______________________________________________________________________ |
From @cpansproutOn Tue Sep 10 06:14:56 2013, LeonT wrote:
You will also find that it is 0 inside the sub (bug #16235). The two Bug #16235 is that local It seems the solution (at least for local I haven’t looked closely to see whether that is what is causing the -- Father Chrysostomos |
From @LeontOn Tue, Sep 10, 2013 at 5:42 PM, Father Chrysostomos via RT <
We have a localize magic 'method' that we currently aren't using for I still don't feel like I really understand the issue, but I'm guessing the Leon |
From @ikegamiOn Tue, Sep 10, 2013 at 9:13 AM, Leon Timmermans <fawaka@gmail.com> wrote:
----- BEGIN CODE ----- { tie $x, 'M'; $x=69; say '{'; { local $x = $x; say "<<$x>>"; } say '}'; say $x; ----- BEGIN OUTPUT -----
It's as if $x=69; { local $x = $x; } say $x; does $x=69; { my $r = \$x; local $x; which is clearly the wrong order. |
From @LeontOn Tue, Sep 10, 2013 at 6:17 PM, Leon Timmermans <fawaka@gmail.com> wrote:
Now I understand. Given: perl -le '$!=69; {local What happens is this: Enter scope So yes, that explains why we're seeing what we're seeing. I think that Leon |
From @LeontOn Tue, Sep 10, 2013 at 7:49 PM, Leon Timmermans <fawaka@gmail.com> wrote:
No, I'm wrong. «Get's value of errno from old $!» means "Assign the value
So no, that solution won't help. Anything that will call getmagic on the Leon |
From @cpansproutOn Mon Sep 09 12:28:08 2013, zefram@fysh.org wrote:
I think this is all stated elsewhere in the thread, but let me recap: Localisation swaps out a new The old $! is still magical, so invoking get-magic on it will read errno into it, clobbering the only place where the old errno value is stored. I see multiple ways to fix this, each with its own drawbacks: 1) Make the old scalar temporarily non-magical when any magical scalar is localised. This would fix ticket #16235 ‘for free’. This could break modules like File::chdir that export a magical scalar to multiple callers. 2) Make the old scalar temporarily non-magical, but only if it is not tied. This would require using method #3 for tied variables; also, ticket #16235 would require a separate fix still, but only for ties. The result would be more complexity and some inconsistency between built-in variables like $! and tied variables. 3) Separately store the actual value to be restored on the savestack, in addition to the old magical scalar. #3 is the easiest to implement, and probably the safest in terms of backward compatibility. #2 might be the best fix overall though. It would make sub { local $!; print -- Father Chrysostomos |
From @nwc10On Sat, Oct 26, 2013 at 01:16:54AM -0700, Father Chrysostomos via RT wrote:
Wouldn't that change the behaviour of code which is able to access the $ cat /tmp/local.pl $::var = 5; print "Before: $::var\n"; sub foo { (I haven't thought very hard about this, but the whole thing does seem to be Nicholas Clark |
From @cpansproutOn Sun Oct 27 00:22:32 2013, nicholas wrote:
Yes, it would change that behaviour. Scratch #3 then. You see why nobody wants to fix this? :-)
I think that is the underlying problem. But how do you fix that for ties? I.e., how do we make your example work with Tie::StdScalar? Do we need to introduce LOCAL and UNWIND methods for ties? Currently with $::var tied to Tie::StdScalar, it prints: Before: 5 And with -- Father Chrysostomos |
From @atoomicCreated by @atoomicWe recently discovered this issue while updating Test::Trap to 0.3.3 local ( view https://rt.cpan.org/Public/Bug/Display.html?id=127112 for more details So I performed some basic tests using multiple perl versions from 5.10 to But I think it's weird that $! cannot be localized performing a copy perl -e'$! = 4; do { local Another variable would work fine and preserve its original value of course a workaround could be or a less convoluted by doing a manual copy perl -e'$! = 4; do { my At this point I'm not sure we can call it a bug... (maybe it's a feature) Perl Info
|
From @LeontOn Fri, Sep 14, 2018 at 7:21 PM Atoomic (via RT)
This is a duplicate of #119683 Leon |
The RT System itself - Status changed from 'new' to 'open' |
From @atoomicThanks Leon for pointing to https://rt-archive.perl.org/perl5/Ticket/Display.html?id=119683 |
The only solution for this that I have thought up would be to:
I should add that this problem exists for most magical variables than can be written to, not just In one (very contrived) example that could even lead to security issues:
Interestingly, this was previously fixed for magical hashes and arrays |
I think this is a duplicate of #5835. |
Migrated from rt.perl.org#119683 (status was 'open')
Searchable as RT119683$
The text was updated successfully, but these errors were encountered: