<div dir="ltr">I think this CL introduced a memory leak. The daily leak report went from 0 to not 0 between June 4 and June 5 and this is the only CL that touched C code.</div><div class="gmail_extra"><br><br><div class="gmail_quote">

On Wed, Jun 5, 2013 at 6:31 PM, richard.oudkerk <span dir="ltr"><<a href="mailto:python-checkins@python.org" target="_blank">python-checkins@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<a href="http://hg.python.org/cpython/rev/0410bf251e10" target="_blank">http://hg.python.org/cpython/rev/0410bf251e10</a><br>
changeset:   84045:0410bf251e10<br>
user:        Richard Oudkerk <<a href="mailto:shibturn@gmail.com">shibturn@gmail.com</a>><br>
date:        Wed Jun 05 23:29:30 2013 +0100<br>
summary:<br>
  Issue #17931: Resolve confusion on Windows between pids and process handles.<br>
<br>
files:<br>
  Include/longobject.h  |  13 +++++++++++++<br>
  Misc/NEWS             |   5 ++---<br>
  Modules/posixmodule.c |  25 +++++++++----------------<br>
  PC/msvcrtmodule.c     |   5 +++--<br>
  PC/pyconfig.h         |   4 ++--<br>
  5 files changed, 29 insertions(+), 23 deletions(-)<br>
<br>
<br>
diff --git a/Include/longobject.h b/Include/longobject.h<br>
--- a/Include/longobject.h<br>
+++ b/Include/longobject.h<br>
@@ -52,6 +52,19 @@<br>
 #error "sizeof(pid_t) is neither sizeof(int), sizeof(long) or sizeof(long long)"<br>
 #endif /* SIZEOF_PID_T */<br>
<br>
+#if SIZEOF_VOID_P == SIZEOF_INT<br>
+#  define _Py_PARSE_INTPTR "i"<br>
+#  define _Py_PARSE_UINTPTR "I"<br>
+#elif SIZEOF_VOID_P == SIZEOF_LONG<br>
+#  define _Py_PARSE_INTPTR "l"<br>
+#  define _Py_PARSE_UINTPTR "k"<br>
+#elif defined(SIZEOF_LONG_LONG) && SIZEOF_VOID_P == SIZEOF_LONG_LONG<br>
+#  define _Py_PARSE_INTPTR "L"<br>
+#  define _Py_PARSE_UINTPTR "K"<br>
+#else<br>
+#  error "void* different in size from int, long and long long"<br>
+#endif /* SIZEOF_VOID_P */<br>
+<br>
 /* Used by Python/mystrtoul.c. */<br>
 #ifndef Py_LIMITED_API<br>
 PyAPI_DATA(unsigned char) _PyLong_DigitValue[256];<br>
diff --git a/Misc/NEWS b/Misc/NEWS<br>
--- a/Misc/NEWS<br>
+++ b/Misc/NEWS<br>
@@ -10,9 +10,8 @@<br>
 Core and Builtins<br>
 -----------------<br>
<br>
-- Issue #17931: Fix PyLong_FromPid() on Windows 64-bit: processes are<br>
-  identified by their HANDLE which is a pointer (and not a long, which is<br>
-  smaller).<br>
+- Issue #17931: Resolve confusion on Windows between pids and process<br>
+  handles.<br>
<br>
 - Tweak the exception message when the magic number or size value in a bytecode<br>
   file is truncated.<br>
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c<br>
--- a/Modules/posixmodule.c<br>
+++ b/Modules/posixmodule.c<br>
@@ -5014,11 +5014,7 @@<br>
     if (spawnval == -1)<br>
         return posix_error();<br>
     else<br>
-#if SIZEOF_LONG == SIZEOF_VOID_P<br>
-        return Py_BuildValue("l", (long) spawnval);<br>
-#else<br>
-        return Py_BuildValue("L", (PY_LONG_LONG) spawnval);<br>
-#endif<br>
+        return Py_BuildValue(_Py_PARSE_INTPTR, spawnval);<br>
 }<br>
<br>
<br>
@@ -5104,11 +5100,7 @@<br>
     if (spawnval == -1)<br>
         (void) posix_error();<br>
     else<br>
-#if SIZEOF_LONG == SIZEOF_VOID_P<br>
-        res = Py_BuildValue("l", (long) spawnval);<br>
-#else<br>
-        res = Py_BuildValue("L", (PY_LONG_LONG) spawnval);<br>
-#endif<br>
+        res = Py_BuildValue(_Py_PARSE_INTPTR, spawnval);<br>
<br>
     while (--envc >= 0)<br>
         PyMem_DEL(envlist[envc]);<br>
