diff options
author | Zachary Turner <zturner@google.com> | 2014-07-09 16:32:07 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2014-07-09 16:32:07 +0000 |
commit | 154364b066827d7afc2f2f8940e37ce0fddd9121 (patch) | |
tree | 686bead771739bba04db54674a39fb4c5a53e8c8 | |
parent | af2672d9931a05c69cb1e1ff322d8c72f8de8037 (diff) |
Fix tests broken by the OptionValidator changes.
The getopt library has a structure called option (lowercase). We
have a structure called Option (uppercase). previously the two
structures had exactly the same definitions, and we were doing a
C-style cast of an Option* to an option*. C-style casts don't
bother to warn you when you cast to unrelated types, but in the
original OptionValidator patch I modified the definition of Option.
This patch fixes the errors by building an array of option
structures and filling it out the correct way before passing it to
the getopt library.
This also fixes one other source of test failures: an uninitialized
read that occurs due to not initializing a field of the
OptionDefinition.
Reviewed By: Todd Fiala
Differential Revision: http://reviews.llvm.org/D4425
git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@212628 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | source/Host/common/OptionParser.cpp | 17 | ||||
-rw-r--r-- | source/Interpreter/OptionGroupBoolean.cpp | 1 | ||||
-rw-r--r-- | source/Interpreter/OptionGroupFile.cpp | 2 | ||||
-rw-r--r-- | source/Interpreter/OptionGroupString.cpp | 1 | ||||
-rw-r--r-- | source/Interpreter/OptionGroupUInt64.cpp | 1 |
5 files changed, 21 insertions, 1 deletions
diff --git a/source/Host/common/OptionParser.cpp b/source/Host/common/OptionParser.cpp index 9a69e0e2e..a91e764bf 100644 --- a/source/Host/common/OptionParser.cpp +++ b/source/Host/common/OptionParser.cpp @@ -9,6 +9,9 @@ #include "lldb/Host/OptionParser.h" #include "lldb/Host/HostGetOpt.h" +#include "lldb/lldb-private-types.h" + +#include <vector> using namespace lldb_private; @@ -36,7 +39,19 @@ OptionParser::Parse (int argc, const Option *longopts, int *longindex) { - return getopt_long_only(argc, argv, optstring, (const option*)longopts, longindex); + std::vector<option> opts; + while (longopts->definition != nullptr) + { + option opt; + opt.flag = longopts->flag; + opt.val = longopts->val; + opt.name = longopts->definition->long_option; + opt.has_arg = longopts->definition->option_has_arg; + opts.push_back(opt); + ++longopts; + } + opts.push_back(option()); + return getopt_long_only(argc, argv, optstring, &opts[0], longindex); } char* diff --git a/source/Interpreter/OptionGroupBoolean.cpp b/source/Interpreter/OptionGroupBoolean.cpp index af2ba7ca0..0c502cc36 100644 --- a/source/Interpreter/OptionGroupBoolean.cpp +++ b/source/Interpreter/OptionGroupBoolean.cpp @@ -30,6 +30,7 @@ OptionGroupBoolean::OptionGroupBoolean (uint32_t usage_mask, m_option_definition.required = required; m_option_definition.long_option = long_option; m_option_definition.short_option = short_option; + m_option_definition.validator = nullptr; m_option_definition.option_has_arg = no_argument_toggle_default ? OptionParser::eNoArgument : OptionParser::eRequiredArgument; m_option_definition.enum_values = nullptr; m_option_definition.completion_type = 0; diff --git a/source/Interpreter/OptionGroupFile.cpp b/source/Interpreter/OptionGroupFile.cpp index a80ed9264..9bfe8ddf0 100644 --- a/source/Interpreter/OptionGroupFile.cpp +++ b/source/Interpreter/OptionGroupFile.cpp @@ -30,6 +30,7 @@ OptionGroupFile::OptionGroupFile (uint32_t usage_mask, m_option_definition.required = required; m_option_definition.long_option = long_option; m_option_definition.short_option = short_option; + m_option_definition.validator = nullptr; m_option_definition.option_has_arg = OptionParser::eRequiredArgument; m_option_definition.enum_values = nullptr; m_option_definition.completion_type = completion_type; @@ -70,6 +71,7 @@ OptionGroupFileList::OptionGroupFileList (uint32_t usage_mask, m_option_definition.required = required; m_option_definition.long_option = long_option; m_option_definition.short_option = short_option; + m_option_definition.validator = nullptr; m_option_definition.option_has_arg = OptionParser::eRequiredArgument; m_option_definition.enum_values = nullptr; m_option_definition.completion_type = completion_type; diff --git a/source/Interpreter/OptionGroupString.cpp b/source/Interpreter/OptionGroupString.cpp index 3c013c6d6..9bc1c94d3 100644 --- a/source/Interpreter/OptionGroupString.cpp +++ b/source/Interpreter/OptionGroupString.cpp @@ -31,6 +31,7 @@ OptionGroupString::OptionGroupString (uint32_t usage_mask, m_option_definition.required = required; m_option_definition.long_option = long_option; m_option_definition.short_option = short_option; + m_option_definition.validator = nullptr; m_option_definition.option_has_arg = OptionParser::eRequiredArgument; m_option_definition.enum_values = nullptr; m_option_definition.completion_type = completion_type; diff --git a/source/Interpreter/OptionGroupUInt64.cpp b/source/Interpreter/OptionGroupUInt64.cpp index 38d037309..440c2a740 100644 --- a/source/Interpreter/OptionGroupUInt64.cpp +++ b/source/Interpreter/OptionGroupUInt64.cpp @@ -31,6 +31,7 @@ OptionGroupUInt64::OptionGroupUInt64 (uint32_t usage_mask, m_option_definition.required = required; m_option_definition.long_option = long_option; m_option_definition.short_option = short_option; + m_option_definition.validator = nullptr; m_option_definition.option_has_arg = OptionParser::eRequiredArgument; m_option_definition.enum_values = nullptr; m_option_definition.completion_type = completion_type; |