develooper Front page | perl.perl5.porters | Postings from July 2021

Re: Missing sv_setrv()

Thread Previous
Andy Xiao
July 27, 2021 01:21
Re: Missing sv_setrv()
Message ID:
yes, add this function please!
From: Leon Timmermans <>
Sent: Friday, July 23, 2021 7:08 PM
To: Paul LeoNerd Evans <>
Cc: Perl5 Porters <>
Subject: Re: Missing sv_setrv()

On Fri, Jul 23, 2021 at 12:51 PM Paul "LeoNerd" Evans <<>> wrote:
Perl has functions to create new SVs containing IV, PV, NV, etc.. and
it has functions to modify an existing SV to take a given IV, PV, etc..

  SV *sv = newSViv(123)        vs  sv_setiv(sv, 123);
  SV *sv = newSVpvn("hi", 2);  vs  sv_setpvn(sv, "hi", 2);
  SV *sv = newSVnv(1.23)       vs  sv_setnv(sv, 1.23);

While we have functions to create new SVs containing an RV, we appear
not to have one to modify an existing SV:

  SV *sv = newRV_noinc(some_av);  vs   nothing.

I don't know of any reason why this should be lacking. I've sometimes
found myself wanting this function, so I copypaste this thing around
the place:

  #define sv_setrv_noinc(s, r)  S_sv_setrv_noinc(aTHX_ s, r)
  static void S_sv_setrv_noinc(pTHX_ SV *sv, SV *rv)
    sv_setiv(sv, (IV)rv);
  #if !HAVE_PERL_VERSION(5, 24, 0)

I'll probably just add this to core (minus the unnecessary #ifdef),
unless anyone has a suggestion why not.

That makes sense to me, I have needed it on at least one occasion.


Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About