@@ -6178,16 +6170,17 @@<br>
 win32_kill(PyObject *self, PyObject *args)<br>
 {<br>
     PyObject *result;<br>
-    DWORD pid, sig, err;<br>
+    pid_t pid;<br>
+    DWORD sig, err;<br>
     HANDLE handle;<br>
<br>
-    if (!PyArg_ParseTuple(args, "kk:kill", &pid, &sig))<br>
+    if (!PyArg_ParseTuple(args, _Py_PARSE_PID "k:kill", &pid, &sig))<br>
         return NULL;<br>
<br>
     /* Console processes which share a common console can be sent CTRL+C or<br>
        CTRL+BREAK events, provided they handle said events. */<br>
     if (sig == CTRL_C_EVENT || sig == CTRL_BREAK_EVENT) {<br>
-        if (GenerateConsoleCtrlEvent(sig, pid) == 0) {<br>
+        if (GenerateConsoleCtrlEvent(sig, (DWORD)pid) == 0) {<br>
             err = GetLastError();<br>
             PyErr_SetFromWindowsErr(err);<br>
         }<br>
@@ -6197,7 +6190,7 @@<br>
<br>
     /* If the signal is outside of what GenerateConsoleCtrlEvent can use,<br>
        attempt to open and terminate the process. */<br>
-    handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);<br>
+    handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, (DWORD)pid);<br>
     if (handle == NULL) {<br>
         err = GetLastError();<br>
         return PyErr_SetFromWindowsErr(err);<br>
@@ -6603,7 +6596,7 @@<br>
     Py_intptr_t pid;<br>
     int status, options;<br>
<br>
-    if (!PyArg_ParseTuple(args, _Py_PARSE_PID "i:waitpid", &pid, &options))<br>
+    if (!PyArg_ParseTuple(args, _Py_PARSE_INTPTR "i:waitpid", &pid, &options))<br>
         return NULL;<br>
     Py_BEGIN_ALLOW_THREADS<br>
     pid = _cwait(&status, pid, options);<br>
@@ -6612,7 +6605,7 @@<br>
         return posix_error();<br>
<br>
     /* shift the status left a byte so this is more like the POSIX waitpid */<br>
-    return Py_BuildValue("Ni", PyLong_FromPid(pid), status << 8);<br>
+    return Py_BuildValue(_Py_PARSE_INTPTR "i", pid, status << 8);<br>
 }<br>
 #endif /* HAVE_WAITPID || HAVE_CWAIT */<br>
<br>
diff --git a/PC/msvcrtmodule.c b/PC/msvcrtmodule.c<br>
--- a/PC/msvcrtmodule.c<br>
+++ b/PC/msvcrtmodule.c<br>
@@ -113,11 +113,12 @@<br>
 static PyObject *<br>
 msvcrt_open_osfhandle(PyObject *self, PyObject *args)<br>
 {<br>
-    long handle;<br>
+    Py_intptr_t handle;<br>
     int flags;<br>
     int fd;<br>
<br>
-    if (!PyArg_ParseTuple(args, "li:open_osfhandle", &handle, &flags))<br>
+    if (!PyArg_ParseTuple(args, _Py_PARSE_INTPTR "i:open_osfhandle",<br>
+                          &handle, &flags))<br>
         return NULL;<br>
<br>
     fd = _open_osfhandle(handle, flags);<br>
diff --git a/PC/pyconfig.h b/PC/pyconfig.h<br>
--- a/PC/pyconfig.h<br>
+++ b/PC/pyconfig.h<br>
@@ -723,8 +723,8 @@<br>
 /* The size of `wchar_t', as computed by sizeof. */<br>
 #define SIZEOF_WCHAR_T 2<br>
<br>
-/* The size of `pid_t' (HANDLE). */<br>
-#define SIZEOF_PID_T SIZEOF_VOID_P<br>
+/* The size of `pid_t', as computed by sizeof. */<br>
+#define SIZEOF_PID_T SIZEOF_INT<br>
<br>
 /* Define if you have the dl library (-ldl).  */<br>
 /* #undef HAVE_LIBDL */<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Repository URL: <a href="http://hg.python.org/cpython" target="_blank">http://hg.python.org/cpython</a><br>
</font></span><br>_______________________________________________<br>
Python-checkins mailing list<br>
<a href="mailto:Python-checkins@python.org">Python-checkins@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-checkins" target="_blank">http://mail.python.org/mailman/listinfo/python-checkins</a><br>
<br></blockquote></div><br></div>