develooper Front page | perl.perl5.porters | Postings from September 2019

Various SvPV() macros return pointers to constant empty strings

Thread Next
From:
demerphq
Date:
September 6, 2019 11:06
Subject:
Various SvPV() macros return pointers to constant empty strings
Message ID:
CANgJU+WGg57LB9UBHQMUDL=Uux+u_Eqf6dN4hSUvhCg1SRTzJA@mail.gmail.com
I was wondering if anyone understood the use cases in sv_2pv_flags()
where it returns a pointer to a constant empty string. (There are
several cases, two of which IMO are somewhat understandable, but one
of which I don't get at all.)

So for instance i have code like this:

SV *tmp= sv_newmortal();
char *pv;
sv_grow(tmp,1000);
pv= SvPV_nolen();

this throws an uninitialized warning because the POK flag is off, but
it then returns the pointer 51c97a every time. Looking into the source
code it falls into a code path that does:

3255: return (char *)"";

I think this is bloody weird. If I dump the sv it has a valid PV
pointer (because of the sv_grow()), but it has not actually coerced it
to a string, and it has not returned the actual pointer to the PV
slot. I feel like this code should have "just worked" and returning a
constant string here when there is a valid SvPVX to return is wrong.

Yves



-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

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