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
main
Bruce Mitchener 7 years ago committed by Facebook Github Bot
parent f021f1d9e1
commit 0de710f5b8
  1. 8
      db/c.cc
  2. 2
      db/db_compaction_filter_test.cc
  3. 8
      db/db_tailing_iter_test.cc
  4. 6
      db/deletefile_test.cc
  5. 10
      db/fault_injection_test.cc
  6. 6
      db/log_test.cc
  7. 6
      db/version_set.cc
  8. 2
      env/env_posix.cc
  9. 6
      env/mock_env.cc
  10. 4
      include/rocksdb/env.h
  11. 2
      port/port_posix.cc
  12. 2
      util/dynamic_bloom.cc
  13. 2
      util/thread_list_test.cc
  14. 2
      utilities/redis/redis_list_iterator.h
  15. 6
      utilities/redis/redis_lists.cc

@ -3026,7 +3026,7 @@ void rocksdb_sstfilewriter_delete(rocksdb_sstfilewriter_t* writer,
void rocksdb_sstfilewriter_finish(rocksdb_sstfilewriter_t* writer, void rocksdb_sstfilewriter_finish(rocksdb_sstfilewriter_t* writer,
char** errptr) { char** errptr) {
SaveError(errptr, writer->rep->Finish(NULL)); SaveError(errptr, writer->rep->Finish(nullptr));
} }
void rocksdb_sstfilewriter_destroy(rocksdb_sstfilewriter_t* writer) { void rocksdb_sstfilewriter_destroy(rocksdb_sstfilewriter_t* writer) {
@ -3808,7 +3808,7 @@ rocksdb_pinnableslice_t* rocksdb_get_pinned(
if (!s.IsNotFound()) { if (!s.IsNotFound()) {
SaveError(errptr, s); SaveError(errptr, s);
} }
return NULL; return nullptr;
} }
return v; return v;
} }
@ -3825,7 +3825,7 @@ rocksdb_pinnableslice_t* rocksdb_get_pinned_cf(
if (!s.IsNotFound()) { if (!s.IsNotFound()) {
SaveError(errptr, s); SaveError(errptr, s);
} }
return NULL; return nullptr;
} }
return v; return v;
} }
@ -3836,7 +3836,7 @@ const char* rocksdb_pinnableslice_value(const rocksdb_pinnableslice_t* v,
size_t* vlen) { size_t* vlen) {
if (!v) { if (!v) {
*vlen = 0; *vlen = 0;
return NULL; return nullptr;
} }
*vlen = v->rep.size(); *vlen = v->rep.size();

@ -767,7 +767,7 @@ TEST_F(DBTestCompactionFilter, CompactionFilterIgnoreSnapshot) {
iter->Next(); iter->Next();
} }
ASSERT_EQ(count, 6); ASSERT_EQ(count, 6);
read_options.snapshot = 0; read_options.snapshot = nullptr;
std::unique_ptr<Iterator> iter1(db_->NewIterator(read_options)); std::unique_ptr<Iterator> iter1(db_->NewIterator(read_options));
iter1->SeekToFirst(); iter1->SeekToFirst();
count = 0; count = 0;

