You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2017/07/11 01:39:18 UTC

[32/50] mesos git commit: Added `vector` explicit cast to `Argv`.

Added `vector<string>` explicit cast to `Argv`.

This is needed for implementations that expect a `vector<string>`
instead of a `char **`.

This includes a slight refactoring because storing a
`vector<string>` is very similar to the current `Argv`
implementation, which uses a `vector<char*>` local variable.

Review: https://reviews.apache.org/r/60326/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/eac6cf4a
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/eac6cf4a
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/eac6cf4a

Branch: refs/heads/master
Commit: eac6cf4ad54d975f69efb08d98ca39b81779cb1a
Parents: 0fb02c8
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 11:27:53 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:36 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/gtest.hpp       |  3 ++-
 3rdparty/stout/include/stout/os/raw/argv.hpp | 29 ++++++++++++-----------
 2 files changed, 17 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/eac6cf4a/3rdparty/stout/include/stout/gtest.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/gtest.hpp b/3rdparty/stout/include/stout/gtest.hpp
index 1df5eaf..a8ae3d9 100644
--- a/3rdparty/stout/include/stout/gtest.hpp
+++ b/3rdparty/stout/include/stout/gtest.hpp
@@ -226,7 +226,8 @@ template <typename T1, typename T2>
 #ifndef __WINDOWS__
 #define SLEEP_COMMAND(x) "sleep " #x
 #else
-#define SLEEP_COMMAND(x) "powershell -NoProfile -Command Start-Sleep " #x
+#define SLEEP_COMMAND(x) \
+  "powershell -NoProfile -Command Start-Sleep -Seconds " #x
 #endif // __WINDOWS__
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/eac6cf4a/3rdparty/stout/include/stout/os/raw/argv.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/raw/argv.hpp b/3rdparty/stout/include/stout/os/raw/argv.hpp
index 58e5ee2..5e7711b 100644
--- a/3rdparty/stout/include/stout/os/raw/argv.hpp
+++ b/3rdparty/stout/include/stout/os/raw/argv.hpp
@@ -39,37 +39,38 @@ public:
   template <typename Iterable>
   explicit Argv(const Iterable& iterable)
   {
-    std::vector<char*> _argv;
     foreach (const std::string& arg, iterable) {
-      char* _arg = new char[arg.size() + 1];
-      ::memcpy(_arg, arg.c_str(), arg.size() + 1);
-      _argv.emplace_back(_arg);
+      args.emplace_back(arg);
     }
 
-    size = _argv.size();
-    argv = new char*[size + 1];
-    for (size_t i = 0; i < size; i++) {
-      argv[i] = _argv[i];
+    argv = new char*[args.size() + 1];
+    for (size_t i = 0; i < args.size(); i++) {
+      argv[i] = const_cast<char*>(args[i].c_str());
     }
-    argv[size] = nullptr;
+
+    argv[args.size()] = nullptr;
   }
 
   ~Argv()
   {
-    for (size_t i = 0; i < size; i++) {
-      delete[] argv[i];
-    }
     delete[] argv;
   }
 
-  operator char**()
+  operator char**() const
   {
     return argv;
   }
 
+  operator std::vector<std::string>() const
+  {
+    return args;
+  }
+
 private:
+  std::vector<std::string> args;
+
+  // NOTE: This points to strings in the vector `args`.
   char** argv;
-  size_t size;
 };
 
 } // namespace raw {