develooper Front page | perl.perl5.porters | Postings from December 2009

Need advice on Perl magic.

From:
karl williamson
Date:
December 6, 2009 21:22
Subject:
Need advice on Perl magic.
Message ID:
4B1C910E.7000902@khwilliamson.com
Perl magic is mystifying to me.

In pp_uc() and similar functions, I need sometimes to copy the input 
parameter to a temporary, and change the copy to be utf8-encoded, then 
get its scalar string.  The following works on my test cases:

source = sv_mortalcopy(source);
len = sv_utf8_upgrade_flags(source,SV_GMAGIC|SV_FORCE_UTF8_UPGRADE);		
s = (const U8*)SvPV_nomg_const(source, len);

(I don't need to refer to the original source after this in the function.)

Earlier, Nicholas told me that the SvPV_nomg_const could change the 
utf8ness of source, if source is a reference to an overloaded value, but 
here I'm creating a new copy of source first.  I don't know if the copy 
gets the overloading or not.  I don't know if the SV_GMAGIC flag does 
anything or not; I just copied it from other code.

And I don't know if it is better to explicitly do a FREETMPS at the end 
of the routine, or to let the temporary be implicitly destroyed.

I would appreciate it if someone would tell me if the code above looks 
right, or not.



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About