Fix tests broken by the OptionValidator changes.
authorZachary Turner <zturner@google.com>
Wed, 9 Jul 2014 16:32:07 +0000 (16:32 +0000)
committerZachary Turner <zturner@google.com>
Wed, 9 Jul 2014 16:32:07 +0000 (16:32 +0000)
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

llvm-svn: 212628

lldb/source/Host/common/OptionParser.cpp
lldb/source/Interpreter/OptionGroupBoolean.cpp
lldb/source/Interpreter/OptionGroupFile.cpp
lldb/source/Interpreter/OptionGroupString.cpp
lldb/source/Interpreter/OptionGroupUInt64.cpp

index 9a69e0e..a91e764 100644 (file)
@@ -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*
index af2ba7c..0c502cc 100644 (file)
@@ -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;
index a80ed92..9bfe8dd 100644 (file)
@@ -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;
index 3c013c6..9bc1c94 100644 (file)
@@ -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;
index 38d0373..440c2a7 100644 (file)
@@ -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;