Skip to content

Commit

Permalink
implement missing stl_allocator stuff and fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
lnkuiper committed Sep 6, 2024
1 parent a164856 commit f9570b2
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 59 deletions.
12 changes: 9 additions & 3 deletions extension/httpfs/crypto.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "crypto.hpp"

#include "duckdb/common/common.hpp"
#include "mbedtls_wrapper.hpp"

#include <iostream>
#include "duckdb/common/common.hpp"
#include <stdio.h>

#define CPPHTTPLIB_OPENSSL_SUPPORT
Expand Down Expand Up @@ -111,7 +113,7 @@ size_t AESGCMStateSSL::Finalize(data_ptr_t out, idx_t out_len, data_ptr_t tag, i
auto text_len = out_len;

switch (mode) {
case ENCRYPT:
case ENCRYPT: {
if (1 != EVP_EncryptFinal_ex(gcm_context, data_ptr_cast(out) + out_len, reinterpret_cast<int *>(&out_len))) {
throw InternalException("EncryptFinal failed");
}
Expand All @@ -121,7 +123,8 @@ size_t AESGCMStateSSL::Finalize(data_ptr_t out, idx_t out_len, data_ptr_t tag, i
throw InternalException("Calculating the tag failed");
}
return text_len;
case DECRYPT:
}
case DECRYPT: {
// Set expected tag value
if (!EVP_CIPHER_CTX_ctrl(gcm_context, EVP_CTRL_GCM_SET_TAG, tag_len, tag)) {
throw InternalException("Finalizing tag failed");
Expand All @@ -136,6 +139,9 @@ size_t AESGCMStateSSL::Finalize(data_ptr_t out, idx_t out_len, data_ptr_t tag, i
}
throw InvalidInputException("Computed AES tag differs from read AES tag, are you using the right key?");
}
default:
throw InternalException("Unknown mode in AESGCMStateSSL::Finalize");
}
}

} // namespace duckdb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,9 @@
/*
* If defined, all the features necessary for background threads are present.
*/
#ifndef __APPLE__
#define JEMALLOC_BACKGROUND_THREAD
#endif

