gst/gstbin.c: Can't use GPOINTER_TO_INT and GINT_TO_POINTER with GTypes.
authorTim-Philipp Müller <tim@centricular.net>
Fri, 7 Jul 2006 15:42:08 +0000 (15:42 +0000)
committerTim-Philipp Müller <tim@centricular.net>
Fri, 7 Jul 2006 15:42:08 +0000 (15:42 +0000)
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.

ChangeLog
gst/gstbin.c

index 632ba0b..807dc91 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 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:
          Ignore more.
 
index 38c41b3..32c0d12 100644 (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;
 }