[0.11] gstreamer: don't do logic in g_assert...

Wim Taymans wtay at kemper.freedesktop.org
Tue Jan 31 03:14:40 PST 2012


Module: gstreamer
Branch: 0.11
Commit: 39c5f0b28a808142770eb08d9c0430f3e823f964
URL:    http://cgit.freedesktop.org/gstreamer/gstreamer/commit/?id=39c5f0b28a808142770eb08d9c0430f3e823f964

Author: Wim Taymans <wim.taymans at collabora.co.uk>
Date:   Tue Jan 31 12:10:21 2012 +0100

don't do logic in g_assert...

---

 gst/gstvalue.c                    |   20 ++++++++++++++++----
 libs/gst/base/gstadapter.c        |    7 +++++--
 libs/gst/base/gstbasetransform.c  |   14 ++++++++------
 libs/gst/base/gsttypefindhelper.c |   10 ++++++----
 4 files changed, 35 insertions(+), 16 deletions(-)

diff --git a/gst/gstvalue.c b/gst/gstvalue.c
index fc292ae..966293a 100644
--- a/gst/gstvalue.c
+++ b/gst/gstvalue.c
@@ -1883,8 +1883,13 @@ gst_value_compare_buffer (const GValue * value1, const GValue * value2)
   if (size1 == 0)
     return GST_VALUE_EQUAL;
 
-  g_assert (gst_buffer_map (buf1, &info1, GST_MAP_READ));
-  g_assert (gst_buffer_map (buf2, &info2, GST_MAP_READ));
+  if (!gst_buffer_map (buf1, &info1, GST_MAP_READ))
+    return GST_VALUE_UNORDERED;
+
+  if (!gst_buffer_map (buf2, &info2, GST_MAP_READ)) {
+    gst_buffer_unmap (buf1, &info2);
+    return GST_VALUE_UNORDERED;
+  }
 
   if (memcmp (info1.data, info2.data, info1.size) == 0)
     result = GST_VALUE_EQUAL;
@@ -1908,7 +1913,9 @@ gst_value_serialize_buffer (const GValue * value)
   if (buffer == NULL)
     return NULL;
 
-  g_assert (gst_buffer_map (buffer, &info, GST_MAP_READ));
+  if (!gst_buffer_map (buffer, &info, GST_MAP_READ))
+    return NULL;
+
   data = info.data;
 
   string = g_malloc (info.size * 2 + 1);
@@ -1937,7 +1944,8 @@ gst_value_deserialize_buffer (GValue * dest, const gchar * s)
     goto wrong_length;
 
   buffer = gst_buffer_new_allocate (NULL, len / 2, 0);
