Skip to content

Commit

Permalink
change NULL to nullptr (OpenAtomFoundation#1408)
Browse files Browse the repository at this point in the history
* NULL --> nullptr

* NULL --> nullptr

* recover nullptr in comment
  • Loading branch information
AlexStocks authored Apr 29, 2023
1 parent 9905576 commit 6012793
Show file tree
Hide file tree
Showing 69 changed files with 315 additions and 315 deletions.
4 changes: 2 additions & 2 deletions include/pika_binlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Version {
}

private:
pstd::RWFile* save_ = NULL;
pstd::RWFile* save_ = nullptr;

// No copying allowed;
Version(const Version&);
Expand All @@ -59,7 +59,7 @@ class Binlog {

Status Put(const std::string& item);

Status GetProducerStatus(uint32_t* filenum, uint64_t* pro_offset, uint32_t* term = NULL, uint64_t* logic_id = NULL);
Status GetProducerStatus(uint32_t* filenum, uint64_t* pro_offset, uint32_t* term = nullptr, uint64_t* logic_id = nullptr);
/*
* Set Producer pro_num and pro_offset with lock
*/
Expand Down
2 changes: 1 addition & 1 deletion include/pika_geohash.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extern "C" {

#define HASHISZERO(r) (!(r).bits && !(r).step)
#define RANGEISZERO(r) (!(r).max && !(r).min)
#define RANGEPISZERO(r) (r == NULL || RANGEISZERO(*r))
#define RANGEPISZERO(r) (r == nullptr || RANGEISZERO(*r))

#define GEO_STEP_MAX 26 /* 26*2 = 52 bits. */

Expand Down
2 changes: 1 addition & 1 deletion include/pika_monitor_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class PikaMonitorThread : public net::Thread {

void AddMonitorClient(std::shared_ptr<PikaClientConn> client_ptr);
void AddMonitorMessage(const std::string& monitor_message);
int32_t ThreadClientList(std::vector<ClientInfo>* client = NULL);
int32_t ThreadClientList(std::vector<ClientInfo>* client = nullptr);
bool ThreadClientKill(const std::string& ip_port = "all");
bool HasMonitorClients();

Expand Down
10 changes: 5 additions & 5 deletions src/net/examples/bg_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ int main() {

std::cout << "TimerItem Struct... " << std::endl;
std::priority_queue<TimerItem> pq;
pq.push(TimerItem(1, task, NULL));
pq.push(TimerItem(5, task, NULL));
pq.push(TimerItem(3, task, NULL));
pq.push(TimerItem(2, task, NULL));
pq.push(TimerItem(4, task, NULL));
pq.push(TimerItem(1, task, nullptr));
pq.push(TimerItem(5, task, nullptr));
pq.push(TimerItem(3, task, nullptr));
pq.push(TimerItem(2, task, nullptr));
pq.push(TimerItem(4, task, nullptr));

while (!pq.empty()) {
printf("%ld\n", pq.top().exec_time);
Expand Down
2 changes: 1 addition & 1 deletion src/net/examples/myredis_cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ int main(int argc, char* argv[]) {
ConnFactory* conn_factory = new MyConnFactory();
ClientHandle* handle = new ClientHandle();

client = new ClientThread(conn_factory, 3000, 60, handle, NULL);
client = new ClientThread(conn_factory, 3000, 60, handle, nullptr);

if (client->StartThread() != 0) {
printf("StartThread error happened!\n");
Expand Down
2 changes: 1 addition & 1 deletion src/net/examples/myredis_srv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ int main(int argc, char* argv[]) {

ConnFactory* conn_factory = new MyConnFactory();

ServerThread* my_thread = new HolyThread(my_port, conn_factory, 1000, NULL, false);
ServerThread* my_thread = new HolyThread(my_port, conn_factory, 1000, nullptr, false);
if (my_thread->StartThread() != 0) {
printf("StartThread error happened!\n");
exit(-1);
Expand Down
4 changes: 2 additions & 2 deletions src/net/examples/performance/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ using namespace std;

uint64_t NowMicros() {
struct timeval tv;
gettimeofday(&tv, NULL);
gettimeofday(&tv, nullptr);
return static_cast<uint64_t>(tv.tv_sec) * 1000000 + tv.tv_usec;
}

static atomic<int> num(0);

class PingConn : public PbConn {
public:
PingConn(int fd, std::string ip_port, net::ServerThread* pself_thread = NULL) : PbConn(fd, ip_port, pself_thread) {}
PingConn(int fd, std::string ip_port, net::ServerThread* pself_thread = nullptr) : PbConn(fd, ip_port, pself_thread) {}
virtual ~PingConn() {}

int DealMessage() {
Expand Down
2 changes: 1 addition & 1 deletion src/net/examples/thread_pool_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ using namespace std;

uint64_t NowMicros() {
struct timeval tv;
gettimeofday(&tv, NULL);
gettimeofday(&tv, nullptr);
return static_cast<uint64_t>(tv.tv_sec) * 1000000 + tv.tv_usec;
}

Expand Down
2 changes: 1 addition & 1 deletion src/net/include/net_cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class NetCli {
virtual Status Send(void* msg) = 0;

// Read, parse and store the reply
virtual Status Recv(void* result = NULL) = 0;
virtual Status Recv(void* result = nullptr) = 0;

void Close();

Expand Down
18 changes: 9 additions & 9 deletions src/net/include/redis_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ struct RedisParserSettings {
RedisParserDataCb DealMessage;
RedisParserMultiDataCb Complete;
RedisParserSettings() {
DealMessage = NULL;
Complete = NULL;
DealMessage = nullptr;
Complete = nullptr;
}
};

Expand All @@ -56,7 +56,7 @@ class RedisParser {
RedisParserStatus ProcessInputBuffer(const char* input_buf, int length, int* parsed_len);
long get_bulk_len() { return bulk_len_; }
RedisParserError get_error_code() { return error_code_; }
void* data; /* A pointer to get hook to the "connection" or "socket" object */
void* data = nullptr; /* A pointer to get hook to the "connection" or "socket" object */
private:
// for DEBUG
void PrintCurrentStatus();
Expand All @@ -76,21 +76,21 @@ class RedisParser {
RedisParserStatus status_code_;
RedisParserError error_code_;

int redis_type_; // REDIS_REQ_INLINE or REDIS_REQ_MULTIBULK
int redis_type_ = -1; // REDIS_REQ_INLINE or REDIS_REQ_MULTIBULK

long multibulk_len_;
long bulk_len_;
long multibulk_len_ = 0;
long bulk_len_ = 0;
std::string half_argv_;

int redis_parser_type_; // REDIS_PARSER_REQUEST or REDIS_PARSER_RESPONSE
int redis_parser_type_ = -1; // REDIS_PARSER_REQUEST or REDIS_PARSER_RESPONSE

RedisCmdArgsType argv_;
std::vector<RedisCmdArgsType> argvs_;

int cur_pos_;
int cur_pos_ = 0;
const char* input_buf_;
std::string input_str_;
int length_;
int length_ = 0;
};

} // namespace net
Expand Down
14 changes: 7 additions & 7 deletions src/net/src/backend_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void BackendThread::SetWaitConnectOnEpoll(int sockfd) {

void BackendThread::AddConnection(const std::string& peer_ip, int peer_port, int sockfd) {
std::string ip_port = peer_ip + ":" + std::to_string(peer_port);
std::shared_ptr<NetConn> tc = conn_factory_->NewNetConn(sockfd, ip_port, this, NULL, net_multiplexer_.get());
std::shared_ptr<NetConn> tc = conn_factory_->NewNetConn(sockfd, ip_port, this, nullptr, net_multiplexer_.get());
tc->SetNonblock();
// This flag specifies that the file descriptor should be closed when an exec function is invoked.
fcntl(sockfd, F_SETFD, fcntl(sockfd, F_GETFD) | FD_CLOEXEC);
Expand Down Expand Up @@ -152,7 +152,7 @@ Status BackendThread::Connect(const std::string& dst_ip, const int dst_port, int
if ((rv = getaddrinfo(dst_ip.c_str(), cport, &hints, &servinfo)) != 0) {
return Status::IOError("connect getaddrinfo error for ", dst_ip);
}
for (p = servinfo; p != NULL; p = p->ai_next) {
for (p = servinfo; p != nullptr; p = p->ai_next) {
if ((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
continue;
}
Expand Down Expand Up @@ -190,7 +190,7 @@ Status BackendThread::Connect(const std::string& dst_ip, const int dst_port, int
freeaddrinfo(servinfo);
return s;
}
if (p == NULL) {
if (p == nullptr) {
s = Status::IOError(strerror(errno), "Can't create socket ");
return s;
}
Expand Down Expand Up @@ -231,7 +231,7 @@ void BackendThread::CleanUpConnRemaining(const int fd) {

void BackendThread::DoCronTask() {
struct timeval now;
gettimeofday(&now, NULL);
gettimeofday(&now, nullptr);
pstd::MutexLock l(&mu_);
std::map<int, std::shared_ptr<NetConn>>::iterator iter = conns_.begin();
while (iter != conns_.end()) {
Expand Down Expand Up @@ -351,10 +351,10 @@ void BackendThread::ProcessNotifyEvents(const NetFiredEvent* pfe) {

void* BackendThread::ThreadMain() {
int nfds = 0;
NetFiredEvent* pfe = NULL;
NetFiredEvent* pfe = nullptr;

struct timeval when;
gettimeofday(&when, NULL);
gettimeofday(&when, nullptr);
struct timeval now = when;

when.tv_sec += (cron_interval_ / 1000);
Expand Down Expand Up @@ -387,7 +387,7 @@ void* BackendThread::ThreadMain() {
nfds = net_multiplexer_->NetPoll(timeout);
for (int i = 0; i < nfds; i++) {
pfe = (net_multiplexer_->FiredEvents()) + i;
if (pfe == NULL) {
if (pfe == nullptr) {
continue;
}

Expand Down
8 changes: 4 additions & 4 deletions src/net/src/bg_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void BGThread::SwallowReadyTasks() {
mu_.Unlock();

struct timeval now;
gettimeofday(&now, NULL);
gettimeofday(&now, nullptr);
uint64_t unow = now.tv_sec * 1000000 + now.tv_usec;
mu_.Lock();
while (!timer_queue_.empty()) {
Expand Down Expand Up @@ -82,7 +82,7 @@ void* BGThread::ThreadMain() {
}
if (!timer_queue_.empty()) {
struct timeval now;
gettimeofday(&now, NULL);
gettimeofday(&now, nullptr);

TimerItem timer_item = timer_queue_.top();
uint64_t unow = now.tv_sec * 1000000 + now.tv_usec;
Expand Down Expand Up @@ -110,7 +110,7 @@ void* BGThread::ThreadMain() {
}
// swalloc all the remain tasks in ready and timer queue
SwallowReadyTasks();
return NULL;
return nullptr;
}

/*
Expand All @@ -122,7 +122,7 @@ void BGThread::DelaySchedule(uint64_t timeout, void (*function)(void*), void* ar
* so we need gettimeofday + timeout
*/
struct timeval now;
gettimeofday(&now, NULL);
gettimeofday(&now, nullptr);
uint64_t exec_time;
exec_time = now.tv_sec * 1000000 + timeout * 1000 + now.tv_usec;

Expand Down
14 changes: 7 additions & 7 deletions src/net/src/client_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void ClientThread::SetWaitConnectOnEpoll(int sockfd) {

void ClientThread::NewConnection(const std::string& peer_ip, int peer_port, int sockfd) {
std::string ip_port = peer_ip + ":" + std::to_string(peer_port);
std::shared_ptr<NetConn> tc = conn_factory_->NewNetConn(sockfd, ip_port, this, NULL, net_multiplexer_.get());
std::shared_ptr<NetConn> tc = conn_factory_->NewNetConn(sockfd, ip_port, this, nullptr, net_multiplexer_.get());
tc->SetNonblock();
// This flag specifies that the file descriptor should be closed when an exec function is invoked.
fcntl(sockfd, F_SETFD, fcntl(sockfd, F_GETFD) | FD_CLOEXEC);
Expand All @@ -141,7 +141,7 @@ Status ClientThread::ScheduleConnect(const std::string& dst_ip, int dst_port) {
if ((rv = getaddrinfo(dst_ip.c_str(), cport, &hints, &servinfo)) != 0) {
return Status::IOError("connect getaddrinfo error for ", dst_ip);
}
for (p = servinfo; p != NULL; p = p->ai_next) {
for (p = servinfo; p != nullptr; p = p->ai_next) {
if ((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
continue;
}
Expand Down Expand Up @@ -179,7 +179,7 @@ Status ClientThread::ScheduleConnect(const std::string& dst_ip, int dst_port) {

return s;
}
if (p == NULL) {
if (p == nullptr) {
s = Status::IOError(strerror(errno), "Can't create socket ");
return s;
}
Expand Down Expand Up @@ -209,7 +209,7 @@ void ClientThread::CleanUpConnRemaining(const std::string& ip_port) {

void ClientThread::DoCronTask() {
struct timeval now;
gettimeofday(&now, NULL);
gettimeofday(&now, nullptr);
std::map<int, std::shared_ptr<NetConn>>::iterator iter = fd_conns_.begin();
while (iter != fd_conns_.end()) {
std::shared_ptr<NetConn> conn = iter->second;
Expand Down Expand Up @@ -358,10 +358,10 @@ void ClientThread::ProcessNotifyEvents(const NetFiredEvent* pfe) {

void* ClientThread::ThreadMain() {
int nfds = 0;
NetFiredEvent* pfe = NULL;
NetFiredEvent* pfe = nullptr;

struct timeval when;
gettimeofday(&when, NULL);
gettimeofday(&when, nullptr);
struct timeval now = when;

when.tv_sec += (cron_interval_ / 1000);
Expand Down Expand Up @@ -394,7 +394,7 @@ void* ClientThread::ThreadMain() {
nfds = net_multiplexer_->NetPoll(timeout);
for (int i = 0; i < nfds; i++) {
pfe = (net_multiplexer_->FiredEvents()) + i;
if (pfe == NULL) {
if (pfe == nullptr) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/net/src/holy_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void HolyThread::HandleConnEvent(NetFiredEvent* pfe) {

void HolyThread::DoCronTask() {
struct timeval now;
gettimeofday(&now, NULL);
gettimeofday(&now, nullptr);
std::vector<std::shared_ptr<NetConn>> to_close;
std::vector<std::shared_ptr<NetConn>> to_timeout;
{
Expand Down
4 changes: 2 additions & 2 deletions src/net/src/net_cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Status NetCli::Connect(const std::string& ip, const int port, const std::string&
if ((rv = getaddrinfo(ip.c_str(), cport, &hints, &servinfo)) != 0) {
return Status::IOError("connect getaddrinfo error for ", ip);
}
for (p = servinfo; p != NULL; p = p->ai_next) {
for (p = servinfo; p != nullptr; p = p->ai_next) {
if ((r->sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
continue;
}
Expand Down Expand Up @@ -150,7 +150,7 @@ Status NetCli::Connect(const std::string& ip, const int port, const std::string&
rep_->available = true;
return s;
}
if (p == NULL) {
if (p == nullptr) {
s = Status::IOError(strerror(errno), "Can't create socket ");
return s;
}
Expand Down
6 changes: 3 additions & 3 deletions src/net/src/net_interfaces.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ std::string GetIpByInterface(const std::string& network_interface) {

log_info("Using Networker Interface: %s", network_interface.c_str());

struct ifaddrs* ifAddrStruct = NULL;
struct ifaddrs* ifa = NULL;
void* tmpAddrPtr = NULL;
struct ifaddrs* ifAddrStruct = nullptr;
struct ifaddrs* ifa = nullptr;
void* tmpAddrPtr = nullptr;

if (getifaddrs(&ifAddrStruct) == -1) {
log_err("getifaddrs failed");
Expand Down
4 changes: 2 additions & 2 deletions src/net/src/net_pubsub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ void* PubSubThread::ThreadMain() {
continue;
}
} else {
in_conn = NULL;
in_conn = nullptr;
bool should_close = false;

{
Expand Down Expand Up @@ -498,7 +498,7 @@ void* PubSubThread::ThreadMain() {
}
}
Cleanup();
return NULL;
return nullptr;
}

void PubSubThread::Cleanup() {
Expand Down
2 changes: 1 addition & 1 deletion src/net/src/pb_conn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ ReadStatus PbConn::GetRequest() {
uint32_t new_size = header_len_ + COMMAND_HEADER_LENGTH;
if (new_size < kProtoMaxMessage) {
rbuf_ = reinterpret_cast<char*>(realloc(rbuf_, sizeof(char) * new_size));
if (rbuf_ == NULL) {
if (rbuf_ == nullptr) {
return kFullError;
}
rbuf_len_ = new_size;
Expand Down
4 changes: 2 additions & 2 deletions src/net/src/period_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ PeriodThread::PeriodThread(struct timeval period) : period_(period) {}

void* PeriodThread::ThreadMain() {
PeriodMain();
select(0, NULL, NULL, NULL, &period_);
return NULL;
select(0, nullptr, nullptr, nullptr, &period_);
return nullptr;
}

} // namespace net
Loading

0 comments on commit 6012793

Please sign in to comment.