THRIFT-2071 clang 3.2 reports warning when comparing shared_ptr<X> == NULL
Patch: Konrad Grochowski
diff --git a/lib/cpp/src/thrift/concurrency/BoostThreadFactory.cpp b/lib/cpp/src/thrift/concurrency/BoostThreadFactory.cpp
index 577329b..decacce 100644
--- a/lib/cpp/src/thrift/concurrency/BoostThreadFactory.cpp
+++ b/lib/cpp/src/thrift/concurrency/BoostThreadFactory.cpp
@@ -115,7 +115,7 @@
shared_ptr<BoostThread> thread = *(shared_ptr<BoostThread>*)arg;
delete reinterpret_cast<shared_ptr<BoostThread>*>(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 d5373de..298dbac 100644
--- a/lib/cpp/src/thrift/concurrency/ThreadManager.cpp
+++ b/lib/cpp/src/thrift/concurrency/ThreadManager.cpp
@@ -308,7 +308,7 @@
}
}
- if (task != NULL) {
+ if (task) {
if (task->state_ == ThreadManager::Task::EXECUTING) {
try {
task->run();
@@ -375,7 +375,7 @@
{
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 b47c697..6821b2e 100644
--- a/lib/cpp/src/thrift/concurrency/TimerManager.cpp
+++ b/lib/cpp/src/thrift/concurrency/TimerManager.cpp
@@ -174,7 +174,7 @@
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 7902776..398eade 100644
--- a/lib/cpp/src/thrift/server/TNonblockingServer.cpp
+++ b/lib/cpp/src/thrift/server/TNonblockingServer.cpp
@@ -347,7 +347,7 @@
void run() {
try {
for (;;) {
- if (serverEventHandler_ != NULL) {
+ if (serverEventHandler_) {
serverEventHandler_->processContext(connectionContext_, connection_->getTSocket());
}
if (!processor_->process(input_, output_, connectionContext_) ||
@@ -424,7 +424,7 @@
// 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 @@
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 @@
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::setThreadManager(boost::shared_ptr<ThreadManager> 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 @@
}
// 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 b132a66..5fc4c97 100644
--- a/lib/cpp/src/thrift/server/TSimpleServer.cpp
+++ b/lib/cpp/src/thrift/server/TSimpleServer.cpp
@@ -46,7 +46,7 @@
serverTransport_->listen();
// Run the preServe event
- if (eventHandler_ != NULL) {
+ if (eventHandler_) {
eventHandler_->preServe();
}
@@ -59,25 +59,25 @@
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 @@
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 @@
} 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 6ff946b..da33ec2 100644
--- a/lib/cpp/src/thrift/server/TThreadPoolServer.cpp
+++ b/lib/cpp/src/thrift/server/TThreadPoolServer.cpp
@@ -57,12 +57,12 @@
boost::shared_ptr<TServerEventHandler> 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 @@
"TThreadPoolServer::Task::run()");
}
- if (eventHandler != NULL) {
+ if (eventHandler) {
eventHandler->deleteContext(connectionContext, input_, output_);
}
@@ -123,7 +123,7 @@
serverTransport_->listen();
// Run the preServe event
- if (eventHandler_ != NULL) {
+ if (eventHandler_) {
eventHandler_->preServe();
}
@@ -153,25 +153,25 @@
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 6ed8fd8..909c3ce 100644
--- a/lib/cpp/src/thrift/server/TThreadedServer.cpp
+++ b/lib/cpp/src/thrift/server/TThreadedServer.cpp
@@ -59,12 +59,12 @@
boost::shared_ptr<TServerEventHandler> 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 @@
} catch (...) {
GlobalOutput("TThreadedServer uncaught exception.");
}
- if (eventHandler != NULL) {
+ if (eventHandler) {
eventHandler->deleteContext(connectionContext, input_, output_);
}
@@ -143,7 +143,7 @@
serverTransport_->listen();
// Run the preServe event
- if (eventHandler_ != NULL) {
+ if (eventHandler_) {
eventHandler_->preServe();
}
@@ -191,25 +191,25 @@
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 d54aa62..2ddee0d 100644
--- a/lib/cpp/src/thrift/transport/TServerTransport.h
+++ b/lib/cpp/src/thrift/transport/TServerTransport.h
@@ -55,7 +55,7 @@
*/
boost::shared_ptr<TTransport> accept() {
boost::shared_ptr<TTransport> result = acceptImpl();
- if (result == NULL) {
+ if (!result) {
throw TTransportException("accept() may not return NULL");
}
return result;