Skip to content

Commit 09217fd

Browse files
committed
Replace NULL with nullptr in C++ files.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=192365747
1 parent 6a3b915 commit 09217fd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+575
-570
lines changed

db/builder.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Status BuildTable(const std::string& dbname,
5656
s = file->Close();
5757
}
5858
delete file;
59-
file = NULL;
59+
file = nullptr;
6060

6161
if (s.ok()) {
6262
// Verify that the table is usable

db/c.cc

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ struct leveldb_env_t {
129129
};
130130

131131
static bool SaveError(char** errptr, const Status& s) {
132-
assert(errptr != NULL);
132+
assert(errptr != nullptr);
133133
if (s.ok()) {
134134
return false;
135-
} else if (*errptr == NULL) {
135+
} else if (*errptr == nullptr) {
136136
*errptr = strdup(s.ToString().c_str());
137137
} else {
138138
// TODO(sanjay): Merge with existing error?
@@ -154,7 +154,7 @@ leveldb_t* leveldb_open(
154154
char** errptr) {
155155
DB* db;
156156
if (SaveError(errptr, DB::Open(options->rep, std::string(name), &db))) {
157-
return NULL;
157+
return nullptr;
158158
}
159159
leveldb_t* result = new leveldb_t;
160160
result->rep = db;
@@ -199,7 +199,7 @@ char* leveldb_get(
199199
const char* key, size_t keylen,
200200
size_t* vallen,
201201
char** errptr) {
202-
char* result = NULL;
202+
char* result = nullptr;
203203
std::string tmp;
204204
Status s = db->rep->Get(options->rep, Slice(key, keylen), &tmp);
205205
if (s.ok()) {
@@ -244,7 +244,7 @@ char* leveldb_property_value(
244244
// We use strdup() since we expect human readable output.
245245
return strdup(tmp.c_str());
246246
} else {
247-
return NULL;
247+
return nullptr;
248248
}
249249
}
250250

@@ -269,9 +269,9 @@ void leveldb_compact_range(
269269
const char* limit_key, size_t limit_key_len) {
270270
Slice a, b;
271271
db->rep->CompactRange(
272-
// Pass NULL Slice if corresponding "const char*" is NULL
273-
(start_key ? (a = Slice(start_key, start_key_len), &a) : NULL),
274-
(limit_key ? (b = Slice(limit_key, limit_key_len), &b) : NULL));
272+
// Pass null Slice if corresponding "const char*" is null
273+
(start_key ? (a = Slice(start_key, start_key_len), &a) : nullptr),
274+
(limit_key ? (b = Slice(limit_key, limit_key_len), &b) : nullptr));
275275
}
276276

277277
void leveldb_destroy_db(
@@ -418,11 +418,11 @@ void leveldb_options_set_paranoid_checks(
418418
}
419419

420420
void leveldb_options_set_env(leveldb_options_t* opt, leveldb_env_t* env) {
421-
opt->rep.env = (env ? env->rep : NULL);
421+
opt->rep.env = (env ? env->rep : nullptr);
422422
}
423423

424424
void leveldb_options_set_info_log(leveldb_options_t* opt, leveldb_logger_t* l) {
425-
opt->rep.info_log = (l ? l->rep : NULL);
425+
opt->rep.info_log = (l ? l->rep : nullptr);
426426
}
427427

428428
void leveldb_options_set_write_buffer_size(leveldb_options_t* opt, size_t s) {
@@ -517,7 +517,7 @@ leveldb_filterpolicy_t* leveldb_filterpolicy_create_bloom(int bits_per_key) {
517517
};
518518
Wrapper* wrapper = new Wrapper;
519519
wrapper->rep_ = NewBloomFilterPolicy(bits_per_key);
520-
wrapper->state_ = NULL;
520+
wrapper->state_ = nullptr;
521521
wrapper->destructor_ = &Wrapper::DoNothing;
522522
return wrapper;
523523
}
@@ -544,7 +544,7 @@ void leveldb_readoptions_set_fill_cache(
544544
void leveldb_readoptions_set_snapshot(
545545
leveldb_readoptions_t* opt,
546546
const leveldb_snapshot_t* snap) {
547-
opt->rep.snapshot = (snap ? snap->rep : NULL);
547+
opt->rep.snapshot = (snap ? snap->rep : nullptr);
548548
}
549549

550550
leveldb_writeoptions_t* leveldb_writeoptions_create() {
@@ -586,7 +586,7 @@ void leveldb_env_destroy(leveldb_env_t* env) {
586586
char* leveldb_env_get_test_directory(leveldb_env_t* env) {
587587
std::string result;
588588
if (!env->rep->GetTestDirectory(&result).ok()) {
589-
return NULL;
589+
return nullptr;
590590
}
591591

592592
char* buffer = static_cast<char*>(malloc(result.size() + 1));

db/corruption_test.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class CorruptionTest {
3939
dbname_ = test::TmpDir() + "/corruption_test";
4040
DestroyDB(dbname_, options_);
4141

42-
db_ = NULL;
42+
db_ = nullptr;
4343
options_.create_if_missing = true;
4444
Reopen();
4545
options_.create_if_missing = false;
@@ -53,7 +53,7 @@ class CorruptionTest {
5353

5454
Status TryReopen() {
5555
delete db_;
56-
db_ = NULL;
56+
db_ = nullptr;
5757
return DB::Open(options_, dbname_, &db_);
5858
}
5959

@@ -63,7 +63,7 @@ class CorruptionTest {
6363

6464
void RepairDB() {
6565
delete db_;
66-
db_ = NULL;
66+
db_ = nullptr;
6767
ASSERT_OK(::leveldb::RepairDB(dbname_, options_));
6868
}
6969

@@ -237,8 +237,8 @@ TEST(CorruptionTest, TableFile) {
237237
Build(100);
238238
DBImpl* dbi = reinterpret_cast<DBImpl*>(db_);
239239
dbi->TEST_CompactMemTable();
240-
dbi->TEST_CompactRange(0, NULL, NULL);
241-
dbi->TEST_CompactRange(1, NULL, NULL);
240+
dbi->TEST_CompactRange(0, nullptr, nullptr);
241+
dbi->TEST_CompactRange(1, nullptr, nullptr);
242242

243243
Corrupt(kTableFile, 100, 1);
244244
Check(90, 99);
@@ -251,8 +251,8 @@ TEST(CorruptionTest, TableFileRepair) {
251251
Build(100);
252252
DBImpl* dbi = reinterpret_cast<DBImpl*>(db_);
253253
dbi->TEST_CompactMemTable();
254-
dbi->TEST_CompactRange(0, NULL, NULL);
255-
dbi->TEST_CompactRange(1, NULL, NULL);
254+
dbi->TEST_CompactRange(0, nullptr, nullptr);
255+
dbi->TEST_CompactRange(1, nullptr, nullptr);
256256

257257
Corrupt(kTableFile, 100, 1);
258258
RepairDB();
@@ -302,7 +302,7 @@ TEST(CorruptionTest, CorruptedDescriptor) {
302302
ASSERT_OK(db_->Put(WriteOptions(), "foo", "hello"));
303303
DBImpl* dbi = reinterpret_cast<DBImpl*>(db_);
304304
dbi->TEST_CompactMemTable();
305-
dbi->TEST_CompactRange(0, NULL, NULL);
305+
dbi->TEST_CompactRange(0, nullptr, nullptr);
306306

307307
Corrupt(kDescriptorFile, 0, 1000);
308308
Status s = TryReopen();
@@ -343,7 +343,7 @@ TEST(CorruptionTest, CompactionInputErrorParanoid) {
343343
Corrupt(kTableFile, 100, 1);
344344
env_.SleepForMicroseconds(100000);
345345
}
346-
dbi->CompactRange(NULL, NULL);
346+
dbi->CompactRange(nullptr, nullptr);
347347

348348
// Write must fail because of corrupted table
349349
std::string tmp1, tmp2;

db/db_bench.cc

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ static bool FLAGS_use_existing_db = false;
111111
static bool FLAGS_reuse_logs = false;
112112

113113
// Use the db with the following name.
114-
static const char* FLAGS_db = NULL;
114+
static const char* FLAGS_db = nullptr;
115115

116116
namespace leveldb {
117117

118118
namespace {
119-
leveldb::Env* g_env = NULL;
119+
leveldb::Env* g_env = nullptr;
120120

121121
// Helper for quickly generating random data.
122122
class RandomGenerator {
@@ -370,18 +370,18 @@ class Benchmark {
370370
kMajorVersion, kMinorVersion);
371371

372372
#if defined(__linux)
373-
time_t now = time(NULL);
373+
time_t now = time(nullptr);
374374
fprintf(stderr, "Date: %s", ctime(&now)); // ctime() adds newline
375375

376376
FILE* cpuinfo = fopen("/proc/cpuinfo", "r");
377-
if (cpuinfo != NULL) {
377+
if (cpuinfo != nullptr) {
378378
char line[1000];
379379
int num_cpus = 0;
380380
std::string cpu_type;
381381
std::string cache_size;
382-
while (fgets(line, sizeof(line), cpuinfo) != NULL) {
382+
while (fgets(line, sizeof(line), cpuinfo) != nullptr) {
383383
const char* sep = strchr(line, ':');
384-
if (sep == NULL) {
384+
if (sep == nullptr) {
385385
continue;
386386
}
387387
Slice key = TrimSpace(Slice(line, sep - 1 - line));
@@ -402,11 +402,11 @@ class Benchmark {
402402

403403
public:
404404
Benchmark()
405-
: cache_(FLAGS_cache_size >= 0 ? NewLRUCache(FLAGS_cache_size) : NULL),
405+
: cache_(FLAGS_cache_size >= 0 ? NewLRUCache(FLAGS_cache_size) : nullptr),
406406
filter_policy_(FLAGS_bloom_bits >= 0
407407
? NewBloomFilterPolicy(FLAGS_bloom_bits)
408-
: NULL),
409-
db_(NULL),
408+
: nullptr),
409+
db_(nullptr),
410410
num_(FLAGS_num),
411411
value_size_(FLAGS_value_size),
412412
entries_per_batch_(1),
@@ -435,12 +435,12 @@ class Benchmark {
435435
Open();
436436

437437
const char* benchmarks = FLAGS_benchmarks;
438-
while (benchmarks != NULL) {
438+
while (benchmarks != nullptr) {
439439
const char* sep = strchr(benchmarks, ',');
440440
Slice name;
441-
if (sep == NULL) {
441+
if (sep == nullptr) {
442442
name = benchmarks;
443-
benchmarks = NULL;
443+
benchmarks = nullptr;
444444
} else {
445445
name = Slice(benchmarks, sep - benchmarks);
446446
benchmarks = sep + 1;
@@ -453,7 +453,7 @@ class Benchmark {
453453
entries_per_batch_ = 1;
454454
write_options_ = WriteOptions();
455455

456-
void (Benchmark::*method)(ThreadState*) = NULL;
456+
void (Benchmark::*method)(ThreadState*) = nullptr;
457457
bool fresh_db = false;
458458
int num_threads = FLAGS_threads;
459459

@@ -532,16 +532,16 @@ class Benchmark {
532532
if (FLAGS_use_existing_db) {
533533
fprintf(stdout, "%-12s : skipped (--use_existing_db is true)\n",
534534
name.ToString().c_str());
535-
method = NULL;
535+
method = nullptr;
536536
} else {
537537
delete db_;
538-
db_ = NULL;
538+
db_ = nullptr;
539539
DestroyDB(FLAGS_db, Options());
540540
Open();
541541
}
542542
}
543543

544-
if (method != NULL) {
544+
if (method != nullptr) {
545545
RunBenchmark(num_threads, name, method);
546546
}
547547
}
@@ -643,7 +643,7 @@ class Benchmark {
643643
int dummy;
644644
port::AtomicPointer ap(&dummy);
645645
int count = 0;
646-
void *ptr = NULL;
646+
void *ptr = nullptr;
647647
thread->stats.AddMessage("(each op is 1000 loads)");
648648
while (count < 100000) {
649649
for (int i = 0; i < 1000; i++) {
@@ -652,7 +652,7 @@ class Benchmark {
652652
count++;
653653
thread->stats.FinishedSingleOp();
654654
}
655-
if (ptr == NULL) exit(1); // Disable unused variable warning.
655+
if (ptr == nullptr) exit(1); // Disable unused variable warning.
656656
}
657657

658658
void SnappyCompress(ThreadState* thread) {
@@ -703,7 +703,7 @@ class Benchmark {
703703
}
704704

705705
void Open() {
706-
assert(db_ == NULL);
706+
assert(db_ == nullptr);
707707
Options options;
708708
options.env = g_env;
709709
options.create_if_missing = !FLAGS_use_existing_db;
@@ -914,7 +914,7 @@ class Benchmark {
914914
}
915915

916916
void Compact(ThreadState* thread) {
917-
db_->CompactRange(NULL, NULL);
917+
db_->CompactRange(nullptr, nullptr);
918918
}
919919

920920
void PrintStats(const char* key) {
@@ -1004,7 +1004,7 @@ int main(int argc, char** argv) {
10041004
leveldb::g_env = leveldb::Env::Default();
10051005

10061006
// Choose a location for the test database if none given with --db=<path>
1007-
if (FLAGS_db == NULL) {
1007+
if (FLAGS_db == nullptr) {
10081008
leveldb::g_env->GetTestDirectory(&default_db_path);
10091009
default_db_path += "/dbbench";
10101010
FLAGS_db = default_db_path.c_str();

0 commit comments

Comments
 (0)