Skip to content

Commit

Permalink
fix #446: get rid of the unicode hack for net_io_counters() on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Dec 31, 2014
1 parent e93f2cc commit ac0da3f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Bug tracker at https://github.com/giampaolo/psutil/issues

**Bug fixes**

- #446: [Windows] get rid of the unicode hack for net_io_counters() NIC names.
- #496: [Solaris] can't import psutil.
- #547: [UNIX] Process.username() may raise KeyError if UID can't be resolved.
- #556: [Linux] lots of file handles were left open.
Expand Down
16 changes: 2 additions & 14 deletions psutil/_psutil_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -2342,21 +2342,9 @@ psutil_net_io_counters(PyObject *self, PyObject *args)
goto error;

sprintf(ifname, "%wS", pCurrAddresses->FriendlyName);
py_nic_name = PyUnicode_Decode(
ifname, _tcslen(ifname), Py_FileSystemDefaultEncoding, "replace");

#if PY_MAJOR_VERSION >= 3
// XXX - Dirty hack to avoid encoding errors on Python 3, see:
// https://github.com/giampaolo/psutil/issues/446#c9
for (i = 0; i < MAX_PATH; i++) {
if (*(ifname+i) < 0 || *(ifname+i) > 256) {
// replace the non unicode character
*(ifname+i) = '?';
}
else if (*(ifname+i) == '\0') {
break;
}
}
#endif
py_nic_name = Py_BuildValue("s", ifname);
if (py_nic_name == NULL)
goto error;
if (PyDict_SetItem(py_retdict, py_nic_name, py_nic_info))
Expand Down

0 comments on commit ac0da3f

Please sign in to comment.