Skip to content

Commit 5efffc0

Browse files
author
David Sommerseth
committed
Clean up - avoid static variables in etherinfo_obj.h
1 parent 70957dc commit 5efffc0

File tree

3 files changed

+80
-79
lines changed

3 files changed

+80
-79
lines changed

python-ethtool/etherinfo_obj.c

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,82 @@ PyObject *_ethtool_etherinfo_str(etherinfo_py *self)
188188
}
189189
return ret;
190190
}
191+
192+
193+
/**
194+
* This is required by Python, which lists all accessible methods
195+
* in the object. But no methods are provided.
196+
*
197+
*/
198+
static PyMethodDef _ethtool_etherinfo_methods[] = {
199+
{NULL} /**< No methods defined */
200+
};
201+
202+
/**
203+
* Defines all accessible object members
204+
*
205+
*/
206+
static PyMemberDef _ethtool_etherinfo_members[] = {
207+
{"device", T_OBJECT_EX, offsetof(etherinfo_py, data), 0,
208+
"Device name of the interface"},
209+
{"mac_address", T_OBJECT_EX, offsetof(etherinfo_py, data), 0,
210+
"MAC address / hardware address of the interface"},
211+
{"ipv4_address", T_OBJECT_EX, offsetof(etherinfo_py, data), 0,
212+
"IPv4 address"},
213+
{"ipv4_netmask", T_INT, offsetof(etherinfo_py, data), 0,
214+
"IPv4 netmask in bits"},
215+
{"ipv4_broadcast", T_OBJECT_EX, offsetof(etherinfo_py, data), 0,
216+
"IPv4 broadcast address"},
217+
{"ipv6_address", T_OBJECT_EX, offsetof(etherinfo_py, data), 0,
218+
"IPv6 address"},
219+
{"ipv6_netmask", T_INT, offsetof(etherinfo_py, data), 0,
220+
"IPv6 netmask in bits"},
221+
{NULL} /* End of member list */
222+
};
223+
224+
/**
225+
* Definition of the functions a Python class/object requires.
226+
*
227+
*/
228+
PyTypeObject ethtool_etherinfoType = {
229+
PyObject_HEAD_INIT(NULL)
230+
0, /*ob_size*/
231+
"ethtool.etherinfo", /*tp_name*/
232+
sizeof(etherinfo_py), /*tp_basicsize*/
233+
0, /*tp_itemsize*/
234+
(destructor)_ethtool_etherinfo_dealloc,/*tp_dealloc*/
235+
0, /*tp_print*/
236+
0, /*tp_getattr*/
237+
0, /*tp_setattr*/
238+
0, /*tp_compare*/
239+
0, /*tp_repr*/
240+
0, /*tp_as_number*/
241+
0, /*tp_as_sequence*/
242+
0, /*tp_as_mapping*/
243+
0, /*tp_hash */
244+
0, /*tp_call*/
245+
(reprfunc)_ethtool_etherinfo_str, /*tp_str*/
246+
(getattrofunc)_ethtool_etherinfo_getter, /*tp_getattro*/
247+
(setattrofunc)_ethtool_etherinfo_setter, /*tp_setattro*/
248+
0, /*tp_as_buffer*/
249+
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
250+
"Contains information about a specific ethernet device", /* tp_doc */
251+
0, /* tp_traverse */
252+
0, /* tp_clear */
253+
0, /* tp_richcompare */
254+
0, /* tp_weaklistoffset */
255+
0, /* tp_iter */
256+
0, /* tp_iternext */
257+
_ethtool_etherinfo_methods, /* tp_methods */
258+
_ethtool_etherinfo_members, /* tp_members */
259+
0, /* tp_getset */
260+
0, /* tp_base */
261+
0, /* tp_dict */
262+
0, /* tp_descr_get */
263+
0, /* tp_descr_set */
264+
0, /* tp_dictoffset */
265+
(initproc)_ethtool_etherinfo_init, /* tp_init */
266+
0, /* tp_alloc */
267+
_ethtool_etherinfo_new, /* tp_new */
268+
};
269+

python-ethtool/etherinfo_obj.h

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#define __ETHERINFO_OBJ_H
1212

1313
#include <Python.h>
14-
#include "structmember.h"
15-
#include "etherinfo.h"
1614
#include "etherinfo_struct.h"
1715

