[farsight2/master] Add unified function to do pylist->glist of fscodecs
Olivier Crête
olivier.crete at collabora.co.uk
Tue Dec 23 15:22:21 PST 2008
---
python/pyfarsight.override | 89 ++++++++++++++++++++------------------------
1 files changed, 40 insertions(+), 49 deletions(-)
diff --git a/python/pyfarsight.override b/python/pyfarsight.override
index fd451c1..fd723d0 100644
--- a/python/pyfarsight.override
+++ b/python/pyfarsight.override
@@ -103,6 +103,41 @@ _fs_candidate_list_to_value (GValue *value, PyObject *obj)
(StructCopyFunc) fs_candidate_copy);
}
+static GList *
+_fs_codec_list_from_pysequence (PyObject *obj)
+{
+ GList *codecs = NULL;
+ gint i;
+
+ if (!PySequence_Check (obj))
+ {
+ PyErr_SetString (PyExc_TypeError,
+ "The parameter must be a List of FsCodec");
+ return NULL;
+ }
+
+ for (i = 0; i < PySequence_Size (obj); i++)
+ {
+ PyObject *item = PySequence_GetItem (obj, i);
+
+ if (!pyg_boxed_check (item, FS_TYPE_CODEC))
+ {
+ PyErr_SetString(PyExc_TypeError,
+ "The parameter must be a List of FsCodec");
+ return NULL;
+ }
+ }
+
+ for (i = 0; i < PySequence_Size (obj); i++)
+ {
+ PyObject *item = PySequence_GetItem (obj, i);
+
+ codecs = g_list_append (codecs, pyg_boxed_get (item, FsCodec));
+ }
+
+ return codecs;
+}
+
%%
modulename farsight
%%
@@ -577,7 +612,6 @@ _wrap_fs_stream_set_remote_codecs (PyGObject *self, PyObject *arg)
gboolean ret = FALSE;
GError *error = NULL;
GList *codecs = NULL;
- int i;
if (!PySequence_Check (arg))
{
@@ -593,24 +627,9 @@ _wrap_fs_stream_set_remote_codecs (PyGObject *self, PyObject *arg)
return NULL;
}
- for (i = 0; i < PySequence_Size (arg); i++)
- {
- PyObject *item = PySequence_GetItem (arg, i);
-
- if (!pyg_boxed_check (item, FS_TYPE_CODEC))
- {
- PyErr_SetString(PyExc_TypeError,
- "The parameter must be a List of FsCodec");
- return NULL;
- }
- }
-
- for (i = 0; i < PySequence_Size (arg); i++)
- {
- PyObject *item = PySequence_GetItem (arg, i);
-
- codecs = g_list_append (codecs, pyg_boxed_get (item, FsCodec));
- }
+ codecs = _fs_codec_list_from_pysequence (arg);
+ if (codecs == NULL)
+ return NULL;
Py_BEGIN_ALLOW_THREADS
ret = fs_stream_set_remote_codecs (FS_STREAM(self->obj), codecs, &error);
@@ -631,38 +650,10 @@ _wrap_fs_session_set_local_codecs_config (PyGObject *self, PyObject *arg)
gboolean ret = FALSE;
GError *error = NULL;
GList *codecs = NULL;
- int i;
- if (arg == Py_None)
- goto none;
-
- if (!PySequence_Check (arg))
- {
- PyErr_SetString (PyExc_TypeError,
- "The parameter must be a List of FsCodec or None");
+ codecs = _fs_codec_list_from_pysequence (arg);
+ if (codecs == NULL)
return NULL;
- }
-
- for (i = 0; i < PySequence_Size (arg); i++)
- {
- PyObject *item = PySequence_GetItem (arg, i);
-
- if (!pyg_boxed_check (item, FS_TYPE_CODEC))
- {
- PyErr_SetString(PyExc_TypeError,
- "The parameter must be a List of FsCodec");
- return NULL;
- }
- }
-
- for (i = 0; i < PySequence_Size (arg); i++)
- {
- PyObject *item = PySequence_GetItem (arg, i);
-
- codecs = g_list_append (codecs, pyg_boxed_get (item, FsCodec));
- }
-
-none:
Py_BEGIN_ALLOW_THREADS
ret = fs_session_set_local_codecs_config (FS_SESSION(self->obj), codecs,
--
1.5.6.5
More information about the farsight-commits
mailing list