hold a reference, and convert it to a macro define prepare_SV_for_RV().
p4raw-id: //depot/perl@32737
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);
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));
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);
} \
} 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 */