diff options
-rw-r--r-- | pp.c | 8 | ||||
-rw-r--r-- | pp_hot.c | 8 | ||||
-rw-r--r-- | sv.c | 8 | ||||
-rw-r--r-- | sv.h | 14 |
4 files changed, 18 insertions, 20 deletions
@@ -172,13 +172,7 @@ PP(pp_rv2gv) const char * const name = CopSTASHPV(PL_curcop); gv = newGVgen(name); } - if (SvTYPE(sv) < SVt_PV && SvTYPE(sv) != SVt_IV) - sv_upgrade(sv, SVt_IV); - else if (SvPVX_const(sv)) { - SvPV_free(sv); - SvLEN_set(sv, 0); - SvCUR_set(sv, 0); - } + prepare_SV_for_RV(sv); SvRV_set(sv, (SV*)gv); SvROK_on(sv); SvSETMAGIC(sv); @@ -2940,13 +2940,7 @@ Perl_vivify_ref(pTHX_ SV *sv, U32 to_what) if (!SvOK(sv)) { if (SvREADONLY(sv)) Perl_croak(aTHX_ PL_no_modify); - if (SvTYPE(sv) < SVt_PV && SvTYPE(sv) != SVt_IV) - sv_upgrade(sv, SVt_IV); - else if (SvTYPE(sv) >= SVt_PV) { - SvPV_free(sv); - SvLEN_set(sv, 0); - SvCUR_set(sv, 0); - } + prepare_SV_for_RV(sv); switch (to_what) { case OPpDEREF_SV: SvRV_set(sv, newSV(0)); @@ -7857,12 +7857,8 @@ Perl_newSVrv(pTHX_ SV *rv, const char *classname) sv_upgrade(rv, SVt_IV); } else if (SvROK(rv)) { SvREFCNT_dec(SvRV(rv)); - } else if (SvTYPE(rv) < SVt_PV && SvTYPE(rv) != SVt_IV) - sv_upgrade(rv, SVt_IV); - else if (SvTYPE(rv) >= SVt_PV) { - SvPV_free(rv); - SvCUR_set(rv, 0); - SvLEN_set(rv, 0); + } else { + prepare_SV_for_RV(rv); } SvOK_off(rv); @@ -1441,6 +1441,20 @@ the scalar's value cannot change unless written to. } \ } STMT_END +#ifdef PERL_CORE +/* Code that crops up in three places to take a scalar and ready it to hold + a reference */ +# define prepare_SV_for_RV(sv) \ + STMT_START { \ + if (SvTYPE(sv) < SVt_PV && SvTYPE(sv) != SVt_IV) \ + sv_upgrade(sv, SVt_IV); \ + else if (SvPVX_const(sv)) { \ + SvPV_free(sv); \ + SvLEN_set(sv, 0); \ + SvCUR_set(sv, 0); \ + } \ + } STMT_END +#endif #define PERL_FBM_TABLE_OFFSET 1 /* Number of bytes between EOS and table */ |