Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix c++ compilation errors on Linux using g++ #12685

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cache/compressed_secondary_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ std::unique_ptr<SecondaryCacheResultHandle> CompressedSecondaryCache::Lookup(

size_t uncompressed_size{0};
CacheAllocationPtr uncompressed =
UncompressData(uncompression_info, (char*)data_ptr,
UncompressData(uncompression_info, data_ptr,
handle_value_charge, &uncompressed_size,
cache_options_.compress_format_version, allocator);

Expand Down
2 changes: 1 addition & 1 deletion db/db_impl/db_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6054,7 +6054,7 @@ Status DBImpl::CreateColumnFamilyWithImport(
return Status::InvalidArgument("Comparator name mismatch");
}
for (auto& file : metadatas[i]->files) {
metadata_files[i].push_back((LiveFileMetaData*)&file);
metadata_files[i].push_back(const_cast<LiveFileMetaData*>(&file));
}
total_file_num += metadatas[i]->files.size();
}
Expand Down
10 changes: 5 additions & 5 deletions env/env_encryption.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ IOStatus EncryptedSequentialFile::Read(size_t n, const IOOptions& options,
{
PERF_TIMER_GUARD(decrypt_data_nanos);
io_s = status_to_io_status(
stream_->Decrypt(offset_, (char*)result->data(), result->size()));
stream_->Decrypt(offset_, const_cast<char*>(result->data()), result->size()));
}
if (io_s.ok()) {
offset_ += result->size(); // We've already read data from disk, so update
Expand Down Expand Up @@ -86,7 +86,7 @@ IOStatus EncryptedSequentialFile::PositionedRead(uint64_t offset, size_t n,
{
PERF_TIMER_GUARD(decrypt_data_nanos);
io_s = status_to_io_status(
stream_->Decrypt(offset, (char*)result->data(), result->size()));
stream_->Decrypt(offset, const_cast<char*>(result->data()), result->size()));
}
return io_s;
}
Expand All @@ -104,7 +104,7 @@ IOStatus EncryptedRandomAccessFile::Read(uint64_t offset, size_t n,
{
PERF_TIMER_GUARD(decrypt_data_nanos);
io_s = status_to_io_status(
stream_->Decrypt(offset, (char*)result->data(), result->size()));
stream_->Decrypt(offset, const_cast<char*>(result->data()), result->size()));
}
return io_s;
}
Expand Down Expand Up @@ -308,7 +308,7 @@ IOStatus EncryptedRandomRWFile::Read(uint64_t offset, size_t n,
{
PERF_TIMER_GUARD(decrypt_data_nanos);
status = status_to_io_status(
stream_->Decrypt(offset, (char*)result->data(), result->size()));
stream_->Decrypt(offset, const_cast<char*>(result->data()), result->size()));
}
return status;
}
Expand Down Expand Up @@ -1100,7 +1100,7 @@ Status CTREncryptionProvider::CreateCipherStream(
Status status;
{
PERF_TIMER_GUARD(decrypt_data_nanos);
status = cipherStream.Decrypt(0, (char*)prefix.data() + (2 * blockSize),
status = cipherStream.Decrypt(0, const_cast<char*>(prefix.data()) + (2 * blockSize),
prefix.size() - (2 * blockSize));
}
if (!status.ok()) {
Expand Down
2 changes: 1 addition & 1 deletion table/block_based/block.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,7 @@ IndexBlockIter* Block::NewIndexIterator(
size_t Block::ApproximateMemoryUsage() const {
size_t usage = usable_size();
#ifdef ROCKSDB_MALLOC_USABLE_SIZE
usage += malloc_usable_size((void*)this);
usage += malloc_usable_size(static_cast<void*>(const_cast<Block*>((this))));
#else
usage += sizeof(*this);
#endif // ROCKSDB_MALLOC_USABLE_SIZE
Expand Down
4 changes: 2 additions & 2 deletions table/block_based/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class BlockReadAmpBitmap {

size_t ApproximateMemoryUsage() const {
#ifdef ROCKSDB_MALLOC_USABLE_SIZE
return malloc_usable_size((void*)this);
return malloc_usable_size(static_cast<void*>(const_cast<BlockReadAmpBitmap*>(this)));
#endif // ROCKSDB_MALLOC_USABLE_SIZE
return sizeof(*this);
}
Expand Down Expand Up @@ -612,7 +612,7 @@ class BlockIter : public InternalIteratorBase<TValue> {
key_pinned_ = false;
}
TEST_SYNC_POINT_CALLBACK("BlockIter::UpdateKey::value",
(void*)value_.data());
static_cast<void*>(const_cast<char*>(value_.data())));
TEST_SYNC_POINT_CALLBACK("Block::VerifyChecksum::checksum_len",
&protection_bytes_per_key_);
if (protection_bytes_per_key_ > 0) {
Expand Down
2 changes: 1 addition & 1 deletion table/table_properties.cc
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ TableProperties::GetAggregatablePropertiesAsMap() const {
std::size_t TableProperties::ApproximateMemoryUsage() const {
std::size_t usage = 0;
#ifdef ROCKSDB_MALLOC_USABLE_SIZE
usage += malloc_usable_size((void*)this);
usage += malloc_usable_size(static_cast<void*>(const_cast<TableProperties*>(this)));
#else
usage += sizeof(*this);
#endif // ROCKSDB_MALLOC_USABLE_SIZE
Expand Down
2 changes: 1 addition & 1 deletion test_util/testutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class OverwritingStringSink : public FSWritableFile {
IOStatus Flush(const IOOptions& /*opts*/, IODebugContext* /*dbg*/) override {
if (last_flush_ < contents_.size()) {
assert(reader_contents_->size() >= contents_.size());
memcpy((char*)reader_contents_->data() + last_flush_,
memcpy(const_cast<char*>(reader_contents_->data()) + last_flush_,
contents_.data() + last_flush_, contents_.size() - last_flush_);
last_flush_ = contents_.size();
}
Expand Down
2 changes: 1 addition & 1 deletion test_util/transaction_test_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ Status RandomTransactionInserter::Verify(DB* db, uint16_t num_sets,
"VerifyRead at %" PRIu64 " (%" PRIu64 "): %.*s value: %" PRIu64,
roptions.snapshot ? roptions.snapshot->GetSequenceNumber() : 0ul,
roptions.snapshot
? ((SnapshotImpl*)roptions.snapshot)->min_uncommitted_
? (static_cast<SnapshotImpl*>(const_cast<Snapshot*>(roptions.snapshot)))->min_uncommitted_
: 0ul,
static_cast<int>(key.size()), key.data(), int_value);
total += int_value;
Expand Down
10 changes: 5 additions & 5 deletions util/crc32c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ std::string IsFastCrc32Supported() {
crc##1 = _mm_crc32_u64(crc##1, *(buf##1 + offset));

#define CRCsinglet(crc, buf, offset) \
crc = _mm_crc32_u64(crc, *(uint64_t*)(buf + offset));
crc = _mm_crc32_u64(crc, *reinterpret_cast<uint64_t*>(const_cast<unsigned char*>(buf + offset)));

// Numbers taken directly from intel whitepaper.
// clang-format off
Expand Down Expand Up @@ -523,11 +523,11 @@ inline void align_to_8(
const unsigned char*& next) { // next data pointer, updated on return
uint32_t crc32bit = static_cast<uint32_t>(crc0);
if (len & 0x04) {
crc32bit = _mm_crc32_u32(crc32bit, *(uint32_t*)next);
crc32bit = _mm_crc32_u32(crc32bit, *reinterpret_cast<uint32_t*>(const_cast<unsigned char*>(next)));
next += sizeof(uint32_t);
}
if (len & 0x02) {
crc32bit = _mm_crc32_u16(crc32bit, *(uint16_t*)next);
crc32bit = _mm_crc32_u16(crc32bit, *reinterpret_cast<uint16_t*>(const_cast<unsigned char*>(next)));
next += sizeof(uint16_t);
}
if (len & 0x01) {
Expand Down Expand Up @@ -555,7 +555,7 @@ inline uint64_t CombineCRC(
const auto res1 = _mm_clmulepi64_si128(crc1_xmm, multiplier, 0x10);
const auto res = _mm_xor_si128(res0, res1);
crc0 = _mm_cvtsi128_si64(res);
crc0 = crc0 ^ *((uint64_t*)next2 - 1);
crc0 = crc0 ^ *(const_cast<uint64_t*>(next2) - 1);
crc2 = _mm_crc32_u64(crc2, crc0);
return crc2;
}
Expand Down Expand Up @@ -596,7 +596,7 @@ uint32_t crc32c_3way(uint32_t crc, const char* buf, size_t len) {
n++;
}
// points to the first byte of the next block
const uint64_t* next0 = (uint64_t*)next + block_size;
const uint64_t* next0 = reinterpret_cast<uint64_t*>(const_cast<unsigned char*>(next)) + block_size;
const uint64_t* next1 = next0 + block_size;
const uint64_t* next2 = next1 + block_size;

Expand Down
4 changes: 2 additions & 2 deletions util/stderr_logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace ROCKSDB_NAMESPACE {
StderrLogger::~StderrLogger() {
if (log_prefix != nullptr) {
free((void*)log_prefix);
free(static_cast<void*>(const_cast<char*>(log_prefix)));
}
}

Expand All @@ -33,7 +33,7 @@ void StderrLogger::Logv(const char* format, va_list ap) {
// 44 bytes, but we allocate 50 to be safe.
//
// ctx_len = 44 = ( 4+ 1+ 2+1+2+ 1+2+ 1+2+ 1+ 2+1+6+ 1+16+1)
const char* ctx_prefix_fmt = "%04d/%02d/%02d-%02d:%02d:%02d.%06d %llx %s";
const char* const ctx_prefix_fmt = "%04d/%02d/%02d-%02d:%02d:%02d.%06d %llx %s";
size_t ctx_len = 50;

va_list ap_copy;
Expand Down
3 changes: 3 additions & 0 deletions util/string_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ std::string TimeToHumanString(int unixtime) {
struct tm tInfo;
struct tm* timeinfo = port::LocalTimeR(&rawtime, &tInfo);
assert(timeinfo == &tInfo);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-y2k"
strftime(time_buffer, 80, "%c", timeinfo);
#pragma GCC diagnostic pop
return std::string(time_buffer);
}

Expand Down
2 changes: 1 addition & 1 deletion utilities/cache_dump_load_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ class CacheDumperHelper {
if (!GetLengthPrefixedSlice(&encoded_slice, &block)) {
return Status::Incomplete("Decode dumped unit string failed");
}
dump_unit->value = (void*)block.data();
dump_unit->value = static_cast<void*>(const_cast<char*>(block.data()));
assert(block.size() == dump_unit->value_len);
return Status::OK();
}
Expand Down
2 changes: 1 addition & 1 deletion utilities/persistent_cache/block_cache_tier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ Status BlockCacheTier::NewCacheFile() {
lock_.AssertHeld();

TEST_SYNC_POINT_CALLBACK("BlockCacheTier::NewCacheFile:DeleteDir",
(void*)(GetCachePath().c_str()));
static_cast<void*>(const_cast<char*>(GetCachePath().c_str())));

std::unique_ptr<WriteableCacheFile> f(new WriteableCacheFile(
opt_.env, &buffer_allocator_, &writer_, GetCachePath(), writer_cache_id_,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void toku_destroy_dbt(DBT *dbt) {
DBT *toku_fill_dbt(DBT *dbt, const void *k, size_t len) {
toku_init_dbt(dbt);
dbt->size = len;
dbt->data = (char *)k;
dbt->data = static_cast<char *>(const_cast<void *>(k));
return dbt;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void RangeTreeLockManager::UnLock(PessimisticTransaction* txn,

// tracked_locks_->range_list may hold nullptr if the transaction has never
// acquired any locks.
((RangeTreeLockTracker*)range_tracker)->ReleaseLocks(this, txn, all_keys);
const_cast<RangeTreeLockTracker*>(range_tracker)->ReleaseLocks(this, txn, all_keys);
}

int RangeTreeLockManager::CompareDbtEndpoints(void* arg, const DBT* a_key,
Expand Down Expand Up @@ -373,7 +373,7 @@ void RangeTreeLockManager::AddColumnFamily(const ColumnFamilyHandle* cfh) {
if (ltree_map_.find(column_family_id) == ltree_map_.end()) {
DICTIONARY_ID dict_id = {.dictid = column_family_id};
toku::comparator cmp;
cmp.create(CompareDbtEndpoints, (void*)cfh->GetComparator());
cmp.create(CompareDbtEndpoints, static_cast<void*>(const_cast<Comparator*>(cfh->GetComparator())));
toku::locktree* ltree =
ltm_.get_lt(dict_id, cmp,
/* on_create_extra*/ static_cast<void*>(this));
Expand Down