Windows: More constness in stout. Also small fixes such as `reserve` over an allocation, and a bad name `si` instead of `info`.
Review: https://reviews.apache.org/r/66426 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/9e93d0e7 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/9e93d0e7 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/9e93d0e7 Branch: refs/heads/master Commit: 9e93d0e731bcc83c8144ef2790c74237b50fd20c Parents: ef51137 Author: Andrew Schwartzmeyer <[email protected]> Authored: Fri Mar 16 16:20:49 2018 -0700 Committer: Andrew Schwartzmeyer <[email protected]> Committed: Tue May 1 18:36:04 2018 -0700 ---------------------------------------------------------------------- 3rdparty/stout/include/stout/os/windows/getcwd.hpp | 4 ++-- 3rdparty/stout/include/stout/os/windows/getenv.hpp | 3 ++- 3rdparty/stout/include/stout/os/windows/jobobject.hpp | 10 +++++----- 3rdparty/stout/include/stout/os/windows/killtree.hpp | 2 +- 3rdparty/stout/include/stout/os/windows/mkdir.hpp | 6 +++--- 3rdparty/stout/include/stout/os/windows/pagesize.hpp | 6 +++--- 3rdparty/stout/include/stout/os/windows/realpath.hpp | 2 +- 3rdparty/stout/include/stout/os/windows/su.hpp | 3 ++- 3rdparty/stout/include/stout/os/windows/temp.hpp | 2 +- 9 files changed, 20 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/9e93d0e7/3rdparty/stout/include/stout/os/windows/getcwd.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/os/windows/getcwd.hpp b/3rdparty/stout/include/stout/os/windows/getcwd.hpp index f316d61..daf131a 100644 --- a/3rdparty/stout/include/stout/os/windows/getcwd.hpp +++ b/3rdparty/stout/include/stout/os/windows/getcwd.hpp @@ -29,13 +29,13 @@ namespace os { inline std::string getcwd() { // First query for the buffer size required. - DWORD length = ::GetCurrentDirectoryW(0, nullptr); + const DWORD length = ::GetCurrentDirectoryW(0, nullptr); CHECK(length != 0) << "Failed to retrieve current directory buffer size"; std::vector<wchar_t> buffer; buffer.reserve(static_cast<size_t>(length)); - DWORD result = ::GetCurrentDirectoryW(length, buffer.data()); + const DWORD result = ::GetCurrentDirectoryW(length, buffer.data()); CHECK(result != 0) << "Failed to determine current directory"; return strings::remove( http://git-wip-us.apache.org/repos/asf/mesos/blob/9e93d0e7/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 58012e0..034510c 100644 --- a/3rdparty/stout/include/stout/os/windows/getenv.hpp +++ b/3rdparty/stout/include/stout/os/windows/getenv.hpp @@ -36,7 +36,8 @@ inline Option<std::string> getenv(const std::string& key) // 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 = ::GetEnvironmentVariableW(wide_key.data(), nullptr, 0); + const DWORD buffer_size = + ::GetEnvironmentVariableW(wide_key.data(), nullptr, 0); if (buffer_size == 0) { if (::GetLastError() == ERROR_ENVVAR_NOT_FOUND) { return None(); http://git-wip-us.apache.org/repos/asf/mesos/blob/9e93d0e7/3rdparty/stout/include/stout/os/windows/jobobject.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/os/windows/jobobject.hpp b/3rdparty/stout/include/stout/os/windows/jobobject.hpp index 3d868f5..7d6678d 100644 --- a/3rdparty/stout/include/stout/os/windows/jobobject.hpp +++ b/3rdparty/stout/include/stout/os/windows/jobobject.hpp @@ -73,7 +73,7 @@ inline Try<SharedHandle> open_job( inline Try<SharedHandle> open_job( const DWORD desired_access, const BOOL inherit_handles, const pid_t pid) { - Try<std::wstring> name = os::name_job(pid); + const Try<std::wstring> name = os::name_job(pid); if (name.isError()) { return Error(name.error()); } @@ -115,7 +115,7 @@ inline Try<JOBOBJECT_BASIC_ACCOUNTING_INFORMATION> get_job_info(pid_t pid) JOBOBJECT_BASIC_ACCOUNTING_INFORMATION info = {}; - BOOL result = ::QueryInformationJobObject( + const BOOL result = ::QueryInformationJobObject( job_handle->get_handle(), JobObjectBasicAccountingInformation, &info, @@ -144,7 +144,7 @@ Result<std::set<Process>> _get_job_processes(const SharedHandle& job_handle) DWORD ProcessIdList[max_pids]; } pid_list; - BOOL result = ::QueryInformationJobObject( + const BOOL result = ::QueryInformationJobObject( job_handle.get_handle(), JobObjectBasicProcessIdList, reinterpret_cast<JOBOBJECT_BASIC_PROCESS_ID_LIST*>(&pid_list), @@ -300,7 +300,7 @@ inline Try<Nothing> set_job_cpu_limit(pid_t pid, double cpus) return Error(job_handle.error()); } - BOOL result = ::SetInformationJobObject( + const BOOL result = ::SetInformationJobObject( job_handle->get_handle(), JobObjectCpuRateControlInformation, &control_info, @@ -331,7 +331,7 @@ inline Try<Nothing> set_job_mem_limit(pid_t pid, Bytes limit) return Error(job_handle.error()); } - BOOL result = ::SetInformationJobObject( + const BOOL result = ::SetInformationJobObject( job_handle->get_handle(), JobObjectExtendedLimitInformation, &info, http://git-wip-us.apache.org/repos/asf/mesos/blob/9e93d0e7/3rdparty/stout/include/stout/os/windows/killtree.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/os/windows/killtree.hpp b/3rdparty/stout/include/stout/os/windows/killtree.hpp index 2de1933..f760cb3 100644 --- a/3rdparty/stout/include/stout/os/windows/killtree.hpp +++ b/3rdparty/stout/include/stout/os/windows/killtree.hpp @@ -32,7 +32,7 @@ inline Try<std::list<ProcessTree>> killtree( bool groups = false, bool sessions = false) { - Try<std::wstring> name = os::name_job(pid); + const Try<std::wstring> name = os::name_job(pid); if (name.isError()) { return Error("Failed to determine job object name: " + name.error()); } http://git-wip-us.apache.org/repos/asf/mesos/blob/9e93d0e7/3rdparty/stout/include/stout/os/windows/mkdir.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/os/windows/mkdir.hpp b/3rdparty/stout/include/stout/os/windows/mkdir.hpp index 8d8d80b..2aef22a 100644 --- a/3rdparty/stout/include/stout/os/windows/mkdir.hpp +++ b/3rdparty/stout/include/stout/os/windows/mkdir.hpp @@ -40,7 +40,7 @@ inline Try<Nothing> mkdir(const std::string& directory, bool recursive = true) return Nothing(); } - std::wstring longpath = ::internal::windows::longpath(directory); + const std::wstring longpath = ::internal::windows::longpath(directory); if (::CreateDirectoryW(longpath.data(), nullptr) == 0) { return WindowsError("Failed to create directory: " + directory); } @@ -48,7 +48,7 @@ inline Try<Nothing> mkdir(const std::string& directory, bool recursive = true) // Remove the long path prefix, if it already exists, otherwise the // tokenizer includes the long path prefix (`\\?\`) as the first part // of the path. - std::vector<std::string> tokens = strings::tokenize( + const std::vector<std::string> tokens = strings::tokenize( strings::remove(directory, os::LONGPATH_PREFIX, strings::Mode::PREFIX), stringify(os::PATH_SEPARATOR)); @@ -56,7 +56,7 @@ inline Try<Nothing> mkdir(const std::string& directory, bool recursive = true) foreach (const std::string& token, tokens) { path += token + os::PATH_SEPARATOR; - Try<Nothing> result = mkdir(path, false); + const Try<Nothing> result = mkdir(path, false); if (result.isError()) { return result; } http://git-wip-us.apache.org/repos/asf/mesos/blob/9e93d0e7/3rdparty/stout/include/stout/os/windows/pagesize.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/os/windows/pagesize.hpp b/3rdparty/stout/include/stout/os/windows/pagesize.hpp index ddf23c1..639c635 100644 --- a/3rdparty/stout/include/stout/os/windows/pagesize.hpp +++ b/3rdparty/stout/include/stout/os/windows/pagesize.hpp @@ -20,9 +20,9 @@ namespace os { inline size_t pagesize() { - SYSTEM_INFO si; - GetSystemInfo(&si); - return si.dwPageSize; + SYSTEM_INFO info; + ::GetSystemInfo(&info); + return static_cast<size_t>(info.dwPageSize); } } // namespace os { http://git-wip-us.apache.org/repos/asf/mesos/blob/9e93d0e7/3rdparty/stout/include/stout/os/windows/realpath.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/os/windows/realpath.hpp b/3rdparty/stout/include/stout/os/windows/realpath.hpp index c6bad50..6bfaaf6 100644 --- a/3rdparty/stout/include/stout/os/windows/realpath.hpp +++ b/3rdparty/stout/include/stout/os/windows/realpath.hpp @@ -38,7 +38,7 @@ inline Result<std::string> realpath(const std::string& path) } // First query for the buffer size required. - DWORD length = ::GetFinalPathNameByHandleW( + const DWORD length = ::GetFinalPathNameByHandleW( handle.get().get_handle(), nullptr, 0, FILE_NAME_NORMALIZED); if (length == 0) { return WindowsError("Failed to retrieve realpath buffer size"); http://git-wip-us.apache.org/repos/asf/mesos/blob/9e93d0e7/3rdparty/stout/include/stout/os/windows/su.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/os/windows/su.hpp b/3rdparty/stout/include/stout/os/windows/su.hpp index 1bfbb26..ac3a896 100644 --- a/3rdparty/stout/include/stout/os/windows/su.hpp +++ b/3rdparty/stout/include/stout/os/windows/su.hpp @@ -87,7 +87,8 @@ inline Result<std::string> user(Option<uid_t> uid = None()) } } - std::vector<wchar_t> user_name(buffer_size); + std::vector<wchar_t> user_name; + user_name.reserve(buffer_size); if (::GetUserNameExW(username_format, user_name.data(), &buffer_size) == FALSE) { return WindowsError("os::user: Failed to get username from OS"); http://git-wip-us.apache.org/repos/asf/mesos/blob/9e93d0e7/3rdparty/stout/include/stout/os/windows/temp.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/os/windows/temp.hpp b/3rdparty/stout/include/stout/os/windows/temp.hpp index 9cf467f..4e8543e 100644 --- a/3rdparty/stout/include/stout/os/windows/temp.hpp +++ b/3rdparty/stout/include/stout/os/windows/temp.hpp @@ -29,7 +29,7 @@ namespace os { // where none of these are found, this function returns the current directory. inline std::string temp() { - size_t size = static_cast<size_t>(MAX_PATH) + 2; + const size_t size = static_cast<size_t>(MAX_PATH) + 2; std::vector<wchar_t> buffer; buffer.reserve(size); if (::GetTempPathW(static_cast<DWORD>(size), buffer.data()) == 0) {
