gst/gstbin.c: Can't use GPOINTER_TO_INT and GINT_TO_POINTER with GTypes.

Original commit message from CVS:
* gst/gstbin.c: (compare_interface), (gst_bin_get_by_interface),
(gst_bin_iterate_all_by_interface):
Can't use GPOINTER_TO_INT and GINT_TO_POINTER with GTypes.
GTypes are gulongs and thus the top 4 bytes might be cut
off on some platforms when doing GPOINTER_TO_INT, leading
to invalid GTypes and bad things happening.
Also add a check to make sure the type passed in is really
an interface type.
This commit is contained in:
Tim-Philipp Müller 2006-07-07 15:42:08 +00:00
parent a55b4bf721
commit 99f16655f4
2 changed files with 18 additions and 4 deletions

View file

@ -1,3 +1,14 @@
2006-07-07 Tim-Philipp Müller <tim at centricular dot net>
* gst/gstbin.c: (compare_interface), (gst_bin_get_by_interface),
(gst_bin_iterate_all_by_interface):
Can't use GPOINTER_TO_INT and GINT_TO_POINTER with GTypes.
GTypes are gulongs and thus the top 4 bytes might be cut
off on some platforms when doing GPOINTER_TO_INT, leading
to invalid GTypes and bad things happening.
Also add a check to make sure the type passed in is really
an interface type.
2006-07-07 Tim-Philipp Müller <tim at centricular dot net>
* .cvsignore:

View file

@ -2516,9 +2516,10 @@ gst_bin_get_by_name_recurse_up (GstBin * bin, const gchar * name)
static gint
compare_interface (GstElement * element, gpointer interface)
{
GType interface_type = (GType) interface;
gint ret;
if (G_TYPE_CHECK_INSTANCE_TYPE (element, GPOINTER_TO_INT (interface))) {
if (G_TYPE_CHECK_INSTANCE_TYPE (element, interface_type)) {
ret = 0;
} else {
/* we did not find the element, need to release the ref
@ -2548,13 +2549,14 @@ GstElement *
gst_bin_get_by_interface (GstBin * bin, GType interface)
{
GstIterator *children;
GstIterator *result;
gpointer result;
g_return_val_if_fail (GST_IS_BIN (bin), NULL);
g_return_val_if_fail (G_TYPE_IS_INTERFACE (interface), NULL);
children = gst_bin_iterate_recurse (bin);
result = gst_iterator_find_custom (children, (GCompareFunc) compare_interface,
GINT_TO_POINTER (interface));
(gpointer) interface);
gst_iterator_free (children);
return GST_ELEMENT_CAST (result);
@ -2585,10 +2587,11 @@ gst_bin_iterate_all_by_interface (GstBin * bin, GType interface)
GstIterator *result;
g_return_val_if_fail (GST_IS_BIN (bin), NULL);
g_return_val_if_fail (G_TYPE_IS_INTERFACE (interface), NULL);
children = gst_bin_iterate_recurse (bin);
result = gst_iterator_filter (children, (GCompareFunc) compare_interface,
GINT_TO_POINTER (interface));
(gpointer) interface);
return result;
}