Skip to content

Commit

Permalink
#1040 fix unicode for memory_maps() on osx
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed May 1, 2017
1 parent 9c22b44 commit d93a437
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 8 additions & 2 deletions psutil/_psutil_osx.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ psutil_proc_memory_maps(PyObject *self, PyObject *args) {
vm_size_t size = 0;

PyObject *py_tuple = NULL;
PyObject *py_path = NULL;
PyObject *py_list = PyList_New(0);

if (py_list == NULL)
Expand Down Expand Up @@ -431,11 +432,14 @@ psutil_proc_memory_maps(PyObject *self, PyObject *args) {
}
}

py_path = psutil_PyUnicode_DecodeFSDefault(buf);
if (! py_path)
goto error;
py_tuple = Py_BuildValue(
"sssIIIIIH",
"ssOIIIIIH",
addr_str, // "start-end"address
perms, // "rwx" permissions
buf, // path
py_path, // path
info.pages_resident * pagesize, // rss
info.pages_shared_now_private * pagesize, // private
info.pages_swapped_out * pagesize, // swapped
Expand All @@ -448,6 +452,7 @@ psutil_proc_memory_maps(PyObject *self, PyObject *args) {
if (PyList_Append(py_list, py_tuple))
goto error;
Py_DECREF(py_tuple);
Py_DECREF(py_path);
}

// increment address for the next map/file
Expand All @@ -463,6 +468,7 @@ psutil_proc_memory_maps(PyObject *self, PyObject *args) {
if (task != MACH_PORT_NULL)
mach_port_deallocate(mach_task_self(), task);
Py_XDECREF(py_tuple);
Py_XDECREF(py_path);
Py_DECREF(py_list);
return NULL;
}
Expand Down
8 changes: 2 additions & 6 deletions psutil/arch/osx/process_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,8 @@ psutil_get_cmdline(long pid) {
goto error;
while (arg_ptr < arg_end && nargs > 0) {
if (*arg_ptr++ == '\0') {
#if PY_MAJOR_VERSION >= 3
py_arg = PyUnicode_DecodeFSDefault(curr_arg);
#else
py_arg = Py_BuildValue("s", curr_arg);
#endif
if (!py_arg)
py_arg = psutil_PyUnicode_DecodeFSDefault(curr_arg);
if (! py_arg)
goto error;
if (PyList_Append(py_retlist, py_arg))
goto error;
Expand Down

0 comments on commit d93a437

Please sign in to comment.