S_save_scalar_at(pTHX_ SV **sptr, const U32 flags)
{
dVAR;
- SV * const osv = *sptr;
- register SV * const sv = *sptr = newSV(0);
+ SV * osv;
+ register SV *sv;
PERL_ARGS_ASSERT_SAVE_SCALAR_AT;
+ osv = *sptr;
+ sv = (flags & SAVEf_KEEPOLDELEM) ? osv : (*sptr = newSV(0));
+
if (SvTYPE(osv) >= SVt_PVMG && SvMAGIC(osv) && SvTYPE(osv) != SVt_PVGV) {
if (SvGMAGICAL(osv)) {
const bool oldtainted = PL_tainted;
(SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
PL_tainted = oldtainted;
}
- mg_localize(osv, sv, (flags & SAVEf_SETMAGIC) != 0);
+ if (!(flags & SAVEf_KEEPOLDELEM))
+ mg_localize(osv, sv, (flags & SAVEf_SETMAGIC) != 0);
}
+
return sv;
}
if (!AvREAL(av) && AvREIFY(av))
SvREFCNT_inc_void(*sptr);
save_scalar_at(sptr, flags); /* XXX - FIXME - see #60360 */
+ if (flags & SAVEf_KEEPOLDELEM)
+ return;
sv = *sptr;
/* If we're localizing a tied array element, this new sv
* won't actually be stored in the array - so it won't get
SSPUSHPTR(SvREFCNT_inc(*sptr));
SSPUSHINT(SAVEt_HELEM);
save_scalar_at(sptr, flags);
+ if (flags & SAVEf_KEEPOLDELEM)
+ return;
sv = *sptr;
/* If we're localizing a tied hash element, this new sv
* won't actually be stored in the hash - so it won't get
#define SAVEt_ADELETE 46
#define SAVEf_SETMAGIC 1
+#define SAVEf_KEEPOLDELEM 2
#define save_aelem(av,idx,sptr) save_aelem_flags(av,idx,sptr,SAVEf_SETMAGIC)
#define save_helem(hv,key,sptr) save_helem_flags(hv,key,sptr,SAVEf_SETMAGIC)