]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
assert: detect when /usr/include/assert.h clobbers us
authorSage Weil <sage@inktank.com>
Wed, 6 Jun 2012 23:06:28 +0000 (16:06 -0700)
committerSage Weil <sage@inktank.com>
Wed, 6 Jun 2012 23:07:04 +0000 (16:07 -0700)
The normal assert.h is very rude in that it clobbers any existing assert
define and replaces it with its own.  An sadly, lots of things we include
include the generic version.

Be extra rude in response.  Clobber any existing assert #define, and also
#define _ASSERT_H to be a magic value that our commonly-used dendl #define
depends on.  This way we get a compile error if the system version replaces
out own.

This is imperfect, since we will only detect their rudeness when we use
the debug macros.  I'm not coming up with something that is more widely
used that would work better, however.

Signed-off-by: Sage Weil <sage@inktank.com>
src/common/dout.h
src/include/assert.h

index e6099315567d6065efc63fe41849a0cb4be208c1..f5536ac9f2218db196acf1691b7666e1bdaee6dd 100644 (file)
@@ -61,8 +61,10 @@ inline std::ostream& operator<<(std::ostream& out, _bad_endl_use_dendl_t) {
 #define lgeneric_dout(cct, v) dout_impl(cct, ceph_subsys_, v) *_dout
 #define lgeneric_derr(cct) dout_impl(cct, ceph_subsys_, -1) *_dout
 
+// NOTE: depend on magic value in _ASSERT_H so that we detect when
+// /usr/include/assert.h clobbers our fancier version.
 #define dendl std::flush;                              \
-      _dout_cct->_log->submit_entry(_dout_e);          \
+  _ASSERT_H->_log->submit_entry(_dout_e);              \
     }                                          \
   } while (0)
 
index 08a13daa2d4e3f7089f9ad4e6d2d1a338226950e..81a37a84be6bf1ea8af1388cbaf568ca5ae080b3 100644 (file)
@@ -105,9 +105,14 @@ using namespace ceph;
 # undef assert
 #endif
 
+// make _ASSERT_H something that *must* have a value other than what
+// /usr/include/assert.h gives it (nothing!), so that we detect when
+// our assert is clobbered.
+#undef _ASSERT_H
+#define _ASSERT_H _dout_cct
+
 #define assert(expr)                                                   \
   ((expr)                                                              \
    ? __CEPH_ASSERT_VOID_CAST (0)                                       \
    : __ceph_assert_fail (__STRING(expr), __FILE__, __LINE__, __ASSERT_FUNCTION))
 
-#undef _ASSERT_H