[vm] Update NULL to nullptr in runtime/platform.

TEST=build
Change-Id: I1a01702451f1be91f14c3a860fa3f84b0c686409
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292062
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
Ryan Macnak 2023-03-30 20:49:48 +00:00 committed by Commit Queue
parent 9e76983782
commit e0e14c370a
12 changed files with 48 additions and 46 deletions

View file

@ -50,7 +50,7 @@ void Assert::Fail(const char* format, ...) const {
va_end(arguments);
// Abort right away.
Dart_DumpNativeStackTrace(NULL);
Dart_DumpNativeStackTrace(nullptr);
Dart_PrepareToAbort();
abort();
}

View file

@ -99,9 +99,9 @@ class Expect : public DynamicAssertionHelper {
template <typename T>
T Assert::NotNull(const T p) {
if (p != NULL) return p;
Fail("expected: not NULL, found NULL");
return NULL;
if (p != nullptr) return p;
Fail("expected: not nullptr, found nullptr");
return nullptr;
}
#if defined(TESTING)
@ -222,8 +222,8 @@ void Expect::GreaterEqual(const E& left, const A& right) {
template <typename T>
void Expect::NotNull(const T p) {
if (p != NULL) return;
Fail("expected: not NULL, found NULL");
if (p != nullptr) return;
Fail("expected: not nullptr, found nullptr");
}
template <typename T>

View file

@ -19,10 +19,10 @@ template <typename T, typename B, typename Allocator>
class BaseGrowableArray : public B {
public:
explicit BaseGrowableArray(Allocator* allocator)
: length_(0), capacity_(0), data_(NULL), allocator_(allocator) {}
: length_(0), capacity_(0), data_(nullptr), allocator_(allocator) {}
BaseGrowableArray(intptr_t initial_capacity, Allocator* allocator)
: length_(0), capacity_(0), data_(NULL), allocator_(allocator) {
: length_(0), capacity_(0), data_(nullptr), allocator_(allocator) {
if (initial_capacity > 0) {
capacity_ = Utils::RoundUpToPowerOfTwo(initial_capacity);
data_ = allocator_->template Alloc<T>(capacity_);
@ -36,7 +36,7 @@ class BaseGrowableArray : public B {
allocator_(other.allocator_) {
other.length_ = 0;
other.capacity_ = 0;
other.data_ = NULL;
other.data_ = nullptr;
}
~BaseGrowableArray() { allocator_->template Free<T>(data_, capacity_); }
@ -198,7 +198,7 @@ class BaseGrowableArray : public B {
void StealBuffer(T** buffer, intptr_t* length) {
*buffer = data_;
*length = length_;
data_ = NULL;
data_ = nullptr;
length_ = 0;
capacity_ = 0;
}
@ -234,7 +234,7 @@ void BaseGrowableArray<T, B, Allocator>::Resize(intptr_t new_length) {
intptr_t new_capacity = Utils::RoundUpToPowerOfTwo(new_length);
T* new_data =
allocator_->template Realloc<T>(data_, capacity_, new_capacity);
ASSERT(new_data != NULL);
ASSERT(new_data != nullptr);
data_ = new_data;
capacity_ = new_capacity;
}
@ -245,7 +245,7 @@ template <typename T, typename B, typename Allocator>
void BaseGrowableArray<T, B, Allocator>::SetLength(intptr_t new_length) {
if (new_length > capacity_) {
T* new_data = allocator_->template Alloc<T>(new_length);
ASSERT(new_data != NULL);
ASSERT(new_data != nullptr);
data_ = new_data;
capacity_ = new_length;
}
@ -275,8 +275,10 @@ class MallocGrowableArray
: public BaseGrowableArray<T, MallocAllocated, Malloc> {
public:
explicit MallocGrowableArray(intptr_t initial_capacity)
: BaseGrowableArray<T, MallocAllocated, Malloc>(initial_capacity, NULL) {}
MallocGrowableArray() : BaseGrowableArray<T, MallocAllocated, Malloc>(NULL) {}
: BaseGrowableArray<T, MallocAllocated, Malloc>(initial_capacity,
nullptr) {}
MallocGrowableArray()
: BaseGrowableArray<T, MallocAllocated, Malloc>(nullptr) {}
};
} // namespace dart

View file

@ -22,14 +22,14 @@ SimpleHashMap::Entry* SimpleHashMap::Lookup(void* key,
bool insert) {
// Find a matching entry.
Entry* p = Probe(key, hash);
if (p->key != NULL) {
if (p->key != nullptr) {
return p;
}
// No entry found; insert one if necessary.
if (insert) {
p->key = key;
p->value = NULL;
p->value = nullptr;
p->hash = hash;
occupancy_++;
@ -43,13 +43,13 @@ SimpleHashMap::Entry* SimpleHashMap::Lookup(void* key,
}
// No entry found and none inserted.
return NULL;
return nullptr;
}
void SimpleHashMap::Remove(void* key, uint32_t hash) {
// Lookup the entry for the key to remove.
Entry* candidate = Probe(key, hash);
if (candidate->key == NULL) {
if (candidate->key == nullptr) {
// Key not found nothing to remove.
return;
}
@ -83,7 +83,7 @@ void SimpleHashMap::Remove(void* key, uint32_t hash) {
// All entries between "candidate" and "next" have their initial position
// between candidate and entry and the entry candidate can be cleared
// without breaking the search for these entries.
if (next->key == NULL) {
if (next->key == nullptr) {
break;
}
@ -104,7 +104,7 @@ void SimpleHashMap::Remove(void* key, uint32_t hash) {
}
// Clear the candidate which will not break searching the hash table.
candidate->key = NULL;
candidate->key = nullptr;
occupancy_--;
}
@ -112,10 +112,10 @@ void SimpleHashMap::Clear(ClearFun clear) {
// Mark all entries as empty.
const Entry* end = map_end();
for (Entry* p = map_; p < end; p++) {
if ((clear != NULL) && (p->key != NULL)) {
if ((clear != nullptr) && (p->key != nullptr)) {
clear(p->value);
}
p->key = NULL;
p->key = nullptr;
}
occupancy_ = 0;
}
@ -128,15 +128,15 @@ SimpleHashMap::Entry* SimpleHashMap::Next(Entry* p) const {
const Entry* end = map_end();
ASSERT(map_ - 1 <= p && p < end);
for (p++; p < end; p++) {
if (p->key != NULL) {
if (p->key != nullptr) {
return p;
}
}
return NULL;
return nullptr;
}
SimpleHashMap::Entry* SimpleHashMap::Probe(void* key, uint32_t hash) {
ASSERT(key != NULL);
ASSERT(key != nullptr);
ASSERT(dart::Utils::IsPowerOfTwo(capacity_));
Entry* p = map_ + (hash & (capacity_ - 1));
@ -144,7 +144,7 @@ SimpleHashMap::Entry* SimpleHashMap::Probe(void* key, uint32_t hash) {
ASSERT(map_ <= p && p < end);
ASSERT(occupancy_ < capacity_); // Guarantees loop termination.
while (p->key != NULL && (hash != p->hash || !match_(key, p->key))) {
while (p->key != nullptr && (hash != p->hash || !match_(key, p->key))) {
p++;
if (p >= end) {
p = map_;
@ -170,7 +170,7 @@ void SimpleHashMap::Resize() {
// Rehash all current entries.
for (Entry* p = map; n > 0; p++) {
if (p->key != NULL) {
if (p->key != nullptr) {
Lookup(p->key, p->hash, true)->value = p->value;
n--;
}

View file

@ -25,7 +25,7 @@ class SimpleHashMap {
static uint32_t StringHash(const char* key) {
uint32_t hash_ = 0;
if (key == NULL) return hash_;
if (key == nullptr) return hash_;
int len = strlen(key);
for (int i = 0; i < len; i++) {
hash_ += key[i];
@ -47,7 +47,7 @@ class SimpleHashMap {
// Some clients may not need to use the value slot
// (e.g. implementers of sets, where the key is the value).
struct Entry {
Entry() : key(NULL), value(NULL), hash(0) {}
Entry() : key(nullptr), value(nullptr), hash(0) {}
void* key;
void* value;
uint32_t hash; // The full hash value for key.
@ -56,8 +56,8 @@ class SimpleHashMap {
// If an entry with matching key is found, Lookup()
// returns that entry. If no matching entry is found,
// but insert is set, a new entry is inserted with
// corresponding key, key hash, and NULL value.
// Otherwise, NULL is returned.
// corresponding key, key hash, and nullptr value.
// Otherwise, nullptr is returned.
Entry* Lookup(void* key, uint32_t hash, bool insert);
// Removes the entry with matching key.
@ -68,7 +68,7 @@ class SimpleHashMap {
// Empties the hash map (occupancy() == 0), and calls the function 'clear' on
// each of the values if given.
void Clear(ClearFun clear = NULL);
void Clear(ClearFun clear = nullptr);
// The number of entries stored in the table.
intptr_t size() const { return occupancy_; }
@ -80,7 +80,7 @@ class SimpleHashMap {
// Iteration
//
// for (Entry* p = map.Start(); p != NULL; p = map.Next(p)) {
// for (Entry* p = map.Start(); p != nullptr; p = map.Next(p)) {
// ...
// }
//

View file

@ -237,7 +237,7 @@ class PriorityQueue {
Entry* new_backing = reinterpret_cast<Entry*>(
realloc(min_heap_, sizeof(Entry) * new_min_heap_size));
if (new_backing == NULL) FATAL("Cannot allocate memory.");
if (new_backing == nullptr) FATAL("Cannot allocate memory.");
min_heap_ = new_backing;
min_heap_size_ = new_min_heap_size;

View file

@ -43,7 +43,7 @@ class ThreadSignalBlocker {
~ThreadSignalBlocker() {
// Restore signal mask.
int r = pthread_sigmask(SIG_SETMASK, &old, NULL);
int r = pthread_sigmask(SIG_SETMASK, &old, nullptr);
USE(r);
ASSERT(r == 0);
}
@ -88,7 +88,7 @@ class ThreadSignalBlocker {
#define CHECK_IS_BLOCKING(signal) \
({ \
sigset_t signal_mask; \
int __r = pthread_sigmask(SIG_BLOCK, NULL, &signal_mask); \
int __r = pthread_sigmask(SIG_BLOCK, nullptr, &signal_mask); \
USE(__r); \
ASSERT(__r == 0); \
sigismember(&signal_mask, signal); \

View file

@ -264,7 +264,7 @@ bool Utf8::DecodeToUTF32(const uint8_t* utf8_array,
}
bool Utf8::DecodeCStringToUTF32(const char* str, int32_t* dst, intptr_t len) {
ASSERT(str != NULL);
ASSERT(str != nullptr);
intptr_t array_len = strlen(str);
const uint8_t* utf8_array = reinterpret_cast<const uint8_t*>(str);
return Utf8::DecodeToUTF32(utf8_array, array_len, dst, len);
@ -272,7 +272,7 @@ bool Utf8::DecodeCStringToUTF32(const char* str, int32_t* dst, intptr_t len) {
void Utf16::Encode(int32_t codepoint, uint16_t* dst) {
ASSERT(codepoint > Utf16::kMaxCodeUnit);
ASSERT(dst != NULL);
ASSERT(dst != nullptr);
dst[0] = (Utf16::kLeadSurrogateOffset + (codepoint >> 10));
dst[1] = (0xDC00 + (codepoint & 0x3FF));
}

View file

@ -292,11 +292,11 @@ char* Utils::VSCreate(const char* format, va_list args) {
// Measure.
va_list measure_args;
va_copy(measure_args, args);
intptr_t len = VSNPrint(NULL, 0, format, measure_args);
intptr_t len = VSNPrint(nullptr, 0, format, measure_args);
va_end(measure_args);
char* buffer = reinterpret_cast<char*>(malloc(len + 1));
ASSERT(buffer != NULL);
ASSERT(buffer != nullptr);
// Print.
va_list print_args;

View file

@ -512,7 +512,7 @@ class Utils {
// output has been truncated. The return value is never negative.
//
// The buffer will always be terminated by a '\0', unless the buffer
// is of size 0. The buffer might be NULL if the size is 0.
// is of size 0. The buffer might be nullptr if the size is 0.
//
// This specification conforms to C99 standard which is implemented
// by glibc 2.1+ with one exception: the C99 standard allows a

View file

@ -20,7 +20,7 @@ char* Utils::StrNDup(const char* s, intptr_t n) {
__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ <= 1060
intptr_t len = strlen(s);
if ((n < 0) || (len < 0)) {
return NULL;
return nullptr;
}
if (n < len) {
len = n;
@ -108,10 +108,10 @@ int32_t DarwinMajorVersionInternal() {
char* dot = strchr(uname_info.release, '.');
if (dot) {
errno = 0;
char* end_ptr = NULL;
char* end_ptr = nullptr;
darwin_major_version = strtol(uname_info.release, &end_ptr, 10);
if (errno != 0 || (end_ptr == uname_info.release)) {
dot = NULL;
dot = nullptr;
}
}

View file

@ -16,7 +16,7 @@ namespace dart {
char* Utils::StrNDup(const char* s, intptr_t n) {
intptr_t len = strlen(s);
if ((n < 0) || (len < 0)) {
return NULL;
return nullptr;
}
if (n < len) {
len = n;
@ -43,7 +43,7 @@ int Utils::SNPrint(char* str, size_t size, const char* format, ...) {
}
int Utils::VSNPrint(char* str, size_t size, const char* format, va_list args) {
if (str == NULL || size == 0) {
if (str == nullptr || size == 0) {
int retval = _vscprintf(format, args);
if (retval < 0) {
FATAL("Fatal error in Utils::VSNPrint with format '%s'", format);