From 17a627a413ea34682a9dfec5fec60d7b470269be Mon Sep 17 00:00:00 2001 From: Craig Silverstein Date: Thu, 3 Nov 2011 23:18:00 +0000 Subject: [PATCH] Add a 'flag_ptr' field to CommandLineFlagInfo that points to the current storage of the flag (i.e. &FLAGS_foo). R=csilvers DELTA=15 (15 added, 0 deleted, 0 changed) Revision created by MOE tool push_codebase. MOE_MIGRATION=3301 git-svn-id: https://gflags.googlecode.com/svn/trunk@67 6586e3c6-dcc4-952a-343f-ff74eb82781d --- src/gflags.cc | 2 ++ src/gflags/gflags.h.in | 1 + src/gflags_unittest.cc | 12 ++++++++++++ src/windows/gflags/gflags.h | 1 + 4 files changed, 16 insertions(+) diff --git a/src/gflags.cc b/src/gflags.cc index 9b4d66c..ffb0955 100644 --- a/src/gflags.cc +++ b/src/gflags.cc @@ -497,6 +497,7 @@ class CommandLineFlag { string default_value() const { return defvalue_->ToString(); } const char* type_name() const { return defvalue_->TypeName(); } ValidateFnProto validate_function() const { return validate_fn_proto_; } + const void* flag_ptr() const { return current_->value_buffer_; } void FillCommandLineFlagInfo(struct CommandLineFlagInfo* result); @@ -581,6 +582,7 @@ void CommandLineFlag::FillCommandLineFlagInfo( UpdateModifiedBit(); result->is_default = !modified_; result->has_validator_fn = validate_function() != NULL; + result->flag_ptr = flag_ptr(); } void CommandLineFlag::UpdateModifiedBit() { diff --git a/src/gflags/gflags.h.in b/src/gflags/gflags.h.in index 53a67d5..47bb027 100644 --- a/src/gflags/gflags.h.in +++ b/src/gflags/gflags.h.in @@ -162,6 +162,7 @@ struct GFLAGS_DLL_DECL CommandLineFlagInfo { bool is_default; // true if the flag has the default value and // has not been set explicitly from the cmdline // or via SetCommandLineOption + const void* flag_ptr; // pointer to the flag's current value (i.e. FLAGS_foo) }; // Using this inside of a validator is a recipe for a deadlock. diff --git a/src/gflags_unittest.cc b/src/gflags_unittest.cc index c7cb30d..25bd748 100644 --- a/src/gflags_unittest.cc +++ b/src/gflags_unittest.cc @@ -871,6 +871,7 @@ TEST(GetAllFlagsTest, BaseTest) { found_test_bool = true; EXPECT_EQ(i->type, "bool"); EXPECT_EQ(i->default_value, "false"); + EXPECT_EQ(i->flag_ptr, &FLAGS_test_bool); break; } } @@ -995,6 +996,7 @@ TEST(GetCommandLineFlagInfoTest, FlagExists) { EXPECT_EQ("-1", info.default_value); EXPECT_TRUE(info.is_default); EXPECT_FALSE(info.has_validator_fn); + EXPECT_EQ(&FLAGS_test_int32, info.flag_ptr); r = GetCommandLineFlagInfo("test_str_with_category", &info); EXPECT_TRUE(r); @@ -1006,6 +1008,7 @@ TEST(GetCommandLineFlagInfoTest, FlagExists) { EXPECT_EQ("", info.default_value); EXPECT_TRUE(info.is_default); EXPECT_FALSE(info.has_validator_fn); + EXPECT_EQ(&FLAGS_test_str_with_category, info.flag_ptr); FLAGS_test_bool = true; r = GetCommandLineFlagInfo("test_bool", &info); @@ -1018,6 +1021,7 @@ TEST(GetCommandLineFlagInfoTest, FlagExists) { EXPECT_EQ("false", info.default_value); EXPECT_FALSE(info.is_default); EXPECT_FALSE(info.has_validator_fn); + EXPECT_EQ(&FLAGS_test_bool, info.flag_ptr); FLAGS_test_bool = false; r = GetCommandLineFlagInfo("test_bool", &info); @@ -1030,6 +1034,7 @@ TEST(GetCommandLineFlagInfoTest, FlagExists) { EXPECT_EQ("false", info.default_value); EXPECT_FALSE(info.is_default); // value is same, but flag *was* modified EXPECT_FALSE(info.has_validator_fn); + EXPECT_EQ(&FLAGS_test_bool, info.flag_ptr); } TEST(GetCommandLineFlagInfoTest, FlagDoesNotExist) { @@ -1042,6 +1047,7 @@ TEST(GetCommandLineFlagInfoTest, FlagDoesNotExist) { info.filename = "/"; info.is_default = false; info.has_validator_fn = true; + info.flag_ptr = NULL; bool r = GetCommandLineFlagInfo("test_int3210", &info); EXPECT_FALSE(r); EXPECT_EQ("name", info.name); @@ -1052,6 +1058,7 @@ TEST(GetCommandLineFlagInfoTest, FlagDoesNotExist) { EXPECT_EQ("/", info.filename); EXPECT_FALSE(info.is_default); EXPECT_TRUE(info.has_validator_fn); + EXPECT_EQ(NULL, info.flag_ptr); } TEST(GetCommandLineFlagInfoOrDieTest, FlagExistsAndIsDefault) { @@ -1063,6 +1070,7 @@ TEST(GetCommandLineFlagInfoOrDieTest, FlagExistsAndIsDefault) { EXPECT_EQ("-1", info.current_value); EXPECT_EQ("-1", info.default_value); EXPECT_TRUE(info.is_default); + EXPECT_EQ(&FLAGS_test_int32, info.flag_ptr); info = GetCommandLineFlagInfoOrDie("test_bool"); EXPECT_EQ("test_bool", info.name); EXPECT_EQ("bool", info.type); @@ -1071,6 +1079,7 @@ TEST(GetCommandLineFlagInfoOrDieTest, FlagExistsAndIsDefault) { EXPECT_EQ("false", info.default_value); EXPECT_TRUE(info.is_default); EXPECT_FALSE(info.has_validator_fn); + EXPECT_EQ(&FLAGS_test_bool, info.flag_ptr); } TEST(GetCommandLineFlagInfoOrDieTest, FlagExistsAndWasAssigned) { @@ -1083,6 +1092,7 @@ TEST(GetCommandLineFlagInfoOrDieTest, FlagExistsAndWasAssigned) { EXPECT_EQ("400", info.current_value); EXPECT_EQ("-1", info.default_value); EXPECT_FALSE(info.is_default); + EXPECT_EQ(&FLAGS_test_int32, info.flag_ptr); FLAGS_test_bool = true; info = GetCommandLineFlagInfoOrDie("test_bool"); EXPECT_EQ("test_bool", info.name); @@ -1092,6 +1102,7 @@ TEST(GetCommandLineFlagInfoOrDieTest, FlagExistsAndWasAssigned) { EXPECT_EQ("false", info.default_value); EXPECT_FALSE(info.is_default); EXPECT_FALSE(info.has_validator_fn); + EXPECT_EQ(&FLAGS_test_bool, info.flag_ptr); } #ifdef GTEST_HAS_DEATH_TEST @@ -1357,6 +1368,7 @@ TEST(ParseCommandLineFlagsWrongFields, CommandLineFlagInfo fi; EXPECT_TRUE(GetCommandLineFlagInfo("flag_name", &fi)); EXPECT_EQ("", fi.description); + EXPECT_EQ(¤t_storage, fi.flag_ptr); } static bool ValidateTestFlagIs5(const char* flagname, int32 flagval) { diff --git a/src/windows/gflags/gflags.h b/src/windows/gflags/gflags.h index 3a64127..337f3dc 100644 --- a/src/windows/gflags/gflags.h +++ b/src/windows/gflags/gflags.h @@ -166,6 +166,7 @@ struct GFLAGS_DLL_DECL CommandLineFlagInfo { bool is_default; // true if the flag has the default value and // has not been set explicitly from the cmdline // or via SetCommandLineOption + const void* flag_ptr; // pointer to the flag's current value (i.e. FLAGS_foo) }; // Using this inside of a validator is a recipe for a deadlock.