From 72163f3e5c618f62c4a5548f55d8d1f8daa9eb3a Mon Sep 17 00:00:00 2001 From: David Schleef Date: Mon, 22 Dec 2003 07:00:25 +0000 Subject: [PATCH] Add gst_value_init_and_copy() and use it, to avoid silly mistakes in using g_value_copy() Original commit message from CVS: Add gst_value_init_and_copy() and use it, to avoid silly mistakes in using g_value_copy() --- ChangeLog | 6 ++++++ gst/gststructure.c | 7 ++----- gst/gstvalue.c | 41 +++++++++++++++++++++-------------------- gst/gstvalue.h | 1 + 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3cbb4d2..6012d69 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2003-12-22 David Schleef + + * gststructure.c, gstvalue.c, gstvalue.h: Add + gst_value_init_and_copy() and use it, to avoid silly mistakes in + using g_value_copy() + 2003-12-21 David Schleef * many, many files: Merge CAPS branch. This includes: diff --git a/gst/gststructure.c b/gst/gststructure.c index 26eb3e9..30cf778 100644 --- a/gst/gststructure.c +++ b/gst/gststructure.c @@ -221,9 +221,7 @@ GstStructure *gst_structure_copy(GstStructure *structure) field = GST_STRUCTURE_FIELD(structure, i); new_field.name = field->name; - g_value_init(&new_field.value, G_VALUE_TYPE(&field->value)); - g_value_copy(&field->value, &new_field.value); - + gst_value_init_and_copy (&new_field.value, &field->value); g_array_append_val(new_structure->fields, new_field); } @@ -308,8 +306,7 @@ void gst_structure_id_set_value(GstStructure *structure, GQuark fieldname, g_return_if_fail(G_IS_VALUE(value)); field.name = fieldname; - g_value_init(&field.value, G_VALUE_TYPE (value)); - g_value_copy(value, &field.value); + gst_value_init_and_copy (&field.value, value); gst_structure_set_field(structure, &field); } diff --git a/gst/gstvalue.c b/gst/gstvalue.c index 5ab7258..29ba90e 100644 --- a/gst/gstvalue.c +++ b/gst/gstvalue.c @@ -71,8 +71,8 @@ gst_value_list_array_copy (const GArray *src) dest = g_array_sized_new (FALSE, TRUE, sizeof(GValue), src->len); g_array_set_size (dest, src->len); for (i = 0; i < src->len; i++) { - g_value_init (&g_array_index(dest, GValue, i), G_VALUE_TYPE (&g_array_index(src, GValue, i))); - g_value_copy (&g_array_index(src, GValue, i), &g_array_index(dest, GValue, i)); + gst_value_init_and_copy (&g_array_index(dest, GValue, i), + &g_array_index(src, GValue, i)); } return dest; @@ -197,22 +197,21 @@ gst_value_list_concat (GValue *dest, const GValue *value1, const GValue *value2) if (GST_VALUE_HOLDS_LIST (value1)) { for (i = 0; i < value1_length; i++) { - g_value_init (&g_array_index(array, GValue, i), G_VALUE_TYPE (gst_value_list_get_value (value1, i))); - g_value_copy (gst_value_list_get_value (value1, i), &g_array_index(array, GValue, i)); + gst_value_init_and_copy (&g_array_index(array, GValue, i), + gst_value_list_get_value (value1, i)); } } else { - g_value_init (&g_array_index(array, GValue, 0), G_VALUE_TYPE (value1)); - g_value_copy (value1, &g_array_index(array, GValue, 0)); + gst_value_init_and_copy (&g_array_index(array, GValue, 0), value1); } if (GST_VALUE_HOLDS_LIST (value2)) { for (i = 0; i < value2_length; i++) { - g_value_init (&g_array_index(array, GValue, i + value1_length), G_VALUE_TYPE (gst_value_list_get_value (value2, i))); - g_value_copy (gst_value_list_get_value (value2, i), &g_array_index(array, GValue, i + value1_length)); + gst_value_init_and_copy (&g_array_index(array, GValue, i + value1_length), + gst_value_list_get_value (value2, i)); } } else { - g_value_init (&g_array_index(array, GValue, value1_length), G_VALUE_TYPE (value2)); - g_value_copy (value2, &g_array_index(array, GValue, value1_length)); + gst_value_init_and_copy (&g_array_index(array, GValue, value1_length), + value2); } } @@ -703,8 +702,7 @@ gst_value_intersect_int_int_range (GValue *dest, const GValue *src1, if (src2->data[0].v_int <= src1->data[0].v_int && src2->data[1].v_int >= src1->data[0].v_int){ - g_value_init(dest, G_TYPE_INT); - g_value_copy(src1, dest); + gst_value_init_and_copy (dest, src1); return TRUE; } @@ -747,8 +745,7 @@ gst_value_intersect_double_double_range (GValue *dest, const GValue *src1, if (src2->data[0].v_double <= src1->data[0].v_double && src2->data[1].v_double >= src1->data[0].v_double){ - g_value_init(dest, G_TYPE_DOUBLE); - g_value_copy(src1, dest); + gst_value_init_and_copy (dest, src1); return TRUE; } @@ -798,16 +795,14 @@ gst_value_intersect_list (GValue *dest, const GValue *value1, const GValue *valu if (gst_value_intersect (&intersection, cur, value2)) { /* append value */ if (!ret) { - g_value_init (dest, G_VALUE_TYPE(&intersection)); - g_value_copy (dest, &intersection); + gst_value_init_and_copy (dest, &intersection); ret = TRUE; } else if (GST_VALUE_HOLDS_LIST (dest)) { gst_value_list_append_value (dest, &intersection); } else { GValue temp = {0, }; - g_value_init (&temp, G_VALUE_TYPE(dest)); - g_value_copy (dest, &temp); + gst_value_init_and_copy (&temp, dest); g_value_unset (dest); gst_value_list_concat (dest, &temp, &intersection); } @@ -868,8 +863,7 @@ gst_value_intersect (GValue *dest, const GValue *value1, const GValue *value2) } if(gst_value_compare(value1, value2) == GST_VALUE_EQUAL){ - g_value_init(dest, G_VALUE_TYPE(value1)); - g_value_copy(value1, dest); + gst_value_init_and_copy (dest, value1); ret = TRUE; } @@ -877,6 +871,13 @@ gst_value_intersect (GValue *dest, const GValue *value1, const GValue *value2) } void +gst_value_init_and_copy (GValue *dest, const GValue *src) +{ + g_value_init (dest, G_VALUE_TYPE(src)); + g_value_copy (src, dest); +} + +void gst_value_register_intersect_func (GType type1, GType type2, GstValueIntersectFunc func) { diff --git a/gst/gstvalue.h b/gst/gstvalue.h index cb23454..119441b 100644 --- a/gst/gstvalue.h +++ b/gst/gstvalue.h @@ -85,6 +85,7 @@ void gst_value_list_concat (GValue *dest, const GValue *value1, const GValue *va void _gst_value_initialize (void); +void gst_value_init_and_copy (GValue *dest, const GValue *src); int gst_value_compare (const GValue *src1, const GValue *src2); gboolean gst_value_intersect (GValue *dest, const GValue *src1, const GValue *src2); gboolean gst_value_union (GValue *dest, const GValue *src1, const GValue *src2); -- 2.7.4