summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--psutil/_psutil_bsd.c22
-rw-r--r--psutil/_psutil_common.c23
-rw-r--r--psutil/_psutil_common.h6
-rw-r--r--psutil/_psutil_osx.c16
-rw-r--r--psutil/arch/bsd/freebsd.c12
-rw-r--r--psutil/arch/bsd/freebsd_socks.c4
-rw-r--r--psutil/arch/bsd/netbsd.c2
-rw-r--r--psutil/arch/bsd/netbsd_socks.c4
-rw-r--r--psutil/arch/osx/process_info.c4
9 files changed, 44 insertions, 49 deletions
diff --git a/psutil/_psutil_bsd.c b/psutil/_psutil_bsd.c
index a3c3d56a..a8ff93fa 100644
--- a/psutil/_psutil_bsd.c
+++ b/psutil/_psutil_bsd.c
@@ -215,7 +215,7 @@ psutil_proc_oneshot_info(PyObject *self, PyObject *args) {
#elif defined(PSUTIL_OPENBSD) || defined(PSUTIL_NETBSD)
sprintf(str, "%s", kp.p_comm);
#endif
- py_name = psutil_PyUnicode_DecodeFSDefault(str);
+ py_name = PyUnicode_DecodeFSDefault(str);
if (! py_name) {
// Likely a decoding error. We don't want to fail the whole
// operation. The python module may retry with proc_name().
@@ -368,7 +368,7 @@ psutil_proc_name(PyObject *self, PyObject *args) {
#elif defined(PSUTIL_OPENBSD) || defined(PSUTIL_NETBSD)
sprintf(str, "%s", kp.p_comm);
#endif
- return psutil_PyUnicode_DecodeFSDefault(str);
+ return PyUnicode_DecodeFSDefault(str);
}
@@ -499,7 +499,7 @@ psutil_proc_open_files(PyObject *self, PyObject *args) {
// XXX - it appears path is not exposed in the kinfo_file struct.
path = "";
#endif
- py_path = psutil_PyUnicode_DecodeFSDefault(path);
+ py_path = PyUnicode_DecodeFSDefault(path);
if (! py_path)
goto error;
if (regular == 1) {
@@ -656,10 +656,10 @@ psutil_disk_partitions(PyObject *self, PyObject *args) {
if (flags & MNT_NODEVMTIME)
strlcat(opts, ",nodevmtime", sizeof(opts));
#endif
- py_dev = psutil_PyUnicode_DecodeFSDefault(fs[i].f_mntfromname);
+ py_dev = PyUnicode_DecodeFSDefault(fs[i].f_mntfromname);
if (! py_dev)
goto error;
- py_mountp = psutil_PyUnicode_DecodeFSDefault(fs[i].f_mntonname);
+ py_mountp = PyUnicode_DecodeFSDefault(fs[i].f_mntonname);
if (! py_mountp)
goto error;
py_tuple = Py_BuildValue("(OOss)",
@@ -812,13 +812,13 @@ psutil_users(PyObject *self, PyObject *args) {
while (fread(&ut, sizeof(ut), 1, fp) == 1) {
if (*ut.ut_name == '\0')
continue;
- py_username = psutil_PyUnicode_DecodeFSDefault(ut.ut_name);
+ py_username = PyUnicode_DecodeFSDefault(ut.ut_name);
if (! py_username)
goto error;
- py_tty = psutil_PyUnicode_DecodeFSDefault(ut.ut_line);
+ py_tty = PyUnicode_DecodeFSDefault(ut.ut_line);
if (! py_tty)
goto error;
- py_hostname = psutil_PyUnicode_DecodeFSDefault(ut.ut_host);
+ py_hostname = PyUnicode_DecodeFSDefault(ut.ut_host);
if (! py_hostname)
goto error;
py_tuple = Py_BuildValue(
@@ -850,13 +850,13 @@ psutil_users(PyObject *self, PyObject *args) {
while ((utx = getutxent()) != NULL) {
if (utx->ut_type != USER_PROCESS)
continue;
- py_username = psutil_PyUnicode_DecodeFSDefault(utx->ut_user);
+ py_username = PyUnicode_DecodeFSDefault(utx->ut_user);
if (! py_username)
goto error;
- py_tty = psutil_PyUnicode_DecodeFSDefault(utx->ut_line);
+ py_tty = PyUnicode_DecodeFSDefault(utx->ut_line);
if (! py_tty)
goto error;
- py_hostname = psutil_PyUnicode_DecodeFSDefault(utx->ut_host);
+ py_hostname = PyUnicode_DecodeFSDefault(utx->ut_host);
if (! py_hostname)
goto error;
py_tuple = Py_BuildValue(
diff --git a/psutil/_psutil_common.c b/psutil/_psutil_common.c
index ab88b99b..bcbd623b 100644
--- a/psutil/_psutil_common.c
+++ b/psutil/_psutil_common.c
@@ -37,26 +37,19 @@ AccessDenied(void) {
/*
- * Alias for PyUnicode_DecodeFSDefault which is not available
- * on Python 2. On Python 2 we just return a plain byte string
+ * Backport of unicode FS APIs from Python 3.
+ * On Python 2 we just return a plain byte string
* which is never supposed to raise decoding errors.
* See: https://github.com/giampaolo/psutil/issues/1040
*/
+#if PY_MAJOR_VERSION < 3
PyObject *
-psutil_PyUnicode_DecodeFSDefault(char *s) {
-#if PY_MAJOR_VERSION >= 3
- return PyUnicode_DecodeFSDefault(s);
-#else
- return Py_BuildValue("s", s);
-#endif
+PyUnicode_DecodeFSDefault(char *s) {
+ return PyString_FromString(s);
}
-
-PyObject*
-psutil_PyUnicode_DecodeFSDefaultAndSize(char *s, Py_ssize_t size) {
-#if PY_MAJOR_VERSION >= 3
- return PyUnicode_DecodeFSDefaultAndSize(s, size);
-#else
+PyObject *
+PyUnicode_DecodeFSDefaultAndSize(char *s, Py_ssize_t size) {
return PyString_FromStringAndSize(s, size);
-#endif
}
+#endif \ No newline at end of file
diff --git a/psutil/_psutil_common.h b/psutil/_psutil_common.h
index 84916d2d..0507458a 100644
--- a/psutil/_psutil_common.h
+++ b/psutil/_psutil_common.h
@@ -8,5 +8,7 @@
PyObject* AccessDenied(void);
PyObject* NoSuchProcess(void);
-PyObject* psutil_PyUnicode_DecodeFSDefault(char *s);
-PyObject* psutil_PyUnicode_DecodeFSDefaultAndSize(char *s, Py_ssize_t size);
+#if PY_MAJOR_VERSION < 3
+PyObject* PyUnicode_DecodeFSDefault(char *s);
+PyObject* PyUnicode_DecodeFSDefaultAndSize(char *s, Py_ssize_t size);
+#endif \ No newline at end of file
diff --git a/psutil/_psutil_osx.c b/psutil/_psutil_osx.c
index 59b7c804..536500f5 100644
--- a/psutil/_psutil_osx.c
+++ b/psutil/_psutil_osx.c
@@ -138,7 +138,7 @@ psutil_proc_kinfo_oneshot(PyObject *self, PyObject *args) {
if (psutil_get_kinfo_proc(pid, &kp) == -1)
return NULL;
- py_name = psutil_PyUnicode_DecodeFSDefault(kp.kp_proc.p_comm);
+ py_name = PyUnicode_DecodeFSDefault(kp.kp_proc.p_comm);
if (! py_name) {
// Likely a decoding error. We don't want to fail the whole
// operation. The python module may retry with proc_name().
@@ -220,7 +220,7 @@ psutil_proc_name(PyObject *self, PyObject *args) {
return NULL;
if (psutil_get_kinfo_proc(pid, &kp) == -1)
return NULL;
- return psutil_PyUnicode_DecodeFSDefault(kp.kp_proc.p_comm);
+ return PyUnicode_DecodeFSDefault(kp.kp_proc.p_comm);
}
@@ -241,7 +241,7 @@ psutil_proc_cwd(PyObject *self, PyObject *args) {
return NULL;
}
- return psutil_PyUnicode_DecodeFSDefault(pathinfo.pvi_cdir.vip_path);
+ return PyUnicode_DecodeFSDefault(pathinfo.pvi_cdir.vip_path);
}
@@ -265,7 +265,7 @@ psutil_proc_exe(PyObject *self, PyObject *args) {
psutil_raise_for_pid(pid, "proc_pidpath() syscall failed");
return NULL;
}
- return psutil_PyUnicode_DecodeFSDefault(buf);
+ return PyUnicode_DecodeFSDefault(buf);
}
@@ -416,7 +416,7 @@ psutil_proc_memory_maps(PyObject *self, PyObject *args) {
}
}
- py_path = psutil_PyUnicode_DecodeFSDefault(buf);
+ py_path = PyUnicode_DecodeFSDefault(buf);
if (! py_path)
goto error;
py_tuple = Py_BuildValue(
@@ -1141,7 +1141,7 @@ psutil_proc_open_files(PyObject *self, PyObject *args) {
// --- /errors checking
// --- construct python list
- py_path = psutil_PyUnicode_DecodeFSDefault(vi.pvip.vip_path);
+ py_path = PyUnicode_DecodeFSDefault(vi.pvip.vip_path);
if (! py_path)
goto error;
py_tuple = Py_BuildValue(
@@ -1337,11 +1337,11 @@ psutil_proc_connections(PyObject *self, PyObject *args) {
Py_DECREF(py_tuple);
}
else if (family == AF_UNIX) {
- py_laddr = psutil_PyUnicode_DecodeFSDefault(
+ py_laddr = PyUnicode_DecodeFSDefault(
si.psi.soi_proto.pri_un.unsi_addr.ua_sun.sun_path);
if (!py_laddr)
goto error;
- py_raddr = psutil_PyUnicode_DecodeFSDefault(
+ py_raddr = PyUnicode_DecodeFSDefault(
si.psi.soi_proto.pri_un.unsi_caddr.ua_sun.sun_path);
if (!py_raddr)
goto error;
diff --git a/psutil/arch/bsd/freebsd.c b/psutil/arch/bsd/freebsd.c
index 9a1f952c..11594b9d 100644
--- a/psutil/arch/bsd/freebsd.c
+++ b/psutil/arch/bsd/freebsd.c
@@ -238,7 +238,7 @@ psutil_get_cmdline(long pid) {
// separator
if (argsize > 0) {
while (pos < argsize) {
- py_arg = psutil_PyUnicode_DecodeFSDefault(&argstr[pos]);
+ py_arg = PyUnicode_DecodeFSDefault(&argstr[pos]);
if (!py_arg)
goto error;
if (PyList_Append(py_retlist, py_arg))
@@ -288,7 +288,7 @@ psutil_proc_exe(PyObject *self, PyObject *args) {
if (error == -1) {
// see: https://github.com/giampaolo/psutil/issues/907
if (errno == ENOENT)
- return psutil_PyUnicode_DecodeFSDefault("");
+ return PyUnicode_DecodeFSDefault("");
else
return PyErr_SetFromErrno(PyExc_OSError);
}
@@ -302,7 +302,7 @@ psutil_proc_exe(PyObject *self, PyObject *args) {
strcpy(pathname, "");
}
- return psutil_PyUnicode_DecodeFSDefault(pathname);
+ return PyUnicode_DecodeFSDefault(pathname);
}
@@ -555,7 +555,7 @@ psutil_proc_cwd(PyObject *self, PyObject *args) {
for (i = 0; i < cnt; i++) {
kif = &freep[i];
if (kif->kf_fd == KF_FD_TYPE_CWD) {
- py_path = psutil_PyUnicode_DecodeFSDefault(kif->kf_path);
+ py_path = PyUnicode_DecodeFSDefault(kif->kf_path);
if (!py_path)
goto error;
break;
@@ -567,7 +567,7 @@ psutil_proc_cwd(PyObject *self, PyObject *args) {
* as root we return an empty string instead of AccessDenied.
*/
if (py_path == NULL)
- py_path = psutil_PyUnicode_DecodeFSDefault("");
+ py_path = PyUnicode_DecodeFSDefault("");
free(freep);
return py_path;
@@ -821,7 +821,7 @@ psutil_proc_memory_maps(PyObject *self, PyObject *args) {
path = kve->kve_path;
}
- py_path = psutil_PyUnicode_DecodeFSDefault(path);
+ py_path = PyUnicode_DecodeFSDefault(path);
if (! py_path)
goto error;
py_tuple = Py_BuildValue("ssOiiii",
diff --git a/psutil/arch/bsd/freebsd_socks.c b/psutil/arch/bsd/freebsd_socks.c
index 708ff893..28695658 100644
--- a/psutil/arch/bsd/freebsd_socks.c
+++ b/psutil/arch/bsd/freebsd_socks.c
@@ -417,7 +417,7 @@ int psutil_gather_unix(int proto, PyObject *py_retlist) {
snprintf(path, sizeof(path), "%.*s",
(int)(sun->sun_len - (sizeof(*sun) - sizeof(sun->sun_path))),
sun->sun_path);
- py_lpath = psutil_PyUnicode_DecodeFSDefault(path);
+ py_lpath = PyUnicode_DecodeFSDefault(path);
if (! py_lpath)
goto error;
@@ -604,7 +604,7 @@ psutil_proc_connections(PyObject *self, PyObject *args) {
(int)(sun->sun_len - (sizeof(*sun) - sizeof(sun->sun_path))),
sun->sun_path);
- py_laddr = psutil_PyUnicode_DecodeFSDefault(path);
+ py_laddr = PyUnicode_DecodeFSDefault(path);
if (! py_laddr)
goto error;
diff --git a/psutil/arch/bsd/netbsd.c b/psutil/arch/bsd/netbsd.c
index 6a17b45e..5748000f 100644
--- a/psutil/arch/bsd/netbsd.c
+++ b/psutil/arch/bsd/netbsd.c
@@ -383,7 +383,7 @@ psutil_get_cmdline(pid_t pid) {
// separator
if (argsize > 0) {
while (pos < argsize) {
- py_arg = psutil_PyUnicode_DecodeFSDefault(&argstr[pos]);
+ py_arg = PyUnicode_DecodeFSDefault(&argstr[pos]);
if (!py_arg)
goto error;
if (PyList_Append(py_retlist, py_arg))
diff --git a/psutil/arch/bsd/netbsd_socks.c b/psutil/arch/bsd/netbsd_socks.c
index ae3ac3f1..06b7c755 100644
--- a/psutil/arch/bsd/netbsd_socks.c
+++ b/psutil/arch/bsd/netbsd_socks.c
@@ -406,10 +406,10 @@ psutil_net_connections(PyObject *self, PyObject *args) {
strcpy(laddr, sun_src->sun_path);
strcpy(raddr, sun_dst->sun_path);
status = PSUTIL_CONN_NONE;
- py_laddr = psutil_PyUnicode_DecodeFSDefault(laddr);
+ py_laddr = PyUnicode_DecodeFSDefault(laddr);
if (! py_laddr)
goto error;
- py_raddr = psutil_PyUnicode_DecodeFSDefault(raddr);
+ py_raddr = PyUnicode_DecodeFSDefault(raddr);
if (! py_raddr)
goto error;
}
diff --git a/psutil/arch/osx/process_info.c b/psutil/arch/osx/process_info.c
index ee395629..7d6861a5 100644
--- a/psutil/arch/osx/process_info.c
+++ b/psutil/arch/osx/process_info.c
@@ -177,7 +177,7 @@ psutil_get_cmdline(long pid) {
goto error;
while (arg_ptr < arg_end && nargs > 0) {
if (*arg_ptr++ == '\0') {
- py_arg = psutil_PyUnicode_DecodeFSDefault(curr_arg);
+ py_arg = PyUnicode_DecodeFSDefault(curr_arg);
if (! py_arg)
goto error;
if (PyList_Append(py_retlist, py_arg))
@@ -289,7 +289,7 @@ psutil_get_environ(long pid) {
arg_ptr = s + 1;
}
- py_ret = psutil_PyUnicode_DecodeFSDefaultAndSize(
+ py_ret = PyUnicode_DecodeFSDefaultAndSize(
procenv, arg_ptr - env_start + 1);
if (!py_ret) {
// XXX: don't want to free() this as per: