Commit 17a627a4 authored by Craig Silverstein's avatar Craig Silverstein

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
parent ee441911
...@@ -497,6 +497,7 @@ class CommandLineFlag { ...@@ -497,6 +497,7 @@ class CommandLineFlag {
string default_value() const { return defvalue_->ToString(); } string default_value() const { return defvalue_->ToString(); }
const char* type_name() const { return defvalue_->TypeName(); } const char* type_name() const { return defvalue_->TypeName(); }
ValidateFnProto validate_function() const { return validate_fn_proto_; } ValidateFnProto validate_function() const { return validate_fn_proto_; }
const void* flag_ptr() const { return current_->value_buffer_; }
void FillCommandLineFlagInfo(struct CommandLineFlagInfo* result); void FillCommandLineFlagInfo(struct CommandLineFlagInfo* result);
...@@ -581,6 +582,7 @@ void CommandLineFlag::FillCommandLineFlagInfo( ...@@ -581,6 +582,7 @@ void CommandLineFlag::FillCommandLineFlagInfo(
UpdateModifiedBit(); UpdateModifiedBit();
result->is_default = !modified_; result->is_default = !modified_;
result->has_validator_fn = validate_function() != NULL; result->has_validator_fn = validate_function() != NULL;
result->flag_ptr = flag_ptr();
} }
void CommandLineFlag::UpdateModifiedBit() { void CommandLineFlag::UpdateModifiedBit() {
......
...@@ -162,6 +162,7 @@ struct GFLAGS_DLL_DECL CommandLineFlagInfo { ...@@ -162,6 +162,7 @@ struct GFLAGS_DLL_DECL CommandLineFlagInfo {
bool is_default; // true if the flag has the default value and bool is_default; // true if the flag has the default value and
// has not been set explicitly from the cmdline // has not been set explicitly from the cmdline
// or via SetCommandLineOption // 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. // Using this inside of a validator is a recipe for a deadlock.
......
...@@ -871,6 +871,7 @@ TEST(GetAllFlagsTest, BaseTest) { ...@@ -871,6 +871,7 @@ TEST(GetAllFlagsTest, BaseTest) {
found_test_bool = true; found_test_bool = true;
EXPECT_EQ(i->type, "bool"); EXPECT_EQ(i->type, "bool");
EXPECT_EQ(i->default_value, "false"); EXPECT_EQ(i->default_value, "false");
EXPECT_EQ(i->flag_ptr, &FLAGS_test_bool);
break; break;
} }
} }
...@@ -995,6 +996,7 @@ TEST(GetCommandLineFlagInfoTest, FlagExists) { ...@@ -995,6 +996,7 @@ TEST(GetCommandLineFlagInfoTest, FlagExists) {
EXPECT_EQ("-1", info.default_value); EXPECT_EQ("-1", info.default_value);
EXPECT_TRUE(info.is_default); EXPECT_TRUE(info.is_default);
EXPECT_FALSE(info.has_validator_fn); EXPECT_FALSE(info.has_validator_fn);
EXPECT_EQ(&FLAGS_test_int32, info.flag_ptr);
r = GetCommandLineFlagInfo("test_str_with_category", &info); r = GetCommandLineFlagInfo("test_str_with_category", &info);
EXPECT_TRUE(r); EXPECT_TRUE(r);
...@@ -1006,6 +1008,7 @@ TEST(GetCommandLineFlagInfoTest, FlagExists) { ...@@ -1006,6 +1008,7 @@ TEST(GetCommandLineFlagInfoTest, FlagExists) {
EXPECT_EQ("", info.default_value); EXPECT_EQ("", info.default_value);
EXPECT_TRUE(info.is_default); EXPECT_TRUE(info.is_default);
EXPECT_FALSE(info.has_validator_fn); EXPECT_FALSE(info.has_validator_fn);
EXPECT_EQ(&FLAGS_test_str_with_category, info.flag_ptr);
FLAGS_test_bool = true; FLAGS_test_bool = true;
r = GetCommandLineFlagInfo("test_bool", &info); r = GetCommandLineFlagInfo("test_bool", &info);
...@@ -1018,6 +1021,7 @@ TEST(GetCommandLineFlagInfoTest, FlagExists) { ...@@ -1018,6 +1021,7 @@ TEST(GetCommandLineFlagInfoTest, FlagExists) {
EXPECT_EQ("false", info.default_value); EXPECT_EQ("false", info.default_value);
EXPECT_FALSE(info.is_default); EXPECT_FALSE(info.is_default);
EXPECT_FALSE(info.has_validator_fn); EXPECT_FALSE(info.has_validator_fn);
EXPECT_EQ(&FLAGS_test_bool, info.flag_ptr);
FLAGS_test_bool = false; FLAGS_test_bool = false;
r = GetCommandLineFlagInfo("test_bool", &info); r = GetCommandLineFlagInfo("test_bool", &info);
...@@ -1030,6 +1034,7 @@ TEST(GetCommandLineFlagInfoTest, FlagExists) { ...@@ -1030,6 +1034,7 @@ TEST(GetCommandLineFlagInfoTest, FlagExists) {
EXPECT_EQ("false", info.default_value); EXPECT_EQ("false", info.default_value);
EXPECT_FALSE(info.is_default); // value is same, but flag *was* modified EXPECT_FALSE(info.is_default); // value is same, but flag *was* modified
EXPECT_FALSE(info.has_validator_fn); EXPECT_FALSE(info.has_validator_fn);
EXPECT_EQ(&FLAGS_test_bool, info.flag_ptr);
} }
TEST(GetCommandLineFlagInfoTest, FlagDoesNotExist) { TEST(GetCommandLineFlagInfoTest, FlagDoesNotExist) {
...@@ -1042,6 +1047,7 @@ TEST(GetCommandLineFlagInfoTest, FlagDoesNotExist) { ...@@ -1042,6 +1047,7 @@ TEST(GetCommandLineFlagInfoTest, FlagDoesNotExist) {
info.filename = "/"; info.filename = "/";
info.is_default = false; info.is_default = false;
info.has_validator_fn = true; info.has_validator_fn = true;
info.flag_ptr = NULL;
bool r = GetCommandLineFlagInfo("test_int3210", &info); bool r = GetCommandLineFlagInfo("test_int3210", &info);
EXPECT_FALSE(r); EXPECT_FALSE(r);
EXPECT_EQ("name", info.name); EXPECT_EQ("name", info.name);
...@@ -1052,6 +1058,7 @@ TEST(GetCommandLineFlagInfoTest, FlagDoesNotExist) { ...@@ -1052,6 +1058,7 @@ TEST(GetCommandLineFlagInfoTest, FlagDoesNotExist) {
EXPECT_EQ("/", info.filename); EXPECT_EQ("/", info.filename);
EXPECT_FALSE(info.is_default); EXPECT_FALSE(info.is_default);
EXPECT_TRUE(info.has_validator_fn); EXPECT_TRUE(info.has_validator_fn);
EXPECT_EQ(NULL, info.flag_ptr);
} }
TEST(GetCommandLineFlagInfoOrDieTest, FlagExistsAndIsDefault) { TEST(GetCommandLineFlagInfoOrDieTest, FlagExistsAndIsDefault) {
...@@ -1063,6 +1070,7 @@ TEST(GetCommandLineFlagInfoOrDieTest, FlagExistsAndIsDefault) { ...@@ -1063,6 +1070,7 @@ TEST(GetCommandLineFlagInfoOrDieTest, FlagExistsAndIsDefault) {
EXPECT_EQ("-1", info.current_value); EXPECT_EQ("-1", info.current_value);
EXPECT_EQ("-1", info.default_value); EXPECT_EQ("-1", info.default_value);
EXPECT_TRUE(info.is_default); EXPECT_TRUE(info.is_default);
EXPECT_EQ(&FLAGS_test_int32, info.flag_ptr);
info = GetCommandLineFlagInfoOrDie("test_bool"); info = GetCommandLineFlagInfoOrDie("test_bool");
EXPECT_EQ("test_bool", info.name); EXPECT_EQ("test_bool", info.name);
EXPECT_EQ("bool", info.type); EXPECT_EQ("bool", info.type);
...@@ -1071,6 +1079,7 @@ TEST(GetCommandLineFlagInfoOrDieTest, FlagExistsAndIsDefault) { ...@@ -1071,6 +1079,7 @@ TEST(GetCommandLineFlagInfoOrDieTest, FlagExistsAndIsDefault) {
EXPECT_EQ("false", info.default_value); EXPECT_EQ("false", info.default_value);
EXPECT_TRUE(info.is_default); EXPECT_TRUE(info.is_default);
EXPECT_FALSE(info.has_validator_fn); EXPECT_FALSE(info.has_validator_fn);
EXPECT_EQ(&FLAGS_test_bool, info.flag_ptr);
} }
TEST(GetCommandLineFlagInfoOrDieTest, FlagExistsAndWasAssigned) { TEST(GetCommandLineFlagInfoOrDieTest, FlagExistsAndWasAssigned) {
...@@ -1083,6 +1092,7 @@ TEST(GetCommandLineFlagInfoOrDieTest, FlagExistsAndWasAssigned) { ...@@ -1083,6 +1092,7 @@ TEST(GetCommandLineFlagInfoOrDieTest, FlagExistsAndWasAssigned) {
EXPECT_EQ("400", info.current_value); EXPECT_EQ("400", info.current_value);
EXPECT_EQ("-1", info.default_value); EXPECT_EQ("-1", info.default_value);
EXPECT_FALSE(info.is_default); EXPECT_FALSE(info.is_default);
EXPECT_EQ(&FLAGS_test_int32, info.flag_ptr);
FLAGS_test_bool = true; FLAGS_test_bool = true;
info = GetCommandLineFlagInfoOrDie("test_bool"); info = GetCommandLineFlagInfoOrDie("test_bool");
EXPECT_EQ("test_bool", info.name); EXPECT_EQ("test_bool", info.name);
...@@ -1092,6 +1102,7 @@ TEST(GetCommandLineFlagInfoOrDieTest, FlagExistsAndWasAssigned) { ...@@ -1092,6 +1102,7 @@ TEST(GetCommandLineFlagInfoOrDieTest, FlagExistsAndWasAssigned) {
EXPECT_EQ("false", info.default_value); EXPECT_EQ("false", info.default_value);
EXPECT_FALSE(info.is_default); EXPECT_FALSE(info.is_default);
EXPECT_FALSE(info.has_validator_fn); EXPECT_FALSE(info.has_validator_fn);
EXPECT_EQ(&FLAGS_test_bool, info.flag_ptr);
} }
#ifdef GTEST_HAS_DEATH_TEST #ifdef GTEST_HAS_DEATH_TEST
...@@ -1357,6 +1368,7 @@ TEST(ParseCommandLineFlagsWrongFields, ...@@ -1357,6 +1368,7 @@ TEST(ParseCommandLineFlagsWrongFields,
CommandLineFlagInfo fi; CommandLineFlagInfo fi;
EXPECT_TRUE(GetCommandLineFlagInfo("flag_name", &fi)); EXPECT_TRUE(GetCommandLineFlagInfo("flag_name", &fi));
EXPECT_EQ("", fi.description); EXPECT_EQ("", fi.description);
EXPECT_EQ(&current_storage, fi.flag_ptr);
} }
static bool ValidateTestFlagIs5(const char* flagname, int32 flagval) { static bool ValidateTestFlagIs5(const char* flagname, int32 flagval) {
......
...@@ -166,6 +166,7 @@ struct GFLAGS_DLL_DECL CommandLineFlagInfo { ...@@ -166,6 +166,7 @@ struct GFLAGS_DLL_DECL CommandLineFlagInfo {
bool is_default; // true if the flag has the default value and bool is_default; // true if the flag has the default value and
// has not been set explicitly from the cmdline // has not been set explicitly from the cmdline
// or via SetCommandLineOption // 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. // Using this inside of a validator is a recipe for a deadlock.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment