From 5c1cfe47028cf63a3434028c4f83c7b945f9ee84 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Wed, 22 Mar 2017 20:00:08 -0700 Subject: [PATCH] Use unique_ptr instead of auto_ptr where available (and define a macro to pick which one to use); fix a few other remaining warnings. --- src/core/codeconvert.cpp | 4 ++-- src/core/msystem.cpp | 3 ++- src/core/refcountobj.cpp | 3 --- src/core/types.h | 11 +++++++++++ src/cryptlib/filters.cpp | 8 +++++++- src/cryptlib/forkjoin.cpp | 8 +++++++- src/tripwire/generatedb.cpp | 8 ++++---- src/tripwire/integritycheck.cpp | 8 ++++---- src/tripwire/tripwiremain.cpp | 4 ++-- src/tripwire/twcmdline.cpp | 2 +- src/tripwire/twcmdlineutil.cpp | 12 ++++++------ src/tw/twutil.cpp | 4 ++-- src/twadmin/twadminmain.cpp | 2 +- src/twprint/twprintmain.cpp | 2 +- src/twtest/codeconvert_t.cpp | 3 ++- src/twtest/refcountobj_t.cpp | 4 ++-- src/twtest/unixfsservices_t.cpp | 2 +- 17 files changed, 55 insertions(+), 33 deletions(-) diff --git a/src/core/codeconvert.cpp b/src/core/codeconvert.cpp index 3d926d5..9142da1 100644 --- a/src/core/codeconvert.cpp +++ b/src/core/codeconvert.cpp @@ -1016,7 +1016,7 @@ cDoubleIconvConverter::Convert( // size_t nBufBytes = nChars * MB_LEN_MAX; ntmbs_t pszBuffer = (ntmbs_t)::operator new( nBufBytes + 1 ); - std::auto_ptr pBuf( pszBuffer ); + TW_UNIQUE_PTR pBuf( pszBuffer ); // // do first conversion @@ -1074,7 +1074,7 @@ cDoubleIconvConverter::Convert( // size_t nBufBytes = nBytes * MB_LEN_MAX; ntmbs_t pszBuffer = (ntmbs_t)::operator new( nBufBytes + 1 ); - std::auto_ptr pBuf( pszBuffer ); + TW_UNIQUE_PTR pBuf( pszBuffer ); // // do first conversion diff --git a/src/core/msystem.cpp b/src/core/msystem.cpp index 5c3a4d4..c551aee 100644 --- a/src/core/msystem.cpp +++ b/src/core/msystem.cpp @@ -207,6 +207,7 @@ char *getenv(); /* get variable from environment */ * on some systems, this is a library function, so define STRDUP * if it is on yours */ +#if 0 #ifdef STRDUP # ifndef __STDC__ char *strdup(); @@ -230,7 +231,7 @@ char *getenv(); /* get variable from environment */ return(p); } #endif - +#endif //0 /* * allocate space for an array of pointers, OR diff --git a/src/core/refcountobj.cpp b/src/core/refcountobj.cpp index 209f03d..f8df324 100644 --- a/src/core/refcountobj.cpp +++ b/src/core/refcountobj.cpp @@ -135,9 +135,6 @@ void cRefCountObj::AddRef() const void cRefCountObj::Release() const { - if (this == 0) - return; - if (--mRefCount == 0) { Delete(); diff --git a/src/core/types.h b/src/core/types.h index 5744e02..170681a 100644 --- a/src/core/types.h +++ b/src/core/types.h @@ -187,5 +187,16 @@ inline int64 SWAPBYTES64(int64 i) #endif //WORDS_BIGENDIAN +//////////////////////////////////////////// + +#if __cplusplus >= 201103L +# define TW_UNIQUE_PTR std::unique_ptr +#else +# define TW_UNIQUE_PTR std::auto_ptr +#endif + + + + #endif // __TYPES_H diff --git a/src/cryptlib/filters.cpp b/src/cryptlib/filters.cpp index b3dbfee..ef47f2a 100644 --- a/src/cryptlib/filters.cpp +++ b/src/cryptlib/filters.cpp @@ -5,6 +5,12 @@ #include "queue.h" #include +#if __cplusplus >= 201103L +# define TW_UNIQUE_PTR std::unique_ptr +#else +# define TW_UNIQUE_PTR std::auto_ptr +#endif + Filter::Filter(BufferedTransformation *outQ) : outQueue(outQ ? outQ : new ByteQueue) { @@ -17,7 +23,7 @@ Filter::Filter(const Filter &source) void Filter::Detach(BufferedTransformation *newOut) { - std::auto_ptr out(newOut ? newOut : new ByteQueue); + TW_UNIQUE_PTR out(newOut ? newOut : new ByteQueue); outQueue->Close(); outQueue->TransferTo(*out); outQueue.reset(out.release()); diff --git a/src/cryptlib/forkjoin.cpp b/src/cryptlib/forkjoin.cpp index 054cc47..899ec85 100644 --- a/src/cryptlib/forkjoin.cpp +++ b/src/cryptlib/forkjoin.cpp @@ -5,6 +5,12 @@ #include "queue.h" #include +#if __cplusplus >= 201103L +# define TW_UNIQUE_PTR std::unique_ptr +#else +# define TW_UNIQUE_PTR std::auto_ptr +#endif + Fork::Fork(int n, BufferedTransformation *const *givenOutPorts) : numberOfPorts(n), outPorts(n) { @@ -21,7 +27,7 @@ void Fork::SelectOutPort(int portNumber) void Fork::Detach(BufferedTransformation *newOut) { - std::auto_ptr out(newOut ? newOut : new ByteQueue); + TW_UNIQUE_PTR out(newOut ? newOut : new ByteQueue); outPorts[currentPort]->Close(); outPorts[currentPort]->TransferTo(*out); outPorts[currentPort].reset(out.release()); diff --git a/src/tripwire/generatedb.cpp b/src/tripwire/generatedb.cpp index 244a051..7bf59b2 100644 --- a/src/tripwire/generatedb.cpp +++ b/src/tripwire/generatedb.cpp @@ -100,7 +100,7 @@ static void util_ProcessDir( cDbDataSourceIter dbIter, iFCODataSourceIter* pIter { dbIter.AddChildArray(); } - std::auto_ptr pCopy( pIter->CreateCopy() ); + TW_UNIQUE_PTR pCopy( pIter->CreateCopy() ); util_ProcessDir( dbIter, pCopy.get(), pSpec, pPC, pPD ); // // if no files were added, remove the child array... @@ -122,7 +122,7 @@ void cGenerateDb::Execute( const cFCOSpecList& specList, cHierDatabase& db, iFCO { // TODO -- assert the db is empty or clear it out myself! - std::auto_ptr pDSIter(iTWFactory::GetInstance()->CreateDataSourceIter()); + TW_UNIQUE_PTR pDSIter(iTWFactory::GetInstance()->CreateDataSourceIter()); // // set up the database's iterator... @@ -139,7 +139,7 @@ void cGenerateDb::Execute( const cFCOSpecList& specList, cHierDatabase& db, iFCO // // this is the object that will calculate all of the properties of the fcos. // - std::auto_ptr pPC(iTWFactory::GetInstance()->CreatePropCalc()); + TW_UNIQUE_PTR pPC(iTWFactory::GetInstance()->CreatePropCalc()); pPC->SetErrorBucket( pBucket ); if( flags & FLAG_ERASE_FOOTPRINTS_GD ) { @@ -193,7 +193,7 @@ void cGenerateDb::Execute( const cFCOSpecList& specList, cHierDatabase& db, iFCO { dbIter.AddChildArray(); } - std::auto_ptr pCopy( pDSIter->CreateCopy() ); + TW_UNIQUE_PTR pCopy( pDSIter->CreateCopy() ); util_ProcessDir( dbIter, pCopy.get(), specIter.Spec(), pPC.get(), pPD ); // // if no files were added, remove the child array... diff --git a/src/tripwire/integritycheck.cpp b/src/tripwire/integritycheck.cpp index 8dc7147..ef599d6 100644 --- a/src/tripwire/integritycheck.cpp +++ b/src/tripwire/integritycheck.cpp @@ -90,7 +90,7 @@ void cIntegrityCheck::ProcessAddedFCO( cDbDataSourceIter dbIter, iFCODataSourceI // to done... // while( ! dbIter.Done() ) dbIter.Next(); - std::auto_ptr pCopy( pIter->CreateCopy() ); + TW_UNIQUE_PTR pCopy( pIter->CreateCopy() ); ProcessDir( dbIter, pCopy.get() ); } } @@ -231,7 +231,7 @@ void cIntegrityCheck::ProcessChangedFCO( cDbDataSourceIter dbIter, iFCODataSourc { if( pIter->CanDescend() || dbIter.CanDescend() ) { - std::auto_ptr pCopy( pIter->CreateCopy() ); + TW_UNIQUE_PTR pCopy( pIter->CreateCopy() ); ProcessDir( dbIter, pCopy.get() ); } } @@ -453,7 +453,7 @@ void cIntegrityCheck::Execute( uint32 flags ) mFlags = flags; // create the data source iterator // - std::auto_ptr pDSIter(iTWFactory::GetInstance()->CreateDataSourceIter()); + TW_UNIQUE_PTR pDSIter(iTWFactory::GetInstance()->CreateDataSourceIter()); // // set up the database's iterator... // I assume the current genre is correct... @@ -560,7 +560,7 @@ void cIntegrityCheck::ExecuteOnObjectList( const std::list& fcoNames, // // create the data source iterator // - std::auto_ptr pDSIter(iTWFactory::GetInstance()->CreateDataSourceIter()); + TW_UNIQUE_PTR pDSIter(iTWFactory::GetInstance()->CreateDataSourceIter()); // // set up the database's iterator... // I assume the current genre is correct... diff --git a/src/tripwire/tripwiremain.cpp b/src/tripwire/tripwiremain.cpp index 67a81f2..266199d 100644 --- a/src/tripwire/tripwiremain.cpp +++ b/src/tripwire/tripwiremain.cpp @@ -44,7 +44,7 @@ #include "core/errorbucketimpl.h" #include "core/usernotifystdout.h" #include "core/timebomb.h" -#include // for auto_ptr +#include // for auto_ptr / unique_ptr #include #include @@ -133,7 +133,7 @@ int __cdecl _tmain( int argc, const TCHAR* argv[ ], const TCHAR* envp[ ] ) // first, get the right mode... - std::auto_ptr pMode(cTWCmdLine::GetMode(argc, argv)); + TW_UNIQUE_PTR pMode(cTWCmdLine::GetMode(argc, argv)); if(! pMode.get()) { // no valid mode passed; GetMode will display an appropriate string (include usage statement) diff --git a/src/tripwire/twcmdline.cpp b/src/tripwire/twcmdline.cpp index e6de6a4..6c51144 100644 --- a/src/tripwire/twcmdline.cpp +++ b/src/tripwire/twcmdline.cpp @@ -1129,7 +1129,7 @@ int cTWModeIC::Execute(cErrorQueue* pQueue) if( ! dbIter.Done() ) { cGenreSwitcher::GetInstance()->SelectGenre( (cGenre::Genre)dbIter.GetGenre() ); - std::auto_ptr pParseUtil (iTWFactory::GetInstance()->CreateParserGenreUtil()); + TW_UNIQUE_PTR pParseUtil (iTWFactory::GetInstance()->CreateParserGenreUtil()); // // I have to turn this into a list of cFCONames // diff --git a/src/tripwire/twcmdlineutil.cpp b/src/tripwire/twcmdlineutil.cpp index 244a75d..67e5893 100644 --- a/src/tripwire/twcmdlineutil.cpp +++ b/src/tripwire/twcmdlineutil.cpp @@ -531,7 +531,7 @@ static bool EmailReportTo(const TSTRING &toAddress, const cFCOReportHeader& head const cTWModeCommon *modeCommon, const bool bForceFullReport) { - std::auto_ptr reportMail; + TW_UNIQUE_PTR reportMail; // allocate the right kind of emailer object based on what came out of the config file. switch (modeCommon->mMailMethod) @@ -540,10 +540,10 @@ static bool EmailReportTo(const TSTRING &toAddress, const cFCOReportHeader& head ASSERT(false); return false; case cMailMessage::MAIL_BY_SMTP: - reportMail = std::auto_ptr(new cSMTPMailMessage(modeCommon->mSmtpHost, modeCommon->mSmtpPort)); + reportMail = TW_UNIQUE_PTR(new cSMTPMailMessage(modeCommon->mSmtpHost, modeCommon->mSmtpPort)); break; case cMailMessage::MAIL_BY_PIPE: - reportMail = std::auto_ptr(new cPipedMailMessage(modeCommon->mMailProgram)); + reportMail = TW_UNIQUE_PTR(new cPipedMailMessage(modeCommon->mMailProgram)); break; } @@ -685,7 +685,7 @@ bool cTWCmdLineUtil::EmailReport(const cFCOReportHeader& header, const cFCORepor bool cTWCmdLineUtil::SendEmailTestMessage(const TSTRING &mAddress, const cTWModeCommon *modeCommon) { - std::auto_ptr reportMail; + TW_UNIQUE_PTR reportMail; // allocate the right kind of emailer object based on what came out of the config file. switch (modeCommon->mMailMethod) @@ -694,10 +694,10 @@ bool cTWCmdLineUtil::SendEmailTestMessage(const TSTRING &mAddress, const cTWMode ASSERT(false); return false; case cMailMessage::MAIL_BY_SMTP: - reportMail = std::auto_ptr(new cSMTPMailMessage(modeCommon->mSmtpHost, modeCommon->mSmtpPort)); + reportMail = TW_UNIQUE_PTR(new cSMTPMailMessage(modeCommon->mSmtpHost, modeCommon->mSmtpPort)); break; case cMailMessage::MAIL_BY_PIPE: - reportMail = std::auto_ptr(new cPipedMailMessage(modeCommon->mMailProgram)); + reportMail = TW_UNIQUE_PTR(new cPipedMailMessage(modeCommon->mMailProgram)); break; } diff --git a/src/tw/twutil.cpp b/src/tw/twutil.cpp index 956d4d5..38656e8 100644 --- a/src/tw/twutil.cpp +++ b/src/tw/twutil.cpp @@ -1247,7 +1247,7 @@ void cTWUtil::ParseObjectList( cTWUtil::GenreObjList& listOut, const cTWUtil::Ob // if( g == cGenre::GENRE_INVALID ) { - std::auto_ptr pParseUtil (iTWFactory::GetInstance()->CreateParserGenreUtil()); + TW_UNIQUE_PTR pParseUtil (iTWFactory::GetInstance()->CreateParserGenreUtil()); if( ! pParseUtil->IsAbsolutePath( *i ) ) throw eTWUnknownSectionName( *i ); } @@ -1310,7 +1310,7 @@ void cTWUtil::ParseObjectList( cTWUtil::GenreObjList& listOut, const cTWUtil::Ob /////////////////////////////////////////////////////////////////////////////// cFCOName cTWUtil::ParseObjectName( const TSTRING& fcoName ) { - std::auto_ptr pParseUtil (iTWFactory::GetInstance()->CreateParserGenreUtil()); + TW_UNIQUE_PTR pParseUtil (iTWFactory::GetInstance()->CreateParserGenreUtil()); cFCOName name( iTWFactory::GetInstance()->GetNameInfo() ); // // make sure the fco name is a full path... diff --git a/src/twadmin/twadminmain.cpp b/src/twadmin/twadminmain.cpp index b24fe6d..696032c 100644 --- a/src/twadmin/twadminmain.cpp +++ b/src/twadmin/twadminmain.cpp @@ -94,7 +94,7 @@ int __cdecl _tmain( int argc, const TCHAR* argv[ ], const TCHAR* envp[ ] ) // first, get the right mode... - std::auto_ptr pMode(cTWAdminCmdLine::GetMode(argc, argv)); + TW_UNIQUE_PTR pMode(cTWAdminCmdLine::GetMode(argc, argv)); if(! pMode.get()) { // no valid mode passed; GetMode will display an appropriate string (include usage statement) diff --git a/src/twprint/twprintmain.cpp b/src/twprint/twprintmain.cpp index c55631e..dc04b56 100644 --- a/src/twprint/twprintmain.cpp +++ b/src/twprint/twprintmain.cpp @@ -128,7 +128,7 @@ int __cdecl _tmain( int argc, const TCHAR* argv[ ] ) } // Next, set the mode... exit with error if now valid mode specified. - std::auto_ptr pMode(cTWPrintCmdLine::GetMode(argc, argv)); + TW_UNIQUE_PTR pMode(cTWPrintCmdLine::GetMode(argc, argv)); if(! pMode.get()) { // no valid mode passed; GetMode will display an appropriate string (include usage statement) diff --git a/src/twtest/codeconvert_t.cpp b/src/twtest/codeconvert_t.cpp index d31a8ba..85eb874 100644 --- a/src/twtest/codeconvert_t.cpp +++ b/src/twtest/codeconvert_t.cpp @@ -182,9 +182,10 @@ char NonZeroChar( char ch ) } // mbchar_t to dbchar_t +//TestMbToDb in codeconvert_t.cpp seems to hit an infinite loop or runs verrrry long; ifdef'd" void TestMbToDb() { - TCERR << "TODO: TestMbToDb in codeconvert_t.cpp seems to hit an infinite loop or runs verrrry long; ifdef'd" << std::endl; + TCERR << "\nTODO: TestMbToDb in codeconvert_t.cpp is flaky & needs to be fixed/replaced; currently disabled." << std::endl; #if 0 std::string s; s.resize( 0x10000 * 2 ); // two bytes for each combination diff --git a/src/twtest/refcountobj_t.cpp b/src/twtest/refcountobj_t.cpp index ea9ec18..dc04d1d 100644 --- a/src/twtest/refcountobj_t.cpp +++ b/src/twtest/refcountobj_t.cpp @@ -39,7 +39,7 @@ class cRefCountTestObj : public cRefCountObj public: cRefCountTestObj(); - virtual void Release(); + virtual void Release() const; void AddChild(cRefCountTestObj* pChild); @@ -74,7 +74,7 @@ void cRefCountTestObj::AddChild(cRefCountTestObj* pChild) mChildren.push_back(pChild); } -void cRefCountTestObj::Release() +void cRefCountTestObj::Release() const { cRefCountObj::Release(); } diff --git a/src/twtest/unixfsservices_t.cpp b/src/twtest/unixfsservices_t.cpp index 5f46f32..c7e852c 100644 --- a/src/twtest/unixfsservices_t.cpp +++ b/src/twtest/unixfsservices_t.cpp @@ -68,7 +68,7 @@ void TestUnixFSServices() d.TraceDebug("name: %d entries\n", v.size()); std::vector ::iterator p; - int n = 0; + size_t n = 0; for (p = v.begin(); p != v.end(); p++) { d.TraceDetail(" %s\n", p->c_str()); n++;