summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pp.c8
-rw-r--r--pp_hot.c8
-rw-r--r--sv.c8
-rw-r--r--sv.h14
4 files changed, 18 insertions, 20 deletions
diff --git a/pp.c b/pp.c
index 08ebe5e784..ed3ae325a6 100644
--- a/pp.c
+++ b/pp.c
@@ -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);
diff --git a/pp_hot.c b/pp_hot.c
index 276010c4db..764d5be0ca 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -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));
diff --git a/sv.c b/sv.c
index 7b49ce21e5..577c13415e 100644
--- a/sv.c
+++ b/sv.c
@@ -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);
diff --git a/sv.h b/sv.h
index 37b79c96bf..8e2417cc7d 100644
--- a/sv.h
+++ b/sv.h
@@ -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 */