summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2020-01-24 19:32:55 +0000
committerGiampaolo Rodola <g.rodola@gmail.com>2020-01-24 19:32:55 +0000
commitf5f4dd4f5ea6c885b9592760c3141c8d5252ab2c (patch)
tree4634f3a530a0ea0ae613c64f5d4900ab9b91350b
parent65b447f63880ebffdbd7522f09d436d2f0707d57 (diff)
downloadpsutil-f5f4dd4f5ea6c885b9592760c3141c8d5252ab2c.tar.gz
use PyLong_FromPid
-rw-r--r--psutil/_psutil_bsd.c4
-rw-r--r--psutil/arch/freebsd/sys_socks.c11
2 files changed, 10 insertions, 5 deletions
diff --git a/psutil/_psutil_bsd.c b/psutil/_psutil_bsd.c
index a20a8333..b117fd50 100644
--- a/psutil/_psutil_bsd.c
+++ b/psutil/_psutil_bsd.c
@@ -142,9 +142,9 @@ psutil_pids(PyObject *self, PyObject *args) {
orig_address = proclist; // save so we can free it after we're done
for (idx = 0; idx < num_processes; idx++) {
#ifdef PSUTIL_FREEBSD
- py_pid = Py_BuildValue("i", proclist->ki_pid);
+ py_pid = PyLong_FromPid(proclist->ki_pid);
#elif defined(PSUTIL_OPENBSD) || defined(PSUTIL_NETBSD)
- py_pid = Py_BuildValue("i", proclist->p_pid);
+ py_pid = PyLong_FromPid(proclist->p_pid);
#endif
if (!py_pid)
goto error;
diff --git a/psutil/arch/freebsd/sys_socks.c b/psutil/arch/freebsd/sys_socks.c
index e0e2046b..c4edfcea 100644
--- a/psutil/arch/freebsd/sys_socks.c
+++ b/psutil/arch/freebsd/sys_socks.c
@@ -91,6 +91,7 @@ int psutil_gather_inet(int proto, PyObject *py_retlist) {
PyObject *py_tuple = NULL;
PyObject *py_laddr = NULL;
PyObject *py_raddr = NULL;
+ PyObject *py_pid = NULL;
switch (proto) {
case IPPROTO_TCP:
@@ -129,7 +130,7 @@ int psutil_gather_inet(int proto, PyObject *py_retlist) {
} while (xig->xig_gen != exig->xig_gen && retry--);
for (;;) {
- struct xfile *xf;
+ struct xfile *xf;
int lport, rport, status, family;
xig = (struct xinpgen *)(void *)((char *)xig + xig->xig_len);
@@ -202,15 +203,18 @@ int psutil_gather_inet(int proto, PyObject *py_retlist) {
py_raddr = Py_BuildValue("()");
if (!py_raddr)
goto error;
+ py_pid = PyLong_FromPid(xf->xf_pid);
+ if (! py_pid)
+ goto error;
py_tuple = Py_BuildValue(
- "(iiiNNii)",
+ "(iiiNNiO)",
xf->xf_fd, // fd
family, // family
type, // type
py_laddr, // laddr
py_raddr, // raddr
status, // status
- xf->xf_pid); // pid
+ py_pid); // pid
if (!py_tuple)
goto error;
if (PyList_Append(py_retlist, py_tuple))
@@ -225,6 +229,7 @@ error:
Py_XDECREF(py_tuple);
Py_XDECREF(py_laddr);
Py_XDECREF(py_raddr);
+ Py_XDECREF(py_pid);
free(buf);
return 0;
}