Skip to content

Commit

Permalink
Windows: explicitly use ASCII-version of Win32 API
Browse files Browse the repository at this point in the history
This way it's easier to find the functions we need
to change to widechar version.

See #2181

--
PiperOrigin-RevId: 141043389
MOS_MIGRATED_REVID=141043389
  • Loading branch information
laszlocsomor authored and damienmg committed Dec 5, 2016
1 parent f161db2 commit d86ae8c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
25 changes: 13 additions & 12 deletions src/main/cpp/blaze_util_windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <errno.h> // errno, ENAMETOOLONG
#include <limits.h>
#include <stdarg.h> // va_start, va_end, va_list

#ifndef COMPILER_MSVC
#include <fcntl.h>
Expand Down Expand Up @@ -231,7 +232,7 @@ string GetSelfPath() {
const size_t PATH_MAX = 4096;
#endif // COMPILER_MSVC
char buffer[PATH_MAX] = {};
if (!GetModuleFileName(0, buffer, sizeof(buffer))) {
if (!GetModuleFileNameA(0, buffer, sizeof(buffer))) {
pdie(255, "Error %u getting executable file name\n", GetLastError());
}

Expand Down Expand Up @@ -420,15 +421,15 @@ string RunProgram(
}

PROCESS_INFORMATION processInfo = {0};
STARTUPINFO startupInfo = {0};
STARTUPINFOA startupInfo = {0};

startupInfo.hStdError = pipe_write;
startupInfo.hStdOutput = pipe_write;
startupInfo.dwFlags |= STARTF_USESTDHANDLES;
CmdLine cmdline;
CreateCommandLine(&cmdline, exe, args_vector);

bool ok = CreateProcess(
bool ok = CreateProcessA(
NULL, // _In_opt_ LPCTSTR lpApplicationName,
// _Inout_opt_ LPTSTR lpCommandLine,
cmdline.cmdline,
Expand Down Expand Up @@ -525,7 +526,7 @@ void ExecuteDaemon(const string& exe, const std::vector<string>& args_vector,
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = NULL;

HANDLE output_file = CreateFile(
HANDLE output_file = CreateFileA(
ConvertPath(daemon_output).c_str(), // lpFileName
GENERIC_READ | GENERIC_WRITE, // dwDesiredAccess
// So that the file can be read while the server is running
Expand All @@ -549,7 +550,7 @@ void ExecuteDaemon(const string& exe, const std::vector<string>& args_vector,
}

PROCESS_INFORMATION processInfo = {0};
STARTUPINFO startupInfo = {0};
STARTUPINFOA startupInfo = {0};

startupInfo.hStdInput = pipe_read;
startupInfo.hStdError = output_file;
Expand All @@ -561,9 +562,9 @@ void ExecuteDaemon(const string& exe, const std::vector<string>& args_vector,
// Propagate BAZEL_SH environment variable to a sub-process.
// todo(dslomov): More principled approach to propagating
// environment variables.
SetEnvironmentVariable("BAZEL_SH", getenv("BAZEL_SH"));
SetEnvironmentVariableA("BAZEL_SH", getenv("BAZEL_SH"));

bool ok = CreateProcess(
bool ok = CreateProcessA(
NULL, // _In_opt_ LPCTSTR lpApplicationName,
// _Inout_opt_ LPTSTR lpCommandLine,
cmdline.cmdline,
Expand Down Expand Up @@ -654,13 +655,13 @@ void ExecuteProgram(
CmdLine cmdline;
CreateCommandLine(&cmdline, exe, args_vector);

STARTUPINFO startupInfo = {0};
STARTUPINFOA startupInfo = {0};
PROCESS_INFORMATION processInfo = {0};

// Propagate BAZEL_SH environment variable to a sub-process.
// todo(dslomov): More principled approach to propagating
// environment variables.
SetEnvironmentVariable("BAZEL_SH", getenv("BAZEL_SH"));
SetEnvironmentVariableA("BAZEL_SH", getenv("BAZEL_SH"));

HANDLE job = CreateJobObject(NULL, NULL);
if (job == NULL) {
Expand All @@ -678,7 +679,7 @@ void ExecuteProgram(
pdie(255, "Error %u while setting up job\n", GetLastError());
}

bool success = CreateProcess(
bool success = CreateProcessA(
NULL, // _In_opt_ LPCTSTR lpApplicationName,
// _Inout_opt_ LPTSTR lpCommandLine,
cmdline.cmdline,
Expand Down Expand Up @@ -799,7 +800,7 @@ typedef struct {
} REPARSE_MOUNTPOINT_DATA_BUFFER, *PREPARSE_MOUNTPOINT_DATA_BUFFER;

HANDLE OpenDirectory(const string& path, bool readWrite) {
HANDLE result = ::CreateFile(
HANDLE result = ::CreateFileA(
path.c_str(),
readWrite ? (GENERIC_READ | GENERIC_WRITE) : GENERIC_READ,
0,
Expand All @@ -819,7 +820,7 @@ bool SymlinkDirectories(const string &posix_target, const string &posix_name) {
string name = ConvertPath(posix_name);

// Junctions are directories, so create one
if (!::CreateDirectory(name.c_str(), NULL)) {
if (!::CreateDirectoryA(name.c_str(), NULL)) {
PrintError("CreateDirectory(" + name + ")");
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/native/windows_processes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Java_com_google_devtools_build_lib_windows_WindowsProcesses_nativeCreateProcess(
HANDLE thread = INVALID_HANDLE_VALUE;
HANDLE event = INVALID_HANDLE_VALUE;
PROCESS_INFORMATION process_info = {0};
STARTUPINFO startup_info = {0};
STARTUPINFOA startup_info = {0};
JOBOBJECT_EXTENDED_LIMIT_INFORMATION job_info = {0};

if (java_env != NULL) {
Expand All @@ -145,7 +145,7 @@ Java_com_google_devtools_build_lib_windows_WindowsProcesses_nativeCreateProcess(
if (stdout_redirect != NULL) {
result->stdout_.close();

stdout_process = CreateFile(
stdout_process = CreateFileA(
stdout_redirect,
FILE_APPEND_DATA,
0,
Expand All @@ -170,7 +170,7 @@ Java_com_google_devtools_build_lib_windows_WindowsProcesses_nativeCreateProcess(
if (!strcmp(stdout_redirect, stderr_redirect)) {
stderr_process = stdout_process;
} else {
stderr_process = CreateFile(
stderr_process = CreateFileA(
stderr_redirect,
FILE_APPEND_DATA,
0,
Expand Down Expand Up @@ -218,7 +218,7 @@ Java_com_google_devtools_build_lib_windows_WindowsProcesses_nativeCreateProcess(
startup_info.hStdError = stderr_process;
startup_info.dwFlags |= STARTF_USESTDHANDLES;

BOOL ok = CreateProcess(
BOOL ok = CreateProcessA(
NULL,
mutable_commandline,
NULL,
Expand Down

1 comment on commit d86ae8c

@abergmeier
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not change all to wide variant? IME normally on Windows you choose one and stick to it. If you don't then there is a good chance that you will have oversights at some points and introduce subtle bugs.

Please sign in to comment.