@@ -40,13 +40,9 @@ extern PyTypeObject ethtool_etherinfoIPv6Type;
4040 */
4141void _ethtool_etherinfo_dealloc (etherinfo_py * self )
4242{
43- if ( self -> data ) {
44- close_netlink (self );
45-
46- if ( self -> data -> ethinfo ) {
47- free_etherinfo (self -> data -> ethinfo );
48- }
49- free (self -> data );
43+ close_netlink (self );
44+ if ( self -> ethinfo ) {
45+ free_etherinfo (self -> ethinfo );
5046 }
5147 self -> ob_type -> tp_free ((PyObject * )self );
5248}
@@ -88,7 +84,7 @@ int _ethtool_etherinfo_init(etherinfo_py *self, PyObject *args, PyObject *kwds)
8884 PyErr_SetString (PyExc_AttributeError , "Invalid data pointer to constructor" );
8985 return -1 ;
9086 }
91- self -> data = (struct etherinfo_obj_data * ) PyCObject_AsVoidPtr (ethinf_ptr );
87+ self -> ethinfo = (struct etherinfo * ) PyCObject_AsVoidPtr (ethinf_ptr );
9288 return 0 ;
9389}
9490
@@ -106,7 +102,7 @@ static PyNetlinkIPaddress * get_last_ipv4_address(etherinfo_py *self)
106102 PyObject * list ;
107103
108104 assert (self );
109- list = self -> data -> ethinfo -> ipv4_addresses ;
105+ list = self -> ethinfo -> ipv4_addresses ;
110106 if (!list ) {
111107 return NULL ;
112108 }
@@ -139,21 +135,21 @@ PyObject *_ethtool_etherinfo_getter(etherinfo_py *self, PyObject *attr_o)
139135 char * attr = PyString_AsString (attr_o );
140136 PyNetlinkIPaddress * py_addr ;
141137
142- if ( !self || !self -> data ) {
138+ if ( !self || !self -> ethinfo ) {
143139 PyErr_SetString (PyExc_AttributeError , "No data available" );
144140 return NULL ;
145141 }
146142
147143 if ( strcmp (attr , "device" ) == 0 ) {
148- if ( self -> data -> ethinfo -> device ) {
149- return PyString_FromString (self -> data -> ethinfo -> device );
144+ if ( self -> ethinfo -> device ) {
145+ return PyString_FromString (self -> ethinfo -> device );
150146 } else {
151147 return Py_INCREF (Py_None ), Py_None ;
152148 }
153149 } else if ( strcmp (attr , "mac_address" ) == 0 ) {
154150 get_etherinfo (self , NLQRY_LINK );
155- Py_INCREF (self -> data -> ethinfo -> hwaddress );
156- return self -> data -> ethinfo -> hwaddress ;
151+ Py_INCREF (self -> ethinfo -> hwaddress );
152+ return self -> ethinfo -> hwaddress ;
157153 } else if ( strcmp (attr , "ipv4_address" ) == 0 ) {
158154 get_etherinfo (self , NLQRY_ADDR4 );
159155 /* For compatiblity with old approach, return last IPv4 address: */
@@ -215,7 +211,7 @@ PyObject *_ethtool_etherinfo_str(etherinfo_py *self)
215211{
216212 PyObject * ret = NULL ;
217213
218- if ( !self || !self -> data || ! self -> data -> ethinfo ) {
214+ if ( !self || !self -> ethinfo ) {
219215 PyErr_SetString (PyExc_AttributeError , "No data available" );
220216 return NULL ;
221217 }
@@ -224,17 +220,17 @@ PyObject *_ethtool_etherinfo_str(etherinfo_py *self)
224220 get_etherinfo (self , NLQRY_ADDR4 );
225221 get_etherinfo (self , NLQRY_ADDR6 );
226222
227- ret = PyString_FromFormat ("Device %s:\n" , self -> data -> ethinfo -> device );
228- if ( self -> data -> ethinfo -> hwaddress ) {
223+ ret = PyString_FromFormat ("Device %s:\n" , self -> ethinfo -> device );
224+ if ( self -> ethinfo -> hwaddress ) {
229225 PyString_ConcatAndDel (& ret , PyString_FromString ("\tMAC address: " ));
230- PyString_Concat (& ret , self -> data -> ethinfo -> hwaddress );
226+ PyString_Concat (& ret , self -> ethinfo -> hwaddress );
231227 PyString_ConcatAndDel (& ret , PyString_FromString ("\n" ));
232228 }
233229
234- if ( self -> data -> ethinfo -> ipv4_addresses ) {
230+ if ( self -> ethinfo -> ipv4_addresses ) {
235231 Py_ssize_t i ;
236- for (i = 0 ; i < PyList_Size (self -> data -> ethinfo -> ipv4_addresses ); i ++ ) {
237- PyNetlinkIPaddress * py_addr = (PyNetlinkIPaddress * )PyList_GetItem (self -> data -> ethinfo -> ipv4_addresses , i );
232+ for (i = 0 ; i < PyList_Size (self -> ethinfo -> ipv4_addresses ); i ++ ) {
233+ PyNetlinkIPaddress * py_addr = (PyNetlinkIPaddress * )PyList_GetItem (self -> ethinfo -> ipv4_addresses , i );
238234 PyObject * tmp = PyString_FromFormat ("\tIPv4 address: " );
239235 PyString_Concat (& tmp , py_addr -> local );
240236 PyString_ConcatAndDel (& tmp , PyString_FromFormat ("/%d" , py_addr -> prefixlen ));
@@ -248,10 +244,10 @@ PyObject *_ethtool_etherinfo_str(etherinfo_py *self)
248244 }
249245 }
250246
251- if ( self -> data -> ethinfo -> ipv6_addresses ) {
247+ if ( self -> ethinfo -> ipv6_addresses ) {
252248 Py_ssize_t i ;
253- for (i = 0 ; i < PyList_Size (self -> data -> ethinfo -> ipv6_addresses ); i ++ ) {
254- PyNetlinkIPaddress * py_addr = (PyNetlinkIPaddress * )PyList_GetItem (self -> data -> ethinfo -> ipv6_addresses , i );
249+ for (i = 0 ; i < PyList_Size (self -> ethinfo -> ipv6_addresses ); i ++ ) {
250+ PyNetlinkIPaddress * py_addr = (PyNetlinkIPaddress * )PyList_GetItem (self -> ethinfo -> ipv6_addresses , i );
255251 PyObject * tmp = PyString_FromFormat ("\tIPv6 address: [" );
256252 PyString_Concat (& tmp , py_addr -> scope );
257253 PyString_ConcatAndDel (& tmp , PyString_FromString ("] " ));
@@ -276,16 +272,16 @@ PyObject *_ethtool_etherinfo_str(etherinfo_py *self)
276272static PyObject * _ethtool_etherinfo_get_ipv4_addresses (etherinfo_py * self , PyObject * notused ) {
277273 PyObject * ret ;
278274
279- if ( !self || !self -> data ) {
275+ if ( !self || !self -> ethinfo ) {
280276 PyErr_SetString (PyExc_AttributeError , "No data available" );
281277 return NULL ;
282278 }
283279
284280 get_etherinfo (self , NLQRY_ADDR4 );
285281
286282 /* Transfer ownership of reference: */
287- ret = self -> data -> ethinfo -> ipv4_addresses ;
288- self -> data -> ethinfo -> ipv4_addresses = NULL ;
283+ ret = self -> ethinfo -> ipv4_addresses ;
284+ self -> ethinfo -> ipv4_addresses = NULL ;
289285
290286 return ret ;
291287}
@@ -302,16 +298,16 @@ static PyObject *_ethtool_etherinfo_get_ipv4_addresses(etherinfo_py *self, PyObj
302298static PyObject * _ethtool_etherinfo_get_ipv6_addresses (etherinfo_py * self , PyObject * notused ) {
303299 PyObject * ret ;
304300
305- if ( !self || !self -> data ) {
301+ if ( !self || !self -> ethinfo ) {
306302 PyErr_SetString (PyExc_AttributeError , "No data available" );
307303 return NULL ;
308304 }
309305
310306 get_etherinfo (self , NLQRY_ADDR6 );
311307
312308 /* Transfer ownership of reference: */
313- ret = self -> data -> ethinfo -> ipv6_addresses ;
314- self -> data -> ethinfo -> ipv6_addresses = NULL ;
309+ ret = self -> ethinfo -> ipv6_addresses ;
310+ self -> ethinfo -> ipv6_addresses = NULL ;
315311
316312 return ret ;
317313}
0 commit comments