diff options
author | 2017-05-30 08:47:25 -0700 | |
---|---|---|
committer | 2017-05-30 08:50:43 -0700 | |
commit | d83074847ebfe8871188f1f9f1e84ab0451f59e6 (patch) | |
tree | dbe0bd71cb9b8934889df83f221cef83f494a28e /tensorflow/core/lib/io | |
parent | b73fea6e27b17dc4349754e585113e7a8138339e (diff) |
Use "nullptr" for null pointer values
PiperOrigin-RevId: 157468186
Diffstat (limited to 'tensorflow/core/lib/io')
-rw-r--r-- | tensorflow/core/lib/io/block.cc | 16 | ||||
-rw-r--r-- | tensorflow/core/lib/io/iterator.cc | 12 | ||||
-rw-r--r-- | tensorflow/core/lib/io/table.cc | 10 | ||||
-rw-r--r-- | tensorflow/core/lib/io/table_test.cc | 14 | ||||
-rw-r--r-- | tensorflow/core/lib/io/two_level_iterator.cc | 20 | ||||
-rw-r--r-- | tensorflow/core/lib/io/zlib_inputstream.cc | 4 | ||||
-rw-r--r-- | tensorflow/core/lib/io/zlib_outputbuffer.cc | 6 |
7 files changed, 42 insertions, 40 deletions
diff --git a/tensorflow/core/lib/io/block.cc b/tensorflow/core/lib/io/block.cc index 30c842208f..1fa26d9147 100644 --- a/tensorflow/core/lib/io/block.cc +++ b/tensorflow/core/lib/io/block.cc @@ -64,7 +64,7 @@ Block::~Block() { static inline const char* DecodeEntry(const char* p, const char* limit, uint32* shared, uint32* non_shared, uint32* value_length) { - if (limit - p < 3) return NULL; + if (limit - p < 3) return nullptr; *shared = reinterpret_cast<const unsigned char*>(p)[0]; *non_shared = reinterpret_cast<const unsigned char*>(p)[1]; *value_length = reinterpret_cast<const unsigned char*>(p)[2]; @@ -72,13 +72,15 @@ static inline const char* DecodeEntry(const char* p, const char* limit, // Fast path: all three values are encoded in one byte each p += 3; } else { - if ((p = core::GetVarint32Ptr(p, limit, shared)) == NULL) return NULL; - if ((p = core::GetVarint32Ptr(p, limit, non_shared)) == NULL) return NULL; - if ((p = core::GetVarint32Ptr(p, limit, value_length)) == NULL) return NULL; + if ((p = core::GetVarint32Ptr(p, limit, shared)) == nullptr) return nullptr; + if ((p = core::GetVarint32Ptr(p, limit, non_shared)) == nullptr) + return nullptr; + if ((p = core::GetVarint32Ptr(p, limit, value_length)) == nullptr) + return nullptr; } if (static_cast<uint32>(limit - p) < (*non_shared + *value_length)) { - return NULL; + return nullptr; } return p; } @@ -158,7 +160,7 @@ class Block::Iter : public Iterator { const char* key_ptr = DecodeEntry(data_ + region_offset, data_ + restarts_, &shared, &non_shared, &value_length); - if (key_ptr == NULL || (shared != 0)) { + if (key_ptr == nullptr || (shared != 0)) { CorruptionError(); return; } @@ -214,7 +216,7 @@ class Block::Iter : public Iterator { // Decode next entry uint32 shared, non_shared, value_length; p = DecodeEntry(p, limit, &shared, &non_shared, &value_length); - if (p == NULL || key_.size() < shared) { + if (p == nullptr || key_.size() < shared) { CorruptionError(); return false; } else { diff --git a/tensorflow/core/lib/io/iterator.cc b/tensorflow/core/lib/io/iterator.cc index 95d2da402b..60f9981c2f 100644 --- a/tensorflow/core/lib/io/iterator.cc +++ b/tensorflow/core/lib/io/iterator.cc @@ -19,14 +19,14 @@ namespace tensorflow { namespace table { Iterator::Iterator() { - cleanup_.function = NULL; - cleanup_.next = NULL; + cleanup_.function = nullptr; + cleanup_.next = nullptr; } Iterator::~Iterator() { - if (cleanup_.function != NULL) { + if (cleanup_.function != nullptr) { (*cleanup_.function)(cleanup_.arg1, cleanup_.arg2); - for (Cleanup* c = cleanup_.next; c != NULL;) { + for (Cleanup* c = cleanup_.next; c != nullptr;) { (*c->function)(c->arg1, c->arg2); Cleanup* next = c->next; delete c; @@ -36,9 +36,9 @@ Iterator::~Iterator() { } void Iterator::RegisterCleanup(CleanupFunction func, void* arg1, void* arg2) { - assert(func != NULL); + assert(func != nullptr); Cleanup* c; - if (cleanup_.function == NULL) { + if (cleanup_.function == nullptr) { c = &cleanup_; } else { c = new Cleanup; diff --git a/tensorflow/core/lib/io/table.cc b/tensorflow/core/lib/io/table.cc index 41eb38fe19..1ef7bb6ccd 100644 --- a/tensorflow/core/lib/io/table.cc +++ b/tensorflow/core/lib/io/table.cc @@ -40,7 +40,7 @@ struct Table::Rep { Status Table::Open(const Options& options, RandomAccessFile* file, uint64 size, Table** table) { - *table = NULL; + *table = nullptr; if (size < Footer::kEncodedLength) { return errors::DataLoss("file is too short to be an sstable"); } @@ -57,7 +57,7 @@ Status Table::Open(const Options& options, RandomAccessFile* file, uint64 size, // Read the index block BlockContents contents; - Block* index_block = NULL; + Block* index_block = nullptr; if (s.ok()) { s = ReadBlock(file, footer.index_handle(), &contents); if (s.ok()) { @@ -94,7 +94,7 @@ static void DeleteBlock(void* arg, void* ignored) { Iterator* Table::BlockReader(void* arg, const StringPiece& index_value) { Table* table = reinterpret_cast<Table*>(arg); // Cache* block_cache = table->rep_->options.block_cache; - Block* block = NULL; + Block* block = nullptr; // Cache::Handle* cache_handle = NULL; BlockHandle handle; @@ -112,9 +112,9 @@ Iterator* Table::BlockReader(void* arg, const StringPiece& index_value) { } Iterator* iter; - if (block != NULL) { + if (block != nullptr) { iter = block->NewIterator(); - iter->RegisterCleanup(&DeleteBlock, block, NULL); + iter->RegisterCleanup(&DeleteBlock, block, nullptr); } else { iter = NewErrorIterator(s); } diff --git a/tensorflow/core/lib/io/table_test.cc b/tensorflow/core/lib/io/table_test.cc index d2002d69c4..d479c2d533 100644 --- a/tensorflow/core/lib/io/table_test.cc +++ b/tensorflow/core/lib/io/table_test.cc @@ -177,11 +177,11 @@ class Constructor { class BlockConstructor : public Constructor { public: - BlockConstructor() : block_(NULL) {} + BlockConstructor() : block_(nullptr) {} ~BlockConstructor() override { delete block_; } Status FinishImpl(const Options& options, const KVMap& data) override { delete block_; - block_ = NULL; + block_ = nullptr; BlockBuilder builder(&options); for (KVMap::const_iterator it = data.begin(); it != data.end(); ++it) { @@ -205,7 +205,7 @@ class BlockConstructor : public Constructor { class TableConstructor : public Constructor { public: - TableConstructor() : source_(NULL), table_(NULL) {} + TableConstructor() : source_(nullptr), table_(nullptr) {} ~TableConstructor() override { Reset(); } Status FinishImpl(const Options& options, const KVMap& data) override { Reset(); @@ -239,8 +239,8 @@ class TableConstructor : public Constructor { void Reset() { delete table_; delete source_; - table_ = NULL; - source_ = NULL; + table_ = nullptr; + source_ = nullptr; } StringSource* source_; @@ -262,11 +262,11 @@ static const int kNumTestArgs = sizeof(kTestArgList) / sizeof(kTestArgList[0]); class Harness : public ::testing::Test { public: - Harness() : constructor_(NULL) {} + Harness() : constructor_(nullptr) {} void Init(const TestArgs& args) { delete constructor_; - constructor_ = NULL; + constructor_ = nullptr; options_ = Options(); options_.block_restart_interval = args.restart_interval; diff --git a/tensorflow/core/lib/io/two_level_iterator.cc b/tensorflow/core/lib/io/two_level_iterator.cc index 8a1034ceea..ad66ae40d8 100644 --- a/tensorflow/core/lib/io/two_level_iterator.cc +++ b/tensorflow/core/lib/io/two_level_iterator.cc @@ -54,7 +54,7 @@ class TwoLevelIterator : public Iterator { // Status if (!index_iter_->status().ok()) { return index_iter_->status(); - } else if (data_iter_ != NULL && !data_iter_->status().ok()) { + } else if (data_iter_ != nullptr && !data_iter_->status().ok()) { return data_iter_->status(); } else { return status_; @@ -84,7 +84,7 @@ TwoLevelIterator::TwoLevelIterator(Iterator* index_iter, : block_function_(block_function), arg_(arg), index_iter_(index_iter), - data_iter_(NULL) {} + data_iter_(nullptr) {} TwoLevelIterator::~TwoLevelIterator() { delete index_iter_; @@ -94,14 +94,14 @@ TwoLevelIterator::~TwoLevelIterator() { void TwoLevelIterator::Seek(const StringPiece& target) { index_iter_->Seek(target); InitDataBlock(); - if (data_iter_ != NULL) data_iter_->Seek(target); + if (data_iter_ != nullptr) data_iter_->Seek(target); SkipEmptyDataBlocksForward(); } void TwoLevelIterator::SeekToFirst() { index_iter_->SeekToFirst(); InitDataBlock(); - if (data_iter_ != NULL) data_iter_->SeekToFirst(); + if (data_iter_ != nullptr) data_iter_->SeekToFirst(); SkipEmptyDataBlocksForward(); } @@ -112,20 +112,20 @@ void TwoLevelIterator::Next() { } void TwoLevelIterator::SkipEmptyDataBlocksForward() { - while (data_iter_ == NULL || !data_iter_->Valid()) { + while (data_iter_ == nullptr || !data_iter_->Valid()) { // Move to next block if (!index_iter_->Valid()) { - SetDataIterator(NULL); + SetDataIterator(nullptr); return; } index_iter_->Next(); InitDataBlock(); - if (data_iter_ != NULL) data_iter_->SeekToFirst(); + if (data_iter_ != nullptr) data_iter_->SeekToFirst(); } } void TwoLevelIterator::SetDataIterator(Iterator* data_iter) { - if (data_iter_ != NULL) { + if (data_iter_ != nullptr) { SaveError(data_iter_->status()); delete data_iter_; } @@ -134,10 +134,10 @@ void TwoLevelIterator::SetDataIterator(Iterator* data_iter) { void TwoLevelIterator::InitDataBlock() { if (!index_iter_->Valid()) { - SetDataIterator(NULL); + SetDataIterator(nullptr); } else { StringPiece handle = index_iter_->value(); - if (data_iter_ != NULL && handle.compare(data_block_handle_) == 0) { + if (data_iter_ != nullptr && handle.compare(data_block_handle_) == 0) { // data_iter_ is already constructed with this iterator, so // no need to change anything } else { diff --git a/tensorflow/core/lib/io/zlib_inputstream.cc b/tensorflow/core/lib/io/zlib_inputstream.cc index 6b64011cc3..d019b65510 100644 --- a/tensorflow/core/lib/io/zlib_inputstream.cc +++ b/tensorflow/core/lib/io/zlib_inputstream.cc @@ -60,7 +60,7 @@ void ZlibInputStream::InitZlibBuffer() { int status = inflateInit2(z_stream_.get(), zlib_options_.window_bits); if (status != Z_OK) { LOG(FATAL) << "inflateInit failed with status " << status; - z_stream_.reset(NULL); + z_stream_.reset(nullptr); } else { z_stream_->next_in = z_stream_input_.get(); z_stream_->next_out = z_stream_output_.get(); @@ -180,7 +180,7 @@ Status ZlibInputStream::Inflate() { if (error != Z_OK && error != Z_STREAM_END) { string error_string = strings::StrCat("inflate() failed with error ", error); - if (z_stream_->msg != NULL) { + if (z_stream_->msg != nullptr) { strings::StrAppend(&error_string, ": ", z_stream_->msg); } return errors::DataLoss(error_string); diff --git a/tensorflow/core/lib/io/zlib_outputbuffer.cc b/tensorflow/core/lib/io/zlib_outputbuffer.cc index a65b36b64d..5901504b87 100644 --- a/tensorflow/core/lib/io/zlib_outputbuffer.cc +++ b/tensorflow/core/lib/io/zlib_outputbuffer.cc @@ -58,7 +58,7 @@ Status ZlibOutputBuffer::Init() { zlib_options_.compression_method, zlib_options_.window_bits, zlib_options_.mem_level, zlib_options_.compression_strategy); if (status != Z_OK) { - z_stream_.reset(NULL); + z_stream_.reset(nullptr); return errors::InvalidArgument("deflateInit failed with status", status); } z_stream_->next_in = z_stream_input_.get(); @@ -206,7 +206,7 @@ Status ZlibOutputBuffer::Close() { TF_RETURN_IF_ERROR(DeflateBuffered(true)); TF_RETURN_IF_ERROR(FlushOutputBufferToFile()); deflateEnd(z_stream_.get()); - z_stream_.reset(NULL); + z_stream_.reset(nullptr); return Status::OK(); } @@ -217,7 +217,7 @@ Status ZlibOutputBuffer::Deflate(int flush) { return Status::OK(); } string error_string = strings::StrCat("deflate() failed with error ", error); - if (z_stream_->msg != NULL) { + if (z_stream_->msg != nullptr) { strings::StrAppend(&error_string, ": ", z_stream_->msg); } return errors::DataLoss(error_string); |