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

Missing sv_setrv()

Thread Next
Paul "LeoNerd" Evans
July 23, 2021 10:51
Missing sv_setrv()
Message ID:
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.

Paul "LeoNerd" Evans      |  |

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