1816
void _ethtool_etherinfo_dealloc(etherinfo_py *);
@@ -22,81 +20,4 @@ PyObject *_ethtool_etherinfo_getter(etherinfo_py *, PyObject *);
2220
int _ethtool_etherinfo_setter(etherinfo_py *, PyObject *, PyObject *);
2321
PyObject *_ethtool_etherinfo_str(etherinfo_py *self);
2422

25-
/**
26-
* This is required by Python, which lists all accessible methods
27-
* in the object. But no methods are provided.
28-
*
29-
*/
30-
static PyMethodDef _ethtool_etherinfo_methods[] = {
31-
{NULL} /**< No methods defined */
32-
};
33-
34-
/**
35-
* Defines all accessible object members
36-
*
37-
*/
38-
static PyMemberDef _ethtool_etherinfo_members[] = {
39-
{"device", T_OBJECT_EX, offsetof(etherinfo_py, data), 0,
40-
"Device name of the interface"},
41-
{"mac_address", T_OBJECT_EX, offsetof(etherinfo_py, data), 0,
42-
"MAC address / hardware address of the interface"},
43-
{"ipv4_address", T_OBJECT_EX, offsetof(etherinfo_py, data), 0,
44-
"IPv4 address"},
45-
{"ipv4_netmask", T_INT, offsetof(etherinfo_py, data), 0,
46-
"IPv4 netmask in bits"},
47-
{"ipv4_broadcast", T_OBJECT_EX, offsetof(etherinfo_py, data), 0,
48-
"IPv4 broadcast address"},
49-
{"ipv6_address", T_OBJECT_EX, offsetof(etherinfo_py, data), 0,
50-
"IPv6 address"},
51-
{"ipv6_netmask", T_INT, offsetof(etherinfo_py, data), 0,
52-
"IPv6 netmask in bits"},
53-
{NULL} /* End of member list */
54-
};
55-
56-
/**
57-
* Definition of the functions a Python class/object requires.
58-
*
59-
*/
60-
PyTypeObject ethtool_etherinfoType = {
61-
PyObject_HEAD_INIT(NULL)
62-
0, /*ob_size*/
63-
"ethtool.etherinfo", /*tp_name*/
64-
sizeof(etherinfo_py), /*tp_basicsize*/
65-
0, /*tp_itemsize*/
66-
(destructor)_ethtool_etherinfo_dealloc,/*tp_dealloc*/
67-
0, /*tp_print*/
68-
0, /*tp_getattr*/
69-
0, /*tp_setattr*/
70-
0, /*tp_compare*/
71-
0, /*tp_repr*/
72-
0, /*tp_as_number*/
73-
0, /*tp_as_sequence*/
74-
0, /*tp_as_mapping*/
75-
0, /*tp_hash */
76-
0, /*tp_call*/
77-
(reprfunc)_ethtool_etherinfo_str, /*tp_str*/
78-
(getattrofunc)_ethtool_etherinfo_getter, /*tp_getattro*/
79-
(setattrofunc)_ethtool_etherinfo_setter, /*tp_setattro*/
80-
0, /*tp_as_buffer*/
81-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
82-
"Contains information about a specific ethernet device", /* tp_doc */
83-
0, /* tp_traverse */
84-
0, /* tp_clear */
85-
0, /* tp_richcompare */
86-
0, /* tp_weaklistoffset */
87-
0, /* tp_iter */
88-
0, /* tp_iternext */
89-
_ethtool_etherinfo_methods, /* tp_methods */
90-
_ethtool_etherinfo_members, /* tp_members */
91-
0, /* tp_getset */
92-
0, /* tp_base */
93-
0, /* tp_dict */
94-
0, /* tp_descr_get */
95-
0, /* tp_descr_set */
96-
0, /* tp_dictoffset */
97-
(initproc)_ethtool_etherinfo_init, /* tp_init */
98-
0, /* tp_alloc */
99-
_ethtool_etherinfo_new, /* tp_new */
100-
};
101-
10223
#endif

python-ethtool/ethtool.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "etherinfo.h"
3232

3333
static struct _nlconnection nlconnection;
34+
extern PyTypeObject ethtool_etherinfoType;
3435

3536
#ifndef IFF_DYNAMIC
3637
#define IFF_DYNAMIC 0x8000 /* dialup device with changing addresses*/

0 commit comments

Comments
 (0)