Use "nullptr" for null pointer values
PiperOrigin-RevId: 157468186
This commit is contained in:
parent
b73fea6e27
commit
d83074847e
@ -330,7 +330,7 @@ TF_DeprecatedSession* TF_NewDeprecatedSession(const TF_SessionOptions* opt,
|
|||||||
return new TF_DeprecatedSession({session});
|
return new TF_DeprecatedSession({session});
|
||||||
} else {
|
} else {
|
||||||
DCHECK_EQ(nullptr, session);
|
DCHECK_EQ(nullptr, session);
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -504,7 +504,7 @@ static void TF_Run_Setup(int noutputs, TF_Tensor** c_outputs,
|
|||||||
TF_Status* status) {
|
TF_Status* status) {
|
||||||
status->status = Status::OK();
|
status->status = Status::OK();
|
||||||
for (int i = 0; i < noutputs; ++i) {
|
for (int i = 0; i < noutputs; ++i) {
|
||||||
c_outputs[i] = NULL;
|
c_outputs[i] = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2158,7 +2158,7 @@ TF_Session* TF_NewSession(TF_Graph* graph, const TF_SessionOptions* opt,
|
|||||||
return new TF_Session(session, graph);
|
return new TF_Session(session, graph);
|
||||||
} else {
|
} else {
|
||||||
DCHECK_EQ(nullptr, session);
|
DCHECK_EQ(nullptr, session);
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ bool IsBinaryInstalled(const string& binary_name) {
|
|||||||
for (const string& dir : str_util::Split(path, ':')) {
|
for (const string& dir : str_util::Split(path, ':')) {
|
||||||
const string binary_path = io::JoinPath(dir, binary_name);
|
const string binary_path = io::JoinPath(dir, binary_name);
|
||||||
char absolute_path[PATH_MAX + 1];
|
char absolute_path[PATH_MAX + 1];
|
||||||
if (::realpath(binary_path.c_str(), absolute_path) == NULL) {
|
if (::realpath(binary_path.c_str(), absolute_path) == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
struct stat statinfo;
|
struct stat statinfo;
|
||||||
|
@ -151,7 +151,7 @@ class SingleImageRandomDotStereogramsOp : public OpKernel {
|
|||||||
BuildZBuffer(inputZ);
|
BuildZBuffer(inputZ);
|
||||||
|
|
||||||
// Output a scalar string.
|
// Output a scalar string.
|
||||||
Tensor* output_tensor = NULL;
|
Tensor* output_tensor = nullptr;
|
||||||
OP_REQUIRES_OK(
|
OP_REQUIRES_OK(
|
||||||
context,
|
context,
|
||||||
context->allocate_output(
|
context->allocate_output(
|
||||||
|
@ -226,7 +226,7 @@ void CUPTIManager::InternalBufferCompleted(CUcontext ctx, uint32_t streamId,
|
|||||||
size_t validSize) {
|
size_t validSize) {
|
||||||
VLOG(2) << "BufferCompleted";
|
VLOG(2) << "BufferCompleted";
|
||||||
CUptiResult status;
|
CUptiResult status;
|
||||||
CUpti_Activity *record = NULL;
|
CUpti_Activity *record = nullptr;
|
||||||
mutex_lock l(mu_); // Hold mu_ while using client_.
|
mutex_lock l(mu_); // Hold mu_ while using client_.
|
||||||
if (client_ && validSize > 0) {
|
if (client_ && validSize > 0) {
|
||||||
do {
|
do {
|
||||||
|
@ -516,7 +516,7 @@ CostGraphDef* InMemoryRunGraphResponse::mutable_cost_graph() {
|
|||||||
|
|
||||||
RunGraphResponse* InMemoryRunGraphResponse::get_proto() {
|
RunGraphResponse* InMemoryRunGraphResponse::get_proto() {
|
||||||
LOG(FATAL) << "Cannot get a mutable protobuf for an InMemoryRunGraphResponse";
|
LOG(FATAL) << "Cannot get a mutable protobuf for an InMemoryRunGraphResponse";
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t OwnedProtoRunGraphResponse::num_recvs() const {
|
size_t OwnedProtoRunGraphResponse::num_recvs() const {
|
||||||
@ -635,7 +635,7 @@ RunMetadata* InMemoryRunStepResponse::mutable_metadata() { return &metadata_; }
|
|||||||
|
|
||||||
RunStepResponse* InMemoryRunStepResponse::get_proto() {
|
RunStepResponse* InMemoryRunStepResponse::get_proto() {
|
||||||
LOG(FATAL) << "Cannot get a mutable protobuf for an InMemoryRunStepResponse";
|
LOG(FATAL) << "Cannot get a mutable protobuf for an InMemoryRunStepResponse";
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t OwnedProtoRunStepResponse::num_tensors() const {
|
size_t OwnedProtoRunStepResponse::num_tensors() const {
|
||||||
|
@ -97,7 +97,7 @@ TEST_F(DebugIdentityOpTest, Int32Success_6_FileURLs) {
|
|||||||
DIR* dir = opendir(dump_roots[i].c_str());
|
DIR* dir = opendir(dump_roots[i].c_str());
|
||||||
struct dirent* ent;
|
struct dirent* ent;
|
||||||
int dump_files_found = 0;
|
int dump_files_found = 0;
|
||||||
while ((ent = readdir(dir)) != NULL) {
|
while ((ent = readdir(dir)) != nullptr) {
|
||||||
if (strcmp(ent->d_name, ".") && strcmp(ent->d_name, "..")) {
|
if (strcmp(ent->d_name, ".") && strcmp(ent->d_name, "..")) {
|
||||||
dump_files_found++;
|
dump_files_found++;
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ class EncodeJpegOp : public OpKernel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Encode image to jpeg string
|
// Encode image to jpeg string
|
||||||
Tensor* output = NULL;
|
Tensor* output = nullptr;
|
||||||
OP_REQUIRES_OK(context,
|
OP_REQUIRES_OK(context,
|
||||||
context->allocate_output(0, TensorShape({}), &output));
|
context->allocate_output(0, TensorShape({}), &output));
|
||||||
OP_REQUIRES(context,
|
OP_REQUIRES(context,
|
||||||
|
@ -73,7 +73,7 @@ class EncodePngOp : public OpKernel {
|
|||||||
"image must have 1, 2, 3, or 4 channels, got ", channels));
|
"image must have 1, 2, 3, or 4 channels, got ", channels));
|
||||||
|
|
||||||
// Encode image to png string
|
// Encode image to png string
|
||||||
Tensor* output = NULL;
|
Tensor* output = nullptr;
|
||||||
OP_REQUIRES_OK(context,
|
OP_REQUIRES_OK(context,
|
||||||
context->allocate_output(0, TensorShape({}), &output));
|
context->allocate_output(0, TensorShape({}), &output));
|
||||||
if (desired_channel_bits_ == 8) {
|
if (desired_channel_bits_ == 8) {
|
||||||
|
@ -52,7 +52,7 @@ class EncodeWavOp : public OpKernel {
|
|||||||
const int32 sample_count = static_cast<int32>(audio.dim_size(0));
|
const int32 sample_count = static_cast<int32>(audio.dim_size(0));
|
||||||
|
|
||||||
// Encode audio to wav string.
|
// Encode audio to wav string.
|
||||||
Tensor* output = NULL;
|
Tensor* output = nullptr;
|
||||||
OP_REQUIRES_OK(context,
|
OP_REQUIRES_OK(context,
|
||||||
context->allocate_output(0, TensorShape({}), &output));
|
context->allocate_output(0, TensorShape({}), &output));
|
||||||
OP_REQUIRES_OK(context,
|
OP_REQUIRES_OK(context,
|
||||||
|
@ -82,7 +82,7 @@ class FactOpKernel : public OpKernel {
|
|||||||
protected:
|
protected:
|
||||||
void Compute(OpKernelContext* context, const char* const facts[],
|
void Compute(OpKernelContext* context, const char* const facts[],
|
||||||
uint64 count) {
|
uint64 count) {
|
||||||
Tensor* output_tensor = NULL;
|
Tensor* output_tensor = nullptr;
|
||||||
OP_REQUIRES_OK(
|
OP_REQUIRES_OK(
|
||||||
context, context->allocate_output(0, TensorShape({}), &output_tensor));
|
context, context->allocate_output(0, TensorShape({}), &output_tensor));
|
||||||
auto output = output_tensor->template scalar<string>();
|
auto output = output_tensor->template scalar<string>();
|
||||||
|
@ -44,9 +44,9 @@ namespace core {
|
|||||||
Arena::Arena(const size_t block_size)
|
Arena::Arena(const size_t block_size)
|
||||||
: remaining_(0),
|
: remaining_(0),
|
||||||
block_size_(block_size),
|
block_size_(block_size),
|
||||||
freestart_(NULL), // set for real in Reset()
|
freestart_(nullptr), // set for real in Reset()
|
||||||
blocks_alloced_(1),
|
blocks_alloced_(1),
|
||||||
overflow_blocks_(NULL) {
|
overflow_blocks_(nullptr) {
|
||||||
assert(block_size > kDefaultAlignment);
|
assert(block_size > kDefaultAlignment);
|
||||||
|
|
||||||
first_blocks_[0].mem =
|
first_blocks_[0].mem =
|
||||||
@ -59,7 +59,7 @@ Arena::Arena(const size_t block_size)
|
|||||||
|
|
||||||
Arena::~Arena() {
|
Arena::~Arena() {
|
||||||
FreeBlocks();
|
FreeBlocks();
|
||||||
assert(overflow_blocks_ == NULL); // FreeBlocks() should do that
|
assert(overflow_blocks_ == nullptr); // FreeBlocks() should do that
|
||||||
// The first X blocks stay allocated always by default. Delete them now.
|
// The first X blocks stay allocated always by default. Delete them now.
|
||||||
for (size_t i = 0; i < blocks_alloced_; ++i) {
|
for (size_t i = 0; i < blocks_alloced_; ++i) {
|
||||||
port::AlignedFree(first_blocks_[i].mem);
|
port::AlignedFree(first_blocks_[i].mem);
|
||||||
@ -152,7 +152,7 @@ Arena::AllocatedBlock* Arena::AllocNewBlock(const size_t block_size,
|
|||||||
// Use one of the pre-allocated blocks
|
// Use one of the pre-allocated blocks
|
||||||
block = &first_blocks_[blocks_alloced_++];
|
block = &first_blocks_[blocks_alloced_++];
|
||||||
} else { // oops, out of space, move to the vector
|
} else { // oops, out of space, move to the vector
|
||||||
if (overflow_blocks_ == NULL)
|
if (overflow_blocks_ == nullptr)
|
||||||
overflow_blocks_ = new std::vector<AllocatedBlock>;
|
overflow_blocks_ = new std::vector<AllocatedBlock>;
|
||||||
// Adds another block to the vector.
|
// Adds another block to the vector.
|
||||||
overflow_blocks_->resize(overflow_blocks_->size() + 1);
|
overflow_blocks_->resize(overflow_blocks_->size() + 1);
|
||||||
@ -185,10 +185,10 @@ Arena::AllocatedBlock* Arena::AllocNewBlock(const size_t block_size,
|
|||||||
block->mem = reinterpret_cast<char*>(
|
block->mem = reinterpret_cast<char*>(
|
||||||
port::AlignedMalloc(adjusted_block_size, adjusted_alignment));
|
port::AlignedMalloc(adjusted_block_size, adjusted_alignment));
|
||||||
block->size = adjusted_block_size;
|
block->size = adjusted_block_size;
|
||||||
CHECK(NULL != block->mem) << "block_size=" << block_size
|
CHECK(nullptr != block->mem) << "block_size=" << block_size
|
||||||
<< " adjusted_block_size=" << adjusted_block_size
|
<< " adjusted_block_size=" << adjusted_block_size
|
||||||
<< " alignment=" << alignment
|
<< " alignment=" << alignment
|
||||||
<< " adjusted_alignment=" << adjusted_alignment;
|
<< " adjusted_alignment=" << adjusted_alignment;
|
||||||
|
|
||||||
return block;
|
return block;
|
||||||
}
|
}
|
||||||
@ -205,7 +205,7 @@ Arena::AllocatedBlock* Arena::AllocNewBlock(const size_t block_size,
|
|||||||
|
|
||||||
void* Arena::GetMemoryFallback(const size_t size, const int alignment) {
|
void* Arena::GetMemoryFallback(const size_t size, const int alignment) {
|
||||||
if (0 == size) {
|
if (0 == size) {
|
||||||
return NULL; // stl/stl_alloc.h says this is okay
|
return nullptr; // stl/stl_alloc.h says this is okay
|
||||||
}
|
}
|
||||||
|
|
||||||
// alignment must be a positive power of 2.
|
// alignment must be a positive power of 2.
|
||||||
@ -246,17 +246,17 @@ void* Arena::GetMemoryFallback(const size_t size, const int alignment) {
|
|||||||
void Arena::FreeBlocks() {
|
void Arena::FreeBlocks() {
|
||||||
for (size_t i = 1; i < blocks_alloced_; ++i) { // keep first block alloced
|
for (size_t i = 1; i < blocks_alloced_; ++i) { // keep first block alloced
|
||||||
port::AlignedFree(first_blocks_[i].mem);
|
port::AlignedFree(first_blocks_[i].mem);
|
||||||
first_blocks_[i].mem = NULL;
|
first_blocks_[i].mem = nullptr;
|
||||||
first_blocks_[i].size = 0;
|
first_blocks_[i].size = 0;
|
||||||
}
|
}
|
||||||
blocks_alloced_ = 1;
|
blocks_alloced_ = 1;
|
||||||
if (overflow_blocks_ != NULL) {
|
if (overflow_blocks_ != nullptr) {
|
||||||
std::vector<AllocatedBlock>::iterator it;
|
std::vector<AllocatedBlock>::iterator it;
|
||||||
for (it = overflow_blocks_->begin(); it != overflow_blocks_->end(); ++it) {
|
for (it = overflow_blocks_->begin(); it != overflow_blocks_->end(); ++it) {
|
||||||
port::AlignedFree(it->mem);
|
port::AlignedFree(it->mem);
|
||||||
}
|
}
|
||||||
delete overflow_blocks_; // These should be used very rarely
|
delete overflow_blocks_; // These should be used very rarely
|
||||||
overflow_blocks_ = NULL;
|
overflow_blocks_ = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,14 +148,14 @@ const char* GetVarint32PtrFallback(const char* p, const char* limit,
|
|||||||
return reinterpret_cast<const char*>(p);
|
return reinterpret_cast<const char*>(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetVarint32(StringPiece* input, uint32* value) {
|
bool GetVarint32(StringPiece* input, uint32* value) {
|
||||||
const char* p = input->data();
|
const char* p = input->data();
|
||||||
const char* limit = p + input->size();
|
const char* limit = p + input->size();
|
||||||
const char* q = GetVarint32Ptr(p, limit, value);
|
const char* q = GetVarint32Ptr(p, limit, value);
|
||||||
if (q == NULL) {
|
if (q == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
*input = StringPiece(q, limit - q);
|
*input = StringPiece(q, limit - q);
|
||||||
@ -177,14 +177,14 @@ const char* GetVarint64Ptr(const char* p, const char* limit, uint64* value) {
|
|||||||
return reinterpret_cast<const char*>(p);
|
return reinterpret_cast<const char*>(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetVarint64(StringPiece* input, uint64* value) {
|
bool GetVarint64(StringPiece* input, uint64* value) {
|
||||||
const char* p = input->data();
|
const char* p = input->data();
|
||||||
const char* limit = p + input->size();
|
const char* limit = p + input->size();
|
||||||
const char* q = GetVarint64Ptr(p, limit, value);
|
const char* q = GetVarint64Ptr(p, limit, value);
|
||||||
if (q == NULL) {
|
if (q == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
*input = StringPiece(q, limit - q);
|
*input = StringPiece(q, limit - q);
|
||||||
|
@ -125,7 +125,7 @@ TEST(Coding, Varint32) {
|
|||||||
uint32 expected = (i / 32) << (i % 32);
|
uint32 expected = (i / 32) << (i % 32);
|
||||||
uint32 actual;
|
uint32 actual;
|
||||||
p = GetVarint32Ptr(p, limit, &actual);
|
p = GetVarint32Ptr(p, limit, &actual);
|
||||||
ASSERT_TRUE(p != NULL);
|
ASSERT_TRUE(p != nullptr);
|
||||||
ASSERT_EQ(expected, actual);
|
ASSERT_EQ(expected, actual);
|
||||||
}
|
}
|
||||||
ASSERT_EQ(p, s.data() + s.size());
|
ASSERT_EQ(p, s.data() + s.size());
|
||||||
@ -158,7 +158,7 @@ TEST(Coding, Varint64) {
|
|||||||
ASSERT_TRUE(p < limit);
|
ASSERT_TRUE(p < limit);
|
||||||
uint64 actual;
|
uint64 actual;
|
||||||
p = GetVarint64Ptr(p, limit, &actual);
|
p = GetVarint64Ptr(p, limit, &actual);
|
||||||
ASSERT_TRUE(p != NULL);
|
ASSERT_TRUE(p != nullptr);
|
||||||
ASSERT_EQ(values[i], actual);
|
ASSERT_EQ(values[i], actual);
|
||||||
}
|
}
|
||||||
ASSERT_EQ(p, limit);
|
ASSERT_EQ(p, limit);
|
||||||
@ -168,7 +168,7 @@ TEST(Coding, Varint32Overflow) {
|
|||||||
uint32 result;
|
uint32 result;
|
||||||
string input("\x81\x82\x83\x84\x85\x11");
|
string input("\x81\x82\x83\x84\x85\x11");
|
||||||
ASSERT_TRUE(GetVarint32Ptr(input.data(), input.data() + input.size(),
|
ASSERT_TRUE(GetVarint32Ptr(input.data(), input.data() + input.size(),
|
||||||
&result) == NULL);
|
&result) == nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Coding, Varint32Truncation) {
|
TEST(Coding, Varint32Truncation) {
|
||||||
@ -177,9 +177,10 @@ TEST(Coding, Varint32Truncation) {
|
|||||||
PutVarint32(&s, large_value);
|
PutVarint32(&s, large_value);
|
||||||
uint32 result;
|
uint32 result;
|
||||||
for (size_t len = 0; len < s.size() - 1; len++) {
|
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);
|
ASSERT_EQ(large_value, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,7 +188,7 @@ TEST(Coding, Varint64Overflow) {
|
|||||||
uint64 result;
|
uint64 result;
|
||||||
string input("\x81\x82\x83\x84\x85\x81\x82\x83\x84\x85\x11");
|
string input("\x81\x82\x83\x84\x85\x81\x82\x83\x84\x85\x11");
|
||||||
ASSERT_TRUE(GetVarint64Ptr(input.data(), input.data() + input.size(),
|
ASSERT_TRUE(GetVarint64Ptr(input.data(), input.data() + input.size(),
|
||||||
&result) == NULL);
|
&result) == nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Coding, Varint64Truncation) {
|
TEST(Coding, Varint64Truncation) {
|
||||||
@ -196,9 +197,10 @@ TEST(Coding, Varint64Truncation) {
|
|||||||
PutVarint64(&s, large_value);
|
PutVarint64(&s, large_value);
|
||||||
uint64 result;
|
uint64 result;
|
||||||
for (size_t len = 0; len < s.size() - 1; len++) {
|
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);
|
ASSERT_EQ(large_value, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ const string& Status::empty_string() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
string Status::ToString() const {
|
string Status::ToString() const {
|
||||||
if (state_ == NULL) {
|
if (state_ == nullptr) {
|
||||||
return "OK";
|
return "OK";
|
||||||
} else {
|
} else {
|
||||||
char tmp[30];
|
char tmp[30];
|
||||||
|
@ -40,7 +40,7 @@ size_t StringPiece::find(char c, size_t pos) const {
|
|||||||
}
|
}
|
||||||
const char* result =
|
const char* result =
|
||||||
reinterpret_cast<const char*>(memchr(data_ + pos, c, size_ - pos));
|
reinterpret_cast<const char*>(memchr(data_ + pos, c, size_ - pos));
|
||||||
return result != NULL ? result - data_ : npos;
|
return result != nullptr ? result - data_ : npos;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search range is [0..pos] inclusive. If pos == npos, search everything.
|
// Search range is [0..pos] inclusive. If pos == npos, search everything.
|
||||||
|
@ -65,7 +65,7 @@ class RefCounted {
|
|||||||
|
|
||||||
~RefCounted() {
|
~RefCounted() {
|
||||||
Unref();
|
Unref();
|
||||||
count_ = NULL;
|
count_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
friend void swap(RefCounted& a, RefCounted& b) {
|
friend void swap(RefCounted& a, RefCounted& b) {
|
||||||
@ -81,7 +81,7 @@ class RefCounted {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Ref() const {
|
void Ref() const {
|
||||||
CHECK(count_ != NULL);
|
CHECK(count_ != nullptr);
|
||||||
++(*count_);
|
++(*count_);
|
||||||
VLOG(5) << "[Ref: refcount " << *count_ << " on count @" << count_ << "]";
|
VLOG(5) << "[Ref: refcount " << *count_ << " on count @" << count_ << "]";
|
||||||
}
|
}
|
||||||
|
@ -172,13 +172,13 @@ TEST(TopNTest, Ptr) {
|
|||||||
LOG(INFO) << "Testing 2-argument push()";
|
LOG(INFO) << "Testing 2-argument push()";
|
||||||
TopN<string *> topn(3);
|
TopN<string *> topn(3);
|
||||||
for (int i = 0; i < 8; ++i) {
|
for (int i = 0; i < 8; ++i) {
|
||||||
string *dropped = NULL;
|
string *dropped = nullptr;
|
||||||
topn.push(new string(std::to_string(i)), &dropped);
|
topn.push(new string(std::to_string(i)), &dropped);
|
||||||
delete dropped;
|
delete dropped;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 8; i > 0; --i) {
|
for (int i = 8; i > 0; --i) {
|
||||||
string *dropped = NULL;
|
string *dropped = nullptr;
|
||||||
topn.push(new string(std::to_string(i)), &dropped);
|
topn.push(new string(std::to_string(i)), &dropped);
|
||||||
delete dropped;
|
delete dropped;
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ Block::~Block() {
|
|||||||
static inline const char* DecodeEntry(const char* p, const char* limit,
|
static inline const char* DecodeEntry(const char* p, const char* limit,
|
||||||
uint32* shared, uint32* non_shared,
|
uint32* shared, uint32* non_shared,
|
||||||
uint32* value_length) {
|
uint32* value_length) {
|
||||||
if (limit - p < 3) return NULL;
|
if (limit - p < 3) return nullptr;
|
||||||
*shared = reinterpret_cast<const unsigned char*>(p)[0];
|
*shared = reinterpret_cast<const unsigned char*>(p)[0];
|
||||||
*non_shared = reinterpret_cast<const unsigned char*>(p)[1];
|
*non_shared = reinterpret_cast<const unsigned char*>(p)[1];
|
||||||
*value_length = reinterpret_cast<const unsigned char*>(p)[2];
|
*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
|
// Fast path: all three values are encoded in one byte each
|
||||||
p += 3;
|
p += 3;
|
||||||
} else {
|
} else {
|
||||||
if ((p = core::GetVarint32Ptr(p, limit, shared)) == NULL) return NULL;
|
if ((p = core::GetVarint32Ptr(p, limit, shared)) == nullptr) return nullptr;
|
||||||
if ((p = core::GetVarint32Ptr(p, limit, non_shared)) == NULL) return NULL;
|
if ((p = core::GetVarint32Ptr(p, limit, non_shared)) == nullptr)
|
||||||
if ((p = core::GetVarint32Ptr(p, limit, value_length)) == NULL) return NULL;
|
return nullptr;
|
||||||
|
if ((p = core::GetVarint32Ptr(p, limit, value_length)) == nullptr)
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (static_cast<uint32>(limit - p) < (*non_shared + *value_length)) {
|
if (static_cast<uint32>(limit - p) < (*non_shared + *value_length)) {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
@ -158,7 +160,7 @@ class Block::Iter : public Iterator {
|
|||||||
const char* key_ptr =
|
const char* key_ptr =
|
||||||
DecodeEntry(data_ + region_offset, data_ + restarts_, &shared,
|
DecodeEntry(data_ + region_offset, data_ + restarts_, &shared,
|
||||||
&non_shared, &value_length);
|
&non_shared, &value_length);
|
||||||
if (key_ptr == NULL || (shared != 0)) {
|
if (key_ptr == nullptr || (shared != 0)) {
|
||||||
CorruptionError();
|
CorruptionError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -214,7 +216,7 @@ class Block::Iter : public Iterator {
|
|||||||
// Decode next entry
|
// Decode next entry
|
||||||
uint32 shared, non_shared, value_length;
|
uint32 shared, non_shared, value_length;
|
||||||
p = DecodeEntry(p, limit, &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();
|
CorruptionError();
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -19,14 +19,14 @@ namespace tensorflow {
|
|||||||
namespace table {
|
namespace table {
|
||||||
|
|
||||||
Iterator::Iterator() {
|
Iterator::Iterator() {
|
||||||
cleanup_.function = NULL;
|
cleanup_.function = nullptr;
|
||||||
cleanup_.next = NULL;
|
cleanup_.next = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator::~Iterator() {
|
Iterator::~Iterator() {
|
||||||
if (cleanup_.function != NULL) {
|
if (cleanup_.function != nullptr) {
|
||||||
(*cleanup_.function)(cleanup_.arg1, cleanup_.arg2);
|
(*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);
|
(*c->function)(c->arg1, c->arg2);
|
||||||
Cleanup* next = c->next;
|
Cleanup* next = c->next;
|
||||||
delete c;
|
delete c;
|
||||||
@ -36,9 +36,9 @@ Iterator::~Iterator() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Iterator::RegisterCleanup(CleanupFunction func, void* arg1, void* arg2) {
|
void Iterator::RegisterCleanup(CleanupFunction func, void* arg1, void* arg2) {
|
||||||
assert(func != NULL);
|
assert(func != nullptr);
|
||||||
Cleanup* c;
|
Cleanup* c;
|
||||||
if (cleanup_.function == NULL) {
|
if (cleanup_.function == nullptr) {
|
||||||
c = &cleanup_;
|
c = &cleanup_;
|
||||||
} else {
|
} else {
|
||||||
c = new Cleanup;
|
c = new Cleanup;
|
||||||
|
@ -40,7 +40,7 @@ struct Table::Rep {
|
|||||||
|
|
||||||
Status Table::Open(const Options& options, RandomAccessFile* file, uint64 size,
|
Status Table::Open(const Options& options, RandomAccessFile* file, uint64 size,
|
||||||
Table** table) {
|
Table** table) {
|
||||||
*table = NULL;
|
*table = nullptr;
|
||||||
if (size < Footer::kEncodedLength) {
|
if (size < Footer::kEncodedLength) {
|
||||||
return errors::DataLoss("file is too short to be an sstable");
|
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
|
// Read the index block
|
||||||
BlockContents contents;
|
BlockContents contents;
|
||||||
Block* index_block = NULL;
|
Block* index_block = nullptr;
|
||||||
if (s.ok()) {
|
if (s.ok()) {
|
||||||
s = ReadBlock(file, footer.index_handle(), &contents);
|
s = ReadBlock(file, footer.index_handle(), &contents);
|
||||||
if (s.ok()) {
|
if (s.ok()) {
|
||||||
@ -94,7 +94,7 @@ static void DeleteBlock(void* arg, void* ignored) {
|
|||||||
Iterator* Table::BlockReader(void* arg, const StringPiece& index_value) {
|
Iterator* Table::BlockReader(void* arg, const StringPiece& index_value) {
|
||||||
Table* table = reinterpret_cast<Table*>(arg);
|
Table* table = reinterpret_cast<Table*>(arg);
|
||||||
// Cache* block_cache = table->rep_->options.block_cache;
|
// Cache* block_cache = table->rep_->options.block_cache;
|
||||||
Block* block = NULL;
|
Block* block = nullptr;
|
||||||
// Cache::Handle* cache_handle = NULL;
|
// Cache::Handle* cache_handle = NULL;
|
||||||
|
|
||||||
BlockHandle handle;
|
BlockHandle handle;
|
||||||
@ -112,9 +112,9 @@ Iterator* Table::BlockReader(void* arg, const StringPiece& index_value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Iterator* iter;
|
Iterator* iter;
|
||||||
if (block != NULL) {
|
if (block != nullptr) {
|
||||||
iter = block->NewIterator();
|
iter = block->NewIterator();
|
||||||
iter->RegisterCleanup(&DeleteBlock, block, NULL);
|
iter->RegisterCleanup(&DeleteBlock, block, nullptr);
|
||||||
} else {
|
} else {
|
||||||
iter = NewErrorIterator(s);
|
iter = NewErrorIterator(s);
|
||||||
}
|
}
|
||||||
|
@ -177,11 +177,11 @@ class Constructor {
|
|||||||
|
|
||||||
class BlockConstructor : public Constructor {
|
class BlockConstructor : public Constructor {
|
||||||
public:
|
public:
|
||||||
BlockConstructor() : block_(NULL) {}
|
BlockConstructor() : block_(nullptr) {}
|
||||||
~BlockConstructor() override { delete block_; }
|
~BlockConstructor() override { delete block_; }
|
||||||
Status FinishImpl(const Options& options, const KVMap& data) override {
|
Status FinishImpl(const Options& options, const KVMap& data) override {
|
||||||
delete block_;
|
delete block_;
|
||||||
block_ = NULL;
|
block_ = nullptr;
|
||||||
BlockBuilder builder(&options);
|
BlockBuilder builder(&options);
|
||||||
|
|
||||||
for (KVMap::const_iterator it = data.begin(); it != data.end(); ++it) {
|
for (KVMap::const_iterator it = data.begin(); it != data.end(); ++it) {
|
||||||
@ -205,7 +205,7 @@ class BlockConstructor : public Constructor {
|
|||||||
|
|
||||||
class TableConstructor : public Constructor {
|
class TableConstructor : public Constructor {
|
||||||
public:
|
public:
|
||||||
TableConstructor() : source_(NULL), table_(NULL) {}
|
TableConstructor() : source_(nullptr), table_(nullptr) {}
|
||||||
~TableConstructor() override { Reset(); }
|
~TableConstructor() override { Reset(); }
|
||||||
Status FinishImpl(const Options& options, const KVMap& data) override {
|
Status FinishImpl(const Options& options, const KVMap& data) override {
|
||||||
Reset();
|
Reset();
|
||||||
@ -239,8 +239,8 @@ class TableConstructor : public Constructor {
|
|||||||
void Reset() {
|
void Reset() {
|
||||||
delete table_;
|
delete table_;
|
||||||
delete source_;
|
delete source_;
|
||||||
table_ = NULL;
|
table_ = nullptr;
|
||||||
source_ = NULL;
|
source_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringSource* source_;
|
StringSource* source_;
|
||||||
@ -262,11 +262,11 @@ static const int kNumTestArgs = sizeof(kTestArgList) / sizeof(kTestArgList[0]);
|
|||||||
|
|
||||||
class Harness : public ::testing::Test {
|
class Harness : public ::testing::Test {
|
||||||
public:
|
public:
|
||||||
Harness() : constructor_(NULL) {}
|
Harness() : constructor_(nullptr) {}
|
||||||
|
|
||||||
void Init(const TestArgs& args) {
|
void Init(const TestArgs& args) {
|
||||||
delete constructor_;
|
delete constructor_;
|
||||||
constructor_ = NULL;
|
constructor_ = nullptr;
|
||||||
options_ = Options();
|
options_ = Options();
|
||||||
|
|
||||||
options_.block_restart_interval = args.restart_interval;
|
options_.block_restart_interval = args.restart_interval;
|
||||||
|
@ -54,7 +54,7 @@ class TwoLevelIterator : public Iterator {
|
|||||||
// Status
|
// Status
|
||||||
if (!index_iter_->status().ok()) {
|
if (!index_iter_->status().ok()) {
|
||||||
return index_iter_->status();
|
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();
|
return data_iter_->status();
|
||||||
} else {
|
} else {
|
||||||
return status_;
|
return status_;
|
||||||
@ -84,7 +84,7 @@ TwoLevelIterator::TwoLevelIterator(Iterator* index_iter,
|
|||||||
: block_function_(block_function),
|
: block_function_(block_function),
|
||||||
arg_(arg),
|
arg_(arg),
|
||||||
index_iter_(index_iter),
|
index_iter_(index_iter),
|
||||||
data_iter_(NULL) {}
|
data_iter_(nullptr) {}
|
||||||
|
|
||||||
TwoLevelIterator::~TwoLevelIterator() {
|
TwoLevelIterator::~TwoLevelIterator() {
|
||||||
delete index_iter_;
|
delete index_iter_;
|
||||||
@ -94,14 +94,14 @@ TwoLevelIterator::~TwoLevelIterator() {
|
|||||||
void TwoLevelIterator::Seek(const StringPiece& target) {
|
void TwoLevelIterator::Seek(const StringPiece& target) {
|
||||||
index_iter_->Seek(target);
|
index_iter_->Seek(target);
|
||||||
InitDataBlock();
|
InitDataBlock();
|
||||||
if (data_iter_ != NULL) data_iter_->Seek(target);
|
if (data_iter_ != nullptr) data_iter_->Seek(target);
|
||||||
SkipEmptyDataBlocksForward();
|
SkipEmptyDataBlocksForward();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TwoLevelIterator::SeekToFirst() {
|
void TwoLevelIterator::SeekToFirst() {
|
||||||
index_iter_->SeekToFirst();
|
index_iter_->SeekToFirst();
|
||||||
InitDataBlock();
|
InitDataBlock();
|
||||||
if (data_iter_ != NULL) data_iter_->SeekToFirst();
|
if (data_iter_ != nullptr) data_iter_->SeekToFirst();
|
||||||
SkipEmptyDataBlocksForward();
|
SkipEmptyDataBlocksForward();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,20 +112,20 @@ void TwoLevelIterator::Next() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TwoLevelIterator::SkipEmptyDataBlocksForward() {
|
void TwoLevelIterator::SkipEmptyDataBlocksForward() {
|
||||||
while (data_iter_ == NULL || !data_iter_->Valid()) {
|
while (data_iter_ == nullptr || !data_iter_->Valid()) {
|
||||||
// Move to next block
|
// Move to next block
|
||||||
if (!index_iter_->Valid()) {
|
if (!index_iter_->Valid()) {
|
||||||
SetDataIterator(NULL);
|
SetDataIterator(nullptr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
index_iter_->Next();
|
index_iter_->Next();
|
||||||
InitDataBlock();
|
InitDataBlock();
|
||||||
if (data_iter_ != NULL) data_iter_->SeekToFirst();
|
if (data_iter_ != nullptr) data_iter_->SeekToFirst();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TwoLevelIterator::SetDataIterator(Iterator* data_iter) {
|
void TwoLevelIterator::SetDataIterator(Iterator* data_iter) {
|
||||||
if (data_iter_ != NULL) {
|
if (data_iter_ != nullptr) {
|
||||||
SaveError(data_iter_->status());
|
SaveError(data_iter_->status());
|
||||||
delete data_iter_;
|
delete data_iter_;
|
||||||
}
|
}
|
||||||
@ -134,10 +134,10 @@ void TwoLevelIterator::SetDataIterator(Iterator* data_iter) {
|
|||||||
|
|
||||||
void TwoLevelIterator::InitDataBlock() {
|
void TwoLevelIterator::InitDataBlock() {
|
||||||
if (!index_iter_->Valid()) {
|
if (!index_iter_->Valid()) {
|
||||||
SetDataIterator(NULL);
|
SetDataIterator(nullptr);
|
||||||
} else {
|
} else {
|
||||||
StringPiece handle = index_iter_->value();
|
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
|
// data_iter_ is already constructed with this iterator, so
|
||||||
// no need to change anything
|
// no need to change anything
|
||||||
} else {
|
} else {
|
||||||
|
@ -60,7 +60,7 @@ void ZlibInputStream::InitZlibBuffer() {
|
|||||||
int status = inflateInit2(z_stream_.get(), zlib_options_.window_bits);
|
int status = inflateInit2(z_stream_.get(), zlib_options_.window_bits);
|
||||||
if (status != Z_OK) {
|
if (status != Z_OK) {
|
||||||
LOG(FATAL) << "inflateInit failed with status " << status;
|
LOG(FATAL) << "inflateInit failed with status " << status;
|
||||||
z_stream_.reset(NULL);
|
z_stream_.reset(nullptr);
|
||||||
} else {
|
} else {
|
||||||
z_stream_->next_in = z_stream_input_.get();
|
z_stream_->next_in = z_stream_input_.get();
|
||||||
z_stream_->next_out = z_stream_output_.get();
|
z_stream_->next_out = z_stream_output_.get();
|
||||||
@ -180,7 +180,7 @@ Status ZlibInputStream::Inflate() {
|
|||||||
if (error != Z_OK && error != Z_STREAM_END) {
|
if (error != Z_OK && error != Z_STREAM_END) {
|
||||||
string error_string =
|
string error_string =
|
||||||
strings::StrCat("inflate() failed with error ", error);
|
strings::StrCat("inflate() failed with error ", error);
|
||||||
if (z_stream_->msg != NULL) {
|
if (z_stream_->msg != nullptr) {
|
||||||
strings::StrAppend(&error_string, ": ", z_stream_->msg);
|
strings::StrAppend(&error_string, ": ", z_stream_->msg);
|
||||||
}
|
}
|
||||||
return errors::DataLoss(error_string);
|
return errors::DataLoss(error_string);
|
||||||
|
@ -58,7 +58,7 @@ Status ZlibOutputBuffer::Init() {
|
|||||||
zlib_options_.compression_method, zlib_options_.window_bits,
|
zlib_options_.compression_method, zlib_options_.window_bits,
|
||||||
zlib_options_.mem_level, zlib_options_.compression_strategy);
|
zlib_options_.mem_level, zlib_options_.compression_strategy);
|
||||||
if (status != Z_OK) {
|
if (status != Z_OK) {
|
||||||
z_stream_.reset(NULL);
|
z_stream_.reset(nullptr);
|
||||||
return errors::InvalidArgument("deflateInit failed with status", status);
|
return errors::InvalidArgument("deflateInit failed with status", status);
|
||||||
}
|
}
|
||||||
z_stream_->next_in = z_stream_input_.get();
|
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(DeflateBuffered(true));
|
||||||
TF_RETURN_IF_ERROR(FlushOutputBufferToFile());
|
TF_RETURN_IF_ERROR(FlushOutputBufferToFile());
|
||||||
deflateEnd(z_stream_.get());
|
deflateEnd(z_stream_.get());
|
||||||
z_stream_.reset(NULL);
|
z_stream_.reset(nullptr);
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,7 +217,7 @@ Status ZlibOutputBuffer::Deflate(int flush) {
|
|||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
string error_string = strings::StrCat("deflate() failed with error ", error);
|
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);
|
strings::StrAppend(&error_string, ": ", z_stream_->msg);
|
||||||
}
|
}
|
||||||
return errors::DataLoss(error_string);
|
return errors::DataLoss(error_string);
|
||||||
|
@ -79,14 +79,14 @@ void MemTermDestination(j_compress_ptr cinfo) {
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
void SetDest(j_compress_ptr cinfo, void *buffer, int bufsize) {
|
void SetDest(j_compress_ptr cinfo, void *buffer, int bufsize) {
|
||||||
SetDest(cinfo, buffer, bufsize, NULL);
|
SetDest(cinfo, buffer, bufsize, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
void SetDest(j_compress_ptr cinfo, void *buffer, int bufsize,
|
void SetDest(j_compress_ptr cinfo, void *buffer, int bufsize,
|
||||||
string *destination) {
|
string *destination) {
|
||||||
MemDestMgr *dest;
|
MemDestMgr *dest;
|
||||||
if (cinfo->dest == NULL) {
|
if (cinfo->dest == nullptr) {
|
||||||
cinfo->dest = reinterpret_cast<struct jpeg_destination_mgr *>(
|
cinfo->dest = reinterpret_cast<struct jpeg_destination_mgr *>(
|
||||||
(*cinfo->mem->alloc_small)(reinterpret_cast<j_common_ptr>(cinfo),
|
(*cinfo->mem->alloc_small)(reinterpret_cast<j_common_ptr>(cinfo),
|
||||||
JPOOL_PERMANENT, sizeof(MemDestMgr)));
|
JPOOL_PERMANENT, sizeof(MemDestMgr)));
|
||||||
@ -177,7 +177,7 @@ void SetSrc(j_decompress_ptr cinfo, const void *data,
|
|||||||
src->data = reinterpret_cast<const unsigned char *>(data);
|
src->data = reinterpret_cast<const unsigned char *>(data);
|
||||||
src->datasize = datasize;
|
src->datasize = datasize;
|
||||||
src->pub.bytes_in_buffer = 0;
|
src->pub.bytes_in_buffer = 0;
|
||||||
src->pub.next_input_byte = NULL;
|
src->pub.next_input_byte = nullptr;
|
||||||
src->try_recover_truncated_jpeg = try_recover_truncated_jpeg;
|
src->try_recover_truncated_jpeg = try_recover_truncated_jpeg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ uint8* UncompressLow(const void* srcdata, FewerArgsForCompiler* argball) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if empty image, return
|
// if empty image, return
|
||||||
if (datasize == 0 || srcdata == NULL) return nullptr;
|
if (datasize == 0 || srcdata == nullptr) return nullptr;
|
||||||
|
|
||||||
// Declare temporary buffer pointer here so that we can free on error paths
|
// Declare temporary buffer pointer here so that we can free on error paths
|
||||||
JSAMPLE* tempdata = nullptr;
|
JSAMPLE* tempdata = nullptr;
|
||||||
@ -183,7 +183,7 @@ uint8* UncompressLow(const void* srcdata, FewerArgsForCompiler* argball) {
|
|||||||
|
|
||||||
// Temporary buffer used for CMYK -> RGB conversion.
|
// Temporary buffer used for CMYK -> RGB conversion.
|
||||||
const bool use_cmyk = (cinfo.out_color_space == JCS_CMYK);
|
const bool use_cmyk = (cinfo.out_color_space == JCS_CMYK);
|
||||||
tempdata = use_cmyk ? new JSAMPLE[cinfo.output_width * 4] : NULL;
|
tempdata = use_cmyk ? new JSAMPLE[cinfo.output_width * 4] : nullptr;
|
||||||
|
|
||||||
// If there is an error reading a line, this aborts the reading.
|
// If there is an error reading a line, this aborts the reading.
|
||||||
// Save the fraction of the image that has been read.
|
// Save the fraction of the image that has been read.
|
||||||
@ -246,7 +246,7 @@ uint8* UncompressLow(const void* srcdata, FewerArgsForCompiler* argball) {
|
|||||||
output_line += stride;
|
output_line += stride;
|
||||||
}
|
}
|
||||||
delete[] tempdata;
|
delete[] tempdata;
|
||||||
tempdata = NULL;
|
tempdata = nullptr;
|
||||||
|
|
||||||
// Convert the RGB data to RGBA, with alpha set to 0xFF to indicate
|
// Convert the RGB data to RGBA, with alpha set to 0xFF to indicate
|
||||||
// opacity.
|
// opacity.
|
||||||
@ -345,10 +345,10 @@ uint8* Uncompress(const void* srcdata, int datasize,
|
|||||||
argball.height_ == 0
|
argball.height_ == 0
|
||||||
? 1.0
|
? 1.0
|
||||||
: (static_cast<float>(argball.height_read_) / argball.height_);
|
: (static_cast<float>(argball.height_read_) / argball.height_);
|
||||||
if (dstdata == NULL ||
|
if (dstdata == nullptr ||
|
||||||
fraction_read < std::min(1.0f, flags.min_acceptable_fraction)) {
|
fraction_read < std::min(1.0f, flags.min_acceptable_fraction)) {
|
||||||
// Major failure, none or too-partial read returned; get out
|
// Major failure, none or too-partial read returned; get out
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there was an error in reading the jpeg data,
|
// If there was an error in reading the jpeg data,
|
||||||
@ -366,7 +366,7 @@ uint8* Uncompress(const void* srcdata, int datasize,
|
|||||||
uint8* Uncompress(const void* srcdata, int datasize,
|
uint8* Uncompress(const void* srcdata, int datasize,
|
||||||
const UncompressFlags& flags, int* pwidth, int* pheight,
|
const UncompressFlags& flags, int* pwidth, int* pheight,
|
||||||
int* pcomponents, int64* nwarn) {
|
int* pcomponents, int64* nwarn) {
|
||||||
uint8* buffer = NULL;
|
uint8* buffer = nullptr;
|
||||||
uint8* result =
|
uint8* result =
|
||||||
Uncompress(srcdata, datasize, flags, nwarn,
|
Uncompress(srcdata, datasize, flags, nwarn,
|
||||||
[=, &buffer](int width, int height, int components) {
|
[=, &buffer](int width, int height, int components) {
|
||||||
@ -391,7 +391,7 @@ bool GetImageInfo(const void* srcdata, int datasize, int* width, int* height,
|
|||||||
if (components) *components = 0;
|
if (components) *components = 0;
|
||||||
|
|
||||||
// If empty image, return
|
// If empty image, return
|
||||||
if (datasize == 0 || srcdata == NULL) return false;
|
if (datasize == 0 || srcdata == nullptr) return false;
|
||||||
|
|
||||||
// Initialize libjpeg structures to have a memory source
|
// Initialize libjpeg structures to have a memory source
|
||||||
// Modify the usual jpeg error manager to catch fatal errors.
|
// Modify the usual jpeg error manager to catch fatal errors.
|
||||||
@ -449,7 +449,7 @@ bool CompressInternal(const uint8* srcdata, int width, int height,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
JOCTET* buffer = 0;
|
JOCTET* buffer = nullptr;
|
||||||
|
|
||||||
// NOTE: for broader use xmp_metadata should be made a unicode string
|
// NOTE: for broader use xmp_metadata should be made a unicode string
|
||||||
CHECK(srcdata != nullptr);
|
CHECK(srcdata != nullptr);
|
||||||
|
@ -70,18 +70,18 @@ void TestJPEG(Env* env, const string& jpegfile) {
|
|||||||
|
|
||||||
// Set min_acceptable_fraction to something insufficient
|
// Set min_acceptable_fraction to something insufficient
|
||||||
flags.min_acceptable_fraction = 0.8;
|
flags.min_acceptable_fraction = 0.8;
|
||||||
imgdata.reset(Uncompress(temp, fsize / 2, flags, &w, &h, &c, NULL));
|
imgdata.reset(Uncompress(temp, fsize / 2, flags, &w, &h, &c, nullptr));
|
||||||
CHECK(imgdata.get() == NULL);
|
CHECK(imgdata.get() == nullptr);
|
||||||
|
|
||||||
// Now, use a value that makes fsize/2 be enough for a black-filling
|
// Now, use a value that makes fsize/2 be enough for a black-filling
|
||||||
flags.min_acceptable_fraction = 0.01;
|
flags.min_acceptable_fraction = 0.01;
|
||||||
imgdata.reset(Uncompress(temp, fsize / 2, flags, &w, &h, &c, NULL));
|
imgdata.reset(Uncompress(temp, fsize / 2, flags, &w, &h, &c, nullptr));
|
||||||
CHECK(imgdata.get() != NULL);
|
CHECK(imgdata.get() != nullptr);
|
||||||
|
|
||||||
// Finally, uncompress the whole data
|
// Finally, uncompress the whole data
|
||||||
flags.min_acceptable_fraction = 1.0;
|
flags.min_acceptable_fraction = 1.0;
|
||||||
imgdata.reset(Uncompress(temp, fsize, flags, &w, &h, &c, NULL));
|
imgdata.reset(Uncompress(temp, fsize, flags, &w, &h, &c, nullptr));
|
||||||
CHECK(imgdata.get() != NULL);
|
CHECK(imgdata.get() != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(JpegMemTest, Jpeg) {
|
TEST(JpegMemTest, Jpeg) {
|
||||||
@ -153,8 +153,8 @@ TEST(JpegMemTest, Jpeg2) {
|
|||||||
UncompressFlags flags;
|
UncompressFlags flags;
|
||||||
flags.components = components;
|
flags.components = components;
|
||||||
int w, h, c;
|
int w, h, c;
|
||||||
imgdata1.reset(
|
imgdata1.reset(Uncompress(cpdata1.c_str(), cpdata1.length(), flags, &w, &h,
|
||||||
Uncompress(cpdata1.c_str(), cpdata1.length(), flags, &w, &h, &c, NULL));
|
&c, nullptr));
|
||||||
|
|
||||||
// Check obvious formatting stuff
|
// Check obvious formatting stuff
|
||||||
CHECK_EQ(w, in_w);
|
CHECK_EQ(w, in_w);
|
||||||
@ -193,8 +193,8 @@ TEST(JpegMemTest, Jpeg2) {
|
|||||||
flags.components = 3;
|
flags.components = 3;
|
||||||
flags.dct_method = JDCT_IFAST;
|
flags.dct_method = JDCT_IFAST;
|
||||||
int w, h, c;
|
int w, h, c;
|
||||||
imgdata1.reset(
|
imgdata1.reset(Uncompress(cpdata1.c_str(), cpdata1.length(), flags, &w, &h,
|
||||||
Uncompress(cpdata1.c_str(), cpdata1.length(), flags, &w, &h, &c, NULL));
|
&c, nullptr));
|
||||||
|
|
||||||
// Check obvious formatting stuff
|
// Check obvious formatting stuff
|
||||||
CHECK_EQ(w, in_w);
|
CHECK_EQ(w, in_w);
|
||||||
@ -267,7 +267,7 @@ TEST(JpegMemTest, ChromaDownsampling) {
|
|||||||
int64 num_warnings;
|
int64 num_warnings;
|
||||||
std::unique_ptr<uint8[]> uncompressed(Uncompress(
|
std::unique_ptr<uint8[]> uncompressed(Uncompress(
|
||||||
jpeg.c_str(), jpeg.size(), unflags, &w, &h, &c, &num_warnings));
|
jpeg.c_str(), jpeg.size(), unflags, &w, &h, &c, &num_warnings));
|
||||||
CHECK(uncompressed.get() != NULL);
|
CHECK(uncompressed.get() != nullptr);
|
||||||
CHECK_EQ(num_warnings, 0);
|
CHECK_EQ(num_warnings, 0);
|
||||||
|
|
||||||
// Recompress the JPEG with and without chroma downsampling
|
// Recompress the JPEG with and without chroma downsampling
|
||||||
@ -296,7 +296,7 @@ void TestBadJPEG(Env* env, const string& bad_jpeg_file, int expected_width,
|
|||||||
int width, height, components;
|
int width, height, components;
|
||||||
std::unique_ptr<uint8[]> imgdata;
|
std::unique_ptr<uint8[]> imgdata;
|
||||||
imgdata.reset(Uncompress(jpeg.c_str(), jpeg.size(), flags, &width, &height,
|
imgdata.reset(Uncompress(jpeg.c_str(), jpeg.size(), flags, &width, &height,
|
||||||
&components, NULL));
|
&components, nullptr));
|
||||||
if (expected_width > 0) { // we expect the file to decode into 'something'
|
if (expected_width > 0) { // we expect the file to decode into 'something'
|
||||||
CHECK_EQ(width, expected_width);
|
CHECK_EQ(width, expected_width);
|
||||||
CHECK_EQ(height, expected_height);
|
CHECK_EQ(height, expected_height);
|
||||||
|
@ -125,7 +125,8 @@ char* check_metadata_string(const string& s) {
|
|||||||
void CommonFreeDecode(DecodeContext* context) {
|
void CommonFreeDecode(DecodeContext* context) {
|
||||||
if (context->png_ptr) {
|
if (context->png_ptr) {
|
||||||
png_destroy_read_struct(&context->png_ptr,
|
png_destroy_read_struct(&context->png_ptr,
|
||||||
context->info_ptr ? &context->info_ptr : NULL, 0);
|
context->info_ptr ? &context->info_ptr : nullptr,
|
||||||
|
nullptr);
|
||||||
context->png_ptr = nullptr;
|
context->png_ptr = nullptr;
|
||||||
context->info_ptr = nullptr;
|
context->info_ptr = nullptr;
|
||||||
}
|
}
|
||||||
@ -150,7 +151,7 @@ bool DecodeHeader(StringPiece png_string, int* width, int* height,
|
|||||||
*width = static_cast<int>(context.width);
|
*width = static_cast<int>(context.width);
|
||||||
CHECK_NOTNULL(height);
|
CHECK_NOTNULL(height);
|
||||||
*height = static_cast<int>(context.height);
|
*height = static_cast<int>(context.height);
|
||||||
if (components != NULL) {
|
if (components != nullptr) {
|
||||||
switch (context.color_type) {
|
switch (context.color_type) {
|
||||||
case PNG_COLOR_TYPE_PALETTE:
|
case PNG_COLOR_TYPE_PALETTE:
|
||||||
*components =
|
*components =
|
||||||
@ -175,12 +176,12 @@ bool DecodeHeader(StringPiece png_string, int* width, int* height,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (channel_bit_depth != NULL) {
|
if (channel_bit_depth != nullptr) {
|
||||||
*channel_bit_depth = context.bit_depth;
|
*channel_bit_depth = context.bit_depth;
|
||||||
}
|
}
|
||||||
if (metadata != NULL) {
|
if (metadata != nullptr) {
|
||||||
metadata->clear();
|
metadata->clear();
|
||||||
png_textp text_ptr = NULL;
|
png_textp text_ptr = nullptr;
|
||||||
int num_text = 0;
|
int num_text = 0;
|
||||||
png_get_text(context.png_ptr, context.info_ptr, &text_ptr, &num_text);
|
png_get_text(context.png_ptr, context.info_ptr, &text_ptr, &num_text);
|
||||||
for (int i = 0; i < num_text; i++) {
|
for (int i = 0; i < num_text; i++) {
|
||||||
@ -222,8 +223,8 @@ bool CommonInitDecode(StringPiece png_string, int desired_channels,
|
|||||||
png_set_read_fn(context->png_ptr, context, StringReader);
|
png_set_read_fn(context->png_ptr, context, StringReader);
|
||||||
png_read_info(context->png_ptr, context->info_ptr);
|
png_read_info(context->png_ptr, context->info_ptr);
|
||||||
png_get_IHDR(context->png_ptr, context->info_ptr, &context->width,
|
png_get_IHDR(context->png_ptr, context->info_ptr, &context->width,
|
||||||
&context->height, &context->bit_depth, &context->color_type, 0,
|
&context->height, &context->bit_depth, &context->color_type,
|
||||||
0, 0);
|
nullptr, nullptr, nullptr);
|
||||||
if (context->error_condition) {
|
if (context->error_condition) {
|
||||||
VLOG(1) << ": DecodePNG <- error during header parsing.";
|
VLOG(1) << ": DecodePNG <- error during header parsing.";
|
||||||
CommonFreeDecode(context);
|
CommonFreeDecode(context);
|
||||||
@ -307,7 +308,7 @@ bool CommonFinishDecode(png_bytep data, int row_bytes, DecodeContext* context) {
|
|||||||
for (int p = 0; p < context->num_passes; ++p) {
|
for (int p = 0; p < context->num_passes; ++p) {
|
||||||
png_bytep row = data;
|
png_bytep row = data;
|
||||||
for (int h = context->height; h-- != 0; row += row_bytes) {
|
for (int h = context->height; h-- != 0; row += row_bytes) {
|
||||||
png_read_row(context->png_ptr, row, NULL);
|
png_read_row(context->png_ptr, row, nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,17 +340,17 @@ bool WriteImageToBuffer(
|
|||||||
if (width == 0 || height == 0) return false;
|
if (width == 0 || height == 0) return false;
|
||||||
|
|
||||||
png_string->resize(0);
|
png_string->resize(0);
|
||||||
png_infop info_ptr = NULL;
|
png_infop info_ptr = nullptr;
|
||||||
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL,
|
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr,
|
||||||
ErrorHandler, WarningHandler);
|
ErrorHandler, WarningHandler);
|
||||||
if (png_ptr == NULL) return false;
|
if (png_ptr == nullptr) return false;
|
||||||
if (setjmp(png_jmpbuf(png_ptr))) {
|
if (setjmp(png_jmpbuf(png_ptr))) {
|
||||||
png_destroy_write_struct(&png_ptr, info_ptr ? &info_ptr : NULL);
|
png_destroy_write_struct(&png_ptr, info_ptr ? &info_ptr : nullptr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
info_ptr = png_create_info_struct(png_ptr);
|
info_ptr = png_create_info_struct(png_ptr);
|
||||||
if (info_ptr == NULL) {
|
if (info_ptr == nullptr) {
|
||||||
png_destroy_write_struct(&png_ptr, NULL);
|
png_destroy_write_struct(&png_ptr, nullptr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -400,7 +401,7 @@ bool WriteImageToBuffer(
|
|||||||
|
|
||||||
png_byte* row = reinterpret_cast<png_byte*>(const_cast<void*>(image));
|
png_byte* row = reinterpret_cast<png_byte*>(const_cast<void*>(image));
|
||||||
for (; height--; row += row_bytes) png_write_row(png_ptr, row);
|
for (; height--; row += row_bytes) png_write_row(png_ptr, row);
|
||||||
png_write_end(png_ptr, NULL);
|
png_write_end(png_ptr, nullptr);
|
||||||
|
|
||||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||||
return true;
|
return true;
|
||||||
|
@ -166,7 +166,7 @@ char* DoubleToBuffer(double value, char* buffer) {
|
|||||||
DCHECK(snprintf_result > 0 && snprintf_result < kFastToBufferSize);
|
DCHECK(snprintf_result > 0 && snprintf_result < kFastToBufferSize);
|
||||||
|
|
||||||
full_precision_needed =
|
full_precision_needed =
|
||||||
locale_independent_strtonum<double>(buffer, NULL) != value;
|
locale_independent_strtonum<double>(buffer, nullptr) != value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (full_precision_needed) {
|
if (full_precision_needed) {
|
||||||
|
@ -102,7 +102,7 @@ static T TestRead(const string& a) {
|
|||||||
// gracefully reject any proper prefix of an encoding
|
// gracefully reject any proper prefix of an encoding
|
||||||
for (int i = 0; i < a.size() - 1; ++i) {
|
for (int i = 0; i < a.size() - 1; ++i) {
|
||||||
StringPiece s(a.data(), i);
|
StringPiece s(a.data(), i);
|
||||||
CHECK(!OCRead<T>(&s, NULL));
|
CHECK(!OCRead<T>(&s, nullptr));
|
||||||
CHECK_EQ(s, a.substr(0, i));
|
CHECK_EQ(s, a.substr(0, i));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -296,7 +296,7 @@ static inline string StrNot(const string& s) {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
static void TestInvalidEncoding(const string& s) {
|
static void TestInvalidEncoding(const string& s) {
|
||||||
StringPiece p(s);
|
StringPiece p(s);
|
||||||
EXPECT_FALSE(OCRead<T>(&p, static_cast<T*>(NULL)));
|
EXPECT_FALSE(OCRead<T>(&p, static_cast<T*>(nullptr)));
|
||||||
EXPECT_EQ(s, p);
|
EXPECT_EQ(s, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -330,7 +330,8 @@ TEST(OrderedCodeInvalidEncodingsDeathTest, NonCanonical) {
|
|||||||
EXPECT_NE(OCWrite<uint64>(0), non_minimal);
|
EXPECT_NE(OCWrite<uint64>(0), non_minimal);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
StringPiece s(non_minimal);
|
StringPiece s(non_minimal);
|
||||||
EXPECT_DEATH(OrderedCode::ReadNumIncreasing(&s, NULL), "invalid encoding");
|
EXPECT_DEATH(OrderedCode::ReadNumIncreasing(&s, nullptr),
|
||||||
|
"invalid encoding");
|
||||||
#else
|
#else
|
||||||
TestRead<uint64>(non_minimal);
|
TestRead<uint64>(non_minimal);
|
||||||
#endif
|
#endif
|
||||||
@ -348,7 +349,7 @@ TEST(OrderedCodeInvalidEncodingsDeathTest, NonCanonical) {
|
|||||||
EXPECT_NE(OCWrite<int64>(0), non_minimal);
|
EXPECT_NE(OCWrite<int64>(0), non_minimal);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
StringPiece s(non_minimal);
|
StringPiece s(non_minimal);
|
||||||
EXPECT_DEATH(OrderedCode::ReadSignedNumIncreasing(&s, NULL),
|
EXPECT_DEATH(OrderedCode::ReadSignedNumIncreasing(&s, nullptr),
|
||||||
"invalid encoding")
|
"invalid encoding")
|
||||||
<< n;
|
<< n;
|
||||||
#else
|
#else
|
||||||
@ -439,15 +440,15 @@ TEST(String, EncodeDecode) {
|
|||||||
StringPiece s = out;
|
StringPiece s = out;
|
||||||
StringPiece s2 = out;
|
StringPiece s2 = out;
|
||||||
CHECK(OCRead<string>(&s, &a2));
|
CHECK(OCRead<string>(&s, &a2));
|
||||||
CHECK(OCRead<string>(&s2, NULL));
|
CHECK(OCRead<string>(&s2, nullptr));
|
||||||
CHECK_EQ(s, s2);
|
CHECK_EQ(s, s2);
|
||||||
|
|
||||||
CHECK(OCRead<string>(&s, &b2));
|
CHECK(OCRead<string>(&s, &b2));
|
||||||
CHECK(OCRead<string>(&s2, NULL));
|
CHECK(OCRead<string>(&s2, nullptr));
|
||||||
CHECK_EQ(s, s2);
|
CHECK_EQ(s, s2);
|
||||||
|
|
||||||
CHECK(!OCRead<string>(&s, &dummy));
|
CHECK(!OCRead<string>(&s, &dummy));
|
||||||
CHECK(!OCRead<string>(&s2, NULL));
|
CHECK(!OCRead<string>(&s2, nullptr));
|
||||||
CHECK_EQ(a, a2);
|
CHECK_EQ(a, a2);
|
||||||
CHECK_EQ(b, b2);
|
CHECK_EQ(b, b2);
|
||||||
CHECK(s.empty());
|
CHECK(s.empty());
|
||||||
|
@ -52,7 +52,7 @@ void Appendv(string* dst, const char* format, va_list ap) {
|
|||||||
// Error or MSVC running out of space. MSVC 8.0 and higher
|
// Error or MSVC running out of space. MSVC 8.0 and higher
|
||||||
// can be asked about space needed with the special idiom below:
|
// can be asked about space needed with the special idiom below:
|
||||||
va_copy(backup_ap, ap);
|
va_copy(backup_ap, ap);
|
||||||
result = vsnprintf(NULL, 0, format, backup_ap);
|
result = vsnprintf(nullptr, 0, format, backup_ap);
|
||||||
va_end(backup_ap);
|
va_end(backup_ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ TEST(PrintfTest, Multibyte) {
|
|||||||
// out of memory while trying to determine destination buffer size.
|
// out of memory while trying to determine destination buffer size.
|
||||||
// see b/4194543.
|
// see b/4194543.
|
||||||
|
|
||||||
char* old_locale = setlocale(LC_CTYPE, NULL);
|
char* old_locale = setlocale(LC_CTYPE, nullptr);
|
||||||
// Push locale with multibyte mode
|
// Push locale with multibyte mode
|
||||||
setlocale(LC_CTYPE, "en_US.utf8");
|
setlocale(LC_CTYPE, "en_US.utf8");
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ TEST(PrintfTest, Multibyte) {
|
|||||||
|
|
||||||
TEST(PrintfTest, NoMultibyte) {
|
TEST(PrintfTest, NoMultibyte) {
|
||||||
// No multibyte handling, but the string contains funny chars.
|
// No multibyte handling, but the string contains funny chars.
|
||||||
char* old_locale = setlocale(LC_CTYPE, NULL);
|
char* old_locale = setlocale(LC_CTYPE, nullptr);
|
||||||
setlocale(LC_CTYPE, "POSIX");
|
setlocale(LC_CTYPE, "POSIX");
|
||||||
string value = Printf("%.*s", 3, "\375\067s");
|
string value = Printf("%.*s", 3, "\375\067s");
|
||||||
setlocale(LC_CTYPE, old_locale);
|
setlocale(LC_CTYPE, old_locale);
|
||||||
|
@ -100,14 +100,14 @@ Status CreateSignature(RSA* private_key, StringPiece to_sign,
|
|||||||
EVP_PKEY_new(), [](EVP_PKEY* ptr) { EVP_PKEY_free(ptr); });
|
EVP_PKEY_new(), [](EVP_PKEY* ptr) { EVP_PKEY_free(ptr); });
|
||||||
EVP_PKEY_set1_RSA(key.get(), private_key);
|
EVP_PKEY_set1_RSA(key.get(), private_key);
|
||||||
|
|
||||||
if (EVP_DigestSignInit(md_ctx.get(), NULL, md, NULL, key.get()) != 1) {
|
if (EVP_DigestSignInit(md_ctx.get(), nullptr, md, nullptr, key.get()) != 1) {
|
||||||
return errors::Internal("DigestInit failed.");
|
return errors::Internal("DigestInit failed.");
|
||||||
}
|
}
|
||||||
if (EVP_DigestSignUpdate(md_ctx.get(), to_sign.data(), to_sign.size()) != 1) {
|
if (EVP_DigestSignUpdate(md_ctx.get(), to_sign.data(), to_sign.size()) != 1) {
|
||||||
return errors::Internal("DigestUpdate failed.");
|
return errors::Internal("DigestUpdate failed.");
|
||||||
}
|
}
|
||||||
size_t sig_len = 0;
|
size_t sig_len = 0;
|
||||||
if (EVP_DigestSignFinal(md_ctx.get(), NULL, &sig_len) != 1) {
|
if (EVP_DigestSignFinal(md_ctx.get(), nullptr, &sig_len) != 1) {
|
||||||
return errors::Internal("DigestFinal (get signature length) failed.");
|
return errors::Internal("DigestFinal (get signature length) failed.");
|
||||||
}
|
}
|
||||||
std::unique_ptr<unsigned char[]> sig(new unsigned char[sig_len]);
|
std::unique_ptr<unsigned char[]> sig(new unsigned char[sig_len]);
|
||||||
|
@ -110,7 +110,7 @@ class CPUIDInfo {
|
|||||||
|
|
||||||
static void Initialize() {
|
static void Initialize() {
|
||||||
// Initialize cpuid struct
|
// Initialize cpuid struct
|
||||||
CHECK(cpuid == NULL) << __func__ << " ran more than once";
|
CHECK(cpuid == nullptr) << __func__ << " ran more than once";
|
||||||
cpuid = new CPUIDInfo;
|
cpuid = new CPUIDInfo;
|
||||||
|
|
||||||
uint32 eax, ebx, ecx, edx;
|
uint32 eax, ebx, ecx, edx;
|
||||||
|
@ -26,7 +26,7 @@ namespace port {
|
|||||||
TEST(Port, AlignedMalloc) {
|
TEST(Port, AlignedMalloc) {
|
||||||
for (size_t alignment = 1; alignment <= 1 << 20; alignment <<= 1) {
|
for (size_t alignment = 1; alignment <= 1 << 20; alignment <<= 1) {
|
||||||
void* p = AlignedMalloc(1, alignment);
|
void* p = AlignedMalloc(1, alignment);
|
||||||
ASSERT_TRUE(p != NULL) << "AlignedMalloc(1, " << alignment << ")";
|
ASSERT_TRUE(p != nullptr) << "AlignedMalloc(1, " << alignment << ")";
|
||||||
uintptr_t pval = reinterpret_cast<uintptr_t>(p);
|
uintptr_t pval = reinterpret_cast<uintptr_t>(p);
|
||||||
EXPECT_EQ(pval % alignment, 0);
|
EXPECT_EQ(pval % alignment, 0);
|
||||||
AlignedFree(p);
|
AlignedFree(p);
|
||||||
@ -38,14 +38,14 @@ TEST(ConditionVariable, WaitForMilliseconds_Timeout) {
|
|||||||
mutex_lock l(m);
|
mutex_lock l(m);
|
||||||
condition_variable cv;
|
condition_variable cv;
|
||||||
ConditionResult result = kCond_MaybeNotified;
|
ConditionResult result = kCond_MaybeNotified;
|
||||||
time_t start = time(NULL);
|
time_t start = time(nullptr);
|
||||||
// Condition variables are subject to spurious wakeups on some platforms,
|
// Condition variables are subject to spurious wakeups on some platforms,
|
||||||
// so need to check for a timeout within a loop.
|
// so need to check for a timeout within a loop.
|
||||||
while (result == kCond_MaybeNotified) {
|
while (result == kCond_MaybeNotified) {
|
||||||
result = WaitForMilliseconds(&l, &cv, 3000);
|
result = WaitForMilliseconds(&l, &cv, 3000);
|
||||||
}
|
}
|
||||||
EXPECT_EQ(result, kCond_Timeout);
|
EXPECT_EQ(result, kCond_Timeout);
|
||||||
time_t finish = time(NULL);
|
time_t finish = time(nullptr);
|
||||||
EXPECT_GE(finish - start, 3);
|
EXPECT_GE(finish - start, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ TEST(ConditionVariable, WaitForMilliseconds_Signalled) {
|
|||||||
mutex m;
|
mutex m;
|
||||||
mutex_lock l(m);
|
mutex_lock l(m);
|
||||||
condition_variable cv;
|
condition_variable cv;
|
||||||
time_t start = time(NULL);
|
time_t start = time(nullptr);
|
||||||
// Sleep for just 1 second then notify. We have a timeout of 3 secs,
|
// Sleep for just 1 second then notify. We have a timeout of 3 secs,
|
||||||
// so the condition variable will notice the cv signal before the timeout.
|
// so the condition variable will notice the cv signal before the timeout.
|
||||||
pool.Schedule([&m, &cv]() {
|
pool.Schedule([&m, &cv]() {
|
||||||
@ -63,7 +63,7 @@ TEST(ConditionVariable, WaitForMilliseconds_Signalled) {
|
|||||||
cv.notify_all();
|
cv.notify_all();
|
||||||
});
|
});
|
||||||
EXPECT_EQ(WaitForMilliseconds(&l, &cv, 3000), kCond_MaybeNotified);
|
EXPECT_EQ(WaitForMilliseconds(&l, &cv, 3000), kCond_MaybeNotified);
|
||||||
time_t finish = time(NULL);
|
time_t finish = time(nullptr);
|
||||||
EXPECT_LT(finish - start, 3);
|
EXPECT_LT(finish - start, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ class PosixEnvTime : public EnvTime {
|
|||||||
|
|
||||||
uint64 NowMicros() override {
|
uint64 NowMicros() override {
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, nullptr);
|
||||||
return static_cast<uint64>(tv.tv_sec) * 1000000 + tv.tv_usec;
|
return static_cast<uint64>(tv.tv_sec) * 1000000 + tv.tv_usec;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -70,7 +70,7 @@ void* AlignedMalloc(size_t size, int minimum_alignment) {
|
|||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
return memalign(minimum_alignment, size);
|
return memalign(minimum_alignment, size);
|
||||||
#else // !defined(__ANDROID__)
|
#else // !defined(__ANDROID__)
|
||||||
void* ptr = NULL;
|
void* ptr = nullptr;
|
||||||
// posix_memalign requires that the requested alignment be at least
|
// posix_memalign requires that the requested alignment be at least
|
||||||
// sizeof(void*). In this case, fall back on malloc which should return
|
// sizeof(void*). In this case, fall back on malloc which should return
|
||||||
// memory aligned to at least the size of a pointer.
|
// memory aligned to at least the size of a pointer.
|
||||||
@ -82,7 +82,7 @@ void* AlignedMalloc(size_t size, int minimum_alignment) {
|
|||||||
int err = posix_memalign(&ptr, minimum_alignment, size);
|
int err = posix_memalign(&ptr, minimum_alignment, size);
|
||||||
#endif
|
#endif
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
return NULL;
|
return nullptr;
|
||||||
} else {
|
} else {
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ class PosixWritableFile : public WritableFile {
|
|||||||
: filename_(fname), file_(f) {}
|
: filename_(fname), file_(f) {}
|
||||||
|
|
||||||
~PosixWritableFile() override {
|
~PosixWritableFile() override {
|
||||||
if (file_ != NULL) {
|
if (file_ != nullptr) {
|
||||||
// Ignoring any potential errors
|
// Ignoring any potential errors
|
||||||
fclose(file_);
|
fclose(file_);
|
||||||
}
|
}
|
||||||
@ -97,7 +97,7 @@ class PosixWritableFile : public WritableFile {
|
|||||||
if (fclose(file_) != 0) {
|
if (fclose(file_) != 0) {
|
||||||
result = IOError(filename_, errno);
|
result = IOError(filename_, errno);
|
||||||
}
|
}
|
||||||
file_ = NULL;
|
file_ = nullptr;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,7 +150,7 @@ Status PosixFileSystem::NewWritableFile(const string& fname,
|
|||||||
string translated_fname = TranslateName(fname);
|
string translated_fname = TranslateName(fname);
|
||||||
Status s;
|
Status s;
|
||||||
FILE* f = fopen(translated_fname.c_str(), "w");
|
FILE* f = fopen(translated_fname.c_str(), "w");
|
||||||
if (f == NULL) {
|
if (f == nullptr) {
|
||||||
s = IOError(fname, errno);
|
s = IOError(fname, errno);
|
||||||
} else {
|
} else {
|
||||||
result->reset(new PosixWritableFile(translated_fname, f));
|
result->reset(new PosixWritableFile(translated_fname, f));
|
||||||
@ -163,7 +163,7 @@ Status PosixFileSystem::NewAppendableFile(
|
|||||||
string translated_fname = TranslateName(fname);
|
string translated_fname = TranslateName(fname);
|
||||||
Status s;
|
Status s;
|
||||||
FILE* f = fopen(translated_fname.c_str(), "a");
|
FILE* f = fopen(translated_fname.c_str(), "a");
|
||||||
if (f == NULL) {
|
if (f == nullptr) {
|
||||||
s = IOError(fname, errno);
|
s = IOError(fname, errno);
|
||||||
} else {
|
} else {
|
||||||
result->reset(new PosixWritableFile(translated_fname, f));
|
result->reset(new PosixWritableFile(translated_fname, f));
|
||||||
@ -205,11 +205,11 @@ Status PosixFileSystem::GetChildren(const string& dir,
|
|||||||
string translated_dir = TranslateName(dir);
|
string translated_dir = TranslateName(dir);
|
||||||
result->clear();
|
result->clear();
|
||||||
DIR* d = opendir(translated_dir.c_str());
|
DIR* d = opendir(translated_dir.c_str());
|
||||||
if (d == NULL) {
|
if (d == nullptr) {
|
||||||
return IOError(dir, errno);
|
return IOError(dir, errno);
|
||||||
}
|
}
|
||||||
struct dirent* entry;
|
struct dirent* entry;
|
||||||
while ((entry = readdir(d)) != NULL) {
|
while ((entry = readdir(d)) != nullptr) {
|
||||||
StringPiece basename = entry->d_name;
|
StringPiece basename = entry->d_name;
|
||||||
if ((basename != ".") && (basename != "..")) {
|
if ((basename != ".") && (basename != "..")) {
|
||||||
result->push_back(entry->d_name);
|
result->push_back(entry->d_name);
|
||||||
|
@ -32,7 +32,7 @@ class FactOp : public OpKernel {
|
|||||||
|
|
||||||
void Compute(OpKernelContext* context) override {
|
void Compute(OpKernelContext* context) override {
|
||||||
// Output a scalar string.
|
// Output a scalar string.
|
||||||
Tensor* output_tensor = NULL;
|
Tensor* output_tensor = nullptr;
|
||||||
OP_REQUIRES_OK(context,
|
OP_REQUIRES_OK(context,
|
||||||
context->allocate_output(0, TensorShape(), &output_tensor));
|
context->allocate_output(0, TensorShape(), &output_tensor));
|
||||||
auto output = output_tensor->template scalar<string>();
|
auto output = output_tensor->template scalar<string>();
|
||||||
|
@ -63,7 +63,7 @@ bool EventsWriter::InitIfNeeded() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
recordio_writer_.reset(new io::RecordWriter(recordio_file_.get()));
|
recordio_writer_.reset(new io::RecordWriter(recordio_file_.get()));
|
||||||
if (recordio_writer_.get() == NULL) {
|
if (recordio_writer_.get() == nullptr) {
|
||||||
LOG(ERROR) << "Could not create record writer";
|
LOG(ERROR) << "Could not create record writer";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -90,7 +90,7 @@ string EventsWriter::FileName() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EventsWriter::WriteSerializedEvent(StringPiece event_str) {
|
void EventsWriter::WriteSerializedEvent(StringPiece event_str) {
|
||||||
if (recordio_writer_.get() == NULL) {
|
if (recordio_writer_.get() == nullptr) {
|
||||||
if (!InitIfNeeded()) {
|
if (!InitIfNeeded()) {
|
||||||
LOG(ERROR) << "Write failed because file could not be opened.";
|
LOG(ERROR) << "Write failed because file could not be opened.";
|
||||||
return;
|
return;
|
||||||
@ -110,7 +110,7 @@ void EventsWriter::WriteEvent(const Event& event) {
|
|||||||
|
|
||||||
bool EventsWriter::Flush() {
|
bool EventsWriter::Flush() {
|
||||||
if (num_outstanding_events_ == 0) return true;
|
if (num_outstanding_events_ == 0) return true;
|
||||||
CHECK(recordio_file_.get() != NULL) << "Unexpected NULL file";
|
CHECK(recordio_file_.get() != nullptr) << "Unexpected NULL file";
|
||||||
|
|
||||||
if (!recordio_writer_->Flush().ok()) {
|
if (!recordio_writer_->Flush().ok()) {
|
||||||
LOG(ERROR) << "Failed to flush " << num_outstanding_events_ << " events to "
|
LOG(ERROR) << "Failed to flush " << num_outstanding_events_ << " events to "
|
||||||
@ -139,15 +139,15 @@ bool EventsWriter::Flush() {
|
|||||||
|
|
||||||
bool EventsWriter::Close() {
|
bool EventsWriter::Close() {
|
||||||
bool return_value = Flush();
|
bool return_value = Flush();
|
||||||
if (recordio_file_.get() != NULL) {
|
if (recordio_file_.get() != nullptr) {
|
||||||
Status s = recordio_file_->Close();
|
Status s = recordio_file_->Close();
|
||||||
if (!s.ok()) {
|
if (!s.ok()) {
|
||||||
LOG(ERROR) << "Error when closing previous event file: " << filename_
|
LOG(ERROR) << "Error when closing previous event file: " << filename_
|
||||||
<< ": " << s;
|
<< ": " << s;
|
||||||
return_value = false;
|
return_value = false;
|
||||||
}
|
}
|
||||||
recordio_writer_.reset(NULL);
|
recordio_writer_.reset(nullptr);
|
||||||
recordio_file_.reset(NULL);
|
recordio_file_.reset(nullptr);
|
||||||
}
|
}
|
||||||
num_outstanding_events_ = 0;
|
num_outstanding_events_ = 0;
|
||||||
return return_value;
|
return return_value;
|
||||||
|
@ -40,7 +40,7 @@ class AddOneOp : public OpKernel {
|
|||||||
auto input = input_tensor.flat<int32>();
|
auto input = input_tensor.flat<int32>();
|
||||||
|
|
||||||
// Create an output tensor
|
// Create an output tensor
|
||||||
Tensor* output_tensor = NULL;
|
Tensor* output_tensor = nullptr;
|
||||||
OP_REQUIRES_OK(context, context->allocate_output(0, input_tensor.shape(),
|
OP_REQUIRES_OK(context, context->allocate_output(0, input_tensor.shape(),
|
||||||
&output_tensor));
|
&output_tensor));
|
||||||
auto output = output_tensor->template flat<int32>();
|
auto output = output_tensor->template flat<int32>();
|
||||||
|
@ -43,7 +43,7 @@ class ZeroOutOp : public OpKernel {
|
|||||||
auto input = input_tensor.flat<int32>();
|
auto input = input_tensor.flat<int32>();
|
||||||
|
|
||||||
// Create an output tensor
|
// Create an output tensor
|
||||||
Tensor* output_tensor = NULL;
|
Tensor* output_tensor = nullptr;
|
||||||
OP_REQUIRES_OK(context, context->allocate_output(0, input_tensor.shape(),
|
OP_REQUIRES_OK(context, context->allocate_output(0, input_tensor.shape(),
|
||||||
&output_tensor));
|
&output_tensor));
|
||||||
auto output = output_tensor->template flat<int32>();
|
auto output = output_tensor->template flat<int32>();
|
||||||
|
@ -65,7 +65,7 @@ class ZeroOutOp : public OpKernel {
|
|||||||
auto input = input_tensor.flat<T>();
|
auto input = input_tensor.flat<T>();
|
||||||
|
|
||||||
// Create an output tensor
|
// Create an output tensor
|
||||||
Tensor* output = NULL;
|
Tensor* output = nullptr;
|
||||||
OP_REQUIRES_OK(context,
|
OP_REQUIRES_OK(context,
|
||||||
context->allocate_output(0, input_tensor.shape(), &output));
|
context->allocate_output(0, input_tensor.shape(), &output));
|
||||||
auto output_flat = output->template flat<T>();
|
auto output_flat = output->template flat<T>();
|
||||||
|
@ -50,7 +50,7 @@ class ZeroOutOp : public OpKernel {
|
|||||||
errors::InvalidArgument("preserve_index out of range"));
|
errors::InvalidArgument("preserve_index out of range"));
|
||||||
|
|
||||||
// Create an output tensor
|
// Create an output tensor
|
||||||
Tensor* output_tensor = NULL;
|
Tensor* output_tensor = nullptr;
|
||||||
OP_REQUIRES_OK(context, context->allocate_output(0, input_tensor.shape(),
|
OP_REQUIRES_OK(context, context->allocate_output(0, input_tensor.shape(),
|
||||||
&output_tensor));
|
&output_tensor));
|
||||||
auto output = output_tensor->template flat<int32>();
|
auto output = output_tensor->template flat<int32>();
|
||||||
|
@ -24,7 +24,7 @@ TF_OperationDescription* requireHandle(JNIEnv* env, jlong handle) {
|
|||||||
if (handle == 0) {
|
if (handle == 0) {
|
||||||
throwException(env, kIllegalStateException,
|
throwException(env, kIllegalStateException,
|
||||||
"Operation has already been built");
|
"Operation has already been built");
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return reinterpret_cast<TF_OperationDescription*>(handle);
|
return reinterpret_cast<TF_OperationDescription*>(handle);
|
||||||
}
|
}
|
||||||
|
@ -81,25 +81,25 @@ PyTypeObject TensorReleaserType = {
|
|||||||
0, /* tp_itemsize */
|
0, /* tp_itemsize */
|
||||||
/* methods */
|
/* methods */
|
||||||
(destructor)TensorReleaser_dealloc, /* tp_dealloc */
|
(destructor)TensorReleaser_dealloc, /* tp_dealloc */
|
||||||
0, /* tp_print */
|
nullptr, /* tp_print */
|
||||||
0, /* tp_getattr */
|
nullptr, /* tp_getattr */
|
||||||
0, /* tp_setattr */
|
nullptr, /* tp_setattr */
|
||||||
0, /* tp_compare */
|
nullptr, /* tp_compare */
|
||||||
0, /* tp_repr */
|
nullptr, /* tp_repr */
|
||||||
0, /* tp_as_number */
|
nullptr, /* tp_as_number */
|
||||||
0, /* tp_as_sequence */
|
nullptr, /* tp_as_sequence */
|
||||||
0, /* tp_as_mapping */
|
nullptr, /* tp_as_mapping */
|
||||||
0, /* tp_hash */
|
nullptr, /* tp_hash */
|
||||||
0, /* tp_call */
|
nullptr, /* tp_call */
|
||||||
0, /* tp_str */
|
nullptr, /* tp_str */
|
||||||
0, /* tp_getattro */
|
nullptr, /* tp_getattro */
|
||||||
0, /* tp_setattro */
|
nullptr, /* tp_setattro */
|
||||||
0, /* tp_as_buffer */
|
nullptr, /* tp_as_buffer */
|
||||||
Py_TPFLAGS_DEFAULT, /* tp_flags */
|
Py_TPFLAGS_DEFAULT, /* tp_flags */
|
||||||
"Wrapped TensorFlow Tensor", /* tp_doc */
|
"Wrapped TensorFlow Tensor", /* tp_doc */
|
||||||
0, /* tp_traverse */
|
nullptr, /* tp_traverse */
|
||||||
0, /* tp_clear */
|
nullptr, /* tp_clear */
|
||||||
0, /* tp_richcompare */
|
nullptr, /* tp_richcompare */
|
||||||
};
|
};
|
||||||
|
|
||||||
Status TF_DataType_to_PyArray_TYPE(TF_DataType tf_datatype,
|
Status TF_DataType_to_PyArray_TYPE(TF_DataType tf_datatype,
|
||||||
|
@ -37,11 +37,11 @@ namespace port {
|
|||||||
string Demangle(const char *mangled) {
|
string Demangle(const char *mangled) {
|
||||||
string demangled;
|
string demangled;
|
||||||
int status = 0;
|
int status = 0;
|
||||||
char *result = NULL;
|
char *result = nullptr;
|
||||||
#if HAS_CXA_DEMANGLE
|
#if HAS_CXA_DEMANGLE
|
||||||
result = abi::__cxa_demangle(mangled, NULL, NULL, &status);
|
result = abi::__cxa_demangle(mangled, nullptr, nullptr, &status);
|
||||||
#endif
|
#endif
|
||||||
if (status == 0 && result != NULL) { // Demangling succeeeded.
|
if (status == 0 && result != nullptr) { // Demangling succeeeded.
|
||||||
demangled.append(result);
|
demangled.append(result);
|
||||||
free(result);
|
free(result);
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ bool GetCurrentDirectory(string* dir) {
|
|||||||
std::unique_ptr<char[]> a(new char[len]);
|
std::unique_ptr<char[]> a(new char[len]);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
char* p = getcwd(a.get(), len);
|
char* p = getcwd(a.get(), len);
|
||||||
if (p != NULL) {
|
if (p != nullptr) {
|
||||||
*dir = p;
|
*dir = p;
|
||||||
return true;
|
return true;
|
||||||
} else if (errno == ERANGE) {
|
} else if (errno == ERANGE) {
|
||||||
|
@ -110,7 +110,7 @@ bool CaseEqual(StringPiece s1, StringPiece s2) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool StringToBool(StringPiece str, bool* value) {
|
bool StringToBool(StringPiece str, bool* value) {
|
||||||
CHECK(value != NULL) << "NULL output boolean given.";
|
CHECK(value != nullptr) << "NULL output boolean given.";
|
||||||
if (CaseEqual(str, "true") || CaseEqual(str, "t") || CaseEqual(str, "yes") ||
|
if (CaseEqual(str, "true") || CaseEqual(str, "t") || CaseEqual(str, "yes") ||
|
||||||
CaseEqual(str, "y") || CaseEqual(str, "1")) {
|
CaseEqual(str, "y") || CaseEqual(str, "1")) {
|
||||||
*value = true;
|
*value = true;
|
||||||
|
@ -32,7 +32,7 @@ class AckermannOp : public OpKernel {
|
|||||||
|
|
||||||
void Compute(OpKernelContext* context) override {
|
void Compute(OpKernelContext* context) override {
|
||||||
// Output a scalar string.
|
// Output a scalar string.
|
||||||
Tensor* output_tensor = NULL;
|
Tensor* output_tensor = nullptr;
|
||||||
OP_REQUIRES_OK(context,
|
OP_REQUIRES_OK(context,
|
||||||
context->allocate_output(0, TensorShape(), &output_tensor));
|
context->allocate_output(0, TensorShape(), &output_tensor));
|
||||||
auto output = output_tensor->scalar<string>();
|
auto output = output_tensor->scalar<string>();
|
||||||
|
Loading…
Reference in New Issue
Block a user