Skip to content

Commit

Permalink
replace assert with verify SERVER-1259
Browse files Browse the repository at this point in the history
  • Loading branch information
erh committed Mar 26, 2012
1 parent a56eef7 commit bd6d0c9
Show file tree
Hide file tree
Showing 275 changed files with 2,590 additions and 2,611 deletions.
5 changes: 2 additions & 3 deletions buildscripts/errorcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ def assignErrorCodes():

def readErrorCodes( callback, replaceZero = False ):

quick = [ "assert" , "Exception" , "verify" ]
quick = [ "assert" , "Exception"]

ps = [ re.compile( "(([umsgf]asser(t|ted))) *\(( *)(\d+)" ) ,
re.compile( "((User|Msg|MsgAssertion)Exceptio(n))\(( *)(\d+)" ) ,
re.compile( "(((verify))) *\(( *)(\d+)" )
re.compile( "((User|Msg|MsgAssertion)Exceptio(n))\(( *)(\d+)" )
]

for x in utils.getAllSourceFiles():
Expand Down
1,631 changes: 823 additions & 808 deletions docs/errors.md

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/mongo/bson/bson-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ namespace mongo {
return 0;
}
default:
assert( false);
verify( false);
}
return -1;
}
Expand Down Expand Up @@ -200,12 +200,12 @@ namespace mongo {
}

inline BSONObj BSONElement::embeddedObject() const {
assert( isABSONObj() );
verify( isABSONObj() );
return BSONObj(value());
}

inline BSONObj BSONElement::codeWScopeObject() const {
assert( type() == CodeWScope );
verify( type() == CodeWScope );
int strSizeWNull = *(int *)( value() + 4 );
return BSONObj( value() + 4 + 4 + strSizeWNull );
}
Expand Down Expand Up @@ -599,7 +599,7 @@ namespace mongo {
len2 = strlen( p );
else {
size_t x = remain - len1 - 1;
assert( x <= 0x7fffffff );
verify( x <= 0x7fffffff );
len2 = mongo::strnlen( p, (int) x );
}
//massert( 10319 , "Invalid regex options string", len2 != -1 ); // ERH - 4/28/10 - don't think this does anything
Expand Down Expand Up @@ -989,8 +989,8 @@ namespace mongo {
appendAs( j.next() , i.next().fieldName() );
}

assert( ! i.more() );
assert( ! j.more() );
verify( ! i.more() );
verify( ! j.more() );
}

