[llvm-commits] [llvm] r82548 - /llvm/trunk/lib/System/Win32/Program.inc

Mikhail Glushenkov foldr at codedgers.com
Tue Sep 22 08:40:33 PDT 2009


Author: foldr
Date: Tue Sep 22 10:40:32 2009
New Revision: 82548

URL: http://llvm.org/viewvc/llvm-project?rev=82548&view=rev
Log:
Remove the GetProcessId() call from Win32/Program.inc, take 2.

GetProcessId() was introduced only in Windows XP, and we want to support earlier
versions.

Modified:
    llvm/trunk/lib/System/Win32/Program.inc

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

==============================================================================
--- llvm/trunk/lib/System/Win32/Program.inc (original)
+++ llvm/trunk/lib/System/Win32/Program.inc Tue Sep 22 10:40:32 2009
@@ -22,6 +22,13 @@
 //===          and must not be UNIX code
 //===----------------------------------------------------------------------===//
 
+namespace {
+  struct Win32ProcessInfo {
+    HANDLE hProcess;
+    DWORD  dwProcessId;
+  };
+}
+
 namespace llvm {
 using namespace sys;
 
@@ -29,15 +36,16 @@
 
 Program::~Program() {
   if (Data_) {
-    HANDLE hProcess = reinterpret_cast<HANDLE>(Data_);
-    CloseHandle(hProcess);
+    Win32ProcessInfo* wpi = reinterpret_cast<Win32ProcessInfo*>(Data_);
+    CloseHandle(wpi->hProcess);
+    delete wpi;
     Data_ = 0;
   }
 }
 
 unsigned Program::GetPid() const {
-  HANDLE hProcess = reinterpret_cast<HANDLE>(Data_);
-  return GetProcessId(hProcess);
+  Win32ProcessInfo* wpi = reinterpret_cast<Win32ProcessInfo*>(Data_);
+  return wpi->dwProcessId;
 }
 
 // This function just uses the PATH environment variable to find the program.
@@ -138,8 +146,9 @@
                  unsigned memoryLimit,
                  std::string* ErrMsg) {
   if (Data_) {
-    HANDLE hProcess = reinterpret_cast<HANDLE>(Data_);
-    CloseHandle(Data_);
+    Win32ProcessInfo* wpi = reinterpret_cast<Win32ProcessInfo*>(Data_);
+    CloseHandle(wpi->hProcess);
+    delete wpi;
     Data_ = 0;
   }
 
@@ -269,7 +278,10 @@
                path.str() + "'");
     return false;
   }
-  Data_ = reinterpret_cast<void*>(pi.hProcess);
+  Win32ProcessInfo* wpi = new Win32ProcessInfo;
+  wpi->hProcess = pi.hProcess;
+  wpi->dwProcessId = pi.dwProcessId;
+  Data_ = wpi;
 
   // Make sure these get closed no matter what.
   AutoHandle hThread(pi.hThread);
@@ -310,7 +322,8 @@
     return -1;
   }
 
-  HANDLE hProcess = reinterpret_cast<HANDLE>(Data_);
+  Win32ProcessInfo* wpi = reinterpret_cast<Win32ProcessInfo*>(Data_);
+  HANDLE hProcess = wpi->hProcess;
 
   // Wait for the process to terminate.
   DWORD millisecondsToWait = INFINITE;
@@ -346,7 +359,8 @@
     return true;
   }
 
-  HANDLE hProcess = reinterpret_cast<HANDLE>(Data_);
+  Win32ProcessInfo* wpi = reinterpret_cast<Win32ProcessInfo*>(Data_);
+  HANDLE hProcess = wpi->hProcess;
   if (TerminateProcess(hProcess, 1) == 0) {
     MakeErrMsg(ErrMsg, "The process couldn't be killed!");
     return true;





More information about the llvm-commits mailing list