summaryrefslogtreecommitdiff
path: root/sv.h
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2006-02-19 20:10:34 +0000
committerNicholas Clark <nick@ccl4.org>2006-02-19 20:10:34 +0000
commit05ef5f8f807e05aa6ac8d4f78bb7f33dd4496cdb (patch)
tree6a1e027d0f5e470da8b162db9d97aa68ae2b3ede /sv.h
parent0aa395f8d7800f582dd6179dfa4fb15674fdc9d2 (diff)
downloadperl-05ef5f8f807e05aa6ac8d4f78bb7f33dd4496cdb.tar.gz
Under -DDEBUGGING, assert that SvIVX, SvUVX and SvNVX aren't being
used on scalars that don't have the memory allocated. Correct SvSTASH and SvMAGIC to only evaluate the sv argument once. p4raw-id: //depot/perl@27229
Diffstat (limited to 'sv.h')
-rw-r--r--sv.h36
1 files changed, 30 insertions, 6 deletions
diff --git a/sv.h b/sv.h
index dd4302c498..ae1c26d549 100644
--- a/sv.h
+++ b/sv.h
@@ -897,18 +897,42 @@ in gv.h: */
# define SvSTASH(sv) (0 + ((XPVMG*) SvANY(sv))->xmg_stash)
# endif
#else
-# define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv
-# define SvUVX(sv) ((XPVUV*) SvANY(sv))->xuv_uv
-# define SvNVX(sv) ((XPVNV*) SvANY(sv))->xnv_nv
# define SvPVX(sv) ((sv)->sv_u.svu_pv)
# define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur
# define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len
# define SvEND(sv) ((sv)->sv_u.svu_pv + ((XPV*)SvANY(sv))->xpv_cur)
-# ifdef DEBUGGING
-# define SvMAGIC(sv) (*(assert(SvTYPE(sv) >= SVt_PVMG), &((XPVMG*) SvANY(sv))->xmg_magic))
-# define SvSTASH(sv) (*(assert(SvTYPE(sv) >= SVt_PVMG), &((XPVMG*) SvANY(sv))->xmg_stash))
+# if defined (DEBUGGING) && defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN)
+/* These get expanded inside other macros that already use a variable _sv */
+# define SvIVX(sv) \
+ (*({ SV *const _svi = (SV *) sv; \
+ assert(SvTYPE(_svi) == SVt_IV || SvTYPE(_svi) >= SVt_PVIV); \
+ &(((XPVIV*) SvANY(_svi))->xiv_iv); \
+ }))
+# define SvUVX(sv) \
+ (*({ SV *const _svi = (SV *) sv; \
+ assert(SvTYPE(_svi) == SVt_IV || SvTYPE(_svi) >= SVt_PVIV); \
+ &(((XPVUV*) SvANY(_svi))->xuv_uv); \
+ }))
+# define SvNVX(sv) \
+ (*({ SV *const _svi = (SV *) sv; \
+ assert(SvTYPE(_svi) == SVt_NV || SvTYPE(_svi) >= SVt_PVNV); \
+ &(((XPVNV*) SvANY(_svi))->xnv_nv); \
+ }))
+# define SvMAGIC(sv) \
+ (*({ SV *const _svi = (SV *) sv; \
+ assert(SvTYPE(_svi) >= SVt_PVMG); \
+ &(((XPVMG*) SvANY(_svi))->xmg_magic); \
+ }))
+# define SvSTASH(sv) \
+ (*({ SV *const _svi = (SV *) sv; \
+ assert(SvTYPE(_svi) >= SVt_PVMG); \
+ &(((XPVMG*) SvANY(_svi))->xmg_stash); \
+ }))
# else
+# define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv
+# define SvUVX(sv) ((XPVUV*) SvANY(sv))->xuv_uv
+# define SvNVX(sv) ((XPVNV*) SvANY(sv))->xnv_nv
# define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_magic
# define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash
# endif