mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-06 07:28:53 +00:00
values: Fix segfault in the testsuite
It seems pygst_value_from_pyobject should not unref the passed in object. Wrap the original pygst_value_from_pyobject in a function that converts unicode python objects and then unrefs the temporary object after extraction into a GValue.
This commit is contained in:
parent
26fa6dd184
commit
71539efe7f
1 changed files with 36 additions and 23 deletions
|
@ -193,32 +193,11 @@ pygst_value_init_for_pyobject (GValue * value, PyObject * obj)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
static int
|
||||||
* pygst_value_from_pyobject:
|
pygst_value_from_pyobject_internal (GValue * value, PyObject * obj)
|
||||||
* @value: the GValue object to store the converted value in.
|
|
||||||
* @obj: the Python object to convert.
|
|
||||||
*
|
|
||||||
* This function converts a Python object and stores the result in a
|
|
||||||
* GValue. The GValue must be initialised in advance with
|
|
||||||
* g_value_init(). If the Python object can't be converted to the
|
|
||||||
* type of the GValue, then an error is returned.
|
|
||||||
*
|
|
||||||
* Returns: 0 on success, -1 on error.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
pygst_value_from_pyobject (GValue * value, PyObject * obj)
|
|
||||||
{
|
{
|
||||||
GType f = g_type_fundamental (G_VALUE_TYPE (value));
|
GType f = g_type_fundamental (G_VALUE_TYPE (value));
|
||||||
|
|
||||||
/* Unicode objects should be converted to utf-8 strings */
|
|
||||||
if (PyObject_TypeCheck (obj, &PyUnicode_Type)) {
|
|
||||||
PyObject *v;
|
|
||||||
|
|
||||||
v = PyUnicode_AsUTF8String (obj);
|
|
||||||
Py_DECREF (obj);
|
|
||||||
obj = v;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* work around a bug in pygtk whereby pyg_value_from_pyobject claims success
|
/* work around a bug in pygtk whereby pyg_value_from_pyobject claims success
|
||||||
for unknown fundamental types without actually doing anything */
|
for unknown fundamental types without actually doing anything */
|
||||||
if (f < G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_USER_FIRST)
|
if (f < G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_USER_FIRST)
|
||||||
|
@ -360,6 +339,40 @@ pygst_value_from_pyobject (GValue * value, PyObject * obj)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pygst_value_from_pyobject:
|
||||||
|
* @value: the GValue object to store the converted value in.
|
||||||
|
* @obj: the Python object to convert.
|
||||||
|
*
|
||||||
|
* This function converts a Python object and stores the result in a
|
||||||
|
* GValue. The GValue must be initialised in advance with
|
||||||
|
* g_value_init(). If the Python object can't be converted to the
|
||||||
|
* type of the GValue, then an error is returned.
|
||||||
|
*
|
||||||
|
* Returns: 0 on success, -1 on error.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
pygst_value_from_pyobject (GValue * value, PyObject * obj)
|
||||||
|
{
|
||||||
|
PyObject *v = NULL;
|
||||||
|
int res;
|
||||||
|
|
||||||
|
/* Unicode objects should be converted to utf-8 strings */
|
||||||
|
if (PyObject_TypeCheck (obj, &PyUnicode_Type)) {
|
||||||
|
|
||||||
|
v = PyUnicode_AsUTF8String (obj);
|
||||||
|
obj = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
res = pygst_value_from_pyobject_internal (value, obj);
|
||||||
|
|
||||||
|
if (v) {
|
||||||
|
Py_DECREF (obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
#define NULL_CHECK(o) if (!o) goto err
|
#define NULL_CHECK(o) if (!o) goto err
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
|
|
Loading…
Reference in a new issue