From edf8e48c216a10d1b867aba0308842116f83547b Mon Sep 17 00:00:00 2001 From: Mikhail Glushenkov Date: Tue, 8 Sep 2009 19:50:55 +0000 Subject: [PATCH] Get rid of the Pid_ member in the Program class. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81247 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/System/Program.h | 6 ++---- lib/System/Unix/Program.inc | 17 +++++++++++------ lib/System/Win32/Program.inc | 32 ++++++++++++++++++-------------- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/include/llvm/System/Program.h b/include/llvm/System/Program.h index ae37ece4b60..f92c3222b08 100644 --- a/include/llvm/System/Program.h +++ b/include/llvm/System/Program.h @@ -30,9 +30,7 @@ namespace sys { /// @brief An abstraction for finding and executing programs. class Program { /// Opaque handle for target specific data. - void *Data; - - unsigned Pid_; + void *Data_; // Noncopyable. Program(const Program& other); @@ -46,7 +44,7 @@ namespace sys { ~Program(); /// Return process ID of this program. - unsigned GetPid() { return Pid_; } + unsigned GetPid(); /// This function executes the program using the \p arguments provided. The /// invoked program will inherit the stdin, stdout, and stderr file diff --git a/lib/System/Unix/Program.inc b/lib/System/Unix/Program.inc index fdd0c25fd14..ce757105f88 100644 --- a/lib/System/Unix/Program.inc +++ b/lib/System/Unix/Program.inc @@ -34,10 +34,14 @@ namespace llvm { using namespace sys; -Program::Program() : Pid_(0) {} +Program::Program() : Data_(0) {} Program::~Program() {} +unsigned Program::GetPid() { + return reinterpret_cast(Data_); +} + // This function just uses the PATH environment variable to find the program. Path Program::FindProgramByName(const std::string& progName) { @@ -209,7 +213,7 @@ Program::Execute(const Path& path, break; } - Pid_ = child; + Data_ = reinterpret_cast(child); return true; } @@ -221,7 +225,7 @@ Program::Wait(unsigned secondsToWait, #ifdef HAVE_SYS_WAIT_H struct sigaction Act, Old; - if (Pid_ == 0) { + if (Data_ == 0) { MakeErrMsg(ErrMsg, "Process not started!"); return -1; } @@ -237,7 +241,7 @@ Program::Wait(unsigned secondsToWait, // Parent process: Wait for the child process to terminate. int status; - int child = this->Pid_; + pid_t child = reinterpret_cast(Data_); while (wait(&status) != child) if (secondsToWait && errno == EINTR) { // Kill the child. @@ -285,12 +289,13 @@ Program::Wait(unsigned secondsToWait, bool Program::Kill(std::string* ErrMsg) { - if (Pid_ == 0) { + if (Data_ == 0) { MakeErrMsg(ErrMsg, "Process not started!"); return true; } - return (kill(Pid_, SIGKILL) == 0); + pid_t pid = reinterpret_cast(Data_); + return (kill(pid, SIGKILL) == 0); } bool Program::ChangeStdinToBinary(){ diff --git a/lib/System/Win32/Program.inc b/lib/System/Win32/Program.inc index 4f4b6b32b1d..b23fdce7825 100644 --- a/lib/System/Win32/Program.inc +++ b/lib/System/Win32/Program.inc @@ -25,16 +25,21 @@ namespace llvm { using namespace sys; -Program::Program() : Pid_(0), Data(0) {} +Program::Program() : Data_(0) {} Program::~Program() { - if (Data) { - HANDLE hProcess = (HANDLE) Data; + if (Data_) { + HANDLE hProcess = reinterpret_cast(Data_); CloseHandle(hProcess); - Data = 0; + Data_ = 0; } } +unsigned Program::GetPid() { + HANDLE hProcess = reinterpret_cast(Data_); + return GetProcessId(hProcess); +} + // This function just uses the PATH environment variable to find the program. Path Program::FindProgramByName(const std::string& progName) { @@ -132,10 +137,10 @@ Program::Execute(const Path& path, const Path** redirects, unsigned memoryLimit, std::string* ErrMsg) { - if (Data) { - HANDLE hProcess = (HANDLE) Data; - CloseHandle(Data); - Data = 0; + if (Data_) { + HANDLE hProcess = reinterpret_cast(Data_); + CloseHandle(Data_); + Data_ = 0; } if (!path.canExecute()) { @@ -264,8 +269,7 @@ Program::Execute(const Path& path, path.str() + "'"); return false; } - Pid_ = pi.dwProcessId; - Data = pi.hProcess; + Data_ = reinterpret_cast(pi.hProcess); // Make sure these get closed no matter what. AutoHandle hThread(pi.hThread); @@ -301,12 +305,12 @@ Program::Execute(const Path& path, int Program::Wait(unsigned secondsToWait, std::string* ErrMsg) { - if (Data == 0) { + if (Data_ == 0) { MakeErrMsg(ErrMsg, "Process not started!"); return -1; } - HANDLE hProcess = (HANDLE) Data; + HANDLE hProcess = reinterpret_cast(Data_); // Wait for the process to terminate. DWORD millisecondsToWait = INFINITE; @@ -337,12 +341,12 @@ Program::Wait(unsigned secondsToWait, bool Program::Kill(std::string* ErrMsg) { - if (Data == 0) { + if (Data_ == 0) { MakeErrMsg(ErrMsg, "Process not started!"); return true; } - HANDLE hProcess = reinterpret_cast(Data); + HANDLE hProcess = reinterpret_cast(Data_); return TerminateProcess(hProcess, 1); } -- 2.34.1