Skip to content

Commit

Permalink
_fresh functions: allow on PVIV & PVNVs too
Browse files Browse the repository at this point in the history
  • Loading branch information
richardleach committed Aug 12, 2021
1 parent 827333a commit 01813f1
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions sv.c
Expand Up @@ -1629,9 +1629,9 @@ Perl_sv_grow(pTHX_ SV *const sv, STRLEN newlen)
=for apidoc sv_grow_fresh
A cut-down version of sv_grow intended only for when sv is a freshly-minted
SVt_PV. i.e. sv has the default flags, has never been any other type, and
does not have an existing string. Basically, just assigns a char* buffer.
Returns a pointer to the character buffer.
SVt_PV, SVt_PVIV, or SVt_PVNV. i.e. sv has the default flags, has never been
any other type, and does not have an existing string. Basically, just assigns
a char buffer and returns a pointer to it.
=cut
*/
Expand All @@ -1644,7 +1644,8 @@ Perl_sv_grow_fresh(pTHX_ SV *const sv, STRLEN newlen)

PERL_ARGS_ASSERT_SV_GROW_FRESH;

assert(SvTYPE(sv) == SVt_PV);
assert(SvTYPE(sv) == SVt_PV || SvTYPE(sv) == SVt_PVIV
|| SvTYPE(sv) == SVt_PVNV);
assert(!SvROK(sv));
assert(!SvOOK(sv));
assert(!SvIsCOW(sv));
Expand Down Expand Up @@ -4976,7 +4977,8 @@ They differ only in that:
C<sv_setpvn> does not handle 'set' magic; C<sv_setpvn_mg> does.
C<sv_setpvn_fresh> is a cut-down alternative to C<sv_setpvn>, intended ONLY
to be used with a fresh sv that has been upgraded to a SVt_PV.
to be used with a fresh sv that has been upgraded to a SVt_PV, SVt_PVIV, or
SVt_PVNV.
=cut
*/
Expand Down Expand Up @@ -5028,16 +5030,17 @@ Perl_sv_setpvn_fresh(pTHX_ SV *const sv, const char *const ptr, const STRLEN len
char *dptr;

PERL_ARGS_ASSERT_SV_SETPVN_FRESH;
assert(SvTYPE(sv) == SVt_PV);
assert(SvTYPE(sv) == SVt_PV || SvTYPE(sv) == SVt_PVIV
|| SvTYPE(sv) == SVt_PVNV);
assert(!SvTHINKFIRST(sv));
assert(!isGV_with_GP(sv));

if (ptr) {
const IV iv = len;
/* len is STRLEN which is unsigned, need to copy to signed */
if (iv < 0)
Perl_croak(aTHX_ "panic: sv_setpvn_fresh called with negative strlen %"
IVdf, iv);
if (iv < 0)
Perl_croak(aTHX_ "panic: sv_setpvn_fresh called with negative strlen %"
IVdf, iv);

dptr = sv_grow_fresh(sv, len + 1);
Move(ptr,dptr,len,char);
Expand Down

0 comments on commit 01813f1

Please sign in to comment.