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

Missing core function: sv_setrv()

Thread Next
From:
Paul "LeoNerd" Evans
Date:
March 18, 2020 16:24
Subject:
Missing core function: sv_setrv()
Message ID:
20200318162437.154a2a02@shy.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/

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