-  g_assert (gst_buffer_map (buffer, &info, GST_MAP_WRITE));
+  if (!gst_buffer_map (buffer, &info, GST_MAP_WRITE))
+    goto map_failed;
   data = info.data;
 
   for (i = 0; i < len / 2; i++) {
@@ -1961,6 +1969,10 @@ wrong_length:
   {
     return FALSE;
   }
+map_failed:
+  {
+    return FALSE;
+  }
 wrong_char:
   {
     gst_buffer_unref (buffer);
diff --git a/libs/gst/base/gstadapter.c b/libs/gst/base/gstadapter.c
index 4c02fe5..2fc29ca 100644
--- a/libs/gst/base/gstadapter.c
+++ b/libs/gst/base/gstadapter.c
@@ -446,7 +446,9 @@ gst_adapter_map (GstAdapter * adapter, gsize size)
 
     csize = gst_buffer_get_size (cur);
     if (csize >= size + skip) {
-      g_assert (gst_buffer_map (cur, &priv->info, GST_MAP_READ));
+      if (!gst_buffer_map (cur, &priv->info, GST_MAP_READ))
+        return FALSE;
+
       return (guint8 *) priv->info.data + skip;
     }
     /* We may be able to efficiently merge buffers in our pool to
@@ -998,7 +1000,8 @@ gst_adapter_masked_scan_uint32_peek (GstAdapter * adapter, guint32 mask,
     bsize = gst_buffer_get_size (buf);
   }
   /* get the data now */
-  g_assert (gst_buffer_map (buf, &info, GST_MAP_READ));
+  if (!gst_buffer_map (buf, &info, GST_MAP_READ))
+    return -1;
 
   bdata = (guint8 *) info.data + skip;
   bsize = info.size - skip;
diff --git a/libs/gst/base/gstbasetransform.c b/libs/gst/base/gstbasetransform.c
index ad89fd3..56349df 100644
--- a/libs/gst/base/gstbasetransform.c
+++ b/libs/gst/base/gstbasetransform.c
@@ -1888,14 +1888,16 @@ no_qos:
          * with subbuffers of the same buffer. Note that because of the FIXME in
          * prepare_output_buffer() we have decreased the refcounts of inbuf and
          * outbuf to keep them writable */
-        g_assert (gst_buffer_map (inbuf, &ininfo, GST_MAP_READ));
-        g_assert (gst_buffer_map (*outbuf, &outinfo, GST_MAP_WRITE));
+        if (gst_buffer_map (inbuf, &ininfo, GST_MAP_READ)) {
+          if (gst_buffer_map (*outbuf, &outinfo, GST_MAP_WRITE)) {
 
-        if (ininfo.data != outinfo.data)
-          memcpy (outinfo.data, ininfo.data, ininfo.size);
+            if (ininfo.data != outinfo.data)
+              memcpy (outinfo.data, ininfo.data, ininfo.size);
 
-        gst_buffer_unmap (inbuf, &ininfo);
-        gst_buffer_unmap (*outbuf, &outinfo);
+            gst_buffer_unmap (*outbuf, &outinfo);
+          }
+          gst_buffer_unmap (inbuf, &ininfo);
+        }
       }
       ret = bclass->transform_ip (trans, *outbuf);
     } else {
diff --git a/libs/gst/base/gsttypefindhelper.c b/libs/gst/base/gsttypefindhelper.c
index 4fdf7a6..9cefb94 100644
--- a/libs/gst/base/gsttypefindhelper.c
+++ b/libs/gst/base/gsttypefindhelper.c
@@ -115,8 +115,8 @@ helper_find_peek (gpointer data, gint64 offset, guint size)
       if (buf_offset <= offset) {
         if ((offset + size) < (buf_offset + buf_size)) {
           /* FIXME, unmap after usage */
-          g_assert (gst_buffer_map (buf, &info, GST_MAP_READ));
-
+          if (!gst_buffer_map (buf, &info, GST_MAP_READ))
+            return NULL;
           return (guint8 *) info.data + (offset - buf_offset);
         }
       } else if (offset + size >= buf_offset + buf_size) {
@@ -180,7 +180,8 @@ helper_find_peek (gpointer data, gint64 offset, guint size)
   }
 
   /* FIXME, unmap */
-  g_assert (gst_buffer_map (buffer, &info, GST_MAP_READ));
+  gst_buffer_map (buffer, &info, GST_MAP_READ);
+
   return info.data;
 
 error:
@@ -570,7 +571,8 @@ gst_type_find_helper_for_buffer (GstObject * obj, GstBuffer * buf,
   g_return_val_if_fail (GST_BUFFER_OFFSET (buf) == 0 ||
       GST_BUFFER_OFFSET (buf) == GST_BUFFER_OFFSET_NONE, NULL);
 
-  g_assert (gst_buffer_map (buf, &info, GST_MAP_READ));
+  if (!gst_buffer_map (buf, &info, GST_MAP_READ))
+    return NULL;
   result = gst_type_find_helper_for_data (obj, info.data, info.size, prob);
   gst_buffer_unmap (buf, &info);
 



More information about the gstreamer-commits mailing list