Abhijit Menon-Sen <[EMAIL PROTECTED]> writes:
>I'm copying some XS code which does this:
>
>| if (output == &sv_undef)
>| output = sv_newmortal();
>|
>| if (!SvUPGRADE(output, SVt_PV))
>| croak("cannot use output argument as lvalue");
>
>What is the SvUPGRADE really trying to do?
Making sure that the SV is ready to accept an SvPV.
>
>I suspect that the croak() message is misleading, since SVt_PVness
>doesn't appear to have anything to do with lvalueness.
But if there isn't a PV (string) slot then presumably code below
cannot set it. What is more worrying is lack of SvREADONLY() check.
>If I comment it
>out, things still work unless output is undef (in which case, it SEGVs).
>
>Should I be doing the SvUPGRADE only in the case where I create a new
>SV?
The SvUPGRADE should be harmless - if the SV is already suitable
it does nothing. (See code in sv.h and sv.c.)
>Russ Allbery's (unrelated) post on 2000-12-18, "Re: Attempt to free
>unreference scalar?" suggests that this is the case (but doesn't explain
>why).
>
>Is there a searchable archive of the perl-xs mailing list anywhere?
>
>- ams
--
Nick Ing-Simmons