summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Milkie <milkie@10gen.com>2012-04-18 17:53:24 -0400
committerEric Milkie <milkie@10gen.com>2012-04-18 17:53:57 -0400
commit41be3168d42f058cdda271c7aa077002d3071256 (patch)
tree4018dc6b674e260a4e961c24da3b77df57945909
parentba8d0f572c9108c0c2f279a393a854c59d475008 (diff)
downloadmongo-41be3168d42f058cdda271c7aa077002d3071256.tar.gz
SERVER-5348 backport C++ driver macro redefinition isolation
-rw-r--r--client/redef_macros.h53
-rw-r--r--client/undef_macros.h32
-rw-r--r--dbtests/macrotests.cpp18
-rw-r--r--pch.h6
-rw-r--r--util/allocator.h2
-rw-r--r--util/assert_util.h9
6 files changed, 81 insertions, 39 deletions
diff --git a/client/redef_macros.h b/client/redef_macros.h
index 897912dba2b..5a39561afd5 100644
--- a/client/redef_macros.h
+++ b/client/redef_macros.h
@@ -1,4 +1,4 @@
-/** @file redef_macros.h macros the implementation uses.
+/** @file redef_macros.h macros for mongo internals
@see undef_macros.h undefines these after use to minimize name pollution.
*/
@@ -20,42 +20,83 @@
// If you define a new global un-prefixed macro, please add it here and in undef_macros
-// #pragma once // this file is intended to be processed multiple times
-
-#if defined(MONGO_MACROS_CLEANED)
+#define MONGO_MACROS_PUSHED 1
// util/allocator.h
+#pragma push_macro("malloc")
+#undef malloc
#define malloc MONGO_malloc
+#pragma push_macro("realloc")
+#undef realloc
#define realloc MONGO_realloc
// util/assert_util.h
+#pragma push_macro("assert")
+#undef assert
#define assert MONGO_assert
+#pragma push_macro("verify")
+#undef verify
+#define verify MONGO_verify
+#pragma push_macro("dassert")
+#undef dassert
#define dassert MONGO_dassert
+#pragma push_macro("wassert")
+#undef wassert
#define wassert MONGO_wassert
+#pragma push_macro("massert")
+#undef massert
#define massert MONGO_massert
+#pragma push_macro("uassert")
+#undef uassert
#define uassert MONGO_uassert
#define BOOST_CHECK_EXCEPTION MONGO_BOOST_CHECK_EXCEPTION
+#pragma push_macro("DESTRUCTOR_GUARD")
+#undef DESTRUCTOR_GUARD
#define DESTRUCTOR_GUARD MONGO_DESTRUCTOR_GUARD
// util/goodies.h
+#pragma push_macro("PRINT")
+#undef PRINT
#define PRINT MONGO_PRINT
+#pragma push_macro("PRINTFL")
+#undef PRINTFL
#define PRINTFL MONGO_PRINTFL
+#pragma push_macro("asctime")
+#undef asctime
#define asctime MONGO_asctime
+#pragma push_macro("gmtime")
+#undef gmtime
#define gmtime MONGO_gmtime
+#pragma push_macro("localtime")
+#undef localtime
#define localtime MONGO_localtime
+#pragma push_macro("ctime")
+#undef ctime
#define ctime MONGO_ctime
// util/debug_util.h
+#pragma push_macro("DEV")
+#undef DEV
#define DEV MONGO_DEV
+#pragma push_macro("DEBUGGING")
+#undef DEBUGGING
#define DEBUGGING MONGO_DEBUGGING
+#pragma push_macro("SOMETIMES")
+#undef SOMETIMES
#define SOMETIMES MONGO_SOMETIMES
+#pragma push_macro("OCCASIONALLY")
+#undef OCCASIONALLY
#define OCCASIONALLY MONGO_OCCASIONALLY
+#pragma push_macro("RARELY")
+#undef RARELY
#define RARELY MONGO_RARELY
+#pragma push_macro("ONCE")
+#undef ONCE
#define ONCE MONGO_ONCE
// util/log.h
+#pragma push_macro("LOG")
+#undef LOG
#define LOG MONGO_LOG
-#undef MONGO_MACROS_CLEANED
-#endif
diff --git a/client/undef_macros.h b/client/undef_macros.h
index 30ece615747..c880f063771 100644
--- a/client/undef_macros.h
+++ b/client/undef_macros.h
@@ -19,43 +19,65 @@
// #pragma once // this file is intended to be processed multiple times
+#if !defined (MONGO_EXPOSE_MACROS)
-/** MONGO_EXPOSE_MACROS - when defined, indicates that you are compiling a mongo program rather
- than just using the C++ driver.
-*/
-#if !defined(MONGO_EXPOSE_MACROS) && !defined(MONGO_MACROS_CLEANED)
+#ifdef MONGO_MACROS_PUSHED
// util/allocator.h
#undef malloc
+#pragma pop_macro("malloc")
#undef realloc
+#pragma pop_macro("realloc")
// util/assert_util.h
#undef assert
+#pragma pop_macro("assert")
#undef dassert
+#pragma pop_macro("dassert")
#undef wassert
+#pragma pop_macro("wassert")
#undef massert
+#pragma pop_macro("massert")
#undef uassert
+#pragma pop_macro("uassert")
#undef BOOST_CHECK_EXCEPTION
+#undef verify
+#pragma pop_macro("verify")
#undef DESTRUCTOR_GUARD
+#pragma pop_macro("DESTRUCTOR_GUARD")
// util/goodies.h
#undef PRINT
+#pragma pop_macro("PRINT")
#undef PRINTFL
+#pragma pop_macro("PRINTFL")
#undef asctime
+#pragma pop_macro("asctime")
#undef gmtime
+#pragma pop_macro("gmtime")
#undef localtime
+#pragma pop_macro("localtime")
#undef ctime
+#pragma pop_macro("ctime")
// util/debug_util.h
#undef DEV
+#pragma pop_macro("DEV")
#undef DEBUGGING
+#pragma pop_macro("DEBUGGING")
#undef SOMETIMES
+#pragma pop_macro("SOMETIMES")
#undef OCCASIONALLY
+#pragma pop_macro("OCCASIONALLY")
#undef RARELY
+#pragma pop_macro("RARELY")
#undef ONCE
+#pragma pop_macro("ONCE")
// util/log.h
#undef LOG
+#pragma pop_macro("LOG")
-#define MONGO_MACROS_CLEANED
+#undef MONGO_MACROS_PUSHED
+#endif
#endif
diff --git a/dbtests/macrotests.cpp b/dbtests/macrotests.cpp
index f547c851677..36167b076c5 100644
--- a/dbtests/macrotests.cpp
+++ b/dbtests/macrotests.cpp
@@ -22,26 +22,16 @@
# error malloc defined 0
#endif
-#ifdef assert
-# error assert defined 1
-#endif
-
-#include "../client/parallel.h" //uses assert
-
-#ifdef assert
-# error assert defined 2
-#endif
-
#include "../client/redef_macros.h"
-#ifndef assert
-# error assert not defined 3
+#ifndef malloc
+# error malloc not defined
#endif
#include "../client/undef_macros.h"
-#ifdef assert
-# error assert defined 3
+#ifdef malloc
+# error malloc defined 1
#endif
diff --git a/pch.h b/pch.h
index 1e9684d16d6..1211e26adc6 100644
--- a/pch.h
+++ b/pch.h
@@ -98,8 +98,6 @@
#include <boost/thread/condition.hpp>
#include <boost/thread/recursive_mutex.hpp>
#include <boost/thread/xtime.hpp>
-#undef assert
-#define assert MONGO_assert
namespace mongo {
@@ -152,6 +150,8 @@ namespace mongo {
}
+#include "util/allocator.h"
+#include "client/redef_macros.h"
// TODO: Rework the headers so we don't need this craziness
#include "bson/inline_decls.h"
@@ -160,7 +160,7 @@ namespace mongo {
#include "util/debug_util.h"
#include "util/goodies.h"
#include "util/log.h"
-#include "util/allocator.h"
+
#include "util/assert_util.h"
namespace mongo {
diff --git a/util/allocator.h b/util/allocator.h
index a642e7cab56..23ee4ee47b0 100644
--- a/util/allocator.h
+++ b/util/allocator.h
@@ -32,8 +32,6 @@ namespace mongo {
}
#define MONGO_malloc mongo::ourmalloc
-#define malloc MONGO_malloc
#define MONGO_realloc mongo::ourrealloc
-#define realloc MONGO_realloc
} // namespace mongo
diff --git a/util/assert_util.h b/util/assert_util.h
index b4c68b7de34..c35f651828b 100644
--- a/util/assert_util.h
+++ b/util/assert_util.h
@@ -171,20 +171,13 @@ namespace mongo {
/** in the mongodb source, use verify() instead of assert(). verify is always evaluated even in release builds. */
inline void verify( int msgid , bool testOK ) { if ( ! testOK ) verifyFailed( msgid ); }
-#ifdef assert
-#undef assert
-#endif
-
#define MONGO_assert(_Expression) (void)( MONGO_likely(!!(_Expression)) || (mongo::asserted(#_Expression, __FILE__, __LINE__), 0) )
-#define assert MONGO_assert
/* "user assert". if asserts, user did something wrong, not our code */
#define MONGO_uassert(msgid, msg, expr) (void)( MONGO_likely(!!(expr)) || (mongo::uasserted(msgid, msg), 0) )
-#define uassert MONGO_uassert
/* warning only - keeps going */
#define MONGO_wassert(_Expression) (void)( MONGO_likely(!!(_Expression)) || (mongo::wasserted(#_Expression, __FILE__, __LINE__), 0) )
-#define wassert MONGO_wassert
/* display a message, no context, and throw assertionexception
@@ -192,7 +185,6 @@ namespace mongo {
display happening.
*/
#define MONGO_massert(msgid, msg, expr) (void)( MONGO_likely(!!(expr)) || (mongo::msgasserted(msgid, msg), 0) )
-#define massert MONGO_massert
/* dassert is 'debug assert' -- might want to turn off for production as these
could be slow.
@@ -202,7 +194,6 @@ namespace mongo {
#else
# define MONGO_dassert(x)
#endif
-#define dassert MONGO_dassert
// some special ids that we want to duplicate