Skip to content

Commit bd6d0c9

Browse files
committed
replace assert with verify SERVER-1259
1 parent a56eef7 commit bd6d0c9

File tree

275 files changed

+2590
-2611
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

275 files changed

+2590
-2611
lines changed

buildscripts/errorcodes.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@ def assignErrorCodes():
3333

3434
def readErrorCodes( callback, replaceZero = False ):
3535

36-
quick = [ "assert" , "Exception" , "verify" ]
36+
quick = [ "assert" , "Exception"]
3737

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

4342
for x in utils.getAllSourceFiles():

docs/errors.md

Lines changed: 823 additions & 808 deletions
Large diffs are not rendered by default.

src/mongo/bson/bson-inl.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ namespace mongo {
162162
return 0;
163163
}
164164
default:
165-
assert( false);
165+
verify( false);
166166
}
167167
return -1;
168168
}
@@ -200,12 +200,12 @@ namespace mongo {
200200
}
201201

202202
inline BSONObj BSONElement::embeddedObject() const {
203-
assert( isABSONObj() );
203+
verify( isABSONObj() );
204204
return BSONObj(value());
205205
}
206206

207207
inline BSONObj BSONElement::codeWScopeObject() const {
208-
assert( type() == CodeWScope );
208+
verify( type() == CodeWScope );
209209
int strSizeWNull = *(int *)( value() + 4 );
210210
return BSONObj( value() + 4 + 4 + strSizeWNull );
211211
}
@@ -599,7 +599,7 @@ namespace mongo {
599599
len2 = strlen( p );
600600
else {
601601
size_t x = remain - len1 - 1;
602-
assert( x <= 0x7fffffff );
602+
verify( x <= 0x7fffffff );
603603
len2 = mongo::strnlen( p, (int) x );
604604
}
605605
//massert( 10319 , "Invalid regex options string", len2 != -1 ); // ERH - 4/28/10 - don't think this does anything
@@ -989,8 +989,8 @@ namespace mongo {
989989
appendAs( j.next() , i.next().fieldName() );
990990
}
991991

992-
assert( ! i.more() );
993-
assert( ! j.more() );
992+
verify( ! i.more() );
993+
verify( ! j.more() );
994994
}
995995

