From 7323e4c8ab27acafebf19f5c98e4d8d7996ed138 Mon Sep 17 00:00:00 2001 From: omegaga Date: Wed, 3 Aug 2016 10:41:27 -0700 Subject: [PATCH] Fix clang on macOS Summary: Fix problem when casting `size_t` to `uint64_t`. Avoid usage of `size_t` when possible. Test Plan: Pass related test on Travis CI. Reviewers: sdong Reviewed By: sdong Subscribers: andrewkr, dhruba, leveldb Differential Revision: https://reviews.facebook.net/D61443 --- utilities/col_buf_decoder.cc | 12 ++++++------ utilities/col_buf_encoder.cc | 2 +- utilities/column_aware_encoding_exp.cc | 11 ++++++++--- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/utilities/col_buf_decoder.cc b/utilities/col_buf_decoder.cc index ad11c0339..60c4626e3 100644 --- a/utilities/col_buf_decoder.cc +++ b/utilities/col_buf_decoder.cc @@ -62,14 +62,14 @@ size_t FixedLengthColBufDecoder::Init(const char* src) { if (col_compression_type_ == kColDict || col_compression_type_ == kColRleDict) { const char* q; - size_t dict_size; + uint64_t dict_size; // Bypass limit q = GetVarint64Ptr(src, src + 10, &dict_size); assert(q != nullptr); src = q; uint64_t dict_key; - for (size_t i = 0; i < dict_size; ++i) { + for (uint64_t i = 0; i < dict_size; ++i) { // Bypass limit ReadVarint64(&src, &dict_key); @@ -145,7 +145,7 @@ size_t FixedLengthColBufDecoder::Decode(const char* src, char** dest) { last_val_ = tmp; } else if (col_compression_type_ == kColRleDict || col_compression_type_ == kColDict) { - size_t dict_val = read_val; + uint64_t dict_val = read_val; assert(dict_val < dict_vec_.size()); write_val = dict_vec_[dict_val]; } @@ -190,14 +190,14 @@ size_t VariableChunkColBufDecoder::Init(const char* src) { const char* orig_src = src; if (col_compression_type_ == kColDict) { const char* q; - size_t dict_size; + uint64_t dict_size; // Bypass limit q = GetVarint64Ptr(src, src + 10, &dict_size); assert(q != nullptr); src = q; uint64_t dict_key; - for (size_t i = 0; i < dict_size; ++i) { + for (uint64_t i = 0; i < dict_size; ++i) { // Bypass limit ReadVarint64(&src, &dict_key); dict_vec_.push_back(dict_key); @@ -219,7 +219,7 @@ size_t VariableChunkColBufDecoder::Decode(const char* src, char** dest) { chunk_size = size % 8; } if (col_compression_type_ == kColDict) { - size_t dict_val; + uint64_t dict_val; ReadVarint64(&src, &dict_val); assert(dict_val < dict_vec_.size()); chunk_buf = dict_vec_[dict_val]; diff --git a/utilities/col_buf_encoder.cc b/utilities/col_buf_encoder.cc index 159917eda..fc5d6cdac 100644 --- a/utilities/col_buf_encoder.cc +++ b/utilities/col_buf_encoder.cc @@ -176,7 +176,7 @@ size_t VariableChunkColBufEncoder::Append(const char *buf) { int8_t chunk_size = 8 - (0xFF - mark); if (col_compression_type_ == kColDict) { auto iter = dictionary_.find(val); - size_t dict_val; + uint64_t dict_val; if (iter == dictionary_.end()) { dict_val = dictionary_.size(); dictionary_.insert(std::make_pair(val, dict_val)); diff --git a/utilities/column_aware_encoding_exp.cc b/utilities/column_aware_encoding_exp.cc index 1393bb7a1..74a5b5b9c 100644 --- a/utilities/column_aware_encoding_exp.cc +++ b/utilities/column_aware_encoding_exp.cc @@ -3,12 +3,17 @@ // LICENSE file in the root directory of this source tree. An additional grant // of patent rights can be found in the PATENTS file in the same directory. // +#ifndef __STDC_FORMAT_MACROS +#define __STDC_FORMAT_MACROS +#endif + #include #ifndef ROCKSDB_LITE #ifdef GFLAGS #include +#include #include #include "rocksdb/env.h" #include "rocksdb/options.h" @@ -106,10 +111,10 @@ class ColumnAwareEncodingExp { if (encoded_out_file != nullptr) { uint64_t size = 0; env->GetFileSize(FLAGS_encoded_file, &size); - fprintf(stdout, "File size: %llu\n", size); + fprintf(stdout, "File size: %" PRIu64 "\n", size); } uint64_t encode_time = sw.ElapsedNanosSafe(false /* reset */); - fprintf(stdout, "Encode time:%llu\n", encode_time); + fprintf(stdout, "Encode time: %" PRIu64 "\n", encode_time); if (decode) { unique_ptr decoded_out_file; if (!FLAGS_decoded_file.empty()) { @@ -124,7 +129,7 @@ class ColumnAwareEncodingExp { &encoded_blocks); } uint64_t decode_time = sw.ElapsedNanosSafe(true /* reset */); - fprintf(stdout, "Decode time:%llu\n", decode_time); + fprintf(stdout, "Decode time: %" PRIu64 "\n", decode_time); } } else { fprintf(stdout, "Unsupported compression type: %s.\n",