Skip to content

Commit 65e6026

Browse files
Andy Groverstratakis
authored andcommitted
python3: Python3 expects str() and repr() to return strings not bytestrings
Obviously this is not true for Python 2, so handle via the preprocessor. Signed-off-by: Andy Grover <agrover@redhat.com>
1 parent 301bbdf commit 65e6026

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

python-ethtool/etherinfo_obj.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ PyObject *_ethtool_etherinfo_str(PyEtherInfo *self)
139139
}
140140
}
141141

142+
#if PY_MAJOR_VERSION >= 3
143+
{
144+
PyObject *bytestr = ret;
145+
ret = PyUnicode_FromString(PyBytes_AsString(bytestr));
146+
Py_DECREF(bytestr);
147+
}
148+
#endif
149+
142150
return ret;
143151
}
144152

python-ethtool/netlink-address.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ netlink_ip_address_repr(PyNetlinkIPaddress *obj)
156156

157157
PyBytes_ConcatAndDel(&result, PyBytes_FromString(")"));
158158

159+
#if PY_MAJOR_VERSION >= 3
160+
{
161+
PyObject *bytestr = result;
162+
result = PyUnicode_FromString(PyBytes_AsString(result));
163+
Py_DECREF(bytestr);
164+
}
165+
#endif
166+
159167
return result;
160168
}
161169

0 commit comments

Comments
 (0)