python: Add conversion functions to/from GSList *
This commit is contained in:
parent
bd7bfe8c51
commit
05cfe1147a
|
@ -125,14 +125,9 @@ class Driver(object):
|
|||
if not self._initialized:
|
||||
check(sr_driver_init(self.context.struct, self.struct))
|
||||
self._initialized = True
|
||||
devices = []
|
||||
device_list = sr_driver_scan(self.struct, None)
|
||||
device_list_item = device_list
|
||||
while device_list_item:
|
||||
ptr = device_list_item.data
|
||||
device_ptr = gpointer_to_sr_dev_inst_ptr(ptr)
|
||||
devices.append(Device(self, device_ptr))
|
||||
device_list_item = device_list_item.next
|
||||
devices = [Device(self, gpointer_to_sr_dev_inst_ptr(ptr))
|
||||
for ptr in gslist_to_python(device_list)]
|
||||
g_slist_free(device_list)
|
||||
return devices
|
||||
|
||||
|
|
|
@ -78,8 +78,36 @@ PyObject *cdata(const void *data, unsigned long size)
|
|||
#endif
|
||||
}
|
||||
|
||||
GSList *python_to_gslist(PyObject *pylist)
|
||||
{
|
||||
if (PyList_Check(pylist)) {
|
||||
GSList *gslist = NULL;
|
||||
int size = PyList_Size(pylist);
|
||||
int i;
|
||||
for (i = size - 1; i >= 0; i--) {
|
||||
SwigPyObject *o = (SwigPyObject *)PyList_GetItem(pylist, i);
|
||||
void *data = o->ptr;
|
||||
gslist = g_slist_prepend(gslist, data);
|
||||
}
|
||||
return gslist;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyObject *gslist_to_python(GSList *gslist)
|
||||
{
|
||||
PyObject *pylist = PyList_New(0);
|
||||
GSList *l;
|
||||
for (l = gslist; l; l = l->next)
|
||||
PyList_Append(pylist, SWIG_NewPointerObj(l->data, SWIGTYPE_p_void, 0));
|
||||
return pylist;
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
int sr_session_datafeed_python_callback_add(PyObject *cb);
|
||||
|
||||
PyObject *cdata(const void *data, unsigned long size);
|
||||
|
||||
GSList *python_to_gslist(PyObject *pylist);
|
||||
PyObject *gslist_to_python(GSList *gslist);
|
||||
|
|
Loading…
Reference in New Issue