inline BSONObj BSONObj::removeField(const StringData& name) const {
Expand Down
4 changes: 2 additions & 2 deletions src/mongo/bson/bson.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ namespace bson {
}

namespace mongo {
#if !defined(assert)
inline void assert(bool expr) {
#if !defined(verify)
inline void verify(bool expr) {
if(!expr) {
throw bson::assertion( 0 , "assertion failure in bson library" );
}
Expand Down
8 changes: 4 additions & 4 deletions src/mongo/bson/bsonelement.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ namespace mongo {
/** Get raw binary data. Element must be of type BinData. Doesn't handle type 2 specially */
const char *binData(int& len) const {
// BinData: <int len> <byte subtype> <byte[len] data>
assert( type() == BinData );
verify( type() == BinData );
len = valuestrsize();
return value() + 5;
}
Expand All @@ -281,14 +281,14 @@ namespace mongo {

BinDataType binDataType() const {
// BinData: <int len> <byte subtype> <byte[len] data>
assert( type() == BinData );
verify( type() == BinData );
unsigned char c = (value() + 4)[0];
return (BinDataType)c;
}

/** Retrieve the regex string for a Regex element */
const char *regex() const {
assert(type() == RegEx);
verify(type() == RegEx);
return value();
}

Expand Down Expand Up @@ -480,7 +480,7 @@ namespace mongo {
case CodeWScope:
return 65;
default:
assert(0);
verify(0);
return -1;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/mongo/bson/bsonobj.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ namespace mongo {
BSONObjIterator begin() const;

void appendSelfToBufBuilder(BufBuilder& b) const {
assert( objsize() );
verify( objsize() );
b.appendBuf(reinterpret_cast<const void *>( objdata() ), objsize());
}

Expand All @@ -451,12 +451,12 @@ namespace mongo {
friend void intrusive_ptr_add_ref(Holder* h) { h->refCount++; }
friend void intrusive_ptr_release(Holder* h) {
#if defined(_DEBUG) // cant use dassert or DEV here
assert((int)h->refCount > 0); // make sure we haven't already freed the buffer
verify((int)h->refCount > 0); // make sure we haven't already freed the buffer
#endif
if(--(h->refCount) == 0){
#if defined(_DEBUG)
unsigned sz = (unsigned&) *h->data;
assert(sz < BSONObjMaxInternalSize * 3);
verify(sz < BSONObjMaxInternalSize * 3);
memset(h->data, 0xdd, sz);
#endif
free(h);
Expand Down
14 changes: 6 additions & 8 deletions src/mongo/bson/bsonobjbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
#include <cmath>
#include <boost/static_assert.hpp>
#if defined(MONGO_EXPOSE_MACROS)
// boost changed it
#undef assert
#define assert MONGO_assert
#define verify MONGO_verify
#endif
#include "bsonelement.h"
#include "bsonobj.h"
Expand Down Expand Up @@ -123,14 +121,14 @@ namespace mongo {

/** append element to the object we are building */
BSONObjBuilder& append( const BSONElement& e) {
assert( !e.eoo() ); // do not append eoo, that would corrupt us. the builder auto appends when done() is called.
verify( !e.eoo() ); // do not append eoo, that would corrupt us. the builder auto appends when done() is called.
_b.appendBuf((void*) e.rawdata(), e.size());
return *this;
}

/** append an element but with a new name */
BSONObjBuilder& appendAs(const BSONElement& e, const StringData& fieldName) {
assert( !e.eoo() ); // do not append eoo, that would corrupt us. the builder auto appends when done() is called.
verify( !e.eoo() ); // do not append eoo, that would corrupt us. the builder auto appends when done() is called.
_b.appendNum((char) e.type());
_b.appendStr(fieldName);
_b.appendBuf((void *) e.value(), e.valuesize());
Expand All @@ -147,12 +145,12 @@ namespace mongo {

/** add a subobject as a member */
BSONObjBuilder& appendObject(const StringData& fieldName, const char * objdata , int size = 0 ) {
assert( objdata );
verify( objdata );
if ( size == 0 ) {
size = *((int*)objdata);
}

assert( size > 4 && size < 100000000 );
verify( size > 4 && size < 100000000 );

_b.appendNum((char) Object);
_b.appendStr(fieldName);
Expand Down Expand Up @@ -582,7 +580,7 @@ namespace mongo {
/* assume ownership of the buffer - you must then free it (with free()) */
char* decouple(int& l) {
char *x = _done();
assert( x );
verify( x );
l = _b.len();
_b.decouple();
return x;
Expand Down
12 changes: 6 additions & 6 deletions src/mongo/bson/bsonobjiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ namespace mongo {

/** @return the next element in the object. For the final element, element.eoo() will be true. */
BSONElement next( bool checkEnd ) {
assert( _pos <= _theend );
verify( _pos <= _theend );
BSONElement e( _pos, checkEnd ? (int)(_theend + 1 - _pos) : -1 );
_pos += e.size( checkEnd ? (int)(_theend + 1 - _pos) : -1 );
return e;
}
BSONElement next() {
assert( _pos <= _theend );
verify( _pos <= _theend );
BSONElement e(_pos);
_pos += e.size();
return e;
Expand All @@ -73,7 +73,7 @@ namespace mongo {
void operator++(int) { next(); }

BSONElement operator*() {
assert( _pos <= _theend );
verify( _pos <= _theend );
return BSONElement(_pos);
}

Expand All @@ -86,7 +86,7 @@ namespace mongo {
class BSONIteratorSorted {
public:
~BSONIteratorSorted() {
assert( _fields );
verify( _fields );
delete[] _fields;
_fields = 0;
}
Expand All @@ -96,7 +96,7 @@ namespace mongo {
}

BSONElement next() {
assert( _fields );
verify( _fields );
if ( _cur < _nfields )
return BSONElement( _fields[_cur++] );
return BSONElement();
Expand Down Expand Up @@ -141,7 +141,7 @@ namespace mongo {
const char *f = e.fieldName();
try {
unsigned u = stringToNum(f);
assert( u < 1000000 );
verify( u < 1000000 );
if( u >= v.size() )
v.resize(u+1);
v[u] = e;
Expand Down
9 changes: 4 additions & 5 deletions src/mongo/bson/oid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
#include "../db/nonce.h"
#include "bsonobjbuilder.h"
#include <boost/functional/hash.hpp>
#undef assert
#define assert MONGO_assert
#define verify MONGO_verify

BOOST_STATIC_ASSERT( sizeof(mongo::OID) == 12 );

Expand Down Expand Up @@ -71,7 +70,7 @@ namespace mongo {
nonce64 a = Security::getNonceDuringInit();
nonce64 b = Security::getNonceDuringInit();
nonce64 c = Security::getNonceDuringInit();
assert( !(a==b && b==c) );
verify( !(a==b && b==c) );
}

unsigned long long n = Security::getNonceDuringInit();
Expand Down Expand Up @@ -106,7 +105,7 @@ namespace mongo {
// xor in the pid into _pid. this reduces the probability of collisions.
foldInPid(x);
ourMachineAndPid = genMachineAndPid();
assert( x != ourMachineAndPid );
verify( x != ourMachineAndPid );
ourMachineAndPid = x;
}

Expand Down Expand Up @@ -134,7 +133,7 @@ namespace mongo {
}

void OID::init( string s ) {
assert( s.size() == 24 );
verify( s.size() == 24 );
const char *p = s.c_str();
for( int i = 0; i < 12; i++ ) {
data[i] = fromHex(p);
Expand Down
8 changes: 4 additions & 4 deletions src/mongo/bson/util/builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ namespace mongo {
const int maxSize = 32;
char * start = _buf.grow( maxSize );
int z = mongo_snprintf( start , maxSize , "%.16g" , x );
assert( z >= 0 );
assert( z < maxSize );
verify( z >= 0 );
verify( z < maxSize );
_buf.l = prev + z;
if( strchr(start, '.') == 0 && strchr(start, 'E') == 0 && strchr(start, 'N') == 0 ) {
write( ".0" , 2 );
Expand Down Expand Up @@ -324,8 +324,8 @@ namespace mongo {
StringBuilder& SBNUM(T val,int maxSize,const char *macro) {
int prev = _buf.l;
int z = mongo_snprintf( _buf.grow(maxSize) , maxSize , macro , (val) );
assert( z >= 0 );
assert( z < maxSize );
verify( z >= 0 );
verify( z < maxSize );
_buf.l = prev + z;
return *this;
}
Expand Down
4 changes: 2 additions & 2 deletions src/mongo/bson/util/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ namespace mongo {
}
time_t toTimeT() const {
// cant use uassert from bson/util
assert((long long)millis >= 0); // TODO when millis is signed, delete
assert(((long long)millis/1000) < (std::numeric_limits<time_t>::max)());
verify((long long)millis >= 0); // TODO when millis is signed, delete
verify(((long long)millis/1000) < (std::numeric_limits<time_t>::max)());
return millis / 1000;
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/mongo/client/clientAndShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ namespace mongo {
}

void Shard::getAllShards( vector<Shard>& all ) {
assert(0);
verify(0);
}

bool Shard::isAShardNode( const string& ident ) {
assert(0);
verify(0);
return false;
}

string prettyHostName() {
assert(0);
verify(0);
return "";
}

Expand Down
2 changes: 1 addition & 1 deletion src/mongo/client/clientOnly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace mongo {
string dynHostMyName() { return ""; }

void dynHostResolve(string& name, int& port) {
assert(false);
verify(false);
}

}
8 changes: 4 additions & 4 deletions src/mongo/client/connpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace mongo {
continue;
}

assert( sc.conn->getSoTimeout() == socketTimeout );
verify( sc.conn->getSoTimeout() == socketTimeout );

return sc.conn;

Expand Down Expand Up @@ -133,7 +133,7 @@ namespace mongo {
}

DBClientBase* DBConnectionPool::_get(const string& ident , double socketTimeout ) {
assert( ! inShutdown() );
verify( ! inShutdown() );
scoped_lock L(_mutex);
PoolForHost& p = _pools[PoolKey(ident,socketTimeout)];
return p.get( this , socketTimeout );
Expand Down Expand Up @@ -347,7 +347,7 @@ namespace mongo {
++ap;
++bp;
}
assert(false);
verify(false);
}

bool DBConnectionPool::poolKeyCompare::operator()( const PoolKey& a , const PoolKey& b ) const {
Expand Down Expand Up @@ -387,7 +387,7 @@ namespace mongo {
// ------ ScopedDbConnection ------

ScopedDbConnection * ScopedDbConnection::steal() {
assert( _conn );
verify( _conn );
ScopedDbConnection * n = new ScopedDbConnection( _host , _conn, _socketTimeout );
_conn = 0;
return n;
Expand Down
6 changes: 3 additions & 3 deletions src/mongo/client/connpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ namespace mongo {
: _created(0) {}

PoolForHost( const PoolForHost& other ) {
assert(other._pool.size() == 0);
verify(other._pool.size() == 0);
_created = other._created;
assert( _created == 0 );
verify( _created == 0 );
}

~PoolForHost();
Expand All @@ -50,7 +50,7 @@ namespace mongo {
void createdOne( DBClientBase * base );
long long numCreated() const { return _created; }

ConnectionString::ConnectionType type() const { assert(_created); return _type; }
ConnectionString::ConnectionType type() const { verify(_created); return _type; }

/**
* gets a connection or return NULL
Expand Down
Loading

0 comments on commit bd6d0c9

Please sign in to comment.