Skip to content

Commit

Permalink
【Hackathon 6th Fundable Projects 2 No.37】Fix modernize-use-nullptr fi…
Browse files Browse the repository at this point in the history
  • Loading branch information
walkalone20 authored and co63oc committed May 23, 2024
1 parent c62183f commit 61da770
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 40 deletions.
4 changes: 2 additions & 2 deletions paddle/fluid/distributed/fleet_executor/message_bus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ bool MessageBus::SendInterRank(int64_t dst_rank,
brpc::Controller ctrl;
ctrl.set_log_id(0);
if (interceptor_message.ctrl_message()) {
stub.IncreaseBarrierCount(&ctrl, &interceptor_message, &response, NULL);
stub.IncreaseBarrierCount(&ctrl, &interceptor_message, &response, nullptr);
} else {
stub.ReceiveInterceptorMessage(
&ctrl, &interceptor_message, &response, NULL);
&ctrl, &interceptor_message, &response, nullptr);
}
if (!ctrl.Failed()) {
if (response.rst()) {
Expand Down
8 changes: 4 additions & 4 deletions paddle/fluid/distributed/ps/service/brpc_ps_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1797,24 +1797,24 @@ int BrpcPsClient::PushSparseAsyncShardMerge(
// 去重 本地merge
uint64_t last_key = sorted_kv_list[0].first;
const float *last_value_data = sorted_kv_list[0].second;
float *last_merge_data = NULL;
float *last_merge_data = nullptr;
std::shared_ptr<char> merger_buffer(new char[value_size],
array_deleter<char>());
for (size_t kv_idx = 1; kv_idx < sorted_kv_size; ++kv_idx) {
while (kv_idx < sorted_kv_size &&
last_key == sorted_kv_list[kv_idx].first) {
if (last_merge_data == NULL) {
if (last_merge_data == nullptr) {
last_merge_data = reinterpret_cast<float *>(merger_buffer.get());
memcpy(last_merge_data, last_value_data, value_size);
}
sparse_local_merge(
accessor, last_merge_data, sorted_kv_list[kv_idx].second);
++kv_idx;
}
if (last_merge_data != NULL) {
if (last_merge_data != nullptr) {
shard_kv_data.value_list[merged_kv_count].assign(
(const char *)last_merge_data, value_size);
last_merge_data = NULL;
last_merge_data = nullptr;
} else {
shard_kv_data.value_list[merged_kv_count].assign(
(const char *)sorted_kv_list[kv_idx - 1].second, value_size);
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/distributed/ps/service/brpc_ps_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int32_t BrpcPsServer::Initialize() {
}
auto *service =
CREATE_PSCORE_CLASS(PsBaseService, service_config.service_class());
if (service == NULL) {
if (service == nullptr) {
LOG(ERROR) << "service is unregistered, service_name:"
<< service_config.service_class();
return -1;
Expand Down
8 changes: 4 additions & 4 deletions paddle/fluid/distributed/ps/service/brpc_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -321,18 +321,18 @@ std::string GetIntTypeEndpoint(const std::string& ip, const uint32_t& port) {
// If there're some problem with DNS, or ip triggers the bug of Brpc
// We will try to get the IP address of the domain name manually again
std::string ip_port = ip + ":" + std::to_string(port);
struct hostent* hp = NULL;
struct hostent* hp = nullptr;
hp = gethostbyname(ip.c_str());

if (NULL == hp) {
if (nullptr == hp) {
LOG(ERROR) << "Brpc Start failed, ip_port= " << ip_port
<< " , Error infomation: " << hstrerror(h_errno);
}

int i = 0;
char* int_ip = NULL;
char* int_ip = nullptr;

while (hp->h_addr_list[i] != NULL) {
while (hp->h_addr_list[i] != nullptr) {
int_ip = inet_ntoa(*(struct in_addr*)hp->h_addr_list[i]);
VLOG(3) << "Brpc Get host by name, host:" << ip << " -> ip: " << int_ip;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const uint32_t MAX_FEASIGN_NUM = 1024 * 100 * 100;

inline double GetCurrentUS() {
struct timeval time;
gettimeofday(&time, NULL);
gettimeofday(&time, nullptr);
return 1e+6 * time.tv_sec + time.tv_usec;
}

Expand Down
6 changes: 3 additions & 3 deletions paddle/fluid/distributed/ps/service/graph_brpc_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void GraphPsService_Stub::service(
const ::paddle::distributed::PsRequestMessage *request,
::paddle::distributed::PsResponseMessage *response,
::google::protobuf::Closure *done) {
if (graph_service != NULL && local_channel == channel()) {
if (graph_service != nullptr && local_channel == channel()) {
// VLOG(0)<<"use local";
task_pool->enqueue([this, controller, request, response, done]() -> int {
this->graph_service->service(controller, request, response, done);
Expand Down Expand Up @@ -714,8 +714,8 @@ int32_t GraphBrpcClient::Initialize() {
// set_shard_num(_config.shard_num());
BrpcPsClient::Initialize();
server_size = GetServerNums();
graph_service = NULL;
local_channel = NULL;
graph_service = nullptr;
local_channel = nullptr;
return 0;
}
} // namespace distributed
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/distributed/ps/service/graph_brpc_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int32_t GraphBrpcServer::Initialize() {
}
auto *service =
CREATE_PSCORE_CLASS(PsBaseService, service_config.service_class());
if (service == NULL) {
if (service == nullptr) {
LOG(ERROR) << "service is unregistered, service_name:"
<< service_config.service_class();
return -1;
Expand Down Expand Up @@ -446,7 +446,7 @@ int32_t GraphBrpcService::graph_random_sample_nodes(
type_id, idx_, size, buffer, actual_size) == 0) {
cntl->response_attachment().append(buffer.get(), actual_size);
} else {
cntl->response_attachment().append(NULL, 0);
cntl->response_attachment().append(nullptr, 0);
}

return 0;
Expand Down
12 changes: 6 additions & 6 deletions paddle/fluid/distributed/ps/service/ps_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,24 @@ PSClient *PSClientFactory::Create(const PSParameter &ps_config) {
const auto &config = ps_config.server_param();
if (!config.has_downpour_server_param()) {
LOG(ERROR) << "miss downpour_server_param in ServerParameter";
return NULL;
return nullptr;
}

if (!config.downpour_server_param().has_service_param()) {
LOG(ERROR) << "miss service_param in ServerParameter.downpour_server_param";
return NULL;
return nullptr;
}

if (!config.downpour_server_param().service_param().has_client_class()) {
LOG(ERROR) << "miss client_class in "
"ServerParameter.downpour_server_param.service_param";
return NULL;
return nullptr;
}

const auto &service_param = config.downpour_server_param().service_param();
const auto &client_name = service_param.client_class();

PSClient *client = NULL;
PSClient *client = nullptr;
#if defined(PADDLE_WITH_GLOO) && defined(PADDLE_WITH_GPU_GRAPH)
auto gloo = ::paddle::framework::GlooWrapper::GetInstance();
if (client_name == "PsLocalClient" && gloo->Size() > 1) {
Expand All @@ -99,10 +99,10 @@ PSClient *PSClientFactory::Create(const PSParameter &ps_config) {
#else
client = CREATE_PSCORE_CLASS(PSClient, client_name);
#endif
if (client == NULL) {
if (client == nullptr) {
LOG(ERROR) << "client is not registered, server_name:"
<< service_param.client_class();
return NULL;
return nullptr;
}

TableManager::Instance().Initialize();
Expand Down
10 changes: 5 additions & 5 deletions paddle/fluid/distributed/ps/service/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,27 @@ PSServer *PSServerFactory::Create(const PSParameter &ps_config) {

if (!config.has_downpour_server_param()) {
LOG(ERROR) << "miss downpour_server_param in ServerParameter";
return NULL;
return nullptr;
}

if (!config.downpour_server_param().has_service_param()) {
LOG(ERROR) << "miss service_param in ServerParameter.downpour_server_param";
return NULL;
return nullptr;
}

if (!config.downpour_server_param().service_param().has_server_class()) {
LOG(ERROR) << "miss server_class in "
"ServerParameter.downpour_server_param.service_param";
return NULL;
return nullptr;
}

const auto &service_param = config.downpour_server_param().service_param();
PSServer *server =
CREATE_PSCORE_CLASS(PSServer, service_param.server_class());
if (server == NULL) {
if (server == nullptr) {
LOG(ERROR) << "server is not registered, server_name:"
<< service_param.server_class();
return NULL;
return nullptr;
}
TableManager::Instance().Initialize();
return server;
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/distributed/ps/table/common_graph_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1818,7 +1818,7 @@ FeatureNode *GraphShard::add_feature_node(uint64_t id,
if (is_overlap) {
return reinterpret_cast<FeatureNode *>(bucket[node_location[id]]);
}
return NULL;
return nullptr;
}

void GraphShard::add_neighbor(uint64_t id, uint64_t dst_id, float weight) {
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/distributed/ps/table/memory_sparse_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ int32_t MemorySparseTable::Load(const std::string &path,
err_no = 0;
std::string line_data;
auto read_channel = _afs_client.open_r(channel_config, 0, &err_no);
char *end = NULL;
char *end = nullptr;
auto &shard = _local_shards[i];
try {
while (read_channel->read_line(line_data) == 0 &&
Expand Down Expand Up @@ -241,7 +241,7 @@ int32_t MemorySparseTable::LoadPatch(const std::vector<std::string> &file_list,
err_no = 0;
std::string line_data;
auto read_channel = _afs_client.open_r(channel_config, 0, &err_no);
char *end = NULL;
char *end = nullptr;
int m_local_shard_id = i % _m_avg_local_shard_num;
std::unordered_set<size_t> global_shard_idx;
std::string global_shard_idx_str;
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/distributed/ps/table/ssd_sparse_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ int32_t SSDSparseTable::PullSparsePtr(int shard_id,
std::vector<std::future<int>> tasks;
RocksDBItem* cur_ctx = context.switch_item();
cur_ctx->reset();
FixedFeatureValue* ret = NULL;
FixedFeatureValue* ret = nullptr;
auto& local_shard = _local_shards[shard_id];
float data_buffer[value_size]; // NOLINT
float* data_buffer_ptr = data_buffer;
Expand Down Expand Up @@ -2612,7 +2612,7 @@ int32_t SSDSparseTable::LoadWithString(
ssd_values.clear();
tmp_key.clear();
std::string line_data;
char* end = NULL;
char* end = nullptr;
int local_shard_id = i % _avg_local_shard_num;
auto& shard = _local_shards[local_shard_id];
float data_buffer[FLAGS_pserver_load_batch_size *
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/distributed/ps/table/table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ int32_t Table::InitializeAccessor() {
auto *accessor =
CREATE_PSCORE_CLASS(ValueAccessor, _config.accessor().accessor_class());

if (accessor == NULL) {
if (accessor == nullptr) {
LOG(ERROR) << "accessor is unregistered, table_id:" << _config.table_id()
<< ", accessor_name:" << _config.accessor().accessor_class();
return -1;
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/framework/program_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ ProgramProcessor::ProgramProcessor() = default;
// write to file
void WriteToFile(const std::string &file_path, const std::string &msg) {
FILE *fp = fopen(file_path.c_str(), "w");
if (fp == NULL) {
if (fp == nullptr) {
LOG(WARNING) << "open write file path=" << file_path << " failed";
return;
}
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/pybind/eager_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2679,7 +2679,7 @@ static Py_tss_t static_op_arg_pre_cast_hook_key = {0, 0};

inline static PyObject* static_op_arg_pre_cast_hook_get() {
void* result = PyThread_tss_get(&static_op_arg_pre_cast_hook_key);
if (result == NULL) {
if (result == nullptr) {
return Py_None;
} else {
return reinterpret_cast<PyObject*>(result);
Expand Down Expand Up @@ -2714,7 +2714,7 @@ PyMODINIT_FUNC PyInit__static_op_arg_pre_cast_hook() {

Py_INCREF(Py_None);
static_op_arg_pre_cast_hook_set(Py_None);
return NULL;
return nullptr;
}

/* ------------------ for auto parallel ----------------------- */
Expand Down
6 changes: 3 additions & 3 deletions paddle/fluid/pybind/op_callstack_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pir::Attribute CallStackRecorder::GetOpCallstackInfo() {
PyObject* traceback_str = PyUnicode_FromString("traceback");
PyObject* traceback_module = PyImport_Import(traceback_str);

if (NULL == traceback_module) {
if (nullptr == traceback_module) {
Py_DECREF(traceback_str);
Py_DECREF(traceback_module);
PADDLE_THROW(paddle::platform::errors::PreconditionNotMet(
Expand All @@ -33,8 +33,8 @@ pir::Attribute CallStackRecorder::GetOpCallstackInfo() {
api_name_));
}
PyObject* tb = PyObject_GetAttrString(traceback_module, "extract_stack");
PyObject* stack = PyObject_CallObject(tb, NULL);
if (NULL == stack) {
PyObject* stack = PyObject_CallObject(tb, nullptr);
if (nullptr == stack) {
Py_DECREF(tb);
Py_DECREF(traceback_str);
Py_DECREF(traceback_module);
Expand Down

0 comments on commit 61da770

Please sign in to comment.