From 0de710f5b88fe430ff2d09de8714b736a9469857 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Wed, 7 Mar 2018 12:39:19 -0800 Subject: [PATCH] Use nullptr instead of NULL / 0 more consistently. Summary: Closes https://github.com/facebook/rocksdb/pull/3569 Differential Revision: D7170968 Pulled By: yiwu-arbug fbshipit-source-id: 308a6b7dd358a04fd9a7de3d927bfd8abd57d348 --- db/c.cc | 8 ++++---- db/db_compaction_filter_test.cc | 2 +- db/db_tailing_iter_test.cc | 8 ++++---- db/deletefile_test.cc | 6 +++--- db/fault_injection_test.cc | 10 +++++----- db/log_test.cc | 6 +++--- db/version_set.cc | 6 +++--- env/env_posix.cc | 2 +- env/mock_env.cc | 6 +++--- include/rocksdb/env.h | 4 ++-- port/port_posix.cc | 2 +- util/dynamic_bloom.cc | 2 +- util/thread_list_test.cc | 2 +- utilities/redis/redis_list_iterator.h | 2 +- utilities/redis/redis_lists.cc | 6 +++--- 15 files changed, 36 insertions(+), 36 deletions(-) diff --git a/db/c.cc b/db/c.cc index 5890d722f..e6ecb3e67 100644 --- a/db/c.cc +++ b/db/c.cc @@ -3026,7 +3026,7 @@ void rocksdb_sstfilewriter_delete(rocksdb_sstfilewriter_t* writer, void rocksdb_sstfilewriter_finish(rocksdb_sstfilewriter_t* writer, char** errptr) { - SaveError(errptr, writer->rep->Finish(NULL)); + SaveError(errptr, writer->rep->Finish(nullptr)); } void rocksdb_sstfilewriter_destroy(rocksdb_sstfilewriter_t* writer) { @@ -3808,7 +3808,7 @@ rocksdb_pinnableslice_t* rocksdb_get_pinned( if (!s.IsNotFound()) { SaveError(errptr, s); } - return NULL; + return nullptr; } return v; } @@ -3825,7 +3825,7 @@ rocksdb_pinnableslice_t* rocksdb_get_pinned_cf( if (!s.IsNotFound()) { SaveError(errptr, s); } - return NULL; + return nullptr; } return v; } @@ -3836,7 +3836,7 @@ const char* rocksdb_pinnableslice_value(const rocksdb_pinnableslice_t* v, size_t* vlen) { if (!v) { *vlen = 0; - return NULL; + return nullptr; } *vlen = v->rep.size(); diff --git a/db/db_compaction_filter_test.cc b/db/db_compaction_filter_test.cc index c2ee78a33..4e06c404e 100644 --- a/db/db_compaction_filter_test.cc +++ b/db/db_compaction_filter_test.cc @@ -767,7 +767,7 @@ TEST_F(DBTestCompactionFilter, CompactionFilterIgnoreSnapshot) { iter->Next(); } ASSERT_EQ(count, 6); - read_options.snapshot = 0; + read_options.snapshot = nullptr; std::unique_ptr iter1(db_->NewIterator(read_options)); iter1->SeekToFirst(); count = 0; diff --git a/db/db_tailing_iter_test.cc b/db/db_tailing_iter_test.cc index d217828db..b1062aea6 100644 --- a/db/db_tailing_iter_test.cc +++ b/db/db_tailing_iter_test.cc @@ -214,9 +214,9 @@ TEST_F(DBTestTailingIterator, TailingIteratorTrimSeekToNext) { } ASSERT_TRUE(file_iters_renewed_null); ASSERT_TRUE(file_iters_renewed_copy); - iter = 0; - itern = 0; - iterh = 0; + iter = nullptr; + itern = nullptr; + iterh = nullptr; BlockBasedTableOptions table_options; table_options.no_block_cache = true; table_options.block_cache_compressed = nullptr; @@ -229,7 +229,7 @@ TEST_F(DBTestTailingIterator, TailingIteratorTrimSeekToNext) { Slice target1(buf5, 20); iteri->Seek(target1); ASSERT_TRUE(iteri->status().IsIncomplete()); - iteri = 0; + iteri = nullptr; read_options.read_tier = kReadAllTier; options.table_factory.reset(NewBlockBasedTableFactory()); diff --git a/db/deletefile_test.cc b/db/deletefile_test.cc index 7a480fc46..dbe779174 100644 --- a/db/deletefile_test.cc +++ b/db/deletefile_test.cc @@ -228,7 +228,7 @@ TEST_F(DeleteFileTest, PurgeObsoleteFilesTest) { // this time, we keep an iterator alive ReopenDB(true); - Iterator *itr = 0; + Iterator *itr = nullptr; CreateTwoLevels(); itr = db_->NewIterator(ReadOptions()); db_->CompactRange(compact_options, &first_slice, &last_slice); @@ -249,7 +249,7 @@ TEST_F(DeleteFileTest, BackgroundPurgeTest) { Slice first_slice(first), last_slice(last); // We keep an iterator alive - Iterator* itr = 0; + Iterator* itr = nullptr; CreateTwoLevels(); ReadOptions options; options.background_purge_on_iterator_cleanup = true; @@ -289,7 +289,7 @@ TEST_F(DeleteFileTest, BackgroundPurgeCopyOptions) { Slice first_slice(first), last_slice(last); // We keep an iterator alive - Iterator* itr = 0; + Iterator* itr = nullptr; CreateTwoLevels(); ReadOptions* options = new ReadOptions(); options->background_purge_on_iterator_cleanup = true; diff --git a/db/fault_injection_test.cc b/db/fault_injection_test.cc index 70a36b662..8feccfff9 100644 --- a/db/fault_injection_test.cc +++ b/db/fault_injection_test.cc @@ -76,8 +76,8 @@ class FaultInjectionTest : public testing::Test, sync_use_wal_(false), sync_use_compact_(true), base_env_(nullptr), - env_(NULL), - db_(NULL) { + env_(nullptr), + db_(nullptr) { } ~FaultInjectionTest() { @@ -139,9 +139,9 @@ class FaultInjectionTest : public testing::Test, } Status NewDB() { - assert(db_ == NULL); + assert(db_ == nullptr); assert(tiny_cache_ == nullptr); - assert(env_ == NULL); + assert(env_ == nullptr); env_ = new FaultInjectionTestEnv(base_env_ ? base_env_.get() : Env::Default()); @@ -176,7 +176,7 @@ class FaultInjectionTest : public testing::Test, Status s = DestroyDB(dbname_, options_); delete env_; - env_ = NULL; + env_ = nullptr; tiny_cache_.reset(); diff --git a/db/log_test.cc b/db/log_test.cc index 24187e048..ee79e10af 100644 --- a/db/log_test.cc +++ b/db/log_test.cc @@ -163,7 +163,7 @@ class LogTest : public ::testing::TestWithParam { source_holder_( test::GetSequentialFileReader(new StringSource(reader_contents_))), writer_(std::move(dest_holder_), 123, GetParam()), - reader_(NULL, std::move(source_holder_), &report_, true /*checksum*/, + reader_(nullptr, std::move(source_holder_), &report_, true /*checksum*/, 0 /*initial_offset*/, 123) { int header_size = GetParam() ? kRecyclableHeaderSize : kHeaderSize; initial_offset_last_record_offsets_[0] = 0; @@ -271,7 +271,7 @@ class LogTest : public ::testing::TestWithParam { unique_ptr file_reader( test::GetSequentialFileReader(new StringSource(reader_contents_))); unique_ptr offset_reader( - new Reader(NULL, std::move(file_reader), &report_, + new Reader(nullptr, std::move(file_reader), &report_, true /*checksum*/, WrittenBytes() + offset_past_end, 123)); Slice record; std::string scratch; @@ -284,7 +284,7 @@ class LogTest : public ::testing::TestWithParam { unique_ptr file_reader( test::GetSequentialFileReader(new StringSource(reader_contents_))); unique_ptr offset_reader( - new Reader(NULL, std::move(file_reader), &report_, + new Reader(nullptr, std::move(file_reader), &report_, true /*checksum*/, initial_offset, 123)); Slice record; std::string scratch; diff --git a/db/version_set.cc b/db/version_set.cc index 3754f176e..43fe0f53f 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -3016,7 +3016,7 @@ Status VersionSet::Recover( { VersionSet::LogReporter reporter; reporter.status = &s; - log::Reader reader(NULL, std::move(manifest_file_reader), &reporter, + log::Reader reader(nullptr, std::move(manifest_file_reader), &reporter, true /*checksum*/, 0 /*initial_offset*/, 0); Slice record; std::string scratch; @@ -3285,7 +3285,7 @@ Status VersionSet::ListColumnFamilies(std::vector* column_families, column_family_names.insert({0, kDefaultColumnFamilyName}); VersionSet::LogReporter reporter; reporter.status = &s; - log::Reader reader(NULL, std::move(file_reader), &reporter, true /*checksum*/, + log::Reader reader(nullptr, std::move(file_reader), &reporter, true /*checksum*/, 0 /*initial_offset*/, 0); Slice record; std::string scratch; @@ -3445,7 +3445,7 @@ Status VersionSet::DumpManifest(Options& options, std::string& dscname, { VersionSet::LogReporter reporter; reporter.status = &s; - log::Reader reader(NULL, std::move(file_reader), &reporter, + log::Reader reader(nullptr, std::move(file_reader), &reporter, true /*checksum*/, 0 /*initial_offset*/, 0); Slice record; std::string scratch; diff --git a/env/env_posix.cc b/env/env_posix.cc index c0e936033..fa40f8fdc 100644 --- a/env/env_posix.cc +++ b/env/env_posix.cc @@ -647,7 +647,7 @@ class PosixEnv : public Env { virtual void Schedule(void (*function)(void* arg1), void* arg, Priority pri = LOW, void* tag = nullptr, - void (*unschedFunction)(void* arg) = 0) override; + void (*unschedFunction)(void* arg) = nullptr) override; virtual int UnSchedule(void* arg, Priority pri) override; diff --git a/env/mock_env.cc b/env/mock_env.cc index 3e5fbb0fb..de008afe6 100644 --- a/env/mock_env.cc +++ b/env/mock_env.cc @@ -454,7 +454,7 @@ Status MockEnv::NewSequentialFile(const std::string& fname, auto fn = NormalizePath(fname); MutexLock lock(&mutex_); if (file_map_.find(fn) == file_map_.end()) { - *result = NULL; + *result = nullptr; return Status::IOError(fn, "File not found"); } auto* f = file_map_[fn]; @@ -471,7 +471,7 @@ Status MockEnv::NewRandomAccessFile(const std::string& fname, auto fn = NormalizePath(fname); MutexLock lock(&mutex_); if (file_map_.find(fn) == file_map_.end()) { - *result = NULL; + *result = nullptr; return Status::IOError(fn, "File not found"); } auto* f = file_map_[fn]; @@ -488,7 +488,7 @@ Status MockEnv::NewRandomRWFile(const std::string& fname, auto fn = NormalizePath(fname); MutexLock lock(&mutex_); if (file_map_.find(fn) == file_map_.end()) { - *result = NULL; + *result = nullptr; return Status::IOError(fn, "File not found"); } auto* f = file_map_[fn]; diff --git a/include/rocksdb/env.h b/include/rocksdb/env.h index 005ec79b4..bd8d54286 100644 --- a/include/rocksdb/env.h +++ b/include/rocksdb/env.h @@ -321,7 +321,7 @@ class Env { // registered at the time of Schedule is invoked with arg as a parameter. virtual void Schedule(void (*function)(void* arg), void* arg, Priority pri = LOW, void* tag = nullptr, - void (*unschedFunction)(void* arg) = 0) = 0; + void (*unschedFunction)(void* arg) = nullptr) = 0; // Arrange to remove jobs for given arg from the queue_ if they are not // already scheduled. Caller is expected to have exclusive lock on arg. @@ -1029,7 +1029,7 @@ class EnvWrapper : public Env { Status UnlockFile(FileLock* l) override { return target_->UnlockFile(l); } void Schedule(void (*f)(void* arg), void* a, Priority pri, - void* tag = nullptr, void (*u)(void* arg) = 0) override { + void* tag = nullptr, void (*u)(void* arg) = nullptr) override { return target_->Schedule(f, a, pri, tag, u); } diff --git a/port/port_posix.cc b/port/port_posix.cc index 0e8c4482c..2408beeb0 100644 --- a/port/port_posix.cc +++ b/port/port_posix.cc @@ -193,7 +193,7 @@ void *cacheline_aligned_alloc(size_t size) { #elif ( _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600 || defined(__APPLE__)) void *m; errno = posix_memalign(&m, CACHE_LINE_SIZE, size); - return errno ? NULL : m; + return errno ? nullptr : m; #else return malloc(size); #endif diff --git a/util/dynamic_bloom.cc b/util/dynamic_bloom.cc index 1dabf2968..635dd98af 100644 --- a/util/dynamic_bloom.cc +++ b/util/dynamic_bloom.cc @@ -45,7 +45,7 @@ DynamicBloom::DynamicBloom(uint32_t num_probes, kNumBlocks(0), kNumProbes(num_probes), hash_func_(hash_func == nullptr ? &BloomHash : hash_func), - data_(0) {} + data_(nullptr) {} void DynamicBloom::SetRawData(unsigned char* raw_data, uint32_t total_bits, uint32_t num_blocks) { diff --git a/util/thread_list_test.cc b/util/thread_list_test.cc index 36a221bf2..a4a343a9c 100644 --- a/util/thread_list_test.cc +++ b/util/thread_list_test.cc @@ -47,7 +47,7 @@ class SimulatedBackgroundTask { } Env::Default()->GetThreadStatusUpdater()->ClearThreadState(); Env::Default()->GetThreadStatusUpdater()->ClearThreadOperation(); - Env::Default()->GetThreadStatusUpdater()->SetColumnFamilyInfoKey(0); + Env::Default()->GetThreadStatusUpdater()->SetColumnFamilyInfoKey(nullptr); running_count_--; bg_cv_.notify_all(); } diff --git a/utilities/redis/redis_list_iterator.h b/utilities/redis/redis_list_iterator.h index 1c4bc11e5..7bfe20690 100644 --- a/utilities/redis/redis_list_iterator.h +++ b/utilities/redis/redis_list_iterator.h @@ -288,7 +288,7 @@ class RedisListIterator { /// Will throw an exception based on the passed-in message. /// This function is guaranteed to STOP THE CONTROL-FLOW. /// (i.e.: you do not have to call "return" after calling ThrowError) - void ThrowError(const char* const /*msg*/ = NULL) { + void ThrowError(const char* const /*msg*/ = nullptr) { // TODO: For now we ignore the msg parameter. This can be expanded later. throw RedisListException(); } diff --git a/utilities/redis/redis_lists.cc b/utilities/redis/redis_lists.cc index 2b38a2da4..3ba7470ec 100644 --- a/utilities/redis/redis_lists.cc +++ b/utilities/redis/redis_lists.cc @@ -101,7 +101,7 @@ bool RedisLists::Index(const std::string& key, int32_t index, if (curIndex == index && !it.Done()) { Slice elem; it.GetCurrent(&elem); - if (result != NULL) { + if (result != nullptr) { *result = elem.ToString(); } @@ -345,7 +345,7 @@ bool RedisLists::PopLeft(const std::string& key, std::string* result) { db_->Put(put_option_, key, it.WriteResult()); // Return the value - if (result != NULL) { + if (result != nullptr) { *result = elem.ToString(); } return true; @@ -385,7 +385,7 @@ bool RedisLists::PopRight(const std::string& key, std::string* result) { db_->Put(put_option_, key, it.WriteResult()); // Return the value - if (result != NULL) { + if (result != nullptr) { *result = elem.ToString(); } return true;