Skip to content

Commit

Permalink
rewriting DCHECK(expr.ok()) to DCHECK_OK(expr)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkietz committed Feb 19, 2019
1 parent 1f949fe commit 72d0930
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cpp/examples/parquet/low-level-api/reader-writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ int main(int argc, char** argv) {
file_writer->Close();

// Write the bytes to file
DCHECK(out_file->Close().ok());
DCHECK_OK(out_file->Close());
} catch (const std::exception& e) {
std::cerr << "Parquet write error: " << e.what() << std::endl;
return -1;
Expand Down
2 changes: 1 addition & 1 deletion cpp/examples/parquet/low-level-api/reader-writer2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ int main(int argc, char** argv) {
file_writer->Close();

// Write the bytes to file
DCHECK(out_file->Close().ok());
DCHECK_OK(out_file->Close());
} catch (const std::exception& e) {
std::cerr << "Parquet write error: " << e.what() << std::endl;
return -1;
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ std::shared_ptr<Array> Array::Slice(int64_t offset) const {

std::string Array::ToString() const {
std::stringstream ss;
DCHECK(PrettyPrint(*this, 0, &ss).ok());
DCHECK_OK(PrettyPrint(*this, 0, &ss));
return ss.str();
}

Expand Down
6 changes: 3 additions & 3 deletions cpp/src/arrow/gpu/cuda_memory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ CudaBuffer::CudaBuffer(uint8_t* data, int64_t size,
mutable_data_ = data;
}

CudaBuffer::~CudaBuffer() { DCHECK(Close().ok()); }
CudaBuffer::~CudaBuffer() { DCHECK_OK(Close()); }

Status CudaBuffer::Close() {
if (own_data_) {
Expand Down Expand Up @@ -182,8 +182,8 @@ Status CudaBuffer::ExportForIpc(std::shared_ptr<CudaIpcMemHandle>* handle) {

CudaHostBuffer::~CudaHostBuffer() {
CudaDeviceManager* manager = nullptr;
DCHECK(CudaDeviceManager::GetInstance(&manager).ok());
DCHECK(manager->FreeHost(mutable_data_, size_).ok());
DCHECK_OK(CudaDeviceManager::GetInstance(&manager));
DCHECK_OK(manager->FreeHost(mutable_data_, size_));
}

// ----------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/io/compressed.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class CompressedOutputStream::Impl {
Impl(MemoryPool* pool, Codec* codec, const std::shared_ptr<OutputStream>& raw)
: pool_(pool), raw_(raw), codec_(codec), is_open_(true), compressed_pos_(0) {}

~Impl() { DCHECK(Close().ok()); }
~Impl() { DCHECK_OK(Close()); }

Status Init() {
RETURN_NOT_OK(codec_->MakeCompressor(&compressor_));
Expand Down Expand Up @@ -236,7 +236,7 @@ class CompressedInputStream::Impl {
return Status::OK();
}

~Impl() { DCHECK(Close().ok()); }
~Impl() { DCHECK_OK(Close()); }

Status Close() {
std::lock_guard<std::mutex> guard(lock_);
Expand Down
7 changes: 4 additions & 3 deletions cpp/src/arrow/io/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class ReadableFile::ReadableFileImpl : public OSFile {

ReadableFile::ReadableFile(MemoryPool* pool) { impl_.reset(new ReadableFileImpl(pool)); }

ReadableFile::~ReadableFile() { DCHECK(impl_->Close().ok()); }
ReadableFile::~ReadableFile() { DCHECK_OK(impl_->Close()); }

Status ReadableFile::Open(const std::string& path, std::shared_ptr<ReadableFile>* file) {
return Open(path, default_memory_pool(), file);
Expand Down Expand Up @@ -299,7 +299,7 @@ FileOutputStream::FileOutputStream() { impl_.reset(new FileOutputStreamImpl());

FileOutputStream::~FileOutputStream() {
// This can fail; better to explicitly call close
DCHECK(impl_->Close().ok());
DCHECK_OK(impl_->Close());
}

Status FileOutputStream::Open(const std::string& path,
Expand Down Expand Up @@ -357,7 +357,8 @@ class MemoryMappedFile::MemoryMap : public MutableBuffer {
~MemoryMap() {
DCHECK_OK(Close());
if (mutable_data_ != nullptr) {
DCHECK_EQ(munmap(mutable_data_, static_cast<size_t>(size_)), 0);
auto length = munmap(mutable_data_, static_cast<size_t>(size_));
DCHECK_EQ(length, 0);
}
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/io/memory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Status BufferOutputStream::Reset(int64_t initial_capacity, MemoryPool* pool) {
BufferOutputStream::~BufferOutputStream() {
// This can fail, better to explicitly call close
if (buffer_) {
DCHECK(Close().ok());
DCHECK_OK(Close());
}
}

Expand Down
6 changes: 4 additions & 2 deletions cpp/src/arrow/util/basic_decimal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,8 @@ void BasicDecimal128::GetWholeAndFraction(int scale, BasicDecimal128* whole,
DCHECK_LE(scale, 38);

BasicDecimal128 multiplier(ScaleMultipliers[scale]);
DCHECK_EQ(Divide(multiplier, whole, fraction), DecimalStatus::kSuccess);
auto status = Divide(multiplier, whole, fraction);
DCHECK_EQ(status, DecimalStatus::kSuccess);
}

const BasicDecimal128& BasicDecimal128::GetScaleMultiplier(int32_t scale) {
Expand All @@ -663,7 +664,8 @@ BasicDecimal128 BasicDecimal128::ReduceScaleBy(int32_t reduce_by, bool round) co
BasicDecimal128 divisor(ScaleMultipliers[reduce_by]);
BasicDecimal128 result;
BasicDecimal128 remainder;
DCHECK_EQ(Divide(divisor, &result, &remainder), DecimalStatus::kSuccess);
auto status = Divide(divisor, &result, &remainder);
DCHECK_EQ(status, DecimalStatus::kSuccess);
if (round) {
auto divisor_half = ScaleMultipliersHalf[reduce_by];
if (remainder.Abs() >= divisor_half) {
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/arrow/util/bit-stream-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,8 @@ inline bool BitReader::GetVlqInt(int32_t* v) {
if (!GetAligned<uint8_t>(1, &byte)) return false;
*v |= (byte & 0x7F) << shift;
shift += 7;
DCHECK_LE(++num_bytes, MAX_VLQ_BYTE_LEN);
++num_bytes;
DCHECK_LE(num_bytes, MAX_VLQ_BYTE_LEN);
} while ((byte & 0x80) != 0);
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/gandiva/precompiled/testing.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ namespace gandiva {

timestamp StringToTimestamp(const char* buf) {
int64_t out = 0;
DCHECK(internal::ParseTimestamp(buf, "%Y-%m-%d %H:%M:%S", false, &out));
bool success = internal::ParseTimestamp(buf, "%Y-%m-%d %H:%M:%S", false, &out);
DCHECK(success);
return out * 1000;
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/parquet/arrow/reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class PARQUET_NO_EXPORT PrimitiveImpl : public ColumnReader::ColumnReaderImpl {
PrimitiveImpl(MemoryPool* pool, std::unique_ptr<FileColumnIterator> input)
: pool_(pool), input_(std::move(input)), descr_(input_->descr()) {
record_reader_ = RecordReader::Make(descr_, pool_);
DCHECK(NodeToField(*input_->descr()->schema_node(), &field_).ok());
DCHECK_OK(NodeToField(*input_->descr()->schema_node(), &field_));
NextRowGroup();
}

Expand Down

0 comments on commit 72d0930

Please sign in to comment.