in reply to XS question
I don't know what you mean with valid string, but in Perl all scalar values are capable of being stringified and as such it has no concept of 'valid string'. Calling SvPV will give you this string value. If you want to force stringification before calling SVPV you could simply do sv_catpvn_mg(sv, "", 0).