Skip to content

Dedicated SV copying code in place of Perl_sv_setsv_flags #23202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: blead
Choose a base branch
from
10 changes: 4 additions & 6 deletions av.c
Original file line number Diff line number Diff line change
@@ -479,6 +479,8 @@ Perl_av_make(pTHX_ SSize_t size, SV **strp)
AvALLOC(av) = ary;
AvARRAY(av) = ary;
AvMAX(av) = size - 1;
SSize_t *fillp = &AvFILLp(av);

/* avoid av being leaked if croak when calling magic below */
EXTEND_MORTAL(1);
PL_tmps_stack[++PL_tmps_ix] = (SV*)av;
@@ -490,12 +492,8 @@ Perl_av_make(pTHX_ SSize_t size, SV **strp)
/* Don't let sv_setsv swipe, since our source array might
have multiple references to the same temp scalar (e.g.
from a list slice) */

SvGETMAGIC(*strp); /* before newSV, in case it dies */
AvFILLp(av)++;
ary[i] = newSV_type(SVt_NULL);
sv_setsv_flags(ary[i], *strp,
SV_DO_COW_SVSETSV|SV_NOSTEAL);
ary[i] = newSVsv_flags(*strp, SV_DO_COW_SVSETSV|SV_NOSTEAL|SV_GMAGIC);
*fillp = i;
strp++;
}
/* disarm av's leak guard */
9 changes: 5 additions & 4 deletions pp.c
Original file line number Diff line number Diff line change
@@ -6421,10 +6421,11 @@ PP(pp_push)
PL_delaymagic = DM_DELAY;
for (++MARK; MARK <= PL_stack_sp; MARK++) {
SV *sv;
if (*MARK) SvGETMAGIC(*MARK);
sv = newSV_type(SVt_NULL);
if (*MARK)
sv_setsv_nomg(sv, *MARK);
if (*MARK) {
sv = newSVsv_flags(*MARK, SV_DO_COW_SVSETSV|SV_GMAGIC);
} else
sv = newSV_type(SVt_NULL);

av_store(ary, AvFILLp(ary)+1, sv);
}
if (PL_delaymagic & DM_ARRAY_ISA)
9 changes: 3 additions & 6 deletions pp_ctl.c
Original file line number Diff line number Diff line change
@@ -4407,13 +4407,11 @@ S_doopen_pm(pTHX_ SV *name)
return NULL;

if (memENDPs(p, namelen, ".pm")) {
SV *const pmcsv = sv_newmortal();
PerlIO * pmcio;
SV *const pmcsv = sv_mortalcopy_flags(name, SV_GMAGIC|SV_NOSTEAL|SV_DO_COW_SVSETSV);

SvSetSV_nosteal(pmcsv,name);
sv_catpvs(pmcsv, "c");

pmcio = check_type_and_open(pmcsv);
PerlIO * pmcio = check_type_and_open(pmcsv);
if (pmcio)
return pmcio;
}
@@ -4805,8 +4803,7 @@ S_require_file(pTHX_ SV *sv)
}

if (SvPADTMP(nsv)) {
nsv = sv_newmortal();
SvSetSV_nosteal(nsv,sv);
nsv = sv_mortalcopy_flags(sv, SV_GMAGIC|SV_NOSTEAL|SV_DO_COW_SVSETSV);
}

const char *method = NULL;
3 changes: 1 addition & 2 deletions pp_hot.c
Original file line number Diff line number Diff line change
@@ -5357,8 +5357,7 @@ PP(pp_subst)
if (dstr) {
/* replacement needing upgrading? */
if (DO_UTF8(TARG) && !doutf8) {
nsv = sv_newmortal();
SvSetSV(nsv, dstr);
nsv = sv_mortalcopy_flags(dstr, SV_GMAGIC|SV_DO_COW_SVSETSV);
sv_utf8_upgrade(nsv);
c = SvPV_const(nsv, clen);
doutf8 = TRUE;
Loading