Skip to content

Commit 719444c

Browse files
committed
First part of move from bytes to str
1 parent 41615bb commit 719444c

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

python-ethtool/etherinfo.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
#include <Python.h>
19+
#include "include/py3c/compat.h"
1920
#include <bytesobject.h>
2021
#include <bits/sockaddr.h>
2122
#include <stdio.h>
@@ -180,7 +181,7 @@ int get_etherinfo_link(PyEtherInfo *self)
180181
if( !open_netlink(self) ) {
181182
PyErr_Format(PyExc_RuntimeError,
182183
"Could not open a NETLINK connection for %s",
183-
PyBytes_AsString(self->device));
184+
PyStr_AsString(self->device));
184185
return 0;
185186
}
186187

@@ -234,7 +235,7 @@ PyObject * get_etherinfo_address(PyEtherInfo *self, nlQuery query)
234235
if( !open_netlink(self) ) {
235236
PyErr_Format(PyExc_RuntimeError,
236237
"Could not open a NETLINK connection for %s",
237-
PyBytes_AsString(self->device));
238+
PyStr_AsString(self->device));
238239
return NULL;
239240
}
240241

python-ethtool/ethtool.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static PyObject *get_active_devices(PyObject *self __unused, PyObject *args __un
6565

6666
list = PyList_New(0);
6767
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
68-
PyObject *str = PyBytes_FromString(ifa->ifa_name);
68+
PyObject *str = PyStr_FromString(ifa->ifa_name);
6969
/* names are not unique (listed for both ipv4 and ipv6) */
7070
if (!PySequence_Contains(list, str) && (ifa->ifa_flags & (IFF_UP))) {
7171
PyList_Append(list, str);
@@ -109,7 +109,7 @@ static PyObject *get_devices(PyObject *self __unused, PyObject *args __unused)
109109
while (*name == ' ')
110110
name++; /* skip over leading whitespace if any */
111111

112-
str = PyBytes_FromString(name);
112+
str = PyStr_FromString(name);
113113
PyList_Append(list, str);
114114
Py_DECREF(str);
115115
}
@@ -156,7 +156,7 @@ static PyObject *get_hwaddress(PyObject *self __unused, PyObject *args)
156156
(unsigned int)ifr.ifr_hwaddr.sa_data[4] % 256,
157157
(unsigned int)ifr.ifr_hwaddr.sa_data[5] % 256);
158158

159-
return PyBytes_FromString(hwaddr);
159+
return PyStr_FromString(hwaddr);
160160
}
161161

162162
static PyObject *get_ipaddress(PyObject *self __unused, PyObject *args)
@@ -196,7 +196,7 @@ static PyObject *get_ipaddress(PyObject *self __unused, PyObject *args)
196196
(unsigned int)ifr.ifr_addr.sa_data[4] % 256,
197197
(unsigned int)ifr.ifr_addr.sa_data[5] % 256);
198198

199-
return PyBytes_FromString(ipaddr);
199+
return PyStr_FromString(ipaddr);
200200
}
201201

202202

@@ -278,7 +278,7 @@ static PyObject *get_interfaces_info(PyObject *self __unused, PyObject *args) {
278278
free(fetch_devs);
279279
return NULL;
280280
}
281-
dev->device = PyBytes_FromString(fetch_devs[i]);
281+
dev->device = PyStr_FromString(fetch_devs[i]);
282282
dev->hwaddress = NULL;
283283
dev->index = -1;
284284

@@ -360,7 +360,7 @@ static PyObject *get_netmask (PyObject *self __unused, PyObject *args)
360360
(unsigned int)ifr.ifr_netmask.sa_data[4] % 256,
361361
(unsigned int)ifr.ifr_netmask.sa_data[5] % 256);
362362

363-
return PyBytes_FromString(netmask);
363+
return PyStr_FromString(netmask);
364364
}
365365

366366
static PyObject *get_broadcast(PyObject *self __unused, PyObject *args)
@@ -400,7 +400,7 @@ static PyObject *get_broadcast(PyObject *self __unused, PyObject *args)
400400
(unsigned int)ifr.ifr_broadaddr.sa_data[4] % 256,
401401
(unsigned int)ifr.ifr_broadaddr.sa_data[5] % 256);
402402

403-
return PyBytes_FromString(broadcast);
403+
return PyStr_FromString(broadcast);
404404
}
405405

406406
static PyObject *get_module(PyObject *self __unused, PyObject *args)
@@ -465,12 +465,12 @@ static PyObject *get_module(PyObject *self __unused, PyObject *args)
465465
return NULL;
466466
} else {
467467
PyErr_Clear();
468-
return PyBytes_FromString(driver);
468+
return PyStr_FromString(driver);
469469
}
470470
}
471471

472472
close(fd);
473-
return PyBytes_FromString(((struct ethtool_drvinfo *)buf)->driver);
473+
return PyStr_FromString(((struct ethtool_drvinfo *)buf)->driver);
474474
}
475475

476476
static PyObject *get_businfo(PyObject *self __unused, PyObject *args)
@@ -509,7 +509,7 @@ static PyObject *get_businfo(PyObject *self __unused, PyObject *args)
509509
}
510510

511511
close(fd);
512-
return PyBytes_FromString(((struct ethtool_drvinfo *)buf)->bus_info);
512+
return PyStr_FromString(((struct ethtool_drvinfo *)buf)->bus_info);
513513
}
514514

515515
static int send_command(int cmd, const char *devname, void *value)

0 commit comments

Comments
 (0)