Skip to content
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
28 changes: 28 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2091,6 +2091,34 @@ René Nyffenegger rene.nyffenegger@adp-gmbh.ch

--------------------------------------------------------------------------------

The file cpp/src/arrow/vendored/span.hpp has the following license

Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

--------------------------------------------------------------------------------

The file cpp/src/arrow/vendored/optional.hpp has the following license

Boost Software License - Version 1.0 - August 17th, 2003
Expand Down
25 changes: 13 additions & 12 deletions cpp/src/arrow/c/bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "arrow/util/key_value_metadata.h"
#include "arrow/util/logging.h"
#include "arrow/util/macros.h"
#include "arrow/util/small_vector.h"
#include "arrow/util/string_view.h"
#include "arrow/util/value_parsing.h"
#include "arrow/visitor_inline.h"
Expand All @@ -47,6 +48,9 @@ namespace arrow {
using internal::checked_cast;
using internal::checked_pointer_cast;

using internal::SmallVector;
using internal::StaticVector;

using internal::ArrayExportGuard;
using internal::ArrayExportTraits;
using internal::SchemaExportGuard;
Expand All @@ -65,9 +69,6 @@ Status ExportingNotImplemented(const DataType& type) {

// XXX use Gandiva's SimpleArena?

template <typename T>
using PoolVector = std::vector<T, ::arrow::stl::allocator<T>>;

template <typename Derived>
struct PoolAllocationMixin {
static void* operator new(size_t size) {
Expand All @@ -90,8 +91,8 @@ struct ExportedSchemaPrivateData : PoolAllocationMixin<ExportedSchemaPrivateData
std::string name_;
std::string metadata_;
struct ArrowSchema dictionary_;
PoolVector<struct ArrowSchema> children_;
PoolVector<struct ArrowSchema*> child_pointers_;
SmallVector<struct ArrowSchema, 1> children_;
SmallVector<struct ArrowSchema*, 4> child_pointers_;

ExportedSchemaPrivateData() = default;
ARROW_DEFAULT_MOVE_AND_ASSIGN(ExportedSchemaPrivateData);
Expand Down Expand Up @@ -225,7 +226,7 @@ struct SchemaExporter {
c_struct->flags = flags_;

c_struct->n_children = static_cast<int64_t>(child_exporters_.size());
c_struct->children = pdata->child_pointers_.data();
c_struct->children = c_struct->n_children ? pdata->child_pointers_.data() : nullptr;
c_struct->dictionary = dict_exporter_ ? &pdata->dictionary_ : nullptr;
c_struct->private_data = pdata;
c_struct->release = ReleaseExportedSchema;
Expand Down Expand Up @@ -475,10 +476,10 @@ namespace {

struct ExportedArrayPrivateData : PoolAllocationMixin<ExportedArrayPrivateData> {
// The buffers are owned by the ArrayData member
PoolVector<const void*> buffers_;
StaticVector<const void*, 3> buffers_;
struct ArrowArray dictionary_;
PoolVector<struct ArrowArray> children_;
PoolVector<struct ArrowArray*> child_pointers_;
SmallVector<struct ArrowArray, 1> children_;
SmallVector<struct ArrowArray*, 4> child_pointers_;

std::shared_ptr<ArrayData> data_;

Expand Down Expand Up @@ -574,7 +575,7 @@ struct ArrayExporter {
c_struct_->n_buffers = static_cast<int64_t>(pdata->buffers_.size());
c_struct_->n_children = static_cast<int64_t>(pdata->child_pointers_.size());
c_struct_->buffers = pdata->buffers_.data();
c_struct_->children = pdata->child_pointers_.data();
c_struct_->children = c_struct_->n_children ? pdata->child_pointers_.data() : nullptr;
c_struct_->dictionary = dict_exporter_ ? &pdata->dictionary_ : nullptr;
c_struct_->private_data = pdata;
c_struct_->release = ReleaseExportedArray;
Expand Down Expand Up @@ -687,8 +688,8 @@ class FormatStringParser {
}
}

std::vector<util::string_view> Split(util::string_view v, char delim = ',') {
std::vector<util::string_view> parts;
SmallVector<util::string_view, 2> Split(util::string_view v, char delim = ',') {
SmallVector<util::string_view, 2> parts;
size_t start = 0, end;
while (true) {
end = v.find_first_of(delim, start);
Expand Down
33 changes: 10 additions & 23 deletions cpp/src/arrow/result.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "arrow/status.h"
#include "arrow/util/compare.h"
#include "arrow/util/launder.h"

namespace arrow {

Expand All @@ -34,15 +35,6 @@ struct EnsureResult;

namespace internal {

#if __cplusplus >= 201703L
using std::launder;
#else
template <class T>
constexpr T* launder(T* p) noexcept {
return p;
}
#endif

ARROW_EXPORT void DieWithMessage(const std::string& msg);

ARROW_EXPORT void InvalidValueOrDie(const Status& st);
Expand Down Expand Up @@ -168,7 +160,7 @@ class ARROW_MUST_USE_TYPE Result : public util::EqualityComparable<Result<T>> {
typename std::remove_cv<U>::type>::type,
Status>::value>::type>
Result(U&& value) noexcept { // NOLINT(runtime/explicit)
ConstructValue(std::forward<U>(value));
data_.Construct(std::forward<U>(value));
}

/// Constructs a Result object that contains `value`. The resulting object
Expand All @@ -183,7 +175,7 @@ class ARROW_MUST_USE_TYPE Result : public util::EqualityComparable<Result<T>> {
// NOTE `Result(U&& value)` above should be sufficient, but some compilers
// fail matching it.
Result(T&& value) noexcept { // NOLINT(runtime/explicit)
ConstructValue(std::move(value));
data_.Construct(std::move(value));
}

/// Copy constructor.
Expand All @@ -198,7 +190,7 @@ class ARROW_MUST_USE_TYPE Result : public util::EqualityComparable<Result<T>> {
/// \param other The value to copy from.
Result(const Result& other) : status_(other.status_) {
if (ARROW_PREDICT_TRUE(status_.ok())) {
ConstructValue(other.ValueUnsafe());
data_.Construct(other.ValueUnsafe());
}
}

Expand All @@ -213,7 +205,7 @@ class ARROW_MUST_USE_TYPE Result : public util::EqualityComparable<Result<T>> {
std::is_convertible<U, T>::value>::type>
Result(const Result<U>& other) : status_(other.status_) {
if (ARROW_PREDICT_TRUE(status_.ok())) {
ConstructValue(other.ValueUnsafe());
data_.Construct(other.ValueUnsafe());
}
}

Expand All @@ -228,7 +220,7 @@ class ARROW_MUST_USE_TYPE Result : public util::EqualityComparable<Result<T>> {
Destroy();
status_ = other.status_;
if (ARROW_PREDICT_TRUE(status_.ok())) {
ConstructValue(other.ValueUnsafe());
data_.Construct(other.ValueUnsafe());
}
return *this;
}
Expand All @@ -247,7 +239,7 @@ class ARROW_MUST_USE_TYPE Result : public util::EqualityComparable<Result<T>> {
Result(Result<U>&& other) noexcept {
if (ARROW_PREDICT_TRUE(other.status_.ok())) {
status_ = std::move(other.status_);
ConstructValue(other.MoveValueUnsafe());
data_.Construct(other.MoveValueUnsafe());
} else {
// If we moved the status, the other status may become ok but the other
// value hasn't been constructed => crash on other destructor.
Expand All @@ -269,7 +261,7 @@ class ARROW_MUST_USE_TYPE Result : public util::EqualityComparable<Result<T>> {
Destroy();
if (ARROW_PREDICT_TRUE(other.status_.ok())) {
status_ = std::move(other.status_);
ConstructValue(other.MoveValueUnsafe());
data_.Construct(other.MoveValueUnsafe());
} else {
// If we moved the status, the other status may become ok but the other
// value hasn't been constructed => crash on other destructor.
Expand Down Expand Up @@ -440,18 +432,13 @@ class ARROW_MUST_USE_TYPE Result : public util::EqualityComparable<Result<T>> {

private:
Status status_; // pointer-sized
typename std::aligned_storage<sizeof(T), alignof(T)>::type data_;

template <typename U>
void ConstructValue(U&& u) {
new (&data_) T(std::forward<U>(u));
}
internal::AlignedStorage<T> data_;

void Destroy() {
if (ARROW_PREDICT_TRUE(status_.ok())) {
static_assert(offsetof(Result<T>, status_) == 0,
"Status is guaranteed to be at the start of Result<>");
internal::launder(reinterpret_cast<const T*>(&data_))->~T();
data_.Destroy();
}
}
};
Expand Down
24 changes: 18 additions & 6 deletions cpp/src/arrow/testing/gtest_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -554,30 +554,38 @@ void PrintTo(const Result<T>& result, std::ostream* os) {
}
}

// A data type with only move constructors.
// A data type with only move constructors (no copy, no default).
struct MoveOnlyDataType {
explicit MoveOnlyDataType(int x) : data(new int(x)) {}

MoveOnlyDataType(const MoveOnlyDataType& other) = delete;
MoveOnlyDataType& operator=(const MoveOnlyDataType& other) = delete;

MoveOnlyDataType(MoveOnlyDataType&& other) { MoveFrom(&other); }
MoveOnlyDataType& operator=(MoveOnlyDataType&& other) {
MoveOnlyDataType(MoveOnlyDataType&& other) noexcept { MoveFrom(&other); }
MoveOnlyDataType& operator=(MoveOnlyDataType&& other) noexcept {
MoveFrom(&other);
return *this;
}

MoveOnlyDataType& operator=(int x) {
if (data != nullptr) {
delete data;
}
data = new int(x);
return *this;
}

~MoveOnlyDataType() { Destroy(); }

void Destroy() {
void Destroy() noexcept {
if (data != nullptr) {
delete data;
data = nullptr;
moves = -1;
}
}

void MoveFrom(MoveOnlyDataType* other) {
void MoveFrom(MoveOnlyDataType* other) noexcept {
Destroy();
data = other->data;
other->data = nullptr;
Expand All @@ -586,10 +594,14 @@ struct MoveOnlyDataType {

int ToInt() const { return data == nullptr ? -42 : *data; }

bool operator==(int other) const { return data != nullptr && *data == other; }
bool operator==(const MoveOnlyDataType& other) const {
return data != nullptr && other.data != nullptr && *data == *other.data;
}
bool operator<(const MoveOnlyDataType& other) const {
return data == nullptr || (other.data != nullptr && *data < *other.data);
}

bool operator==(int other) const { return data != nullptr && *data == other; }
friend bool operator==(int left, const MoveOnlyDataType& right) {
return right == left;
}
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/arrow/util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ add_arrow_test(utility-test
range_test.cc
reflection_test.cc
rle_encoding_test.cc
small_vector_test.cc
stl_util_test.cc
string_test.cc
tdigest_test.cc
Expand Down Expand Up @@ -88,6 +89,7 @@ add_arrow_benchmark(int_util_benchmark)
add_arrow_benchmark(machine_benchmark)
add_arrow_benchmark(queue_benchmark)
add_arrow_benchmark(range_benchmark)
add_arrow_benchmark(small_vector_benchmark)
add_arrow_benchmark(tdigest_benchmark)
add_arrow_benchmark(thread_pool_benchmark)
add_arrow_benchmark(trie_benchmark)
Expand Down
69 changes: 69 additions & 0 deletions cpp/src/arrow/util/launder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#pragma once

#include <new>
#include <type_traits>

namespace arrow {
namespace internal {

#if __cplusplus >= 201703L
using std::launder;
#else
template <class T>
constexpr T* launder(T* p) noexcept {
return p;
}
#endif

template <typename T>
class AlignedStorage {
public:
T* get() { return launder(reinterpret_cast<T*>(&data_)); }
constexpr const T* get() const { return launder(reinterpret_cast<const T*>(&data_)); }

T& operator*() { return *get(); }
constexpr const T& operator*() const { return *get(); }

T* operator->() { return get(); }
constexpr const T* operator->() const { return get(); }

void Destroy() noexcept {
if (!std::is_trivially_destructible<T>::value) {
get()->~T();
}
}

template <typename... A>
void Construct(A&&... args) {
new (&data_) T(std::forward<A>(args)...);
}

void MoveFrom(AlignedStorage* other) noexcept {
static_assert(std::is_nothrow_move_constructible<T>::value, "");
Construct(std::move(*other->get()));
other->Destroy();
}

private:
typename std::aligned_storage<sizeof(T), alignof(T)>::type data_;
};

} // namespace internal
} // namespace arrow
1 change: 1 addition & 0 deletions cpp/src/arrow/util/make_unique.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ typename std::enable_if<std::is_array<T>::value && std::extent<T>::value == 0,
std::unique_ptr<T>>::type
make_unique(std::size_t n) {
using value_type = typename std::remove_extent<T>::type;
// NOLINTNEXTLINE modernize-avoid-c-arrays
return std::unique_ptr<value_type[]>(new value_type[n]);
}

Expand Down
Loading