summaryrefslogtreecommitdiff
path: root/absl/flags
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2020-07-28 11:13:39 -0700
committerGravatar Mark Barolak <mbar@google.com>2020-07-28 14:37:27 -0400
commitdea76486cb76c7e1032a5efc15b43538b7c5ce50 (patch)
tree4c7b7f6bbd39d399b446fdfd9cb6cb37c44e914a /absl/flags
parentd39fe6cd6f5eb72dc741f17d3a143a6a5a56538a (diff)
Export of internal Abseil changes
-- e1d2e93a3328d9e4362c5510e81bd15ddd0dcf00 by Derek Mauro <dmauro@google.com>: ROLLBACK: Use auto-detected sanitizer attributes for ASAN, MSAN, and TSAN builds PiperOrigin-RevId: 323612219 -- 6fe0914715bcb680ac1dc533aae3461e2ca1ad50 by Derek Mauro <dmauro@google.com>: Use auto-detected sanitizer attributes for ASAN, MSAN, and TSAN builds PiperOrigin-RevId: 323597765 -- 9ad74e277348585f06a511aac31fff917a89a5d7 by Mark Barolak <mbar@google.com>: Import of CCTZ from GitHub. PiperOrigin-RevId: 323594550 -- 9e77ccb5adf7e9867cfa254105930f8fed19699d by Evan Brown <ezb@google.com>: Remove an unnecessary nullptr check in Cord::PrependTree(). We already check for nullptr at all callsites. PiperOrigin-RevId: 323583641 -- 31ab2355c1b91e474b67ff88b8597ad99f346511 by Gennadiy Rozental <rogeeff@google.com>: Avoid memory allocations while registering retired flags. PiperOrigin-RevId: 323523011 -- 33435e9b97b31763a80d3e41b5ab2459e862e99a by Jorg Brown <jorg@google.com>: Allow ABSL_PREDICT_FALSE to be used with a type that's explicitly convertible to bool. So far ABSL_PREDICT_TRUE could be used with these, but not ABSL_PREDICT_FALSE. PiperOrigin-RevId: 323514860 GitOrigin-RevId: e1d2e93a3328d9e4362c5510e81bd15ddd0dcf00 Change-Id: Iee5b030d9aec1ae2c0fe8997763cee7bd84b4090
Diffstat (limited to 'absl/flags')
-rw-r--r--absl/flags/flag.h11
-rw-r--r--absl/flags/flag_test_defs.cc2
-rw-r--r--absl/flags/internal/registry.h17
-rw-r--r--absl/flags/reflection.cc17
4 files changed, 23 insertions, 24 deletions
diff --git a/absl/flags/flag.h b/absl/flags/flag.h
index 90dc2894..e1707252 100644
--- a/absl/flags/flag.h
+++ b/absl/flags/flag.h
@@ -379,11 +379,10 @@ ABSL_NAMESPACE_END
//
// `default_value` is only used as a double check on the type. `explanation` is
// unused.
-// TODO(rogeeff): Return an anonymous struct instead of bool, and place it into
-// the unnamed namespace.
-#define ABSL_RETIRED_FLAG(type, flagname, default_value, explanation) \
- ABSL_ATTRIBUTE_UNUSED static const bool ignored_##flagname = \
- ([] { return type(default_value); }, \
- absl::flags_internal::RetiredFlag<type>(#flagname))
+// TODO(rogeeff): replace RETIRED_FLAGS with FLAGS once forward declarations of
+// retired flags are cleaned up.
+#define ABSL_RETIRED_FLAG(type, name, default_value, explanation) \
+ ABSL_ATTRIBUTE_UNUSED static const absl::flags_internal::RetiredFlag<type> \
+ RETIRED_FLAGS_##name(#name)
#endif // ABSL_FLAGS_FLAG_H_
diff --git a/absl/flags/flag_test_defs.cc b/absl/flags/flag_test_defs.cc
index 49f91dee..3366c580 100644
--- a/absl/flags/flag_test_defs.cc
+++ b/absl/flags/flag_test_defs.cc
@@ -20,5 +20,3 @@
ABSL_FLAG(int, mistyped_int_flag, 0, "");
ABSL_FLAG(std::string, mistyped_string_flag, "", "");
-ABSL_RETIRED_FLAG(bool, old_bool_flag, true,
- "repetition of retired flag definition");
diff --git a/absl/flags/internal/registry.h b/absl/flags/internal/registry.h
index 6f5006a0..5f85ded5 100644
--- a/absl/flags/internal/registry.h
+++ b/absl/flags/internal/registry.h
@@ -74,13 +74,22 @@ bool RegisterCommandLineFlag(CommandLineFlag&);
//
// Retire flag with name "name" and type indicated by ops.
-bool Retire(const char* name, FlagFastTypeId type_id);
+void Retire(const char* name, FlagFastTypeId type_id, char* buf);
+
+constexpr size_t kRetiredFlagObjSize = 3 * sizeof(void*);
+constexpr size_t kRetiredFlagObjAlignment = alignof(void*);
// Registered a retired flag with name 'flag_name' and type 'T'.
template <typename T>
-inline bool RetiredFlag(const char* flag_name) {
- return flags_internal::Retire(flag_name, base_internal::FastTypeId<T>());
-}
+class RetiredFlag {
+ public:
+ explicit RetiredFlag(const char* flag_name) {
+ flags_internal::Retire(flag_name, base_internal::FastTypeId<T>(), buf_);
+ }
+
+ private:
+ alignas(kRetiredFlagObjAlignment) char buf_[kRetiredFlagObjSize];
+};
} // namespace flags_internal
ABSL_NAMESPACE_END
diff --git a/absl/flags/reflection.cc b/absl/flags/reflection.cc
index 1b025835..e4145b34 100644
--- a/absl/flags/reflection.cc
+++ b/absl/flags/reflection.cc
@@ -99,8 +99,6 @@ class FlagRegistryLock {
FlagRegistry& fr_;
};
-void DestroyRetiredFlag(CommandLineFlag& flag);
-
} // namespace
void FlagRegistry::RegisterFlag(CommandLineFlag& flag) {
@@ -125,8 +123,6 @@ void FlagRegistry::RegisterFlag(CommandLineFlag& flag) {
old_flag.Filename(), "' and '", flag.Filename(), "'."),
true);
} else if (old_flag.IsRetired()) {
- // Retired flag can just be deleted.
- DestroyRetiredFlag(flag);
return;
} else if (old_flag.Filename() != flag.Filename()) {
flags_internal::ReportUsageError(
@@ -241,17 +237,14 @@ class RetiredFlagObj final : public CommandLineFlag {
const FlagFastTypeId type_id_;
};
-void DestroyRetiredFlag(CommandLineFlag& flag) {
- assert(flag.IsRetired());
- delete static_cast<RetiredFlagObj*>(&flag);
-}
-
} // namespace
-bool Retire(const char* name, FlagFastTypeId type_id) {
- auto* flag = new flags_internal::RetiredFlagObj(name, type_id);
+void Retire(const char* name, FlagFastTypeId type_id, char* buf) {
+ static_assert(sizeof(RetiredFlagObj) == kRetiredFlagObjSize, "");
+ static_assert(alignof(RetiredFlagObj) == kRetiredFlagObjAlignment, "");
+ auto* flag = ::new (static_cast<void*>(buf))
+ flags_internal::RetiredFlagObj(name, type_id);
FlagRegistry::GlobalRegistry().RegisterFlag(*flag);
- return true;
}
// --------------------------------------------------------------------