Re: Avoid using PL_na with newSVpv

[email protected] (Jan Dubois)
Newsgroups perl.xs
Message-ID <CAD-TLz_MCf_4nd41JtWjTnLfhibdJW_10aOLiAVZrKYjZaKybQ@mail.gmail.com>
On Wed, Sep 25, 2013 at 11:50 AM, Torsten Schoenfeld <[email protected]> wrote:
>
>   newSVpv (string, PL_na) // do not do this

Is this recomended anywhere?  PL_na is a legacy variable that used to
be used for

    str = SvPV(sv, PL_na);

in case you don't care about the length of the string. Since this will
always write the length of the string to PL_na, I can't think of any
reason why you would assume that PL_na would always be zero.

A more efficient way is to use

    str = SvPV_nolen(sv);

As more and more code gets rid of using PL_na, it becomes more and
more likely that PL_na will indeed be 0 (because it has never been
used before), but as you point out, that is a dangerous assumption.

Cheers,
-Jan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.