summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2015-09-03 11:09:52 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2015-09-03 11:09:52 +0200
commit311287c30fceeeb7d4d381869763b191f7060ef1 (patch)
treea59a7b20ce4ef0adeb91fa82727af027c2a5c790
parent6a5f980a23ecda2b7bbe9ea95bc165df6a6951ad (diff)
downloadpsutil-311287c30fceeeb7d4d381869763b191f7060ef1.tar.gz
C: var names -> add py_ prefix
-rw-r--r--docs/index.rst2
-rw-r--r--psutil/_psutil_bsd.c296
-rw-r--r--psutil/_psutil_linux.c70
-rw-r--r--psutil/_psutil_osx.c175
-rw-r--r--psutil/_psutil_windows.c331
-rw-r--r--psutil/arch/bsd/process_info.c22
-rw-r--r--psutil/arch/bsd/process_info.h2
-rw-r--r--psutil/arch/osx/process_info.c25
-rw-r--r--psutil/arch/osx/process_info.h2
-rw-r--r--psutil/arch/windows/process_handles.c64
-rw-r--r--psutil/arch/windows/process_info.c14
-rw-r--r--psutil/arch/windows/process_info.h2
12 files changed, 507 insertions, 498 deletions
diff --git a/docs/index.rst b/docs/index.rst
index a27ac2fb..e8998390 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -1184,7 +1184,7 @@ Process class
`signal module <http://docs.python.org//library/signal.html>`__
constants) pre-emptively checking whether PID has been reused.
On UNIX this is the same as ``os.kill(pid, sig)``.
- On Windows only **SIGTERM**, **CTRL_C_EVENT ** and **CTRL_BREAK_EVENT**
+ On Windows only **SIGTERM**, **CTRL_C_EVENT** and **CTRL_BREAK_EVENT**
signals are supported and **SIGTERM** is treated as an alias for
:meth:`kill()`.
diff --git a/psutil/_psutil_bsd.c b/psutil/_psutil_bsd.c
index 402b9fe8..5bf6640b 100644
--- a/psutil/_psutil_bsd.c
+++ b/psutil/_psutil_bsd.c
@@ -114,10 +114,10 @@ psutil_pids(PyObject *self, PyObject *args) {
kinfo_proc *orig_address = NULL;
size_t num_processes;
size_t idx;
- PyObject *retlist = PyList_New(0);
- PyObject *pid = NULL;
+ PyObject *py_retlist = PyList_New(0);
+ PyObject *py_pid = NULL;
- if (retlist == NULL)
+ if (py_retlist == NULL)
return NULL;
if (psutil_get_proc_list(&proclist, &num_processes) != 0) {
PyErr_SetString(PyExc_RuntimeError,
@@ -128,22 +128,22 @@ psutil_pids(PyObject *self, PyObject *args) {
if (num_processes > 0) {
orig_address = proclist; // save so we can free it after we're done
for (idx = 0; idx < num_processes; idx++) {
- pid = Py_BuildValue("i", proclist->ki_pid);
+ py_pid = Py_BuildValue("i", proclist->ki_pid);
if (!pid)
goto error;
- if (PyList_Append(retlist, pid))
+ if (PyList_Append(py_retlist, py_pid))
goto error;
- Py_DECREF(pid);
+ Py_DECREF(py_pid);
proclist++;
}
free(orig_address);
}
- return retlist;
+ return py_retlist;
error:
- Py_XDECREF(pid);
- Py_DECREF(retlist);
+ Py_XDECREF(py_pid);
+ Py_DECREF(py_retlist);
if (orig_address != NULL)
free(orig_address);
return NULL;
@@ -227,19 +227,19 @@ psutil_proc_exe(PyObject *self, PyObject *args) {
static PyObject *
psutil_proc_cmdline(PyObject *self, PyObject *args) {
long pid;
- PyObject *arglist = NULL;
+ PyObject *py_retlist = NULL;
if (! PyArg_ParseTuple(args, "l", &pid))
return NULL;
// get the commandline, defined in arch/bsd/process_info.c
- arglist = psutil_get_arg_list(pid);
+ py_retlist = psutil_get_cmdline(pid);
- // psutil_get_arg_list() returns NULL only if psutil_cmd_args
+ // psutil_get_cmdline() returns NULL only if psutil_cmd_args
// failed with ESRCH (no process with that PID)
- if (NULL == arglist)
+ if (NULL == py_retlist)
return PyErr_SetFromErrno(PyExc_OSError);
- return Py_BuildValue("N", arglist);
+ return Py_BuildValue("N", py_retlist);
}
@@ -375,10 +375,10 @@ psutil_proc_threads(PyObject *self, PyObject *args) {
int error;
unsigned int i;
size_t size;
- PyObject *retList = PyList_New(0);
- PyObject *pyTuple = NULL;
+ PyObject *py_retlist = PyList_New(0);
+ PyObject *py_tuple = NULL;
- if (retList == NULL)
+ if (py_retlist == NULL)
return NULL;
if (! PyArg_ParseTuple(args, "l", &pid))
goto error;
@@ -418,22 +418,22 @@ psutil_proc_threads(PyObject *self, PyObject *args) {
for (i = 0; i < size / sizeof(*kipp); i++) {
kipp = &kip[i];
- pyTuple = Py_BuildValue("Idd",
- kipp->ki_tid,
- TV2DOUBLE(kipp->ki_rusage.ru_utime),
- TV2DOUBLE(kipp->ki_rusage.ru_stime));
- if (pyTuple == NULL)
+ py_tuple = Py_BuildValue("Idd",
+ kipp->ki_tid,
+ TV2DOUBLE(kipp->ki_rusage.ru_utime),
+ TV2DOUBLE(kipp->ki_rusage.ru_stime));
+ if (py_tuple == NULL)
goto error;
- if (PyList_Append(retList, pyTuple))
+ if (PyList_Append(py_retlist, py_tuple))
goto error;
- Py_DECREF(pyTuple);
+ Py_DECREF(py_tuple);
}
free(kip);
- return retList;
+ return py_retlist;
error:
- Py_XDECREF(pyTuple);
- Py_DECREF(retList);
+ Py_XDECREF(py_tuple);
+ Py_DECREF(py_retlist);
if (kip != NULL)
free(kip);
return NULL;
@@ -721,10 +721,10 @@ psutil_proc_open_files(PyObject *self, PyObject *args) {
struct kinfo_file *freep = NULL;
struct kinfo_file *kif;
struct kinfo_proc kipp;
- PyObject *retList = PyList_New(0);
- PyObject *tuple = NULL;
+ PyObject *py_retlist = PyList_New(0);
+ PyObject *py_tuple = NULL;
- if (retList == NULL)
+ if (py_retlist == NULL)
return NULL;
if (! PyArg_ParseTuple(args, "l", &pid))
goto error;
@@ -742,20 +742,20 @@ psutil_proc_open_files(PyObject *self, PyObject *args) {
if ((kif->kf_type == KF_TYPE_VNODE) &&
(kif->kf_vnode_type == KF_VTYPE_VREG))
{
- tuple = Py_BuildValue("(si)", kif->kf_path, kif->kf_fd);
- if (tuple == NULL)
+ py_tuple = Py_BuildValue("(si)", kif->kf_path, kif->kf_fd);
+ if (py_tuple == NULL)
goto error;
- if (PyList_Append(retList, tuple))
+ if (PyList_Append(py_retlist, py_tuple))
goto error;
- Py_DECREF(tuple);
+ Py_DECREF(py_tuple);
}
}
free(freep);
- return retList;
+ return py_retlist;
error:
- Py_XDECREF(tuple);
- Py_DECREF(retList);
+ Py_XDECREF(py_tuple);
+ Py_DECREF(py_retlist);
if (freep != NULL)
free(freep);
return NULL;
@@ -795,10 +795,10 @@ psutil_proc_num_fds(PyObject *self, PyObject *args) {
static PyObject *
psutil_proc_cwd(PyObject *self, PyObject *args) {
long pid;
- PyObject *path = NULL;
struct kinfo_file *freep = NULL;
struct kinfo_file *kif;
struct kinfo_proc kipp;
+ PyObject *py_path = NULL;
int i, cnt;
@@ -816,8 +816,8 @@ psutil_proc_cwd(PyObject *self, PyObject *args) {
for (i = 0; i < cnt; i++) {
kif = &freep[i];
if (kif->kf_fd == KF_FD_TYPE_CWD) {
- path = Py_BuildValue("s", kif->kf_path);
- if (!path)
+ py_path = Py_BuildValue("s", kif->kf_path);
+ if (!py_path)
goto error;
break;
}
@@ -827,13 +827,13 @@ psutil_proc_cwd(PyObject *self, PyObject *args) {
* (lsof can't do that it either). Since this happens even
* as root we return an empty string instead of AccessDenied.
*/
- if (path == NULL)
- path = Py_BuildValue("s", "");
+ if (py_path == NULL)
+ py_path = Py_BuildValue("s", "");
free(freep);
- return path;
+ return py_path;
error:
- Py_XDECREF(path);
+ Py_XDECREF(py_path);
if (freep != NULL)
free(freep);
return NULL;
@@ -974,20 +974,20 @@ psutil_proc_connections(PyObject *self, PyObject *args) {
char *tcplist = NULL;
struct tcpcb *tcp;
- PyObject *retList = PyList_New(0);
- PyObject *tuple = NULL;
- PyObject *laddr = NULL;
- PyObject *raddr = NULL;
- PyObject *af_filter = NULL;
- PyObject *type_filter = NULL;
- PyObject *_family = NULL;
- PyObject *_type = NULL;
+ PyObject *py_retlist = PyList_New(0);
+ PyObject *py_tuple = NULL;
+ PyObject *py_laddr = NULL;
+ PyObject *py_raddr = NULL;
+ PyObject *py_af_filter = NULL;
+ PyObject *py_type_filter = NULL;
+ PyObject *py_family = NULL;
+ PyObject *py_type = NULL;
- if (retList == NULL)
+ if (py_retlist == NULL)
return NULL;
- if (! PyArg_ParseTuple(args, "lOO", &pid, &af_filter, &type_filter))
+ if (! PyArg_ParseTuple(args, "lOO", &pid, &py_af_filter, &py_type_filter))
goto error;
- if (!PySequence_Check(af_filter) || !PySequence_Check(type_filter)) {
+ if (!PySequence_Check(py_af_filter) || !PySequence_Check(py_type_filter)) {
PyErr_SetString(PyExc_TypeError, "arg 2 or 3 is not a sequence");
goto error;
}
@@ -1009,21 +1009,21 @@ psutil_proc_connections(PyObject *self, PyObject *args) {
char lip[200], rip[200];
char path[PATH_MAX];
int inseq;
- tuple = NULL;
- laddr = NULL;
- raddr = NULL;
+ py_tuple = NULL;
+ py_laddr = NULL;
+ py_raddr = NULL;
kif = &freep[i];
if (kif->kf_type == KF_TYPE_SOCKET) {
// apply filters
- _family = PyLong_FromLong((long)kif->kf_sock_domain);
- inseq = PySequence_Contains(af_filter, _family);
- Py_DECREF(_family);
+ py_family = PyLong_FromLong((long)kif->kf_sock_domain);
+ inseq = PySequence_Contains(py_af_filter, py_family);
+ Py_DECREF(py_family);
if (inseq == 0)
continue;
- _type = PyLong_FromLong((long)kif->kf_sock_type);
- inseq = PySequence_Contains(type_filter, _type);
- Py_DECREF(_type);
+ py_type = PyLong_FromLong((long)kif->kf_sock_type);
+ inseq = PySequence_Contains(py_type_filter, py_type);
+ Py_DECREF(py_type);
if (inseq == 0)
continue;
// IPv4 / IPv6 socket
@@ -1056,27 +1056,29 @@ psutil_proc_connections(PyObject *self, PyObject *args) {
&kif->kf_sa_peer));
// construct python tuple/list
- laddr = Py_BuildValue("(si)", lip, lport);
- if (!laddr)
+ py_laddr = Py_BuildValue("(si)", lip, lport);
+ if (!py_laddr)
goto error;
if (rport != 0)
- raddr = Py_BuildValue("(si)", rip, rport);
+ py_raddr = Py_BuildValue("(si)", rip, rport);
else
- raddr = Py_BuildValue("()");
- if (!raddr)
+ py_raddr = Py_BuildValue("()");
+ if (!py_raddr)
goto error;
- tuple = Py_BuildValue("(iiiNNi)",
- kif->kf_fd,
- kif->kf_sock_domain,
- kif->kf_sock_type,
- laddr,
- raddr,
- state);
- if (!tuple)
+ py_tuple = Py_BuildValue(
+ "(iiiNNi)",
+ kif->kf_fd,
+ kif->kf_sock_domain,
+ kif->kf_sock_type,
+ py_laddr,
+ py_raddr,
+ state
+ );
+ if (!py_tuple)
goto error;
- if (PyList_Append(retList, tuple))
+ if (PyList_Append(py_retlist, py_tuple))
goto error;
- Py_DECREF(tuple);
+ Py_DECREF(py_tuple);
}
// UNIX socket
else if (kif->kf_sock_domain == AF_UNIX) {
@@ -1088,31 +1090,33 @@ psutil_proc_connections(PyObject *self, PyObject *args) {
(int)(sun->sun_len - (sizeof(*sun) - sizeof(sun->sun_path))),
sun->sun_path);
- tuple = Py_BuildValue("(iiisOi)",
- kif->kf_fd,
- kif->kf_sock_domain,
- kif->kf_sock_type,
- path,
- Py_None,
- PSUTIL_CONN_NONE);
- if (!tuple)
+ py_tuple = Py_BuildValue(
+ "(iiisOi)",
+ kif->kf_fd,
+ kif->kf_sock_domain,
+ kif->kf_sock_type,
+ path,
+ Py_None,
+ PSUTIL_CONN_NONE
+ );
+ if (!py_tuple)
goto error;
- if (PyList_Append(retList, tuple))
+ if (PyList_Append(py_retlist, py_tuple))
goto error;
- Py_DECREF(tuple);
+ Py_DECREF(py_tuple);
Py_INCREF(Py_None);
}
}
}
free(freep);
free(tcplist);
- return retList;
+ return py_retlist;
error:
- Py_XDECREF(tuple);
- Py_XDECREF(laddr);
- Py_XDECREF(raddr);
- Py_DECREF(retList);
+ Py_XDECREF(py_tuple);
+ Py_XDECREF(py_laddr);
+ Py_XDECREF(py_raddr);
+ Py_DECREF(py_retlist);
if (freep != NULL)
free(freep);
if (tcplist != NULL)
@@ -1214,10 +1218,10 @@ psutil_proc_memory_maps(PyObject *self, PyObject *args) {
struct kinfo_vmentry *freep = NULL;
struct kinfo_vmentry *kve;
ptrwidth = 2 * sizeof(void *);
- PyObject *pytuple = NULL;
- PyObject *retlist = PyList_New(0);
+ PyObject *py_tuple = NULL;
+ PyObject *py_retlist = PyList_New(0);
- if (retlist == NULL)
+ if (py_retlist == NULL)
return NULL;
if (! PyArg_ParseTuple(args, "l", &pid))
goto error;
@@ -1230,7 +1234,7 @@ psutil_proc_memory_maps(PyObject *self, PyObject *args) {
goto error;
}
for (i = 0; i < cnt; i++) {
- pytuple = NULL;
+ py_tuple = NULL;
kve = &freep[i];
addr[0] = '\0';
perms[0] = '\0';
@@ -1282,7 +1286,7 @@ psutil_proc_memory_maps(PyObject *self, PyObject *args) {
path = kve->kve_path;
}
- pytuple = Py_BuildValue("sssiiii",
+ py_tuple = Py_BuildValue("sssiiii",
addr, // "start-end" address
perms, // "rwx" permissions
path, // path
@@ -1290,18 +1294,18 @@ psutil_proc_memory_maps(PyObject *self, PyObject *args) {
kve->kve_private_resident, // private
kve->kve_ref_count, // ref count
kve->kve_shadow_count); // shadow count
- if (!pytuple)
+ if (!py_tuple)
goto error;
- if (PyList_Append(retlist, pytuple))
+ if (PyList_Append(py_retlist, py_tuple))
goto error;
- Py_DECREF(pytuple);
+ Py_DECREF(py_tuple);
}
free(freep);
- return retlist;
+ return py_retlist;
error:
- Py_XDECREF(pytuple);
- Py_DECREF(retlist);
+ Py_XDECREF(py_tuple);
+ Py_DECREF(py_retlist);
if (freep != NULL)
free(freep);
return NULL;
@@ -1581,10 +1585,10 @@ error:
*/
static PyObject *
psutil_users(PyObject *self, PyObject *args) {
- PyObject *ret_list = PyList_New(0);
- PyObject *tuple = NULL;
+ PyObject *py_retlist = PyList_New(0);
+ PyObject *py_tuple = NULL;
- if (ret_list == NULL)
+ if (py_retlist == NULL)
return NULL;
#if __FreeBSD_version < 900000
@@ -1600,21 +1604,21 @@ psutil_users(PyObject *self, PyObject *args) {
while (fread(&ut, sizeof(ut), 1, fp) == 1) {
if (*ut.ut_name == '\0')
continue;
- tuple = Py_BuildValue(
+ py_tuple = Py_BuildValue(
"(sssf)",
ut.ut_name, // username
ut.ut_line, // tty
ut.ut_host, // hostname
(float)ut.ut_time); // start time
- if (!tuple) {
+ if (!py_tuple) {
fclose(fp);
goto error;
}
- if (PyList_Append(ret_list, tuple)) {
+ if (PyList_Append(py_retlist, py_tuple)) {
fclose(fp);
goto error;
}
- Py_DECREF(tuple);
+ Py_DECREF(py_tuple);
}
fclose(fp);
@@ -1624,7 +1628,7 @@ psutil_users(PyObject *self, PyObject *args) {
while ((utx = getutxent()) != NULL) {
if (utx->ut_type != USER_PROCESS)
continue;
- tuple = Py_BuildValue(
+ py_tuple = Py_BuildValue(
"(sssf)",
utx->ut_user, // username
utx->ut_line, // tty
@@ -1632,24 +1636,24 @@ psutil_users(PyObject *self, PyObject *args) {
(float)utx->ut_tv.tv_sec // start time
);
- if (!tuple) {
+ if (!py_tuple) {
endutxent();
goto error;
}
- if (PyList_Append(ret_list, tuple)) {
+ if (PyList_Append(py_retlist, py_tuple)) {
endutxent();
goto error;
}
- Py_DECREF(tuple);
+ Py_DECREF(py_tuple);
}
endutxent();
#endif
- return ret_list;
+ return py_retlist;
error:
- Py_XDECREF(tuple);
- Py_DECREF(ret_list);
+ Py_XDECREF(py_tuple);
+ Py_DECREF(py_retlist);
return NULL;
}
@@ -1721,9 +1725,9 @@ int psutil_gather_inet(int proto, PyObject *py_retlist) {
int retry;
int type;
- PyObject *tuple = NULL;
- PyObject *laddr = NULL;
- PyObject *raddr = NULL;
+ PyObject *py_tuple = NULL;
+ PyObject *py_laddr = NULL;
+ PyObject *py_raddr = NULL;
switch (proto) {
case IPPROTO_TCP:
@@ -1818,31 +1822,31 @@ int psutil_gather_inet(int proto, PyObject *py_retlist) {
}
// construct python tuple/list
- laddr = Py_BuildValue("(si)", lip, lport);
- if (!laddr)
+ py_laddr = Py_BuildValue("(si)", lip, lport);
+ if (!py_laddr)
goto error;
if (rport != 0)
- raddr = Py_BuildValue("(si)", rip, rport);
+ py_raddr = Py_BuildValue("(si)", rip, rport);
else
- raddr = Py_BuildValue("()");
- if (!raddr)
+ py_raddr = Py_BuildValue("()");
+ if (!py_raddr)
goto error;
- tuple = Py_BuildValue("(iiiNNii)", -1, family, type, laddr, raddr,
- status, pid);
- if (!tuple)
+ py_tuple = Py_BuildValue("(iiiNNii)", -1, family, type, py_laddr,
+ py_raddr, status, pid);
+ if (!py_tuple)
goto error;
- if (PyList_Append(py_retlist, tuple))
+ if (PyList_Append(py_retlist, py_tuple))
goto error;
- Py_DECREF(tuple);
+ Py_DECREF(py_tuple);
}
free(buf);
return 1;
error:
- Py_XDECREF(tuple);
- Py_XDECREF(laddr);
- Py_XDECREF(raddr);
+ Py_XDECREF(py_tuple);
+ Py_XDECREF(py_laddr);
+ Py_XDECREF(py_raddr);
free(buf);
return 0;
}
@@ -1862,9 +1866,9 @@ int psutil_gather_unix(int proto, PyObject *py_retlist) {
struct sockaddr_un *sun;
char path[PATH_MAX];
- PyObject *tuple = NULL;
- PyObject *laddr = NULL;
- PyObject *raddr = NULL;
+ PyObject *py_tuple = NULL;
+ PyObject *py_laddr = NULL;
+ PyObject *py_raddr = NULL;
switch (proto) {
case SOCK_STREAM:
@@ -1924,13 +1928,13 @@ int psutil_gather_unix(int proto, PyObject *py_retlist) {
(int)(sun->sun_len - (sizeof(*sun) - sizeof(sun->sun_path))),
sun->sun_path);
- tuple = Py_BuildValue("(iiisOii)", -1, AF_UNIX, proto, path, Py_None,
- PSUTIL_CONN_NONE, pid);
- if (!tuple)
+ py_tuple = Py_BuildValue("(iiisOii)", -1, AF_UNIX, proto, path,
+ Py_None, PSUTIL_CONN_NONE, pid);
+ if (!py_tuple)
goto error;
- if (PyList_Append(py_retlist, tuple))
+ if (PyList_Append(py_retlist, py_tuple))
goto error;
- Py_DECREF(tuple);
+ Py_DECREF(py_tuple);
Py_INCREF(Py_None);
}
@@ -1938,9 +1942,9 @@ int psutil_gather_unix(int proto, PyObject *py_retlist) {
return 1;
error:
- Py_XDECREF(tuple);
- Py_XDECREF(laddr);
- Py_XDECREF(raddr);
+ Py_XDECREF(py_tuple);
+ Py_XDECREF(py_laddr);
+ Py_XDECREF(py_raddr);
free(buf);
return 0;
}
diff --git a/psutil/_psutil_linux.c b/psutil/_psutil_linux.c
index 0a97d667..b582a870 100644
--- a/psutil/_psutil_linux.c
+++ b/psutil/_psutil_linux.c
@@ -136,14 +136,14 @@ psutil_linux_prlimit(PyObject *self, PyObject *args) {
int ret, resource;
struct rlimit old, new;
struct rlimit *newp = NULL;
- PyObject *soft = NULL;
- PyObject *hard = NULL;
+ PyObject *py_soft = NULL;
+ PyObject *py_hard = NULL;
- if (! PyArg_ParseTuple(args, "li|OO", &pid, &resource, &soft, &hard))
+ if (! PyArg_ParseTuple(args, "li|OO", &pid, &resource, &py_soft, &py_hard))
return NULL;
// get
- if (soft == NULL && hard == NULL) {
+ if (py_soft == NULL && py_hard == NULL) {
ret = prlimit(pid, resource, NULL, &old);
if (ret == -1)
return PyErr_SetFromErrno(PyExc_OSError);
@@ -160,17 +160,17 @@ psutil_linux_prlimit(PyObject *self, PyObject *args) {
// set
else {
#if defined(PSUTIL_HAVE_LARGEFILE_SUPPORT)
- new.rlim_cur = PyLong_AsLongLong(soft);
+ new.rlim_cur = PyLong_AsLongLong(py_soft);
if (new.rlim_cur == (rlim_t) - 1 && PyErr_Occurred())
return NULL;
- new.rlim_max = PyLong_AsLongLong(hard);
+ new.rlim_max = PyLong_AsLongLong(py_hard);
if (new.rlim_max == (rlim_t) - 1 && PyErr_Occurred())
return NULL;
#else
- new.rlim_cur = PyLong_AsLong(soft);
+ new.rlim_cur = PyLong_AsLong(py_soft);
if (new.rlim_cur == (rlim_t) - 1 && PyErr_Occurred())
return NULL;
- new.rlim_max = PyLong_AsLong(hard);
+ new.rlim_max = PyLong_AsLong(py_hard);
if (new.rlim_max == (rlim_t) - 1 && PyErr_Occurred())
return NULL;
#endif
@@ -270,7 +270,7 @@ psutil_proc_cpu_affinity_get(PyObject *self, PyObject *args) {
long pid;
size_t setsize;
cpu_set_t *mask = NULL;
- PyObject *res = NULL;
+ PyObject *py_list = NULL;
if (!PyArg_ParseTuple(args, "i", &pid))
return NULL;
@@ -293,8 +293,8 @@ psutil_proc_cpu_affinity_get(PyObject *self, PyObject *args) {
ncpus = ncpus * 2;
}
- res = PyList_New(0);
- if (res == NULL)
+ py_list = PyList_New(0);
+ if (py_list == NULL)
goto error;
cpucount_s = CPU_COUNT_S(setsize, mask);
@@ -307,7 +307,7 @@ psutil_proc_cpu_affinity_get(PyObject *self, PyObject *args) {
#endif
if (cpu_num == NULL)
goto error;
- if (PyList_Append(res, cpu_num)) {
+ if (PyList_Append(py_list, cpu_num)) {
Py_DECREF(cpu_num);
goto error;
}
@@ -316,12 +316,12 @@ psutil_proc_cpu_affinity_get(PyObject *self, PyObject *args) {
}
}
CPU_FREE(mask);
- return res;
+ return py_list;
error:
if (mask)
CPU_FREE(mask);
- Py_XDECREF(res);
+ Py_XDECREF(py_list);
return NULL;
}
#else
@@ -427,42 +427,42 @@ error:
*/
static PyObject *
psutil_users(PyObject *self, PyObject *args) {
- PyObject *ret_list = PyList_New(0);
- PyObject *tuple = NULL;
- PyObject *user_proc = NULL;
struct utmp *ut;
+ PyObject *py_retlist = PyList_New(0);
+ PyObject *py_tuple = NULL;
+ PyObject *py_user_proc = NULL;
- if (ret_list == NULL)
+ if (py_retlist == NULL)
return NULL;
setutent();
while (NULL != (ut = getutent())) {
- tuple = NULL;
- user_proc = NULL;
+ py_tuple = NULL;
+ py_user_proc = NULL;
if (ut->ut_type == USER_PROCESS)
- user_proc = Py_True;
+ py_user_proc = Py_True;
else
- user_proc = Py_False;
- tuple = Py_BuildValue(
+ py_user_proc = Py_False;
+ py_tuple = Py_BuildValue(
"(sssfO)",
ut->ut_user, // username
ut->ut_line, // tty
ut->ut_host, // hostname
(float)ut->ut_tv.tv_sec, // tstamp
- user_proc // (bool) user process
+ py_user_proc // (bool) user process
);
- if (! tuple)
+ if (! py_tuple)
goto error;
- if (PyList_Append(ret_list, tuple))
+ if (PyList_Append(py_retlist, py_tuple))
goto error;
- Py_DECREF(tuple);
+ Py_DECREF(py_tuple);
}
endutent();
- return ret_list;
+ return py_retlist;
error:
- Py_XDECREF(tuple);
- Py_XDECREF(user_proc);
- Py_DECREF(ret_list);
+ Py_XDECREF(py_tuple);
+ Py_XDECREF(py_user_proc);
+ Py_DECREF(py_retlist);
endutent();
return NULL;
}
@@ -485,7 +485,7 @@ psutil_net_if_stats(PyObject* self, PyObject* args) {
struct ifreq ifr;
struct ethtool_cmd ethcmd;
PyObject *py_is_up = NULL;
- PyObject *py_ret = NULL;
+ PyObject *py_retlist = NULL;
if (! PyArg_ParseTuple(args, "s", &nic_name))
return NULL;
@@ -533,11 +533,11 @@ psutil_net_if_stats(PyObject* self, PyObject* args) {
}
close(sock);
- py_ret = Py_BuildValue("[Oiii]", py_is_up, duplex, speed, mtu);
- if (!py_ret)
+ py_retlist = Py_BuildValue("[Oiii]", py_is_up, duplex, speed, mtu);
+ if (!py_retlist)
goto error;
Py_DECREF(py_is_up);
- return py_ret;
+ return py_retlist;
error:
Py_XDECREF(py_is_up);
diff --git a/psutil/_psutil_osx.c b/psutil/_psutil_osx.c
index 2b876e76..53ad668d 100644
--- a/psutil/_psutil_osx.c
+++ b/psutil/_psutil_osx.c
@@ -73,10 +73,10 @@ psutil_pids(PyObject *self, PyObject *args) {
kinfo_proc *orig_address = NULL;
size_t num_processes;
size_t idx;
- PyObject *pid = NULL;
- PyObject *retlist = PyList_New(0);
+ PyObject *py_pid = NULL;
+ PyObject *py_retlist = PyList_New(0);
- if (retlist == NULL)
+ if (py_retlist == NULL)
return NULL;
if (psutil_get_proc_list(&proclist, &num_processes) != 0) {
@@ -89,21 +89,21 @@ psutil_pids(PyObject *self, PyObject *args) {
// save the address of proclist so we can free it later
orig_address = proclist;
for (idx = 0; idx < num_processes; idx++) {
- pid = Py_BuildValue("i", proclist->kp_proc.p_pid);
- if (!pid)
+ py_pid = Py_BuildValue("i", proclist->kp_proc.p_pid);
+ if (! py_pid)
goto error;
- if (PyList_Append(retlist, pid))
+ if (PyList_Append(py_retlist, py_pid))
goto error;
- Py_DECREF(pid);
+ Py_DECREF(py_pid);
proclist++;
}
free(orig_address);
}
- return retlist;
+ return py_retlist;
error:
- Py_XDECREF(pid);
- Py_DECREF(retlist);
+ Py_XDECREF(py_pid);
+ Py_DECREF(py_retlist);
if (orig_address != NULL)
free(orig_address);
return NULL;
@@ -173,14 +173,14 @@ psutil_proc_exe(PyObject *self, PyObject *args) {
static PyObject *
psutil_proc_cmdline(PyObject *self, PyObject *args) {
long pid;
- PyObject *arglist = NULL;
+ PyObject *py_retlist = NULL;
if (! PyArg_ParseTuple(args, "l", &pid))
return NULL;
// get the commandline, defined in arch/osx/process_info.c
- arglist = psutil_get_arg_list(pid);
- return arglist;
+ py_retlist = psutil_get_cmdline(pid);
+ return py_retlist;
}
@@ -870,10 +870,10 @@ psutil_proc_threads(PyObject *self, PyObject *args) {
thread_basic_info_t basic_info_th;
mach_msg_type_number_t thread_count, thread_info_count;
- PyObject *retList = PyList_New(0);
- PyObject *pyTuple = NULL;
+ PyObject *py_tuple = NULL;
+ PyObject *py_retlist = PyList_New(0);
- if (retList == NULL)
+ if (py_retlist == NULL)
return NULL;
// the argument passed should be a process id
@@ -913,7 +913,7 @@ psutil_proc_threads(PyObject *self, PyObject *args) {
}
for (j = 0; j < thread_count; j++) {
- pyTuple = NULL;
+ py_tuple = NULL;
thread_info_count = THREAD_INFO_MAX;
kr = thread_info(thread_list[j], THREAD_BASIC_INFO,
(thread_info_t)thinfo_basic, &thread_info_count);
@@ -924,17 +924,17 @@ psutil_proc_threads(PyObject *self, PyObject *args) {
}
basic_info_th = (thread_basic_info_t)thinfo_basic;
- pyTuple = Py_BuildValue(
+ py_tuple = Py_BuildValue(
"Iff",
j + 1,
(float)basic_info_th->user_time.microseconds / 1000000.0,
(float)basic_info_th->system_time.microseconds / 1000000.0
);
- if (!pyTuple)
+ if (!py_tuple)
goto error;
- if (PyList_Append(retList, pyTuple))
+ if (PyList_Append(py_retlist, py_tuple))
goto error;
- Py_DECREF(pyTuple);
+ Py_DECREF(py_tuple);
}
ret = vm_deallocate(task, (vm_address_t)thread_list,
@@ -944,13 +944,13 @@ psutil_proc_threads(PyObject *self, PyObject *args) {
mach_port_deallocate(mach_task_self(), task);
- return retList;
+ return py_retlist;
error:
if (task != MACH_PORT_NULL)
mach_port_deallocate(mach_task_self(), task);
- Py_XDECREF(pyTuple);
- Py_DECREF(retList);
+ Py_XDECREF(py_tuple);
+ Py_DECREF(py_retlist);
if (thread_list != NULL) {
ret = vm_deallocate(task, (vm_address_t)thread_list,
thread_count * sizeof(int));
@@ -979,10 +979,10 @@ psutil_proc_open_files(PyObject *self, PyObject *args) {
struct proc_fdinfo *fdp_pointer;
struct vnode_fdinfowithpath vi;
- PyObject *retList = PyList_New(0);
- PyObject *tuple = NULL;
+ PyObject *py_retlist = PyList_New(0);
+ PyObject *py_tuple = NULL;
- if (retList == NULL)
+ if (py_retlist == NULL)
return NULL;
if (! PyArg_ParseTuple(args, "l", &pid))
@@ -1013,7 +1013,7 @@ psutil_proc_open_files(PyObject *self, PyObject *args) {
iterations = (pidinfo_result / PROC_PIDLISTFD_SIZE);
for (i = 0; i < iterations; i++) {
- tuple = NULL;
+ py_tuple = NULL;
fdp_pointer = &fds_pointer[i];
if (fdp_pointer->proc_fdtype == PROX_FDTYPE_VNODE)
@@ -1045,24 +1045,25 @@ psutil_proc_open_files(PyObject *self, PyObject *args) {
// --- /errors checking
// --- construct python list
- tuple = Py_BuildValue("(si)",
- vi.pvip.vip_path,
- (int)fdp_pointer->proc_fd);
- if (!tuple)
+ py_tuple = Py_BuildValue(
+ "(si)",
+ vi.pvip.vip_path,
+ (int)fdp_pointer->proc_fd);
+ if (!py_tuple)
goto error;
- if (PyList_Append(retList, tuple))
+ if (PyList_Append(py_retlist, py_tuple))
goto error;
- Py_DECREF(tuple);
+ Py_DECREF(py_tuple);
// --- /construct python list
}
}
free(fds_pointer);
- return retList;
+ return py_retlist;
error:
- Py_XDECREF(tuple);
- Py_DECREF(retList);
+ Py_XDECREF(py_tuple);
+ Py_DECREF(py_retlist);
if (fds_pointer != NULL)
free(fds_pointer);
if (errno != 0)
@@ -1095,26 +1096,26 @@ psutil_proc_connections(PyObject *self, PyObject *args) {
struct proc_fdinfo *fdp_pointer;
struct socket_fdinfo si;
- PyObject *retList = PyList_New(0);
- PyObject *tuple = NULL;
- PyObject *laddr = NULL;
- PyObject *raddr = NULL;
- PyObject *af_filter = NULL;
- PyObject *type_filter = NULL;
+ PyObject *py_retlist = PyList_New(0);
+ PyObject *py_tuple = NULL;
+ PyObject *py_laddr = NULL;
+ PyObject *py_raddr = NULL;
+ PyObject *py_af_filter = NULL;
+ PyObject *py_type_filter = NULL;
- if (retList == NULL)
+ if (py_retlist == NULL)
return NULL;
- if (! PyArg_ParseTuple(args, "lOO", &pid, &af_filter, &type_filter))
+ if (! PyArg_ParseTuple(args, "lOO", &pid, &py_af_filter, &py_type_filter))
goto error;
- if (!PySequence_Check(af_filter) || !PySequence_Check(type_filter)) {
+ if (!PySequence_Check(py_af_filter) || !PySequence_Check(py_type_filter)) {
PyErr_SetString(PyExc_TypeError, "arg 2 or 3 is not a sequence");
goto error;
}
if (pid == 0)
- return retList;
+ return py_retlist;
pidinfo_result = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, NULL, 0);
if (pidinfo_result <= 0)
goto error;
@@ -1132,9 +1133,9 @@ psutil_proc_connections(PyObject *self, PyObject *args) {
iterations = (pidinfo_result / PROC_PIDLISTFD_SIZE);
for (i = 0; i < iterations; i++) {
- tuple = NULL;
- laddr = NULL;
- raddr = NULL;
+ py_tuple = NULL;
+ py_laddr = NULL;
+ py_raddr = NULL;
errno = 0;
fdp_pointer = &fds_pointer[i];
@@ -1169,22 +1170,22 @@ psutil_proc_connections(PyObject *self, PyObject *args) {
int fd, family, type, lport, rport, state;
char lip[200], rip[200];
int inseq;
- PyObject *_family;
- PyObject *_type;
+ PyObject *py_family;
+ PyObject *py_type;
fd = (int)fdp_pointer->proc_fd;
family = si.psi.soi_family;
type = si.psi.soi_type;
// apply filters
- _family = PyLong_FromLong((long)family);
- inseq = PySequence_Contains(af_filter, _family);
- Py_DECREF(_family);
+ py_family = PyLong_FromLong((long)family);
+ inseq = PySequence_Contains(py_af_filter, py_family);
+ Py_DECREF(py_family);
if (inseq == 0)
continue;
- _type = PyLong_FromLong((long)type);
- inseq = PySequence_Contains(type_filter, _type);
- Py_DECREF(_type);
+ py_type = PyLong_FromLong((long)type);
+ inseq = PySequence_Contains(py_type_filter, py_type);
+ Py_DECREF(py_type);
if (inseq == 0)
continue;
@@ -1230,50 +1231,50 @@ psutil_proc_connections(PyObject *self, PyObject *args) {
else
state = PSUTIL_CONN_NONE;
- laddr = Py_BuildValue("(si)", lip, lport);
- if (!laddr)
+ py_laddr = Py_BuildValue("(si)", lip, lport);
+ if (!py_laddr)
goto error;
if (rport != 0)
- raddr = Py_BuildValue("(si)", rip, rport);
+ py_raddr = Py_BuildValue("(si)", rip, rport);
else
- raddr = Py_BuildValue("()");
- if (!raddr)
+ py_raddr = Py_BuildValue("()");
+ if (!py_raddr)
goto error;
// construct the python list
- tuple = Py_BuildValue("(iiiNNi)", fd, family, type, laddr,
- raddr, state);
- if (!tuple)
+ py_tuple = Py_BuildValue(
+ "(iiiNNi)", fd, family, type, py_laddr, py_raddr, state);
+ if (!py_tuple)
goto error;
- if (PyList_Append(retList, tuple))
+ if (PyList_Append(py_retlist, py_tuple))
goto error;
- Py_DECREF(tuple);
+ Py_DECREF(py_tuple);
}
else if (family == AF_UNIX) {
// construct the python list
- tuple = Py_BuildValue(
+ py_tuple = Py_BuildValue(
"(iiissi)",
fd, family, type,
si.psi.soi_proto.pri_un.unsi_addr.ua_sun.sun_path,
si.psi.soi_proto.pri_un.unsi_caddr.ua_sun.sun_path,
PSUTIL_CONN_NONE);
- if (!tuple)
+ if (!py_tuple)
goto error;
- if (PyList_Append(retList, tuple))
+ if (PyList_Append(py_retlist, py_tuple))
goto error;
- Py_DECREF(tuple);
+ Py_DECREF(py_tuple);
}
}
}
free(fds_pointer);
- return retList;
+ return py_retlist;
error:
- Py_XDECREF(tuple);
- Py_XDECREF(laddr);
- Py_XDECREF(raddr);
- Py_DECREF(retList);
+ Py_XDECREF(py_tuple);
+ Py_XDECREF(py_laddr);
+ Py_XDECREF(py_raddr);
+ Py_DECREF(py_retlist);
if (fds_pointer != NULL)
free(fds_pointer);
@@ -1587,38 +1588,38 @@ error:
static PyObject *
psutil_users(PyObject *self, PyObject *args) {
struct utmpx *utx;
- PyObject *ret_list = PyList_New(0);
- PyObject *tuple = NULL;
+ PyObject *py_retlist = PyList_New(0);
+ PyObject *py_tuple = NULL;
- if (ret_list == NULL)
+ if (py_retlist == NULL)
return NULL;
while ((utx = getutxent()) != NULL) {
if (utx->ut_type != USER_PROCESS)
continue;
- tuple = Py_BuildValue(
+ py_tuple = Py_BuildValue(
"(sssf)",
utx->ut_user, // username
utx->ut_line, // tty
utx->ut_host, // hostname
(float)utx->ut_tv.tv_sec // start time
);
- if (!tuple) {
+ if (!py_tuple) {
endutxent();
goto error;
}
- if (PyList_Append(ret_list, tuple)) {
+ if (PyList_Append(py_retlist, py_tuple)) {
endutxent();
goto error;
}
- Py_DECREF(tuple);
+ Py_DECREF(py_tuple);
}
endutxent();
- return ret_list;
+ return py_retlist;
error:
- Py_XDECREF(tuple);
- Py_DECREF(ret_list);
+ Py_XDECREF(py_tuple);
+ Py_DECREF(py_retlist);
return NULL;
}
diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c
index 43ef0d47..b2fe2f53 100644
--- a/psutil/_psutil_windows.c
+++ b/psutil/_psutil_windows.c
@@ -245,22 +245,22 @@ psutil_pids(PyObject *self, PyObject *args) {
DWORD *proclist = NULL;
DWORD numberOfReturnedPIDs;
DWORD i;
- PyObject *pid = NULL;
- PyObject *retlist = PyList_New(0);
+ PyObject *py_pid = NULL;
+ PyObject *py_list = PyList_New(0);
- if (retlist == NULL)
+ if (py_list == NULL)
return NULL;
proclist = psutil_get_pids(&numberOfReturnedPIDs);
if (proclist == NULL)
goto error;
for (i = 0; i < numberOfReturnedPIDs; i++) {
- pid = Py_BuildValue("I", proclist[i]);
+ py_pid = Py_BuildValue("I", proclist[i]);
if (!pid)
goto error;
- if (PyList_Append(retlist, pid))
+ if (PyList_Append(py_list, py_pid))
goto error;
- Py_DECREF(pid);
+ Py_DECREF(py_pid);
}
// free C array allocated for PIDs
@@ -268,8 +268,8 @@ psutil_pids(PyObject *self, PyObject *args) {
return retlist;
error:
- Py_XDECREF(pid);
- Py_DECREF(retlist);
+ Py_XDECREF(py_pid);
+ Py_DECREF(py_list);
if (proclist != NULL)
free(proclist);
return NULL;
@@ -575,7 +575,7 @@ static PyObject *
psutil_proc_cmdline(PyObject *self, PyObject *args) {
long pid;
int pid_return;
- PyObject *arglist;
+ PyObject *py_list;
if (! PyArg_ParseTuple(args, "l", &pid))
return NULL;
@@ -593,14 +593,14 @@ psutil_proc_cmdline(PyObject *self, PyObject *args) {
// May fail any of several ReadProcessMemory calls etc. and
// not indicate a real problem so we ignore any errors and
// just live without commandline.
- arglist = psutil_get_arg_list(pid);
- if ( NULL == arglist ) {
+ py_list = psutil_get_cmdline(pid);
+ if ( NULL == py_list ) {
// carry on anyway, clear any exceptions too
PyErr_Clear();
return Py_BuildValue("[]");
}
- return arglist;
+ return py_list;
}
@@ -612,9 +612,9 @@ psutil_proc_exe(PyObject *self, PyObject *args) {
long pid;
HANDLE hProcess;
wchar_t exe[MAX_PATH];
+
if (! PyArg_ParseTuple(args, "l", &pid))
return NULL;
-
hProcess = psutil_handle_from_pid_waccess(pid, PROCESS_QUERY_INFORMATION);
if (NULL == hProcess)
return NULL;
@@ -851,10 +851,10 @@ psutil_per_cpu_times(PyObject *self, PyObject *args) {
SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION *sppi = NULL;
SYSTEM_INFO si;
UINT i;
- PyObject *arg = NULL;
- PyObject *retlist = PyList_New(0);
+ PyObject *py_tuple = NULL;
+ PyObject *py_list = PyList_New(0);
- if (retlist == NULL)
+ if (py_list == NULL)
return NULL;
// dynamic linking is mandatory to use NtQuerySystemInformation
@@ -887,7 +887,7 @@ psutil_per_cpu_times(PyObject *self, PyObject *args) {
// processor value
idle = user = kernel = 0;
for (i = 0; i < si.dwNumberOfProcessors; i++) {
- arg = NULL;
+ py_tuple = NULL;
user = (float)((HI_T * sppi[i].UserTime.HighPart) +
(LO_T * sppi[i].UserTime.LowPart));
idle = (float)((HI_T * sppi[i].IdleTime.HighPart) +
@@ -897,19 +897,19 @@ psutil_per_cpu_times(PyObject *self, PyObject *args) {
// kernel time includes idle time on windows
// we return only busy kernel time subtracting
// idle time from kernel time
- arg = Py_BuildValue("(ddd)",
+ py_tuple = Py_BuildValue("(ddd)",
user,
kernel - idle,
idle);
- if (!arg)
+ if (!py_tuple)
goto error;
- if (PyList_Append(retlist, arg))
+ if (PyList_Append(py_list, py_tuple))
goto error;
- Py_DECREF(arg);
+ Py_DECREF(py_tuple);
}
free(sppi);
FreeLibrary(hNtDll);
- return retlist;
+ return py_list;
} // END NtQuerySystemInformation
} // END malloc SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
@@ -918,8 +918,8 @@ psutil_per_cpu_times(PyObject *self, PyObject *args) {
goto error;
error:
- Py_XDECREF(arg);
- Py_DECREF(retlist);
+ Py_XDECREF(py_tuple);
+ Py_DECREF(py_list);
if (sppi)
free(sppi);
if (hNtDll)
@@ -941,7 +941,7 @@ psutil_proc_cwd(PyObject *self, PyObject *args) {
PVOID rtlUserProcParamsAddress;
UNICODE_STRING currentDirectory;
WCHAR *currentDirectoryContent = NULL;
- PyObject *py_cwd = NULL;
+ PyObject *py_unicode = NULL;
if (! PyArg_ParseTuple(args, "l", &pid))
return NULL;
@@ -1023,16 +1023,16 @@ psutil_proc_cwd(PyObject *self, PyObject *args) {
currentDirectoryContent[(currentDirectory.Length / sizeof(WCHAR))] = '\0';
// convert wchar array to a Python unicode string
- py_cwd = PyUnicode_FromWideChar(
+ py_unicode = PyUnicode_FromWideChar(
currentDirectoryContent, wcslen(currentDirectoryContent));
- if (py_cwd == NULL)
+ if (py_unicode == NULL)
goto error;
CloseHandle(processHandle);
free(currentDirectoryContent);
- return py_cwd;
+ return py_unicode;
error:
- Py_XDECREF(py_cwd);
+ Py_XDECREF(py_unicode);
if (currentDirectoryContent != NULL)
free(currentDirectoryContent);
if (processHandle != NULL)
@@ -1146,11 +1146,11 @@ psutil_proc_threads(PyObject *self, PyObject *args) {
int pid_return;
int rc;
FILETIME ftDummy, ftKernel, ftUser;
- PyObject *retList = PyList_New(0);
- PyObject *pyTuple = NULL;
HANDLE hThreadSnap = NULL;
+ PyObject *py_tuple = NULL;
+ PyObject *py_list = PyList_New(0);
- if (retList == NULL)
+ if (py_list == NULL)
return NULL;
if (! PyArg_ParseTuple(args, "l", &pid))
goto error;
@@ -1187,7 +1187,7 @@ psutil_proc_threads(PyObject *self, PyObject *args) {
// If the thread belongs to the process, increase the counter.
do {
if (te32.th32OwnerProcessID == pid) {
- pyTuple = NULL;
+ py_tuple = NULL;
hThread = NULL;
hThread = OpenThread(THREAD_QUERY_INFORMATION,
FALSE, te32.th32ThreadID);
@@ -1212,29 +1212,29 @@ psutil_proc_threads(PyObject *self, PyObject *args) {
* process has executed in user/kernel mode I borrowed the code
* below from Python's Modules/posixmodule.c
*/
- pyTuple = Py_BuildValue(
+ py_tuple = Py_BuildValue(
"kdd",
te32.th32ThreadID,
(double)(ftUser.dwHighDateTime * 429.4967296 + \
ftUser.dwLowDateTime * 1e-7),
(double)(ftKernel.dwHighDateTime * 429.4967296 + \
ftKernel.dwLowDateTime * 1e-7));
- if (!pyTuple)
+ if (!py_tuple)
goto error;
- if (PyList_Append(retList, pyTuple))
+ if (PyList_Append(py_list, py_tuple))
goto error;
- Py_DECREF(pyTuple);
+ Py_DECREF(py_tuple);
CloseHandle(hThread);
}
} while (Thread32Next(hThreadSnap, &te32));
CloseHandle(hThreadSnap);
- return retList;
+ return py_list;
error:
- Py_XDECREF(pyTuple);
- Py_DECREF(retList);
+ Py_XDECREF(py_tuple);
+ Py_DECREF(py_list);
if (hThread != NULL)
CloseHandle(hThread);
if (hThreadSnap != NULL)
@@ -1248,7 +1248,7 @@ psutil_proc_open_files(PyObject *self, PyObject *args) {
long pid;
HANDLE processHandle;
DWORD access = PROCESS_DUP_HANDLE | PROCESS_QUERY_INFORMATION;
- PyObject *filesList;
+ PyObject *py_list;
if (! PyArg_ParseTuple(args, "l", &pid))
return NULL;
@@ -1256,11 +1256,11 @@ psutil_proc_open_files(PyObject *self, PyObject *args) {
processHandle = psutil_handle_from_pid_waccess(pid, access);
if (processHandle == NULL)
return NULL;
- filesList = psutil_get_open_files(pid, processHandle);
+ py_list = psutil_get_open_files(pid, processHandle);
CloseHandle(processHandle);
- if (filesList == NULL)
+ if (py_list == NULL)
return PyErr_SetFromWindowsErr(0);
- return filesList;
+ return py_list;
}
@@ -1309,7 +1309,7 @@ psutil_proc_username(PyObject *self, PyObject *args) {
ULONG domainNameSize;
SID_NAME_USE nameUse;
PTSTR fullName;
- PyObject *returnObject;
+ PyObject *py_unicode;
if (! PyArg_ParseTuple(args, "l", &pid))
return NULL;
@@ -1402,7 +1402,7 @@ psutil_proc_username(PyObject *self, PyObject *args) {
memcpy(&fullName[domainNameSize + 1], name, nameSize);
fullName[domainNameSize + 1 + nameSize] = '\0';
- returnObject = PyUnicode_Decode(
+ py_unicode = PyUnicode_Decode(
fullName, _tcslen(fullName), Py_FileSystemDefaultEncoding, "replace");
free(fullName);
@@ -1410,7 +1410,7 @@ psutil_proc_username(PyObject *self, PyObject *args) {
free(domainName);
free(user);
- return returnObject;
+ return py_unicode;
}
@@ -1420,18 +1420,7 @@ psutil_proc_username(PyObject *self, PyObject *args) {
static PyObject *
psutil_net_connections(PyObject *self, PyObject *args) {
static long null_address[4] = { 0, 0, 0, 0 };
-
unsigned long pid;
- PyObject *connectionsList;
- PyObject *connectionTuple = NULL;
- PyObject *af_filter = NULL;
- PyObject *type_filter = NULL;
-
- PyObject *_AF_INET = PyLong_FromLong((long)AF_INET);
- PyObject *_AF_INET6 = PyLong_FromLong((long)AF_INET6);
- PyObject *_SOCK_STREAM = PyLong_FromLong((long)SOCK_STREAM);
- PyObject *_SOCK_DGRAM = PyLong_FromLong((long)SOCK_DGRAM);
-
typedef PSTR (NTAPI * _RtlIpv4AddressToStringA)(struct in_addr *, PSTR);
_RtlIpv4AddressToStringA rtlIpv4AddressToStringA;
typedef PSTR (NTAPI * _RtlIpv6AddressToStringA)(struct in6_addr *, PSTR);
@@ -1450,16 +1439,34 @@ psutil_net_connections(PyObject *self, PyObject *args) {
PMIB_UDP6TABLE_OWNER_PID udp6Table;
ULONG i;
CHAR addressBufferLocal[65];
- PyObject *addressTupleLocal = NULL;
CHAR addressBufferRemote[65];
- PyObject *addressTupleRemote = NULL;
- if (! PyArg_ParseTuple(args, "lOO", &pid, &af_filter, &type_filter)) {
+ PyObject *py_retlist;
+ PyObject *py_conn_tuple = NULL;
+ PyObject *py_af_filter = NULL;
+ PyObject *py_type_filter = NULL;
+ PyObject *py_addr_tuple_local = NULL;
+ PyObject *py_addr_tuple_remote = NULL;
+ PyObject *_AF_INET = PyLong_FromLong((long)AF_INET);
+ if (_AF_INET == NULL)
+ return NULL;
+ PyObject *_AF_INET6 = PyLong_FromLong((long)AF_INET6);
+ if (_AF_INET6 == NULL)
+ return NULL;
+ PyObject *_SOCK_STREAM = PyLong_FromLong((long)SOCK_STREAM);
+ if (_SOCK_STREAM == NULL)
+ return NULL;
+ PyObject *_SOCK_DGRAM = PyLong_FromLong((long)SOCK_DGRAM);
+ if (_SOCK_DGRAM == NULL)
+ return NULL;
+
+ if (! PyArg_ParseTuple(args, "lOO", &pid, &py_af_filter, &py_type_filter))
+ {
_psutil_conn_decref_objs();
return NULL;
}
- if (!PySequence_Check(af_filter) || !PySequence_Check(type_filter)) {
+ if (!PySequence_Check(py_af_filter) || !PySequence_Check(py_type_filter)) {
_psutil_conn_decref_objs();
PyErr_SetString(PyExc_TypeError, "arg 2 or 3 is not a sequence");
return NULL;
@@ -1500,21 +1507,21 @@ psutil_net_connections(PyObject *self, PyObject *args) {
return NULL;
}
- connectionsList = PyList_New(0);
- if (connectionsList == NULL) {
+ py_retlist = PyList_New(0);
+ if (py_retlist == NULL) {
_psutil_conn_decref_objs();
return NULL;
}
// TCP IPv4
- if ((PySequence_Contains(af_filter, _AF_INET) == 1) &&
- (PySequence_Contains(type_filter, _SOCK_STREAM) == 1))
+ if ((PySequence_Contains(py_af_filter, _AF_INET) == 1) &&
+ (PySequence_Contains(py_type_filter, _SOCK_STREAM) == 1))
{
table = NULL;
- connectionTuple = NULL;
- addressTupleLocal = NULL;
- addressTupleRemote = NULL;
+ py_conn_tuple = NULL;
+ py_addr_tuple_local = NULL;
+ py_addr_tuple_remote = NULL;
tableSize = 0;
getExtendedTcpTable(NULL, &tableSize, FALSE, AF_INET,
TCP_TABLE_OWNER_PID_ALL, 0);
@@ -1545,16 +1552,16 @@ psutil_net_connections(PyObject *self, PyObject *args) {
addr.S_un.S_addr = tcp4Table->table[i].dwLocalAddr;
rtlIpv4AddressToStringA(&addr, addressBufferLocal);
- addressTupleLocal = Py_BuildValue(
+ py_addr_tuple_local = Py_BuildValue(
"(si)",
addressBufferLocal,
BYTESWAP_USHORT(tcp4Table->table[i].dwLocalPort));
}
else {
- addressTupleLocal = PyTuple_New(0);
+ py_addr_tuple_local = PyTuple_New(0);
}
- if (addressTupleLocal == NULL)
+ if (py_addr_tuple_local == NULL)
goto error;
// On Windows <= XP, remote addr is filled even if socket
@@ -1567,33 +1574,33 @@ psutil_net_connections(PyObject *self, PyObject *args) {
addr.S_un.S_addr = tcp4Table->table[i].dwRemoteAddr;
rtlIpv4AddressToStringA(&addr, addressBufferRemote);
- addressTupleRemote = Py_BuildValue(
+ py_addr_tuple_remote = Py_BuildValue(
"(si)",
addressBufferRemote,
BYTESWAP_USHORT(tcp4Table->table[i].dwRemotePort));
}
else
{
- addressTupleRemote = PyTuple_New(0);
+ py_addr_tuple_remote = PyTuple_New(0);
}
- if (addressTupleRemote == NULL)
+ if (py_addr_tuple_remote == NULL)
goto error;
- connectionTuple = Py_BuildValue(
+ py_conn_tuple = Py_BuildValue(
"(iiiNNiI)",
-1,
AF_INET,
SOCK_STREAM,
- addressTupleLocal,
- addressTupleRemote,
+ py_addr_tuple_local,
+ py_addr_tuple_remote,
tcp4Table->table[i].dwState,
tcp4Table->table[i].dwOwningPid);
- if (!connectionTuple)
+ if (!py_conn_tuple)
goto error;
- if (PyList_Append(connectionsList, connectionTuple))
+ if (PyList_Append(py_retlist, py_conn_tuple))
goto error;
- Py_DECREF(connectionTuple);
+ Py_DECREF(py_conn_tuple);
}
}
@@ -1602,13 +1609,13 @@ psutil_net_connections(PyObject *self, PyObject *args) {
// TCP IPv6
- if ((PySequence_Contains(af_filter, _AF_INET6) == 1) &&
- (PySequence_Contains(type_filter, _SOCK_STREAM) == 1))
+ if ((PySequence_Contains(py_af_filter, _AF_INET6) == 1) &&
+ (PySequence_Contains(py_type_filter, _SOCK_STREAM) == 1))
{
table = NULL;
- connectionTuple = NULL;
- addressTupleLocal = NULL;
- addressTupleRemote = NULL;
+ py_conn_tuple = NULL;
+ py_addr_tuple_local = NULL;
+ py_addr_tuple_remote = NULL;
tableSize = 0;
getExtendedTcpTable(NULL, &tableSize, FALSE, AF_INET6,
TCP_TABLE_OWNER_PID_ALL, 0);
@@ -1639,16 +1646,16 @@ psutil_net_connections(PyObject *self, PyObject *args) {
memcpy(&addr, tcp6Table->table[i].ucLocalAddr, 16);
rtlIpv6AddressToStringA(&addr, addressBufferLocal);
- addressTupleLocal = Py_BuildValue(
+ py_addr_tuple_local = Py_BuildValue(
"(si)",
addressBufferLocal,
BYTESWAP_USHORT(tcp6Table->table[i].dwLocalPort));
}
else {
- addressTupleLocal = PyTuple_New(0);
+ py_addr_tuple_local = PyTuple_New(0);
}
- if (addressTupleLocal == NULL)
+ if (py_addr_tuple_local == NULL)
goto error;
// On Windows <= XP, remote addr is filled even if socket
@@ -1662,32 +1669,32 @@ psutil_net_connections(PyObject *self, PyObject *args) {
memcpy(&addr, tcp6Table->table[i].ucRemoteAddr, 16);
rtlIpv6AddressToStringA(&addr, addressBufferRemote);
- addressTupleRemote = Py_BuildValue(
+ py_addr_tuple_remote = Py_BuildValue(
"(si)",
addressBufferRemote,
BYTESWAP_USHORT(tcp6Table->table[i].dwRemotePort));
}
else {
- addressTupleRemote = PyTuple_New(0);
+ py_addr_tuple_remote = PyTuple_New(0);
}
- if (addressTupleRemote == NULL)
+ if (py_addr_tuple_remote == NULL)
goto error;
- connectionTuple = Py_BuildValue(
+ py_conn_tuple = Py_BuildValue(
"(iiiNNiI)",
-1,
AF_INET6,
SOCK_STREAM,
- addressTupleLocal,
- addressTupleRemote,
+ py_addr_tuple_local,
+ py_addr_tuple_remote,
tcp6Table->table[i].dwState,
tcp6Table->table[i].dwOwningPid);
- if (!connectionTuple)
+ if (!py_conn_tuple)
goto error;
- if (PyList_Append(connectionsList, connectionTuple))
+ if (PyList_Append(py_retlist, py_conn_tuple))
goto error;
- Py_DECREF(connectionTuple);
+ Py_DECREF(py_conn_tuple);
}
}
@@ -1696,13 +1703,13 @@ psutil_net_connections(PyObject *self, PyObject *args) {
// UDP IPv4
- if ((PySequence_Contains(af_filter, _AF_INET) == 1) &&
- (PySequence_Contains(type_filter, _SOCK_DGRAM) == 1))
+ if ((PySequence_Contains(py_af_filter, _AF_INET) == 1) &&
+ (PySequence_Contains(py_type_filter, _SOCK_DGRAM) == 1))
{
table = NULL;
- connectionTuple = NULL;
- addressTupleLocal = NULL;
- addressTupleRemote = NULL;
+ py_conn_tuple = NULL;
+ py_addr_tuple_local = NULL;
+ py_addr_tuple_remote = NULL;
tableSize = 0;
getExtendedUdpTable(NULL, &tableSize, FALSE, AF_INET,
UDP_TABLE_OWNER_PID, 0);
@@ -1733,32 +1740,32 @@ psutil_net_connections(PyObject *self, PyObject *args) {
addr.S_un.S_addr = udp4Table->table[i].dwLocalAddr;
rtlIpv4AddressToStringA(&addr, addressBufferLocal);
- addressTupleLocal = Py_BuildValue(
+ py_addr_tuple_local = Py_BuildValue(
"(si)",
addressBufferLocal,
BYTESWAP_USHORT(udp4Table->table[i].dwLocalPort));
}
else {
- addressTupleLocal = PyTuple_New(0);
+ py_addr_tuple_local = PyTuple_New(0);
}
- if (addressTupleLocal == NULL)
+ if (py_addr_tuple_local == NULL)
goto error;
- connectionTuple = Py_BuildValue(
+ py_conn_tuple = Py_BuildValue(
"(iiiNNiI)",
-1,
AF_INET,
SOCK_DGRAM,
- addressTupleLocal,
+ py_addr_tuple_local,
PyTuple_New(0),
PSUTIL_CONN_NONE,
udp4Table->table[i].dwOwningPid);
- if (!connectionTuple)
+ if (!py_conn_tuple)
goto error;
- if (PyList_Append(connectionsList, connectionTuple))
+ if (PyList_Append(py_retlist, py_conn_tuple))
goto error;
- Py_DECREF(connectionTuple);
+ Py_DECREF(py_conn_tuple);
}
}
@@ -1767,13 +1774,13 @@ psutil_net_connections(PyObject *self, PyObject *args) {
// UDP IPv6
- if ((PySequence_Contains(af_filter, _AF_INET6) == 1) &&
- (PySequence_Contains(type_filter, _SOCK_DGRAM) == 1))
+ if ((PySequence_Contains(py_af_filter, _AF_INET6) == 1) &&
+ (PySequence_Contains(py_type_filter, _SOCK_DGRAM) == 1))
{
table = NULL;
- connectionTuple = NULL;
- addressTupleLocal = NULL;
- addressTupleRemote = NULL;
+ py_conn_tuple = NULL;
+ py_addr_tuple_local = NULL;
+ py_addr_tuple_remote = NULL;
tableSize = 0;
getExtendedUdpTable(NULL, &tableSize, FALSE,
AF_INET6, UDP_TABLE_OWNER_PID, 0);
@@ -1803,32 +1810,32 @@ psutil_net_connections(PyObject *self, PyObject *args) {
memcpy(&addr, udp6Table->table[i].ucLocalAddr, 16);
rtlIpv6AddressToStringA(&addr, addressBufferLocal);
- addressTupleLocal = Py_BuildValue(
+ py_addr_tuple_local = Py_BuildValue(
"(si)",
addressBufferLocal,
BYTESWAP_USHORT(udp6Table->table[i].dwLocalPort));
}
else {
- addressTupleLocal = PyTuple_New(0);
+ py_addr_tuple_local = PyTuple_New(0);
}
- if (addressTupleLocal == NULL)
+ if (py_addr_tuple_local == NULL)
goto error;
- connectionTuple = Py_BuildValue(
+ py_conn_tuple = Py_BuildValue(
"(iiiNNiI)",
-1,
AF_INET6,
SOCK_DGRAM,
- addressTupleLocal,
+ py_addr_tuple_local,
PyTuple_New(0),
PSUTIL_CONN_NONE,
udp6Table->table[i].dwOwningPid);
- if (!connectionTuple)
+ if (!py_conn_tuple)
goto error;
- if (PyList_Append(connectionsList, connectionTuple))
+ if (PyList_Append(py_retlist, py_conn_tuple))
goto error;
- Py_DECREF(connectionTuple);
+ Py_DECREF(py_conn_tuple);
}
}
@@ -1836,14 +1843,14 @@ psutil_net_connections(PyObject *self, PyObject *args) {
}
_psutil_conn_decref_objs();
- return connectionsList;
+ return py_retlist;
error:
_psutil_conn_decref_objs();
- Py_XDECREF(connectionTuple);
- Py_XDECREF(addressTupleLocal);
- Py_XDECREF(addressTupleRemote);
- Py_DECREF(connectionsList);
+ Py_XDECREF(py_conn_tuple);
+ Py_XDECREF(py_addr_tuple_local);
+ Py_XDECREF(py_addr_tuple_remote);
+ Py_DECREF(py_retlist);
if (table != NULL)
free(table);
return NULL;
@@ -1858,14 +1865,12 @@ psutil_proc_priority_get(PyObject *self, PyObject *args) {
long pid;
DWORD priority;
HANDLE hProcess;
+
if (! PyArg_ParseTuple(args, "l", &pid))
return NULL;
-
hProcess = psutil_handle_from_pid(pid);
- if (hProcess == NULL) {
+ if (hProcess == NULL)
return NULL;
- }
-
priority = GetPriorityClass(hProcess);
CloseHandle(hProcess);
if (priority == 0) {
@@ -1885,17 +1890,13 @@ psutil_proc_priority_set(PyObject *self, PyObject *args) {
int priority;
int retval;
HANDLE hProcess;
- DWORD dwDesiredAccess = \
- PROCESS_QUERY_INFORMATION | PROCESS_SET_INFORMATION;
- if (! PyArg_ParseTuple(args, "li", &pid, &priority)) {
- return NULL;
- }
+ DWORD access = PROCESS_QUERY_INFORMATION | PROCESS_SET_INFORMATION;
- hProcess = psutil_handle_from_pid_waccess(pid, dwDesiredAccess);
- if (hProcess == NULL) {
+ if (! PyArg_ParseTuple(args, "li", &pid, &priority))
+ return NULL;
+ hProcess = psutil_handle_from_pid_waccess(pid, access);
+ if (hProcess == NULL)
return NULL;
- }
-
retval = SetPriorityClass(hProcess, priority);
CloseHandle(hProcess);
if (retval == 0) {
@@ -2142,7 +2143,6 @@ psutil_net_io_counters(PyObject *self, PyObject *args) {
MIB_IFROW *pIfRow = NULL;
PIP_ADAPTER_ADDRESSES pAddresses = NULL;
PIP_ADAPTER_ADDRESSES pCurrAddresses = NULL;
-
PyObject *py_retdict = PyDict_New();
PyObject *py_nic_info = NULL;
PyObject *py_nic_name = NULL;
@@ -2225,16 +2225,16 @@ psutil_disk_io_counters(PyObject *self, PyObject *args) {
char szDeviceDisplay[MAX_PATH];
int devNum;
PyObject *py_retdict = PyDict_New();
- PyObject *py_disk_info = NULL;
+ PyObject *py_tuple = NULL;
+
if (py_retdict == NULL)
return NULL;
-
// Apparently there's no way to figure out how many times we have
// to iterate in order to find valid drives.
// Let's assume 32, which is higher than 26, the number of letters
// in the alphabet (from A:\ to Z:\).
for (devNum = 0; devNum <= 32; ++devNum) {
- py_disk_info = NULL;
+ py_tuple = NULL;
sprintf_s(szDevice, MAX_PATH, "\\\\.\\PhysicalDrive%d", devNum);
hDevice = CreateFile(szDevice, 0, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL);
@@ -2246,7 +2246,7 @@ psutil_disk_io_counters(PyObject *self, PyObject *args) {
&dwSize, NULL))
{
sprintf_s(szDeviceDisplay, MAX_PATH, "PhysicalDrive%d", devNum);
- py_disk_info = Py_BuildValue(
+ py_tuple = Py_BuildValue(
"(IILLKK)",
diskPerformance.ReadCount,
diskPerformance.WriteCount,
@@ -2254,14 +2254,14 @@ psutil_disk_io_counters(PyObject *self, PyObject *args) {
diskPerformance.BytesWritten,
(unsigned long long)(diskPerformance.ReadTime.QuadPart * 10) / 1000,
(unsigned long long)(diskPerformance.WriteTime.QuadPart * 10) / 1000);
- if (!py_disk_info)
+ if (!py_tuple)
goto error;
if (PyDict_SetItemString(py_retdict, szDeviceDisplay,
- py_disk_info))
+ py_tuple))
{
goto error;
}
- Py_XDECREF(py_disk_info);
+ Py_XDECREF(py_tuple);
}
else {
// XXX we might get here with ERROR_INSUFFICIENT_BUFFER when
@@ -2276,7 +2276,7 @@ psutil_disk_io_counters(PyObject *self, PyObject *args) {
return py_retdict;
error:
- Py_XDECREF(py_disk_info);
+ Py_XDECREF(py_tuple);
Py_DECREF(py_retdict);
if (hDevice != NULL)
CloseHandle(hDevice);
@@ -2768,12 +2768,12 @@ error:
*/
static PyObject *
psutil_ppid_map(PyObject *self, PyObject *args) {
- PyObject *pid = NULL;
- PyObject *ppid = NULL;
- PyObject *py_retdict = PyDict_New();
HANDLE handle = NULL;
PROCESSENTRY32 pe = {0};
pe.dwSize = sizeof(PROCESSENTRY32);
+ PyObject *py_pid = NULL;
+ PyObject *py_ppid = NULL;
+ PyObject *py_retdict = PyDict_New();
if (py_retdict == NULL)
return NULL;
@@ -2786,16 +2786,16 @@ psutil_ppid_map(PyObject *self, PyObject *args) {
if (Process32First(handle, &pe)) {
do {
- pid = Py_BuildValue("I", pe.th32ProcessID);
- if (pid == NULL)
+ py_pid = Py_BuildValue("I", pe.th32ProcessID);
+ if (py_pid == NULL)
goto error;
- ppid = Py_BuildValue("I", pe.th32ParentProcessID);
- if (ppid == NULL)
+ py_ppid = Py_BuildValue("I", pe.th32ParentProcessID);
+ if (py_ppid == NULL)
goto error;
- if (PyDict_SetItem(py_retdict, pid, ppid))
+ if (PyDict_SetItem(py_retdict, py_pid, py_ppid))
goto error;
- Py_DECREF(pid);
- Py_DECREF(ppid);
+ Py_DECREF(py_pid);
+ Py_DECREF(py_ppid);
} while (Process32Next(handle, &pe));
}
@@ -2803,8 +2803,8 @@ psutil_ppid_map(PyObject *self, PyObject *args) {
return py_retdict;
error:
- Py_XDECREF(pid);
- Py_XDECREF(ppid);
+ Py_XDECREF(py_pid);
+ Py_XDECREF(py_ppid);
Py_DECREF(py_retdict);
CloseHandle(handle);
return NULL;
@@ -2845,8 +2845,9 @@ psutil_net_if_addrs(PyObject *self, PyObject *args) {
pUnicast = pCurrAddresses->FirstUnicastAddress;
py_nic_name = NULL;
- py_nic_name = PyUnicode_FromWideChar(pCurrAddresses->FriendlyName,
- wcslen(pCurrAddresses->FriendlyName));
+ py_nic_name = PyUnicode_FromWideChar(
+ pCurrAddresses->FriendlyName,
+ wcslen(pCurrAddresses->FriendlyName));
if (py_nic_name == NULL)
goto error;
diff --git a/psutil/arch/bsd/process_info.c b/psutil/arch/bsd/process_info.c
index a895a436..d343b655 100644
--- a/psutil/arch/bsd/process_info.c
+++ b/psutil/arch/bsd/process_info.c
@@ -201,15 +201,15 @@ char
// returns the command line as a python list object
PyObject *
-psutil_get_arg_list(long pid) {
+psutil_get_cmdline(long pid) {
char *argstr = NULL;
int pos = 0;
size_t argsize = 0;
- PyObject *retlist = Py_BuildValue("[]");
- PyObject *item = NULL;
+ PyObject *py_retlist = Py_BuildValue("[]");
+ PyObject *py_arg = NULL;
if (pid < 0)
- return retlist;
+ return py_retlist;
argstr = psutil_get_cmd_args(pid, &argsize);
if (argstr == NULL)
goto error;
@@ -219,22 +219,22 @@ psutil_get_arg_list(long pid) {
// separator
if (argsize > 0) {
while (pos < argsize) {
- item = Py_BuildValue("s", &argstr[pos]);
- if (!item)
+ py_arg = Py_BuildValue("s", &argstr[pos]);
+ if (!py_arg)
goto error;
- if (PyList_Append(retlist, item))
+ if (PyList_Append(py_retlist, py_arg))
goto error;
- Py_DECREF(item);
+ Py_DECREF(py_arg);
pos = pos + strlen(&argstr[pos]) + 1;
}
}
free(argstr);
- return retlist;
+ return py_retlist;
error:
- Py_XDECREF(item);
- Py_DECREF(retlist);
+ Py_XDECREF(py_arg);
+ Py_DECREF(py_retlist);
if (argstr != NULL)
free(argstr);
return NULL;
diff --git a/psutil/arch/bsd/process_info.h b/psutil/arch/bsd/process_info.h
index 858bd88a..b70ca23c 100644
--- a/psutil/arch/bsd/process_info.h
+++ b/psutil/arch/bsd/process_info.h
@@ -12,4 +12,4 @@ char *psutil_get_cmd_args(long pid, size_t *argsize);
char *psutil_get_cmd_path(long pid, size_t *pathsize);
int psutil_get_proc_list(struct kinfo_proc **procList, size_t *procCount);
int psutil_pid_exists(long pid);
-PyObject* psutil_get_arg_list(long pid);
+PyObject* psutil_get_cmdline(long pid);
diff --git a/psutil/arch/osx/process_info.c b/psutil/arch/osx/process_info.c
index e0a908e3..a165e039 100644
--- a/psutil/arch/osx/process_info.c
+++ b/psutil/arch/osx/process_info.c
@@ -127,7 +127,7 @@ psutil_get_argmax() {
// return process args as a python list
PyObject *
-psutil_get_arg_list(long pid) {
+psutil_get_cmdline(long pid) {
int mib[3];
int nargs;
int len;
@@ -136,8 +136,9 @@ psutil_get_arg_list(long pid) {
char *arg_end;
char *curr_arg;
size_t argmax;
- PyObject *arg = NULL;
- PyObject *arglist = NULL;
+
+ PyObject *py_arg = NULL;
+ PyObject *py_retlist = NULL;
// special case for PID 0 (kernel_task) where cmdline cannot be fetched
if (pid == 0)
@@ -192,17 +193,17 @@ psutil_get_arg_list(long pid) {
// iterate through arguments
curr_arg = arg_ptr;
- arglist = Py_BuildValue("[]");
- if (!arglist)
+ py_retlist = Py_BuildValue("[]");
+ if (!py_retlist)
goto error;
while (arg_ptr < arg_end && nargs > 0) {
if (*arg_ptr++ == '\0') {
- arg = Py_BuildValue("s", curr_arg);
- if (!arg)
+ py_arg = Py_BuildValue("s", curr_arg);
+ if (!py_arg)
goto error;
- if (PyList_Append(arglist, arg))
+ if (PyList_Append(py_retlist, py_arg))
goto error;
- Py_DECREF(arg);
+ Py_DECREF(py_arg);
// iterate to next arg and decrement # of args
curr_arg = arg_ptr;
nargs--;
@@ -210,11 +211,11 @@ psutil_get_arg_list(long pid) {
}
free(procargs);
- return arglist;
+ return py_retlist;
error:
- Py_XDECREF(arg);
- Py_XDECREF(arglist);
+ Py_XDECREF(py_arg);
+ Py_XDECREF(py_retlist);
if (procargs != NULL)
free(procargs);
return NULL;
diff --git a/psutil/arch/osx/process_info.h b/psutil/arch/osx/process_info.h
index c89c8570..ac71bbe3 100644
--- a/psutil/arch/osx/process_info.h
+++ b/psutil/arch/osx/process_info.h
@@ -13,4 +13,4 @@ int psutil_get_kinfo_proc(pid_t pid, struct kinfo_proc *kp);
int psutil_get_proc_list(kinfo_proc **procList, size_t *procCount);
int psutil_pid_exists(long pid);
int psutil_proc_pidinfo(long pid, int flavor, void *pti, int size);
-PyObject* psutil_get_arg_list(long pid);
+PyObject* psutil_get_cmdline(long pid);
diff --git a/psutil/arch/windows/process_handles.c b/psutil/arch/windows/process_handles.c
index 2ddfa504..433da349 100644
--- a/psutil/arch/windows/process_handles.c
+++ b/psutil/arch/windows/process_handles.c
@@ -74,9 +74,9 @@ psutil_get_open_files_ntqueryobject(long dwPid, HANDLE hProcess) {
PSYSTEM_HANDLE_TABLE_ENTRY_INFO_EX hHandle = NULL;
DWORD i = 0;
BOOLEAN error = FALSE;
- PyObject* pyListFiles = NULL;
- PyObject* pyFilePath = NULL;
DWORD dwWait = 0;
+ PyObject* py_retlist = NULL;
+ PyObject* py_path = NULL;
if (g_initialized == FALSE)
psutil_get_open_files_init(TRUE);
@@ -97,8 +97,8 @@ psutil_get_open_files_ntqueryobject(long dwPid, HANDLE hProcess) {
}
// Py_BuildValue raises an exception if NULL is returned
- pyListFiles = PyList_New(0);
- if (pyListFiles == NULL) {
+ py_retlist = PyList_New(0);
+ if (py_retlist == NULL) {
error = TRUE;
goto cleanup;
}
@@ -207,9 +207,9 @@ psutil_get_open_files_ntqueryobject(long dwPid, HANDLE hProcess) {
g_pNameBuffer->Buffer);
*/
- pyFilePath = PyUnicode_FromWideChar(g_pNameBuffer->Buffer,
+ py_path = PyUnicode_FromWideChar(g_pNameBuffer->Buffer,
g_pNameBuffer->Length/2);
- if (pyFilePath == NULL) {
+ if (py_path == NULL) {
/*
printf("[%d] PyUnicode_FromWideChar (%#x): %#x \n",
dwPid,
@@ -220,7 +220,7 @@ psutil_get_open_files_ntqueryobject(long dwPid, HANDLE hProcess) {
goto loop_cleanup;
}
- if (PyList_Append(pyListFiles, pyFilePath)) {
+ if (PyList_Append(py_retlist, py_path)) {
/*
printf("[%d] PyList_Append (%#x): %#x \n",
dwPid,
@@ -233,8 +233,8 @@ psutil_get_open_files_ntqueryobject(long dwPid, HANDLE hProcess) {
}
loop_cleanup:
- Py_XDECREF(pyFilePath);
- pyFilePath = NULL;
+ Py_XDECREF(py_path);
+ py_path = NULL;
if (g_pNameBuffer != NULL)
HeapFree(GetProcessHeap(), 0, g_pNameBuffer);
@@ -263,13 +263,13 @@ cleanup:
pHandleInfo = NULL;
if (error) {
- Py_XDECREF(pyListFiles);
- pyListFiles = NULL;
+ Py_XDECREF(py_retlist);
+ py_retlist = NULL;
}
LeaveCriticalSection(&g_cs);
- return pyListFiles;
+ return py_retlist;
}
@@ -278,12 +278,13 @@ psutil_NtQueryObject() {
DWORD dwWait = 0;
if (g_hThread == NULL)
- g_hThread = CreateThread(NULL,
- 0,
- (LPTHREAD_START_ROUTINE)psutil_NtQueryObjectThread,
- NULL,
- 0,
- NULL);
+ g_hThread = CreateThread(
+ NULL,
+ 0,
+ (LPTHREAD_START_ROUTINE)psutil_NtQueryObjectThread,
+ NULL,
+ 0,
+ NULL);
if (g_hThread == NULL)
return GetLastError();
@@ -343,8 +344,8 @@ psutil_get_open_files_getmappedfilename(long dwPid, HANDLE hProcess) {
HANDLE hMap = NULL;
DWORD i = 0;
BOOLEAN error = FALSE;
- PyObject* pyListFiles = NULL;
- PyObject* pyFilePath = NULL;
+ PyObject* py_retlist = NULL;
+ PyObject* py_path = NULL;
ULONG dwSize = 0;
LPVOID pMem = NULL;
TCHAR pszFilename[MAX_PATH+1];
@@ -359,8 +360,8 @@ psutil_get_open_files_getmappedfilename(long dwPid, HANDLE hProcess) {
}
// Py_BuildValue raises an exception if NULL is returned
- pyListFiles = PyList_New(0);
- if (pyListFiles == NULL) {
+ py_retlist = PyList_New(0);
+ if (py_retlist == NULL) {
error = TRUE;
goto cleanup;
}
@@ -444,7 +445,8 @@ psutil_get_open_files_getmappedfilename(long dwPid, HANDLE hProcess) {
goto loop_cleanup;
}
- dwSize = GetMappedFileName(GetCurrentProcess(), pMem, pszFilename, MAX_PATH);
+ dwSize = GetMappedFileName(
+ GetCurrentProcess(), pMem, pszFilename, MAX_PATH);
if (dwSize == 0) {
/*
printf("[%d] GetMappedFileName (%#x): %#x \n",
@@ -464,8 +466,8 @@ psutil_get_open_files_getmappedfilename(long dwPid, HANDLE hProcess) {
pszFilename);
*/
- pyFilePath = PyUnicode_FromWideChar(pszFilename, dwSize);
- if (pyFilePath == NULL) {
+ py_path = PyUnicode_FromWideChar(pszFilename, dwSize);
+ if (py_path == NULL) {
/*
printf("[%d] PyUnicode_FromStringAndSize (%#x): %#x \n",
dwPid,
@@ -476,7 +478,7 @@ psutil_get_open_files_getmappedfilename(long dwPid, HANDLE hProcess) {
goto loop_cleanup;
}
- if (PyList_Append(pyListFiles, pyFilePath)) {
+ if (PyList_Append(py_retlist, py_path)) {
/*
printf("[%d] PyList_Append (%#x): %#x \n",
dwPid,
@@ -488,8 +490,8 @@ psutil_get_open_files_getmappedfilename(long dwPid, HANDLE hProcess) {
}
loop_cleanup:
- Py_XDECREF(pyFilePath);
- pyFilePath = NULL;
+ Py_XDECREF(py_path);
+ py_path = NULL;
if (pMem != NULL)
UnmapViewOfFile(pMem);
@@ -524,9 +526,9 @@ cleanup:
pHandleInfo = NULL;
if (error) {
- Py_XDECREF(pyListFiles);
- pyListFiles = NULL;
+ Py_XDECREF(py_retlist);
+ py_retlist = NULL;
}
- return pyListFiles;
+ return py_retlist;
}
diff --git a/psutil/arch/windows/process_info.c b/psutil/arch/windows/process_info.c
index 84860413..a064baa7 100644
--- a/psutil/arch/windows/process_info.c
+++ b/psutil/arch/windows/process_info.c
@@ -209,7 +209,7 @@ handlep_is_running(HANDLE hProcess) {
* with given pid or NULL on error.
*/
PyObject *
-psutil_get_arg_list(long pid) {
+psutil_get_cmdline(long pid) {
int nArgs, i;
LPWSTR *szArglist = NULL;
HANDLE hProcess = NULL;
@@ -217,7 +217,7 @@ psutil_get_arg_list(long pid) {
PVOID rtlUserProcParamsAddress;
UNICODE_STRING commandLine;
WCHAR *commandLineContents = NULL;
- PyObject *py_arg = NULL;
+ PyObject *py_unicode = NULL;
PyObject *py_retlist = NULL;
hProcess = psutil_handle_from_pid(pid);
@@ -287,13 +287,13 @@ psutil_get_arg_list(long pid) {
if (py_retlist == NULL)
goto error;
for (i = 0; i < nArgs; i++) {
- py_arg = PyUnicode_FromWideChar(
+ py_unicode = PyUnicode_FromWideChar(
szArglist[i], wcslen(szArglist[i]));
- if (py_arg == NULL)
+ if (py_unicode == NULL)
goto error;
- if (PyList_Append(py_retlist, py_arg))
+ if (PyList_Append(py_retlist, py_unicode))
goto error;
- Py_XDECREF(py_arg);
+ Py_XDECREF(py_unicode);
}
}
@@ -304,7 +304,7 @@ psutil_get_arg_list(long pid) {
return py_retlist;
error:
- Py_XDECREF(py_arg);
+ Py_XDECREF(py_unicode);
Py_XDECREF(py_retlist);
if (hProcess != NULL)
CloseHandle(hProcess);
diff --git a/psutil/arch/windows/process_info.h b/psutil/arch/windows/process_info.h
index a44c4ace..c2699192 100644
--- a/psutil/arch/windows/process_info.h
+++ b/psutil/arch/windows/process_info.h
@@ -19,7 +19,7 @@ int psutil_handlep_is_running(HANDLE hProcess);
int psutil_pid_in_proclist(DWORD pid);
int psutil_pid_is_running(DWORD pid);
PVOID psutil_get_peb_address(HANDLE ProcessHandle);
-PyObject* psutil_get_arg_list(long pid);
+PyObject* psutil_get_cmdline(long pid);
int psutil_get_proc_info(DWORD pid, PSYSTEM_PROCESS_INFORMATION *retProcess,
PVOID *retBuffer);