develooper Front page | perl.perl5.porters | Postings from August 2006

Re: [perl #37731] junk and uninit'ed values in tied scalars

Thread Previous | Thread Next
From:
Rafael Garcia-Suarez
Date:
August 9, 2006 08:49
Subject:
Re: [perl #37731] junk and uninit'ed values in tied scalars
Message ID:
b77c1dce0608090849x2ed31737t382bd5a42fd2ec35@mail.gmail.com
On 28/11/05, Yitzchak Scott-Thoennes <sthoenna@efn.org> wrote:
> > >     Finally, the mysterious Bug #3:
> > >
> > >         sub foo::TIESCALAR { bless {value => $_[1]}, $_[0] }
> > >         sub foo::FETCH { $_[0]->{value} }
> > >         tie my $VAR, 'foo', 'SEARCH';
> > >         foreach my $var ($VAR)
> > >         {
> > >            print +($var eq $VAR) ? 'yes' : 'no';
> > >         }
> > >
> > > This prints "no".
> >
> > Still a problem in blead.  I hope any fix to this would make something
> > that does: sub FETCH { ++$_[0]->{value} } have eq return *false*.
>
> This does it, if a little heavy-handedly:

Thanks, applied as change #28684 (I added a regression test.)

> --- perl/sv.c.orig      2005-11-25 09:33:11.000000000 -0800
> +++ perl/sv.c   2005-11-27 21:30:09.828265600 -0800
> @@ -5579,6 +5579,15 @@ Perl_sv_eq(pTHX_ register SV *sv1, regis
>      else
>         pv1 = SvPV_const(sv1, cur1);
>
> +    /* if pv1 and pv2 are the same, second SvPV_const call may
> +       invalidate pv1, so we may need to make a copy */
> +
> +    if (sv1 == sv2 && sv1 && (SvTHINKFIRST(sv1) || SvGMAGICAL(sv1))) {
> +        sv1 = sv_2mortal(newSVpvn(pv1, cur1));
> +        if (SvUTF8(sv2)) SvUTF8_on(sv1);
> +        pv1 = SvPV_const(sv1, cur1);
> +    }
> +
>      if (!sv2){
>         pv2 = "";
>         cur2 = 0;
>
>

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