summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Sommerseth <davids@redhat.com>2013-12-20 01:46:01 +0100
committerDavid Sommerseth <davids@redhat.com>2013-12-20 01:46:01 +0100
commitd4bc3a50bb6124a0000879f27d43e9685934d682 (patch)
tree90bba459968245d81f7b76a67d8f6e6b20d1b889
parent50704634080bb653e899ff4a1d730968fb731398 (diff)
downloadpython-ethtool-d4bc3a50bb6124a0000879f27d43e9685934d682.tar.gz
python-ethtool-d4bc3a50bb6124a0000879f27d43e9685934d682.tar.xz
python-ethtool-d4bc3a50bb6124a0000879f27d43e9685934d682.zip
Make the device string a python object as well
This will simplify to "pythonize" struct etherinfo further. Signed-off-by: David Sommerseth <davids@redhat.com>
-rw-r--r--python-ethtool/etherinfo.c9
-rw-r--r--python-ethtool/etherinfo_obj.c8
-rw-r--r--python-ethtool/etherinfo_struct.h2
-rw-r--r--python-ethtool/ethtool.c2
4 files changed, 12 insertions, 9 deletions
diff --git a/python-ethtool/etherinfo.c b/python-ethtool/etherinfo.c
index 61fe037..88cefc8 100644
--- a/python-ethtool/etherinfo.c
+++ b/python-ethtool/etherinfo.c
@@ -52,8 +52,7 @@ void free_etherinfo(struct etherinfo *ptr)
return;
}
- free(ptr->device);
-
+ Py_XDECREF(ptr->device);
Py_XDECREF(ptr->hwaddress);
free(ptr);
@@ -145,7 +144,7 @@ static int _set_device_index(struct etherinfo *ethinf)
return 0;
}
- link = rtnl_link_get_by_name(link_cache, ethinf->device);
+ link = rtnl_link_get_by_name(link_cache, PyString_AsString(ethinf->device));
if( !link ) {
nl_cache_free(link_cache);
return 0;
@@ -185,7 +184,7 @@ int get_etherinfo_link(etherinfo_py *self)
if( !open_netlink(self) ) {
PyErr_Format(PyExc_RuntimeError,
"Could not open a NETLINK connection for %s",
- ethinf->device);
+ PyString_AsString(ethinf->device));
return 0;
}
@@ -235,7 +234,7 @@ PyObject * get_etherinfo_address(etherinfo_py *self, nlQuery query)
if( !open_netlink(self) ) {
PyErr_Format(PyExc_RuntimeError,
"Could not open a NETLINK connection for %s",
- ethinf->device);
+ PyString_AsString(ethinf->device));
return NULL;
}
diff --git a/python-ethtool/etherinfo_obj.c b/python-ethtool/etherinfo_obj.c
index 7885a48..07e4b58 100644
--- a/python-ethtool/etherinfo_obj.c
+++ b/python-ethtool/etherinfo_obj.c
@@ -138,7 +138,8 @@ PyObject *_ethtool_etherinfo_getter(etherinfo_py *self, PyObject *attr_o)
if( strcmp(attr, "device") == 0 ) {
if( self->ethinfo->device ) {
- return PyString_FromString(self->ethinfo->device);
+ Py_INCREF(self->ethinfo->device);
+ return self->ethinfo->device;
} else {
return Py_INCREF(Py_None), Py_None;
}
@@ -215,7 +216,10 @@ PyObject *_ethtool_etherinfo_str(etherinfo_py *self)
get_etherinfo_link(self);
- ret = PyString_FromFormat("Device %s:\n", self->ethinfo->device);
+ ret = PyString_FromFormat("Device ");
+ PyString_Concat(&ret, self->ethinfo->device);
+ PyString_ConcatAndDel(&ret, PyString_FromString(":\n"));
+
if( self->ethinfo->hwaddress ) {
PyString_ConcatAndDel(&ret, PyString_FromString("\tMAC address: "));
PyString_Concat(&ret, self->ethinfo->hwaddress);
diff --git a/python-ethtool/etherinfo_struct.h b/python-ethtool/etherinfo_struct.h
index ffa6254..83d06fe 100644
--- a/python-ethtool/etherinfo_struct.h
+++ b/python-ethtool/etherinfo_struct.h
@@ -33,7 +33,7 @@
*
*/
struct etherinfo {
- char *device; /**< Device name */
+ PyObject *device; /**< Device name */
int index; /**< NETLINK index reference */
PyObject *hwaddress; /**< string: HW address / MAC address of device */
};
diff --git a/python-ethtool/ethtool.c b/python-ethtool/ethtool.c
index 7d2a243..e37bcf1 100644
--- a/python-ethtool/ethtool.c
+++ b/python-ethtool/ethtool.c
@@ -281,7 +281,7 @@ static PyObject *get_interfaces_info(PyObject *self __unused, PyObject *args) {
/* Store the device name and a reference to the NETLINK connection for
* objects to use when quering for device info
*/
- ethinfo->device = strdup(fetch_devs[i]);
+ ethinfo->device = PyString_FromString(fetch_devs[i]);
ethinfo->index = -1;
/* Instantiate a new etherinfo object with the device information */