8000 Remove all C-style casts and add clang-tidy rule to forbid them by Mytherin · Pull Request #7656 · duckdb/duckdb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Remove all C-style casts and add clang-tidy rule to forbid them #7656

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

Merged
merged 30 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
eddc926
Remove C-style casts and add clang-tidy rule (WIP)
Mytherin May 18, 2023
5188232
Remove clang-tidy rule again for now
Mytherin May 20, 2023
6b9112f
Revert Makefile
Mytherin May 20, 2023
19f65c5
Transformer - avoid using C-style casts, and move to using references…
Mytherin May 21, 2023
45846c7
Get rid of more C-style casts
Mytherin May 21, 2023
2e09719
UnifiedVectorFormat::GetData
Mytherin May 22, 2023
4e38e6f
Many more C-style cast removals
Mytherin May 22, 2023
5fcb727
More UnifiedVectorFormat::GetData and other casts
Mytherin May 22, 2023
be6d125
Format and HyperLogLog avoid using void*
Mytherin May 22, 2023
39d2451
Tidy-fixes in date_part
Mytherin May 22, 2023
4a13e8a
Many more C-style casts
Mytherin May 23, 2023
2194b6f
data_ptr_cast
Mytherin May 23, 2023
435606b
const_data_ptr_cast
Mytherin May 23, 2023
c8ae629
char* and const char* casts
Mytherin May 23, 2023
c124fc0
Missing dereference
Mytherin May 23, 2023
88ace2d
Remove C-style casts from vector and others
Mytherin May 23, 2023
1821ba4
Even more C-style cast removal
Mytherin May 23, 2023
8d4e3fb
Turn resizable buffer ptr into data_ptr_t, and remove casts from Parq…
Mytherin May 23, 2023
f4bf9bd
Less c-style casts in the Parquet extension
Mytherin May 23, 2023
26651f2
Revert R changes
Mytherin May 23, 2023
14a5d11
Remove extra ;
Mytherin May 23, 2023
1256895
CastNoConst
Mytherin May 23, 2023
281057c
Format fix
Mytherin May 23, 2023
1145997
Merge branch 'master' into moreclangtidy
Mytherin May 23, 2023
a23725a
Use reinterpret_cast in Cast headers, and more cast removal in Python…
Mytherin May 23, 2023
bfe1fbd
Python - move unicode methods into separate functions
Mytherin May 23, 2023
91a585d
Move these defines to header
Mytherin May 23, 2023
4386429
Fix sql auto complete extension
Mytherin May 23, 2023
81806e9
Merge branch 'extfix' into moreclangtidy
Mytherin May 23, 2023
0c5ecc3
Coverage fixes
Mytherin May 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Checks: '-*,clang-diagnostic-*,bugprone-*,performance-*,google-explicit-constructor,google-build-using-namespace,google-runtime-int,misc-definitions-in-headers,modernize-use-nullptr,modernize-use-override,-bugprone-macro-parentheses,readability-braces-around-statements,-bugprone-branch-clone,readability-identifier-naming,hicpp-exception-baseclass,misc-throw-by-value-catch-by-reference,-bugprone-signed-char-misuse,-bugprone-misplaced-widening-cast,-bugprone-sizeof-expression,-bugprone-narrowing-conversions,-bugprone-easily-swappable-parameters,google-global-names-in-headers,llvm-header-guard,misc-definitions-in-headers,modernize-use-emplace,modernize-use-bool-literals,-performance-inefficient-string-concatenation,-performance-no-int-to-ptr,readability-container-size-empty'
Checks: '-*,clang-diagnostic-*,bugprone-*,performance-*,google-explicit-constructor,google-build-using-namespace,google-runtime-int,misc-definitions-in-headers,modernize-use-nullptr,modernize-use-override,-bugprone-macro-parentheses,readability-braces-around-statements,-bugprone-branch-clone,readability-identifier-naming,hicpp-exception-baseclass,misc-throw-by-value-catch-by-reference,-bugprone-signed-char-misuse,-bugprone-misplaced-widening-cast,-bugprone-sizeof-expression,-bugprone-narrowing-conversions,-bugprone-easily-swappable-parameters,google-global-names-in-headers,llvm-header-guard,misc-definitions-in-headers,modernize-use-emplace,modernize-use-bool-literals,-performance-inefficient-string-concatenation,-performance-no-int-to-ptr,readability-container-size-empty,cppcoreguidelines-pro-type-cstyle-cast'
WarningsAsErrors: '*'
HeaderFilterRegex: '.*^(re2.h)'
AnalyzeTemporaryDtors: false
Expand Down
10 changes: 5 additions & 5 deletions .github/config/uncovered_files.csv
10000
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ common/exception_format_value.cpp 8
common/field_writer.cpp 3
common/file_buffer.cpp 5
common/file_system.cpp 19
common/fsst.cpp 5
common/fsst.cpp 6
common/gzip_file_system.cpp 40
common/hive_partitioning.cpp 54
common/local_file_system.cpp 16
Expand All @@ -53,7 +53,7 @@ common/serializer/buffered_deserializer.cpp 3
common/serializer/buffered_file_reader.cpp 9
common/serializer/buffered_file_writer.cpp 2
common/sort/comparators.cpp 72
common/sort/merge_sorter.cpp 99
common/sort/merge_sorter.cpp 100
common/sort/partition_state.cpp 43
common/sort/sort_state.cpp 10
common/sort/sorted_block.cpp 20
Expand Down Expand Up @@ -258,7 +258,7 @@ function/scalar_function.cpp 7
function/table/arrow.cpp 61
function/table/arrow_conversion.cpp 225
function/table/checkpoint.cpp 7
function/table/copy_csv.cpp 14
function/table/copy_csv.cpp 16
function/table/pragma_detailed_profiling_output.cpp 86
function/table/pragma_last_profiling_output.cpp 51
function/table/range.cpp 5
Expand Down Expand Up @@ -390,7 +390,7 @@ include/duckdb/main/connection_manager.hpp 3
include/duckdb/main/database.hpp 2
include/duckdb/main/prepared_statement.hpp 9
include/duckdb/main/query_profiler.hpp 9
include/duckdb/main/query_result.hpp 9
include/duckdb/main/query_result.hpp 11
include/duckdb/main/relation.hpp 3
include/duckdb/main/relation/subquery_relation.hpp 3
include/duckdb/main/relation/write_parquet_relation.hpp 3
Expand Down Expand Up @@ -564,7 +564,7 @@ parser/statement/multi_statement.cpp 7
parser/statement/select_statement.cpp 2
parser/statement/set_statement.cpp 3
parser/statement/update_statement.cpp 2
parser/tableref.cpp 8
parser/tableref.cpp 9
parser/tableref/basetableref.cpp 2
parser/tableref/emptytableref.cpp 3
parser/tableref/expressionlistref.cpp 5
Expand Down
4 changes: 2 additions & 2 deletions extension/autocomplete/sql_auto_complete-extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct SQLAutoCompleteData : public GlobalTableFunctionState {
};

