Skip Menu |
Report information
Id: 132964
Status: new
Priority: 0/
Queue: perl5

Owner: Nobody
Requestors: pali [at] cpan.org
Cc:
AdminCc:

Operating System: (no value)
PatchStatus: (no value)
Severity: low
Type: unknown
Perl Version: (no value)
Fixed In: (no value)



Date: Mon, 12 Mar 2018 10:59:55 +0100
To: perlbug [...] perl.org
Subject: Missing newSVsv_nomg macro variant
From: pali [...] cpan.org
Download (untitled) / with headers
text/plain 1.7k
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.
From: pali [...] cpan.org
Date: Thu, 9 Aug 2018 13:22:18 +0200
Subject: Re: [perl #132964] Missing newSVsv_nomg macro variant
To: perlbug-followup [...] perl.org
Download (untitled) / with headers
text/plain 2.2k
On Monday 12 March 2018 10:59:55 pali@cpan.org wrote: Show quoted text
> 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.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org