From d060bfb595b04ba33f90a8efba1dcafe8267cb07 Mon Sep 17 00:00:00 2001 From: Mathias Stearn Date: Fri, 14 May 2010 13:33:16 -0400 Subject: [PATCH] convert massert and uassert back to macros --- client/redef_macros.h | 2 ++ client/undef_macros.h | 2 ++ db/index_geo2d.cpp | 2 +- db/repl.cpp | 2 +- tools/sniffer.cpp | 1 - util/assert_util.h | 36 ++++-------------------------------- 6 files changed, 10 insertions(+), 35 deletions(-) diff --git a/client/redef_macros.h b/client/redef_macros.h index 203a6362946..dd2e66f5a31 100644 --- a/client/redef_macros.h +++ b/client/redef_macros.h @@ -29,6 +29,8 @@ #define assert MONGO_assert #define dassert MONGO_dassert #define wassert MONGO_wassert +#define massert MONGO_massert +#define uassert MONGO_uassert #define BOOST_CHECK_EXCEPTION MONGO_BOOST_CHECK_EXCEPTION #define DESTRUCTOR_GUARD MONGO_DESTRUCTOR_GUARD diff --git a/client/undef_macros.h b/client/undef_macros.h index 5f7df1b7e9b..cce8692ffab 100644 --- a/client/undef_macros.h +++ b/client/undef_macros.h @@ -33,6 +33,8 @@ #undef assert #undef dassert #undef wassert +#undef massert +#undef uassert #undef BOOST_CHECK_EXCEPTION #undef DESTRUCTOR_GUARD diff --git a/db/index_geo2d.cpp b/db/index_geo2d.cpp index 5f6554a88c2..8978853f7e9 100644 --- a/db/index_geo2d.cpp +++ b/db/index_geo2d.cpp @@ -417,7 +417,7 @@ namespace mongo { uassert( 13068 , "geo field only has 1 element" , i.more() ); BSONElement y = i.next(); - uassert( 13026 , "geo values have to be numbers" , o , x.isNumber() && y.isNumber() ); + uassert( 13026 , "geo values have to be numbers: " + o.toString() , x.isNumber() && y.isNumber() ); return _hash( x.number() , y.number() ); } diff --git a/db/repl.cpp b/db/repl.cpp index 197b322b7f2..ec9293902c1 100644 --- a/db/repl.cpp +++ b/db/repl.cpp @@ -1065,7 +1065,7 @@ namespace mongo { BSONObj last = conn->findOne( _ns.c_str(), Query( b.done() ).sort( BSON( "$natural" << -1 ) ) ); if ( !last.isEmpty() ) { BSONElement ts = last.getField( "ts" ); - massert( 10386 , "non Date ts found", last, ts.type() == Date || ts.type() == Timestamp ); + massert( 10386 , "non Date ts found: " + last.toString(), ts.type() == Date || ts.type() == Timestamp ); syncedTo = OpTime( ts.date() ); } } diff --git a/tools/sniffer.cpp b/tools/sniffer.cpp index 9eda16761ae..a417dbea5e5 100644 --- a/tools/sniffer.cpp +++ b/tools/sniffer.cpp @@ -68,7 +68,6 @@ using mongo::BufBuilder; using mongo::DBClientConnection; using mongo::QueryResult; using mongo::MemoryMappedFile; -using mongo::uassert; #define SNAP_LEN 65535 diff --git a/util/assert_util.h b/util/assert_util.h index 5c6e07d0a91..12c9c8dbae3 100644 --- a/util/assert_util.h +++ b/util/assert_util.h @@ -166,23 +166,8 @@ namespace mongo { #define assert MONGO_assert /* "user assert". if asserts, user did something wrong, not our code */ - inline void uassert(unsigned msgid, string msg, bool expr) { - if( !expr ) uasserted(msgid, msg.c_str()); - } - - template - inline void uassert(unsigned msgid, string msg, const T&t , bool expr) { - if( !expr ){ - stringstream ss; - ss << msg << " " << t.toString(); - uasserted(msgid, ss.str()); - } - } - - - inline void uassert(unsigned msgid, const char * msg, bool expr) { - if( !expr ) uasserted(msgid, msg); - } +#define MONGO_uassert(msgid, msg, expr) (void)( (!!(expr)) || (mongo::uasserted(msgid, msg), 0) ) +#define uassert MONGO_uassert /* warning only - keeps going */ #define MONGO_wassert(_Expression) (void)( (!!(_Expression)) || (mongo::wasserted(#_Expression, __FILE__, __LINE__), 0) ) @@ -193,21 +178,8 @@ namespace mongo { easy way to throw an exception and log something without our stack trace display happening. */ - inline void massert(unsigned msgid, string msg, bool expr) { - if( !expr) msgasserted(msgid, msg.c_str()); - } - inline void massert(unsigned msgid, const char * msg, bool expr) { - if( !expr) msgasserted(msgid, msg); - } - template - inline void massert(unsigned msgid, const string& msg, const T& t, bool expr) { - if ( ! expr ){ - stringstream ss; - ss << msg << " " << (string)t; - string s = ss.str(); - msgasserted( msgid, s.c_str() ); - } - } +#define MONGO_massert(msgid, msg, expr) (void)( (!!(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.