[PATCH] llvm::sys::process: Use GetCurrentProcessId to get PID on Windows
Kim Gräsman
kim.grasman at gmail.com
Thu Jun 6 00:44:34 PDT 2013
Hi chandlerc,
llvm::sys::process::get_id() didn't return the PID on Windows, but the process handle.
I don't know if this was intentional, but it caused confusion here:
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20130603/080917.html
It seems more congruent to have both platforms return the actual process ID and in an integer type.
This patch makes process::id_type an unsigned long on Windows, and uses GetCurrentProcessId to get the actual PID.
http://llvm-reviews.chandlerc.com/D923
Files:
include/llvm/Support/Process.h
lib/Support/Windows/Process.inc
unittests/Support/ProcessTest.cpp
Index: include/llvm/Support/Process.h
===================================================================
--- include/llvm/Support/Process.h
+++ include/llvm/Support/Process.h
@@ -50,13 +50,13 @@
public:
/// \brief Operating system specific type to identify a process.
///
- /// Note that the windows one is defined to 'void *' as this is the
- /// documented type for HANDLE on windows, and we don't want to pull in the
+ /// Note that the windows one is defined to 'unsigned long' as this is the
+ /// documented type for DWORD on windows, and we don't want to pull in the
/// Windows headers here.
#if defined(LLVM_ON_UNIX)
typedef pid_t id_type;
#elif defined(LLVM_ON_WIN32)
- typedef void *id_type; // Must match the type of HANDLE.
+ typedef unsigned long id_type; // Must match the type of DWORD.
#else
#error Unsupported operating system.
#endif
Index: lib/Support/Windows/Process.inc
===================================================================
--- lib/Support/Windows/Process.inc
+++ lib/Support/Windows/Process.inc
@@ -40,7 +40,7 @@
process::id_type self_process::get_id() {
- return GetCurrentProcess();
+ return GetCurrentProcessId();
}
static TimeValue getTimeValueFromFILETIME(FILETIME Time) {
Index: unittests/Support/ProcessTest.cpp
===================================================================
--- unittests/Support/ProcessTest.cpp
+++ unittests/Support/ProcessTest.cpp
@@ -26,7 +26,7 @@
#if defined(LLVM_ON_UNIX)
EXPECT_EQ(getpid(), process::get_self()->get_id());
#elif defined(LLVM_ON_WIN32)
- EXPECT_EQ(GetCurrentProcess(), process::get_self()->get_id());
+ EXPECT_EQ(GetCurrentProcessId(), process::get_self()->get_id());
#endif
EXPECT_LT(1u, process::get_self()->page_size());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D923.1.patch
Type: text/x-patch
Size: 1762 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130606/3bb7b24a/attachment.bin>
More information about the llvm-commits
mailing list