This is an automated email from the ASF dual-hosted git repository.
wwbmmm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git
The following commit(s) were added to refs/heads/master by this push:
new bd6fa80b Replace NULL with nullptr in butil/details, butil/mac,
butil/synchronization and butil/time (#3439)
bd6fa80b is described below
commit bd6fa80ba6f72f004bbd3bda928d894c48057640
Author: Bright Chen <[email protected]>
AuthorDate: Sat Aug 15 13:55:40 2026 +0800
Replace NULL with nullptr in butil/details, butil/mac,
butil/synchronization and butil/time (#3439)
---
src/butil/details/extended_endpoint.hpp | 30 +++++++++++-----------
src/butil/mac/foundation_util.h | 14 +++++-----
src/butil/mac/foundation_util.mm | 26 +++++++++----------
src/butil/mac/scoped_cftyperef.h | 2 +-
src/butil/mac/scoped_typeref.h | 8 +++---
.../synchronization/condition_variable_posix.cc | 4 +--
src/butil/synchronization/lock.h | 2 +-
src/butil/synchronization/waitable_event_posix.cc | 2 +-
src/butil/time/time.h | 2 +-
src/butil/time/time_mac.cc | 6 ++---
src/butil/time/time_posix.cc | 2 +-
11 files changed, 49 insertions(+), 49 deletions(-)
diff --git a/src/butil/details/extended_endpoint.hpp
b/src/butil/details/extended_endpoint.hpp
index 36a67719..ce425349 100644
--- a/src/butil/details/extended_endpoint.hpp
+++ b/src/butil/details/extended_endpoint.hpp
@@ -109,51 +109,51 @@ public:
static ExtendedEndPoint* create(StringPiece sp, EndPoint* ep) {
sp.trim_spaces();
if (sp.empty()) {
- return NULL;
+ return nullptr;
}
if (sp[0] == '[') {
size_t colon_pos = sp.find(']');
if (colon_pos == StringPiece::npos || colon_pos == 1 /* [] is
invalid */ || ++colon_pos >= sp.size()) {
- return NULL;
+ return nullptr;
}
StringPiece port_sp = sp.substr(colon_pos);
if (port_sp.size() < 2 /* colon and at least one integer */ ||
port_sp[0] != ':') {
- return NULL;
+ return nullptr;
}
port_sp.remove_prefix(1); // remove `:'
if (port_sp.size() > 5) { // max 65535
- return NULL;
+ return nullptr;
}
char buf[6];
buf[port_sp.copy(buf, port_sp.size())] = '\0';
- char* end = NULL;
+ char* end = nullptr;
int port = ::strtol(buf, &end, 10 /* base */);
if (end != buf + port_sp.size()) {
- return NULL;
+ return nullptr;
}
return create(sp.substr(0, colon_pos), port, ep);
} else if (sp.starts_with("unix:")) {
return create(sp, EXTENDED_ENDPOINT_PORT, ep);
}
- return NULL;
+ return nullptr;
}
static ExtendedEndPoint* create(StringPiece sp, int port, EndPoint* ep) {
sp.trim_spaces();
if (sp.empty()) {
- return NULL;
+ return nullptr;
}
- ExtendedEndPoint* eep = NULL;
+ ExtendedEndPoint* eep = nullptr;
if (sp[0] == '[' && port >= 0 && port <= 65535) {
if (sp.back() != ']' || sp.size() == 2 || sp.size() - 2 >=
INET6_ADDRSTRLEN) {
- return NULL;
+ return nullptr;
}
char buf[INET6_ADDRSTRLEN];
buf[sp.copy(buf, sp.size() - 2 /* skip `[' and `]' */, 1 /* skip
`[' */)] = '\0';
in6_addr addr;
if (inet_pton(AF_INET6, buf, &addr) != 1 /* succ */) {
- return NULL;
+ return nullptr;
}
eep = new_extended_endpoint(AF_INET6);
@@ -170,7 +170,7 @@ public:
} else if (sp.starts_with("unix:")) { // ignore port
sp.remove_prefix(5); // remove `unix:'
if (sp.empty() || sp.size() >= UDS_PATH_SIZE) {
- return NULL;
+ return nullptr;
}
eep = new_extended_endpoint(AF_UNIX);
if (eep) {
@@ -190,7 +190,7 @@ public:
}
static ExtendedEndPoint* create(sockaddr_storage* ss, socklen_t size,
EndPoint* ep) {
- ExtendedEndPoint* eep = NULL;
+ ExtendedEndPoint* eep = nullptr;
if (ss->ss_family == AF_INET6 || ss->ss_family == AF_UNIX) {
eep = new_extended_endpoint(ss->ss_family);
}
@@ -211,7 +211,7 @@ public:
// Get ExtendedEndPoint instance from EndPoint
static ExtendedEndPoint* address(const EndPoint& ep) {
if (!is_extended(ep)) {
- return NULL;
+ return nullptr;
}
::butil::ResourceId<ExtendedEndPoint> id;
id.value = ep.ip.s_addr;
@@ -310,7 +310,7 @@ public:
return 0;
} else if (_u.sa.sa_family == AF_INET6) {
sockaddr_in6 sa = _u.in6;
- if (getnameinfo((const sockaddr*) &sa, sizeof(sa), host, host_len,
NULL, 0, NI_NAMEREQD) != 0) {
+ if (getnameinfo((const sockaddr*) &sa, sizeof(sa), host, host_len,
nullptr, 0, NI_NAMEREQD) != 0) {
return -1;
}
size_t len = ::strlen(host);
diff --git a/src/butil/mac/foundation_util.h b/src/butil/mac/foundation_util.h
index 12b8e66a..5b588694 100644
--- a/src/butil/mac/foundation_util.h
+++ b/src/butil/mac/foundation_util.h
@@ -79,20 +79,20 @@ OSType CreatorCodeForCFBundleRef(CFBundleRef bundle);
BUTIL_EXPORT OSType CreatorCodeForApplication();
// Searches for directories for the given key in only the given |domain_mask|.
-// If found, fills result (which must always be non-NULL) with the
+// If found, fills result (which must always be non-nullptr) with the
// first found directory and returns true. Otherwise, returns false.
BUTIL_EXPORT bool GetSearchPathDirectory(NSSearchPathDirectory directory,
NSSearchPathDomainMask domain_mask,
FilePath* result);
// Searches for directories for the given key in only the local domain.
-// If found, fills result (which must always be non-NULL) with the
+// If found, fills result (which must always be non-nullptr) with the
// first found directory and returns true. Otherwise, returns false.
BUTIL_EXPORT bool GetLocalDirectory(NSSearchPathDirectory directory,
FilePath* result);
// Searches for directories for the given key in only the user domain.
-// If found, fills result (which must always be non-NULL) with the
+// If found, fills result (which must always be non-nullptr) with the
// first found directory and returns true. Otherwise, returns false.
BUTIL_EXPORT bool GetUserDirectory(NSSearchPathDirectory directory,
FilePath* result);
@@ -154,7 +154,7 @@ BUTIL_EXPORT void NSObjectRelease(void* obj);
BUTIL_EXPORT void* CFTypeRefToNSObjectAutorelease(CFTypeRef cf_object);
// Returns the base bundle ID, which can be set by SetBaseBundleID but
-// defaults to a reasonable string. This never returns NULL. BaseBundleID
+// defaults to a reasonable string. This never returns nullptr. BaseBundleID
// returns a pointer to static storage that must not be freed.
BUTIL_EXPORT const char* BaseBundleID();
@@ -244,8 +244,8 @@ namespace mac {
// object is found by comparing its opaque type against the
// requested type identifier. If the supplied object is not
// compatible with the requested return type, CFCast<>() returns
-// NULL and CFCastStrict<>() will DCHECK. Providing a NULL pointer
-// to either variant results in NULL being returned without
+// nullptr and CFCastStrict<>() will DCHECK. Providing a nullptr pointer
+// to either variant results in nullptr being returned without
// triggering any DCHECK.
//
// Example usage:
@@ -338,7 +338,7 @@ BUTIL_EXPORT std::string GetValueFromDictionaryErrorMessage(
CFStringRef key, const std::string& expected_type, CFTypeRef value);
// Utility function to pull out a value from a dictionary, check its type, and
-// return it. Returns NULL if the key is not present or of the wrong type.
+// return it. Returns nullptr if the key is not present or of the wrong type.
template<typename T>
T GetValueFromDictionary(CFDictionaryRef dict, CFStringRef key) {
CFTypeRef value = CFDictionaryGetValue(dict, key);
diff --git a/src/butil/mac/foundation_util.mm b/src/butil/mac/foundation_util.mm
index 74d26aaf..b180122e 100644
--- a/src/butil/mac/foundation_util.mm
+++ b/src/butil/mac/foundation_util.mm
@@ -83,7 +83,7 @@ FilePath PathForFrameworkBundleResource(CFStringRef
resourceName) {
OSType CreatorCodeForCFBundleRef(CFBundleRef bundle) {
OSType creator = kUnknownType;
- CFBundleGetPackageInfo(bundle, NULL, &creator);
+ CFBundleGetPackageInfo(bundle, nullptr, &creator);
return creator;
}
@@ -215,7 +215,7 @@ void* CFTypeRefToNSObjectAutorelease(CFTypeRef cf_object) {
// In the traditional GC-less environment, NSMakeCollectable is a no-op,
// and cf_object is autoreleased, balancing out the caller's ownership claim.
//
- // NSMakeCollectable returns nil when used on a NULL object.
+ // NSMakeCollectable returns nil when used on a nullptr object.
return [NSMakeCollectable(cf_object) autorelease];
}
@@ -236,7 +236,7 @@ const char* BaseBundleID() {
void SetBaseBundleID(const char* new_base_bundle_id) {
if (new_base_bundle_id != base_bundle_id) {
free((void*)base_bundle_id);
- base_bundle_id = new_base_bundle_id ? strdup(new_base_bundle_id) : NULL;
+ base_bundle_id = new_base_bundle_id ? strdup(new_base_bundle_id) : nullptr;
}
}
@@ -322,19 +322,19 @@ CTFontRef NSToCFCast(NSFont* ns_val) {
#define CF_CAST_DEFN(TypeCF) \
template<> TypeCF##Ref \
CFCast<TypeCF##Ref>(const CFTypeRef& cf_val) { \
- if (cf_val == NULL) { \
- return NULL; \
+ if (cf_val == nullptr) { \
+ return nullptr; \
} \
if (CFGetTypeID(cf_val) == TypeCF##GetTypeID()) { \
return (TypeCF##Ref)(cf_val); \
} \
- return NULL; \
+ return nullptr; \
} \
\
template<> TypeCF##Ref \
CFCastStrict<TypeCF##Ref>(const CFTypeRef& cf_val) { \
TypeCF##Ref rv = CFCast<TypeCF##Ref>(cf_val); \
- DCHECK(cf_val == NULL || rv); \
+ DCHECK(cf_val == nullptr || rv); \
return rv; \
}
@@ -363,27 +363,27 @@ CF_CAST_DEFN(CTFont);
// http://www.openradar.me/15341349 rdar://15341349
template<> CTFontRef
CFCast<CTFontRef>(const CFTypeRef& cf_val) {
- if (cf_val == NULL) {
- return NULL;
+ if (cf_val == nullptr) {
+ return nullptr;
}
if (CFGetTypeID(cf_val) == CTFontGetTypeID()) {
return (CTFontRef)(cf_val);
}
if (!_CFIsObjC(CTFontGetTypeID(), cf_val))
- return NULL;
+ return nullptr;
id<NSObject> ns_val = reinterpret_cast<id>(const_cast<void*>(cf_val));
if ([ns_val isKindOfClass:NSClassFromString(@"NSFont")]) {
return (CTFontRef)(cf_val);
}
- return NULL;
+ return nullptr;
}
template<> CTFontRef
CFCastStrict<CTFontRef>(const CFTypeRef& cf_val) {
CTFontRef rv = CFCast<CTFontRef>(cf_val);
- DCHECK(cf_val == NULL || rv);
+ DCHECK(cf_val == nullptr || rv);
return rv;
}
#endif
@@ -430,7 +430,7 @@ std::ostream& operator<<(std::ostream& o, const CFStringRef
string) {
std::ostream& operator<<(std::ostream& o, const CFErrorRef err) {
butil::ScopedCFTypeRef<CFStringRef> desc(CFErrorCopyDescription(err));
butil::ScopedCFTypeRef<CFDictionaryRef> user_info(CFErrorCopyUserInfo(err));
- CFStringRef errorDesc = NULL;
+ CFStringRef errorDesc = nullptr;
if (user_info.get()) {
errorDesc = reinterpret_cast<CFStringRef>(
CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey));
diff --git a/src/butil/mac/scoped_cftyperef.h b/src/butil/mac/scoped_cftyperef.h
index 626a431c..977f910c 100644
--- a/src/butil/mac/scoped_cftyperef.h
+++ b/src/butil/mac/scoped_cftyperef.h
@@ -45,7 +45,7 @@ class ScopedCFTypeRef
typedef CFT element_type;
explicit ScopedCFTypeRef(
- CFT object = NULL,
+ CFT object = nullptr,
butil::scoped_policy::OwnershipPolicy policy =
butil::scoped_policy::ASSUME)
: ScopedTypeRef<CFT,
internal::ScopedCFTypeRefTraits>(object, policy) {}
diff --git a/src/butil/mac/scoped_typeref.h b/src/butil/mac/scoped_typeref.h
index 85efbf49..22e9de4a 100644
--- a/src/butil/mac/scoped_typeref.h
+++ b/src/butil/mac/scoped_typeref.h
@@ -51,7 +51,7 @@ class ScopedTypeRef {
typedef T element_type;
ScopedTypeRef(
- T object = NULL,
+ T object = nullptr,
scoped_policy::OwnershipPolicy policy = scoped_policy::ASSUME)
: object_(object) {
if (object_ && policy == scoped_policy::RETAIN)
@@ -76,13 +76,13 @@ class ScopedTypeRef {
// This is to be used only to take ownership of objects that are created
// by pass-by-pointer create functions. To enforce this, require that the
- // object be reset to NULL before this may be used.
+ // object be reset to nullptr before this may be used.
T* InitializeInto() WARN_UNUSED_RESULT {
DCHECK(!object_);
return &object_;
}
- void reset(T object = NULL,
+ void reset(T object = nullptr,
scoped_policy::OwnershipPolicy policy = scoped_policy::ASSUME) {
if (object && policy == scoped_policy::RETAIN)
Traits::Retain(object);
@@ -118,7 +118,7 @@ class ScopedTypeRef {
// Release(), use ScopedTypeRef<>::reset().
T release() WARN_UNUSED_RESULT {
T temp = object_;
- object_ = NULL;
+ object_ = nullptr;
return temp;
}
diff --git a/src/butil/synchronization/condition_variable_posix.cc
b/src/butil/synchronization/condition_variable_posix.cc
index 4a4b9f3e..6ac2bf55 100644
--- a/src/butil/synchronization/condition_variable_posix.cc
+++ b/src/butil/synchronization/condition_variable_posix.cc
@@ -18,7 +18,7 @@ ConditionVariable::ConditionVariable(Mutex* user_lock)
: user_mutex_(user_lock->native_handle()) {
// NOTE(gejun): Disable monotonic clock always due to difficulty of adapting
// all versions of gcc
- int rv = pthread_cond_init(&condition_, NULL);
+ int rv = pthread_cond_init(&condition_, nullptr);
DCHECK_EQ(0, rv);
}
@@ -46,7 +46,7 @@ void ConditionVariable::TimedWait(const TimeDelta& max_time) {
&condition_, user_mutex_, &relative_time);
#else
struct timeval now;
- gettimeofday(&now, NULL);
+ gettimeofday(&now, nullptr);
struct timespec absolute_time;
absolute_time.tv_sec = now.tv_sec;
absolute_time.tv_nsec = now.tv_usec * Time::kNanosecondsPerMicrosecond;
diff --git a/src/butil/synchronization/lock.h b/src/butil/synchronization/lock.h
index e62c76c4..eb5f9822 100644
--- a/src/butil/synchronization/lock.h
+++ b/src/butil/synchronization/lock.h
@@ -53,7 +53,7 @@ public:
// contending thread from going to sleep which helps performance greatly.
::InitializeCriticalSectionAndSpinCount(&_native_handle, 2000);
#elif defined(OS_POSIX)
- pthread_mutex_init(&_native_handle, NULL);
+ pthread_mutex_init(&_native_handle, nullptr);
#endif
}
diff --git a/src/butil/synchronization/waitable_event_posix.cc
b/src/butil/synchronization/waitable_event_posix.cc
index adeb5730..dd3f9046 100644
--- a/src/butil/synchronization/waitable_event_posix.cc
+++ b/src/butil/synchronization/waitable_event_posix.cc
@@ -87,7 +87,7 @@ class SyncWaiter : public WaitableEvent::Waiter {
public:
SyncWaiter()
: fired_(false),
- signaling_event_(NULL),
+ signaling_event_(nullptr),
lock_(),
cv_(&lock_) {
}
diff --git a/src/butil/time/time.h b/src/butil/time/time.h
index cdc57b63..d341271a 100644
--- a/src/butil/time/time.h
+++ b/src/butil/time/time.h
@@ -268,7 +268,7 @@ class BUTIL_EXPORT Time {
bool HasValidValues() const;
};
- // Contains the NULL time. Use Time::Now() to get the current time.
+ // Contains the nullptr time. Use Time::Now() to get the current time.
Time() : us_(0) {
}
diff --git a/src/butil/time/time_mac.cc b/src/butil/time/time_mac.cc
index 98e818a9..733d7e24 100644
--- a/src/butil/time/time_mac.cc
+++ b/src/butil/time/time_mac.cc
@@ -29,7 +29,7 @@ uint64_t ComputeCurrentTicks() {
struct timeval boottime;
int mib[2] = {CTL_KERN, KERN_BOOTTIME};
size_t size = sizeof(boottime);
- int kr = sysctl(mib, arraysize(mib), &boottime, &size, NULL, 0);
+ int kr = sysctl(mib, arraysize(mib), &boottime, &size, nullptr, 0);
DCHECK_EQ(KERN_SUCCESS, kr);
butil::TimeDelta time_difference = butil::Time::Now() -
(butil::Time::FromTimeT(boottime.tv_sec) +
@@ -171,7 +171,7 @@ Time Time::FromExploded(bool is_local, const Exploded&
exploded) {
date.year = exploded.year;
butil::ScopedCFTypeRef<CFTimeZoneRef> time_zone(
- is_local ? CFTimeZoneCopySystem() : NULL);
+ is_local ? CFTimeZoneCopySystem() : nullptr);
CFAbsoluteTime seconds = CFGregorianDateGetAbsoluteTime(date, time_zone) +
kCFAbsoluteTimeIntervalSince1970;
return Time(static_cast<int64_t>(seconds * kMicrosecondsPerSecond) +
@@ -189,7 +189,7 @@ void Time::Explode(bool is_local, Exploded* exploded) const
{
kCFAbsoluteTimeIntervalSince1970;
butil::ScopedCFTypeRef<CFTimeZoneRef> time_zone(
- is_local ? CFTimeZoneCopySystem() : NULL);
+ is_local ? CFTimeZoneCopySystem() : nullptr);
CFGregorianDate date = CFAbsoluteTimeGetGregorianDate(seconds, time_zone);
// 1 = Monday, ..., 7 = Sunday.
int cf_day_of_week = CFAbsoluteTimeGetDayOfWeek(seconds, time_zone);
diff --git a/src/butil/time/time_posix.cc b/src/butil/time/time_posix.cc
index 2b363839..75890967 100644
--- a/src/butil/time/time_posix.cc
+++ b/src/butil/time/time_posix.cc
@@ -211,7 +211,7 @@ Time Time::FromExploded(bool is_local, const Exploded&
exploded) {
timestruct.tm_isdst = -1; // attempt to figure it out
#if !defined(OS_NACL) && !defined(OS_SOLARIS)
timestruct.tm_gmtoff = 0; // not a POSIX field, so mktime/timegm ignore
- timestruct.tm_zone = NULL; // not a POSIX field, so mktime/timegm ignore
+ timestruct.tm_zone = nullptr; // not a POSIX field, so mktime/timegm
ignore
#endif
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]