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

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

Thread Previous | Thread Next
From:
bulk88 via RT
Date:
May 9, 2013 18:55
Subject:
[perl #116407] SvPVutf8 != SvPVX, and sv_2pvutf8
Message ID:
rt-3.6.HEAD-6955-1368125686-1838.116407-15-0@perl.org
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. The previous sentence might need to be another
ticket. perlguts in blead says nothing about SvPV is not SvPVX and says
nothing about COW.

-- 
bulk88 ~ bulk88 at hotmail.com

---
via perlbug:  queue: perl5 status: resolved
https://rt.perl.org:443/rt3/Ticket/Display.html?id=116407

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