No, let's not use g_slice_{dup|copy} here, since they only exist since GLib 2.14...
authorTim-Philipp Müller <tim@centricular.net>
Fri, 9 May 2008 20:48:24 +0000 (20:48 +0000)
committerTim-Philipp Müller <tim@centricular.net>
Fri, 9 May 2008 20:48:24 +0000 (20:48 +0000)
Original commit message from CVS:
* gst/gstsegment.c:
* tests/check/gst/gstsegment.c:
No, let's not use g_slice_{dup|copy} here, since they only exist
since GLib 2.14 and we still depend only on >= 2.12. Also add
unit test for gst_segment_copy().

ChangeLog
gst/gstsegment.c
tests/check/gst/gstsegment.c

index a60af45..af2b7f1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2008-05-09  Tim-Philipp Müller  <tim.muller at collabora co uk>
 
+       * gst/gstsegment.c:
+       * tests/check/gst/gstsegment.c:
+         No, let's not use g_slice_{dup|copy} here, since they only exist
+         since GLib 2.14 and we still depend only on >= 2.12. Also add
+         unit test for gst_segment_copy().
+
+2008-05-09  Tim-Philipp Müller  <tim.muller at collabora co uk>
+
        * gst/gstutils.h: (GST_BOILERPLATE_FULL):
          Try to fix 'dereferencing type-punned pointer will break strict
          aliasing rules' warnings with C++ compilers and GLib >= 2.14.0: GLib
index fcd148c..f3f9812 100644 (file)
@@ -99,7 +99,10 @@ gst_segment_copy (GstSegment * segment)
   GstSegment *result = NULL;
 
   if (segment) {
-    result = (GstSegment *) g_slice_copy (sizeof (GstSegment), segment);
+    /* we do not use g_slice_dup or g_slice_copy here because those were
+     * added in GLib 2.14 and we require only >= 2.12 */
+    result = g_slice_new (GstSegment);
+    *result = *segment;
   }
   return result;
 }
index c6a13cf..1c9b7b6 100644 (file)
@@ -1624,6 +1624,29 @@ GST_START_TEST (segment_newsegment_accum2)
 
 GST_END_TEST;
 
+GST_START_TEST (segment_copy)
+{
+  GstSegment *copy;
+  GstSegment segment = { 0.0, };
+
+  /* this is a boxed type copy function, we support copying NULL */
+  fail_unless (gst_segment_copy (NULL) == NULL);
+
+  gst_segment_init (&segment, GST_FORMAT_TIME);
+
+  gst_segment_set_newsegment_full (&segment, FALSE, -1.0, 1.0,
+      GST_FORMAT_TIME, 0, 200, 0);
+
+  copy = gst_segment_copy (&segment);
+  fail_unless (copy != NULL);
+  /* we inited the struct on the stack to zeroes, so direct comparison should
+   * be ok here despite the padding field and regardless of implementation */
+  fail_unless (memcmp (copy, &segment, sizeof (GstSegment)) == 0);
+  gst_segment_free (copy);
+}
+
+GST_END_TEST;
+
 static Suite *
 gst_segment_suite (void)
 {
@@ -1646,6 +1669,7 @@ gst_segment_suite (void)
   tcase_add_test (tc_chain, segment_newsegment_runningtime);
   tcase_add_test (tc_chain, segment_newsegment_accum);
   tcase_add_test (tc_chain, segment_newsegment_accum2);
+  tcase_add_test (tc_chain, segment_copy);
 
   return s;
 }