develooper Front page | perl.perl5.porters | Postings from January 2012

[perl #78194] Referencing a PADTMP twice produces two copies

Thread Previous | Thread Next
From:
Father Chrysostomos via RT
Date:
January 8, 2012 14:21
Subject:
[perl #78194] Referencing a PADTMP twice produces two copies
Message ID:
rt-3.6.HEAD-14510-1326061293-1398.78194-14-0@perl.org
On Sun Jun 05 16:04:53 2011, sprout wrote:
> On Sun Oct 03 14:08:37 2010, sprout wrote:
> > $ perl  -le' for( "$y" ){print \$_.\$_}'
> > SCALAR(0x8039f0)SCALAR(0x8038d0)
> > 
> > (The same address should be printed twice.)
> > 
> > It looks as though the TARG ought to be stolen by S_refto, and then
> > replaced via pad_swipe or something similar.
> 
> It might be cleaner for not only S_refto, but also any op that aliases a
> PADTMP to copy it. That would include for, map, grep, arguments to
> subroutines, and the lhs of (...)x...

Here is a difficult case:

$ ./perl -Ilib -e 'use Devel::Peek; "$_" =~ /(?{ Dump $_ })/;'
SV = PVMG(0x824b78) at 0x826ba0
  REFCNT = 1
  FLAGS = (PADTMP,SMG,POK,pPOK)
...

Fixing the operators I mentioned above is easy.  Fixing patterns without
a speed hit (since regexps are used so often) is not so easy.

Are regular expressions with code blocks in them flagged somehow, so we
can avoid making a copy for every PADTMP =~ // ?

In case it’s not obvious, this is the bug I’m trying to fix:

$ ./perl -Ilib -le '"$_" =~ /(?{ print \$_; print \$_ })/;'
SCALAR(0x803a10)
SCALAR(0x803b50)

Taking a reference to $_ twice should not create references to two
different variables.  The implementation details are leaking through.

-- 

Father Chrysostomos


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