summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/arena.cc2
-rw-r--r--util/cache.cc24
-rw-r--r--util/cache_test.cc4
-rw-r--r--util/coding.cc12
-rw-r--r--util/coding.h2
-rw-r--r--util/coding_test.cc19
-rw-r--r--util/env.cc2
-rw-r--r--util/env_posix.cc40
-rw-r--r--util/env_posix_test.cc2
-rw-r--r--util/env_test.cc6
-rw-r--r--util/options.cc6
-rw-r--r--util/posix_logger.h2
-rw-r--r--util/status.cc2
-rw-r--r--util/testharness.cc10
-rw-r--r--util/testutil.h4
15 files changed, 69 insertions, 68 deletions
diff --git a/util/arena.cc b/util/arena.cc
index 7407821..a0338bf 100644
--- a/util/arena.cc
+++ b/util/arena.cc
@@ -10,7 +10,7 @@ namespace leveldb {
static const int kBlockSize = 4096;
Arena::Arena() : memory_usage_(0) {
- alloc_ptr_ = NULL; // First allocation will allocate a block
+ alloc_ptr_ = nullptr; // First allocation will allocate a block
alloc_bytes_remaining_ = 0;
}
diff --git a/util/cache.cc b/util/cache.cc
index 10b7103..7cc2cea 100644
--- a/util/cache.cc
+++ b/util/cache.cc
@@ -69,7 +69,7 @@ struct LRUHandle {
// 4.4.3's builtin hashtable.
class HandleTable {
public:
- HandleTable() : length_(0), elems_(0), list_(NULL) { Resize(); }
+ HandleTable() : length_(0), elems_(0), list_(nullptr) { Resize(); }
~HandleTable() { delete[] list_; }
LRUHandle* Lookup(const Slice& key, uint32_t hash) {
@@ -79,9 +79,9 @@ class HandleTable {
LRUHandle* Insert(LRUHandle* h) {
LRUHandle** ptr = FindPointer(h->key(), h->hash);
LRUHandle* old = *ptr;
- h->next_hash = (old == NULL ? NULL : old->next_hash);
+ h->next_hash = (old == nullptr ? nullptr : old->next_hash);
*ptr = h;
- if (old == NULL) {
+ if (old == nullptr) {
++elems_;
if (elems_ > length_) {
// Since each cache entry is fairly large, we aim for a small
@@ -95,7 +95,7 @@ class HandleTable {
LRUHandle* Remove(const Slice& key, uint32_t hash) {
LRUHandle** ptr = FindPointer(key, hash);
LRUHandle* result = *ptr;
- if (result != NULL) {
+ if (result != nullptr) {
*ptr = result->next_hash;
--elems_;
}
@@ -114,7 +114,7 @@ class HandleTable {
// pointer to the trailing slot in the corresponding linked list.
LRUHandle** FindPointer(const Slice& key, uint32_t hash) {
LRUHandle** ptr = &list_[hash & (length_ - 1)];
- while (*ptr != NULL &&
+ while (*ptr != nullptr &&
((*ptr)->hash != hash || key != (*ptr)->key())) {
ptr = &(*ptr)->next_hash;
}
@@ -131,7 +131,7 @@ class HandleTable {
uint32_t count = 0;
for (uint32_t i = 0; i < length_; i++) {
LRUHandle* h = list_[i];
- while (h != NULL) {
+ while (h != nullptr) {
LRUHandle* next = h->next_hash;
uint32_t hash = h->hash;
LRUHandle** ptr = &new_list[hash & (new_length - 1)];
@@ -255,7 +255,7 @@ void LRUCache::LRU_Append(LRUHandle* list, LRUHandle* e) {
Cache::Handle* LRUCache::Lookup(const Slice& key, uint32_t hash) {
MutexLock l(&mutex_);
LRUHandle* e = table_.Lookup(key, hash);
- if (e != NULL) {
+ if (e != nullptr) {
Ref(e);
}
return reinterpret_cast<Cache::Handle*>(e);
@@ -290,7 +290,7 @@ Cache::Handle* LRUCache::Insert(
FinishErase(table_.Insert(e));
} else { // don't cache. (capacity_==0 is supported and turns off caching.)
// next is read by key() in an assert, so it must be initialized
- e->next = NULL;
+ e->next = nullptr;
}
while (usage_ > capacity_ && lru_.next != &lru_) {
LRUHandle* old = lru_.next;
@@ -304,17 +304,17 @@ Cache::Handle* LRUCache::Insert(
return reinterpret_cast<Cache::Handle*>(e);
}
-// If e != NULL, finish removing *e from the cache; it has already been removed
-// from the hash table. Return whether e != NULL. Requires mutex_ held.
+// If e != nullptr, finish removing *e from the cache; it has already been
+// removed from the hash table. Return whether e != nullptr.
bool LRUCache::FinishErase(LRUHandle* e) {
- if (e != NULL) {
+ if (e != nullptr) {
assert(e->in_cache);
LRU_Remove(e);
e->in_cache = false;
usage_ -= e->charge;
Unref(e);
}
- return e != NULL;
+ return e != nullptr;
}
void LRUCache::Erase(const Slice& key, uint32_t hash) {
diff --git a/util/cache_test.cc b/util/cache_test.cc
index 246ab8e..8647feb 100644
--- a/util/cache_test.cc
+++ b/util/cache_test.cc
@@ -47,8 +47,8 @@ class CacheTest {
int Lookup(int key) {
Cache::Handle* handle = cache_->Lookup(EncodeKey(key));
- const int r = (handle == NULL) ? -1 : DecodeValue(cache_->Value(handle));
- if (handle != NULL) {
+ const int r = (handle == nullptr) ? -1 : DecodeValue(cache_->Value(handle));
+ if (handle != nullptr) {
cache_->Release(handle);
}
return r;
diff --git a/util/coding.cc b/util/coding.cc
index 21e3186..9e72613 100644
--- a/util/coding.cc
+++ b/util/coding.cc
@@ -125,14 +125,14 @@ const char* GetVarint32PtrFallback(const char* p,
return reinterpret_cast<const char*>(p);
}
}
- return NULL;
+ return nullptr;
}
bool GetVarint32(Slice* input, uint32_t* value) {
const char* p = input->data();
const char* limit = p + input->size();
const char* q = GetVarint32Ptr(p, limit, value);
- if (q == NULL) {
+ if (q == nullptr) {
return false;
} else {
*input = Slice(q, limit - q);
@@ -154,14 +154,14 @@ const char* GetVarint64Ptr(const char* p, const char* limit, uint64_t* value) {
return reinterpret_cast<const char*>(p);
}
}
- return NULL;
+ return nullptr;
}
bool GetVarint64(Slice* input, uint64_t* value) {
const char* p = input->data();
const char* limit = p + input->size();
const char* q = GetVarint64Ptr(p, limit, value);
- if (q == NULL) {
+ if (q == nullptr) {
return false;
} else {
*input = Slice(q, limit - q);
@@ -173,8 +173,8 @@ const char* GetLengthPrefixedSlice(const char* p, const char* limit,
Slice* result) {
uint32_t len;
p = GetVarint32Ptr(p, limit, &len);
- if (p == NULL) return NULL;
- if (p + len > limit) return NULL;
+ if (p == nullptr) return nullptr;
+ if (p + len > limit) return nullptr;
*result = Slice(p, len);
return p + len;
}
diff --git a/util/coding.h b/util/coding.h
index 1fb3d66..f0fa2cb 100644
--- a/util/coding.h
+++ b/util/coding.h
@@ -35,7 +35,7 @@ bool GetLengthPrefixedSlice(Slice* input, Slice* result);
// Pointer-based variants of GetVarint... These either store a value
// in *v and return a pointer just past the parsed value, or return
-// NULL on error. These routines only look at bytes in the range
+// nullptr on error. These routines only look at bytes in the range
// [p..limit-1]
const char* GetVarint32Ptr(const char* p, const char* limit, uint32_t* v);
const char* GetVarint64Ptr(const char* p, const char* limit, uint64_t* v);
diff --git a/util/coding_test.cc b/util/coding_test.cc
index 22f6adc..d315e19 100644
--- a/util/coding_test.cc
+++ b/util/coding_test.cc
@@ -89,7 +89,7 @@ TEST(Coding, Varint32) {
uint32_t actual;
const char* start = p;
p = GetVarint32Ptr(p, limit, &actual);
- ASSERT_TRUE(p != NULL);
+ ASSERT_TRUE(p != nullptr);
ASSERT_EQ(expected, actual);
ASSERT_EQ(VarintLength(actual), p - start);
}
@@ -124,19 +124,18 @@ TEST(Coding, Varint64) {
uint64_t actual;
const char* start = p;
p = GetVarint64Ptr(p, limit, &actual);
- ASSERT_TRUE(p != NULL);
+ ASSERT_TRUE(p != nullptr);
ASSERT_EQ(values[i], actual);
ASSERT_EQ(VarintLength(actual), p - start);
}
ASSERT_EQ(p, limit);
-
}
TEST(Coding, Varint32Overflow) {
uint32_t result;
std::string input("\x81\x82\x83\x84\x85\x11");
ASSERT_TRUE(GetVarint32Ptr(input.data(), input.data() + input.size(), &result)
- == NULL);
+ == nullptr);
}
TEST(Coding, Varint32Truncation) {
@@ -145,9 +144,10 @@ TEST(Coding, Varint32Truncation) {
PutVarint32(&s, large_value);
uint32_t result;
for (size_t len = 0; len < s.size() - 1; len++) {
- ASSERT_TRUE(GetVarint32Ptr(s.data(), s.data() + len, &result) == NULL);
+ ASSERT_TRUE(GetVarint32Ptr(s.data(), s.data() + len, &result) == nullptr);
}
- ASSERT_TRUE(GetVarint32Ptr(s.data(), s.data() + s.size(), &result) != NULL);
+ ASSERT_TRUE(
+ GetVarint32Ptr(s.data(), s.data() + s.size(), &result) != nullptr);
ASSERT_EQ(large_value, result);
}
@@ -155,7 +155,7 @@ TEST(Coding, Varint64Overflow) {
uint64_t result;
std::string input("\x81\x82\x83\x84\x85\x81\x82\x83\x84\x85\x11");
ASSERT_TRUE(GetVarint64Ptr(input.data(), input.data() + input.size(), &result)
- == NULL);
+ == nullptr);
}
TEST(Coding, Varint64Truncation) {
@@ -164,9 +164,10 @@ TEST(Coding, Varint64Truncation) {
PutVarint64(&s, large_value);
uint64_t result;
for (size_t len = 0; len < s.size() - 1; len++) {
- ASSERT_TRUE(GetVarint64Ptr(s.data(), s.data() + len, &result) == NULL);
+ ASSERT_TRUE(GetVarint64Ptr(s.data(), s.data() + len, &result) == nullptr);
}
- ASSERT_TRUE(GetVarint64Ptr(s.data(), s.data() + s.size(), &result) != NULL);
+ ASSERT_TRUE(
+ GetVarint64Ptr(s.data(), s.data() + s.size(), &result) != nullptr);
ASSERT_EQ(large_value, result);
}
diff --git a/util/env.cc b/util/env.cc
index c58a082..40a1363 100644
--- a/util/env.cc
+++ b/util/env.cc
@@ -29,7 +29,7 @@ FileLock::~FileLock() {
}
void Log(Logger* info_log, const char* format, ...) {
- if (info_log != NULL) {
+ if (info_log != nullptr) {
va_list ap;
va_start(ap, format);
info_log->Logv(format, ap);
diff --git a/util/env_posix.cc b/util/env_posix.cc
index 4bfaf6c..e758d5f 100644
--- a/util/env_posix.cc
+++ b/util/env_posix.cc
@@ -282,7 +282,7 @@ class PosixWritableFile : public WritableFile {
const char* sep = strrchr(f, '/');
Slice basename;
std::string dir;
- if (sep == NULL) {
+ if (sep == nullptr) {
dir = ".";
basename = f;
} else {
@@ -390,7 +390,7 @@ class PosixEnv : public Env {
SequentialFile** result) {
int fd = open(fname.c_str(), O_RDONLY);
if (fd < 0) {
- *result = NULL;
+ *result = nullptr;
return PosixError(fname, errno);
} else {
*result = new PosixSequentialFile(fname, fd);
@@ -400,7 +400,7 @@ class PosixEnv : public Env {
virtual Status NewRandomAccessFile(const std::string& fname,
RandomAccessFile** result) {
- *result = NULL;
+ *result = nullptr;
Status s;
int fd = open(fname.c_str(), O_RDONLY);
if (fd < 0) {
@@ -409,7 +409,7 @@ class PosixEnv : public Env {
uint64_t size;
s = GetFileSize(fname, &size);
if (s.ok()) {
- void* base = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
+ void* base = mmap(nullptr, size, PROT_READ, MAP_SHARED, fd, 0);
if (base != MAP_FAILED) {
*result = new PosixMmapReadableFile(fname, base, size, &mmap_limit_);
} else {
@@ -431,7 +431,7 @@ class PosixEnv : public Env {
Status s;
int fd = open(fname.c_str(), O_TRUNC | O_WRONLY | O_CREAT, 0644);
if (fd < 0) {
- *result = NULL;
+ *result = nullptr;
s = PosixError(fname, errno);
} else {
*result = new PosixWritableFile(fname, fd);
@@ -444,7 +444,7 @@ class PosixEnv : public Env {
Status s;
int fd = open(fname.c_str(), O_APPEND | O_WRONLY | O_CREAT, 0644);
if (fd < 0) {
- *result = NULL;
+ *result = nullptr;
s = PosixError(fname, errno);
} else {
*result = new PosixWritableFile(fname, fd);
@@ -460,11 +460,11 @@ class PosixEnv : public Env {
std::vector<std::string>* result) {
result->clear();
DIR* d = opendir(dir.c_str());
- if (d == NULL) {
+ if (d == nullptr) {
return PosixError(dir, errno);
}
struct dirent* entry;
- while ((entry = readdir(d)) != NULL) {
+ while ((entry = readdir(d)) != nullptr) {
result->push_back(entry->d_name);
}
closedir(d);
@@ -516,7 +516,7 @@ class PosixEnv : public Env {
}
virtual Status LockFile(const std::string& fname, FileLock** lock) {
- *lock = NULL;
+ *lock = nullptr;
Status result;
int fd = open(fname.c_str(), O_RDWR | O_CREAT, 0644);
if (fd < 0) {
@@ -576,8 +576,8 @@ class PosixEnv : public Env {
virtual Status NewLogger(const std::string& fname, Logger** result) {
FILE* f = fopen(fname.c_str(), "w");
- if (f == NULL) {
- *result = NULL;
+ if (f == nullptr) {
+ *result = nullptr;
return PosixError(fname, errno);
} else {
*result = new PosixLogger(f, &PosixEnv::gettid);
@@ -587,7 +587,7 @@ class PosixEnv : public Env {
virtual uint64_t NowMicros() {
struct timeval tv;
- gettimeofday(&tv, NULL);
+ gettimeofday(&tv, nullptr);
return static_cast<uint64_t>(tv.tv_sec) * 1000000 + tv.tv_usec;
}
@@ -607,7 +607,7 @@ class PosixEnv : public Env {
void BGThread();
static void* BGThreadWrapper(void* arg) {
reinterpret_cast<PosixEnv*>(arg)->BGThread();
- return NULL;
+ return nullptr;
}
pthread_mutex_t mu_;
@@ -657,8 +657,8 @@ PosixEnv::PosixEnv()
: started_bgthread_(false),
mmap_limit_(MaxMmaps()),
fd_limit_(MaxOpenFiles()) {
- PthreadCall("mutex_init", pthread_mutex_init(&mu_, NULL));
- PthreadCall("cvar_init", pthread_cond_init(&bgsignal_, NULL));
+ PthreadCall("mutex_init", pthread_mutex_init(&mu_, nullptr));
+ PthreadCall("cvar_init", pthread_cond_init(&bgsignal_, nullptr));
}
void PosixEnv::Schedule(void (*function)(void*), void* arg) {
@@ -669,7 +669,7 @@ void PosixEnv::Schedule(void (*function)(void*), void* arg) {
started_bgthread_ = true;
PthreadCall(
"create thread",
- pthread_create(&bgthread_, NULL, &PosixEnv::BGThreadWrapper, this));
+ pthread_create(&bgthread_, nullptr, &PosixEnv::BGThreadWrapper, this));
}
// If the queue is currently empty, the background thread may currently be
@@ -713,7 +713,7 @@ static void* StartThreadWrapper(void* arg) {
StartThreadState* state = reinterpret_cast<StartThreadState*>(arg);
state->user_function(state->arg);
delete state;
- return NULL;
+ return nullptr;
}
void PosixEnv::StartThread(void (*function)(void* arg), void* arg) {
@@ -722,7 +722,7 @@ void PosixEnv::StartThread(void (*function)(void* arg), void* arg) {
state->user_function = function;
state->arg = arg;
PthreadCall("start thread",
- pthread_create(&t, NULL, &StartThreadWrapper, state));
+ pthread_create(&t, nullptr, &StartThreadWrapper, state));
}
} // namespace
@@ -732,12 +732,12 @@ static Env* default_env;
static void InitDefaultEnv() { default_env = new PosixEnv; }
void EnvPosixTestHelper::SetReadOnlyFDLimit(int limit) {
- assert(default_env == NULL);
+ assert(default_env == nullptr);
open_read_only_file_limit = limit;
}
void EnvPosixTestHelper::SetReadOnlyMMapLimit(int limit) {
- assert(default_env == NULL);
+ assert(default_env == nullptr);
mmap_limit = limit;
}
diff --git a/util/env_posix_test.cc b/util/env_posix_test.cc
index 295f8ae..e28df9a 100644
--- a/util/env_posix_test.cc
+++ b/util/env_posix_test.cc
@@ -32,7 +32,7 @@ TEST(EnvPosixTest, TestOpenOnRead) {
std::string test_file = test_dir + "/open_on_read.txt";
FILE* f = fopen(test_file.c_str(), "w");
- ASSERT_TRUE(f != NULL);
+ ASSERT_TRUE(f != nullptr);
const char kFileData[] = "abcdefghijklmnopqrstuvwxyz";
fputs(kFileData, f);
fclose(f);
diff --git a/util/env_test.cc b/util/env_test.cc
index fd89b4c..070109b 100644
--- a/util/env_test.cc
+++ b/util/env_test.cc
@@ -77,14 +77,14 @@ TEST(EnvTest, ReadWrite) {
}
TEST(EnvTest, RunImmediately) {
- port::AtomicPointer called (NULL);
+ port::AtomicPointer called(nullptr);
env_->Schedule(&SetBool, &called);
env_->SleepForMicroseconds(kDelayMicros);
- ASSERT_TRUE(called.NoBarrier_Load() != NULL);
+ ASSERT_TRUE(called.NoBarrier_Load() != nullptr);
}
TEST(EnvTest, RunMany) {
- port::AtomicPointer last_id (NULL);
+ port::AtomicPointer last_id(nullptr);
struct CB {
port::AtomicPointer* last_id_ptr; // Pointer to shared slot
diff --git a/util/options.cc b/util/options.cc
index b5e6227..351fa39 100644
--- a/util/options.cc
+++ b/util/options.cc
@@ -15,16 +15,16 @@ Options::Options()
error_if_exists(false),
paranoid_checks(false),
env(Env::Default()),
- info_log(NULL),
+ info_log(nullptr),
write_buffer_size(4<<20),
max_open_files(1000),
- block_cache(NULL),
+ block_cache(nullptr),
block_size(4096),
block_restart_interval(16),
max_file_size(2<<20),
compression(kSnappyCompression),
reuse_logs(false),
- filter_policy(NULL) {
+ filter_policy(nullptr) {
}
} // namespace leveldb
diff --git a/util/posix_logger.h b/util/posix_logger.h
index 9741b1a..1909e61 100644
--- a/util/posix_logger.h
+++ b/util/posix_logger.h
@@ -45,7 +45,7 @@ class PosixLogger : public Logger {
char* limit = base + bufsize;
struct timeval now_tv;
- gettimeofday(&now_tv, NULL);
+ gettimeofday(&now_tv, nullptr);
const time_t seconds = now_tv.tv_sec;
struct tm t;
localtime_r(&seconds, &t);
diff --git a/util/status.cc b/util/status.cc
index a44f35b..5591381 100644
--- a/util/status.cc
+++ b/util/status.cc
@@ -34,7 +34,7 @@ Status::Status(Code code, const Slice& msg, const Slice& msg2) {
}
std::string Status::ToString() const {
- if (state_ == NULL) {
+ if (state_ == nullptr) {
return "OK";
} else {
char tmp[30];
diff --git a/util/testharness.cc b/util/testharness.cc
index 95f025f..37ba410 100644
--- a/util/testharness.cc
+++ b/util/testharness.cc
@@ -26,7 +26,7 @@ std::vector<Test>* tests;
}
bool RegisterTest(const char* base, const char* name, void (*func)()) {
- if (tests == NULL) {
+ if (tests == nullptr) {
tests = new std::vector<Test>;
}
Test t;
@@ -41,14 +41,14 @@ int RunAllTests() {
const char* matcher = getenv("LEVELDB_TESTS");
int num = 0;
- if (tests != NULL) {
+ if (tests != nullptr) {
for (size_t i = 0; i < tests->size(); i++) {
const Test& t = (*tests)[i];
- if (matcher != NULL) {
+ if (matcher != nullptr) {
std::string name = t.base;
name.push_back('.');
name.append(t.name);
- if (strstr(name.c_str(), matcher) == NULL) {
+ if (strstr(name.c_str(), matcher) == nullptr) {
continue;
}
}
@@ -70,7 +70,7 @@ std::string TmpDir() {
int RandomSeed() {
const char* env = getenv("TEST_RANDOM_SEED");
- int result = (env != NULL ? atoi(env) : 301);
+ int result = (env != nullptr ? atoi(env) : 301);
if (result <= 0) {
result = 301;
}
diff --git a/util/testutil.h b/util/testutil.h
index 8726bf7..dc77ac3 100644
--- a/util/testutil.h
+++ b/util/testutil.h
@@ -40,7 +40,7 @@ class ErrorEnv : public EnvWrapper {
WritableFile** result) {
if (writable_file_error_) {
++num_writable_file_errors_;
- *result = NULL;
+ *result = nullptr;
return Status::IOError(fname, "fake error");
}
return target()->NewWritableFile(fname, result);
@@ -50,7 +50,7 @@ class ErrorEnv : public EnvWrapper {
WritableFile** result) {
if (writable_file_error_) {
++num_writable_file_errors_;
- *result = NULL;
+ *result = nullptr;
return Status::IOError(fname, "fake error");
}
return target()->NewAppendableFile(fname, result);