Skip to content

Commit

Permalink
fix: Convert C-Style Casts to C++-Style Type Casts
Browse files Browse the repository at this point in the history
issue: #35900

Signed-off-by: Abdullah Ahmed <[email protected]>
  • Loading branch information
abd-770 committed Sep 24, 2024
1 parent 325f198 commit 7a38102
Show file tree
Hide file tree
Showing 19 changed files with 67 additions and 68 deletions.
18 changes: 9 additions & 9 deletions internal/core/src/common/binary_set_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ NewBinarySet(CBinarySet* c_binary_set) {

void
DeleteBinarySet(CBinarySet c_binary_set) {
auto binary_set = (knowhere::BinarySet*)c_binary_set;
auto binary_set = static_cast<knowhere::BinarySet*>(c_binary_set);
delete binary_set;
}

Expand All @@ -48,9 +48,9 @@ AppendIndexBinary(CBinarySet c_binary_set,
const char* c_index_key) {
auto status = CStatus();
try {
auto binary_set = (knowhere::BinarySet*)c_binary_set;
auto binary_set = static_cast<knowhere::BinarySet*>(c_binary_set);
std::string index_key(c_index_key);
uint8_t* index = (uint8_t*)index_binary;
uint8_t* index = static_cast<uint8_t*>(index_binary);
uint8_t* dup = new uint8_t[index_size]();
memcpy(dup, index, index_size);
std::shared_ptr<uint8_t[]> data(dup);
Expand All @@ -67,15 +67,15 @@ AppendIndexBinary(CBinarySet c_binary_set,

int
GetBinarySetSize(CBinarySet c_binary_set) {
auto binary_set = (knowhere::BinarySet*)c_binary_set;
auto binary_set = static_cast<knowhere::BinarySet*>(c_binary_set);
return binary_set->binary_map_.size();
}

void
GetBinarySetKeys(CBinarySet c_binary_set, void* data) {
auto binary_set = (knowhere::BinarySet*)c_binary_set;
auto binary_set = static_cast<knowhere::BinarySet*>(c_binary_set);
auto& map_ = binary_set->binary_map_;
const char** data_ = (const char**)data;
const char** data_ = static_cast<const char**>(data);
std::size_t i = 0;
for (auto it = map_.begin(); it != map_.end(); ++it, i++) {
data_[i] = it->first.c_str();
Expand All @@ -84,7 +84,7 @@ GetBinarySetKeys(CBinarySet c_binary_set, void* data) {

int
GetBinarySetValueSize(CBinarySet c_binary_set, const char* key) {
auto binary_set = (knowhere::BinarySet*)c_binary_set;
auto binary_set = static_cast<knowhere::BinarySet*>(c_binary_set);
int64_t ret_ = 0;
try {
std::string key_(key);
Expand All @@ -98,12 +98,12 @@ GetBinarySetValueSize(CBinarySet c_binary_set, const char* key) {
CStatus
CopyBinarySetValue(void* data, const char* key, CBinarySet c_binary_set) {
auto status = CStatus();
auto binary_set = (knowhere::BinarySet*)c_binary_set;
auto binary_set = static_cast<knowhere::BinarySet*>(c_binary_set);
try {
auto binary = binary_set->GetByName(key);
status.error_code = milvus::ErrorCode::Success;
status.error_msg = "";
memcpy((uint8_t*)data, binary->data.get(), binary->size);
memcpy(static_cast<uint8_t*>(data), binary->data.get(), binary->size);
} catch (std::exception& e) {
status.error_code = milvus::ErrorCode::UnexpectedError;
status.error_msg = strdup(e.what());
Expand Down
7 changes: 3 additions & 4 deletions internal/core/src/exec/expression/TermExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ PhyTermFilterExpr::InitPkCacheOffset() {
segment_->search_ids(*id_array, query_timestamp_);
cached_bits_.resize(active_count_, false);
for (const auto& offset : seg_offsets) {
auto _offset = (int64_t)offset.get();
auto _offset = static_cast<int64_t>(offset.get());
cached_bits_[_offset] = true;
}
cached_offsets_inited_ = true;
Expand Down Expand Up @@ -525,10 +525,9 @@ PhyTermFilterExpr::ExecVisitorImplForIndex<bool>() {
for (auto& val : expr_->vals_) {
vals.emplace_back(GetValueFromProto<bool>(val) ? 1 : 0);
}
auto execute_sub_batch = [](Index* index_ptr,
const std::vector<uint8_t>& vals) {
auto execute_sub_batch = [](Index* index_ptr, std::vector<uint8_t>& vals) {
TermIndexFunc<bool> func;
return std::move(func(index_ptr, vals.size(), (bool*)vals.data()));
return std::move(func(index_ptr, vals.size(), reinterpret_cast<bool*>(vals.data())));
};
auto res = ProcessIndexChunks<bool>(execute_sub_batch, vals);
return std::make_shared<ColumnVector>(std::move(res));
Expand Down
6 changes: 3 additions & 3 deletions internal/core/src/index/ScalarIndexSort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ ScalarIndexSort<T>::LoadWithoutAssemble(const BinarySet& index_binary,
const Config& config) {
size_t index_size;
auto index_length = index_binary.GetByName("index_length");
memcpy(&index_size, index_length->data.get(), (size_t)index_length->size);
memcpy(&index_size, index_length->data.get(), static_cast<size_t>(index_length->size));

auto index_data = index_binary.GetByName("index_data");
data_.resize(index_size);
Expand All @@ -176,7 +176,7 @@ ScalarIndexSort<T>::LoadWithoutAssemble(const BinarySet& index_binary,
(size_t)index_num_rows->size);
idx_to_offsets_.resize(total_num_rows_);
valid_bitset = TargetBitmap(total_num_rows_, false);
memcpy(data_.data(), index_data->data.get(), (size_t)index_data->size);
memcpy(data_.data(), index_data->data.get(), static_cast<size_t>(index_data->size));
for (size_t i = 0; i < data_.size(); ++i) {
idx_to_offsets_[data_[i].idx_] = i;
valid_bitset.set(data_[i].idx_);
Expand Down Expand Up @@ -207,7 +207,7 @@ ScalarIndexSort<T>::Load(milvus::tracer::TraceContext ctx,
auto size = data->DataSize();
auto deleter = [&](uint8_t*) {}; // avoid repeated deconstruction
auto buf = std::shared_ptr<uint8_t[]>(
(uint8_t*)const_cast<void*>(data->Data()), deleter);
static_cast<uint8_t*>(const_cast<void*>(data->Data())), deleter);
binary_set.Append(key, buf, size);
}

Expand Down
2 changes: 1 addition & 1 deletion internal/core/src/index/StringIndexMarisa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ StringIndexMarisa::Load(milvus::tracer::TraceContext ctx,
auto size = data->DataSize();
auto deleter = [&](uint8_t*) {}; // avoid repeated deconstruction
auto buf = std::shared_ptr<uint8_t[]>(
(uint8_t*)const_cast<void*>(data->Data()), deleter);
static_cast<uint8_t*>(const_cast<void*>(data->Data())), deleter);
binary_set.Append(key, buf, size);
}

Expand Down
6 changes: 3 additions & 3 deletions internal/core/src/index/VectorDiskIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,11 @@ VectorDiskAnnIndex<T>::BuildWithDataset(const DatasetPtr& dataset,
}

int64_t offset = 0;
auto num = uint32_t(milvus::GetDatasetRows(dataset));
auto num = static_cast<uint32_t>(milvus::GetDatasetRows(dataset));
local_chunk_manager->Write(local_data_path, offset, &num, sizeof(num));
offset += sizeof(num);

auto dim = uint32_t(milvus::GetDatasetDim(dataset));
auto dim = static_cast<uint32_t>(milvus::GetDatasetDim(dataset));
local_chunk_manager->Write(local_data_path, offset, &dim, sizeof(dim));
offset += sizeof(dim);

Expand Down Expand Up @@ -256,7 +256,7 @@ VectorDiskAnnIndex<T>::Query(const DatasetPtr dataset,
search_info.search_params_[DISK_ANN_QUERY_LIST];
}
// set beamwidth
search_config[DISK_ANN_QUERY_BEAMWIDTH] = int(search_beamwidth_);
search_config[DISK_ANN_QUERY_BEAMWIDTH] = static_cast<int>(search_beamwidth_);
// set json reset field, will be removed later
search_config[DISK_ANN_PQ_CODE_BUDGET] = 0.0;
}
Expand Down
2 changes: 1 addition & 1 deletion internal/core/src/index/VectorMemIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ VectorMemIndex<T>::Load(milvus::tracer::TraceContext ctx,
auto size = data->Size();
auto deleter = [&](uint8_t*) {}; // avoid repeated deconstruction
auto buf = std::shared_ptr<uint8_t[]>(
(uint8_t*)const_cast<void*>(data->Data()), deleter);
static_cast<uint8_t*>(const_cast<void*>(data->Data())), deleter);
binary_set.Append(key, buf, size);
}

Expand Down
20 changes: 10 additions & 10 deletions internal/core/src/indexbuilder/index_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ NewBuildIndexInfo(CBuildIndexInfo* c_build_index_info,

void
DeleteBuildIndexInfo(CBuildIndexInfo c_build_index_info) {
auto info = (BuildIndexInfo*)c_build_index_info;
auto info = static_cast<BuildIndexInfo*>(c_build_index_info);
delete info;
}

Expand All @@ -516,7 +516,7 @@ AppendBuildIndexParam(CBuildIndexInfo c_build_index_info,
const uint8_t* serialized_index_params,
const uint64_t len) {
try {
auto build_index_info = (BuildIndexInfo*)c_build_index_info;
auto build_index_info = static_cast<BuildIndexInfo*>(c_build_index_info);
auto index_params =
std::make_unique<milvus::proto::indexcgo::IndexParams>();
auto res = index_params->ParseFromArray(serialized_index_params, len);
Expand All @@ -543,7 +543,7 @@ AppendBuildTypeParam(CBuildIndexInfo c_build_index_info,
const uint8_t* serialized_type_params,
const uint64_t len) {
try {
auto build_index_info = (BuildIndexInfo*)c_build_index_info;
auto build_index_info = static_cast<BuildIndexInfo*>(c_build_index_info);
auto type_params =
std::make_unique<milvus::proto::indexcgo::TypeParams>();
auto res = type_params->ParseFromArray(serialized_type_params, len);
Expand Down Expand Up @@ -575,7 +575,7 @@ AppendFieldMetaInfoV2(CBuildIndexInfo c_build_index_info,
enum CDataType field_type,
int64_t dim) {
try {
auto build_index_info = (BuildIndexInfo*)c_build_index_info;
auto build_index_info = static_cast<BuildIndexInfo*>(c_build_index_info);
build_index_info->collection_id = collection_id;
build_index_info->partition_id = partition_id;
build_index_info->segment_id = segment_id;
Expand All @@ -598,7 +598,7 @@ AppendFieldMetaInfo(CBuildIndexInfo c_build_index_info,
int64_t field_id,
enum CDataType field_type) {
try {
auto build_index_info = (BuildIndexInfo*)c_build_index_info;
auto build_index_info = static_cast<BuildIndexInfo*>(c_build_index_info);
build_index_info->collection_id = collection_id;
build_index_info->partition_id = partition_id;
build_index_info->segment_id = segment_id;
Expand All @@ -624,7 +624,7 @@ AppendIndexMetaInfo(CBuildIndexInfo c_build_index_info,
int64_t build_id,
int64_t version) {
try {
auto build_index_info = (BuildIndexInfo*)c_build_index_info;
auto build_index_info = static_cast<BuildIndexInfo*>(c_build_index_info);
build_index_info->index_id = index_id;
build_index_info->index_build_id = build_id;
build_index_info->index_version = version;
Expand All @@ -645,7 +645,7 @@ CStatus
AppendInsertFilePath(CBuildIndexInfo c_build_index_info,
const char* c_file_path) {
try {
auto build_index_info = (BuildIndexInfo*)c_build_index_info;
auto build_index_info = static_cast<BuildIndexInfo*>(c_build_index_info);
std::string insert_file_path(c_file_path);
build_index_info->insert_files.emplace_back(insert_file_path);

Expand All @@ -662,7 +662,7 @@ CStatus
AppendIndexEngineVersionToBuildInfo(CBuildIndexInfo c_load_index_info,
int32_t index_engine_version) {
try {
auto build_index_info = (BuildIndexInfo*)c_load_index_info;
auto build_index_info = static_cast<BuildIndexInfo*>(c_load_index_info);
build_index_info->index_engine_version = index_engine_version;

auto status = CStatus();
Expand All @@ -680,7 +680,7 @@ AppendIndexStorageInfo(CBuildIndexInfo c_build_index_info,
const char* c_index_store_path,
int64_t data_store_version) {
try {
auto build_index_info = (BuildIndexInfo*)c_build_index_info;
auto build_index_info = static_cast<BuildIndexInfo*>(c_build_index_info);
std::string data_store_path(c_data_store_path),
index_store_path(c_index_store_path);
build_index_info->data_store_path = data_store_path;
Expand Down Expand Up @@ -727,7 +727,7 @@ AppendOptionalFieldDataPath(CBuildIndexInfo c_build_index_info,
const int32_t field_type,
const char* c_file_path) {
try {
auto build_index_info = (BuildIndexInfo*)c_build_index_info;
auto build_index_info = static_cast<BuildIndexInfo*>(c_build_index_info);
std::string field_name_str(field_name);
auto& opt_fields_map = build_index_info->opt_fields;
if (opt_fields_map.find(field_id) == opt_fields_map.end()) {
Expand Down
2 changes: 1 addition & 1 deletion internal/core/src/log/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ get_thread_starttime() {
thread_stat, "%lld %s %s ", (long long*)&val, comm, &state); // NOLINT

for (auto i = 4; i < 23; i++) {
ret = fscanf(thread_stat, "%lld ", (long long*)&val); // NOLINT
ret = fscanf(thread_stat, "%lld ", reinterpret_cast<long long*>(&val)); // NOLINT
if (i == 22) {
break;
}
Expand Down
2 changes: 1 addition & 1 deletion internal/core/src/query/SearchOnGrowing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ SearchOnGrowing(const segcore::SegmentGrowingImpl& segment,
auto& schema = segment.get_schema();
auto& record = segment.get_insert_record();
auto active_count =
std::min(int64_t(bitset.size()), segment.get_active_count(timestamp));
std::min(static_cast<int64_t>(bitset.size()), segment.get_active_count(timestamp));

// step 1.1: get meta
// step 1.2: get which vector field to search
Expand Down
4 changes: 2 additions & 2 deletions internal/core/src/segcore/FieldIndexing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ VectorFieldIndexing::AppendSegmentIndexDense(int64_t reserved_offset,
: size_per_chunk;
std::memcpy(
vec_data.get() + offset * dim,
(const float*)field_raw_data->get_chunk_data(chunk_id) +
static_cast<const float*>(field_raw_data->get_chunk_data(chunk_id)) +
chunk_offset * dim,
chunk_copysz * dim * sizeof(float));
offset += chunk_copysz;
Expand Down Expand Up @@ -249,7 +249,7 @@ VectorFieldIndexing::AppendSegmentIndexDense(int64_t reserved_offset,
auto dataset = knowhere::GenDataSet(
chunk_sz,
dim,
(const float*)source->get_chunk_data(chunk_id) +
static_cast<const float*>(source->get_chunk_data(chunk_id)) +
chunk_offset * dim);
index_->AddWithDataset(dataset, conf);
index_cur_.fetch_add(chunk_sz);
Expand Down
4 changes: 2 additions & 2 deletions internal/core/src/segcore/IndexConfigGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ VecIndexConfig::VecIndexConfig(const int64_t max_index_row_cout,
build_params_[knowhere::indexparam::NLIST] =
std::to_string(config_.get_nlist());
build_params_[knowhere::indexparam::SSIZE] = std::to_string(
std::max((int)(config_.get_chunk_rows() / config_.get_nlist()), 48));
std::max(static_cast<int>(config_.get_chunk_rows()) / static_cast<int>(config_.get_nlist()), 48));
search_params_[knowhere::indexparam::NPROBE] =
std::to_string(config_.get_nprobe());
// note for sparse vector index: drop_ratio_build is not allowed for growing
Expand All @@ -71,7 +71,7 @@ VecIndexConfig::GetBuildThreshold() const noexcept {
assert(VecIndexConfig::index_build_ratio.count(index_type_));
auto ratio = VecIndexConfig::index_build_ratio.at(index_type_);
assert(ratio >= 0.0 && ratio < 1.0);
return std::max(int64_t(max_index_row_count_ * ratio),
return std::max(static_cast<int64_t>(max_index_row_count_ * ratio),
config_.get_nlist() * 39);
}

Expand Down
4 changes: 2 additions & 2 deletions internal/core/src/segcore/SegmentGrowingImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ SegmentGrowingImpl::bulk_subscript(FieldId field_id,
DataType::VECTOR_SPARSE_FLOAT) {
bulk_subscript_sparse_float_vector_impl(
field_id,
(const ConcurrentVector<SparseFloatVector>*)vec_ptr,
static_cast<const ConcurrentVector<SparseFloatVector>*>(vec_ptr),
seg_offsets,
count,
result->mutable_vectors()->mutable_sparse_float_vector());
Expand Down Expand Up @@ -675,7 +675,7 @@ SegmentGrowingImpl::bulk_subscript_impl(FieldId field_id,
if (offset == INVALID_SEG_OFFSET) {
memset(dst, 0, element_sizeof);
} else {
auto src = (const uint8_t*)vec.get_element(offset);
auto src = reinterpret_cast<const uint8_t*>(vec.get_element(offset));
memcpy(dst, src, element_sizeof);
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/core/src/segcore/SegmentInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ SegmentInternalInterface::Search(
query::ExecPlanNodeVisitor visitor(*this, timestamp, placeholder_group);
auto results = std::make_unique<SearchResult>();
*results = visitor.get_moved_result(*plan->plan_node_);
results->segment_ = (void*)this;
results->segment_ = static_cast<void*>(const_cast<milvus::segcore::SegmentInternalInterface*>(this));
return results;
}

Expand All @@ -101,7 +101,7 @@ SegmentInternalInterface::Retrieve(tracer::TraceContext* trace_ctx,
auto results = std::make_unique<proto::segcore::RetrieveResults>();
query::ExecPlanNodeVisitor visitor(*this, timestamp);
auto retrieve_results = visitor.get_retrieve_result(*plan->plan_node_);
retrieve_results.segment_ = (void*)this;
retrieve_results.segment_ = static_cast<void*>(const_cast<milvus::segcore::SegmentInternalInterface*>(this));
results->set_has_more_result(retrieve_results.has_more_result);

auto result_rows = retrieve_results.result_offsets_.size();
Expand Down
4 changes: 2 additions & 2 deletions internal/core/src/segcore/SegmentSealedImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ int64_t
SegmentSealedImpl::num_chunk_index(FieldId field_id) const {
auto& field_meta = schema_->operator[](field_id);
if (field_meta.is_vector()) {
return int64_t(vector_indexings_.is_ready(field_id));
return static_cast<int64_t>(vector_indexings_.is_ready(field_id));
}

return scalar_indexings_.count(field_id);
Expand Down Expand Up @@ -1944,7 +1944,7 @@ SegmentSealedImpl::generate_interim_index(const FieldId field_id) {
auto index_metric = field_binlog_config->GetMetricType();

auto dataset =
knowhere::GenDataSet(row_count, dim, (void*)vec_data->Data());
knowhere::GenDataSet(row_count, dim, static_cast<const void*>(vec_data->Data()));
dataset->SetIsOwner(false);
dataset->SetIsSparse(is_sparse);

Expand Down
6 changes: 3 additions & 3 deletions internal/core/src/segcore/collection_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ CCollection
NewCollection(const void* schema_proto_blob, const int64_t length) {
auto collection = std::make_unique<milvus::segcore::Collection>(
schema_proto_blob, length);
return (void*)collection.release();
return static_cast<void*>(collection.release());
}

void
SetIndexMeta(CCollection collection,
const void* proto_blob,
const int64_t length) {
auto col = (milvus::segcore::Collection*)collection;
auto col = static_cast<milvus::segcore::Collection*>(collection);
col->parseIndexMeta(proto_blob, length);
}

void
DeleteCollection(CCollection collection) {
auto col = (milvus::segcore::Collection*)collection;
auto col = static_cast<milvus::segcore::Collection*>(collection);
delete col;
}

Expand Down
Loading

0 comments on commit 7a38102

Please sign in to comment.