From 593bf1f12683fb79b428ebded1dbacd4df0a4ac3 Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 18 Feb 2009 13:42:32 -0500 Subject: [PATCH] virtual dtors == good --- SConstruct | 2 +- client/dbclient.h | 1 + db/commands.h | 1 + db/cursor.h | 1 + db/pdfile.h | 1 + db/replset.h | 1 + db/security.h | 2 +- dbtests/btreetests.cpp | 1 + dbtests/jsobjtests.cpp | 2 ++ dbtests/jsontests.cpp | 3 +++ dbtests/mockdbclient.h | 1 + dbtests/namespacetests.cpp | 4 ++-- dbtests/pairingtests.cpp | 2 ++ dbtests/pdfiletests.cpp | 2 +- dbtests/queryoptimizertests.cpp | 2 ++ dbtests/querytests.cpp | 1 + dbtests/repltests.cpp | 1 + mongo.xcodeproj/project.pbxproj | 16 ++++++++++++++++ s/request.h | 1 + s/shardkey.h | 1 + util/log.h | 2 ++ util/message.h | 1 + util/miniwebserver.h | 1 + util/unittest.h | 1 + 24 files changed, 46 insertions(+), 5 deletions(-) diff --git a/SConstruct b/SConstruct index 54385f15a66..4a942ba148f 100644 --- a/SConstruct +++ b/SConstruct @@ -301,7 +301,7 @@ if useJavaHome: if nix: - env.Append( CPPFLAGS="-fPIC -fno-strict-aliasing -ggdb -pthread -Wall -Wsign-compare -Wno-non-virtual-dtor" ) + env.Append( CPPFLAGS="-fPIC -fno-strict-aliasing -ggdb -pthread -Wall -Wsign-compare -Wnon-virtual-dtor" ) env.Append( LINKFLAGS=" -fPIC " ) env.Append( LIBS=[] ) diff --git a/client/dbclient.h b/client/dbclient.h index 06d587e85d8..70ab322e8cc 100644 --- a/client/dbclient.h +++ b/client/dbclient.h @@ -123,6 +123,7 @@ namespace mongo { */ class DBConnector { public: + virtual ~DBConnector() {} virtual bool call( Message &toSend, Message &response, bool assertOk=true ) = 0; virtual void say( Message &toSend ) = 0; virtual void sayPiggyBack( Message &toSend ) = 0; diff --git a/db/commands.h b/db/commands.h index 927ed1adc51..be0ceecba6c 100644 --- a/db/commands.h +++ b/db/commands.h @@ -73,6 +73,7 @@ namespace mongo { virtual bool requiresAuth() { return true; } Command(const char *_name); + virtual ~Command() {} }; bool runCommandAgainstRegistered(const char *ns, BSONObj& jsobj, BSONObjBuilder& anObjBuilder); diff --git a/db/cursor.h b/db/cursor.h index 0c918ef21a0..441f836975c 100644 --- a/db/cursor.h +++ b/db/cursor.h @@ -110,6 +110,7 @@ namespace mongo { class AdvanceStrategy { public: + virtual ~AdvanceStrategy() {} virtual DiskLoc next( const DiskLoc &prev ) const = 0; }; diff --git a/db/pdfile.h b/db/pdfile.h index c5a5f5ae947..504a353f83b 100644 --- a/db/pdfile.h +++ b/db/pdfile.h @@ -362,6 +362,7 @@ namespace mongo { class FileOp { public: + virtual ~FileOp() {} virtual bool apply( const boost::filesystem::path &p ) = 0; virtual const char * op() const = 0; }; diff --git a/db/replset.h b/db/replset.h index 322fe16402c..44fd44fdbe5 100644 --- a/db/replset.h +++ b/db/replset.h @@ -71,6 +71,7 @@ namespace mongo { } ReplPair(const char *remoteEnd, const char *arbiter); + virtual ~ReplPair() {} bool dominant(const string& myname) { if ( myname == remoteHost ) diff --git a/db/security.h b/db/security.h index 7bb116a459c..ec52c672f2d 100644 --- a/db/security.h +++ b/db/security.h @@ -40,7 +40,7 @@ namespace mongo { public: bool isLocalHost; AuthenticationInfo() { isLocalHost = false; } - ~AuthenticationInfo() { + virtual ~AuthenticationInfo() { } void logout(const char *dbname) { assert( dbMutexInfo.isLocked() ); diff --git a/dbtests/btreetests.cpp b/dbtests/btreetests.cpp index 5ad8d0ec9c2..077f9db065a 100644 --- a/dbtests/btreetests.cpp +++ b/dbtests/btreetests.cpp @@ -121,6 +121,7 @@ namespace BtreeTests { class SplitUnevenBucketBase : public Base { public: + virtual ~SplitUnevenBucketBase() {} void run() { for ( int i = 0; i < 10; ++i ) { BSONObj shortKey = simpleKey( shortToken( i ), 1 ); diff --git a/dbtests/jsobjtests.cpp b/dbtests/jsobjtests.cpp index e6f17de1c85..460065191c6 100644 --- a/dbtests/jsobjtests.cpp +++ b/dbtests/jsobjtests.cpp @@ -114,6 +114,7 @@ namespace JsobjTests { class Base { public: + virtual ~Base() {} void run() { ASSERT( valid().valid() ); ASSERT( !invalid().valid() ); @@ -445,6 +446,7 @@ namespace JsobjTests { class LabelBase { public: + virtual ~LabelBase() {} void run() { ASSERT( !expected().woCompare( actual() ) ); } diff --git a/dbtests/jsontests.cpp b/dbtests/jsontests.cpp index 5893d89f83b..f2b7c007471 100644 --- a/dbtests/jsontests.cpp +++ b/dbtests/jsontests.cpp @@ -326,6 +326,7 @@ namespace JsonTests { class Base { public: + virtual ~Base() {} void run() { ASSERT( fromjson( json() ).valid() ); assertEquals( bson(), fromjson( json() ) ); @@ -348,6 +349,7 @@ namespace JsonTests { class Bad { public: + virtual ~Bad() {} void run() { ASSERT_EXCEPTION( fromjson( json() ), MsgAssertionException ); } @@ -427,6 +429,7 @@ namespace JsonTests { class FancyNumber { public: + virtual ~FancyNumber() {} void run() { ASSERT_EQUALS( int( 1000000 * bson().firstElement().number() ), int( 1000000 * fromjson( json() ).firstElement().number() ) ); diff --git a/dbtests/mockdbclient.h b/dbtests/mockdbclient.h index af9149c51e6..23ae226b4d2 100644 --- a/dbtests/mockdbclient.h +++ b/dbtests/mockdbclient.h @@ -54,6 +54,7 @@ private: class DirectDBClientConnection : public DBClientConnection { public: struct ConnectionCallback { + virtual ~ConnectionCallback() {} virtual void beforeCommand() {} virtual void afterCommand() {} }; diff --git a/dbtests/namespacetests.cpp b/dbtests/namespacetests.cpp index b7365a27847..ba1f80e8364 100644 --- a/dbtests/namespacetests.cpp +++ b/dbtests/namespacetests.cpp @@ -32,7 +32,7 @@ namespace NamespaceTests { Base() { setClient( ns() ); } - ~Base() { + virtual ~Base() { if ( id_.info.isNull() ) return; theDataFileMgr.deleteRecord( ns(), id_.info.rec(), id_.info ); @@ -379,7 +379,7 @@ namespace NamespaceTests { class Base { public: Base( const char *ns = "foo" ) : ns_( ns ) {} - ~Base() { + virtual ~Base() { if ( !nsd() ) return; string s( ns() ); diff --git a/dbtests/pairingtests.cpp b/dbtests/pairingtests.cpp index b19ed8ec98e..91e598e55aa 100644 --- a/dbtests/pairingtests.cpp +++ b/dbtests/pairingtests.cpp @@ -232,6 +232,8 @@ namespace PairingTests { } // namespace ReplPairTests class DirectConnectBase : public Base { + public: + virtual ~DirectConnectBase() {} protected: void negotiate( ReplPair &a, ReplPair &b ) { auto_ptr< DBClientConnection > c( new DirectDBClientConnection( &b, cc() ) ); diff --git a/dbtests/pdfiletests.cpp b/dbtests/pdfiletests.cpp index dcc9787ab7f..e42cd152f18 100644 --- a/dbtests/pdfiletests.cpp +++ b/dbtests/pdfiletests.cpp @@ -33,7 +33,7 @@ namespace PdfileTests { Base() { setClient( ns() ); } - ~Base() { + virtual ~Base() { if ( !nsd() ) return; string n( ns() ); diff --git a/dbtests/queryoptimizertests.cpp b/dbtests/queryoptimizertests.cpp index 26314a13c19..fa8397c7d9b 100644 --- a/dbtests/queryoptimizertests.cpp +++ b/dbtests/queryoptimizertests.cpp @@ -26,6 +26,7 @@ namespace QueryOptimizerTests { namespace FieldBoundTests { class Base { public: + virtual ~Base() {} void run() { FieldBoundSet s( query() ); checkElt( lower(), s.bound( "a" ).lower() ); @@ -47,6 +48,7 @@ namespace QueryOptimizerTests { class Bad { public: + virtual ~Bad() {} void run() { ASSERT_EXCEPTION( FieldBoundSet f( query() ), AssertionException ); } diff --git a/dbtests/querytests.cpp b/dbtests/querytests.cpp index a8923e67670..56ef78138b7 100644 --- a/dbtests/querytests.cpp +++ b/dbtests/querytests.cpp @@ -198,6 +198,7 @@ namespace QueryTests { class Fail : public ClientBase { public: + virtual ~Fail() {} void run() { prep(); ASSERT( !error() ); diff --git a/dbtests/repltests.cpp b/dbtests/repltests.cpp index fd33ebd0da6..12481b9560c 100644 --- a/dbtests/repltests.cpp +++ b/dbtests/repltests.cpp @@ -175,6 +175,7 @@ namespace ReplTests { class Base : public ReplTests::Base { public: + virtual ~Base() {} void run() { reset(); doIt(); diff --git a/mongo.xcodeproj/project.pbxproj b/mongo.xcodeproj/project.pbxproj index df7b6630872..0f430329187 100644 --- a/mongo.xcodeproj/project.pbxproj +++ b/mongo.xcodeproj/project.pbxproj @@ -111,6 +111,14 @@ 936AB4BB0F3A5B0300D5015F /* update3.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = update3.js; sourceTree = ""; }; 936AB9350F3C8AB800D5015F /* _lodeRunner.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = _lodeRunner.js; sourceTree = ""; }; 936ABBAB0F3CBE5400D5015F /* dbNoCreate.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = dbNoCreate.js; sourceTree = ""; }; + 936B89590F4C899400934AF2 /* file.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = file.h; sourceTree = ""; }; + 936B895A0F4C899400934AF2 /* md5.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = md5.c; sourceTree = ""; }; + 936B895B0F4C899400934AF2 /* md5.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = md5.h; sourceTree = ""; }; + 936B895C0F4C899400934AF2 /* md5.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = md5.hpp; sourceTree = ""; }; + 936B895D0F4C899400934AF2 /* md5main.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = md5main.c; sourceTree = ""; }; + 936B895E0F4C899400934AF2 /* message.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = message.cpp; sourceTree = ""; }; + 936B895F0F4C899400934AF2 /* message.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = message.h; sourceTree = ""; }; + 936B89600F4C899400934AF2 /* top.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = top.h; sourceTree = ""; }; 937CACE90F27BF4900C57AA6 /* socktests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = socktests.cpp; sourceTree = ""; }; 937D0E340F28CB070071FFA9 /* repltests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = repltests.cpp; sourceTree = ""; }; 937D14AB0F2A225F0071FFA9 /* nonce.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = nonce.h; sourceTree = ""; }; @@ -400,6 +408,14 @@ 934DD87B0EFAD23B00459CC1 /* util */ = { isa = PBXGroup; children = ( + 936B89590F4C899400934AF2 /* file.h */, + 936B895A0F4C899400934AF2 /* md5.c */, + 936B895B0F4C899400934AF2 /* md5.h */, + 936B895C0F4C899400934AF2 /* md5.hpp */, + 936B895D0F4C899400934AF2 /* md5main.c */, + 936B895E0F4C899400934AF2 /* message.cpp */, + 936B895F0F4C899400934AF2 /* message.h */, + 936B89600F4C899400934AF2 /* top.h */, 934DD87C0EFAD23B00459CC1 /* background.cpp */, 934DD87D0EFAD23B00459CC1 /* background.h */, 934DD87F0EFAD23B00459CC1 /* builder.h */, diff --git a/s/request.h b/s/request.h index 3919211f516..ce79d5aa3a5 100644 --- a/s/request.h +++ b/s/request.h @@ -54,6 +54,7 @@ namespace mongo { class Strategy { public: + virtual ~Strategy() {} virtual void queryOp( Request& r ) = 0; virtual void getMore( Request& r ) = 0; virtual void writeOp( int op , Request& r ) = 0; diff --git a/s/shardkey.h b/s/shardkey.h index b73eb10e2ee..3cf2ab508d7 100644 --- a/s/shardkey.h +++ b/s/shardkey.h @@ -26,6 +26,7 @@ namespace mongo { public: ShardKey( BSONObj fieldsAndOrder = emptyObj ); void init( BSONObj fieldsAndOrder ); + virtual ~ShardKey() {} void globalMin( BSONObjBuilder & b ); BSONObj globalMin(){ BSONObjBuilder b; globalMin( b ); return b.obj(); } diff --git a/util/log.h b/util/log.h index 692eab2cf7e..5c8a5de626f 100644 --- a/util/log.h +++ b/util/log.h @@ -22,11 +22,13 @@ namespace mongo { class Stringable { public: + virtual ~Stringable() {} virtual string toString() const = 0; }; class Nullstream { public: + virtual ~Nullstream() {} // todo: just use a template for all these virtual Nullstream& operator<<(const char *) { return *this; diff --git a/util/message.h b/util/message.h index 63ac392df16..6088e857bc8 100644 --- a/util/message.h +++ b/util/message.h @@ -31,6 +31,7 @@ namespace mongo { class Listener { public: Listener(int p) : port(p) { } + virtual ~Listener() {} void listen(); // never returns (start a thread) /* spawn a thread, etc., then return */ diff --git a/util/miniwebserver.h b/util/miniwebserver.h index 408b29e50a2..579e6f59b37 100644 --- a/util/miniwebserver.h +++ b/util/miniwebserver.h @@ -25,6 +25,7 @@ namespace mongo { class MiniWebServer { public: MiniWebServer(); + virtual ~MiniWebServer() {} bool init(int port); void run(); diff --git a/util/unittest.h b/util/unittest.h index 2e24baab1eb..1d34cd363a4 100644 --- a/util/unittest.h +++ b/util/unittest.h @@ -31,6 +31,7 @@ namespace mongo { UnitTest() { registerTest(this); } + virtual ~UnitTest() {} // assert if fails virtual void run() = 0;