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:27 UTC
[41/50] mesos git commit: Windows: Made environment abstractions use
Unicode.
Windows: Made environment abstractions use Unicode.
Review: https://reviews.apache.org/r/60336/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/0f2bfe76
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/0f2bfe76
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/0f2bfe76
Branch: refs/heads/master
Commit: 0f2bfe7623c1df62b6ac7fc9cfe7733b021b001f
Parents: 498c530
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 15:14:08 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:38 2017 -0700
----------------------------------------------------------------------
3rdparty/stout/include/stout/os/windows/environment.hpp | 12 +++++++-----
3rdparty/stout/include/stout/os/windows/getenv.hpp | 12 ++++++++----
3rdparty/stout/include/stout/windows/os.hpp | 7 ++++---
3 files changed, 19 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/0f2bfe76/3rdparty/stout/include/stout/os/windows/environment.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/environment.hpp b/3rdparty/stout/include/stout/os/windows/environment.hpp
index 96f0eb4..f79cbfa 100644
--- a/3rdparty/stout/include/stout/os/windows/environment.hpp
+++ b/3rdparty/stout/include/stout/os/windows/environment.hpp
@@ -15,6 +15,7 @@
#include <map>
#include <string>
+#include <stout/stringify.hpp>
namespace os {
@@ -28,21 +29,22 @@ inline std::map<std::string, std::string> environment()
// Var3=Value3\0
// ...
// VarN=ValueN\0\0
- char* env = GetEnvironmentStrings();
+ wchar_t* env = ::GetEnvironmentStringsW();
std::map<std::string, std::string> result;
- for (size_t i = 0; env[i] != '\0' && env[i+1] != '\0';) {
- std::string entry(env + i);
+ for (size_t i = 0; env[i] != L'\0' && env[i+1] != L'\0';) {
+ std::wstring entry(env + i);
// Increment past the current environment string and null terminator.
i = i + entry.size() + 1;
- size_t position = entry.find_first_of('=');
+ size_t position = entry.find_first_of(L'=');
if (position == std::string::npos) {
continue; // Skip malformed environment entries.
}
- result[entry.substr(0, position)] = entry.substr(position + 1);
+ result[stringify(entry.substr(0, position))] =
+ stringify(entry.substr(position + 1));
}
return result;
http://git-wip-us.apache.org/repos/asf/mesos/blob/0f2bfe76/3rdparty/stout/include/stout/os/windows/getenv.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/getenv.hpp b/3rdparty/stout/include/stout/os/windows/getenv.hpp
index 2200f85..27a0e87 100644
--- a/3rdparty/stout/include/stout/os/windows/getenv.hpp
+++ b/3rdparty/stout/include/stout/os/windows/getenv.hpp
@@ -18,6 +18,7 @@
#include <stout/none.hpp>
#include <stout/option.hpp>
+#include <stout/stringify.hpp>
#include <stout/windows.hpp>
@@ -28,20 +29,23 @@ namespace os {
// variable matching key is found, None() is returned.
inline Option<std::string> getenv(const std::string& key)
{
+ std::wstring wide_key = wide_stringify(key);
+
// NOTE: The double-call to `::GetEnvironmentVariable` here uses the first
// call to get the size of the variable's value, and then again to retrieve
// the value itself. It is possible to have `::GetEnvironmentVariable`
// allocate the space for this, but we explicitly do it this way to avoid
// that.
- DWORD buffer_size = ::GetEnvironmentVariable(key.c_str(), nullptr, 0);
+ DWORD buffer_size = ::GetEnvironmentVariableW(wide_key.data(), nullptr, 0);
if (buffer_size == 0) {
return None();
}
- std::unique_ptr<char[]> environment(new char[buffer_size]);
+ std::vector<wchar_t> environment;
+ environment.reserve(static_cast<size_t>(buffer_size));
DWORD value_size =
- ::GetEnvironmentVariable(key.c_str(), environment.get(), buffer_size);
+ ::GetEnvironmentVariableW(wide_key.data(), environment.data(), buffer_size);
if (value_size == 0) {
// If `value_size == 0` here, that probably means the environment variable
@@ -50,7 +54,7 @@ inline Option<std::string> getenv(const std::string& key)
return None();
}
- return std::string(environment.get());
+ return stringify(std::wstring(environment.data()));
}
} // namespace os {
http://git-wip-us.apache.org/repos/asf/mesos/blob/0f2bfe76/3rdparty/stout/include/stout/windows/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/windows/os.hpp b/3rdparty/stout/include/stout/windows/os.hpp
index 42fda71..e24022e 100644
--- a/3rdparty/stout/include/stout/windows/os.hpp
+++ b/3rdparty/stout/include/stout/windows/os.hpp
@@ -209,13 +209,14 @@ inline void setenv(
//
// [1] https://msdn.microsoft.com/en-us/library/windows/desktop/ms683188(v=vs.85).aspx
if (!overwrite &&
- ::GetEnvironmentVariable(key.c_str(), nullptr, 0) != 0 &&
+ ::GetEnvironmentVariableW(wide_stringify(key).data(), nullptr, 0) != 0 &&
::GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
return;
}
// `SetEnvironmentVariable` returns an error code, but we can't act on it.
- ::SetEnvironmentVariable(key.c_str(), value.c_str());
+ ::SetEnvironmentVariableW(
+ wide_stringify(key).data(), wide_stringify(value).data());
}
@@ -225,7 +226,7 @@ inline void unsetenv(const std::string& key)
{
// Per MSDN documentation[1], passing `nullptr` as the value will cause
// `SetEnvironmentVariable` to delete the key from the process's environment.
- ::SetEnvironmentVariable(key.c_str(), nullptr);
+ ::SetEnvironmentVariableW(wide_stringify(key).data(), nullptr);
}