/*
* If defined, jemalloc symbols are not exported (doesn't work when
Expand Down
6 changes: 0 additions & 6 deletions extension/jemalloc/jemalloc_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,9 @@ void JemallocExtension::ThreadIdle() {
}

void JemallocExtension::FlushAll() {
// Flush thread-local cache
SetJemallocCTL("thread.tcache.flush");

// Flush all arenas
const auto purge_arena = PurgeArenaString(MALLCTL_ARENAS_ALL);
SetJemallocCTL(purge_arena.c_str());

// Reset the peak after resetting
SetJemallocCTL("thread.peak.reset");
}

void JemallocExtension::SetBackgroundThreads(bool enable) {
Expand Down
7 changes: 4 additions & 3 deletions src/common/types/column/column_data_collection.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include "duckdb/common/types/column/column_data_collection.hpp"

#include "duckdb/common/printer.hpp"
#include "duckdb/common/serializer/deserializer.hpp"
#include "duckdb/common/serializer/serializer.hpp"
#include "duckdb/common/string_util.hpp"
#include "duckdb/common/types/column/column_data_collection_segment.hpp"
#include "duckdb/common/types/value_map.hpp"
#include "duckdb/common/uhugeint.hpp"
#include "duckdb/common/vector_operations/vector_operations.hpp"
#include "duckdb/storage/buffer_manager.hpp"
#include "duckdb/common/serializer/serializer.hpp"
#include "duckdb/common/serializer/deserializer.hpp"

namespace duckdb {

Expand Down Expand Up @@ -548,7 +548,8 @@ void ColumnDataCopy<string_t>(ColumnDataMetaData &meta_data, const UnifiedVector
}

if (heap_size != 0) {
current_segment.swizzle_data.emplace_back(child_index, current_segment.count, append_count);
current_segment.swizzle_data.emplace_back(child_index, current_segment.count,
UnsafeNumericCast<uint16_t>(append_count));
}

current_segment.count += append_count;
Expand Down
2 changes: 1 addition & 1 deletion src/common/types/column/column_data_consumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void ColumnDataConsumer::InitializeScan() {
chunk_references.reserve(chunk_count);
for (auto &segment : collection.GetSegments()) {
for (idx_t chunk_index = 0; chunk_index < segment->chunk_data.size(); chunk_index++) {
chunk_references.emplace_back(segment.get(), chunk_index);
chunk_references.emplace_back(segment.get(), NumericCast<uint32_t>(chunk_index));
}
}
std::sort(chunk_references.begin(), chunk_references.end());
Expand Down
2 changes: 1 addition & 1 deletion src/common/vector_operations/vector_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void VectorOperations::Copy(const Vector &source_p, Vector &target, const Select
auto source_idx = sel->get_index(source_offset + i);
auto &source_entry = sdata[source_idx];
for (idx_t j = 0; j < source_entry.length; ++j) {
child_rows.emplace_back(source_entry.offset + j);
child_rows.emplace_back(UnsafeNumericCast<sel_t>(source_entry.offset + j));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core_functions/lambda_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct ListFilterFunctor {
}
//! Pushes an empty list to the entry_lengths vector
static void PushEmptyList(vector<idx_t> &entry_lengths) {
entry_lengths.emplace_back(0);
entry_lengths.emplace_back(0ULL);
}
//! Pushes the length of the original list to the entry_lengths vector
static void SetResultEntry(list_entry_t *, idx_t &, const list_entry_t &entry, const idx_t,
Expand Down
4 changes: 2 additions & 2 deletions src/execution/index/art/iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void Iterator::FindMinimum(const Node &node) {
D_ASSERT(nested_depth < Prefix::ROW_ID_SIZE);
}
}
nodes.emplace(node, 0);
nodes.emplace(node, static_cast<uint8_t>(0));
return FindMinimum(*prefix.ptr);
}

Expand Down Expand Up @@ -188,7 +188,7 @@ bool Iterator::LowerBound(const Node &node, const ARTKey &key, const bool equal,
for (idx_t i = 0; i < prefix.data[Prefix::Count(art)]; i++) {
current_key.Push(prefix.data[i]);
}
nodes.emplace(node, 0);
nodes.emplace(node, static_cast<uint8_t>(0));

// We compare the prefix bytes with the key bytes.
for (idx_t i = 0; i < prefix.data[Prefix::Count(art)]; i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/execution/window_segment_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ WindowConstantAggregatorGlobalState::WindowConstantAggregatorGlobalState(const W

// Locate the partition boundaries
if (partition_mask.AllValid()) {
partition_offsets.emplace_back(0);
partition_offsets.emplace_back(0ULL);
} else {
idx_t entry_idx;
idx_t shift;
Expand Down
6 changes: 3 additions & 3 deletions src/function/cast/union_casts.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "duckdb/common/exception/conversion_exception.hpp"
#include "duckdb/common/numeric_utils.hpp"
#include "duckdb/function/cast/bound_cast_data.hpp"
#include "duckdb/function/cast/cast_function_set.hpp"
#include "duckdb/function/cast/default_casts.hpp"
#include "duckdb/function/cast/bound_cast_data.hpp"

#include <algorithm> // for std::sort

Expand All @@ -24,8 +24,8 @@ unique_ptr<BoundCastData> BindToUnionCast(BindCastInput &input, const LogicalTyp
auto member_cast_cost = input.function_set.ImplicitCastCost(source, member_type);
if (member_cast_cost != -1) {
auto member_cast_info = input.GetCastFunction(source, member_type);
candidates.emplace_back(member_idx, member_name, member_type, member_cast_cost,
std::move(member_cast_info));
candidates.emplace_back(UnsafeNumericCast<union_tag_t>(member_idx), member_name, member_type,
member_cast_cost, std::move(member_cast_info));
}
};

Expand Down
50 changes: 23 additions & 27 deletions src/include/duckdb/common/stl_allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

#pragma once

#include "duckdb/common/winapi.hpp"

#include <memory>

namespace duckdb {

void *stl_malloc(size_t size); // NOLINT: not using camelcase on purpose here
void stl_free(void *ptr); // NOLINT: not using camelcase on purpose here
DUCKDB_API void *stl_malloc(size_t size); // NOLINT: not using camelcase on purpose here
DUCKDB_API void stl_free(void *ptr); // NOLINT: not using camelcase on purpose here

template <class T>
T *stl_new_array_uninitialized(size_t size) {
Expand Down Expand Up @@ -77,14 +79,15 @@ class stl_allocator { // NOLINT: not using camelcase on purpose here
using const_reference = typename original::const_reference;
using size_type = typename original::size_type;
using difference_type = typename original::difference_type;
using propagate_on_container_move_assignment = typename original::propagate_on_container_move_assignment;
using propagate_on_container_copy_assignment = std::true_type;
using propagate_on_container_move_assignment = std::true_type;
using propagate_on_container_swap = std::true_type;
template <class U>
struct rebind {
typedef stl_allocator<U> other;
};
using is_always_equal = typename original::is_always_equal;

public:
stl_allocator() noexcept {
}
stl_allocator(const stl_allocator &) noexcept {
Expand All @@ -95,28 +98,31 @@ class stl_allocator { // NOLINT: not using camelcase on purpose here
~stl_allocator() {
}

public:
pointer allocate(size_type count, const void * = 0) { // NOLINT: matching name of std
return static_cast<pointer>(stl_malloc(count * sizeof(value_type)));
pointer allocate(size_type n, const void * = 0) { // NOLINT: matching name of std
return static_cast<pointer>(stl_malloc(n * sizeof(value_type)));
}

void deallocate(T *p, size_type) { // NOLINT: matching name of std
stl_free(p);
}
};

template <class T, class U>
bool operator==(const stl_allocator<T> &, const stl_allocator<U> &) noexcept {
return true;
}
size_type max_size() const noexcept { // NOLINT: matching name of std
return PTRDIFF_MAX / sizeof(value_type);
}

template <class T, class U>
bool operator==(stl_allocator<T> &, const stl_allocator<U> &) noexcept {
return true;
}
template <class U, class... Args>
void construct(U *p, Args &&...args) { // NOLINT: matching name of std
new (p) U(std::forward<Args>(args)...);
}

template <class U>
void destroy(U *p) { // NOLINT: matching name of std
p->~U();
}
};

template <class T, class U>
bool operator==(const stl_allocator<T> &, stl_allocator<U> &) noexcept {
bool operator==(const stl_allocator<T> &, const stl_allocator<U> &) noexcept {
return true;
}

Expand All @@ -125,14 +131,4 @@ bool operator!=(const stl_allocator<T> &, const stl_allocator<U> &) noexcept {
return false;
}

template <class T, class U>
bool operator!=(stl_allocator<T> &, const stl_allocator<U> &) noexcept {
return false;
}

template <class T, class U>
bool operator!=(const stl_allocator<T> &, stl_allocator<U> &) noexcept {
return false;
}

} // namespace duckdb
2 changes: 1 addition & 1 deletion src/include/duckdb/common/winapi.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//===----------------------------------------------------------------------===//
// DuckDB
//
// duckdb/main/winapi.hpp
// duckdb/common/winapi.hpp
//
//
//===----------------------------------------------------------------------===//
Expand Down
12 changes: 6 additions & 6 deletions src/include/duckdb/storage/compression/alp/algorithm/alp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

#include "duckdb/common/bitpacking.hpp"
#include "duckdb/common/common.hpp"
#include "duckdb/common/unordered_map.hpp"
#include "duckdb/common/pair.hpp"
#include "duckdb/common/limits.hpp"
#include "duckdb/common/pair.hpp"
#include "duckdb/common/types/hash.hpp"
#include "duckdb/common/unordered_map.hpp"
#include "duckdb/storage/compression/alp/alp_constants.hpp"
#include "duckdb/storage/compression/alp/alp_utils.hpp"

Expand Down Expand Up @@ -233,10 +233,10 @@ struct AlpCompression {
// Note that this vector is always small (< 10 combinations)
vector<AlpCombination> best_k_combinations;
for (auto const &combination : best_k_combinations_hash) {
best_k_combinations.emplace_back(
combination.first, // Encoding Indices
combination.second, // N of times it appeared (hash value)
0 // Compression size is irrelevant at this phase since we compare combinations from different vectors
best_k_combinations.emplace_back(combination.first, // Encoding Indices
combination.second, // N of times it appeared (hash value)
0ULL // Compression size is irrelevant at this phase since we compare
// combinations from different vectors
);
}
sort(best_k_combinations.begin(), best_k_combinations.end(), CompareALPCombinations);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct AlpRDCompression {

template <bool PERSIST_DICT>
static double BuildLeftPartsDictionary(const vector<EXACT_TYPE> &values, uint8_t right_bit_width, State &state) {
unordered_map<EXACT_TYPE, int32_t> left_parts_hash;
unordered_map<EXACT_TYPE, uint32_t> left_parts_hash;
vector<AlpRDLeftPartInfo> left_parts_sorted_repetitions;

// Building a hash for all the left parts and how many times they appear
Expand Down
2 changes: 1 addition & 1 deletion src/planner/operator/logical_join.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ vector<ColumnBinding> LogicalJoin::GetColumnBindings() {

if (join_type == JoinType::MARK) {
// for MARK join we project the left hand side plus the MARK column
left_bindings.emplace_back(mark_index, 0);
left_bindings.emplace_back(mark_index, 0ULL);
return left_bindings;
}
// for other join types we project both the LHS and the RHS
Expand Down
6 changes: 4 additions & 2 deletions third_party/concurrentqueue/concurrentqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
#include <array>
#include <thread> // partly for __WINPTHREADS_VERSION if on MinGW-w64 w/ POSIX threading

#include "duckdb/common/stl_allocator.hpp"

// Platform-specific definitions of a numeric thread ID type and an invalid value
namespace duckdb_moodycamel { namespace details {
template<typename thread_id_t> struct thread_id_converter {
Expand Down Expand Up @@ -335,8 +337,8 @@ struct ConcurrentQueueDefaultTraits
static inline void* (malloc)(size_t size) { return WORKAROUND_malloc(size); }
static inline void (free)(void* ptr) { return WORKAROUND_free(ptr); }
#else
static inline void* malloc(size_t size) { return std::malloc(size); }
static inline void free(void* ptr) { return std::free(ptr); }
static inline void* malloc(size_t size) { return duckdb::stl_malloc(size); }
static inline void free(void* ptr) { return duckdb::stl_free(ptr); }
#endif
#else
// Debug versions when running under the Relacy race detector (ignore
Expand Down

0 comments on commit f9570b2

Please sign in to comment.