diff options
author | Abseil Team <absl-team@google.com> | 2021-01-12 07:36:20 -0800 |
---|---|---|
committer | Andy Getz <durandal@google.com> | 2021-01-12 11:57:11 -0500 |
commit | 322ae2420d27fc96d0a8ab1167d7de33671048df (patch) | |
tree | e00368177de976612408e0d995ff352fac200a0d /absl/flags | |
parent | 62ce712ecc887f669610a93efe18abecf70b47a0 (diff) |
Export of internal Abseil changes
--
1609589925459c2c0b2a17912c0d65227f709db9 by Abseil Team <absl-team@google.com>:
Clarify the "Potential Mutex deadlock" reason message.
PiperOrigin-RevId: 351367862
--
88bf28863db2c2d2d48767c3e4dfab6a48bdff79 by Abseil Team <absl-team@google.com>:
Print CPU number is fault handler.
This CL adds code to print CPU number inside the fault handler. This is only supported on Linux. The CPU number is also a hint only. There is no guarantee that it is indeed the CPU on which a fault happened.
PiperOrigin-RevId: 351238373
--
66a9c8e44b5744fec1ca0d7b8db7e1d50772d9a2 by Samuel Benzaquen <sbenza@google.com>:
Add better error message for ODR violations of flags.
PiperOrigin-RevId: 351197423
--
6efd1efb341563148dd43255aaa4bf959dfd9554 by Chris Kennelly <ckennelly@google.com>:
Assume bitwise builtins are available on GCC.
These are long-standing builtins but are not consistently detected by
ABSL_HAVE_BUILTIN.
PiperOrigin-RevId: 350814036
GitOrigin-RevId: 1609589925459c2c0b2a17912c0d65227f709db9
Change-Id: Ied3fd2f135187f2c316b403fba45f3bbaea54138
Diffstat (limited to 'absl/flags')
-rw-r--r-- | absl/flags/flag.h | 10 | ||||
-rw-r--r-- | absl/flags/flag_test.cc | 2 | ||||
-rw-r--r-- | absl/flags/internal/flag.h | 5 | ||||
-rw-r--r-- | absl/flags/internal/registry.h | 2 | ||||
-rw-r--r-- | absl/flags/reflection.cc | 23 |
5 files changed, 29 insertions, 13 deletions
diff --git a/absl/flags/flag.h b/absl/flags/flag.h index a9cb2b79..f09580b0 100644 --- a/absl/flags/flag.h +++ b/absl/flags/flag.h @@ -301,13 +301,15 @@ ABSL_NAMESPACE_END #if ABSL_FLAGS_STRIP_NAMES #define ABSL_FLAG_IMPL_FLAGNAME(txt) "" #define ABSL_FLAG_IMPL_FILENAME() "" -#define ABSL_FLAG_IMPL_REGISTRAR(T, flag) \ - absl::flags_internal::FlagRegistrar<T, false>(ABSL_FLAG_IMPL_FLAG_PTR(flag)) +#define ABSL_FLAG_IMPL_REGISTRAR(T, flag) \ + absl::flags_internal::FlagRegistrar<T, false>(ABSL_FLAG_IMPL_FLAG_PTR(flag), \ + nullptr) #else #define ABSL_FLAG_IMPL_FLAGNAME(txt) txt #define ABSL_FLAG_IMPL_FILENAME() __FILE__ -#define ABSL_FLAG_IMPL_REGISTRAR(T, flag) \ - absl::flags_internal::FlagRegistrar<T, true>(ABSL_FLAG_IMPL_FLAG_PTR(flag)) +#define ABSL_FLAG_IMPL_REGISTRAR(T, flag) \ + absl::flags_internal::FlagRegistrar<T, true>(ABSL_FLAG_IMPL_FLAG_PTR(flag), \ + __FILE__) #endif // ABSL_FLAG_IMPL macro definition conditional on ABSL_FLAGS_STRIP_HELP diff --git a/absl/flags/flag_test.cc b/absl/flags/flag_test.cc index 72507b99..6912b546 100644 --- a/absl/flags/flag_test.cc +++ b/absl/flags/flag_test.cc @@ -177,7 +177,7 @@ bool TestConstructionFor(const absl::Flag<T>& f1, absl::Flag<T>& f2) { EXPECT_EQ(absl::GetFlagReflectionHandle(f1).Help(), "literal help"); EXPECT_EQ(absl::GetFlagReflectionHandle(f1).Filename(), "file"); - flags::FlagRegistrar<T, false>(ABSL_FLAG_IMPL_FLAG_PTR(f2)) + flags::FlagRegistrar<T, false>(ABSL_FLAG_IMPL_FLAG_PTR(f2), nullptr) .OnUpdate(TestCallback); EXPECT_EQ(absl::GetFlagReflectionHandle(f2).Name(), "f2"); diff --git a/absl/flags/internal/flag.h b/absl/flags/internal/flag.h index 83548143..e6bade0a 100644 --- a/absl/flags/internal/flag.h +++ b/absl/flags/internal/flag.h @@ -721,8 +721,9 @@ struct FlagRegistrarEmpty {}; template <typename T, bool do_register> class FlagRegistrar { public: - explicit FlagRegistrar(Flag<T>& flag) : flag_(flag) { - if (do_register) flags_internal::RegisterCommandLineFlag(flag_.impl_); + explicit FlagRegistrar(Flag<T>& flag, const char* filename) : flag_(flag) { + if (do_register) + flags_internal::RegisterCommandLineFlag(flag_.impl_, filename); } FlagRegistrar OnUpdate(FlagCallbackFunc cb) && { diff --git a/absl/flags/internal/registry.h b/absl/flags/internal/registry.h index a8d9eb9c..4b68c85f 100644 --- a/absl/flags/internal/registry.h +++ b/absl/flags/internal/registry.h @@ -36,7 +36,7 @@ void ForEachFlag(std::function<void(CommandLineFlag&)> visitor); //----------------------------------------------------------------------------- -bool RegisterCommandLineFlag(CommandLineFlag&); +bool RegisterCommandLineFlag(CommandLineFlag&, const char* filename); void FinalizeRegistry(); diff --git a/absl/flags/reflection.cc b/absl/flags/reflection.cc index c976d467..0c761101 100644 --- a/absl/flags/reflection.cc +++ b/absl/flags/reflection.cc @@ -50,7 +50,7 @@ class FlagRegistry { ~FlagRegistry() = default; // Store a flag in this registry. Takes ownership of *flag. - void RegisterFlag(CommandLineFlag& flag); + void RegisterFlag(CommandLineFlag& flag, const char* filename); void Lock() ABSL_EXCLUSIVE_LOCK_FUNCTION(lock_) { lock_.Lock(); } void Unlock() ABSL_UNLOCK_FUNCTION(lock_) { lock_.Unlock(); } @@ -110,7 +110,20 @@ CommandLineFlag* FlagRegistry::FindFlag(absl::string_view name) { return it != flags_.end() ? it->second : nullptr; } -void FlagRegistry::RegisterFlag(CommandLineFlag& flag) { +void FlagRegistry::RegisterFlag(CommandLineFlag& flag, const char* filename) { + if (filename != nullptr && + flag.Filename() != GetUsageConfig().normalize_filename(filename)) { + flags_internal::ReportUsageError( + absl::StrCat( + "Inconsistency between flag object and registration for flag '", + flag.Name(), + "', likely due to duplicate flags or an ODR violation. Relevant " + "files: ", + flag.Filename(), " and ", filename), + true); + std::exit(1); + } + FlagRegistryLock registry_lock(*this); std::pair<FlagIterator, bool> ins = @@ -175,8 +188,8 @@ void ForEachFlag(std::function<void(CommandLineFlag&)> visitor) { // -------------------------------------------------------------------- -bool RegisterCommandLineFlag(CommandLineFlag& flag) { - FlagRegistry::GlobalRegistry().RegisterFlag(flag); +bool RegisterCommandLineFlag(CommandLineFlag& flag, const char* filename) { + FlagRegistry::GlobalRegistry().RegisterFlag(flag, filename); return true; } @@ -266,7 +279,7 @@ void Retire(const char* name, FlagFastTypeId type_id, char* buf) { static_assert(alignof(RetiredFlagObj) == kRetiredFlagObjAlignment, ""); auto* flag = ::new (static_cast<void*>(buf)) flags_internal::RetiredFlagObj(name, type_id); - FlagRegistry::GlobalRegistry().RegisterFlag(*flag); + FlagRegistry::GlobalRegistry().RegisterFlag(*flag, nullptr); } // -------------------------------------------------------------------- |