summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2015-08-26 06:03:44 -0700
committerGiampaolo Rodola <g.rodola@gmail.com>2015-08-26 06:03:44 -0700
commit0847640d3ed3108051377042cdf1b1d811cd07c5 (patch)
tree77f7f4484b5885df2a67cb0b1c1b8c613a96bded
parent064e65ede4c6fe0cc35887c4593de99d0243b7b0 (diff)
downloadpsutil-0847640d3ed3108051377042cdf1b1d811cd07c5.tar.gz
#655: have Process.name() fallback method return unicode instead of str
-rw-r--r--HISTORY.rst11
-rw-r--r--psutil/_psutil_windows.c11
2 files changed, 16 insertions, 6 deletions
diff --git a/HISTORY.rst b/HISTORY.rst
index 1d175594..9e7188b4 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -7,12 +7,21 @@ Bug tracker at https://github.com/giampaolo/psutil/issues
- #648: CI test integration for OSX. (patch by Jeff Tang)
- #663: net_if_addrs() now returns point-to-point addresses (for VPNs).
+- #655: [Windows] str/uniocde unification. Different methods returning a string
+ now return unicode on both Python 2 and 3:
+ - net_if_stats
+ - net_io_counters
+ - users
+ - Process.username
+ - Process.name
+ - Process.cmdline
**Bug fixes**
- #513: [Linux] fixed integer overflow for RLIM_INFINITY.
- #641: [Windows] fixed many compilation warnings. (patch by Jeff Tang)
-- #655: [Windows] net_if_stats unicode error in in case of non-ASCII NIC names.
+- #655: [Windows] net_if_stats UnicodeDecodeError in case of non-ASCII NIC
+ names.
- #659: [Linux] compilation error on Suse 10.
- #664: [Linux] compilation error on Alpine Linux. (patch by Bart van Kleef)
- #670: [Windows] segfgault of net_if_addrs() in case of non-ASCII NIC names.
diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c
index 07345f0f..a6bf28bc 100644
--- a/psutil/_psutil_windows.c
+++ b/psutil/_psutil_windows.c
@@ -638,7 +638,7 @@ static PyObject *
psutil_proc_name(PyObject *self, PyObject *args) {
long pid;
int ok;
- PROCESSENTRY32 pentry;
+ PROCESSENTRY32W pentry;
HANDLE hSnapShot;
if (! PyArg_ParseTuple(args, "l", &pid))
@@ -648,8 +648,8 @@ psutil_proc_name(PyObject *self, PyObject *args) {
PyErr_SetFromWindowsErr(0);
return NULL;
}
- pentry.dwSize = sizeof(PROCESSENTRY32);
- ok = Process32First(hSnapShot, &pentry);
+ pentry.dwSize = sizeof(PROCESSENTRY32W);
+ ok = Process32FirstW(hSnapShot, &pentry);
if (! ok) {
CloseHandle(hSnapShot);
PyErr_SetFromWindowsErr(0);
@@ -658,9 +658,10 @@ psutil_proc_name(PyObject *self, PyObject *args) {
while (ok) {
if (pentry.th32ProcessID == pid) {
CloseHandle(hSnapShot);
- return Py_BuildValue("s", pentry.szExeFile);
+ return PyUnicode_FromWideChar(
+ pentry.szExeFile, wcslen(pentry.szExeFile));
}
- ok = Process32Next(hSnapShot, &pentry);
+ ok = Process32NextW(hSnapShot, &pentry);
}
CloseHandle(hSnapShot);