On Thursday 09 August 2018 13:22:18 pali@cpan.org wrote: > On Monday 12 March 2018 10:59:55 pali@cpan.org wrote: > > Hi! In perl XS api is missing function which creates a copy of the > > scalar without processing get magic and without destroying source scalar > > when is mortal. > > > > It is needed in situation when you want to call other perl function (via > > call_pv()) with scalar argument which comes from the argument passed to > > the current XS function (e.g. ST(0)) on which was already called > > SvGETMAGIC() and it is needed to prevent modification of it argument > > (e.g. because it is used also after call_pv() call). > > > > Table of available functions: > > > > magic steal mortal > > target source source target > > sv_setsv() X X > > sv_setsv_mg() X X X > > sv_setsv_nomg() X > > SvSetMagicSV() X X X > > SvSetMagicSV_nosteal() X X > > SvSetSV() X X > > SvSetSV_nosteal() X > > sv_mortalcopy() X X X > > newSVsv() X > > sv_setsv_flags() CAN CAN CAN > > > > Function which would create a copy of the scalar without processing get > > magic and without destroying (stealing) source scalar can be caller > > newSVsv_nomg() (according to to other _nomg names). > > > > Primitive implementation is there: > > > > static SV *newSVsv_nomg(SV *sv) { > > SV *ret = newSV(0); > > sv_setsv_flags(ret, sv, SV_NOSTEAL); > > return ret; > > } > > > > For above case with call_pv() can be useful function like > > newSVsv_nomg(), but which would return mortal copy. Based on above used > > naming scheme, I would propose sv_mortalcopy_nosteal_nomg(). > > > > Primitive implementation: > > > > static SV *sv_mortalcopy_nosteal_nomg(SV *sv) { > > SV *ret = sv_newmortal(); > > sv_setsv_flags(ret, sv, SV_NOSTEAL); > > return ret; > > } > > > > Please consider implementing these two functions into perl.h/perlapi. > > Now I found that in blead is undocumented macro sv_mortalcopy_flags and > function Perl_sv_mortalcopy_flags() which could potentially replace that > idea for sv_mortalcopy_nosteal_nomg(). So what about documenting macro > sv_mortalcopy_flags and making it public? > > Also there is still a need for newSVsv_nomg()-like function or macro. Hi! Any comments for making Perl_sv_mortalcopy_flags() function public? And for providing newSVsv_nomg()-like function?Thread Next