struct AutoCompleteCandidate {
AutoCompleteCandidate(string candidate_p, int32_t score_bonus = 0)
explicit AutoCompleteCandidate(string candidate_p, int32_t score_bonus = 0)
: candidate(std::move(candidate_p)), score_bonus(score_bonus) {
}

Expand Down Expand Up @@ -408,7 +408,7 @@ void SQLAutoCompleteExtension::Load(DuckDB &db) {
}

std::string SQLAutoCompleteExtension::Name() {
return "sql_auto_complete";
return "autocomplete";
}

} // namespace duckdb
Expand Down
2 changes: 1 addition & 1 deletion extension/icu/icu-datepart.cpp
Original file line number Diff li 8000 ne number Diff line change
Expand Up @@ -329,7 +329,7 @@ struct ICUDatePart : public ICUDateFunc {
input.ToUnifiedFormat(count, rdata);

const auto &arg_valid = rdata.validity;
auto tdata = (const INPUT_TYPE *)rdata.data;
auto tdata = UnifiedVectorFormat::GetData<INPUT_TYPE>(rdata);

result.SetVectorType(VectorType::FLAT_VECTOR);
auto &child_entries = StructVector::GetEntries(result);
Expand Down
2 changes: 1 addition & 1 deletion extension/inet/inet_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ bool INetFunctions::CastVarcharToINET(Vector &source, Vector &result, idx_t coun
auto address_data = FlatVector::GetData<hugeint_t>(*entries[1]);
auto mask_data = FlatVector::GetData<uint16_t>(*entries[2]);

auto input = (string_t *)vdata.data;
auto input = UnifiedVectorFormat::GetData<string_t>(vdata);
bool success = true;
for (idx_t i = 0; i < (constant ? 1 : count); i++) {
auto idx = vdata.sel->get_index(i);
Expand Down
4 changes: 2 additions & 2 deletions extension/jemalloc/jemalloc-extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ std::string JEMallocExtension::Name() {
}

data_ptr_t JEMallocExtension::Allocate(PrivateAllocatorData *private_data, idx_t size) {
return (data_ptr_t)duckdb_jemalloc::je_malloc(size);
return data_ptr_cast(duckdb_jemalloc::je_malloc(size));
}

void JEMallocExtension::Free(PrivateAllocatorData *private_data, data_ptr_t pointer, idx_t size) {
Expand All @@ -24,7 +24,7 @@ void JEMallocExtension::Free(PrivateAllocatorData *private_data, data_ptr_t poin

data_ptr_t JEMallocExtension::Reallocate(PrivateAllocatorData *private_data, data_ptr_t pointer, idx_t old_size,
idx_t size) {
return (data_ptr_t)duckdb_jemalloc::je_realloc(pointer, size);
return data_ptr_cast(duckdb_jemalloc::je_realloc(pointer, size));
}

} // namespace duckdb
Expand Down
2 changes: 1 addition & 1 deletion extension/json/include/json_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class JSONAllocator {

static inline void *Reallocate(void *ctx, void *ptr, size_t old_size, size_t size) {
auto alloc = (ArenaAllocator *)ctx;
return alloc->ReallocateAligned((data_ptr_t)ptr, old_size, size);
return alloc->ReallocateAligned(data_ptr_cast(ptr), old_size, size);
}

static inline void Free(void *ctx, void *ptr) {
Expand Down
2 changes: 1 addition & 1 deletion extension/json/include/json_executors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct JSONExecutors {
UnifiedVectorFormat input_data;
auto &input_vector = args.data[0];
input_vector.ToUnifiedFormat(count, input_data);
auto inputs = (string_t *)input_data.data;
auto inputs = UnifiedVectorFormat::GetData<string_t>(input_data);

ListVector::Reserve(result, list_size);
auto list_entries = FlatVector::GetData<list_entry_t>(result);
Expand Down
12 changes: 6 additions & 6 deletions extension/json/json_functions/json_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ static void AddKeyValuePairs(yyjson_mut_doc *doc, yyjson_mut_val *objs[], Vector
idx_t count) {
UnifiedVectorFormat key_data;
key_v.ToUnifiedFormat(count, key_data);
auto keys = (string_t *)key_data.data;
auto keys = UnifiedVectorFormat::GetData<string_t>(key_data);

for (idx_t i = 0; i < count; i++) {
auto key_idx = key_data.sel->get_index(i);
Expand Down Expand Up @@ -253,7 +253,7 @@ template <class INPUT_TYPE, class TARGET_TYPE>
static void TemplatedCreateValues(yyjson_mut_doc *doc, yyjson_mut_val *vals[], Vector &value_v, idx_t count) {
UnifiedVectorFormat value_data;
value_v.ToUnifiedFormat(count, value_data);
auto values = (INPUT_TYPE *)value_data.data;
auto values = UnifiedVectorFormat::GetData<INPUT_TYPE>(value_data);

const auto type_is_json = JSONCommon::LogicalTypeIsJSON(value_v.GetType());
for (idx_t i = 0; i < count; i++) {
Expand Down Expand Up @@ -311,7 +311,7 @@ static void CreateValuesMap(const StructNames &names, yyjson_mut_doc *doc, yyjso
// Add the key/value pairs to the values
UnifiedVectorFormat map_data;
value_v.ToUnifiedFormat(count, map_data);
auto map_key_list_entries = (list_entry_t *)map_data.data;
auto map_key_list_entries = UnifiedVectorFormat::GetData<list_entry_t>(map_data);
for (idx_t i = 0; i < count; i++) {
idx_t idx = map_data.sel->get_index(i);
if (!map_data.validity.RowIsValid(idx)) {
Expand Down Expand Up @@ -358,14 +358,14 @@ static void CreateValuesUnion(const StructNames &names, yyjson_mut_doc *doc, yyj
// and the rows where the member is not matching the tag
UnifiedVectorFormat key_data;
member_key_v.ToUnifiedFormat(count, key_data);
auto keys = (string_t *)key_data.data;
auto keys = UnifiedVectorFormat::GetData<string_t>(key_data);

for (idx_t i = 0; i < count; i++) {
auto tag_idx = tag_data.sel->get_index(i);
if (!tag_data.validity.RowIsValid(tag_idx)) {
continue;
}
auto tag = ((uint8_t *)tag_data.data)[tag_idx];
auto tag = (UnifiedVectorFormat::GetData<uint8_t>(tag_data))[tag_idx];
if (tag != member_idx) {
continue;
}
Expand All @@ -390,7 +390,7 @@ static void CreateValuesList(const StructNames &names, yyjson_mut_doc *doc, yyjs
// Now we add the values to the appropriate JSON arrays
UnifiedVectorFormat list_data;
value_v.ToUnifiedFormat(count, list_data);
auto list_entries = (list_entry_t *)list_data.data;
auto list_entries = UnifiedVectorFormat::GetData<list_entry_t>(list_data);
for (idx_t i = 0; i < count; i++) {
idx_t idx = list_data.sel->get_index(i);
if (!list_data.validity.RowIsValid(idx)) {
Expand Down
2 changes: 1 addition & 1 deletion extension/json/json_functions/json_merge_patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static inline void ReadObjects(yyjson_mut_doc *doc, Vector &input, yyjson_mut_va
UnifiedVectorFormat input_data;
auto &input_vector = input;
input_vector.ToUnifiedFormat(count, input_data);
auto inputs = (string_t *)input_data.data;
auto inputs = UnifiedVectorFormat::GetData<string_t>(input_data);

// Read the documents
for (idx_t i = 0; i < count; i++) {
Expand Down
2 changes: 1 addition & 1 deletion extension/json/json_functions/json_transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ static bool TransformFunctionInternal(Vector &input, const idx_t count, Vector &
JSONTransformOptions &options) {
UnifiedVectorFormat input_data;
input.ToUnifiedFormat(count, input_data);
auto inputs = (string_t *)input_data.data;
auto inputs = UnifiedVectorFormat::GetData<string_t>(input_data);

// Read documents
auto docs = (yyjson_doc **)alc->malloc(alc->ctx, sizeof(yyjson_doc *) * count);
Expand Down
Loading
0