develooper Front page | perl.perl5.porters | Postings from July 2016

[perl #128588] Tied hash magic ignored in references the first time'round

Thread Previous | Thread Next
From:
Father Chrysostomos via RT
Date:
July 10, 2016 00:39
Subject:
[perl #128588] Tied hash magic ignored in references the first time'round
Message ID:
rt-4.0.18-29777-1468111169-387.128588-15-0@perl.org
On Sat Jul 09 14:46:08 2016, sanko wrote:
> A few years ago, I reported a tie related bug where the magic was
> being ignored on scalar values until they're accessed. Now, I'm back
> with a similar bug: tie magic is ignored by ref() (and likely others
> but ref() makes it obvious) when handed references to parts of a tied
> structure unless that reference is accessed (not modified) by other
> means first.

I have known about that behaviour for years, but I was not sure that it was a bug, and I was hesitant to change it because most perl operators will call FETCH on their operands, but not on their operands’ referents.  (This is related to #77502.)

In other words:

    ref $var

calls FETCH on $var if it is tied, but

    ref \$var

does not call FETCH, because $var is not the operand to ref().

Most of the time, perl tries to call FETCH exactly once for each mentioned variable.  To fix the bug would require a FETCH on $bar on line 2 of this example, even though that line does not mention $bar:

    $foo = \$bar;
    ref $foo;

That said, it can be a real problem (e.g., for your module), so it may be worth fixing.

What do others think?

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=128588

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About