This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
assert_(...)
authorFather Chrysostomos <sprout@cpan.org>
Mon, 6 Aug 2012 00:22:29 +0000 (17:22 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Mon, 6 Aug 2012 05:27:04 +0000 (22:27 -0700)
This new macro expands to ‘assert(...),’ (with a trailing comma) under
debugging builds; the empty string otherwise.

It allows for the removal of some #ifdef DEBUGGINGs, which could not be
avoided otherwise.

cop.h
op.h
perl.h
sv.h

diff --git a/cop.h b/cop.h
index ed55483..8a0ea80 100644 (file)
--- a/cop.h
+++ b/cop.h
@@ -420,12 +420,8 @@ struct cop {
                                 ? GvSV(gv_fetchfile(CopFILE(c))) : NULL)
 #  define CopFILEAV(c)         (CopFILE(c) \
                                 ? GvAV(gv_fetchfile(CopFILE(c))) : NULL)
-#  ifdef DEBUGGING
-#    define CopFILEAVx(c)      (assert(CopFILE(c)), \
+#  define CopFILEAVx(c)                (assert_(CopFILE(c)) \
                                   GvAV(gv_fetchfile(CopFILE(c))))
-#  else
-#    define CopFILEAVx(c)      (GvAV(gv_fetchfile(CopFILE(c))))
-#  endif
 
 #  define CopSTASH(c)           PL_stashpad[(c)->cop_stashoff]
 #  define CopSTASH_set(c,hv)   ((c)->cop_stashoff = (hv)               \
diff --git a/op.h b/op.h
index 3f1e250..c4147ce 100644 (file)
--- a/op.h
+++ b/op.h
@@ -748,12 +748,8 @@ struct opslab {
 
 # define OPSLOT_HEADER         STRUCT_OFFSET(OPSLOT, opslot_op)
 # define OPSLOT_HEADER_P       (OPSLOT_HEADER/sizeof(I32 *))
-# ifdef DEBUGGING
-#  define OpSLOT(o)            (assert(o->op_slabbed), \
+# define OpSLOT(o)             (assert_(o->op_slabbed) \
                                 (OPSLOT *)(((char *)o)-OPSLOT_HEADER))
-# else
-#  define OpSLOT(o)            ((OPSLOT *)(((char *)o)-OPSLOT_HEADER))
-# endif
 # define OpSLAB(o)             OpSLOT(o)->opslot_slab
 # define OpslabREFCNT_dec(slab)      \
        (((slab)->opslab_refcnt == 1) \
diff --git a/perl.h b/perl.h
index ad8f6a9..af4e9bf 100644 (file)
--- a/perl.h
+++ b/perl.h
@@ -3868,6 +3868,11 @@ Gid_t getegid (void);
 #ifndef assert
 #  define assert(what) Perl_assert(what)
 #endif
+#ifdef DEBUGGING
+#  define assert_(what)        assert(what),
+#else
+#  define assert_(what)
+#endif
 
 struct ufuncs {
     I32 (*uf_val)(pTHX_ IV, SV*);
diff --git a/sv.h b/sv.h
index 4c9bc55..82eaa61 100644 (file)
--- a/sv.h
+++ b/sv.h
@@ -752,13 +752,8 @@ Set the actual length of the string which is in the SV.  See C<SvIV_set>.
 #define SvNIOK_off(sv)         (SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK| \
                                                  SVp_IOK|SVp_NOK|SVf_IVisUV))
 
-#if defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN)
-#define assert_not_ROK(sv)     ({assert(!SvROK(sv) || !SvRV(sv));}),
-#define assert_not_glob(sv)    ({assert(!isGV_with_GP(sv));}),
-#else
-#define assert_not_ROK(sv)     
-#define assert_not_glob(sv)    
-#endif
+#define assert_not_ROK(sv)     assert_(!SvROK(sv) || !SvRV(sv))
+#define assert_not_glob(sv)    assert_(!isGV_with_GP(sv))
 
 #define SvOK(sv)               ((SvTYPE(sv) == SVt_BIND)               \
                                 ? (SvFLAGS(SvRV(sv)) & SVf_OK)         \
@@ -1139,7 +1134,7 @@ sv_force_normal does nothing.
 #  define SvRV_const(sv) (0 + (sv)->sv_u.svu_rv)
 /* Don't test the core XS code yet.  */
 #  if defined (PERL_CORE) && PERL_DEBUG_COW > 1
-#    define SvPVX(sv) (0 + (assert(!SvREADONLY(sv)), (sv)->sv_u.svu_pv))
+#    define SvPVX(sv) (0 + (assert_(!SvREADONLY(sv)) (sv)->sv_u.svu_pv))
 #  else
 #  define SvPVX(sv) SvPVX_mutable(sv)
 #  endif
@@ -1147,13 +1142,8 @@ sv_force_normal does nothing.
 #  define SvLEN(sv) (0 + ((XPV*) SvANY(sv))->xpv_len)
 #  define SvEND(sv) ((sv)->sv_u.svu_pv + ((XPV*)SvANY(sv))->xpv_cur)
 
-#  ifdef DEBUGGING
-#    define SvMAGIC(sv)        (0 + *(assert(SvTYPE(sv) >= SVt_PVMG), &((XPVMG*)  SvANY(sv))->xmg_u.xmg_magic))
-#    define SvSTASH(sv)        (0 + *(assert(SvTYPE(sv) >= SVt_PVMG), &((XPVMG*)  SvANY(sv))->xmg_stash))
-#  else
-#    define SvMAGIC(sv)        (0 + ((XPVMG*)  SvANY(sv))->xmg_u.xmg_magic)
-#    define SvSTASH(sv)        (0 + ((XPVMG*)  SvANY(sv))->xmg_stash)
-#  endif
+#  define SvMAGIC(sv)  (0 + *(assert_(SvTYPE(sv) >= SVt_PVMG) &((XPVMG*)  SvANY(sv))->xmg_u.xmg_magic))
+#  define SvSTASH(sv)  (0 + *(assert_(SvTYPE(sv) >= SVt_PVMG) &((XPVMG*)  SvANY(sv))->xmg_stash))
 #else
 #  define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len
 #  define SvEND(sv) ((sv)->sv_u.svu_pv + ((XPV*)SvANY(sv))->xpv_cur)