996996
inline BSONObj BSONObj::removeField(const StringData& name) const {

src/mongo/bson/bson.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ namespace bson {
7171
}
7272

7373
namespace mongo {
74-
#if !defined(assert)
75-
inline void assert(bool expr) {
74+
#if !defined(verify)
75+
inline void verify(bool expr) {
7676
if(!expr) {
7777
throw bson::assertion( 0 , "assertion failure in bson library" );
7878
}

src/mongo/bson/bsonelement.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ namespace mongo {
262262
/** Get raw binary data. Element must be of type BinData. Doesn't handle type 2 specially */
263263
const char *binData(int& len) const {
264264
// BinData: <int len> <byte subtype> <byte[len] data>
265-
assert( type() == BinData );
265+
verify( type() == BinData );
266266
len = valuestrsize();
267267
return value() + 5;
268268
}
@@ -281,14 +281,14 @@ namespace mongo {
281281

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

289289
/** Retrieve the regex string for a Regex element */
290290
const char *regex() const {
291-
assert(type() == RegEx);
291+
verify(type() == RegEx);
292292
return value();
293293
}
294294

@@ -480,7 +480,7 @@ namespace mongo {
480480
case CodeWScope:
481481
return 65;
482482
default:
483-
assert(0);
483+
verify(0);
484484
return -1;
485485
}
486486
}

src/mongo/bson/bsonobj.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ namespace mongo {
433433
BSONObjIterator begin() const;
434434

435435
void appendSelfToBufBuilder(BufBuilder& b) const {
436-
assert( objsize() );
436+
verify( objsize() );
437437
b.appendBuf(reinterpret_cast<const void *>( objdata() ), objsize());
438438
}
439439

@@ -451,12 +451,12 @@ namespace mongo {
451451
friend void intrusive_ptr_add_ref(Holder* h) { h->refCount++; }
452452
friend void intrusive_ptr_release(Holder* h) {
453453
#if defined(_DEBUG) // cant use dassert or DEV here
454-
assert((int)h->refCount > 0); // make sure we haven't already freed the buffer
454+
verify((int)h->refCount > 0); // make sure we haven't already freed the buffer
455455
#endif
456456
if(--(h->refCount) == 0){
457457
#if defined(_DEBUG)
458458
unsigned sz = (unsigned&) *h->data;
459-
assert(sz < BSONObjMaxInternalSize * 3);
459+
verify(sz < BSONObjMaxInternalSize * 3);
460460
memset(h->data, 0xdd, sz);
461461
#endif
462462
free(h);

src/mongo/bson/bsonobjbuilder.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
#include <cmath>
2727
#include <boost/static_assert.hpp>
2828
#if defined(MONGO_EXPOSE_MACROS)
29-
// boost changed it
30-
#undef assert
31-
#define assert MONGO_assert
29+
#define verify MONGO_verify
3230
#endif
3331
#include "bsonelement.h"
3432
#include "bsonobj.h"
@@ -123,14 +121,14 @@ namespace mongo {
123121

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

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

148146
/** add a subobject as a member */
149147
BSONObjBuilder& appendObject(const StringData& fieldName, const char * objdata , int size = 0 ) {
150-
assert( objdata );
148+
verify( objdata );
151149
if ( size == 0 ) {
152150
size = *((int*)objdata);
153151
}
154152

155-
assert( size > 4 && size < 100000000 );
153+
verify( size > 4 && size < 100000000 );
156154

157155
_b.appendNum((char) Object);
158156
_b.appendStr(fieldName);
@@ -582,7 +580,7 @@ namespace mongo {
582580
/* assume ownership of the buffer - you must then free it (with free()) */
583581
char* decouple(int& l) {
584582
char *x = _done();
585-
assert( x );
583+
verify( x );
586584
l = _b.len();
587585
_b.decouple();
588586
return x;

src/mongo/bson/bsonobjiterator.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ namespace mongo {
5858

5959
/** @return the next element in the object. For the final element, element.eoo() will be true. */
6060
BSONElement next( bool checkEnd ) {
61-
assert( _pos <= _theend );
61+
verify( _pos <= _theend );
6262
BSONElement e( _pos, checkEnd ? (int)(_theend + 1 - _pos) : -1 );
6363
_pos += e.size( checkEnd ? (int)(_theend + 1 - _pos) : -1 );
6464
return e;
6565
}
6666
BSONElement next() {
67-
assert( _pos <= _theend );
67+
verify( _pos <= _theend );
6868
BSONElement e(_pos);
6969
_pos += e.size();
7070
return e;
@@ -73,7 +73,7 @@ namespace mongo {
7373
void operator++(int) { next(); }
7474

7575
BSONElement operator*() {
76-
assert( _pos <= _theend );
76+
verify( _pos <= _theend );
7777
return BSONElement(_pos);
7878
}
7979

@@ -86,7 +86,7 @@ namespace mongo {
8686
class BSONIteratorSorted {
8787
public:
8888
~BSONIteratorSorted() {
89-
assert( _fields );
89+
verify( _fields );
9090
delete[] _fields;
9191
_fields = 0;
9292
}
@@ -96,7 +96,7 @@ namespace mongo {
9696
}
9797

9898
BSONElement next() {
99-
assert( _fields );
99+
verify( _fields );
100100
if ( _cur < _nfields )
101101
return BSONElement( _fields[_cur++] );
102102
return BSONElement();
@@ -141,7 +141,7 @@ namespace mongo {
141141
const char *f = e.fieldName();
142142
try {
143143
unsigned u = stringToNum(f);
144-
assert( u < 1000000 );
144+
verify( u < 1000000 );
145145
if( u >= v.size() )
146146
v.resize(u+1);
147147
v[u] = e;

src/mongo/bson/oid.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
#include "../db/nonce.h"
2222
#include "bsonobjbuilder.h"
2323
#include <boost/functional/hash.hpp>
24-
#undef assert
25-
#define assert MONGO_assert
24+
#define verify MONGO_verify
2625

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

@@ -71,7 +70,7 @@ namespace mongo {
7170
nonce64 a = Security::getNonceDuringInit();
7271
nonce64 b = Security::getNonceDuringInit();
7372
nonce64 c = Security::getNonceDuringInit();
74-
assert( !(a==b && b==c) );
73+
verify( !(a==b && b==c) );
7574
}
7675

7776
unsigned long long n = Security::getNonceDuringInit();
@@ -106,7 +105,7 @@ namespace mongo {
106105
// xor in the pid into _pid. this reduces the probability of collisions.
107106
foldInPid(x);
108107
ourMachineAndPid = genMachineAndPid();
109-
assert( x != ourMachineAndPid );
108+
verify( x != ourMachineAndPid );
110109
ourMachineAndPid = x;
111110
}
112111

@@ -134,7 +133,7 @@ namespace mongo {
134133
}
135134

136135
void OID::init( string s ) {
137-
assert( s.size() == 24 );
136+
verify( s.size() == 24 );
138137
const char *p = s.c_str();
139138
for( int i = 0; i < 12; i++ ) {
140139
data[i] = fromHex(p);

src/mongo/bson/util/builder.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ namespace mongo {
290290
const int maxSize = 32;
291291
char * start = _buf.grow( maxSize );
292292
int z = mongo_snprintf( start , maxSize , "%.16g" , x );
293-
assert( z >= 0 );
294-
assert( z < maxSize );
293+
verify( z >= 0 );
294+
verify( z < maxSize );
295295
_buf.l = prev + z;
296296
if( strchr(start, '.') == 0 && strchr(start, 'E') == 0 && strchr(start, 'N') == 0 ) {
297297
write( ".0" , 2 );
@@ -324,8 +324,8 @@ namespace mongo {
324324
StringBuilder& SBNUM(T val,int maxSize,const char *macro) {
325325
int prev = _buf.l;
326326
int z = mongo_snprintf( _buf.grow(maxSize) , maxSize , macro , (val) );
327-
assert( z >= 0 );
328-
assert( z < maxSize );
327+
verify( z >= 0 );
328+
verify( z < maxSize );
329329
_buf.l = prev + z;
330330
return *this;
331331
}

0 commit comments

Comments
 (0)