diff options
author | David Zeuthen <davidz@redhat.com> | 2008-12-07 00:39:47 -0500 |
---|---|---|
committer | David Zeuthen <davidz@redhat.com> | 2008-12-07 00:39:47 -0500 |
commit | d057ff0183cdf4eb0686cc57b142f577001d32c1 (patch) | |
tree | 57bff610e40a5d9803b7ac62b55965216c690295 | |
parent | a37e773de605836ebc407fb2df779626f5cdf0d4 (diff) |
make struct getters non-reffing
There's really no point in reffing the values except for being
annoying... it's not like real D-Bus interfaces where properties can
change all the time.
-rw-r--r-- | src/eggdbus/eggdbusstructure.c | 20 | ||||
-rw-r--r-- | src/eggdbus/struct.c | 4 | ||||
-rw-r--r-- | src/tests/testclient.c | 62 | ||||
-rw-r--r-- | src/tests/testsubject.c | 10 |
4 files changed, 33 insertions, 63 deletions
diff --git a/src/eggdbus/eggdbusstructure.c b/src/eggdbus/eggdbusstructure.c index b04e6c8..f445ca3 100644 --- a/src/eggdbus/eggdbusstructure.c +++ b/src/eggdbus/eggdbusstructure.c @@ -139,12 +139,13 @@ egg_dbus_structure_get_num_elements (EggDBusStructure *structure) * @...: Return location for the first element, followed optionally by * more element number / return location pairs, followed by -1. * - * Gets element values in a #EggDBusStructure. + * Gets element values in a #EggDBusStructure. The returned values + * should not be freed; @structure owns the reference. **/ void egg_dbus_structure_get_element (EggDBusStructure *structure, - guint first_structure_element_number, - ...) + guint first_structure_element_number, + ...) { va_list var_args; @@ -167,8 +168,8 @@ egg_dbus_structure_get_element (EggDBusStructure *structure, **/ void egg_dbus_structure_get_element_valist (EggDBusStructure *structure, - guint first_structure_elem_number, - va_list var_args) + guint first_structure_elem_number, + va_list var_args) { EggDBusStructurePrivate *priv; guint elem_number; @@ -188,7 +189,7 @@ egg_dbus_structure_get_element_valist (EggDBusStructure *structure, break; } - G_VALUE_LCOPY (&(priv->elem_values[elem_number]), var_args, 0, &error); + G_VALUE_LCOPY (&(priv->elem_values[elem_number]), var_args, G_VALUE_NOCOPY_CONTENTS, &error); if (error != NULL) { g_warning ("%s: %s", G_STRFUNC, error); @@ -208,12 +209,13 @@ egg_dbus_structure_get_element_valist (EggDBusStructure *structure, * * Sets @value to the contents of the value of @element_number. This * will also initalize @value so it needs to be uninitialized - * (e.g. set to zeroes). + * (e.g. set to zeroes). Unlike egg_dbus_structure_get_element(), note + * that the value is copied; use g_value_unset() to free it. **/ void egg_dbus_structure_get_element_as_gvalue (EggDBusStructure *structure, - guint elem_number, - GValue *value) + guint elem_number, + GValue *value) { EggDBusStructurePrivate *priv; diff --git a/src/eggdbus/struct.c b/src/eggdbus/struct.c index 7c41449..4fd878e 100644 --- a/src/eggdbus/struct.c +++ b/src/eggdbus/struct.c @@ -342,7 +342,7 @@ struct_generate_h_file (StructData *struct_data, type_name = get_type_names_for_signature (struct_data->elements[n]->signature, struct_data->elements[n]->annotations, FALSE, - FALSE, + TRUE, NULL, NULL, NULL, @@ -524,7 +524,7 @@ struct_generate_c_file (StructData *struct_data, type_name = get_type_names_for_signature (struct_data->elements[n]->signature, struct_data->elements[n]->annotations, FALSE, - FALSE, + TRUE, NULL, &free_function_name, NULL, diff --git a/src/tests/testclient.c b/src/tests/testclient.c index f4db7ea..2520fd9 100644 --- a/src/tests/testclient.c +++ b/src/tests/testclient.c @@ -673,7 +673,7 @@ test_structure_types (void) TestPoint *res_point; TestPoint *res_point2; TestDescribedPoint *res_dpoint; - char *s; + const char *s; error = NULL; @@ -695,11 +695,9 @@ test_structure_types (void) res_point2 = test_described_point_get_point (res_dpoint); g_assert_cmpint (test_point_get_x (point2) + 2, ==, test_point_get_x (res_point2)); g_assert_cmpint (test_point_get_y (point2) + 2, ==, test_point_get_y (res_point2)); - g_object_unref (res_point2); s = test_described_point_get_desc (res_dpoint); g_assert_cmpstr (s, ==, "replaced desc"); - g_free (s); g_object_unref (res_dpoint); g_object_unref (res_point); @@ -749,9 +747,9 @@ test_array_of_structure_types (void) TestPoint *res_point; TestExtendedDescribedPoint *edpoint; TestExtendedDescribedPoint *res_edpoint; - char *res_s; + const char *res_s; char *p; - char *s; + const char *s; edpoint = TEST_EXTENDED_DESCRIBED_POINT (g_list_nth_data (list, n)); res_edpoint = TEST_EXTENDED_DESCRIBED_POINT (g_list_nth_data (res_list, n)); @@ -760,23 +758,17 @@ test_array_of_structure_types (void) res_point = test_extended_described_point_get_point (res_edpoint); g_assert_cmpint (test_point_get_x (point) + 1, ==, test_point_get_x (res_point)); g_assert_cmpint (test_point_get_y (point) + 1, ==, test_point_get_y (res_point)); - g_object_unref (point); - g_object_unref (res_point); s = test_extended_described_point_get_desc (edpoint); res_s = test_extended_described_point_get_desc (res_edpoint); p = g_strdup_printf ("%s_%d", s, n); g_assert_cmpstr (p, ==, res_s); - g_free (s); - g_free (res_s); g_free (p); s = test_extended_described_point_get_ext_desc (edpoint); res_s = test_extended_described_point_get_ext_desc (res_edpoint); p = g_strdup_printf ("%s_%d", s, n); g_assert_cmpstr (p, ==, res_s); - g_free (s); - g_free (res_s); g_free (p); } @@ -1316,7 +1308,7 @@ test_hash_table_of_structures (void) GHashTable *hash_of_described_points; TestPoint *point; TestDescribedPoint *dpoint; - char *s; + const char *s; error = NULL; @@ -1338,8 +1330,6 @@ test_hash_table_of_structures (void) g_assert_cmpstr (s, ==, "alpha"); g_assert_cmpint (test_point_get_x (point), ==, 10 + 100); g_assert_cmpint (test_point_get_y (point), ==, 10 + 200); - g_object_unref (point); - g_free (s); dpoint = g_hash_table_lookup (hash_of_described_points, "beta_new"); s = test_described_point_get_desc (dpoint); @@ -1347,8 +1337,6 @@ test_hash_table_of_structures (void) g_assert_cmpstr (s, ==, "beta"); g_assert_cmpint (test_point_get_x (point), ==, 12 + 100); g_assert_cmpint (test_point_get_y (point), ==, 12 + 200); - g_object_unref (point); - g_free (s); dpoint = g_hash_table_lookup (hash_of_described_points, "gamma_new"); s = test_described_point_get_desc (dpoint); @@ -1356,8 +1344,6 @@ test_hash_table_of_structures (void) g_assert_cmpstr (s, ==, "gamma"); g_assert_cmpint (test_point_get_x (point), ==, 14 + 100); g_assert_cmpint (test_point_get_y (point), ==, 14 + 200); - g_object_unref (point); - g_free (s); g_hash_table_unref (hash_of_points); egg_dbus_hash_table_unref (hash_of_described_points); @@ -1695,7 +1681,7 @@ test_variant_return (void) TestPoint *point; TestDescribedPoint *dpoint; GHashTable *hash_of_points; - char *s; + const char *s; error = NULL; @@ -1872,12 +1858,9 @@ test_variant_return (void) dpoint = TEST_DESCRIBED_POINT (egg_dbus_variant_get_structure (variant)); s = test_described_point_get_desc (dpoint); g_assert_cmpstr (s, ==, "the desc"); - g_free (s); point = test_described_point_get_point (dpoint); g_assert_cmpint (test_point_get_x (point), ==, 3); g_assert_cmpint (test_point_get_y (point), ==, 4); - g_object_unref (point); - g_object_unref (variant); g_assert (test_frob_invoke_test_variant_return (TEST_FROB (proxy), 0, /* flags */ @@ -1914,8 +1897,8 @@ test_variant_return (void) structure = egg_dbus_variant_get_structure (variant); egg_dbus_structure_get_element (structure, - 4, &my_array, - -1); + 4, &my_array, + -1); g_assert_cmpstr (egg_dbus_array_get_elem_signature (my_array), ==, "i"); g_assert_cmpuint (my_array->len, ==, 4); @@ -1923,7 +1906,6 @@ test_variant_return (void) g_assert_cmpint (g_array_index (my_array, gint32, 1), ==, 1); g_assert_cmpint (g_array_index (my_array, gint32, 2), ==, 2); g_assert_cmpint (g_array_index (my_array, gint32, 3), ==, 3); - egg_dbus_array_free (my_array); g_object_unref (variant); } @@ -2465,18 +2447,16 @@ frob_signal_with_struct_and_hash_cb (TestFrob *instance, { gboolean *b = user_data; TestPoint *point2; - gchar *desc; + const gchar *desc; g_assert_cmpint (test_point_get_x (point), ==, 40); g_assert_cmpint (test_point_get_y (point), ==, 41); desc = test_described_point_get_desc (dpoint); g_assert_cmpstr (desc, ==, "xmas"); - g_free (desc); point2 = test_described_point_get_point (dpoint); g_assert_cmpint (test_point_get_x (point2), ==, 42); g_assert_cmpint (test_point_get_y (point2), ==, 43); - g_object_unref (point2); g_assert_cmpint (g_hash_table_size (hash_of_string_to_string), ==, 3); g_assert_cmpstr (g_hash_table_lookup (hash_of_string_to_string, "secret"), ==, "emerald"); @@ -2750,8 +2730,8 @@ test_egg_dbus_structure (void) { EggDBusStructure *as; GValue *values; - gchar *s1; - gchar *s2; + const gchar *s1; + const gchar *s2; gint i1; gint i2; gint16 n; @@ -2786,19 +2766,17 @@ test_egg_dbus_structure (void) /* check we get the right values back */ egg_dbus_structure_get_element (as, - 0, &s1, - 1, &s2, - 2, &i1, - 3, &n, - 4, &d, - -1); + 0, &s1, + 1, &s2, + 2, &i1, + 3, &n, + 4, &d, + -1); g_assert_cmpstr (s1, ==, "a string"); g_assert_cmpstr (s2, ==, "another string"); g_assert_cmpint (i1, ==, 42); g_assert_cmpint (n, ==, 43); g_assert_cmpint (d, ==, 0.5); - g_free (s1); - g_free (s2); /* check we can set elements */ egg_dbus_structure_set_element (as, @@ -2811,7 +2789,6 @@ test_egg_dbus_structure (void) -1); g_assert_cmpstr (s2, ==, "yet another string"); g_assert_cmpint (d, ==, 0.6); - g_free (s2); /* and as GValue */ egg_dbus_structure_get_element_as_gvalue (as, 0, &str_gvalue); @@ -2831,12 +2808,11 @@ test_egg_dbus_structure (void) /* and check that it's properly set */ egg_dbus_structure_get_element (as, - 0, &s1, - 2, &i1, - -1); + 0, &s1, + 2, &i1, + -1); g_assert_cmpstr (s1, ==, "modified string"); g_assert_cmpint (i1, ==, 44); - g_free (s1); g_object_unref (as); diff --git a/src/tests/testsubject.c b/src/tests/testsubject.c index e1cc363..198f9eb 100644 --- a/src/tests/testsubject.c +++ b/src/tests/testsubject.c @@ -150,7 +150,7 @@ test_subject_new (TestSubjectKind kind, TestSubjectKind test_subject_get_kind (TestSubject *subject) { - gchar *kind_str; + const gchar *kind_str; TestSubjectKind kind; g_return_val_if_fail (TEST_IS_SUBJECT (subject), TEST_SUBJECT_KIND_UNKNOWN); @@ -172,8 +172,6 @@ test_subject_get_kind (TestSubject *subject) kind = TEST_SUBJECT_KIND_UNKNOWN; } - g_free (kind_str); - return kind; } @@ -202,8 +200,6 @@ test_subject_get_name (TestSubject *subject) variant = g_hash_table_lookup (value, "name"); result = egg_dbus_variant_get_string (variant); - egg_dbus_hash_table_unref (value); - return result; } @@ -232,8 +228,6 @@ test_subject_get_favorite_food (TestSubject *subject) variant = g_hash_table_lookup (value, "favorite-food"); result = egg_dbus_variant_get_string (variant); - egg_dbus_hash_table_unref (value); - return result; } @@ -262,7 +256,5 @@ test_subject_get_favorite_color (TestSubject *subject) variant = g_hash_table_lookup (value, "favorite-color"); result = egg_dbus_variant_get_string (variant); - egg_dbus_hash_table_unref (value); - return result; } |