From: Nicholas Clark Date: Mon, 14 Jun 2004 15:26:38 +0000 (+0000) Subject: Assert that SV type has magic member when reading/writing. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ffb05e06c71730527accd4c1399a30e98fb7f6d5;p=p5sagit%2Fp5-mst-13.2.git Assert that SV type has magic member when reading/writing. Will catch buggy code. p4raw-id: //depot/perl@22934 --- diff --git a/sv.c b/sv.c index fe1d406..57ca682 100644 --- a/sv.c +++ b/sv.c @@ -1869,6 +1869,9 @@ Perl_sv_upgrade(pTHX_ register SV *sv, U32 mt) Perl_croak(aTHX_ "Can't upgrade that kind of scalar"); } + SvFLAGS(sv) &= ~SVTYPEMASK; + SvFLAGS(sv) |= mt; + switch (mt) { case SVt_NULL: Perl_croak(aTHX_ "Can't upgrade to undef"); @@ -2031,8 +2034,6 @@ Perl_sv_upgrade(pTHX_ register SV *sv, U32 mt) IoPAGE_LEN(sv) = 60; break; } - SvFLAGS(sv) &= ~SVTYPEMASK; - SvFLAGS(sv) |= mt; return TRUE; } diff --git a/sv.h b/sv.h index 4edd87f..bc03bb8 100644 --- a/sv.h +++ b/sv.h @@ -739,8 +739,14 @@ and leaves the UTF-8 status as it was. #define SvLENx(sv) SvLEN(sv) #define SvEND(sv)(((XPV*) SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur) #define SvENDx(sv) ((PL_Sv = (sv)), SvEND(PL_Sv)) + +#ifdef DEBUGGING +#define SvMAGIC(sv) ((assert(SvTYPE(sv) >= SVt_PVMG)), ((XPVMG*) SvANY(sv))->xmg_magic) +#define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash +#else #define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_magic #define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash +#endif /* Ask a scalar nicely to try to become an IV, if possible. Not guaranteed to stay returning void */