summaryrefslogtreecommitdiff
path: root/absl
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2021-02-17 09:48:49 -0800
committerGravatar Andy Getz <durandal@google.com>2021-02-18 02:38:12 -0500
commitb315753c0b8b4aa4e3e1479375eddb518393bab6 (patch)
tree07255ad54a6555677f3b54f2b0c7bcec9c320be5 /absl
parent143a27800eb35f4568b9be51647726281916aac9 (diff)
Export of internal Abseil changes
-- 2247e59ee5696e61c7cb24dce479db572980032d by Derek Mauro <dmauro@google.com>: Ensure ThreadIdentity::WaiterState data has the correct alignment PiperOrigin-RevId: 357969866 -- 79bb81a2e6723b186536ad4b4f25cd7ee83f3e72 by Laramie Leavitt <lar@google.com>: Rework absl::MockingBitGen internal mock registry. Use a virtual base class with template-specialized derived classes to implement match method rather than taking the address of a function specialization and using casts everywhere. This combines several of the previously type-erased pointers into a single object, eliminates the separate cleanup container previously used, and eliminates some gratuitous static_cast<>s. PiperOrigin-RevId: 357827438 -- a2eb53d002c9b376360a70b2b0f6a18a1de1e16f by Todd Lipcon <tlipcon@google.com>: Reduce runtime of sequence_lock_test PiperOrigin-RevId: 357785571 -- dd1175ff13b560f01c4aaa64bc6759a5300e391c by Abseil Team <absl-team@google.com>: Don't assume that compiling for Windows means that MSVC or clang-cl is being used. PiperOrigin-RevId: 357760052 -- 251a9cbede52e729b3a25911b6e225b779c285a8 by Andy Getzendanner <durandal@google.com>: Internal change. PiperOrigin-RevId: 357702979 GitOrigin-RevId: 2247e59ee5696e61c7cb24dce479db572980032d Change-Id: Icd366d3775d88d623695209b5f328dbd69f01d27
Diffstat (limited to 'absl')
-rw-r--r--absl/BUILD.bazel25
-rw-r--r--absl/base/BUILD.bazel8
-rw-r--r--absl/base/config.h2
-rw-r--r--absl/base/internal/thread_identity.h2
-rw-r--r--absl/copts/configure_copts.bzl8
-rw-r--r--absl/debugging/BUILD.bazel12
-rw-r--r--absl/flags/BUILD.bazel2
-rw-r--r--absl/flags/internal/sequence_lock_test.cc16
-rw-r--r--absl/random/internal/BUILD.bazel9
-rw-r--r--absl/random/mocking_bit_gen.h87
-rw-r--r--absl/synchronization/BUILD.bazel3
11 files changed, 105 insertions, 69 deletions
diff --git a/absl/BUILD.bazel b/absl/BUILD.bazel
index 6da20c49..c9d4a2da 100644
--- a/absl/BUILD.bazel
+++ b/absl/BUILD.bazel
@@ -26,6 +26,22 @@ config_setting(
)
config_setting(
+ name = "msvc_compiler",
+ flag_values = {
+ "@bazel_tools//tools/cpp:compiler": "msvc-cl",
+ },
+ visibility = [":__subpackages__"],
+)
+
+config_setting(
+ name = "clang-cl_compiler",
+ flag_values = {
+ "@bazel_tools//tools/cpp:compiler": "clang-cl",
+ },
+ visibility = [":__subpackages__"],
+)
+
+config_setting(
name = "osx",
constraint_values = [
"@bazel_tools//platforms:osx",
@@ -40,15 +56,6 @@ config_setting(
)
config_setting(
- name = "windows",
- constraint_values = [
- "@bazel_tools//platforms:x86_64",
- "@bazel_tools//platforms:windows",
- ],
- visibility = [":__subpackages__"],
-)
-
-config_setting(
name = "ppc",
values = {
"cpu": "ppc",
diff --git a/absl/base/BUILD.bazel b/absl/base/BUILD.bazel
index 7d2ff308..65ff0dde 100644
--- a/absl/base/BUILD.bazel
+++ b/absl/base/BUILD.bazel
@@ -160,7 +160,8 @@ cc_library(
],
copts = ABSL_DEFAULT_COPTS,
linkopts = select({
- "//absl:windows": [],
+ "//absl:msvc_compiler": [],
+ "//absl:clang-cl_compiler": [],
"//absl:wasm": [],
"//conditions:default": ["-pthread"],
}) + ABSL_DEFAULT_LINKOPTS,
@@ -220,7 +221,10 @@ cc_library(
],
copts = ABSL_DEFAULT_COPTS,
linkopts = select({
- "//absl:windows": [
+ "//absl:msvc_compiler": [
+ "-DEFAULTLIB:advapi32.lib",
+ ],
+ "//absl:clang-cl_compiler": [
"-DEFAULTLIB:advapi32.lib",
],
"//absl:wasm": [],
diff --git a/absl/base/config.h b/absl/base/config.h
index 3d6aa178..444330d3 100644
--- a/absl/base/config.h
+++ b/absl/base/config.h
@@ -216,6 +216,8 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
#if ABSL_INTERNAL_HAS_KEYWORD(__builtin_LINE) && \
ABSL_INTERNAL_HAS_KEYWORD(__builtin_FILE)
#define ABSL_HAVE_SOURCE_LOCATION_CURRENT 1
+#elif defined(__GNUC__) && __GNUC__ >= 5
+#define ABSL_HAVE_SOURCE_LOCATION_CURRENT 1
#endif
#endif
diff --git a/absl/base/internal/thread_identity.h b/absl/base/internal/thread_identity.h
index d2a65fd8..9ee651a3 100644
--- a/absl/base/internal/thread_identity.h
+++ b/absl/base/internal/thread_identity.h
@@ -143,7 +143,7 @@ struct ThreadIdentity {
// Private: Reserved for absl::synchronization_internal::Waiter.
struct WaiterState {
- char data[128];
+ alignas(void*) char data[128];
} waiter_state;
// Used by PerThreadSem::{Get,Set}ThreadBlockedCounter().
diff --git a/absl/copts/configure_copts.bzl b/absl/copts/configure_copts.bzl
index 4d342544..669a9060 100644
--- a/absl/copts/configure_copts.bzl
+++ b/absl/copts/configure_copts.bzl
@@ -22,19 +22,21 @@ load(
)
ABSL_DEFAULT_COPTS = select({
- "//absl:windows": ABSL_MSVC_FLAGS,
+ "//absl:msvc_compiler": ABSL_MSVC_FLAGS,
+ "//absl:clang-cl_compiler": ABSL_CLANG_CL_FLAGS,
"//absl:clang_compiler": ABSL_LLVM_FLAGS,
"//conditions:default": ABSL_GCC_FLAGS,
})
ABSL_TEST_COPTS = ABSL_DEFAULT_COPTS + select({
- "//absl:windows": ABSL_MSVC_TEST_FLAGS,
+ "//absl:msvc_compiler": ABSL_MSVC_TEST_FLAGS,
+ "//absl:clang-cl_compiler": ABSL_CLANG_CL_TEST_FLAGS,
"//absl:clang_compiler": ABSL_LLVM_TEST_FLAGS,
"//conditions:default": ABSL_GCC_TEST_FLAGS,
})
ABSL_DEFAULT_LINKOPTS = select({
- "//absl:windows": ABSL_MSVC_LINKOPTS,
+ "//absl:msvc_compiler": ABSL_MSVC_LINKOPTS,
"//conditions:default": [],
})
diff --git a/absl/debugging/BUILD.bazel b/absl/debugging/BUILD.bazel
index cd6e4543..e7fd1152 100644
--- a/absl/debugging/BUILD.bazel
+++ b/absl/debugging/BUILD.bazel
@@ -66,7 +66,8 @@ cc_library(
],
copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS + select({
- "//absl:windows": ["-DEFAULTLIB:dbghelp.lib"],
+ "//absl:msvc_compiler": ["-DEFAULTLIB:dbghelp.lib"],
+ "//absl:clang-cl_compiler": ["-DEFAULTLIB:dbghelp.lib"],
"//conditions:default": [],
}),
deps = [
@@ -86,11 +87,13 @@ cc_test(
name = "symbolize_test",
srcs = ["symbolize_test.cc"],
copts = ABSL_TEST_COPTS + select({
- "//absl:windows": ["/Z7"],
+ "//absl:msvc_compiler": ["/Z7"],
+ "//absl:clang-cl_compiler": ["/Z7"],
"//conditions:default": [],
}),
linkopts = ABSL_DEFAULT_LINKOPTS + select({
- "//absl:windows": ["/DEBUG"],
+ "//absl:msvc_compiler": ["/DEBUG"],
+ "//absl:clang-cl_compiler": ["/DEBUG"],
"//conditions:default": [],
}),
deps = [
@@ -148,7 +151,8 @@ cc_test(
srcs = ["failure_signal_handler_test.cc"],
copts = ABSL_TEST_COPTS,
linkopts = select({
- "//absl:windows": [],
+ "//absl:msvc_compiler": [],
+ "//absl:clang-cl_compiler": [],
"//absl:wasm": [],
"//conditions:default": ["-pthread"],
}) + ABSL_DEFAULT_LINKOPTS,
diff --git a/absl/flags/BUILD.bazel b/absl/flags/BUILD.bazel
index 1937609a..147249ed 100644
--- a/absl/flags/BUILD.bazel
+++ b/absl/flags/BUILD.bazel
@@ -488,7 +488,7 @@ cc_test(
],
copts = ABSL_TEST_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
- shard_count = 32,
+ shard_count = 31,
deps = [
":flag_internal",
"//absl/base",
diff --git a/absl/flags/internal/sequence_lock_test.cc b/absl/flags/internal/sequence_lock_test.cc
index ff8b476b..c3ec372e 100644
--- a/absl/flags/internal/sequence_lock_test.cc
+++ b/absl/flags/internal/sequence_lock_test.cc
@@ -121,11 +121,25 @@ const int kMaxThreads = absl::base_internal::NumCPUs();
const int kMaxThreads = std::min(absl::base_internal::NumCPUs(), 4);
#endif
+// Return all of the interesting buffer sizes worth testing:
+// powers of two and adjacent values.
+std::vector<int> InterestingBufferSizes() {
+ std::vector<int> ret;
+ for (int v : MultiplicativeRange(1, 128, 2)) {
+ ret.push_back(v);
+ if (v > 1) {
+ ret.push_back(v - 1);
+ }
+ ret.push_back(v + 1);
+ }
+ return ret;
+}
+
INSTANTIATE_TEST_SUITE_P(
TestManyByteSizes, ConcurrentSequenceLockTest,
testing::Combine(
// Buffer size (bytes).
- testing::Range(1, 128),
+ testing::ValuesIn(InterestingBufferSizes()),
// Number of reader threads.
testing::ValuesIn(MultiplicativeRange(1, kMaxThreads, 2))));
diff --git a/absl/random/internal/BUILD.bazel b/absl/random/internal/BUILD.bazel
index 4e778aee..612b1505 100644
--- a/absl/random/internal/BUILD.bazel
+++ b/absl/random/internal/BUILD.bazel
@@ -75,7 +75,8 @@ cc_library(
],
copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS + select({
- "//absl:windows": ["-DEFAULTLIB:bcrypt.lib"],
+ "//absl:msvc_compiler": ["-DEFAULTLIB:bcrypt.lib"],
+ "//absl:clang-cl_compiler": ["-DEFAULTLIB:bcrypt.lib"],
"//conditions:default": [],
}),
deps = [
@@ -98,7 +99,8 @@ cc_library(
],
copts = ABSL_DEFAULT_COPTS,
linkopts = select({
- "//absl:windows": [],
+ "//absl:msvc_compiler": [],
+ "//absl:clang-cl_compiler": [],
"//absl:wasm": [],
"//conditions:default": ["-pthread"],
}) + ABSL_DEFAULT_LINKOPTS,
@@ -325,7 +327,8 @@ cc_library(
"randen_hwaes.h",
],
copts = ABSL_DEFAULT_COPTS + ABSL_RANDOM_RANDEN_COPTS + select({
- "//absl:windows": [],
+ "//absl:msvc_compiler": [],
+ "//absl:clang-cl_compiler": [],
"//conditions:default": ["-Wno-pass-failed"],
}),
linkopts = ABSL_DEFAULT_LINKOPTS,
diff --git a/absl/random/mocking_bit_gen.h b/absl/random/mocking_bit_gen.h
index 6d2f2c83..6815ca44 100644
--- a/absl/random/mocking_bit_gen.h
+++ b/absl/random/mocking_bit_gen.h
@@ -104,10 +104,7 @@ class BitGenRef;
class MockingBitGen {
public:
MockingBitGen() = default;
-
- ~MockingBitGen() {
- for (const auto& del : deleters_) del();
- }
+ ~MockingBitGen() = default;
// URBG interface
using result_type = absl::BitGen::result_type;
@@ -117,14 +114,6 @@ class MockingBitGen {
result_type operator()() { return gen_(); }
private:
- using match_impl_fn = void (*)(void* mock_fn, void* t_erased_arg_tuple,
- void* t_erased_result);
-
- struct MockData {
- void* mock_fn = nullptr;
- match_impl_fn match_impl = nullptr;
- };
-
// GetMockFnType returns the testing::MockFunction for a result and tuple.
// This method only exists for type deduction and is otherwise unimplemented.
template <typename ResultT, typename... Args>
@@ -136,17 +125,46 @@ class MockingBitGen {
// NOTE: MockFnCaller is essentially equivalent to the lambda:
// [fn](auto... args) { return fn->Call(std::move(args)...)}
// however that fails to build on some supported platforms.
- template <typename ResultT, typename MockFnType, typename Tuple>
+ template <typename MockFnType, typename ResultT, typename Tuple>
struct MockFnCaller;
+
// specialization for std::tuple.
- template <typename ResultT, typename MockFnType, typename... Args>
- struct MockFnCaller<ResultT, MockFnType, std::tuple<Args...>> {
+ template <typename MockFnType, typename ResultT, typename... Args>
+ struct MockFnCaller<MockFnType, ResultT, std::tuple<Args...>> {
MockFnType* fn;
inline ResultT operator()(Args... args) {
return fn->Call(std::move(args)...);
}
};
+ // FunctionHolder owns a particular ::testing::MockFunction associated with
+ // a mocked type signature, and implement the type-erased Apply call, which
+ // applies type-erased arguments to the mock.
+ class FunctionHolder {
+ public:
+ virtual ~FunctionHolder() = default;
+
+ // Call is a dispatch function which converts the
+ // generic type-erased parameters into a specific mock invocation call.
+ virtual void Apply(/*ArgTupleT*/ void* args_tuple,
+ /*ResultT*/ void* result) = 0;
+ };
+
+ template <typename MockFnType, typename ResultT, typename ArgTupleT>
+ class FunctionHolderImpl final : public FunctionHolder {
+ public:
+ void Apply(void* args_tuple, void* result) override {
+ // Requires tuple_args to point to a ArgTupleT, which is a
+ // std::tuple<Args...> used to invoke the mock function. Requires result
+ // to point to a ResultT, which is the result of the call.
+ *static_cast<ResultT*>(result) =
+ absl::apply(MockFnCaller<MockFnType, ResultT, ArgTupleT>{&mock_fn_},
+ *static_cast<ArgTupleT*>(args_tuple));
+ }
+
+ MockFnType mock_fn_;
+ };
+
// MockingBitGen::RegisterMock
//
// RegisterMock<ResultT, ArgTupleT>(FastTypeIdType) is the main extension
@@ -161,33 +179,14 @@ class MockingBitGen {
auto RegisterMock(base_internal::FastTypeIdType type)
-> decltype(GetMockFnType(std::declval<ResultT>(),
std::declval<ArgTupleT>()))& {
- using MockFnType = decltype(
- GetMockFnType(std::declval<ResultT>(), std::declval<ArgTupleT>()));
+ using MockFnType = decltype(GetMockFnType(std::declval<ResultT>(),
+ std::declval<ArgTupleT>()));
+ using ImplT = FunctionHolderImpl<MockFnType, ResultT, ArgTupleT>;
auto& mock = mocks_[type];
- if (!mock.mock_fn) {
- auto* mock_fn = new MockFnType;
- mock.mock_fn = mock_fn;
- mock.match_impl = &MatchImpl<ResultT, ArgTupleT>;
- deleters_.emplace_back([mock_fn] { delete mock_fn; });
+ if (!mock) {
+ mock = absl::make_unique<ImplT>();
}
- return *static_cast<MockFnType*>(mock.mock_fn);
- }
-
- // MockingBitGen::MatchImpl<> is a dispatch function which converts the
- // generic type-erased parameters into a specific mock invocation call.
- // Requires tuple_args to point to a ArgTupleT, which is a std::tuple<Args...>
- // used to invoke the mock function.
- // Requires result to point to a ResultT, which is the result of the call.
- template <typename ResultT, typename ArgTupleT>
- static void MatchImpl(/*MockFnType<ResultT, Args...>*/ void* mock_fn,
- /*ArgTupleT*/ void* args_tuple,
- /*ResultT*/ void* result) {
- using MockFnType = decltype(
- GetMockFnType(std::declval<ResultT>(), std::declval<ArgTupleT>()));
- *static_cast<ResultT*>(result) = absl::apply(
- MockFnCaller<ResultT, MockFnType, ArgTupleT>{
- static_cast<MockFnType*>(mock_fn)},
- *static_cast<ArgTupleT*>(args_tuple));
+ return static_cast<ImplT*>(mock.get())->mock_fn_;
}
// MockingBitGen::InvokeMock
@@ -206,13 +205,13 @@ class MockingBitGen {
// Trigger a mock, if there exists one that matches `param`.
auto it = mocks_.find(type);
if (it == mocks_.end()) return false;
- auto* mock_data = static_cast<MockData*>(&it->second);
- mock_data->match_impl(mock_data->mock_fn, args_tuple, result);
+ it->second->Apply(args_tuple, result);
return true;
}
- absl::flat_hash_map<base_internal::FastTypeIdType, MockData> mocks_;
- std::vector<std::function<void()>> deleters_;
+ absl::flat_hash_map<base_internal::FastTypeIdType,
+ std::unique_ptr<FunctionHolder>>
+ mocks_;
absl::BitGen gen_;
template <typename>
diff --git a/absl/synchronization/BUILD.bazel b/absl/synchronization/BUILD.bazel
index cd4009a1..5ce16958 100644
--- a/absl/synchronization/BUILD.bazel
+++ b/absl/synchronization/BUILD.bazel
@@ -88,7 +88,8 @@ cc_library(
],
copts = ABSL_DEFAULT_COPTS,
linkopts = select({
- "//absl:windows": [],
+ "//absl:msvc_compiler": [],
+ "//absl:clang-cl_compiler": [],
"//absl:wasm": [],
"//conditions:default": ["-pthread"],
}) + ABSL_DEFAULT_LINKOPTS,