summaryrefslogtreecommitdiffstats
path: root/python-ethtool/ethtool.c
diff options
context:
space:
mode:
authorDavid Sommerseth <davids@redhat.com>2013-12-20 02:20:21 +0100
committerDavid Sommerseth <davids@redhat.com>2013-12-20 02:22:48 +0100
commit54a6b0bea9e210c0377c3510d8819df59c009d64 (patch)
tree7795a60a1e63de04e1f8d44680c26d75025d2990 /python-ethtool/ethtool.c
parentd4bc3a50bb6124a0000879f27d43e9685934d682 (diff)
downloadpython-ethtool-54a6b0bea9e210c0377c3510d8819df59c009d64.tar.gz
python-ethtool-54a6b0bea9e210c0377c3510d8819df59c009d64.tar.xz
python-ethtool-54a6b0bea9e210c0377c3510d8819df59c009d64.zip
Merge struct etherinfo and etherinfo_py
Make things more "pythonic" and avoid another layer of wrapping by removing the struct etherinfo. Move that information to the main Python object instead. This simplifies the object creation and handling too, as now all strings are python objects. Also update some of the documentation blocks along the way. Signed-off-by: David Sommerseth <davids@redhat.com>
Diffstat (limited to 'python-ethtool/ethtool.c')
-rw-r--r--python-ethtool/ethtool.c54
1 files changed, 25 insertions, 29 deletions
diff --git a/python-ethtool/ethtool.c b/python-ethtool/ethtool.c
index e37bcf1..146618f 100644
--- a/python-ethtool/ethtool.c
+++ b/python-ethtool/ethtool.c
@@ -213,12 +213,12 @@ static PyObject *get_ipaddress(PyObject *self __unused, PyObject *args)
* returned as a list of objects per interface.
*
* @param self Not used
- * @param args Python arguments
+ * @param args Python arguments - device name(s) as either a string or a list
*
* @return Python list of objects on success, otherwise NULL.
*/
static PyObject *get_interfaces_info(PyObject *self __unused, PyObject *args) {
- PyObject *devlist = NULL, *ethinf_py = NULL;
+ PyObject *devlist = NULL;
PyObject *inargs = NULL;
char **fetch_devs = NULL;
int i = 0, fetch_devs_len = 0;
@@ -268,37 +268,25 @@ static PyObject *get_interfaces_info(PyObject *self __unused, PyObject *args) {
devlist = PyList_New(0);
for( i = 0; i < fetch_devs_len; i++ ) {
- struct etherinfo *ethinfo = NULL;
-
- /* Allocate memory for data structures for each interface */
- ethinfo = calloc(1, sizeof(struct etherinfo));
- if( !ethinfo ) {
- PyErr_SetString(PyExc_OSError, strerror(errno));
- free(fetch_devs);
- return NULL;
- }
+ etherinfo_py *dev = NULL;
/* Store the device name and a reference to the NETLINK connection for
* objects to use when quering for device info
*/
- ethinfo->device = PyString_FromString(fetch_devs[i]);
- ethinfo->index = -1;
-
- /* Instantiate a new etherinfo object with the device information */
- ethinf_py = PyCObject_FromVoidPtr(ethinfo, NULL);
- if( ethinf_py ) {
- /* Prepare the argument list for the object constructor */
- PyObject *args = PyTuple_New(1);
- PyTuple_SetItem(args, 0, ethinf_py);
-
- /* Create the object */
- PyObject *dev = PyObject_CallObject((PyObject *)&ethtool_etherinfoType, args);
- if( dev ) {
- PyList_Append(devlist, dev);
- Py_DECREF(dev);
- }
- Py_DECREF(args);
- }
+
+ dev = PyObject_New(etherinfo_py, &ethtool_etherinfoType);
+ if( !dev ) {
+ PyErr_SetString(PyExc_OSError, strerror(errno));
+ free(fetch_devs);
+ return NULL;
+ }
+ dev->device = PyString_FromString(fetch_devs[i]);
+ dev->hwaddress = NULL;
+ dev->index = -1;
+
+ /* Append device object to the device list */
+ PyList_Append(devlist, (PyObject *)dev);
+ Py_DECREF(dev);
}
free(fetch_devs);
@@ -982,3 +970,11 @@ PyMODINIT_FUNC initethtool(void)
PyModule_AddStringConstant(m, "version", "python-ethtool v" VERSION);
}
+
+/*
+Local variables:
+c-basic-offset: 8
+indent-tabs-mode: y
+End:
+*/
+