}
}
/* we know that type >= SVt_PV */
- SvOOK_off(PL_mess_sv);
- Safefree(SvPVX(PL_mess_sv));
+ SvPV_free(PL_mess_sv);
Safefree(SvANY(PL_mess_sv));
Safefree(PL_mess_sv);
PL_mess_sv = Nullsv;
if (SvTYPE(sv) < SVt_RV)
sv_upgrade(sv, SVt_RV);
if (SvPVX(sv)) {
- SvOOK_off(sv); /* backoff */
- if (SvLEN(sv))
- Safefree(SvPVX(sv));
+ SvPV_free(sv);
SvLEN_set(sv, 0);
SvCUR_set(sv, 0);
}
break;
default:
if (SvTYPE(sv) >= SVt_PV && SvPVX(sv) && SvLEN(sv)) {
- SvOOK_off(sv);
- Safefree(SvPVX(sv));
+ SvPV_free(sv);
SvPV_set(sv, Nullch);
SvLEN_set(sv, 0);
}
} else
#endif
{
- SvOOK_off(targ);
- if (SvLEN(targ))
- Safefree(SvPVX(targ));
+ SvPV_free(targ);
}
SvPV_set(targ, SvPVX(dstr));
SvCUR_set(targ, SvCUR(dstr));
} else
#endif
{
- SvOOK_off(TARG);
- if (SvLEN(TARG))
- Safefree(SvPVX(TARG));
+ SvPV_free(TARG);
}
SvPV_set(TARG, SvPVX(dstr));
SvCUR_set(TARG, SvCUR(dstr));
if (SvTYPE(sv) < SVt_RV)
sv_upgrade(sv, SVt_RV);
else if (SvTYPE(sv) >= SVt_PV) {
- SvOOK_off(sv);
- Safefree(SvPVX(sv));
+ SvPV_free(sv);
SvLEN_set(sv, 0);
SvCUR_set(sv, 0);
}
/* to here. */
/* XXX? Only SVt_NULL is ever upgraded to AV or HV? */
assert(!pv);
- /* FIXME. Should be able to remove this if the above assertion is
- genuinely always true. */
- (void)SvOOK_off(sv);
- if (pv)
- Safefree(pv);
+ /* FIXME. Should be able to remove all this if()... if the above
+ assertion is genuinely always true. */
+ if(SvOOK(sv)) {
+ pv -= iv;
+ SvFLAGS(sv) &= ~SVf_OOK;
+ }
+ Safefree(pv);
SvPV_set(sv, (char*)0);
SvMAGIC_set(sv, magic);
SvSTASH_set(sv, stash);
return;
}
if (SvPVX(dstr)) {
- if (SvLEN(dstr)) {
- /* Unwrap the OOK offset by hand, to save a needless
- memmove on memory that's about to be free()d. */
- char *pv = SvPVX(dstr);
- if (SvOOK(dstr)) {
- pv -= SvIVX(dstr);
- SvFLAGS(dstr) &= ~SVf_OOK;
- }
- Safefree(pv);
- }
+ SvPV_free(dstr);
SvLEN_set(dstr, 0);
SvCUR_set(dstr, 0);
}
(void)SvOK_off(sv);
return;
}
- (void)SvOOK_off(sv);
- if (SvPVX(sv) && SvLEN(sv))
- Safefree(SvPVX(sv));
+ if (SvPVX(sv))
+ SvPV_free(sv);
Renew(ptr, len+1, char);
SvPV_set(sv, ptr);
SvCUR_set(sv, len);
if (SvTYPE(rv) < SVt_RV)
sv_upgrade(rv, SVt_RV);
else if (SvTYPE(rv) > SVt_RV) {
- SvOOK_off(rv);
- if (SvPVX(rv) && SvLEN(rv))
- Safefree(SvPVX(rv));
+ SvPV_free(rv);
SvCUR_set(rv, 0);
SvLEN_set(rv, 0);
}
SvPV_renew(sv, _lEnGtH); \
} STMT_END
+#define SvPV_free(sv) \
+ STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
+ if (SvLEN(sv)) { \
+ if(SvOOK(sv)) { \
+ Safefree(SvPVX(sv) - SvIVX(sv)); \
+ SvFLAGS(sv) &= ~SVf_OOK; \
+ } else { \
+ Safefree(SvPVX(sv)); \
+ } \
+ } \
+ } STMT_END
+
#define BmRARE(sv) ((XPVBM*) SvANY(sv))->xbm_rare
#define BmUSEFUL(sv) ((XPVBM*) SvANY(sv))->xbm_useful
#define BmPREVIOUS(sv) ((XPVBM*) SvANY(sv))->xbm_previous