develooper Front page | perl.perl5.porters | Postings from March 2020

Re: Missing core function: sv_setrv()

Thread Previous | Thread Next
From:
Олег Пронин
Date:
March 19, 2020 14:20
Subject:
Re: Missing core function: sv_setrv()
Message ID:
CABFBc452wyN+5TsoHXz81qSvXCgERKTKRRbWB7-sVaCoV029uw@mail.gmail.com
Hello. Maybe offtopic, but there are convenient C++ Perl API (designed to
use instead of perl native one) provided by XS::Framework;

With this API it can be done as
xs::Ref ref = sv1;
xs::Sv value = sv2;
ref.value(value);

or (the same)
Ref(sv1).value(sv2);

ср, 18 мар. 2020 г. в 19:24, Paul "LeoNerd" Evans <leonerd@leonerd.org.uk>:

> I'm trying to do the following in a bit of XS code:
>
>   CV *cv = ...;
>   sv_setrv(get_sv("Some::Package::VAR", GV_ADD), (SV *)cv);
>
> this fails because there isn't an sv_setrv(). I vote it should be added.
>
> However, I'm struggling to find a sensible implementation for it. A
> hacked-up version that does work just fine is:
>
>   static void sv_setrv(SV *sv, SV *rv)
>   {
>     SV *tmp = newRV_noinc(rv);
>     sv_setsv(sv, tmp);
>     SvREFCNT_dec(tmp);
>   }
>
> but of course this is rather silly having to create and throw away that
> `tmp`.
>
> I've tried hunting around perl core for various bits to copypaste, but
> lots of tempting ideas end up containing macros that are #ifdef
> PERL_CORE so I can't see them from XS.
>
> Can anyone suggest something better?
>
> --
> Paul "LeoNerd" Evans
>
> leonerd@leonerd.org.uk      |  https://metacpan.org/author/PEVANS
> http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/
>


-- 
Oleg Pronin, Crazy Panda LTD

Thread Previous | Thread Next


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