Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 80B91200C06 for ; Fri, 13 Jan 2017 03:28:35 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 7F762160B4C; Fri, 13 Jan 2017 02:28:35 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id C55BC160B40 for ; Fri, 13 Jan 2017 03:28:34 +0100 (CET) Received: (qmail 51922 invoked by uid 500); 13 Jan 2017 02:28:29 -0000 Mailing-List: contact commits-help@mesos.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@mesos.apache.org Delivered-To: mailing list commits@mesos.apache.org Received: (qmail 51812 invoked by uid 99); 13 Jan 2017 02:28:29 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Jan 2017 02:28:29 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B7A9BDF9E6; Fri, 13 Jan 2017 02:28:28 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: josephwu@apache.org To: commits@mesos.apache.org Date: Fri, 13 Jan 2017 02:28:31 -0000 Message-Id: In-Reply-To: <2558177fb8244bea917c724f52033d03@git.apache.org> References: <2558177fb8244bea917c724f52033d03@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [4/4] mesos git commit: Windows: Stout: Removed dependency on Shell API. archived-at: Fri, 13 Jan 2017 02:28:35 -0000 Windows: Stout: Removed dependency on Shell API. The API `SHGetKnownFolderPath` requires `Shell32.dll`, which is not available on Nano server (a version of Windows Server 2016). An equivalent API `GetAllUsersProfileDirectory` is. This API is also friendlier, as we own the allocation. The Unicode version `GetAllUsersProfileDirectoryW` is explicitly used so that we are guaranteed a Unicode path, which we then convert from UTF-16 to UTF-8, instead of using the ANSI version which depends on a varying Windows code-page, and is not recommended. A `vector` is used over a `wstring` to avoid dealing with the placement of the null-terminating character. Review: https://reviews.apache.org/r/54877/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/104532d8 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/104532d8 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/104532d8 Branch: refs/heads/master Commit: 104532d867214b6d3c6fe96d6ebb144aa8803f7c Parents: a92b8ad Author: Andrew Schwartzmeyer Authored: Thu Jan 12 17:54:14 2017 -0800 Committer: Joseph Wu Committed: Thu Jan 12 17:59:08 2017 -0800 ---------------------------------------------------------------------- 3rdparty/stout/include/stout/windows.hpp | 5 ---- 3rdparty/stout/include/stout/windows/os.hpp | 35 +++++++++++------------- 2 files changed, 16 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/104532d8/3rdparty/stout/include/stout/windows.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/windows.hpp b/3rdparty/stout/include/stout/windows.hpp index e641c46..d89c709 100644 --- a/3rdparty/stout/include/stout/windows.hpp +++ b/3rdparty/stout/include/stout/windows.hpp @@ -50,11 +50,6 @@ #error "Mesos doesn't currently support the `_UNICODE` Windows header constant" #endif // _UNICODE -// Similarly, the Windows API uses `PWSTR` to mean `wchar_t*`, -// but rather than assuming this is true, it should be asserted. -static_assert(std::is_same::value, - "Expected `PWSTR` to be of type `wchar_t*`."); - // An RAII `HANDLE`. class SharedHandle : public std::shared_ptr { http://git-wip-us.apache.org/repos/asf/mesos/blob/104532d8/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 5cd9254..b4a66ba 100644 --- a/3rdparty/stout/include/stout/windows/os.hpp +++ b/3rdparty/stout/include/stout/windows/os.hpp @@ -16,8 +16,8 @@ #include #include #include -#include #include +#include #include @@ -724,27 +724,24 @@ inline Try kill_job(pid_t pid) inline Try var() { - wchar_t* var_folder = nullptr; - - // Retrieves the directory of `ProgramData` using the default options. - // NOTE: The location of `ProgramData` is fixed and so does not - // depend on the current user. - if (::SHGetKnownFolderPath( - FOLDERID_ProgramData, - KF_FLAG_DEFAULT, - nullptr, - &var_folder) // `PWSTR` is `typedef wchar_t*`. - != S_OK) { - return WindowsError("os::var: Call to `SHGetKnownFolderPath` failed"); + // Get the `ProgramData` path. First, find the size of the output buffer. + // This size includes the null-terminating character. + DWORD size = 0; + if (::GetAllUsersProfileDirectoryW(nullptr, &size)) { + // The expected behavior here is for the function to "fail" + // and return `false`, and `size` receives necessary buffer size. + return WindowsError( + "os::var: `GetAllUsersProfileDirectory` succeeded unexpectedly"); } - // Convert `wchar_t*` to `wstring`. - std::wstring wvar_folder(var_folder); - - // Free the buffer allocated by `SHGetKnownFolderPath`. - CoTaskMemFree(static_cast(var_folder)); + std::vector var_folder(size); + if (!::GetAllUsersProfileDirectoryW(&var_folder[0], &size)) { + return WindowsError( + "os::var: `GetAllUsersProfileDirectory` failed"); + } - // Convert UTF-16 `wstring` to UTF-8 `string`. + // Convert UTF-16 `wchar[]` to UTF-8 `string`. + std::wstring wvar_folder(&var_folder[0]); std::wstring_convert, wchar_t> converter; return converter.to_bytes(wvar_folder); }