develooper Front page | perl.perl5.porters | Postings from May 2013

Re: [perl #116407] SvPVutf8 != SvPVX, and sv_2pvutf8

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
May 10, 2013 11:14
Subject:
Re: [perl #116407] SvPVutf8 != SvPVX, and sv_2pvutf8
Message ID:
20130510111338.GD2069@iabyn.com
On Thu, May 09, 2013 at 11:54:47AM -0700, bulk88 via RT wrote:
> On Thu May 09 09:07:02 2013, davem wrote:
> >  Note that there is no guarantee that the return value of C<SvPV()> is
> > -equal to C<SvPVX(sv)> (or even that C<SvPVX(sv)> contains valid
> > data), due
> > -to the way that things like overloading and Copy-On-Write are
> > handled.  In
> > -these cases, the return value may point to a temporary buffer or
> > similar.
> > -If you absolutely need the SvPVX field to be valid (for example, if
> > you
> > -intend to write to it), then see L</SvPV_force>.
> > +equal to C<SvPVX(sv)>, or that C<SvPVX(sv)> contains valid data, or
> > that
> > +successive calls to C<SvPV(sv)) will return the same pointer value
> > each
> > +time. This is due to the way that things like overloading and
> > +Copy-On-Write are handled.  In these cases, the return value may
> > point to
> > +a temporary buffer or similar.  If you absolutely need the SvPVX
> > field to
> > +be valid (for example, if you intend to write to it), then see
> > +L</SvPV_force>.
> > 
> > 
> 
> "(for example, if you intend to write to it), then see L</SvPV_force>."
> 
> SvPV_force runs get magic, so if you are "writing to SvPVX", you just at
> minimum did "read" and then maybe (if you are doing XS right) "write"
> for what should have been just a "write", which is wrong in magic land.
> Also SvPV_force might have done a "sv_2pv_flags" internally to generate
> a valid PV buffer (IV to PV conversion) which will be immediately
> overwritten (and wasted cpu to generate it) by passing SvPVX to a
> non-perl C function.

I have no idea what point you're trying to make here.
I've added some sentences to the docs for SvPV that say under some
circumstances you might need SvPV_force instead. All the stuff about
calling magic etc seems completely orthogonal to that.


> The previous sentence might need to be another
> ticket. perlguts in blead says nothing about SvPV is not SvPVX and says
> nothing about COW.

Currently near the top of my things to do prior to 5.18 is to add some
notes about that issue to perlguts.

-- 
Indomitable in retreat, invincible in advance, insufferable in victory
    -- Churchill on Montgomery

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