diff --git a/.clang-tidy b/.clang-tidy index 900175f9f0510abc214f82785a51c523bfb94ced..c31fb9ba8f1af6319b8ab49a6131b9d3c4760749 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -184,7 +184,7 @@ modernize-redundant-void-arg, -modernize-use-equals-default, -modernize-use-equals-delete, -modernize-use-noexcept, --modernize-use-nullptr, +modernize-use-nullptr, modernize-use-override, -modernize-use-transparent-functors, -modernize-use-uncaught-exceptions, diff --git a/paddle/fluid/framework/data_feed.cc b/paddle/fluid/framework/data_feed.cc index 4623d452c7d2b15d8b836c27fe3ac6830613fbb2..b5584e94e8fc495db0ef42b128b89f5cb105b376 100644 --- a/paddle/fluid/framework/data_feed.cc +++ b/paddle/fluid/framework/data_feed.cc @@ -59,8 +59,8 @@ class BufferedLineFileReader { int read_lines(T* reader, LineFunc func, int skip_lines) { int lines = 0; size_t ret = 0; - char* ptr = NULL; - char* eol = NULL; + char* ptr = nullptr; + char* eol = nullptr; total_len_ = 0; error_line_ = 0; @@ -70,7 +70,7 @@ class BufferedLineFileReader { total_len_ += ret; ptr = buff_; eol = reinterpret_cast(memchr(ptr, '\n', ret)); - while (eol != NULL) { + while (eol != nullptr) { int size = static_cast((eol - ptr) + 1); x.append(ptr, size - 1); ++lines; @@ -1106,13 +1106,13 @@ void MultiSlotInMemoryDataFeed::GetMsgFromLogKey(const std::string& log_key, uint32_t* cmatch, uint32_t* rank) { std::string searchid_str = log_key.substr(16, 16); - *search_id = (uint64_t)strtoull(searchid_str.c_str(), NULL, 16); + *search_id = (uint64_t)strtoull(searchid_str.c_str(), nullptr, 16); std::string cmatch_str = log_key.substr(11, 3); - *cmatch = (uint32_t)strtoul(cmatch_str.c_str(), NULL, 16); + *cmatch = (uint32_t)strtoul(cmatch_str.c_str(), nullptr, 16); std::string rank_str = log_key.substr(14, 2); - *rank = (uint32_t)strtoul(rank_str.c_str(), NULL, 16); + *rank = (uint32_t)strtoul(rank_str.c_str(), nullptr, 16); } int MultiSlotInMemoryDataFeed::ParseInstanceFromSo( @@ -1657,8 +1657,8 @@ bool MultiSlotFileInstantDataFeed::Preprocess(const std::string& filename) { fstat(fd_, &sb); end_ = static_cast(sb.st_size); - buffer_ = - reinterpret_cast(mmap(NULL, end_, PROT_READ, MAP_PRIVATE, fd_, 0)); + buffer_ = reinterpret_cast( + mmap(nullptr, end_, PROT_READ, MAP_PRIVATE, fd_, 0)); PADDLE_ENFORCE_NE( buffer_, MAP_FAILED, @@ -2401,11 +2401,12 @@ static void parser_log_key(const std::string& log_key, uint32_t* cmatch, uint32_t* rank) { std::string searchid_str = log_key.substr(16, 16); - *search_id = static_cast(strtoull(searchid_str.c_str(), NULL, 16)); + *search_id = + static_cast(strtoull(searchid_str.c_str(), nullptr, 16)); std::string cmatch_str = log_key.substr(11, 3); - *cmatch = static_cast(strtoul(cmatch_str.c_str(), NULL, 16)); + *cmatch = static_cast(strtoul(cmatch_str.c_str(), nullptr, 16)); std::string rank_str = log_key.substr(14, 2); - *rank = static_cast(strtoul(rank_str.c_str(), NULL, 16)); + *rank = static_cast(strtoul(rank_str.c_str(), nullptr, 16)); } bool SlotRecordInMemoryDataFeed::ParseOneInstance(const std::string& line, diff --git a/paddle/fluid/framework/io/crypto/aes_cipher.cc b/paddle/fluid/framework/io/crypto/aes_cipher.cc index fd07d4d6ebfb1608ed8a273038bb24cff7e1221a..5d27af0301fcf3a4c6d52eb7271b0ab961c55aa1 100644 --- a/paddle/fluid/framework/io/crypto/aes_cipher.cc +++ b/paddle/fluid/framework/io/crypto/aes_cipher.cc @@ -187,38 +187,42 @@ void AESCipher::BuildCipher( m_cipher->reset(new CryptoPP::ECB_Mode::Encryption); m_filter->reset(new CryptoPP::StreamTransformationFilter( *(*m_cipher).get(), - NULL, + nullptr, CryptoPP::BlockPaddingSchemeDef::PKCS_PADDING)); } else if (aes_cipher_name_ == "AES_ECB_PKCSPadding" && !for_encrypt) { m_cipher->reset(new CryptoPP::ECB_Mode::Decryption); m_filter->reset(new CryptoPP::StreamTransformationFilter( *(*m_cipher).get(), - NULL, + nullptr, CryptoPP::BlockPaddingSchemeDef::PKCS_PADDING)); } else if (aes_cipher_name_ == "AES_CBC_PKCSPadding" && for_encrypt) { m_cipher->reset(new CryptoPP::CBC_Mode::Encryption); *need_iv = true; m_filter->reset(new CryptoPP::StreamTransformationFilter( *(*m_cipher).get(), - NULL, + nullptr, CryptoPP::BlockPaddingSchemeDef::PKCS_PADDING)); } else if (aes_cipher_name_ == "AES_CBC_PKCSPadding" && !for_encrypt) { m_cipher->reset(new CryptoPP::CBC_Mode::Decryption); *need_iv = true; m_filter->reset(new CryptoPP::StreamTransformationFilter( *(*m_cipher).get(), - NULL, + nullptr, CryptoPP::BlockPaddingSchemeDef::PKCS_PADDING)); } else if (aes_cipher_name_ == "AES_CTR_NoPadding" && for_encrypt) { m_cipher->reset(new CryptoPP::CTR_Mode::Encryption); *need_iv = true; m_filter->reset(new CryptoPP::StreamTransformationFilter( - *(*m_cipher).get(), NULL, CryptoPP::BlockPaddingSchemeDef::NO_PADDING)); + *(*m_cipher).get(), + nullptr, + CryptoPP::BlockPaddingSchemeDef::NO_PADDING)); } else if (aes_cipher_name_ == "AES_CTR_NoPadding" && !for_encrypt) { m_cipher->reset(new CryptoPP::CTR_Mode::Decryption); *need_iv = true; m_filter->reset(new CryptoPP::StreamTransformationFilter( - *(*m_cipher).get(), NULL, CryptoPP::BlockPaddingSchemeDef::NO_PADDING)); + *(*m_cipher).get(), + nullptr, + CryptoPP::BlockPaddingSchemeDef::NO_PADDING)); } else { PADDLE_THROW(paddle::platform::errors::Unimplemented( "Create cipher error. " @@ -236,7 +240,7 @@ void AESCipher::BuildAuthEncCipher( *need_iv = true; m_filter->reset(new CryptoPP::AuthenticatedEncryptionFilter( *(*m_cipher).get(), - NULL, + nullptr, false, tag_size_ / 8, CryptoPP::DEFAULT_CHANNEL, @@ -258,7 +262,7 @@ void AESCipher::BuildAuthDecCipher( *need_iv = true; m_filter->reset(new CryptoPP::AuthenticatedDecryptionFilter( *(*m_cipher).get(), - NULL, + nullptr, CryptoPP::AuthenticatedDecryptionFilter::DEFAULT_FLAGS, tag_size_ / 8, CryptoPP::BlockPaddingSchemeDef::NO_PADDING)); diff --git a/paddle/fluid/framework/io/fs.cc b/paddle/fluid/framework/io/fs.cc index 3bc36a81482ea956357d736d781c5432fa155a7c..3d5f956c26b962d97428c554b2ca18837046b366 100644 --- a/paddle/fluid/framework/io/fs.cc +++ b/paddle/fluid/framework/io/fs.cc @@ -60,7 +60,7 @@ static std::shared_ptr fs_open_internal(const std::string& path, bool is_pipe, const std::string& mode, size_t buffer_size, - int* err_no = 0) { + int* err_no = nullptr) { std::shared_ptr fp = nullptr; if (!is_pipe) { diff --git a/paddle/fluid/framework/io/shell.cc b/paddle/fluid/framework/io/shell.cc index 27c96e362e01d8e7a7a68bba5e8d614872099a2d..62855afcf04ead7ed80872085ecf0adbed9ab3ef 100644 --- a/paddle/fluid/framework/io/shell.cc +++ b/paddle/fluid/framework/io/shell.cc @@ -82,7 +82,7 @@ static int close_open_fds_internal() { break; } - linux_dirent* entry = NULL; + linux_dirent* entry = nullptr; for (int offset = 0; offset < bytes; offset += entry->d_reclen) { entry = reinterpret_cast(buffer + offset); @@ -140,9 +140,9 @@ static int shell_popen_fork_internal(const char* real_cmd, close_open_fds_internal(); #if defined(PADDLE_WITH_MUSL) - PCHECK(execl("/bin/sh", "sh", "-c", real_cmd, NULL) >= 0); + PCHECK(execl("/bin/sh", "sh", "-c", real_cmd, nullptr) >= 0); #else - PCHECK(execl("/bin/bash", "bash", "-c", real_cmd, NULL) >= 0); + PCHECK(execl("/bin/bash", "bash", "-c", real_cmd, nullptr) >= 0); #endif // Note: just for compilation. the child don't run this line. _exit(0); @@ -179,7 +179,7 @@ std::shared_ptr shell_popen(const std::string& cmd, bool do_write = mode == "w"; if (!(do_read || do_write)) { *err_no = -1; - return NULL; + return nullptr; } VLOG(3) << "Opening pipe[" << cmd << "] with mode[" << mode << "]"; @@ -189,7 +189,7 @@ std::shared_ptr shell_popen(const std::string& cmd, int pipe_fds[2]; if (pipe(pipe_fds) != 0) { *err_no = -1; - return NULL; + return nullptr; } int parent_end = 0; int child_end = 0; @@ -212,11 +212,11 @@ std::shared_ptr shell_popen(const std::string& cmd, close(child_end); - FILE* fp = NULL; - if ((fp = fdopen(parent_end, mode.c_str())) == NULL) { + FILE* fp = nullptr; + if ((fp = fdopen(parent_end, mode.c_str())) == nullptr) { *err_no = -1; signal(SIGCHLD, old_handler); - return NULL; + return nullptr; } return {fp, [cmd, child_pid, old_handler, err_no, status](FILE* fp) { @@ -281,7 +281,7 @@ static int shell_p2open_fork_internal(const char* real_cmd, } close_open_fds_internal(); - if (execl("/bin/sh", "sh", "-c", real_cmd, NULL) < 0) { + if (execl("/bin/sh", "sh", "-c", real_cmd, nullptr) < 0) { return -1; } exit(127); @@ -302,10 +302,10 @@ std::pair, std::shared_ptr> shell_p2open( int pipein_fds[2]; int pipeout_fds[2]; if (pipe(pipein_fds) != 0) { - return {NULL, NULL}; + return {nullptr, nullptr}; } if (pipe(pipeout_fds) != 0) { - return {NULL, NULL}; + return {nullptr, nullptr}; } int child_pid = @@ -317,7 +317,7 @@ std::pair, std::shared_ptr> shell_p2open( fcntl(pipeout_fds[1], F_SETFD, FD_CLOEXEC); std::shared_ptr child_life = { - NULL, [child_pid, cmd](void*) { + nullptr, [child_pid, cmd](void*) { if (shell_verbose()) { LOG(INFO) << "Closing bidirectional pipe[" << cmd << "]"; } @@ -340,9 +340,9 @@ std::pair, std::shared_ptr> shell_p2open( }}; FILE* in_fp; - PCHECK((in_fp = fdopen(pipein_fds[0], "r")) != NULL); + PCHECK((in_fp = fdopen(pipein_fds[0], "r")) != nullptr); FILE* out_fp; - PCHECK((out_fp = fdopen(pipeout_fds[1], "w")) != NULL); + PCHECK((out_fp = fdopen(pipeout_fds[1], "w")) != nullptr); return {{in_fp, [child_life](FILE* fp) { PCHECK(fclose(fp) == 0); }}, {out_fp, [child_life](FILE* fp) { PCHECK(fclose(fp) == 0); }}}; #endif diff --git a/paddle/fluid/framework/ir/multi_devices_graph_pass/fuse_all_reduce_op_pass.cc b/paddle/fluid/framework/ir/multi_devices_graph_pass/fuse_all_reduce_op_pass.cc index 3b6b384115999a01a953822731cc692cf6152c00..6b4e786a5aae9e9781ce2cc55187c0c56a7fd05e 100644 --- a/paddle/fluid/framework/ir/multi_devices_graph_pass/fuse_all_reduce_op_pass.cc +++ b/paddle/fluid/framework/ir/multi_devices_graph_pass/fuse_all_reduce_op_pass.cc @@ -291,7 +291,7 @@ class FuseAllReduceOpPass : public ir::Pass { const platform::BKCLCommunicator *multi_bkcl_ctxs, #endif ir::Graph *result) const { - details::FusedAllReduceOpHandle *op_handle = NULL; + details::FusedAllReduceOpHandle *op_handle = nullptr; if (is_grad_merge) { #if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL) op_handle = new details::FusedGradMergeAllReduceOpHandle( diff --git a/paddle/fluid/inference/capi_exp/pd_config.cc b/paddle/fluid/inference/capi_exp/pd_config.cc index ca7e03407ddf6a360cd7ed70ec6218d0a90fb975..cb635116dffa5cb84facde1830c7ab2c911a123c 100644 --- a/paddle/fluid/inference/capi_exp/pd_config.cc +++ b/paddle/fluid/inference/capi_exp/pd_config.cc @@ -55,7 +55,7 @@ __pd_give PD_Config* PD_ConfigCreate() { } void PD_ConfigDestroy(__pd_take PD_Config* pd_config) { - if (pd_config != NULL) { + if (pd_config != nullptr) { delete reinterpret_cast(pd_config); } } diff --git a/paddle/fluid/inference/capi_exp/pd_predictor.cc b/paddle/fluid/inference/capi_exp/pd_predictor.cc index f0a16fee611dad0d5e5dd1037a846eeda34a184d..54da0f9c9195264255349f9d127a0c188adca911 100644 --- a/paddle/fluid/inference/capi_exp/pd_predictor.cc +++ b/paddle/fluid/inference/capi_exp/pd_predictor.cc @@ -68,7 +68,7 @@ __pd_give PD_IOInfos* PD_PredictorGetInputInfos( PD_IOInfos* input_infos = new PD_IOInfos; input_infos->size = names.size(); - input_infos->io_info = names.empty() ? NULL : new PD_IOInfo*[names.size()]; + input_infos->io_info = names.empty() ? nullptr : new PD_IOInfo*[names.size()]; for (size_t i = 0; i < names.size(); i++) { const std::string& name = names[i]; input_infos->io_info[i] = new PD_IOInfo; @@ -99,7 +99,8 @@ __pd_give PD_IOInfos* PD_PredictorGetOutputInfos( PD_IOInfos* output_infos = new PD_IOInfos; output_infos->size = names.size(); - output_infos->io_info = names.empty() ? NULL : new PD_IOInfo*[names.size()]; + output_infos->io_info = + names.empty() ? nullptr : new PD_IOInfo*[names.size()]; for (size_t i = 0; i < names.size(); i++) { const std::string& name = names[i]; output_infos->io_info[i] = new PD_IOInfo; diff --git a/paddle/fluid/inference/capi_exp/pd_utils.cc b/paddle/fluid/inference/capi_exp/pd_utils.cc index 4482e4bc098d61d3881171f4c38b5d65e31ea450..d1df35619b993b8410ab7b76c529668d0ee8c8f0 100644 --- a/paddle/fluid/inference/capi_exp/pd_utils.cc +++ b/paddle/fluid/inference/capi_exp/pd_utils.cc @@ -20,27 +20,27 @@ #define DESTROY_ONE_DIM_ARRAY(type) \ void PD_OneDimArray##type##Destroy(__pd_take PD_OneDimArray##type* array) { \ - if (array != NULL) { \ + if (array != nullptr) { \ delete[] array->data; \ delete array; \ } \ } -#define CONVERT_VEC_TO_ONE_DIM_ARRAY(type, Type, vec_type) \ - __pd_give PD_OneDimArray##Type* CvtVecToOneDimArray##Type( \ - const std::vector& vec) { \ - PD_OneDimArray##Type* array = new PD_OneDimArray##Type; \ - array->size = vec.size(); \ - array->data = vec.empty() ? NULL : new type[vec.size()]; \ - for (size_t index = 0; index < vec.size(); ++index) { \ - array->data[index] = vec[index]; \ - } \ - return array; \ +#define CONVERT_VEC_TO_ONE_DIM_ARRAY(type, Type, vec_type) \ + __pd_give PD_OneDimArray##Type* CvtVecToOneDimArray##Type( \ + const std::vector& vec) { \ + PD_OneDimArray##Type* array = new PD_OneDimArray##Type; \ + array->size = vec.size(); \ + array->data = vec.empty() ? nullptr : new type[vec.size()]; \ + for (size_t index = 0; index < vec.size(); ++index) { \ + array->data[index] = vec[index]; \ + } \ + return array; \ } #define CONVERT_ONE_DIM_ARRAY_TO_VEC(type, Type, vec_type) \ std::vector CvtOneDimArrayToVec##Type( \ __pd_keep const PD_OneDimArray##Type* array) { \ std::vector vec; \ - if (array != NULL) { \ + if (array != nullptr) { \ vec.resize(array->size); \ for (size_t index = 0; index < array->size; ++index) { \ vec[index] = array->data[index]; \ @@ -68,7 +68,7 @@ ONE_DIM_ARRAY_UTILS_FUNC_IMPL(int64_t, Int64, int64_t) #undef DESTROY_ONE_DIM_ARRAY void PD_OneDimArrayCstrDestroy(__pd_take PD_OneDimArrayCstr* array) { - if (array != NULL) { + if (array != nullptr) { if (array->size != 0) { for (size_t index = 0; index < array->size; ++index) { delete[] array->data[index]; @@ -80,11 +80,11 @@ void PD_OneDimArrayCstrDestroy(__pd_take PD_OneDimArrayCstr* array) { } void PD_CstrDestroy(__pd_take PD_Cstr* cstr) { - if (cstr != NULL) { + if (cstr != nullptr) { if (cstr->size != 0) { cstr->size = 0; delete[] cstr->data; - cstr->data = NULL; + cstr->data = nullptr; } delete cstr; } @@ -95,7 +95,7 @@ __pd_give PD_OneDimArrayCstr* CvtVecToOneDimArrayCstr( const std::vector& vec) { PD_OneDimArrayCstr* array = new PD_OneDimArrayCstr; array->size = vec.size(); - array->data = vec.empty() ? NULL : new char*[vec.size()]; + array->data = vec.empty() ? nullptr : new char*[vec.size()]; for (size_t index = 0u; index < vec.size(); ++index) { array->data[index] = new char[vec[index].size() + 1]; memcpy(array->data[index], vec[index].c_str(), vec[index].size() + 1); @@ -116,7 +116,7 @@ __pd_give PD_Cstr* CvtStrToCstr(const std::string& str) { PD_Cstr* cstr = new PD_Cstr; if (str.empty()) { cstr->size = 0; - cstr->data = NULL; + cstr->data = nullptr; } else { cstr->size = str.length() + 1; cstr->data = new char[str.length() + 1]; @@ -128,7 +128,7 @@ __pd_give PD_Cstr* CvtStrToCstr(const std::string& str) { #define DESTROY_TWO_DIM_ARRAY(type) \ void PD_TwoDimArray##type##Destroy(__pd_take PD_TwoDimArray##type* array) { \ - if (array != NULL) { \ + if (array != nullptr) { \ if (array->size != 0) { \ for (size_t index = 0; index < array->size; ++index) { \ PD_OneDimArray##type##Destroy(array->data[index]); \ @@ -138,22 +138,23 @@ __pd_give PD_Cstr* CvtStrToCstr(const std::string& str) { delete array; \ } \ } -#define CONVERT_VEC_TO_TWO_DIM_ARRAY(type, Type, vec_type) \ - __pd_give PD_TwoDimArray##Type* CvtVecToTwoDimArray##Type( \ - const std::vector>& vec) { \ - PD_TwoDimArray##Type* array = new PD_TwoDimArray##Type; \ - array->size = vec.size(); \ - array->data = vec.empty() ? NULL : new PD_OneDimArray##Type*[vec.size()]; \ - for (size_t index = 0; index < vec.size(); ++index) { \ - array->data[index] = CvtVecToOneDimArray##Type(vec[index]); \ - } \ - return array; \ +#define CONVERT_VEC_TO_TWO_DIM_ARRAY(type, Type, vec_type) \ + __pd_give PD_TwoDimArray##Type* CvtVecToTwoDimArray##Type( \ + const std::vector>& vec) { \ + PD_TwoDimArray##Type* array = new PD_TwoDimArray##Type; \ + array->size = vec.size(); \ + array->data = \ + vec.empty() ? nullptr : new PD_OneDimArray##Type*[vec.size()]; \ + for (size_t index = 0; index < vec.size(); ++index) { \ + array->data[index] = CvtVecToOneDimArray##Type(vec[index]); \ + } \ + return array; \ } #define CONVERT_TWO_DIM_ARRAY_TO_VEC(type, Type, vec_type) \ std::vector> CvtTwoDimArrayToVec##Type( \ __pd_keep const PD_TwoDimArray##Type* array) { \ std::vector> vec; \ - if (array != NULL && array->size != 0) { \ + if (array != nullptr && array->size != 0) { \ vec.resize(array->size); \ for (size_t index = 0; index < array->size; ++index) { \ vec[index] = CvtOneDimArrayToVec##Type((array->data)[index]); \ @@ -182,17 +183,17 @@ extern "C" { #endif void PD_IOInfoDestroy(__pd_take PD_IOInfo* io_info) { - if (io_info != NULL) { + if (io_info != nullptr) { PD_CstrDestroy(io_info->name); - io_info->name = NULL; + io_info->name = nullptr; PD_OneDimArrayInt64Destroy(io_info->shape); - io_info->shape = NULL; + io_info->shape = nullptr; delete io_info; } } void PD_IOInfosDestroy(__pd_take PD_IOInfos* io_infos) { - if (io_infos != NULL) { + if (io_infos != nullptr) { if (io_infos->size != 0) { for (size_t index = 0; index < io_infos->size; ++index) { PD_IOInfoDestroy(io_infos->io_info[index]); @@ -200,7 +201,7 @@ void PD_IOInfosDestroy(__pd_take PD_IOInfos* io_infos) { io_infos->size = 0; } delete[] io_infos->io_info; - io_infos->io_info = NULL; + io_infos->io_info = nullptr; delete io_infos; } } diff --git a/paddle/fluid/memory/allocation/best_fit_allocator_test.cc b/paddle/fluid/memory/allocation/best_fit_allocator_test.cc index 440fc85b57867b5836d4872d76cb28f1c3b8164d..67f81b5e71ba82df5a0be6b761a4dcb78ec9554a 100644 --- a/paddle/fluid/memory/allocation/best_fit_allocator_test.cc +++ b/paddle/fluid/memory/allocation/best_fit_allocator_test.cc @@ -30,7 +30,7 @@ namespace allocation { class StubAllocation : public Allocation { public: explicit StubAllocation(size_t size) - : Allocation(0, size, platform::CPUPlace()) {} + : Allocation(nullptr, size, platform::CPUPlace()) {} }; TEST(BestFitAllocator, test_allocation) { diff --git a/paddle/fluid/memory/allocation/mmap_allocator.cc b/paddle/fluid/memory/allocation/mmap_allocator.cc index ceda4ee578cee849b2862c9d7c0dde170f0e155b..60d97e5c5895588e1e3f35e6e898e9bdb36257fe 100644 --- a/paddle/fluid/memory/allocation/mmap_allocator.cc +++ b/paddle/fluid/memory/allocation/mmap_allocator.cc @@ -269,7 +269,7 @@ std::shared_ptr AllocateMemoryMapWriterAllocation( platform::errors::Unavailable( "Fruncate a file to a specified length failed!")); - void *ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + void *ptr = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); PADDLE_ENFORCE_NE(ptr, MAP_FAILED, platform::errors::Unavailable( diff --git a/paddle/fluid/operators/pyramid_hash_op.cc b/paddle/fluid/operators/pyramid_hash_op.cc index 991155e8d27ef702dfa16949762272653397433c..c255cd9a393c37d5fcc3b8c23a6817763543a366 100644 --- a/paddle/fluid/operators/pyramid_hash_op.cc +++ b/paddle/fluid/operators/pyramid_hash_op.cc @@ -307,8 +307,8 @@ class CPUPyramidHashOPKernel : public framework::OpKernel { top_offset.resize(offset.size()); top_offset[0] = 0; - math::bloomfilter* _filter = NULL; - math::bloomfilter* _black_filter = NULL; + math::bloomfilter* _filter = nullptr; + math::bloomfilter* _black_filter = nullptr; if (use_filter) { if (white_list_len != 0) { _filter = (math::bloomfilter*)_blobs_1->data(); diff --git a/paddle/fluid/platform/gen_comm_id_helper.cc b/paddle/fluid/platform/gen_comm_id_helper.cc index 365c44fc9abebe1d5f5a85ea90e23fbae55f6568..fd284a9e5401b2244ce9ce352b2edebee3419442 100644 --- a/paddle/fluid/platform/gen_comm_id_helper.cc +++ b/paddle/fluid/platform/gen_comm_id_helper.cc @@ -259,13 +259,13 @@ static int ConnectAddr(const std::string& ep, const CommHead head) { server_addr.sin_family = AF_INET; server_addr.sin_port = htons(port); - char* ip = NULL; - struct hostent* hp = NULL; + char* ip = nullptr; + struct hostent* hp = nullptr; // sleep for get_host_by_name_time seconds. for (int i = 0; 2 * i < FLAGS_get_host_by_name_time; i++) { hp = gethostbyname(host.c_str()); - if (hp != NULL) { + if (hp != nullptr) { break; } std::this_thread::sleep_for(std::chrono::seconds(2)); @@ -276,7 +276,7 @@ static int ConnectAddr(const std::string& ep, const CommHead head) { platform::errors::InvalidArgument("Fail to get host by name %s.", host)); int i = 0; - while (hp->h_addr_list[i] != NULL) { + while (hp->h_addr_list[i] != nullptr) { ip = inet_ntoa(*(struct in_addr*)hp->h_addr_list[i]); VLOG(3) << "gethostbyname host:" << host << " ->ip: " << ip; break; diff --git a/paddle/fluid/platform/init.cc b/paddle/fluid/platform/init.cc index c90c255ab044cdac29177a30a549284b3c03a911..49c996b9b621d25d6d4d4908bf3e5ecf06835803 100644 --- a/paddle/fluid/platform/init.cc +++ b/paddle/fluid/platform/init.cc @@ -348,7 +348,7 @@ void DisableSignalHandler() { memset(&sig_action, 0, sizeof(sig_action)); sigemptyset(&sig_action.sa_mask); sig_action.sa_handler = SIG_DFL; - sigaction(signal_number, &sig_action, NULL); + sigaction(signal_number, &sig_action, nullptr); } #endif } @@ -367,10 +367,10 @@ void CreateDumpFile(LPCSTR lpstrDumpFilePathName, HANDLE hDumpFile = CreateFile(lpstrDumpFilePathName, GENERIC_WRITE, 0, - NULL, + nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, - NULL); + nullptr); MINIDUMP_EXCEPTION_INFORMATION dumpInfo; dumpInfo.ExceptionPointers = pException; dumpInfo.ThreadId = GetCurrentThreadId(); @@ -384,8 +384,8 @@ void CreateDumpFile(LPCSTR lpstrDumpFilePathName, hDumpFile, MiniDumpWithPrivateReadWriteMemory, &dumpInfo, - NULL, - NULL); + nullptr, + nullptr); CloseHandle(hDumpFile); } diff --git a/paddle/fluid/platform/timer.cc b/paddle/fluid/platform/timer.cc index 75d4e5cbf90bd81c73756605eacc6b0c15a63e9d..7ddb5aeedb6fb463c4f4e6e9321112613c566104 100644 --- a/paddle/fluid/platform/timer.cc +++ b/paddle/fluid/platform/timer.cc @@ -41,7 +41,7 @@ void Timer::Pause() { } void Timer::Resume() { - gettimeofday(&_start, NULL); + gettimeofday(&_start, nullptr); _paused = false; } @@ -54,7 +54,7 @@ double Timer::ElapsedMS() { return _elapsed / 1000.0; } double Timer::ElapsedSec() { return _elapsed / 1000000.0; } int64_t Timer::Tickus() { - gettimeofday(&_now, NULL); + gettimeofday(&_now, nullptr); return (_now.tv_sec - _start.tv_sec) * 1000 * 1000L + (_now.tv_usec - _start.tv_usec); } diff --git a/paddle/fluid/pybind/eager.cc b/paddle/fluid/pybind/eager.cc index b90de78c1dbf8088c4ce01434e31cc1f04a65615..e2d23fa80d460c7b4b339cd97d959384f4f577b5 100644 --- a/paddle/fluid/pybind/eager.cc +++ b/paddle/fluid/pybind/eager.cc @@ -376,7 +376,7 @@ py::object ParsePyArray( numpy_value = py::object( py::handle(PyTuple_GET_ITEM(args, kw_order_map["value"] - 1)), true); } else { - if (flag_kwargs && kws_map["value"] != NULL) { + if (flag_kwargs && kws_map["value"] != nullptr) { numpy_value = py::object(py::handle(kws_map["value"]), true); } else { PADDLE_THROW(platform::errors::InvalidArgument( @@ -403,7 +403,7 @@ paddle::platform::Place ParsePlace( place = CastPyArg2Place(PyTuple_GET_ITEM(args, kw_order_map["place"] - 1), kw_order_map["place"] - 1); } else { - if (flag_kwargs && kws_map["place"] != NULL) { + if (flag_kwargs && kws_map["place"] != nullptr) { place = CastPyArg2Place(kws_map["place"], 0); } else { // default @@ -425,7 +425,7 @@ std::shared_ptr ParseDistAttrArgs( dist_attr = CastPyArg2DistAttr( PyTuple_GET_ITEM(args, kw_order_map["dist_attr"] - 1), kw_order_map["dist_attr"] - 1); - } else if (flag_kwargs && kws_map["dist_attr"] != NULL) { + } else if (flag_kwargs && kws_map["dist_attr"] != nullptr) { dist_attr = CastPyArg2DistAttr(kws_map["dist_attr"], 0); } return dist_attr; @@ -445,7 +445,7 @@ int ParseBooleanArgs(std::string key, res = static_cast(CastPyArg2AttrBoolean( PyTuple_GET_ITEM(args, kw_order_map[key] - 1), kw_order_map[key] - 1)); } else { - if (flag_kwargs && kws_map[key] != NULL) { + if (flag_kwargs && kws_map[key] != nullptr) { res = static_cast(CastPyArg2AttrBoolean(kws_map[key], 0)); } } @@ -469,7 +469,7 @@ std::string ParseName(std::unordered_map kws_map, } } else { if (flag_kwargs) { - if ((kws_map["name"] == NULL) || (kws_map["name"] == Py_None)) { + if ((kws_map["name"] == nullptr) || (kws_map["name"] == Py_None)) { act_name = egr::Controller::Instance().GenerateUniqueName(unique_name_prefix); } else { @@ -581,7 +581,7 @@ void AutoInitTensorByTensor(TensorObject* py_tensor_ptr, CastPyArg2Tensor(PyTuple_GET_ITEM(args, kw_order_map["value"] - 1), kw_order_map["value"] - 1); } else { - if (flag_kwargs && kws_map["value"] != NULL) { + if (flag_kwargs && kws_map["value"] != nullptr) { src_tensor = CastPyArg2Tensor(kws_map["value"], 0); } else { PADDLE_THROW(platform::errors::InvalidArgument( @@ -610,7 +610,7 @@ void AutoInitTensorByTensor(TensorObject* py_tensor_ptr, PyTuple_GET_ITEM(args, kw_order_map["value"] - 1), kw_order_map["value"] - 1); } else { - if (flag_kwargs && kws_map["value"] != NULL) { + if (flag_kwargs && kws_map["value"] != nullptr) { src_tensor = CastPyArg2FrameworkTensor(kws_map["value"], 0); } else { PADDLE_THROW(platform::errors::InvalidArgument( @@ -687,7 +687,7 @@ void AutoInitStringTensorByStringTensor( CastPyArg2Tensor(PyTuple_GET_ITEM(args, kw_order_map["value"] - 1), kw_order_map["value"] - 1); } else { - if (flag_kwargs && kws_map["value"] != NULL) { + if (flag_kwargs && kws_map["value"] != nullptr) { src_tensor = CastPyArg2Tensor(kws_map["value"], 0); } else { PADDLE_THROW(platform::errors::InvalidArgument( @@ -764,17 +764,17 @@ int TensorInit(PyObject* self, PyObject* args, PyObject* kwargs) { if (kwargs) flag_kwargs = true; // all kwargs - PyObject* kw_zero_copy = NULL; - PyObject* kw_persistable = NULL; - PyObject* kw_stop_gradient = NULL; - - PyObject* kw_value = NULL; // receive PyArray or Tensor - PyObject* kw_place = NULL; - PyObject* kw_name = NULL; - PyObject* kw_dims = NULL; - PyObject* kw_dtype = NULL; - PyObject* kw_type = NULL; - PyObject* kw_dist_attr = NULL; + PyObject* kw_zero_copy = nullptr; + PyObject* kw_persistable = nullptr; + PyObject* kw_stop_gradient = nullptr; + + PyObject* kw_value = nullptr; // receive PyArray or Tensor + PyObject* kw_place = nullptr; + PyObject* kw_name = nullptr; + PyObject* kw_dims = nullptr; + PyObject* kw_dtype = nullptr; + PyObject* kw_type = nullptr; + PyObject* kw_dist_attr = nullptr; // the keywords argument static char* kwlist[] = {const_cast("value"), @@ -787,7 +787,7 @@ int TensorInit(PyObject* self, PyObject* args, PyObject* kwargs) { const_cast("dtype"), const_cast("type"), const_cast("dist_attr"), - NULL}; + nullptr}; // 'O' Store a Python object (without any conversion) in a C object pointer, // '|' Indicates that the remaining arguments in the Python argument list are @@ -856,7 +856,7 @@ int TensorInit(PyObject* self, PyObject* args, PyObject* kwargs) { egr::Controller::Instance().GetExpectedPlace()); return 0; } else { // no position args, all arguments are kwargs - if (kw_value != NULL) { + if (kw_value != nullptr) { if (pybind11::detail::npy_api::get().PyArray_Check_(kw_value)) { VLOG(6) << "Calling case3's or case4's initializer"; AutoInitTensorByPyArray( @@ -884,7 +884,7 @@ int TensorInit(PyObject* self, PyObject* args, PyObject* kwargs) { "Please check your input first and make sure you are on the " "right way.")); } - } else if (kw_dtype != NULL && + } else if (kw_dtype != nullptr && PyObject_TypeCheck(kw_dtype, g_vartype_pytype)) { VLOG(6) << "Calling case2's initializer"; @@ -1122,18 +1122,18 @@ int StringTensorInit(PyObject* self, PyObject* args, PyObject* kwargs) { if (kwargs) flag_kwargs = true; // all kwargs - PyObject* kw_zero_copy = NULL; + PyObject* kw_zero_copy = nullptr; - PyObject* kw_value = NULL; // receive PyArray or Tensor - PyObject* kw_name = NULL; - PyObject* kw_dims = NULL; + PyObject* kw_value = nullptr; // receive PyArray or Tensor + PyObject* kw_name = nullptr; + PyObject* kw_dims = nullptr; // the keywords argument static char* kwlist[] = {const_cast("value"), const_cast("zero_copy"), const_cast("name"), const_cast("dims"), - NULL}; + nullptr}; // 'O' Store a Python object (without any conversion) in a C object pointer, // '|' Indicates that the remaining arguments in the Python argument list are // optional. @@ -1188,7 +1188,7 @@ int StringTensorInit(PyObject* self, PyObject* args, PyObject* kwargs) { egr::Controller::Instance().GetExpectedPlace()); return 0; } else { - if (kw_value != NULL) { + if (kw_value != nullptr) { if (pybind11::detail::npy_api::get().PyArray_Check_(kw_value)) { VLOG(6) << "Calling case3's or case4's string initializer"; AutoInitStringTensorByPyArray( @@ -1207,7 +1207,7 @@ int StringTensorInit(PyObject* self, PyObject* args, PyObject* kwargs) { "Please check your input first and make sure you are on the " "right way.")); } - } else if (kw_dims != NULL) { + } else if (kw_dims != nullptr) { VLOG(6) << "Calling case2's string initializer."; std::unordered_map kw_order_map{{"dims", 1}, {"name", 2}}; @@ -1311,7 +1311,7 @@ void AddPyMethodDefs(std::vector* vector, PyMethodDef* methods) { } static void TensorDealloc(TensorObject* self) { - if (self->weakrefs != NULL) + if (self->weakrefs != nullptr) PyObject_ClearWeakRefs(reinterpret_cast(self)); self->tensor.~Tensor(); Py_TYPE(self)->tp_free(reinterpret_cast(self)); diff --git a/paddle/fluid/pybind/eager_functions.cc b/paddle/fluid/pybind/eager_functions.cc index b4a4f46cb37b6ce60ee772fd261e15d10e56b84c..20fb007ed2367d47509392ef50d3a5838b07ba1f 100644 --- a/paddle/fluid/pybind/eager_functions.cc +++ b/paddle/fluid/pybind/eager_functions.cc @@ -1258,7 +1258,7 @@ static PyObject* eager_api_set_master_grads(PyObject* self, PADDLE_ENFORCE_NE(grad, nullptr, paddle::platform::errors::Fatal( - "Detected NULL grad" + "Detected nullptr grad" "Please check if you have manually cleared" "the grad inside autograd_meta")); if ((*grad).initialized() && ((*grad).dtype() == phi::DataType::FLOAT16 || @@ -1278,90 +1278,90 @@ PyMethodDef variable_functions[] = { {"scale", (PyCFunction)(void (*)())eager_api_scale, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_add_backward_final_hook", (PyCFunction)(void (*)())eager_api__add_backward_final_hook, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"run_backward", (PyCFunction)(void (*)())eager_api_run_backward, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"run_partial_grad", (PyCFunction)(void (*)())eager_api_run_partial_grad, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_get_custom_operator_inplace_map", (PyCFunction)(void (*)( void))eager_api__get_custom_operator_inplace_reverse_idx, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_run_custom_op", (PyCFunction)(void (*)())eager_api_run_custom_op, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"tensor_copy", (PyCFunction)(void (*)())eager_api_tensor_copy, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"get_all_grads", (PyCFunction)(void (*)())eager_api_get_all_grads, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"get_grads_lists", (PyCFunction)(void (*)())eager_api_get_grads_lists, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"get_grads_types", (PyCFunction)(void (*)())eager_api_get_grads_types, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"read_next_tensor_list", (PyCFunction)(void (*)())eager_api_read_next_tensor_list, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"jit_function_call", (PyCFunction)(void (*)())eager_api_jit_function_call, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, /**sparse functions**/ {"sparse_coo_tensor", (PyCFunction)(void (*)())eager_api_sparse_coo_tensor, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"sparse_csr_tensor", (PyCFunction)(void (*)())eager_api_sparse_csr_tensor, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"register_saved_tensors_hooks", (PyCFunction)(void (*)())eager_api_register_saved_tensors_hooks, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"reset_saved_tensors_hooks", (PyCFunction)(void (*)())eager_api_reset_saved_tensors_hooks, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, /**amp functions**/ {"set_master_grads", (PyCFunction)(void (*)())eager_api_set_master_grads, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, /**sparse functions**/ #if defined(PADDLE_WITH_CUDA) {"async_read", (PyCFunction)(void (*)())eager_api_async_read, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"async_write", (PyCFunction)(void (*)())eager_api_async_write, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"to_uva_tensor", (PyCFunction)(void (*)())eager_api_to_uva_tensor, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, #endif - {NULL, NULL, 0, NULL}}; + {nullptr, nullptr, 0, nullptr}}; void BindFunctions(PyObject* module) { if (PyModule_AddFunctions(module, variable_functions) < 0) { diff --git a/paddle/fluid/pybind/eager_math_op_patch.cc b/paddle/fluid/pybind/eager_math_op_patch.cc index 2ae38c7bac0eb5b29b8194d03de6a756ed166330..e26a35490ccbca5b569623d150298f39f8bb6461 100644 --- a/paddle/fluid/pybind/eager_math_op_patch.cc +++ b/paddle/fluid/pybind/eager_math_op_patch.cc @@ -1837,88 +1837,88 @@ PyMethodDef math_op_patch_methods[] = { {"__add__", (PyCFunction)(void (*)())tensor__add__method, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"__radd__", (PyCFunction)(void (*)())tensor__add__method, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"__sub__", (PyCFunction)(void (*)())tensor__sub__method, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"__rsub__", (PyCFunction)(void (*)())tensor__rsub__method, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"__mul__", (PyCFunction)(void (*)())tensor__mul__method, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"__rmul__", (PyCFunction)(void (*)())tensor__mul__method, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"__div__", (PyCFunction)(void (*)())tensor__div__method, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"__truediv__", (PyCFunction)(void (*)())tensor__div__method, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"__rdiv__", (PyCFunction)(void (*)())tensor__rdiv__method, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"__rtruediv__", (PyCFunction)(void (*)())tensor__rdiv__method, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"__floordiv__", (PyCFunction)(void (*)())tensor__floordiv__method, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"__pow__", (PyCFunction)(void (*)())tensor__pow__method, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"__rpow__", (PyCFunction)(void (*)())tensor__rpow__method, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"__mod__", (PyCFunction)(void (*)())tensor__mod__method, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"__matmul__", (PyCFunction)(void (*)())tensor__matmul__method, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"__gt__", (PyCFunction)(void (*)())tensor__gt__method, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"__ge__", (PyCFunction)(void (*)())tensor__ge__method, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"__lt__", (PyCFunction)(void (*)())tensor__lt__method, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"__le__", (PyCFunction)(void (*)())tensor__le__method, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"__eq__", (PyCFunction)(void (*)())tensor__eq__method, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"__ne__", (PyCFunction)(void (*)())tensor__ne__method, METH_VARARGS | METH_KEYWORDS, - NULL}, - {NULL, NULL, 0, NULL}}; + nullptr}, + {nullptr, nullptr, 0, nullptr}}; } // namespace pybind } // namespace paddle diff --git a/paddle/fluid/pybind/eager_method.cc b/paddle/fluid/pybind/eager_method.cc index cb11759af335b951ed531940e586466c4115a293..06edbeef48cb05081d1b49e248bf771b013b092f 100644 --- a/paddle/fluid/pybind/eager_method.cc +++ b/paddle/fluid/pybind/eager_method.cc @@ -716,7 +716,7 @@ static PyObject* tensor_clear_gradient(TensorObject* self, grad = egr::EagerUtils::mutable_grad(self->tensor); PADDLE_ENFORCE(grad != nullptr, paddle::platform::errors::Fatal( - "Detected NULL grad" + "Detected nullptr grad" "Please check if you have manually cleared" "the grad inside autograd_meta")); } else { @@ -773,7 +773,7 @@ static PyObject* tensor__zero_grads(TensorObject* self, paddle::Tensor* grad = egr::EagerUtils::mutable_grad(self->tensor); PADDLE_ENFORCE(grad != nullptr, paddle::platform::errors::Fatal( - "Detected NULL grad" + "Detected nullptr grad" "Please check if you have manually cleared" "the grad inside autograd_meta")); if (grad->initialized()) { @@ -1570,7 +1570,7 @@ static PyObject* tensor_register_grad_hook(TensorObject* self, if (autograd_meta && !autograd_meta->StopGradient()) { if (!autograd_meta->GetMutableGradNode()) { - VLOG(6) << "Detected NULL grad_node, Leaf tensor should have had " + VLOG(6) << "Detected nullptr grad_node, Leaf tensor should have had " "grad_node with type: GradNodeAccumulation."; autograd_meta->SetGradNode( std::make_shared(autograd_meta)); @@ -1666,7 +1666,7 @@ static PyObject* tensor_register_reduce_hook(TensorObject* self, "gradient.")); PADDLE_ENFORCE( grad_node.get() != nullptr, - paddle::platform::errors::Fatal("Detected NULL grad_node," + paddle::platform::errors::Fatal("Detected nullptr grad_node," "Leaf tensor should have had grad_node " "with type: GradNodeAccumulation.")); PyObject* hook_func = PyTuple_GET_ITEM(args, 0); @@ -2171,11 +2171,12 @@ static PyObject* tensor__grad_name(TensorObject* self, PyObject* kwargs) { EAGER_TRY paddle::Tensor* grad = egr::EagerUtils::mutable_grad(self->tensor); - PADDLE_ENFORCE_EQ(grad != nullptr, - true, - platform::errors::InvalidArgument( - "Detected NULL grad. Please check if you have manually " - "cleared the grad inside autograd_meta")); + PADDLE_ENFORCE_EQ( + grad != nullptr, + true, + platform::errors::InvalidArgument( + "Detected nullptr grad. Please check if you have manually " + "cleared the grad inside autograd_meta")); return ToPyObject(grad->name()); EAGER_CATCH_AND_THROW_RETURN_NULL } @@ -2185,11 +2186,12 @@ static PyObject* tensor__grad_value(TensorObject* self, PyObject* kwargs) { EAGER_TRY paddle::Tensor* grad = egr::EagerUtils::mutable_grad(self->tensor); - PADDLE_ENFORCE_EQ(grad != nullptr, - true, - platform::errors::InvalidArgument( - "Detected NULL grad. Please check if you have manually " - "cleared the grad inside autograd_meta")); + PADDLE_ENFORCE_EQ( + grad != nullptr, + true, + platform::errors::InvalidArgument( + "Detected nullptr grad. Please check if you have manually " + "cleared the grad inside autograd_meta")); if (!grad->defined()) { RETURN_PY_NONE @@ -2210,11 +2212,12 @@ static PyObject* tensor__unset_fake_empty(TensorObject* self, PyObject* kwargs) { EAGER_TRY paddle::Tensor* grad = egr::EagerUtils::mutable_grad(self->tensor); - PADDLE_ENFORCE_EQ(grad != nullptr, - true, - platform::errors::InvalidArgument( - "Detected NULL grad. Please check if you have manually " - "cleared the grad inside autograd_meta")); + PADDLE_ENFORCE_EQ( + grad != nullptr, + true, + platform::errors::InvalidArgument( + "Detected nullptr grad. Please check if you have manually " + "cleared the grad inside autograd_meta")); bool is_leaf = egr::EagerUtils::IsLeafTensor(self->tensor); if (is_leaf) { @@ -2357,20 +2360,20 @@ PyMethodDef variable_methods[] = { {"_is_initialized", (PyCFunction)(void (*)())tensor_method__is_initialized, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_is_dense_tensor_hold_allocation", (PyCFunction)(void (*)( void))tensor_method__is_dense_tensor_hold_allocation, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_copy_to", (PyCFunction)(void (*)())tensor_method__copy_to, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"copy_", (PyCFunction)(void (*)())tensor_method_copy_, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"clone", (PyCFunction)(void (*)())tensor_method_clone, METH_VARARGS | METH_KEYWORDS, @@ -2378,11 +2381,11 @@ PyMethodDef variable_methods[] = { {"reconstruct_from_", (PyCFunction)(void (*)())tensor_method_reconstruct_from_, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"retain_grads", (PyCFunction)(void (*)())tensor_retain_grads, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"clear_gradient", (PyCFunction)(void (*)())tensor_clear_gradient, METH_VARARGS | METH_KEYWORDS, @@ -2390,31 +2393,31 @@ PyMethodDef variable_methods[] = { {"is_dense", (PyCFunction)(void (*)())tensor_method_is_dense, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"is_dist", (PyCFunction)(void (*)())tensor_method_is_dist, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_zero_grads", (PyCFunction)(void (*)())tensor__zero_grads, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_share_buffer_to", (PyCFunction)(void (*)())tensor__share_buffer_to, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_is_shared_buffer_with", (PyCFunction)(void (*)())tensor__is_shared_buffer_with, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_share_underline_tensor_to", (PyCFunction)(void (*)())tensor__share_underline_tensor_to, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_is_shared_underline_tensor_with", (PyCFunction)(void (*)())tensor__is_shared_underline_tensor_with, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"detach", (PyCFunction)(void (*)())tensor_method_detach, METH_VARARGS | METH_KEYWORDS, @@ -2422,39 +2425,39 @@ PyMethodDef variable_methods[] = { {"detach_", (PyCFunction)(void (*)(void))tensor_method_detach_, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"get_tensor", (PyCFunction)(void (*)())tensor_method_get_underline_tensor, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"get_selected_rows", (PyCFunction)(void (*)())tensor_method_get_underline_selected_rows, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_get_tensor_from_selected_rows", (PyCFunction)(void (*)())tensor_method__get_tensor_from_selected_rows, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_getitem_index_not_tensor", (PyCFunction)(void (*)())tensor__getitem_index_not_tensor, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_getitem_from_offset", (PyCFunction)(void (*)())tensor__getitem_from_offset, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"__setitem_eager_tensor__", (PyCFunction)(void (*)())tensor_method__setitem_eager_tensor, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_register_grad_hook", (PyCFunction)(void (*)())tensor_register_grad_hook, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_remove_grad_hook", (PyCFunction)(void (*)())tensor_remove_grad_hook, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_register_backward_hook", (PyCFunction)(void (*)())tensor_register_reduce_hook, METH_VARARGS | METH_KEYWORDS, @@ -2462,77 +2465,77 @@ PyMethodDef variable_methods[] = { {"_set_grad_type", (PyCFunction)(void (*)())tensor__set_grad_type, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_clear", (PyCFunction)(void (*)())tensor__clear, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_clear_dataptr", (PyCFunction)(void (*)())tensor__clear_dataptr, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_copy_gradient_from", (PyCFunction)(void (*)())tensor__copy_gradient_from, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_tensor_use_gpudnn", (PyCFunction)(void (*)())tensor__use_gpudnn, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, /** the methods to adapt old dygraph, will be removed in the future **/ {"set_string_list", (PyCFunction)(void (*)())tensor_method_set_string_list, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"set_vocab", (PyCFunction)(void (*)())tensor_method_set_vocab, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"get_map_tensor", (PyCFunction)(void (*)())tensor_method_get_map_tensor, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, /***the method of sparse tensor****/ {"nnz", (PyCFunction)(void (*)())tensor_method_get_non_zero_nums, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"indices", (PyCFunction)(void (*)())tensor_method_get_non_zero_indices, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"values", (PyCFunction)(void (*)())tensor_method_get_non_zero_elements, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"crows", (PyCFunction)(void (*)())tensor_method_get_non_zero_crows, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"cols", (PyCFunction)(void (*)())tensor_method_get_non_zero_cols, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"is_sparse", (PyCFunction)(void (*)())tensor_method_is_sparse, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"is_sparse_coo", (PyCFunction)(void (*)())tensor_method_is_sparse_coo, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"is_sparse_csr", (PyCFunction)(void (*)())tensor_method_is_sparse_csr, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"is_same_shape", (PyCFunction)(void (*)())tensor_method_is_same_shape, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"to_sparse_csr", (PyCFunction)(void (*)())tensor_method_to_sparse_csr, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"element_size", (PyCFunction)(void (*)())tensor_method_element_size, METH_VARARGS | METH_KEYWORDS, @@ -2541,7 +2544,7 @@ PyMethodDef variable_methods[] = { {"_inplace_version", (PyCFunction)(void (*)())tensor__inplace_version, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_bump_inplace_version", (PyCFunction)(void (*)())tensor__bump_inplace_version, METH_VARARGS | METH_KEYWORDS, @@ -2549,80 +2552,80 @@ PyMethodDef variable_methods[] = { {"is_selected_rows", (PyCFunction)(void (*)())tensor_method_is_selected_rows, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"rows", (PyCFunction)(void (*)())tensor_method_get_rows, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_reset_grad_inplace_version", (PyCFunction)(void (*)())tensor__reset_grad_inplace_version, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_share_memory", (PyCFunction)(void (*)())tensor_method__share_memory, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_offset", (PyCFunction)(void (*)())tensor__offset, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_grad_name", (PyCFunction)(void (*)())tensor__grad_name, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_grad_value", (PyCFunction)(void (*)())tensor__grad_value, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_unset_fake_empty", (PyCFunction)(void (*)())tensor__unset_fake_empty, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"data_ptr", (PyCFunction)(void (*)())tensor_data_ptr, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_grad_ivar", (PyCFunction)(void (*)())tensor__grad_ivar, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"contiguous", (PyCFunction)(void (*)(void))tensor_contiguous, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"is_contiguous", (PyCFunction)(void (*)(void))tensor_is_contiguous, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"get_strides", (PyCFunction)(void (*)(void))tensor_method_strides, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, #if defined(PADDLE_WITH_CUDA) {"_tensor_uva", (PyCFunction)(void (*)())tensor_method__uva, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, #endif - {NULL, NULL, 0, NULL}}; + {nullptr, nullptr, 0, nullptr}}; // variable_methods for core.eager.StringTensor PyMethodDef string_tensor_variable_methods[] = { {"numpy", (PyCFunction)(void (*)())tensor_method_numpy_for_string_tensor, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_is_initialized", (PyCFunction)(void (*)())tensor_method__is_initialized, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, {"_is_string_tensor_hold_allocation", (PyCFunction)(void (*)( void))tensor_method__is_string_tensor_hold_allocation, METH_VARARGS | METH_KEYWORDS, - NULL}, + nullptr}, // TODO(zhoushunjie): Need to add _copy_to, copy_ for StringTensor. - {NULL, NULL, 0, NULL}}; + {nullptr, nullptr, 0, nullptr}}; } // namespace pybind } // namespace paddle diff --git a/paddle/fluid/pybind/eager_py_layer.cc b/paddle/fluid/pybind/eager_py_layer.cc index 75174573cd77fea12449c914ba70e41b5919c3a6..6d5814bdaf8d2307dce4fd7ccb1db5983b71eff9 100644 --- a/paddle/fluid/pybind/eager_py_layer.cc +++ b/paddle/fluid/pybind/eager_py_layer.cc @@ -662,13 +662,15 @@ int tensor_properties_set_materialize_grads(PyLayerObject* self, EAGER_CATCH_AND_THROW_RETURN_NEG } -PyMethodDef pylayer_methods[] = { - {"name", (PyCFunction)(void (*)())pylayer_method_name, METH_NOARGS, NULL}, - {"apply", - (PyCFunction)(void (*)())pylayer_method_apply, - METH_CLASS | METH_VARARGS | METH_KEYWORDS, - NULL}, - {NULL, NULL, 0, NULL}}; +PyMethodDef pylayer_methods[] = {{"name", + (PyCFunction)(void (*)())pylayer_method_name, + METH_NOARGS, + nullptr}, + {"apply", + (PyCFunction)(void (*)())pylayer_method_apply, + METH_CLASS | METH_VARARGS | METH_KEYWORDS, + nullptr}, + {nullptr, nullptr, 0, nullptr}}; struct PyGetSetDef pylayer_properties[] { {"container", diff --git a/paddle/fluid/pybind/exception.cc b/paddle/fluid/pybind/exception.cc index 2fac903c8dff35a188d8466a5035346b56c46039..7c166021f7b00411701826184316595ff8811086 100644 --- a/paddle/fluid/pybind/exception.cc +++ b/paddle/fluid/pybind/exception.cc @@ -87,9 +87,9 @@ void BindException(pybind11::module* m) { void ThrowExceptionToPython(std::exception_ptr p) { static PyObject* EOFExceptionException = - PyErr_NewException("paddle.EOFException", PyExc_Exception, NULL); + PyErr_NewException("paddle.EOFException", PyExc_Exception, nullptr); static PyObject* EnforceNotMetException = - PyErr_NewException("paddle.EnforceNotMet", PyExc_Exception, NULL); + PyErr_NewException("paddle.EnforceNotMet", PyExc_Exception, nullptr); try { if (p) std::rethrow_exception(p); } catch (const platform::EOFException& e) { diff --git a/paddle/fluid/pybind/jit.cc b/paddle/fluid/pybind/jit.cc index 38c2ffe6f1fca672843ba0f539d42b869569bef4..5f4ed6fbec2f74b0a7674b9ac5b56fdb7070bd8f 100644 --- a/paddle/fluid/pybind/jit.cc +++ b/paddle/fluid/pybind/jit.cc @@ -120,7 +120,7 @@ static Py_tss_t eval_frame_callback_key = {0, 0}; inline static PyObject *eval_frame_callback_get() { void *result = PyThread_tss_get(&eval_frame_callback_key); - if (unlikely(result == NULL)) { + if (unlikely(result == nullptr)) { Py_RETURN_NONE; } else { return reinterpret_cast(result); @@ -136,7 +136,7 @@ inline static PyObject *eval_frame_default(PyThreadState *tstate, FrameObject *frame, int throw_flag) { #if PY_VERSION_HEX >= 0x03090000 - if (tstate == NULL) { + if (tstate == nullptr) { tstate = PyThreadState_GET(); } return _PyEval_EvalFrameDefault(tstate, frame, throw_flag); @@ -164,9 +164,9 @@ inline static PyObject *eval_custom_code(PyThreadState *tstate, nfrees = PyTuple_GET_SIZE(code->co_freevars); #endif - PyFrameObject *shadow = PyFrame_New(tstate, code, frame->f_globals, NULL); - if (shadow == NULL) { - return NULL; + PyFrameObject *shadow = PyFrame_New(tstate, code, frame->f_globals, nullptr); + if (shadow == nullptr) { + return nullptr; } #if PY_VERSION_HEX >= 0x030b0000 @@ -210,7 +210,7 @@ static PyObject *_custom_eval_frame(PyThreadState *tstate, #else if (PyFrame_FastToLocalsWithError(frame) < 0) { #endif - return NULL; + return nullptr; } // NOTE:(xiongkun): Handle GeneratorExit exception: (Spend a day) @@ -241,10 +241,10 @@ static PyObject *_custom_eval_frame(PyThreadState *tstate, Py_DECREF(args); VLOG(7) << "After call eval_frame_function and decrease frame."; // result: GuardedCode - if (result == NULL) { + if (result == nullptr) { // internal exception VLOG(7) << "Error happened."; - return NULL; + return nullptr; } else if (result != Py_None) { // NOTE: Cache is not supported now PyCodeObject *code = reinterpret_cast( @@ -354,7 +354,7 @@ PyMODINIT_FUNC PyInit__eval_frame() { Py_INCREF(Py_None); eval_frame_callback_set(Py_None); - return NULL; + return nullptr; } PyTypeObject *g_jit_function_pytype = nullptr; diff --git a/paddle/phi/kernels/cpu/eigvals_kernel.cc b/paddle/phi/kernels/cpu/eigvals_kernel.cc index 48da00b8a7006066067a37aaeef2ee43c6f8f13e..ec264f523b947b15a3c9b581c079c80225322dee 100644 --- a/paddle/phi/kernels/cpu/eigvals_kernel.cc +++ b/paddle/phi/kernels/cpu/eigvals_kernel.cc @@ -100,13 +100,13 @@ typename std::enable_if::value>::type LapackEigvals( a.template data(), static_cast(n_dim), w_data, - NULL, + nullptr, 1, - NULL, + nullptr, 1, work->template data(), static_cast(work_mem / sizeof(T)), - static_cast(NULL), + static_cast(nullptr), &info); std::string name = "phi::backend::dynload::dgeev_"; @@ -165,9 +165,9 @@ LapackEigvals(const Context& ctx, a.template data(), static_cast(n_dim), output->template data(), - NULL, + nullptr, 1, - NULL, + nullptr, 1, work->template data(), static_cast(work_mem / sizeof(T)), @@ -222,14 +222,14 @@ void EigvalsKernel(const Context& ctx, const DenseTensor& x, DenseTensor* out) { static_cast(n_dim), x_matrices[0].template data(), static_cast(n_dim), - NULL, - NULL, + nullptr, + nullptr, 1, - NULL, + nullptr, 1, &qwork, -1, - static_cast*>(NULL), + static_cast*>(nullptr), &info); int64_t lwork = static_cast(qwork); diff --git a/paddle/phi/kernels/funcs/fc_functor.cc b/paddle/phi/kernels/funcs/fc_functor.cc index 098502f1eb5b945207280985ffc0a01f47a23747..5344a23a64ed3c84ca452ce157f5e456d6e0a551 100644 --- a/paddle/phi/kernels/funcs/fc_functor.cc +++ b/paddle/phi/kernels/funcs/fc_functor.cc @@ -66,7 +66,7 @@ void FCFunctor::operator()(const DeviceContext& context, } else { blas.MatMul(M, N, K, X, W, Y); } - if (B == NULL) { + if (B == nullptr) { if (padding_weights) { #ifdef PADDLE_WITH_MKLML #pragma omp parallel for diff --git a/paddle/phi/kernels/funcs/gpc.cc b/paddle/phi/kernels/funcs/gpc.cc index cb9b3413af7c65d08a170090bfd7887803bff424..f7e852d53a7cfe09a59c84067fdc456540673c1e 100644 --- a/paddle/phi/kernels/funcs/gpc.cc +++ b/paddle/phi/kernels/funcs/gpc.cc @@ -107,7 +107,7 @@ static void reset_lmt(lmt_node **lmt) { } static void insert_bound(edge_node **b, edge_node *e) { - edge_node *existing_bound = NULL; + edge_node *existing_bound = nullptr; if (!*b) { /* Link node e to the tail of the list */ @@ -147,8 +147,8 @@ static edge_node **bound_list(lmt_node **lmt, double y) { gpc_malloc( *lmt, sizeof(lmt_node), const_cast("LMT insertion")); (*lmt)->y = y; - (*lmt)->first_bound = NULL; - (*lmt)->next = NULL; + (*lmt)->first_bound = nullptr; + (*lmt)->next = nullptr; return &((*lmt)->first_bound); } else if (y < (*lmt)->y) { /* Insert a new LMT node before the current node */ @@ -156,7 +156,7 @@ static edge_node **bound_list(lmt_node **lmt, double y) { gpc_malloc( *lmt, sizeof(lmt_node), const_cast("LMT insertion")); (*lmt)->y = y; - (*lmt)->first_bound = NULL; + (*lmt)->first_bound = nullptr; (*lmt)->next = existing_node; return &((*lmt)->first_bound); } else { @@ -177,8 +177,8 @@ static void add_to_sbtree(int *entries, sb_tree **sbtree, double y) { sizeof(sb_tree), const_cast("scanbeam tree insertion")); (*sbtree)->y = y; - (*sbtree)->less = NULL; - (*sbtree)->more = NULL; + (*sbtree)->less = nullptr; + (*sbtree)->more = nullptr; (*entries)++; } else { if ((*sbtree)->y > y) { @@ -243,8 +243,8 @@ static edge_node *build_lmt(lmt_node **lmt, int num_vertices = 0; int total_vertices = 0; int e_index = 0; - edge_node *e = NULL; - edge_node *edge_table = NULL; + edge_node *e = nullptr; + edge_node *edge_table = nullptr; for (c = 0; c < p->num_contours; c++) { total_vertices += count_optimal_vertices(p->contour[c]); @@ -305,14 +305,14 @@ static edge_node *build_lmt(lmt_node **lmt, e[i].dx = (edge_table[v].vertex.x - e[i].bot.x) / (e[i].top.y - e[i].bot.y); e[i].type = type; - e[i].outp[ABOVE] = NULL; - e[i].outp[BELOW] = NULL; - e[i].next = NULL; - e[i].prev = NULL; - e[i].succ = - ((num_edges > 1) && (i < (num_edges - 1))) ? &(e[i + 1]) : NULL; - e[i].pred = ((num_edges > 1) && (i > 0)) ? &(e[i - 1]) : NULL; - e[i].next_bound = NULL; + e[i].outp[ABOVE] = nullptr; + e[i].outp[BELOW] = nullptr; + e[i].next = nullptr; + e[i].prev = nullptr; + e[i].succ = ((num_edges > 1) && (i < (num_edges - 1))) ? &(e[i + 1]) + : nullptr; + e[i].pred = ((num_edges > 1) && (i > 0)) ? &(e[i - 1]) : nullptr; + e[i].next_bound = nullptr; e[i].bside[CLIP] = (op == GPC_DIFF) ? RIGHT : LEFT; e[i].bside[SUBJ] = LEFT; } @@ -351,14 +351,14 @@ static edge_node *build_lmt(lmt_node **lmt, e[i].dx = (edge_table[v].vertex.x - e[i].bot.x) / (e[i].top.y - e[i].bot.y); e[i].type = type; - e[i].outp[ABOVE] = NULL; - e[i].outp[BELOW] = NULL; - e[i].next = NULL; - e[i].prev = NULL; - e[i].succ = - ((num_edges > 1) && (i < (num_edges - 1))) ? &(e[i + 1]) : NULL; - e[i].pred = ((num_edges > 1) && (i > 0)) ? &(e[i - 1]) : NULL; - e[i].next_bound = NULL; + e[i].outp[ABOVE] = nullptr; + e[i].outp[BELOW] = nullptr; + e[i].next = nullptr; + e[i].prev = nullptr; + e[i].succ = ((num_edges > 1) && (i < (num_edges - 1))) ? &(e[i + 1]) + : nullptr; + e[i].pred = ((num_edges > 1) && (i > 0)) ? &(e[i - 1]) : nullptr; + e[i].next_bound = nullptr; e[i].bside[CLIP] = (op == GPC_DIFF) ? RIGHT : LEFT; e[i].bside[SUBJ] = LEFT; } @@ -375,7 +375,7 @@ static void add_edge_to_aet(edge_node **aet, edge_node *edge, edge_node *prev) { /* Append edge onto the tail end of the AET */ *aet = edge; edge->prev = prev; - edge->next = NULL; + edge->next = nullptr; } else { /* Do primary sort on the xb field */ if (edge->xb < (*aet)->xb) { @@ -417,7 +417,7 @@ static void add_intersection( (*it)->ie[1] = edge1; (*it)->point.x = x; (*it)->point.y = y; - (*it)->next = NULL; + (*it)->next = nullptr; } else { if ((*it)->point.y > y) { /* Insert a new node mid-list */ @@ -454,7 +454,7 @@ static void add_st_edge(st_node **st, (*st)->xb = edge->xb; (*st)->xt = edge->xt; (*st)->dx = edge->dx; - (*st)->prev = NULL; + (*st)->prev = nullptr; } else { den = ((*st)->xt - (*st)->xb) - (edge->xt - edge->xb); @@ -488,11 +488,11 @@ static void add_st_edge(st_node **st, static void build_intersection_table(it_node **it, edge_node *aet, double dy) { st_node *st; st_node *stp; - edge_node *edge = NULL; + edge_node *edge = nullptr; /* Build intersection table for the current scanbeam */ reset_it(it); - st = NULL; + st = nullptr; /* Process each AET edge */ for (edge = aet; edge; edge = edge->next) { @@ -513,8 +513,8 @@ static void build_intersection_table(it_node **it, edge_node *aet, double dy) { static int count_contours(polygon_node *polygon) { int nc = 0; int nv = 0; - vertex_node *v = NULL; - vertex_node *nextv = NULL; + vertex_node *v = nullptr; + vertex_node *nextv = nullptr; for (nc = 0; polygon; polygon = polygon->next) { if (polygon->active) { @@ -544,7 +544,7 @@ static int count_contours(polygon_node *polygon) { static void add_left(polygon_node *p, double x, double y) { PADDLE_ENFORCE_NOT_NULL( p, phi::errors::InvalidArgument("Input polygon node is nullptr.")); - vertex_node *nv = NULL; + vertex_node *nv = nullptr; /* Create a new vertex node and set its fields */ gpc_malloc( @@ -560,7 +560,7 @@ static void add_left(polygon_node *p, double x, double y) { } static void merge_left(polygon_node *p, polygon_node *q, polygon_node *list) { - polygon_node *target = NULL; + polygon_node *target = nullptr; /* Label contour as a hole */ q->proxy->hole = 1; @@ -582,14 +582,14 @@ static void merge_left(polygon_node *p, polygon_node *q, polygon_node *list) { } static void add_right(polygon_node *p, double x, double y) { - vertex_node *nv = NULL; + vertex_node *nv = nullptr; /* Create a new vertex node and set its fields */ gpc_malloc( nv, sizeof(vertex_node), const_cast("vertex node creation")); nv->x = x; nv->y = y; - nv->next = NULL; + nv->next = nullptr; /* Add vertex nv to the right end of the polygon's vertex list */ p->proxy->v[RIGHT]->next = nv; @@ -601,7 +601,7 @@ static void add_right(polygon_node *p, double x, double y) { static void merge_right(polygon_node *p, polygon_node *q, polygon_node *list) { PADDLE_ENFORCE_NOT_NULL( p, phi::errors::InvalidArgument("Input polygon node is nullptr.")); - polygon_node *target = NULL; + polygon_node *target = nullptr; /* Label contour as external */ q->proxy->hole = 0; @@ -625,8 +625,8 @@ static void add_local_min(polygon_node **p, edge_node *edge, double x, double y) { - polygon_node *existing_min = NULL; - vertex_node *nv = NULL; + polygon_node *existing_min = nullptr; + vertex_node *nv = nullptr; existing_min = *p; @@ -638,7 +638,7 @@ static void add_local_min(polygon_node **p, nv, sizeof(vertex_node), const_cast("vertex node creation")); nv->x = x; nv->y = y; - nv->next = NULL; + nv->next = nullptr; /* Initialise proxy to point to p itself */ (*p)->proxy = (*p); @@ -671,7 +671,7 @@ void add_vertex(vertex_node **t, double x, double y) { const_cast("tristrip vertex creation")); (*t)->x = x; (*t)->y = y; - (*t)->next = NULL; + (*t)->next = nullptr; } else { /* Head further down the list */ add_vertex(&((*t)->next), x, y); @@ -693,9 +693,9 @@ static void new_tristrip(polygon_node **tn, gpc_malloc(*tn, sizeof(polygon_node), const_cast("tristrip node creation")); - (*tn)->next = NULL; - (*tn)->v[LEFT] = NULL; - (*tn)->v[RIGHT] = NULL; + (*tn)->next = nullptr; + (*tn)->v[LEFT] = nullptr; + (*tn)->v[RIGHT] = nullptr; (*tn)->active = 1; add_vertex(&((*tn)->v[LEFT]), x, y); edge->outp[ABOVE] = *tn; @@ -748,7 +748,7 @@ static void minimax_test(gpc_polygon *subj, gpc_polygon *clip, gpc_op op) { bbox *c_bbox; int s = 0; int c = 0; - int *o_table = NULL; + int *o_table = nullptr; int overlap = 0; s_bbox = create_contour_bboxes(subj); @@ -870,10 +870,10 @@ void gpc_write_polygon(FILE *fp, int write_hole_flags, gpc_polygon *p) { */ void gpc_add_contour(gpc_polygon *p, gpc_vertex_list *new_contour, int hole) { - int *extended_hole = NULL; + int *extended_hole = nullptr; int c = 0; int v = 0; - gpc_vertex_list *extended_contour = NULL; + gpc_vertex_list *extended_contour = nullptr; /* Create an extended hole array */ gpc_malloc(extended_hole, @@ -920,28 +920,28 @@ void gpc_polygon_clip(gpc_op op, gpc_polygon *subj, gpc_polygon *clip, gpc_polygon *result) { - sb_tree *sbtree = NULL; - it_node *it = NULL; - it_node *intersect = NULL; - edge_node *edge = NULL; - edge_node *prev_edge = NULL; - edge_node *next_edge = NULL; - edge_node *succ_edge = NULL; - edge_node *e0 = NULL; - edge_node *e1 = NULL; - edge_node *aet = NULL; - edge_node *c_heap = NULL; - edge_node *s_heap = NULL; - lmt_node *lmt = NULL; - lmt_node *local_min = NULL; - polygon_node *out_poly = NULL; - polygon_node *p = NULL; - polygon_node *q = NULL; - polygon_node *poly = NULL; - polygon_node *npoly = NULL; - polygon_node *cf = NULL; - vertex_node *vtx = NULL; - vertex_node *nv = NULL; + sb_tree *sbtree = nullptr; + it_node *it = nullptr; + it_node *intersect = nullptr; + edge_node *edge = nullptr; + edge_node *prev_edge = nullptr; + edge_node *next_edge = nullptr; + edge_node *succ_edge = nullptr; + edge_node *e0 = nullptr; + edge_node *e1 = nullptr; + edge_node *aet = nullptr; + edge_node *c_heap = nullptr; + edge_node *s_heap = nullptr; + lmt_node *lmt = nullptr; + lmt_node *local_min = nullptr; + polygon_node *out_poly = nullptr; + polygon_node *p = nullptr; + polygon_node *q = nullptr; + polygon_node *poly = nullptr; + polygon_node *npoly = nullptr; + polygon_node *cf = nullptr; + vertex_node *vtx = nullptr; + vertex_node *nv = nullptr; std::array horiz; std::array in; std::array exists; @@ -957,7 +957,7 @@ void gpc_polygon_clip(gpc_op op, int br = 0; int tl = 0; int tr = 0; - double *sbt = NULL; + double *sbt = nullptr; double xb = 0.0; double px = 0.0; double yb = 0.0; @@ -971,8 +971,8 @@ void gpc_polygon_clip(gpc_op op, ((subj->num_contours == 0) && ((op == GPC_INT) || (op == GPC_DIFF))) || ((clip->num_contours == 0) && (op == GPC_INT))) { result->num_contours = 0; - result->hole = NULL; - result->contour = NULL; + result->hole = nullptr; + result->contour = nullptr; return; } /* Identify potentialy contributing contours */ @@ -988,10 +988,10 @@ void gpc_polygon_clip(gpc_op op, c_heap = build_lmt(&lmt, &sbtree, &sbt_entries, clip, CLIP, op); } /* Return a NULL result if no contours contribute */ - if (lmt == NULL) { + if (lmt == nullptr) { result->num_contours = 0; - result->hole = NULL; - result->contour = NULL; + result->hole = nullptr; + result->contour = nullptr; reset_lmt(&lmt); gpc_free(s_heap); gpc_free(c_heap); @@ -1035,7 +1035,7 @@ void gpc_polygon_clip(gpc_op op, if (local_min->y == yb) { /* Add edges starting at this local minimum to the AET */ for (edge = local_min->first_bound; edge; edge = edge->next_bound) { - add_edge_to_aet(&aet, edge, NULL); + add_edge_to_aet(&aet, edge, nullptr); } local_min = local_min->next; } @@ -1161,7 +1161,7 @@ void gpc_polygon_clip(gpc_op op, px = xb; } edge->outp[ABOVE] = cf; - cf = NULL; + cf = nullptr; break; case ELI: add_left(edge->outp[BELOW], xb, yb); @@ -1174,7 +1174,7 @@ void gpc_polygon_clip(gpc_op op, px = xb; } merge_right(cf, edge->outp[BELOW], out_poly); - cf = NULL; + cf = nullptr; break; case ILI: if (xb != px) { @@ -1182,13 +1182,13 @@ void gpc_polygon_clip(gpc_op op, px = xb; } edge->outp[ABOVE] = cf; - cf = NULL; + cf = nullptr; break; case IRI: add_right(edge->outp[BELOW], xb, yb); px = xb; cf = edge->outp[BELOW]; - edge->outp[BELOW] = NULL; + edge->outp[BELOW] = nullptr; break; case IMX: if (xb != px) { @@ -1196,8 +1196,8 @@ void gpc_polygon_clip(gpc_op op, px = xb; } merge_left(cf, edge->outp[BELOW], out_poly); - cf = NULL; - edge->outp[BELOW] = NULL; + cf = nullptr; + edge->outp[BELOW] = nullptr; break; case IMM: if (xb != px) { @@ -1205,7 +1205,7 @@ void gpc_polygon_clip(gpc_op op, px = xb; } merge_left(cf, edge->outp[BELOW], out_poly); - edge->outp[BELOW] = NULL; + edge->outp[BELOW] = nullptr; add_local_min(&out_poly, edge, xb, yb); cf = edge->outp[ABOVE]; break; @@ -1215,7 +1215,7 @@ void gpc_polygon_clip(gpc_op op, px = xb; } merge_right(cf, edge->outp[BELOW], out_poly); - edge->outp[BELOW] = NULL; + edge->outp[BELOW] = nullptr; add_local_min(&out_poly, edge, xb, yb); cf = edge->outp[ABOVE]; break; @@ -1345,22 +1345,22 @@ void gpc_polygon_clip(gpc_op op, if (p) { add_right(p, ix, iy); e1->outp[ABOVE] = p; - e0->outp[ABOVE] = NULL; + e0->outp[ABOVE] = nullptr; } break; case ELI: if (q) { add_left(q, ix, iy); e0->outp[ABOVE] = q; - e1->outp[ABOVE] = NULL; + e1->outp[ABOVE] = nullptr; } break; case EMX: if (p && q) { add_left(p, ix, iy); merge_right(p, q, out_poly); - e0->outp[ABOVE] = NULL; - e1->outp[ABOVE] = NULL; + e0->outp[ABOVE] = nullptr; + e1->outp[ABOVE] = nullptr; } break; case IMN: @@ -1371,22 +1371,22 @@ void gpc_polygon_clip(gpc_op op, if (p) { add_left(p, ix, iy); e1->outp[ABOVE] = p; - e0->outp[ABOVE] = NULL; + e0->outp[ABOVE] = nullptr; } break; case IRI: if (q) { add_right(q, ix, iy); e0->outp[ABOVE] = q; - e1->outp[ABOVE] = NULL; + e1->outp[ABOVE] = nullptr; } break; case IMX: if (p && q) { add_right(p, ix, iy); merge_left(p, q, out_poly); - e0->outp[ABOVE] = NULL; - e1->outp[ABOVE] = NULL; + e0->outp[ABOVE] = nullptr; + e1->outp[ABOVE] = nullptr; } break; case IMM: @@ -1486,13 +1486,13 @@ void gpc_polygon_clip(gpc_op op, edge->bundle[BELOW][SUBJ] = edge->bundle[ABOVE][SUBJ]; edge->xb = edge->xt; } - edge->outp[ABOVE] = NULL; + edge->outp[ABOVE] = nullptr; } } } /* === END OF SCANBEAM PROCESSING ================================== */ // Generate result polygon from out_poly - result->contour = NULL; - result->hole = NULL; + result->contour = nullptr; + result->hole = nullptr; result->num_contours = count_contours(out_poly); if (result->num_contours > 0) { gpc_malloc(result->hole, @@ -1552,8 +1552,8 @@ void gpc_free_tristrip(gpc_tristrip *t) { void gpc_polygon_to_tristrip(gpc_polygon *s, gpc_tristrip *t) { gpc_polygon c; c.num_contours = 0; - c.hole = NULL; - c.contour = NULL; + c.hole = nullptr; + c.contour = nullptr; gpc_tristrip_clip(GPC_DIFF, s, &c, t); } @@ -1562,30 +1562,30 @@ void gpc_tristrip_clip(gpc_op op, gpc_polygon *subj, gpc_polygon *clip, gpc_tristrip *result) { - sb_tree *sbtree = NULL; - it_node *it = NULL; - it_node *intersect = NULL; - edge_node *edge = NULL; - edge_node *prev_edge = NULL; - edge_node *next_edge = NULL; - edge_node *succ_edge = NULL; - edge_node *e0 = NULL; - edge_node *e1 = NULL; - edge_node *aet = NULL; - edge_node *c_heap = NULL; - edge_node *s_heap = NULL; - edge_node *cf = NULL; - lmt_node *lmt = NULL; - lmt_node *local_min = NULL; - polygon_node *tlist = NULL; - polygon_node *tn = NULL; - polygon_node *tnn = NULL; - polygon_node *p = NULL; - polygon_node *q = NULL; - vertex_node *lt = NULL; - vertex_node *ltn = NULL; - vertex_node *rt = NULL; - vertex_node *rtn = NULL; + sb_tree *sbtree = nullptr; + it_node *it = nullptr; + it_node *intersect = nullptr; + edge_node *edge = nullptr; + edge_node *prev_edge = nullptr; + edge_node *next_edge = nullptr; + edge_node *succ_edge = nullptr; + edge_node *e0 = nullptr; + edge_node *e1 = nullptr; + edge_node *aet = nullptr; + edge_node *c_heap = nullptr; + edge_node *s_heap = nullptr; + edge_node *cf = nullptr; + lmt_node *lmt = nullptr; + lmt_node *local_min = nullptr; + polygon_node *tlist = nullptr; + polygon_node *tn = nullptr; + polygon_node *tnn = nullptr; + polygon_node *p = nullptr; + polygon_node *q = nullptr; + vertex_node *lt = nullptr; + vertex_node *ltn = nullptr; + vertex_node *rt = nullptr; + vertex_node *rtn = nullptr; std::array horiz; vertex_type cft = NUL; std::array in; @@ -1602,7 +1602,7 @@ void gpc_tristrip_clip(gpc_op op, int br = 0; int tl = 0; int tr = 0; - double *sbt = NULL; + double *sbt = nullptr; double xb = 0.0; double px = 0.0; double nx = 0.0; @@ -1617,7 +1617,7 @@ void gpc_tristrip_clip(gpc_op op, ((subj->num_contours == 0) && ((op == GPC_INT) || (op == GPC_DIFF))) || ((clip->num_contours == 0) && (op == GPC_INT))) { result->num_strips = 0; - result->strip = NULL; + result->strip = nullptr; return; } @@ -1634,9 +1634,9 @@ void gpc_tristrip_clip(gpc_op op, c_heap = build_lmt(&lmt, &sbtree, &sbt_entries, clip, CLIP, op); } /* Return a NULL result if no contours contribute */ - if (lmt == NULL) { + if (lmt == nullptr) { result->num_strips = 0; - result->strip = NULL; + result->strip = nullptr; reset_lmt(&lmt); gpc_free(s_heap); gpc_free(c_heap); @@ -1674,7 +1674,7 @@ void gpc_tristrip_clip(gpc_op op, if (local_min->y == yb) { /* Add edges starting at this local minimum to the AET */ for (edge = local_min->first_bound; edge; edge = edge->next_bound) { - add_edge_to_aet(&aet, edge, NULL); + add_edge_to_aet(&aet, edge, nullptr); } local_min = local_min->next; } @@ -1803,19 +1803,19 @@ void gpc_tristrip_clip(gpc_op op, if (xb != cf->xb) { gpc_vertex_create(edge, ABOVE, RIGHT, xb, yb); } - cf = NULL; + cf = nullptr; break; case ELI: gpc_vertex_create(edge, BELOW, LEFT, xb, yb); - edge->outp[ABOVE] = NULL; + edge->outp[ABOVE] = nullptr; cf = edge; break; case EMX: if (xb != cf->xb) { gpc_vertex_create(edge, BELOW, RIGHT, xb, yb); } - edge->outp[ABOVE] = NULL; - cf = NULL; + edge->outp[ABOVE] = nullptr; + cf = nullptr; break; case IMN: if (cft == LED) { @@ -1840,11 +1840,11 @@ void gpc_tristrip_clip(gpc_op op, new_tristrip(&tlist, cf, cf->xb, yb); } gpc_vertex_create(edge, BELOW, RIGHT, xb, yb); - edge->outp[ABOVE] = NULL; + edge->outp[ABOVE] = nullptr; break; case IMX: gpc_vertex_create(edge, BELOW, LEFT, xb, yb); - edge->outp[ABOVE] = NULL; + edge->outp[ABOVE] = nullptr; cft = IMX; break; case IMM: @@ -1857,7 +1857,7 @@ void gpc_tristrip_clip(gpc_op op, break; case EMM: gpc_vertex_create(edge, BELOW, RIGHT, xb, yb); - edge->outp[ABOVE] = NULL; + edge->outp[ABOVE] = nullptr; new_tristrip(&tlist, edge, xb, yb); cf = edge; break; @@ -1884,7 +1884,7 @@ void gpc_tristrip_clip(gpc_op op, gpc_vertex_create(edge, BELOW, RIGHT, xb, yb); gpc_vertex_create(edge, ABOVE, RIGHT, xb, yb); } - cf = NULL; + cf = nullptr; break; default: break; @@ -2002,7 +2002,7 @@ void gpc_tristrip_clip(gpc_op op, gpc_vertex_create(prev_edge, ABOVE, LEFT, px, iy); gpc_vertex_create(e0, ABOVE, RIGHT, ix, iy); e1->outp[ABOVE] = e0->outp[ABOVE]; - e0->outp[ABOVE] = NULL; + e0->outp[ABOVE] = nullptr; } break; case ELI: @@ -2011,14 +2011,14 @@ void gpc_tristrip_clip(gpc_op op, gpc_vertex_create(e1, ABOVE, LEFT, ix, iy); gpc_vertex_create(next_edge, ABOVE, RIGHT, nx, iy); e0->outp[ABOVE] = e1->outp[ABOVE]; - e1->outp[ABOVE] = NULL; + e1->outp[ABOVE] = nullptr; } break; case EMX: if (p && q) { gpc_vertex_create(e0, ABOVE, LEFT, ix, iy); - e0->outp[ABOVE] = NULL; - e1->outp[ABOVE] = NULL; + e0->outp[ABOVE] = nullptr; + e1->outp[ABOVE] = nullptr; } break; case IMN: @@ -2039,7 +2039,7 @@ void gpc_tristrip_clip(gpc_op op, gpc_n_edge(next_edge, e1, ABOVE); gpc_vertex_create(next_edge, ABOVE, RIGHT, nx, iy); e1->outp[ABOVE] = e0->outp[ABOVE]; - e0->outp[ABOVE] = NULL; + e0->outp[ABOVE] = nullptr; } break; case IRI: @@ -2048,15 +2048,15 @@ void gpc_tristrip_clip(gpc_op op, gpc_p_edge(prev_edge, e0, ABOVE); gpc_vertex_create(prev_edge, ABOVE, LEFT, px, iy); e0->outp[ABOVE] = e1->outp[ABOVE]; - e1->outp[ABOVE] = NULL; + e1->outp[ABOVE] = nullptr; } break; case IMX: if (p && q) { gpc_vertex_create(e0, ABOVE, RIGHT, ix, iy); gpc_vertex_create(e1, ABOVE, LEFT, ix, iy); - e0->outp[ABOVE] = NULL; - e1->outp[ABOVE] = NULL; + e0->outp[ABOVE] = nullptr; + e1->outp[ABOVE] = nullptr; gpc_p_edge(prev_edge, e0, ABOVE); gpc_vertex_create(prev_edge, ABOVE, LEFT, px, iy); new_tristrip(&tlist, prev_edge, px, iy); @@ -2172,13 +2172,13 @@ void gpc_tristrip_clip(gpc_op op, edge->bundle[BELOW][SUBJ] = edge->bundle[ABOVE][SUBJ]; edge->xb = edge->xt; } - edge->outp[ABOVE] = NULL; + edge->outp[ABOVE] = nullptr; } } } /* === END OF SCANBEAM PROCESSING ================================== */ // Generate result tristrip from tlist - result->strip = NULL; + result->strip = nullptr; result->num_strips = count_tristrips(tlist); if (result->num_strips > 0) { gpc_malloc(result->strip, diff --git a/paddle/phi/kernels/funcs/jit/gen/sgd.cc b/paddle/phi/kernels/funcs/jit/gen/sgd.cc index 839f0288c9e940410ab61547695e3c64c10e17d4..c09f934ae5b7ddd65d01d1f319b685d77a552df1 100644 --- a/paddle/phi/kernels/funcs/jit/gen/sgd.cc +++ b/paddle/phi/kernels/funcs/jit/gen/sgd.cc @@ -83,7 +83,7 @@ void SgdJitCode::genCode() { Label inner_loop; Label escape_loop; - mov(rax, 0); + mov(rax, 0); // NOLINT L(inner_loop); { cmp(rax, num_groups); diff --git a/paddle/phi/kernels/onednn/matmul_kernel.cc b/paddle/phi/kernels/onednn/matmul_kernel.cc index a87b74b0f9c502961e4e05f679544f2676984124..3b5529783fd92ae2036456e1858dd168298639c6 100644 --- a/paddle/phi/kernels/onednn/matmul_kernel.cc +++ b/paddle/phi/kernels/onednn/matmul_kernel.cc @@ -407,7 +407,7 @@ class MulPrimitiveFactory { memory Reorder(const memory::desc &src_desc, const memory::desc &dst_desc, void *src_data, - void *dst_data = NULL) { + void *dst_data = nullptr) { auto src_mem = memory(src_desc, engine_, src_data); auto dst_mem = dst_data ? memory(dst_desc, engine_, dst_data) : memory(dst_desc, engine_); diff --git a/paddle/utils/string/string_helper.cc b/paddle/utils/string/string_helper.cc index 2b694de4b5834132b6c3137e54a2a4bcdce26237..c94e6993c3a6895b7e4dc1ec92c2a93aee4c7fe7 100644 --- a/paddle/utils/string/string_helper.cc +++ b/paddle/utils/string/string_helper.cc @@ -77,7 +77,7 @@ char* LineFileReader::getdelim(FILE* f, char delim) { int code = feof(f); (void)code; assert(code); - return NULL; + return nullptr; } #else return NULL; diff --git a/test/cpp/fluid/gather_test.cc b/test/cpp/fluid/gather_test.cc index ff48ab776a856ff5e835b3adcdd5a420289b5a5f..9a09d747a5565863626d5c370a5b1109c074fc2f 100644 --- a/test/cpp/fluid/gather_test.cc +++ b/test/cpp/fluid/gather_test.cc @@ -42,7 +42,7 @@ TEST(Gather, GatherData) { phi::CPUContext ctx(*cpu_place); phi::funcs::CPUGather(ctx, *src, *index, output); delete cpu_place; - cpu_place = NULL; + cpu_place = nullptr; for (int i = 0; i < 4; ++i) EXPECT_EQ(p_output[i], i + 4); for (int i = 4; i < 8; ++i) EXPECT_EQ(p_output[i], i - 4); diff --git a/test/cpp/fluid/math/im2col_test.cc b/test/cpp/fluid/math/im2col_test.cc index 1fa0cb1aeb1616d59a27c4a308acab7c043c58e6..e89d60090746d06685acaf27c6f19fa4dda8a7a1 100644 --- a/test/cpp/fluid/math/im2col_test.cc +++ b/test/cpp/fluid/math/im2col_test.cc @@ -362,7 +362,7 @@ void benchIm2col(int ic, int ih, int iw, int fh, int fw, int ph, int pw) { constexpr int repeat = 100; auto GetCurrentMs = []() -> double { struct timeval time; - gettimeofday(&time, NULL); + gettimeofday(&time, nullptr); return 1e+3 * time.tv_sec + 1e-3 * time.tv_usec; }; auto t1 = GetCurrentMs(); diff --git a/test/cpp/imperative/test_layer.cc b/test/cpp/imperative/test_layer.cc index 5a0edbce6d55eb2e0bb6ebc280de68c56f42751f..da24d2b252ef5cdbfd408cc7f1cef2dfc17f4f15 100644 --- a/test/cpp/imperative/test_layer.cc +++ b/test/cpp/imperative/test_layer.cc @@ -328,9 +328,9 @@ TEST(test_layer, test_varbase_basic) { new imperative::VarBase(true, "vin")); ASSERT_ANY_THROW(vin->MutableGradVar()); ASSERT_NO_THROW(ASSERT_TRUE(dynamic_cast( - vin_with_grad->MutableGradVar()) != 0)); - ASSERT_TRUE( - dynamic_cast(vin_with_grad->MutableGradVar()) != 0); + vin_with_grad->MutableGradVar()) != nullptr)); + ASSERT_TRUE(dynamic_cast( + vin_with_grad->MutableGradVar()) != nullptr); vin_with_grad->SetOverridedStopGradient(false); ASSERT_FALSE(vin_with_grad->OverridedStopGradient()); ASSERT_NO_FATAL_FAILURE(vin_with_grad->SetPersistable(true)); diff --git a/test/cpp/phi/kernels/test_cpu_vec.cc b/test/cpp/phi/kernels/test_cpu_vec.cc index 3cb925e8ef4375660fe74d423297566d69149efd..f9d07f1ca293329269e409a8087684ef1eea57ef 100644 --- a/test/cpp/phi/kernels/test_cpu_vec.cc +++ b/test/cpp/phi/kernels/test_cpu_vec.cc @@ -25,7 +25,7 @@ namespace tests { inline double GetCurrentUS() { struct timeval time; - gettimeofday(&time, NULL); + gettimeofday(&time, nullptr); return 1e+6 * time.tv_sec + time.tv_usec; } constexpr int repeat = 1000;