@ -214,9 +214,9 @@ TEST_F(DBTestTailingIterator, TailingIteratorTrimSeekToNext) {
} }
ASSERT_TRUE(file_iters_renewed_null); ASSERT_TRUE(file_iters_renewed_null);
ASSERT_TRUE(file_iters_renewed_copy); ASSERT_TRUE(file_iters_renewed_copy);
iter = 0; iter = nullptr;
itern = 0; itern = nullptr;
iterh = 0; iterh = nullptr;
BlockBasedTableOptions table_options; BlockBasedTableOptions table_options;
table_options.no_block_cache = true; table_options.no_block_cache = true;
table_options.block_cache_compressed = nullptr; table_options.block_cache_compressed = nullptr;
@ -229,7 +229,7 @@ TEST_F(DBTestTailingIterator, TailingIteratorTrimSeekToNext) {
Slice target1(buf5, 20); Slice target1(buf5, 20);
iteri->Seek(target1); iteri->Seek(target1);
ASSERT_TRUE(iteri->status().IsIncomplete()); ASSERT_TRUE(iteri->status().IsIncomplete());
iteri = 0; iteri = nullptr;
read_options.read_tier = kReadAllTier; read_options.read_tier = kReadAllTier;
options.table_factory.reset(NewBlockBasedTableFactory()); options.table_factory.reset(NewBlockBasedTableFactory());

@ -228,7 +228,7 @@ TEST_F(DeleteFileTest, PurgeObsoleteFilesTest) {
// this time, we keep an iterator alive // this time, we keep an iterator alive
ReopenDB(true); ReopenDB(true);
Iterator *itr = 0; Iterator *itr = nullptr;
CreateTwoLevels(); CreateTwoLevels();
itr = db_->NewIterator(ReadOptions()); itr = db_->NewIterator(ReadOptions());
db_->CompactRange(compact_options, &first_slice, &last_slice); db_->CompactRange(compact_options, &first_slice, &last_slice);
@ -249,7 +249,7 @@ TEST_F(DeleteFileTest, BackgroundPurgeTest) {
Slice first_slice(first), last_slice(last); Slice first_slice(first), last_slice(last);
// We keep an iterator alive // We keep an iterator alive
Iterator* itr = 0; Iterator* itr = nullptr;
CreateTwoLevels(); CreateTwoLevels();
ReadOptions options; ReadOptions options;
options.background_purge_on_iterator_cleanup = true; options.background_purge_on_iterator_cleanup = true;
@ -289,7 +289,7 @@ TEST_F(DeleteFileTest, BackgroundPurgeCopyOptions) {
Slice first_slice(first), last_slice(last); Slice first_slice(first), last_slice(last);
// We keep an iterator alive // We keep an iterator alive
Iterator* itr = 0; Iterator* itr = nullptr;
CreateTwoLevels(); CreateTwoLevels();
ReadOptions* options = new ReadOptions(); ReadOptions* options = new ReadOptions();
options->background_purge_on_iterator_cleanup = true; options->background_purge_on_iterator_cleanup = true;

@ -76,8 +76,8 @@ class FaultInjectionTest : public testing::Test,
sync_use_wal_(false), sync_use_wal_(false),
sync_use_compact_(true), sync_use_compact_(true),
base_env_(nullptr), base_env_(nullptr),
env_(NULL), env_(nullptr),
db_(NULL) { db_(nullptr) {
} }
~FaultInjectionTest() { ~FaultInjectionTest() {
@ -139,9 +139,9 @@ class FaultInjectionTest : public testing::Test,
} }
Status NewDB() { Status NewDB() {
assert(db_ == NULL); assert(db_ == nullptr);
assert(tiny_cache_ == nullptr); assert(tiny_cache_ == nullptr);
assert(env_ == NULL); assert(env_ == nullptr);
env_ = env_ =
new FaultInjectionTestEnv(base_env_ ? base_env_.get() : Env::Default()); new FaultInjectionTestEnv(base_env_ ? base_env_.get() : Env::Default());
@ -176,7 +176,7 @@ class FaultInjectionTest : public testing::Test,
Status s = DestroyDB(dbname_, options_); Status s = DestroyDB(dbname_, options_);
delete env_; delete env_;
env_ = NULL; env_ = nullptr;
tiny_cache_.reset(); tiny_cache_.reset();

@ -163,7 +163,7 @@ class LogTest : public ::testing::TestWithParam<int> {
source_holder_( source_holder_(
test::GetSequentialFileReader(new StringSource(reader_contents_))), test::GetSequentialFileReader(new StringSource(reader_contents_))),
writer_(std::move(dest_holder_), 123, GetParam()), 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) { 0 /*initial_offset*/, 123) {
int header_size = GetParam() ? kRecyclableHeaderSize : kHeaderSize; int header_size = GetParam() ? kRecyclableHeaderSize : kHeaderSize;
initial_offset_last_record_offsets_[0] = 0; initial_offset_last_record_offsets_[0] = 0;
@ -271,7 +271,7 @@ class LogTest : public ::testing::TestWithParam<int> {
unique_ptr<SequentialFileReader> file_reader( unique_ptr<SequentialFileReader> file_reader(
test::GetSequentialFileReader(new StringSource(reader_contents_))); test::GetSequentialFileReader(new StringSource(reader_contents_)));
unique_ptr<Reader> offset_reader( unique_ptr<Reader> 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)); true /*checksum*/, WrittenBytes() + offset_past_end, 123));
Slice record; Slice record;
std::string scratch; std::string scratch;
@ -284,7 +284,7 @@ class LogTest : public ::testing::TestWithParam<int> {
unique_ptr<SequentialFileReader> file_reader( unique_ptr<SequentialFileReader> file_reader(
test::GetSequentialFileReader(new StringSource(reader_contents_))); test::GetSequentialFileReader(new StringSource(reader_contents_)));
unique_ptr<Reader> offset_reader( unique_ptr<Reader> offset_reader(
new Reader(NULL, std::move(file_reader), &report_, new Reader(nullptr, std::move(file_reader), &report_,
true /*checksum*/, initial_offset, 123)); true /*checksum*/, initial_offset, 123));
Slice record; Slice record;
std::string scratch; std::string scratch;

@ -3016,7 +3016,7 @@ Status VersionSet::Recover(
{ {
VersionSet::LogReporter reporter; VersionSet::LogReporter reporter;
reporter.status = &s; 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); true /*checksum*/, 0 /*initial_offset*/, 0);
Slice record; Slice record;
std::string scratch; std::string scratch;
@ -3285,7 +3285,7 @@ Status VersionSet::ListColumnFamilies(std::vector<std::string>* column_families,
column_family_names.insert({0, kDefaultColumnFamilyName}); column_family_names.insert({0, kDefaultColumnFamilyName});
VersionSet::LogReporter reporter; VersionSet::LogReporter reporter;
reporter.status = &s; 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); 0 /*initial_offset*/, 0);
Slice record; Slice record;
std::string scratch; std::string scratch;
@ -3445,7 +3445,7 @@ Status VersionSet::DumpManifest(Options& options, std::string& dscname,
{ {
VersionSet::LogReporter reporter; VersionSet::LogReporter reporter;
reporter.status = &s; 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); true /*checksum*/, 0 /*initial_offset*/, 0);
Slice record; Slice record;
std::string scratch; std::string scratch;

2
env/env_posix.cc vendored

@ -647,7 +647,7 @@ class PosixEnv : public Env {
virtual void Schedule(void (*function)(void* arg1), void* arg, virtual void Schedule(void (*function)(void* arg1), void* arg,
Priority pri = LOW, void* tag = nullptr, 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; virtual int UnSchedule(void* arg, Priority pri) override;

6
env/mock_env.cc vendored

@ -454,7 +454,7 @@ Status MockEnv::NewSequentialFile(const std::string& fname,
auto fn = NormalizePath(fname); auto fn = NormalizePath(fname);
MutexLock lock(&mutex_); MutexLock lock(&mutex_);
if (file_map_.find(fn) == file_map_.end()) { if (file_map_.find(fn) == file_map_.end()) {
*result = NULL; *result = nullptr;
return Status::IOError(fn, "File not found"); return Status::IOError(fn, "File not found");
} }
auto* f = file_map_[fn]; auto* f = file_map_[fn];
@ -471,7 +471,7 @@ Status MockEnv::NewRandomAccessFile(const std::string& fname,
auto fn = NormalizePath(fname); auto fn = NormalizePath(fname);
MutexLock lock(&mutex_); MutexLock lock(&mutex_);
if (file_map_.find(fn) == file_map_.end()) { if (file_map_.find(fn) == file_map_.end()) {
*result = NULL; *result = nullptr;
return Status::IOError(fn, "File not found"); return Status::IOError(fn, "File not found");
} }
auto* f = file_map_[fn]; auto* f = file_map_[fn];
@ -488,7 +488,7 @@ Status MockEnv::NewRandomRWFile(const std::string& fname,
auto fn = NormalizePath(fname); auto fn = NormalizePath(fname);
MutexLock lock(&mutex_); MutexLock lock(&mutex_);
if (file_map_.find(fn) == file_map_.end()) { if (file_map_.find(fn) == file_map_.end()) {
*result = NULL; *result = nullptr;
return Status::IOError(fn, "File not found"); return Status::IOError(fn, "File not found");
} }
auto* f = file_map_[fn]; auto* f = file_map_[fn];

@ -321,7 +321,7 @@ class Env {
// registered at the time of Schedule is invoked with arg as a parameter. // registered at the time of Schedule is invoked with arg as a parameter.
virtual void Schedule(void (*function)(void* arg), void* arg, virtual void Schedule(void (*function)(void* arg), void* arg,
Priority pri = LOW, void* tag = nullptr, 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 // 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. // 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); } Status UnlockFile(FileLock* l) override { return target_->UnlockFile(l); }
void Schedule(void (*f)(void* arg), void* a, Priority pri, 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); return target_->Schedule(f, a, pri, tag, u);
} }

@ -193,7 +193,7 @@ void *cacheline_aligned_alloc(size_t size) {
#elif ( _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600 || defined(__APPLE__)) #elif ( _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600 || defined(__APPLE__))
void *m; void *m;
errno = posix_memalign(&m, CACHE_LINE_SIZE, size); errno = posix_memalign(&m, CACHE_LINE_SIZE, size);
return errno ? NULL : m; return errno ? nullptr : m;
#else #else
return malloc(size); return malloc(size);
#endif #endif

@ -45,7 +45,7 @@ DynamicBloom::DynamicBloom(uint32_t num_probes,
kNumBlocks(0), kNumBlocks(0),
kNumProbes(num_probes), kNumProbes(num_probes),
hash_func_(hash_func == nullptr ? &BloomHash : hash_func), hash_func_(hash_func == nullptr ? &BloomHash : hash_func),
data_(0) {} data_(nullptr) {}
void DynamicBloom::SetRawData(unsigned char* raw_data, uint32_t total_bits, void DynamicBloom::SetRawData(unsigned char* raw_data, uint32_t total_bits,
uint32_t num_blocks) { uint32_t num_blocks) {

@ -47,7 +47,7 @@ class SimulatedBackgroundTask {
} }
Env::Default()->GetThreadStatusUpdater()->ClearThreadState(); Env::Default()->GetThreadStatusUpdater()->ClearThreadState();
Env::Default()->GetThreadStatusUpdater()->ClearThreadOperation(); Env::Default()->GetThreadStatusUpdater()->ClearThreadOperation();
Env::Default()->GetThreadStatusUpdater()->SetColumnFamilyInfoKey(0); Env::Default()->GetThreadStatusUpdater()->SetColumnFamilyInfoKey(nullptr);
running_count_--; running_count_--;
bg_cv_.notify_all(); bg_cv_.notify_all();
} }

@ -288,7 +288,7 @@ class RedisListIterator {
/// Will throw an exception based on the passed-in message. /// Will throw an exception based on the passed-in message.
/// This function is guaranteed to STOP THE CONTROL-FLOW. /// This function is guaranteed to STOP THE CONTROL-FLOW.
/// (i.e.: you do not have to call "return" after calling ThrowError) /// (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. // TODO: For now we ignore the msg parameter. This can be expanded later.
throw RedisListException(); throw RedisListException();
} }

@ -101,7 +101,7 @@ bool RedisLists::Index(const std::string& key, int32_t index,
if (curIndex == index && !it.Done()) { if (curIndex == index && !it.Done()) {
Slice elem; Slice elem;
it.GetCurrent(&elem); it.GetCurrent(&elem);
if (result != NULL) { if (result != nullptr) {
*result = elem.ToString(); *result = elem.ToString();
} }
@ -345,7 +345,7 @@ bool RedisLists::PopLeft(const std::string& key, std::string* result) {
db_->Put(put_option_, key, it.WriteResult()); db_->Put(put_option_, key, it.WriteResult());
// Return the value // Return the value
if (result != NULL) { if (result != nullptr) {
*result = elem.ToString(); *result = elem.ToString();
} }
return true; return true;
@ -385,7 +385,7 @@ bool RedisLists::PopRight(const std::string& key, std::string* result) {
db_->Put(put_option_, key, it.WriteResult()); db_->Put(put_option_, key, it.WriteResult());
// Return the value // Return the value
if (result != NULL) { if (result != nullptr) {
*result = elem.ToString(); *result = elem.ToString();
} }
return true; return true;

Loading…
Cancel
Save