diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2015-02-12 15:12:47 +0100 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2015-02-12 15:12:47 +0100 |
commit | cc5d4885c8c3dca2c0aea8e6baf34cff7aa95e32 (patch) | |
tree | a67cce52e95a5179a470ea05fe654f2fb8cc1230 | |
parent | 3f016bf2dec467b5dfa51ceca887984349b4162e (diff) | |
download | psutil-cc5d4885c8c3dca2c0aea8e6baf34cff7aa95e32.tar.gz |
#250: use int instead of PyObject
-rw-r--r-- | psutil/_psutil_bsd.c | 11 | ||||
-rw-r--r-- | psutil/_psutil_linux.c | 11 |
2 files changed, 6 insertions, 16 deletions
diff --git a/psutil/_psutil_bsd.c b/psutil/_psutil_bsd.c index eb75ba83..5a7bad1a 100644 --- a/psutil/_psutil_bsd.c +++ b/psutil/_psutil_bsd.c @@ -2316,11 +2316,11 @@ psutil_net_if_stats(PyObject *self, PyObject *args) int ret; int duplex; int speed; + int mtu; struct ifreq ifr; struct ifmediareq ifmed; PyObject *py_is_up = NULL; - PyObject *py_mtu = NULL; if (! PyArg_ParseTuple(args, "s", &nic_name)) return NULL; @@ -2344,10 +2344,7 @@ psutil_net_if_stats(PyObject *self, PyObject *args) ret = ioctl(sock, SIOCGIFMTU, &ifr); if (ret == -1) goto error; - py_mtu = Py_BuildValue("i", ifr.ifr_mtu); - if (!py_mtu) - goto error; - Py_INCREF(py_mtu); + mtu = ifr.ifr_mtu; // speed / duplex memset(&ifmed, 0, sizeof(struct ifmediareq)); @@ -2369,13 +2366,11 @@ psutil_net_if_stats(PyObject *self, PyObject *args) close(sock); Py_DECREF(py_is_up); - Py_DECREF(py_mtu); - return Py_BuildValue("[OiiO]", py_is_up, duplex, speed, py_mtu); + return Py_BuildValue("[Oiii]", py_is_up, duplex, speed, mtu); error: Py_XDECREF(py_is_up); - Py_XDECREF(py_mtu); if (sock != 0) close(sock); PyErr_SetFromErrno(PyExc_OSError); diff --git a/psutil/_psutil_linux.c b/psutil/_psutil_linux.c index 1161378c..1eee2a9d 100644 --- a/psutil/_psutil_linux.c +++ b/psutil/_psutil_linux.c @@ -494,10 +494,10 @@ psutil_net_if_stats(PyObject* self, PyObject* args) int ret; int duplex; int speed; + int mtu; struct ifreq ifr; struct ethtool_cmd ethcmd; PyObject *py_is_up = NULL; - PyObject *py_mtu = NULL; PyObject *py_ret = NULL; if (! PyArg_ParseTuple(args, "s", &nic_name)) @@ -522,10 +522,7 @@ psutil_net_if_stats(PyObject* self, PyObject* args) ret = ioctl(sock, SIOCGIFMTU, &ifr); if (ret == -1) goto error; - py_mtu = Py_BuildValue("i", ifr.ifr_mtu); - if (!py_mtu) - goto error; - Py_INCREF(py_mtu); + mtu = ifr.ifr_mtu; // duplex and speed memset(ðcmd, 0, sizeof ethcmd); @@ -549,16 +546,14 @@ psutil_net_if_stats(PyObject* self, PyObject* args) } close(sock); - py_ret = Py_BuildValue("[OiiO]", py_is_up, duplex, speed, py_mtu); + py_ret = Py_BuildValue("[Oiii]", py_is_up, duplex, speed, mtu); if (!py_ret) goto error; Py_DECREF(py_is_up); - Py_DECREF(py_mtu); return py_ret; error: Py_XDECREF(py_is_up); - Py_XDECREF(py_mtu); if (sock != 0) close(sock); PyErr_SetFromErrno(PyExc_OSError); |