develooper Front page | perl.perl5.porters | Postings from March 2023

Re: refaliasing disrespects readonlyness of array or hash

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
March 23, 2023 12:20
Subject:
Re: refaliasing disrespects readonlyness of array or hash
Message ID:
ZBxEJBELyriX8u5s@iabyn.com
On Mon, Mar 20, 2023 at 09:41:19PM +0100, demerphq wrote:
> On Mon, 20 Mar 2023 at 21:33, Zefram via perl5-porters <
> perl5-porters@perl.org> wrote:
> 
> > $ perl -Mexperimental=refaliasing -lwe '%a = (aa=>11,bb=>22,cc=>33);
> > Internals::SvREADONLY(%a, 1); Internals::SvREADONLY($a{bb}, 1); print
> > \$a{bb}; \$a{bb} = \555; print \$a{bb}'
> > SCALAR(0x55f3eee968a0)
> > SCALAR(0x55f3eefd7aa8)
> >
> 
> Yep, that is a bug.

Note that this is a general issue with aliasing, e.g. via 'local', not
just with the \ refaliasing mechanism:

    %a = (aa=>11,bb=>22,cc=>33);
    Internals::SvREADONLY(%a, 1);
    Internals::SvREADONLY($a{bb}, 1);
    local $a{bb} = 555 if @ARGV;
    delete $a{bb};


$ pp
Attempt to delete readonly key 'bb' from a restricted hash at /home/davem/tmp/p line 9.
$ pp 1
$


-- 
It's not that I'm afraid to die, I just don't want to be there when it
happens.
    -- Woody Allen

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