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

Re: Missing core function: sv_setrv()

Thread Previous | Thread Next
From:
Paul "LeoNerd" Evans
Date:
April 16, 2020 18:04
Subject:
Re: Missing core function: sv_setrv()
Message ID:
20200416190426.6f174ade@shy.leonerd.org.uk
On Wed, 18 Mar 2020 16:24:37 +0000
"Paul \"LeoNerd\" Evans" <leonerd@leonerd.org.uk> wrote:

> 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?

Update: This appears to do the trick:

  #define sv_setrv(s, r)  S_sv_setrv(aTHX_ s, r)
  static void S_sv_setrv(pTHX_ SV *sv, SV *rv)
  {
    sv_upgrade(sv, SVt_IV);
    SvROK_on(sv);
    SvIV_set(sv, 0);
    SvRV_set(sv, rv);
  }

At least, it's sufficient for newly-created blank SVs such as with:

  SV **svp = hv_fetchs(hv, "key", 1);
  if(!SvROK(*svp))
    sv_setrv(*svp, newAV());

The search continues...

-- 
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk      |  https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/

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