277 lines
8.8 KiB
Diff
277 lines
8.8 KiB
Diff
# Copyright 2023 The Pigweed Authors
|
|
#
|
|
# Licensed 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
|
|
#
|
|
# https://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.
|
|
|
|
# Patch the fit::function implementation for use in Pigweed:
|
|
#
|
|
# - Use PW_ASSERT instead of __builtin_abort.
|
|
# - Temporarily disable sanitizers when invoking a function for b/241567321.
|
|
#
|
|
diff --git a/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/internal/function.h b/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/internal/function.h
|
|
--- a/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/internal/function.h
|
|
+++ b/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/internal/function.h
|
|
@@ -18,6 +18,8 @@
|
|
#include <utility>
|
|
|
|
#include "../nullable.h"
|
|
+#include "pw_assert/assert.h"
|
|
+#include "pw_preprocessor/compiler.h"
|
|
|
|
namespace fit {
|
|
namespace internal {
|
|
@@ -87,7 +89,7 @@ inline const void* unshared_target_type_id(void* /*bits*/, const void* impl_ops)
|
|
// elsewhere in the header as an inline variable.
|
|
template <typename Unused = void>
|
|
struct null_target {
|
|
- static void invoke(void* /*bits*/) { __builtin_abort(); }
|
|
+ static void invoke(void* /*bits*/) { PW_ASSERT(false); }
|
|
|
|
static const target_ops<void> ops;
|
|
|
|
@@ -493,7 +495,8 @@ class function_base<inline_target_size, require_inline, Result(Args...)>
|
|
// Note that fit::callback will release the target immediately after
|
|
// invoke() (also affecting any share()d copies).
|
|
// Aborts if the function's target is empty.
|
|
- Result invoke(Args... args) const {
|
|
+ // TODO(b/241567321): Remove "no sanitize" after pw_protobuf is fixed.
|
|
+ Result invoke(Args... args) const PW_NO_SANITIZE("function") {
|
|
// Down cast the ops to the derived type that this function was instantiated
|
|
// with, which includes the invoke function.
|
|
//
|
|
@@ -523,7 +526,7 @@ class function_base<inline_target_size, require_inline, Result(Args...)>
|
|
template <typename SharedFunction>
|
|
void copy_shared_target_to(SharedFunction& copy) {
|
|
copy.destroy_target();
|
|
- assert(base::ops() == &shared_target_type<SharedFunction>::ops);
|
|
+ PW_ASSERT(base::ops() == &shared_target_type<SharedFunction>::ops);
|
|
shared_target_type<SharedFunction>::copy_shared_ptr(base::bits(), copy.bits());
|
|
copy.set_ops(base::ops());
|
|
}
|
|
@@ -553,7 +556,7 @@ class function_base<inline_target_size, require_inline, Result(Args...)>
|
|
void check_target_type() const {
|
|
if (target_type<Callable>::ops.target_type_id(nullptr, &target_type<Callable>::ops) !=
|
|
base::target_type_id()) {
|
|
- __builtin_abort();
|
|
+ PW_ASSERT(false);
|
|
}
|
|
}
|
|
};
|
|
diff --git a/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/nullable.h b/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/nullable.h
|
|
--- a/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/nullable.h
|
|
+++ b/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/nullable.h
|
|
@@ -11,6 +11,8 @@
|
|
#include <type_traits>
|
|
#include <utility>
|
|
|
|
+#include "pw_assert/assert.h"
|
|
+
|
|
namespace fit {
|
|
|
|
// Determines whether a type can be compared with nullptr.
|
|
@@ -130,28 +132,28 @@ class nullable<T, true> final {
|
|
if (has_value()) {
|
|
return value_;
|
|
} else {
|
|
- __builtin_abort();
|
|
+ PW_ASSERT(false);
|
|
}
|
|
}
|
|
constexpr const T& value() const& {
|
|
if (has_value()) {
|
|
return value_;
|
|
} else {
|
|
- __builtin_abort();
|
|
+ PW_ASSERT(false);
|
|
}
|
|
}
|
|
constexpr T&& value() && {
|
|
if (has_value()) {
|
|
return std::move(value_);
|
|
} else {
|
|
- __builtin_abort();
|
|
+ PW_ASSERT(false);
|
|
}
|
|
}
|
|
constexpr const T&& value() const&& {
|
|
if (has_value()) {
|
|
return std::move(value_);
|
|
} else {
|
|
- __builtin_abort();
|
|
+ PW_ASSERT(false);
|
|
}
|
|
}
|
|
|
|
diff --git a/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/result.h b/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/result.h
|
|
--- a/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/result.h
|
|
+++ b/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/result.h
|
|
@@ -55,6 +55,8 @@
|
|
// // fit::result with a different "success" vluae type (or
|
|
// // fit::result<E>).
|
|
|
|
+#include "pw_assert/assert.h"
|
|
+
|
|
namespace fit {
|
|
|
|
// Convenience type to indicate failure without elaboration.
|
|
@@ -280,25 +282,25 @@ class LIB_FIT_NODISCARD result<E, T> {
|
|
if (is_error()) {
|
|
return storage_.error_or_value.error;
|
|
}
|
|
- __builtin_abort();
|
|
+ PW_ASSERT(false);
|
|
}
|
|
constexpr const E& error_value() const& {
|
|
if (is_error()) {
|
|
return storage_.error_or_value.error;
|
|
}
|
|
- __builtin_abort();
|
|
+ PW_ASSERT(false);
|
|
}
|
|
constexpr E&& error_value() && {
|
|
if (is_error()) {
|
|
return std::move(storage_.error_or_value.error);
|
|
}
|
|
- __builtin_abort();
|
|
+ PW_ASSERT(false);
|
|
}
|
|
constexpr const E&& error_value() const&& {
|
|
if (is_error()) {
|
|
return std::move(storage_.error_or_value.error);
|
|
}
|
|
- __builtin_abort();
|
|
+ PW_ASSERT(false);
|
|
}
|
|
|
|
// Moves the underlying error and returns it as an instance of fit::error, simplifying
|
|
@@ -309,7 +311,7 @@ class LIB_FIT_NODISCARD result<E, T> {
|
|
if (is_error()) {
|
|
return error<E>(std::move(storage_.error_or_value.error));
|
|
}
|
|
- __builtin_abort();
|
|
+ PW_ASSERT(false);
|
|
}
|
|
|
|
// Accessors for the underlying value.
|
|
@@ -319,25 +321,25 @@ class LIB_FIT_NODISCARD result<E, T> {
|
|
if (is_ok()) {
|
|
return storage_.error_or_value.value;
|
|
}
|
|
- __builtin_abort();
|
|
+ PW_ASSERT(false);
|
|
}
|
|
constexpr const T& value() const& {
|
|
if (is_ok()) {
|
|
return storage_.error_or_value.value;
|
|
}
|
|
- __builtin_abort();
|
|
+ PW_ASSERT(false);
|
|
}
|
|
constexpr T&& value() && {
|
|
if (is_ok()) {
|
|
return std::move(storage_.error_or_value.value);
|
|
}
|
|
- __builtin_abort();
|
|
+ PW_ASSERT(false);
|
|
}
|
|
constexpr const T&& value() const&& {
|
|
if (is_ok()) {
|
|
return std::move(storage_.error_or_value.value);
|
|
}
|
|
- __builtin_abort();
|
|
+ PW_ASSERT(false);
|
|
}
|
|
|
|
// Moves the underlying value and returns it as an instance of fit::success, simplifying
|
|
@@ -348,7 +350,7 @@ class LIB_FIT_NODISCARD result<E, T> {
|
|
if (is_ok()) {
|
|
return success<T>(std::move(storage_.error_or_value.value));
|
|
}
|
|
- __builtin_abort();
|
|
+ PW_ASSERT(false);
|
|
}
|
|
|
|
// Contingent accessors for the underlying value.
|
|
@@ -377,13 +379,13 @@ class LIB_FIT_NODISCARD result<E, T> {
|
|
if (is_ok()) {
|
|
return ::fit::internal::arrow_operator<T>::forward(storage_.error_or_value.value);
|
|
}
|
|
- __builtin_abort();
|
|
+ PW_ASSERT(false);
|
|
}
|
|
constexpr decltype(auto) operator->() const {
|
|
if (is_ok()) {
|
|
return ::fit::internal::arrow_operator<T>::forward(storage_.error_or_value.value);
|
|
}
|
|
- __builtin_abort();
|
|
+ PW_ASSERT(false);
|
|
}
|
|
|
|
// Accessors for the underlying value. This is a syntax sugar for value().
|
|
@@ -406,7 +408,7 @@ class LIB_FIT_NODISCARD result<E, T> {
|
|
storage_.error_or_value.error += std::move(error.value_);
|
|
return *this;
|
|
}
|
|
- __builtin_abort();
|
|
+ PW_ASSERT(false);
|
|
}
|
|
|
|
// Maps a result<E, T> to a result<E2, T> by transforming the error through
|
|
@@ -517,25 +519,25 @@ class LIB_FIT_NODISCARD result<E> {
|
|
if (is_error()) {
|
|
return storage_.error_or_value.error;
|
|
}
|
|
- __builtin_abort();
|
|
+ PW_ASSERT(false);
|
|
}
|
|
constexpr const E& error_value() const& {
|
|
if (is_error()) {
|
|
return storage_.error_or_value.error;
|
|
}
|
|
- __builtin_abort();
|
|
+ PW_ASSERT(false);
|
|
}
|
|
constexpr E&& error_value() && {
|
|
if (is_error()) {
|
|
return std::move(storage_.error_or_value.error);
|
|
}
|
|
- __builtin_abort();
|
|
+ PW_ASSERT(false);
|
|
}
|
|
constexpr const E&& error_value() const&& {
|
|
if (is_error()) {
|
|
return std::move(storage_.error_or_value.error);
|
|
}
|
|
- __builtin_abort();
|
|
+ PW_ASSERT(false);
|
|
}
|
|
|
|
// Moves the underlying error and returns it as an instance of fit::error, simplifying
|
|
@@ -546,7 +548,7 @@ class LIB_FIT_NODISCARD result<E> {
|
|
if (is_error()) {
|
|
return error<E>(std::move(storage_.error_or_value.error));
|
|
}
|
|
- __builtin_abort();
|
|
+ PW_ASSERT(false);
|
|
}
|
|
|
|
// Augments the error value of the result with the given value. The operator E::operator+=(F) must
|
|
@@ -560,7 +562,7 @@ class LIB_FIT_NODISCARD result<E> {
|
|
storage_.error_or_value.error += std::move(error.value_);
|
|
return *this;
|
|
}
|
|
- __builtin_abort();
|
|
+ PW_ASSERT(false);
|
|
}
|
|
|
|
// Maps a result<E, T> to a result<E2, T> by transforming the error through
|