On Sun, Jul 11, 2004 at 09:34:40PM -0000, Erland Sommarskog wrote:
> Is this the way to go?
> 
>      perl_len = (SvPOK(sv) ? SvCUR(sv) : strlen(SvPV(sv, Pl_na));
> 
> That is, if sv is a string, then use SvCUR, else use strlen on the 
> stringified value?
> 
> Or is there a direct function that I have missed?

I don't see anything wrong with

   STRLEN perl_len;
   SvPV(sv, perl_len);

The macro SvPV will always assign the length to perl_len.
(I'm ignoring the return value from it because you didn't seem to need the
pointer)

To be portable you need to ensure that the type of the second argument to SvPV
is STRLEN, else your code will have problems on 64 bit platforms. The macro
passes a pointer to the variable into a function, and if the variable is 32
bits when 64 is expected, or vice versa, you'll get corrupt values.

Nicholas Clark

Reply via email to