Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert an enum to an enum class in Program.cpp #78751

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions lib/Basic/Program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ swift::ExecuteWithPipe(llvm::StringRef program,
llvm::ArrayRef<llvm::StringRef> args,
std::optional<llvm::ArrayRef<llvm::StringRef>> env) {
using unique_handle = std::unique_ptr<void, decltype(&CloseHandle)>;
enum { PI_READ, PI_WRITE };
enum class PI : uint8_t {READ, WRITE };

unique_handle input[2] = {
{INVALID_HANDLE_VALUE, CloseHandle},
Expand All @@ -214,18 +214,18 @@ swift::ExecuteWithPipe(llvm::StringRef program,

if (!CreatePipe(&hRead, &hWrite, &saAttrs, 0))
return std::error_code(GetLastError(), std::system_category());
output[PI_READ].reset(hRead);
output[PI_WRITE].reset(hWrite);
output[PI::READ].reset(hRead);
output[PI::WRITE].reset(hWrite);

if (!SetHandleInformation(output[PI_READ].get(), HANDLE_FLAG_INHERIT, FALSE))
if (!SetHandleInformation(output[PI::READ].get(), HANDLE_FLAG_INHERIT, FALSE))
return std::error_code(GetLastError(), std::system_category());

if (!CreatePipe(&hRead, &hWrite, &saAttrs, 0))
return std::error_code(GetLastError(), std::system_category());
input[PI_READ].reset(hRead);
input[PI_WRITE].reset(hWrite);
input[PI::READ].reset(hRead);
input[PI::WRITE].reset(hWrite);

if (!SetHandleInformation(input[PI_WRITE].get(), HANDLE_FLAG_INHERIT, FALSE))
if (!SetHandleInformation(input[PI::WRITE].get(), HANDLE_FLAG_INHERIT, FALSE))
return std::error_code(GetLastError(), std::system_category());

if (!DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_ERROR_HANDLE),
Expand All @@ -236,8 +236,8 @@ swift::ExecuteWithPipe(llvm::StringRef program,

STARTUPINFO si = {0};
si.cb = sizeof(si);
si.hStdInput = input[PI_READ].get();
si.hStdOutput = output[PI_WRITE].get();
si.hStdInput = input[PI::READ].get();
si.hStdOutput = output[PI::WRITE].get();
si.hStdError = error.get();
si.dwFlags = STARTF_USESTDHANDLES;

Expand Down Expand Up @@ -265,17 +265,17 @@ swift::ExecuteWithPipe(llvm::StringRef program,
unique_handle hThread{pi.hThread, CloseHandle};
unique_handle hProcess{pi.hProcess, CloseHandle};

int ifd = _open_osfhandle(reinterpret_cast<intptr_t>(input[PI_WRITE].get()), 0);
int ifd = _open_osfhandle(reinterpret_cast<intptr_t>(input[PI::WRITE].get()), 0);
if (ifd < 0)
return std::error_code(errno, std::system_category());
input[PI_WRITE].release();
input[PI::WRITE].release();

int ofd = _open_osfhandle(reinterpret_cast<intptr_t>(output[PI_READ].get()), 0);
int ofd = _open_osfhandle(reinterpret_cast<intptr_t>(output[PI::READ].get()), 0);
if (ofd < 0) {
_close(ifd);
return std::error_code(errno, std::system_category());
}
output[PI_READ].release();
output[PI::READ].release();

llvm::sys::ProcessInfo proc;
proc.Pid = pi.dwProcessId;
Expand Down