Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
G
gflags
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
gflags
Commits
f4eace13
Commit
f4eace13
authored
Sep 17, 2016
by
Andreas Schuh
Committed by
GitHub
Sep 17, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: Validate modified flags only once (#173)
parent
408061b4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
8 deletions
+23
-8
gflags.cc
src/gflags.cc
+23
-8
No files found.
src/gflags.cc
View file @
f4eace13
...
...
@@ -539,6 +539,7 @@ class CommandLineFlag {
// If validate_fn_proto_ is non-NULL, calls it on value, returns result.
bool
Validate
(
const
FlagValue
&
value
)
const
;
bool
ValidateCurrent
()
const
{
return
Validate
(
*
current_
);
}
bool
Modified
()
const
{
return
modified_
;
}
private
:
// for SetFlagLocked() and setting flags_by_ptr_
...
...
@@ -711,7 +712,7 @@ class FlagRegistry {
private
:
friend
class
GFLAGS_NAMESPACE
::
FlagSaverImpl
;
// reads all the flags in order to copy them
friend
class
CommandLineFlagParser
;
// for Validate
All
Flags
friend
class
CommandLineFlagParser
;
// for Validate
Unmodified
Flags
friend
void
GFLAGS_NAMESPACE
::
GetAllFlags
(
vector
<
CommandLineFlagInfo
>*
);
// The map from name to flag, for FindFlagLocked().
...
...
@@ -967,8 +968,10 @@ class CommandLineFlagParser {
// In gflags_reporting.cc:HandleCommandLineHelpFlags().
// Stage 3: validate all the commandline flags that have validators
// registered.
// registered and were not set/modified by ParseNewCommandLineFlags.
void
ValidateFlags
(
bool
all
);
void
ValidateAllFlags
();
void
ValidateUnmodifiedFlags
();
// Stage 4: report any errors and return true if any were found.
bool
ReportErrors
();
...
...
@@ -1234,23 +1237,35 @@ string CommandLineFlagParser::ProcessSingleOptionLocked(
return
msg
;
}
void
CommandLineFlagParser
::
Validate
AllFlags
(
)
{
void
CommandLineFlagParser
::
Validate
Flags
(
bool
all
)
{
FlagRegistryLock
frl
(
registry_
);
for
(
FlagRegistry
::
FlagConstIterator
i
=
registry_
->
flags_
.
begin
();
i
!=
registry_
->
flags_
.
end
();
++
i
)
{
if
(
!
i
->
second
->
ValidateCurrent
())
{
if
(
(
all
||
!
i
->
second
->
Modified
())
&&
!
i
->
second
->
ValidateCurrent
())
{
// only set a message if one isn't already there. (If there's
// an error message, our job is done, even if it's not exactly
// the same error.)
if
(
error_flags_
[
i
->
second
->
name
()].
empty
())
if
(
error_flags_
[
i
->
second
->
name
()].
empty
())
{
error_flags_
[
i
->
second
->
name
()]
=
string
(
kError
)
+
"--"
+
i
->
second
->
name
()
+
" must be set on the commandline"
" (default value fails validation)
\n
"
;
" must be set on the commandline"
;
if
(
!
i
->
second
->
Modified
())
{
error_flags_
[
i
->
second
->
name
()]
+=
" (default value fails validation)"
;
}
error_flags_
[
i
->
second
->
name
()]
+=
"
\n
"
;
}
}
}
}
void
CommandLineFlagParser
::
ValidateAllFlags
()
{
ValidateFlags
(
true
);
}
void
CommandLineFlagParser
::
ValidateUnmodifiedFlags
()
{
ValidateFlags
(
false
);
}
bool
CommandLineFlagParser
::
ReportErrors
()
{
// error_flags_ indicates errors we saw while parsing.
// But we ignore undefined-names if ok'ed by --undef_ok
...
...
@@ -1980,7 +1995,7 @@ static uint32 ParseCommandLineFlagsInternal(int* argc, char*** argv,
HandleCommandLineHelpFlags
();
// may cause us to exit on --help, etc.
// See if any of the unset flags fail their validation checks
parser
.
Validate
All
Flags
();
parser
.
Validate
Unmodified
Flags
();
if
(
parser
.
ReportErrors
())
// may cause us to exit on illegal flags
gflags_exitfunc
(
1
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment