From 7295745b1762255af50dadd0e480e8393a25f9ff Mon Sep 17 00:00:00 2001 From: Roger Meier Date: Sat, 29 Jun 2013 00:28:50 +0200 Subject: [PATCH] THRIFT-2071 clang 3.2 reports warning when comparing shared_ptr == NULL Patch: Konrad Grochowski --- .../thrift/concurrency/BoostThreadFactory.cpp | 2 +- .../src/thrift/concurrency/ThreadManager.cpp | 4 +-- .../src/thrift/concurrency/TimerManager.cpp | 2 +- .../src/thrift/server/TNonblockingServer.cpp | 18 ++++++------- lib/cpp/src/thrift/server/TSimpleServer.cpp | 26 +++++++++---------- .../src/thrift/server/TThreadPoolServer.cpp | 26 +++++++++---------- lib/cpp/src/thrift/server/TThreadedServer.cpp | 26 +++++++++---------- .../src/thrift/transport/TServerTransport.h | 2 +- 8 files changed, 53 insertions(+), 53 deletions(-) diff --git a/lib/cpp/src/thrift/concurrency/BoostThreadFactory.cpp b/lib/cpp/src/thrift/concurrency/BoostThreadFactory.cpp index 577329b5..decacced 100644 --- a/lib/cpp/src/thrift/concurrency/BoostThreadFactory.cpp +++ b/lib/cpp/src/thrift/concurrency/BoostThreadFactory.cpp @@ -115,7 +115,7 @@ void* BoostThread::threadMain(void* arg) { shared_ptr thread = *(shared_ptr*)arg; delete reinterpret_cast*>(arg); - if (thread == NULL) { + if (!thread) { return (void*)0; } diff --git a/lib/cpp/src/thrift/concurrency/ThreadManager.cpp b/lib/cpp/src/thrift/concurrency/ThreadManager.cpp index d5373dee..298dbac7 100644 --- a/lib/cpp/src/thrift/concurrency/ThreadManager.cpp +++ b/lib/cpp/src/thrift/concurrency/ThreadManager.cpp @@ -308,7 +308,7 @@ class ThreadManager::Worker: public Runnable { } } - if (task != NULL) { + if (task) { if (task->state_ == ThreadManager::Task::EXECUTING) { try { task->run(); @@ -375,7 +375,7 @@ void ThreadManager::Impl::start() { { Synchronized s(monitor_); if (state_ == ThreadManager::UNINITIALIZED) { - if (threadFactory_ == NULL) { + if (!threadFactory_) { throw InvalidArgumentException(); } state_ = ThreadManager::STARTED; diff --git a/lib/cpp/src/thrift/concurrency/TimerManager.cpp b/lib/cpp/src/thrift/concurrency/TimerManager.cpp index b47c6973..6821b2e4 100644 --- a/lib/cpp/src/thrift/concurrency/TimerManager.cpp +++ b/lib/cpp/src/thrift/concurrency/TimerManager.cpp @@ -174,7 +174,7 @@ void TimerManager::start() { bool doStart = false; { Synchronized s(monitor_); - if (threadFactory_ == NULL) { + if (!threadFactory_) { throw InvalidArgumentException(); } if (state_ == TimerManager::UNINITIALIZED) { diff --git a/lib/cpp/src/thrift/server/TNonblockingServer.cpp b/lib/cpp/src/thrift/server/TNonblockingServer.cpp index 79027769..398eadec 100644 --- a/lib/cpp/src/thrift/server/TNonblockingServer.cpp +++ b/lib/cpp/src/thrift/server/TNonblockingServer.cpp @@ -347,7 +347,7 @@ class TNonblockingServer::TConnection::Task: public Runnable { void run() { try { for (;;) { - if (serverEventHandler_ != NULL) { + if (serverEventHandler_) { serverEventHandler_->processContext(connectionContext_, connection_->getTSocket()); } if (!processor_->process(input_, output_, connectionContext_) || @@ -424,7 +424,7 @@ void TNonblockingServer::TConnection::init(THRIFT_SOCKET socket, // Set up for any server event handler serverEventHandler_ = server_->getEventHandler(); - if (serverEventHandler_ != NULL) { + if (serverEventHandler_) { connectionContext_ = serverEventHandler_->createContext(inputProtocol_, outputProtocol_); } else { @@ -615,10 +615,10 @@ void TNonblockingServer::TConnection::transition() { return; } else { try { - if (serverEventHandler_ != NULL) { - serverEventHandler_->processContext(connectionContext_, - getTSocket()); - } + if (serverEventHandler_) { + serverEventHandler_->processContext(connectionContext_, + getTSocket()); + } // Invoke the processor processor_->process(inputProtocol_, outputProtocol_, connectionContext_); @@ -828,7 +828,7 @@ void TNonblockingServer::TConnection::close() { GlobalOutput.perror("TConnection::close() event_del", THRIFT_GET_SOCKET_ERROR); } - if (serverEventHandler_ != NULL) { + if (serverEventHandler_) { serverEventHandler_->deleteContext(connectionContext_, inputProtocol_, outputProtocol_); } ioThread_ = NULL; @@ -1130,7 +1130,7 @@ void TNonblockingServer::listenSocket(THRIFT_SOCKET s) { void TNonblockingServer::setThreadManager(boost::shared_ptr threadManager) { threadManager_ = threadManager; - if (threadManager != NULL) { + if (threadManager) { threadManager->setExpireCallback(apache::thrift::stdcxx::bind(&TNonblockingServer::expireClose, this, apache::thrift::stdcxx::placeholders::_1)); threadPoolProcessing_ = true; } else { @@ -1215,7 +1215,7 @@ void TNonblockingServer::serve() { } // Notify handler of the preServe event - if (eventHandler_ != NULL) { + if (eventHandler_) { eventHandler_->preServe(); } diff --git a/lib/cpp/src/thrift/server/TSimpleServer.cpp b/lib/cpp/src/thrift/server/TSimpleServer.cpp index b132a66a..5fc4c973 100644 --- a/lib/cpp/src/thrift/server/TSimpleServer.cpp +++ b/lib/cpp/src/thrift/server/TSimpleServer.cpp @@ -46,7 +46,7 @@ void TSimpleServer::serve() { serverTransport_->listen(); // Run the preServe event - if (eventHandler_ != NULL) { + if (eventHandler_) { eventHandler_->preServe(); } @@ -59,25 +59,25 @@ void TSimpleServer::serve() { inputProtocol = inputProtocolFactory_->getProtocol(inputTransport); outputProtocol = outputProtocolFactory_->getProtocol(outputTransport); } catch (TTransportException& ttx) { - if (inputTransport != NULL) { inputTransport->close(); } - if (outputTransport != NULL) { outputTransport->close(); } - if (client != NULL) { client->close(); } + if (inputTransport) { inputTransport->close(); } + if (outputTransport) { outputTransport->close(); } + if (client) { client->close(); } if (!stop_ || ttx.getType() != TTransportException::INTERRUPTED) { string errStr = string("TServerTransport died on accept: ") + ttx.what(); GlobalOutput(errStr.c_str()); } continue; } catch (TException& tx) { - if (inputTransport != NULL) { inputTransport->close(); } - if (outputTransport != NULL) { outputTransport->close(); } - if (client != NULL) { client->close(); } + if (inputTransport) { inputTransport->close(); } + if (outputTransport) { outputTransport->close(); } + if (client) { client->close(); } string errStr = string("Some kind of accept exception: ") + tx.what(); GlobalOutput(errStr.c_str()); continue; } catch (string s) { - if (inputTransport != NULL) { inputTransport->close(); } - if (outputTransport != NULL) { outputTransport->close(); } - if (client != NULL) { client->close(); } + if (inputTransport) { inputTransport->close(); } + if (outputTransport) { outputTransport->close(); } + if (client) { client->close(); } string errStr = string("Some kind of accept exception: ") + s; GlobalOutput(errStr.c_str()); break; @@ -88,12 +88,12 @@ void TSimpleServer::serve() { outputProtocol, client); void* connectionContext = NULL; - if (eventHandler_ != NULL) { + if (eventHandler_) { connectionContext = eventHandler_->createContext(inputProtocol, outputProtocol); } try { for (;;) { - if (eventHandler_ != NULL) { + if (eventHandler_) { eventHandler_->processContext(connectionContext, client); } if (!processor->process(inputProtocol, outputProtocol, @@ -112,7 +112,7 @@ void TSimpleServer::serve() { } catch (...) { GlobalOutput("TSimpleServer uncaught exception."); } - if (eventHandler_ != NULL) { + if (eventHandler_) { eventHandler_->deleteContext(connectionContext, inputProtocol, outputProtocol); } diff --git a/lib/cpp/src/thrift/server/TThreadPoolServer.cpp b/lib/cpp/src/thrift/server/TThreadPoolServer.cpp index 6ff946b3..da33ec24 100644 --- a/lib/cpp/src/thrift/server/TThreadPoolServer.cpp +++ b/lib/cpp/src/thrift/server/TThreadPoolServer.cpp @@ -57,12 +57,12 @@ public: boost::shared_ptr eventHandler = server_.getEventHandler(); void* connectionContext = NULL; - if (eventHandler != NULL) { + if (eventHandler) { connectionContext = eventHandler->createContext(input_, output_); } try { for (;;) { - if (eventHandler != NULL) { + if (eventHandler) { eventHandler->processContext(connectionContext, transport_); } if (!processor_->process(input_, output_, connectionContext) || @@ -83,7 +83,7 @@ public: "TThreadPoolServer::Task::run()"); } - if (eventHandler != NULL) { + if (eventHandler) { eventHandler->deleteContext(connectionContext, input_, output_); } @@ -123,7 +123,7 @@ void TThreadPoolServer::serve() { serverTransport_->listen(); // Run the preServe event - if (eventHandler_ != NULL) { + if (eventHandler_) { eventHandler_->preServe(); } @@ -153,25 +153,25 @@ void TThreadPoolServer::serve() { threadManager_->add(task, timeout_, taskExpiration_); } catch (TTransportException& ttx) { - if (inputTransport != NULL) { inputTransport->close(); } - if (outputTransport != NULL) { outputTransport->close(); } - if (client != NULL) { client->close(); } + if (inputTransport) { inputTransport->close(); } + if (outputTransport) { outputTransport->close(); } + if (client) { client->close(); } if (!stop_ || ttx.getType() != TTransportException::INTERRUPTED) { string errStr = string("TThreadPoolServer: TServerTransport died on accept: ") + ttx.what(); GlobalOutput(errStr.c_str()); } continue; } catch (TException& tx) { - if (inputTransport != NULL) { inputTransport->close(); } - if (outputTransport != NULL) { outputTransport->close(); } - if (client != NULL) { client->close(); } + if (inputTransport) { inputTransport->close(); } + if (outputTransport) { outputTransport->close(); } + if (client) { client->close(); } string errStr = string("TThreadPoolServer: Caught TException: ") + tx.what(); GlobalOutput(errStr.c_str()); continue; } catch (string s) { - if (inputTransport != NULL) { inputTransport->close(); } - if (outputTransport != NULL) { outputTransport->close(); } - if (client != NULL) { client->close(); } + if (inputTransport) { inputTransport->close(); } + if (outputTransport) { outputTransport->close(); } + if (client) { client->close(); } string errStr = "TThreadPoolServer: Unknown exception: " + s; GlobalOutput(errStr.c_str()); break; diff --git a/lib/cpp/src/thrift/server/TThreadedServer.cpp b/lib/cpp/src/thrift/server/TThreadedServer.cpp index 6ed8fd88..909c3cee 100644 --- a/lib/cpp/src/thrift/server/TThreadedServer.cpp +++ b/lib/cpp/src/thrift/server/TThreadedServer.cpp @@ -59,12 +59,12 @@ public: boost::shared_ptr eventHandler = server_.getEventHandler(); void* connectionContext = NULL; - if (eventHandler != NULL) { + if (eventHandler) { connectionContext = eventHandler->createContext(input_, output_); } try { for (;;) { - if (eventHandler != NULL) { + if (eventHandler) { eventHandler->processContext(connectionContext, transport_); } if (!processor_->process(input_, output_, connectionContext) || @@ -83,7 +83,7 @@ public: } catch (...) { GlobalOutput("TThreadedServer uncaught exception."); } - if (eventHandler != NULL) { + if (eventHandler) { eventHandler->deleteContext(connectionContext, input_, output_); } @@ -143,7 +143,7 @@ void TThreadedServer::serve() { serverTransport_->listen(); // Run the preServe event - if (eventHandler_ != NULL) { + if (eventHandler_) { eventHandler_->preServe(); } @@ -191,25 +191,25 @@ void TThreadedServer::serve() { thread->start(); } catch (TTransportException& ttx) { - if (inputTransport != NULL) { inputTransport->close(); } - if (outputTransport != NULL) { outputTransport->close(); } - if (client != NULL) { client->close(); } + if (inputTransport) { inputTransport->close(); } + if (outputTransport) { outputTransport->close(); } + if (client) { client->close(); } if (!stop_ || ttx.getType() != TTransportException::INTERRUPTED) { string errStr = string("TThreadedServer: TServerTransport died on accept: ") + ttx.what(); GlobalOutput(errStr.c_str()); } continue; } catch (TException& tx) { - if (inputTransport != NULL) { inputTransport->close(); } - if (outputTransport != NULL) { outputTransport->close(); } - if (client != NULL) { client->close(); } + if (inputTransport) { inputTransport->close(); } + if (outputTransport) { outputTransport->close(); } + if (client) { client->close(); } string errStr = string("TThreadedServer: Caught TException: ") + tx.what(); GlobalOutput(errStr.c_str()); continue; } catch (string s) { - if (inputTransport != NULL) { inputTransport->close(); } - if (outputTransport != NULL) { outputTransport->close(); } - if (client != NULL) { client->close(); } + if (inputTransport) { inputTransport->close(); } + if (outputTransport) { outputTransport->close(); } + if (client) { client->close(); } string errStr = "TThreadedServer: Unknown exception: " + s; GlobalOutput(errStr.c_str()); break; diff --git a/lib/cpp/src/thrift/transport/TServerTransport.h b/lib/cpp/src/thrift/transport/TServerTransport.h index d54aa625..2ddee0d1 100644 --- a/lib/cpp/src/thrift/transport/TServerTransport.h +++ b/lib/cpp/src/thrift/transport/TServerTransport.h @@ -55,7 +55,7 @@ class TServerTransport { */ boost::shared_ptr accept() { boost::shared_ptr result = acceptImpl(); - if (result == NULL) { + if (!result) { throw TTransportException("accept() may not return NULL"); } return result; -- 2.17.1