[llvm-commits] [llvm] r81247 - in /llvm/trunk: include/llvm/System/Program.h lib/System/Unix/Program.inc lib/System/Win32/Program.inc

Mikhail Glushenkov foldr at codedgers.com
Tue Sep 8 12:50:55 PDT 2009


Author: foldr
Date: Tue Sep  8 14:50:55 2009
New Revision: 81247

URL: http://llvm.org/viewvc/llvm-project?rev=81247&view=rev
Log:
Get rid of the Pid_ member in the Program class.

Modified:
    llvm/trunk/include/llvm/System/Program.h
    llvm/trunk/lib/System/Unix/Program.inc
    llvm/trunk/lib/System/Win32/Program.inc

Modified: llvm/trunk/include/llvm/System/Program.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/System/Program.h?rev=81247&r1=81246&r2=81247&view=diff

==============================================================================
--- llvm/trunk/include/llvm/System/Program.h (original)
+++ llvm/trunk/include/llvm/System/Program.h Tue Sep  8 14:50:55 2009
@@ -30,9 +30,7 @@
   /// @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 @@
     ~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

Modified: llvm/trunk/lib/System/Unix/Program.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Unix/Program.inc?rev=81247&r1=81246&r2=81247&view=diff

==============================================================================
--- llvm/trunk/lib/System/Unix/Program.inc (original)
+++ llvm/trunk/lib/System/Unix/Program.inc Tue Sep  8 14:50:55 2009
@@ -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<unsigned>(Data_);
+}
+
 // This function just uses the PATH environment variable to find the program.
 Path
 Program::FindProgramByName(const std::string& progName) {
@@ -209,7 +213,7 @@
       break;
   }
 
-  Pid_ = child;
+  Data_ = reinterpret_cast<void*>(child);
 
   return true;
 }
@@ -221,7 +225,7 @@
 #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 @@
 
   // Parent process: Wait for the child process to terminate.
   int status;
-  int child = this->Pid_;
+  pid_t child = reinterpret_cast<pid_t>(Data_);
   while (wait(&status) != child)
     if (secondsToWait && errno == EINTR) {
       // Kill the child.
@@ -285,12 +289,13 @@
 
 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<pid_t>(Data_);
+  return (kill(pid, SIGKILL) == 0);
 }
 
 bool Program::ChangeStdinToBinary(){

Modified: llvm/trunk/lib/System/Win32/Program.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Win32/Program.inc?rev=81247&r1=81246&r2=81247&view=diff

==============================================================================
--- llvm/trunk/lib/System/Win32/Program.inc (original)
+++ llvm/trunk/lib/System/Win32/Program.inc Tue Sep  8 14:50:55 2009
@@ -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<HANDLE>(Data_);
     CloseHandle(hProcess);
-    Data = 0;
+    Data_ = 0;
   }
 }
 
+unsigned Program::GetPid() {
+  HANDLE hProcess = reinterpret_cast<HANDLE>(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 @@
                  const Path** redirects,
                  unsigned memoryLimit,
                  std::string* ErrMsg) {
-  if (Data) {
-    HANDLE hProcess = (HANDLE) Data;
-    CloseHandle(Data);
-    Data = 0;
+  if (Data_) {
+    HANDLE hProcess = reinterpret_cast<HANDLE>(Data_);
+    CloseHandle(Data_);
+    Data_ = 0;
   }
 
   if (!path.canExecute()) {
@@ -264,8 +269,7 @@
                path.str() + "'");
     return false;
   }
-  Pid_ = pi.dwProcessId;
-  Data = pi.hProcess;
+  Data_ = reinterpret_cast<void*>(pi.hProcess);
 
   // Make sure these get closed no matter what.
   AutoHandle hThread(pi.hThread);
@@ -301,12 +305,12 @@
 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<HANDLE>(Data_);
 
   // Wait for the process to terminate.
   DWORD millisecondsToWait = INFINITE;
@@ -337,12 +341,12 @@
 
 bool
 Program::Kill(std::string* ErrMsg) {
-  if (Data == 0) {
+  if (Data_ == 0) {
     MakeErrMsg(ErrMsg, "Process not started!");
     return true;
   }
 
-  HANDLE hProcess = reinterpret_cast<HANDLE>(Data);
+  HANDLE hProcess = reinterpret_cast<HANDLE>(Data_);
   return TerminateProcess(hProcess, 1);
 }
 





More information about the llvm-commits mailing list