GVariant: add g_variant_take_ref()

This function implements the following logic:

  if (g_variant_is_floating (value))
    g_variant_ref_sink (value);

which is used for consuming the return value of callbacks that may or
may not return floating references.

This patch also replaces a few instances of the above code with the new
function (GSettings, GDBus) and lifts a long-standing restriction on the
use of floating values as the return value for signal handlers by
improving g_value_take_variant().

https://bugzilla.gnome.org/show_bug.cgi?id=627974
This commit is contained in:
Ryan Lortie
2011-07-11 14:27:53 +02:00
parent 2121e56ea7
commit 58c247e51b
8 changed files with 64 additions and 16 deletions

View File

@@ -2031,8 +2031,7 @@ class CodeGenerator:
' value = _%s_skeleton_handle_get_property (g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (skeleton)), NULL, g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (skeleton)), "%s", info->name, NULL, skeleton);\n'
' if (value != NULL)\n'
' {\n'
' if (g_variant_is_floating (value))\n'
' g_variant_ref_sink (value);\n'
' g_variant_take_ref (value);\n'
' g_variant_builder_add (&builder, "{sv}", info->name, value);\n'
' g_variant_unref (value);\n'
' }\n'

View File

@@ -3787,8 +3787,7 @@ invoke_get_property_in_idle_cb (gpointer _data)
{
g_assert_no_error (error);
if (g_variant_is_floating (value))
g_variant_ref_sink (value);
g_variant_take_ref (value);
reply = g_dbus_message_new_method_reply (data->message);
g_dbus_message_set_body (reply, g_variant_new ("(v)", value));
g_dbus_connection_send_message (data->connection, reply, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
@@ -4117,8 +4116,7 @@ invoke_get_all_properties_in_idle_cb (gpointer _data)
if (value == NULL)
continue;
if (g_variant_is_floating (value))
g_variant_ref_sink (value);
g_variant_take_ref (value);
g_variant_builder_add (&builder,
"{sv}",
property_info->name,

View File

@@ -2604,8 +2604,7 @@ g_settings_binding_property_changed (GObject *object,
if ((variant = binding->set_mapping (&value, binding->info.type,
binding->user_data)))
{
if (g_variant_is_floating (variant))
g_variant_ref_sink (variant);
g_variant_take_ref (variant);
if (!g_settings_type_check (&binding->info, variant))
{