From 93726dd3d8eade4c05d0d620110dccc3fc3b95b2 Mon Sep 17 00:00:00 2001 From: Peng Huang Date: Tue, 26 Jan 2010 21:22:06 +0800 Subject: [PATCH] Use GInitiallyUnowned correctly --- bus/Makefile.am | 4 +++- bus/dbusimpl.c | 5 ++--- bus/engineproxy.c | 39 ++++++++++++++++++--------------------- bus/factoryproxy.c | 2 +- bus/ibusimpl.c | 14 +++++++------- bus/inputcontext.c | 20 +++++++++++--------- bus/matchrule.c | 3 +-- bus/panelproxy.c | 2 +- bus/registry.c | 2 ++ client/gtk2/ibusimcontext.c | 1 + src/ibusattrlist.c | 3 +-- src/ibuscomponent.c | 4 ++++ src/ibusconfigservice.c | 1 - src/ibusconnection.c | 14 +++++++++++++- src/ibusengine.c | 2 +- src/ibusfactory.c | 2 +- src/ibusinputcontext.c | 18 ++++++++++++------ src/ibuskeymap.c | 6 ++++-- src/ibuskeymap.h | 8 ++++---- src/ibuslookuptable.c | 8 ++------ src/ibusobservedpath.c | 3 ++- src/ibuspanelservice.c | 16 +++++++++++++++- src/ibusproperty.c | 19 +++++++++++++------ src/ibusproplist.c | 10 ++++------ src/ibusproxy.c | 2 +- src/ibusserver.c | 6 +++++- src/ibusservice.c | 8 ++------ src/ibustext.c | 10 +++++++--- src/test-keymap.c | 2 +- 29 files changed, 139 insertions(+), 95 deletions(-) diff --git a/bus/Makefile.am b/bus/Makefile.am index d59550c..e9dffa9 100644 --- a/bus/Makefile.am +++ b/bus/Makefile.am @@ -126,4 +126,6 @@ $(libibus): $(MAKE) -C $(top_builddir)/src test: ibus-daemon - $(builddir)/ibus-daemon -v + $(ENV) \ + G_DEBUG=fatal_warnings \ + $(builddir)/ibus-daemon -v diff --git a/bus/dbusimpl.c b/bus/dbusimpl.c index 93066aa..980e8ca 100644 --- a/bus/dbusimpl.c +++ b/bus/dbusimpl.c @@ -979,7 +979,7 @@ bus_dbus_impl_new_connection (BusDBusImpl *dbus, g_assert (g_list_find (dbus->connections, connection) == NULL); - g_object_ref (connection); + g_object_ref_sink (connection); dbus->connections = g_list_append (dbus->connections, connection); g_signal_connect (connection, @@ -1100,7 +1100,6 @@ bus_dbus_impl_dispatch_message_by_rule (BusDBusImpl *dbus, if (connection != skip_connection) { ibus_connection_send (IBUS_CONNECTION (connection), message); } - g_object_unref (connection); } g_list_free (recipients); } @@ -1132,7 +1131,7 @@ bus_dbus_impl_register_object (BusDBusImpl *dbus, g_return_val_if_fail (g_hash_table_lookup (dbus->objects, path) == NULL, FALSE); - g_object_ref (object); + g_object_ref_sink (object); g_hash_table_insert (dbus->objects, (gpointer)path, object); g_signal_connect (object, "destroy", G_CALLBACK (_object_destroy_cb), dbus); diff --git a/bus/engineproxy.c b/bus/engineproxy.c index cc3193f..2d8d85e 100644 --- a/bus/engineproxy.c +++ b/bus/engineproxy.c @@ -105,13 +105,13 @@ bus_engine_proxy_new (const gchar *path, NULL); engine->desc = desc; - g_object_ref (desc); + g_object_ref_sink (desc); if (desc->layout != NULL && desc->layout[0] != '\0') { - engine->keymap = ibus_keymap_new (desc->layout); + engine->keymap = ibus_keymap_get (desc->layout); } if (engine->keymap == NULL) { - engine->keymap = ibus_keymap_new ("us"); + engine->keymap = ibus_keymap_get ("us"); } return engine; @@ -332,7 +332,6 @@ static void bus_engine_proxy_init (BusEngineProxy *engine) { engine->enabled = FALSE; - engine->prop_list = NULL; engine->desc = NULL; engine->keymap = NULL; } @@ -340,11 +339,6 @@ bus_engine_proxy_init (BusEngineProxy *engine) static void bus_engine_proxy_real_destroy (BusEngineProxy *engine) { - if (engine->prop_list) { - g_object_unref (engine->prop_list); - engine->prop_list = NULL; - } - if (ibus_proxy_get_connection ((IBusProxy *) engine)) { ibus_proxy_call ((IBusProxy *) engine, "Destroy", @@ -476,7 +470,8 @@ bus_engine_proxy_ibus_signal (IBusProxy *proxy, g_signal_emit (engine, engine_signals[UPDATE_PREEDIT_TEXT], 0, text, cursor_pos, visible); - g_object_unref (text); + if (g_object_is_floating (text)) + g_object_unref (text); } else if (g_strcmp0 (name, "UpdateAuxiliaryText") == 0) { IBusText *text; @@ -493,7 +488,8 @@ bus_engine_proxy_ibus_signal (IBusProxy *proxy, goto failed; g_signal_emit (engine, engine_signals[UPDATE_AUXILIARY_TEXT], 0, text, visible); - g_object_unref (text); + if (g_object_is_floating (text)) + g_object_unref (text); } else if (g_strcmp0 (name, "UpdateLookupTable") == 0) { IBusLookupTable *table; @@ -510,25 +506,25 @@ bus_engine_proxy_ibus_signal (IBusProxy *proxy, goto failed; g_signal_emit (engine, engine_signals[UPDATE_LOOKUP_TABLE], 0, table, visible); - g_object_unref (table); + if (g_object_is_floating (table)) + g_object_unref (table); } else if (g_strcmp0 (name, "RegisterProperties") == 0) { gboolean retval; - - if (engine->prop_list) { - g_object_unref (engine->prop_list); - engine->prop_list = NULL; - } + IBusPropList *prop_list; retval = ibus_message_get_args (message, &error, - IBUS_TYPE_PROP_LIST, &engine->prop_list, + IBUS_TYPE_PROP_LIST, &prop_list, G_TYPE_INVALID); if (!retval) { - engine->prop_list = NULL; goto failed; } - g_signal_emit (engine, engine_signals[REGISTER_PROPERTIES], 0, engine->prop_list); + g_signal_emit (engine, engine_signals[REGISTER_PROPERTIES], 0, prop_list); + + if (g_object_is_floating (prop_list)) + g_object_unref (prop_list); + } else if (g_strcmp0 (name, "UpdateProperty") == 0) { IBusProperty *prop; @@ -543,7 +539,8 @@ bus_engine_proxy_ibus_signal (IBusProxy *proxy, goto failed; g_signal_emit (engine, engine_signals[UPDATE_PROPERTY], 0, prop); - g_object_unref (prop); + if (g_object_is_floating (prop)) + g_object_unref (prop); } else return FALSE; diff --git a/bus/factoryproxy.c b/bus/factoryproxy.c index 91115d6..dd97621 100644 --- a/bus/factoryproxy.c +++ b/bus/factoryproxy.c @@ -82,7 +82,7 @@ bus_factory_proxy_new (IBusComponent *component, "connection", connection, NULL); - g_object_ref (component); + g_object_ref_sink (component); factory->component = component; g_object_set_data ((GObject *)factory->component, "factory", factory); diff --git a/bus/ibusimpl.c b/bus/ibusimpl.c index 8ebf2a6..10f1164 100644 --- a/bus/ibusimpl.c +++ b/bus/ibusimpl.c @@ -403,8 +403,8 @@ _config_destroy_cb (IBusConfig *config, g_assert (ibus->config == config); + g_object_unref (ibus->config); ibus->config = NULL; - g_object_unref (config); } static void @@ -442,6 +442,7 @@ _dbus_name_owner_changed_cb (BusDBusImpl *dbus, g_return_if_fail (connection != NULL); ibus->panel = bus_panel_proxy_new (connection); + g_object_ref_sink (ibus->panel); g_signal_connect (ibus->panel, "destroy", @@ -470,6 +471,7 @@ _dbus_name_owner_changed_cb (BusDBusImpl *dbus, "path", IBUS_PATH_CONFIG, "connection", connection, NULL); + g_object_ref_sink (ibus->config); g_signal_connect (ibus->config, "value-changed", @@ -490,7 +492,6 @@ _dbus_name_owner_changed_cb (BusDBusImpl *dbus, if (factory) { bus_ibus_impl_add_factory (ibus, factory); - g_object_unref (factory); } } @@ -524,7 +525,7 @@ bus_ibus_impl_init (BusIBusImpl *ibus) #endif ibus->hotkey_profile = ibus_hotkey_profile_new (); - ibus->keymap = ibus_keymap_new ("us"); + ibus->keymap = ibus_keymap_get ("us"); ibus->use_sys_layout = FALSE; @@ -782,7 +783,6 @@ _context_request_engine_cb (BusInputContext *context, } bus_input_context_set_engine (context, engine); - g_object_unref (engine); } static void @@ -828,7 +828,6 @@ _context_request_next_engine_cb (BusInputContext *context, if (next_desc != NULL) { engine = bus_ibus_impl_create_engine (next_desc); bus_input_context_set_engine (context, engine); - g_object_unref (engine); } } @@ -926,6 +925,7 @@ _ibus_create_input_context (BusIBusImpl *ibus, } context = bus_input_context_new (connection, client); + g_object_ref_sink (context); ibus->contexts = g_list_append (ibus->contexts, context); static const struct { @@ -1022,7 +1022,7 @@ bus_ibus_impl_add_factory (BusIBusImpl *ibus, g_assert (BUS_IS_IBUS_IMPL (ibus)); g_assert (BUS_IS_FACTORY_PROXY (factory)); - g_object_ref (factory); + g_object_ref_sink (factory); ibus->factory_list = g_list_append (ibus->factory_list, factory); g_signal_connect (factory, "destroy", G_CALLBACK (_factory_destroy_cb), ibus); @@ -1054,6 +1054,7 @@ _ibus_register_component (BusIBusImpl *ibus, return reply; } + g_object_ref_sink (component); factory = bus_factory_proxy_new (component, connection); if (factory == NULL) { @@ -1064,7 +1065,6 @@ _ibus_register_component (BusIBusImpl *ibus, } bus_ibus_impl_add_factory (ibus, factory); - g_object_unref (factory); engines = ibus_component_get_engines (component); diff --git a/bus/inputcontext.c b/bus/inputcontext.c index a39f91f..7b105b4 100644 --- a/bus/inputcontext.c +++ b/bus/inputcontext.c @@ -188,7 +188,7 @@ bus_input_context_new (BusConnection *connection, IBUS_CONNECTION (connection)); #endif - g_object_ref (connection); + g_object_ref_sink (connection); context->connection = connection; context->client = g_strdup (client); @@ -471,8 +471,11 @@ bus_input_context_class_init (BusInputContextClass *klass) 0); text_empty = ibus_text_new_from_string (""); + g_object_ref_sink (text_empty); lookup_table_empty = ibus_lookup_table_new (9, 0, FALSE, FALSE); + g_object_ref_sink (lookup_table_empty); props_empty = ibus_prop_list_new (); + g_object_ref_sink (props_empty); } static void @@ -494,20 +497,19 @@ bus_input_context_init (BusInputContext *context) context->w = 0; context->h = 0; - g_object_ref (text_empty); + g_object_ref_sink (text_empty); context->preedit_text = text_empty; context->preedit_cursor_pos = 0; context->preedit_visible = FALSE; - g_object_ref (text_empty); + g_object_ref_sink (text_empty); context->auxiliary_text = text_empty; context->auxiliary_visible = FALSE; - g_object_ref (lookup_table_empty); + g_object_ref_sink (lookup_table_empty); context->lookup_table = lookup_table_empty; context->lookup_table_visible = FALSE; - g_object_ref (props_empty); } static void @@ -1289,7 +1291,7 @@ bus_input_context_update_preedit_text (BusInputContext *context, g_object_unref (context->preedit_text); } - context->preedit_text = (IBusText *) g_object_ref (text ? text : text_empty); + context->preedit_text = (IBusText *) g_object_ref_sink (text ? text : text_empty); context->preedit_cursor_pos = cursor_pos; context->preedit_visible = visible; @@ -1368,7 +1370,7 @@ bus_input_context_update_auxiliary_text (BusInputContext *context, g_object_unref (context->auxiliary_text); } - context->auxiliary_text = (IBusText *) g_object_ref (text ? text : text_empty); + context->auxiliary_text = (IBusText *) g_object_ref_sink (text ? text : text_empty); context->auxiliary_visible = visible; if (context->capabilities & IBUS_CAP_AUXILIARY_TEXT) { @@ -1444,7 +1446,7 @@ bus_input_context_update_lookup_table (BusInputContext *context, g_object_unref (context->lookup_table); } - context->lookup_table = (IBusLookupTable *) g_object_ref (table ? table : lookup_table_empty); + context->lookup_table = (IBusLookupTable *) g_object_ref_sink (table ? table : lookup_table_empty); context->lookup_table_visible = visible; if (context->capabilities & IBUS_CAP_LOOKUP_TABLE) { @@ -1926,7 +1928,7 @@ bus_input_context_set_engine (BusInputContext *context, else { gint i; context->engine = engine; - g_object_ref (context->engine); + g_object_ref_sink (context->engine); for (i = 0; signals[i].name != NULL; i++) { g_signal_connect (context->engine, diff --git a/bus/matchrule.c b/bus/matchrule.c index 8e5d488..1bf775f 100644 --- a/bus/matchrule.c +++ b/bus/matchrule.c @@ -607,7 +607,7 @@ bus_match_rule_add_recipient (BusMatchRule *rule, recipient = g_slice_new (BusRecipient); - g_object_ref (connection); + g_object_ref_sink (connection); recipient->connection = connection; recipient->refcount = 1; @@ -667,7 +667,6 @@ bus_match_rule_get_recipients (BusMatchRule *rule, for (link = rule->recipients; link != NULL; link = link->next) { BusRecipient *recipient = (BusRecipient *) link->data; - g_object_ref (recipient->connection); recipients = g_list_append (recipients, recipient->connection); } diff --git a/bus/panelproxy.c b/bus/panelproxy.c index 7532bf1..01f5aea 100644 --- a/bus/panelproxy.c +++ b/bus/panelproxy.c @@ -668,7 +668,7 @@ bus_panel_proxy_focus_in (BusPanelProxy *panel, if (panel->focused_context != NULL) bus_panel_proxy_focus_out (panel, panel->focused_context); - g_object_ref (context); + g_object_ref_sink (context); panel->focused_context = context; const gchar *path = ibus_service_get_path ((IBusService *)context); diff --git a/bus/registry.c b/bus/registry.c index 97e9cff..8b71280 100644 --- a/bus/registry.c +++ b/bus/registry.c @@ -247,6 +247,7 @@ bus_registry_load_cache (BusRegistry *registry) IBusObservedPath *path; path = ibus_observed_path_new_from_xml_node (pp->data, FALSE); if (path) { + g_object_ref_sink (path); registry->observed_paths = g_list_append (registry->observed_paths, path); } } @@ -258,6 +259,7 @@ bus_registry_load_cache (BusRegistry *registry) IBusComponent *component; component = ibus_component_new_from_xml_node (pp->data); if (component) { + g_object_ref_sink (component); registry->components = g_list_append (registry->components, component); } } diff --git a/client/gtk2/ibusimcontext.c b/client/gtk2/ibusimcontext.c index d5f89fb..8ac2fb8 100644 --- a/client/gtk2/ibusimcontext.c +++ b/client/gtk2/ibusimcontext.c @@ -898,6 +898,7 @@ _create_input_context (IBusIMContext *ibusimcontext) ibusimcontext->ibuscontext = ibus_bus_create_input_context (_bus, "test"); g_return_if_fail (ibusimcontext->ibuscontext != NULL); + g_object_ref_sink (ibusimcontext->ibuscontext); g_signal_connect (ibusimcontext->ibuscontext, "commit-text", diff --git a/src/ibusattrlist.c b/src/ibusattrlist.c index 81d558f..cbdea98 100644 --- a/src/ibusattrlist.c +++ b/src/ibusattrlist.c @@ -161,7 +161,6 @@ ibus_attr_list_deserialize (IBusAttrList *attr_list, ibus_message_iter_next (&array_iter); ibus_attr_list_append (attr_list, attr); - g_object_unref (attr); } ibus_message_iter_next (iter); @@ -217,7 +216,7 @@ ibus_attr_list_append (IBusAttrList *attr_list, g_assert (IBUS_IS_ATTR_LIST (attr_list)); g_assert (IBUS_IS_ATTRIBUTE (attr)); - g_object_ref (attr); + g_object_ref_sink (attr); g_array_append_val (attr_list->attributes, attr); } diff --git a/src/ibuscomponent.c b/src/ibuscomponent.c index 263c72c..4cb16a6 100644 --- a/src/ibuscomponent.c +++ b/src/ibuscomponent.c @@ -282,6 +282,7 @@ ibus_component_deserialize (IBusComponent *component, g_return_val_if_fail (retval, FALSE); ibus_message_iter_next (&array_iter); + g_object_ref_sink (path); component->observed_paths = g_list_append (component->observed_paths, path); } ibus_message_iter_next (iter); @@ -537,6 +538,7 @@ ibus_component_parse_observed_paths (IBusComponent *component, IBusObservedPath *path; path = ibus_observed_path_new_from_xml_node ((XMLNode *)p->data, access_fs); + g_object_ref_sink (path); component->observed_paths = g_list_append (component->observed_paths, path); if (access_fs && path->is_dir && path->is_exist) { @@ -635,6 +637,7 @@ ibus_component_add_observed_path (IBusComponent *component, IBusObservedPath *p; p = ibus_observed_path_new (path, access_fs); + g_object_ref_sink (p); component->observed_paths = g_list_append (component->observed_paths, p); if (access_fs && p->is_dir && p->is_exist) { @@ -650,6 +653,7 @@ ibus_component_add_engine (IBusComponent *component, g_assert (IBUS_IS_COMPONENT (component)); g_assert (IBUS_IS_ENGINE_DESC (engine)); + g_object_ref_sink (engine); component->engines = g_list_append (component->engines, engine); g_object_set_data ((GObject *)engine, "component", component); } diff --git a/src/ibusconfigservice.c b/src/ibusconfigservice.c index dad8647..30d515b 100644 --- a/src/ibusconfigservice.c +++ b/src/ibusconfigservice.c @@ -177,7 +177,6 @@ ibus_config_service_get_property (IBusConfigService *config, else { g_value_set_object (value, NULL); } - g_list_foreach (connections, (GFunc) g_object_unref, NULL); g_list_free (connections); } break; diff --git a/src/ibusconnection.c b/src/ibusconnection.c index 682bb12..5d16418 100644 --- a/src/ibusconnection.c +++ b/src/ibusconnection.c @@ -378,6 +378,14 @@ ibus_connection_set_connection (IBusConnection *connection, DBusConnection *dbus g_warn_if_fail (result); } +static void +_connection_destroy_cb (IBusConnection *connection, + gpointer user_data) +{ + g_hash_table_remove (_connections, user_data); + g_object_unref (connection); +} + IBusConnection * ibus_connection_open (const gchar *address) { @@ -409,8 +417,12 @@ ibus_connection_open (const gchar *address) } connection = ibus_connection_new (); + g_object_ref_sink (connection); + ibus_connection_set_connection (connection, dbus_connection, TRUE); - g_hash_table_insert (_connections, dbus_connection, connection); + g_hash_table_insert (_connections, dbus_connection, g_object_ref (connection)); + + g_signal_connect (connection, "destroy", G_CALLBACK (_connection_destroy_cb), dbus_connection); return connection; } diff --git a/src/ibusengine.c b/src/ibusengine.c index aa27fbb..c7c9d55 100644 --- a/src/ibusengine.c +++ b/src/ibusengine.c @@ -610,7 +610,7 @@ ibus_engine_set_property (IBusEngine *engine, case PROP_CONNECTION: priv->connection = g_value_get_object (value); - g_object_ref (priv->connection); + g_object_ref_sink (priv->connection); ibus_service_add_to_connection ((IBusService *) engine, priv->connection); break; diff --git a/src/ibusfactory.c b/src/ibusfactory.c index 738c150..8a0fefe 100644 --- a/src/ibusfactory.c +++ b/src/ibusfactory.c @@ -92,7 +92,7 @@ ibus_factory_new (IBusConnection *connection) NULL); priv = IBUS_FACTORY_GET_PRIVATE (factory); - priv->connection = g_object_ref (connection); + priv->connection = g_object_ref_sink (connection); ibus_service_add_to_connection ((IBusService *)factory, connection); return factory; diff --git a/src/ibusinputcontext.c b/src/ibusinputcontext.c index 6d8a2de..2493983 100644 --- a/src/ibusinputcontext.c +++ b/src/ibusinputcontext.c @@ -557,7 +557,8 @@ ibus_input_context_ibus_signal (IBusProxy *proxy, G_TYPE_INVALID); if (retval) { g_signal_emit (context, context_signals[COMMIT_TEXT], 0, text); - g_object_unref (text); + if (g_object_is_floating (text)) + g_object_unref (text); } break; } @@ -581,7 +582,8 @@ ibus_input_context_ibus_signal (IBusProxy *proxy, text, cursor_pos, visible); - g_object_unref (text); + if (g_object_is_floating (text)) + g_object_unref (text); } break; } @@ -612,7 +614,8 @@ ibus_input_context_ibus_signal (IBusProxy *proxy, 0, text, visible); - g_object_unref (text); + if (g_object_is_floating (text)) + g_object_unref (text); } } else if (g_strcmp0 (name, "UpdateLookupTable") == 0) { @@ -632,7 +635,8 @@ ibus_input_context_ibus_signal (IBusProxy *proxy, 0, table, visible); - g_object_unref (table); + if (g_object_is_floating (table)) + g_object_unref (table); } } else if (g_strcmp0 (name, "RegisterProperties") == 0) { @@ -649,7 +653,8 @@ ibus_input_context_ibus_signal (IBusProxy *proxy, context_signals[REGISTER_PROPERTIES], 0, prop_list); - g_object_unref (prop_list); + if (g_object_is_floating (prop_list)) + g_object_unref (prop_list); } } else if (g_strcmp0 (name, "UpdateProperty") == 0) { @@ -662,7 +667,8 @@ ibus_input_context_ibus_signal (IBusProxy *proxy, G_TYPE_INVALID); if (retval) { g_signal_emit (context, context_signals[UPDATE_PROPERTY], 0, prop); - g_object_unref (prop); + if (g_object_is_floating (prop)) + g_object_unref (prop); } } else if (g_strcmp0 (name, "ForwardKeyEvent") == 0) { diff --git a/src/ibuskeymap.c b/src/ibuskeymap.c index 1396cbc..57f2c25 100644 --- a/src/ibuskeymap.c +++ b/src/ibuskeymap.c @@ -256,10 +256,11 @@ _keymap_destroy_cb (IBusKeymap *keymap, gpointer user_data) { g_hash_table_remove (keymaps, keymap->name); + g_object_unref (keymap); } IBusKeymap * -ibus_keymap_new (const gchar *name) +ibus_keymap_get (const gchar *name) { g_assert (name != NULL); @@ -279,6 +280,8 @@ ibus_keymap_new (const gchar *name) } keymap = g_object_new (IBUS_TYPE_KEYMAP, NULL); + g_object_ref_sink (keymap); + if (!ibus_keymap_load (name, keymap->keymap)) { g_object_unref (keymap); return NULL; @@ -293,7 +296,6 @@ ibus_keymap_new (const gchar *name) return keymap; } - guint32 ibus_keymap_lookup_keysym (IBusKeymap *keymap, guint16 keycode, diff --git a/src/ibuskeymap.h b/src/ibuskeymap.h index 47f366b..a0b3edc 100644 --- a/src/ibuskeymap.h +++ b/src/ibuskeymap.h @@ -103,16 +103,16 @@ struct _IBusKeymapClass { GType ibus_keymap_get_type (void); /** - * ibus_keymap_new: + * ibus_keymap_get: * @name: The keymap file to be loaded, such as 'us', 'jp'. - * @returns: A newly allocated IBusKeymap; or NULL if failed. + * @returns: An IBusKeymap associated with the giving name; or NULL if failed. * - * New an IBusKeymap. + * Get an IBusKeymap associated with the giving name. * * This function loads the keymap file specified in @name * in the IBUS_DATA_DIR/keymaps directory. */ -IBusKeymap *ibus_keymap_new (const gchar *name); +IBusKeymap *ibus_keymap_get (const gchar *name); /** * ibus_keymap_lookup_keysym: diff --git a/src/ibuslookuptable.c b/src/ibuslookuptable.c index ca2da67..10c3f34 100644 --- a/src/ibuslookuptable.c +++ b/src/ibuslookuptable.c @@ -228,7 +228,6 @@ ibus_lookup_table_deserialize (IBusLookupTable *table, ibus_message_iter_next (&array_iter); ibus_lookup_table_append_candidate (table, text); - g_object_unref (text); } ibus_message_iter_next (iter); @@ -244,7 +243,6 @@ ibus_lookup_table_deserialize (IBusLookupTable *table, ibus_message_iter_next (&array_iter); ibus_lookup_table_append_label (table, text); - g_object_unref (text); } ibus_message_iter_next (iter); @@ -276,7 +274,6 @@ ibus_lookup_table_copy (IBusLookupTable *dest, text = (IBusText *) ibus_serializable_copy ((IBusSerializable *) text); ibus_lookup_table_append_candidate (dest, text); - g_object_unref (text); } // copy labels @@ -290,7 +287,6 @@ ibus_lookup_table_copy (IBusLookupTable *dest, text = (IBusText *) ibus_serializable_copy ((IBusSerializable *) text); ibus_lookup_table_append_label (dest, text); - g_object_unref (text); } return TRUE; @@ -333,7 +329,7 @@ ibus_lookup_table_append_candidate (IBusLookupTable *table, g_assert (IBUS_IS_LOOKUP_TABLE (table)); g_assert (IBUS_IS_TEXT (text)); - g_object_ref (text); + g_object_ref_sink (text); g_array_append_val (table->candidates, text); } @@ -356,7 +352,7 @@ ibus_lookup_table_append_label (IBusLookupTable *table, g_assert (IBUS_IS_LOOKUP_TABLE (table)); g_assert (IBUS_IS_TEXT (text)); - g_object_ref (text); + g_object_ref_sink (text); g_array_append_val (table->labels, text); } diff --git a/src/ibusobservedpath.c b/src/ibusobservedpath.c index 03de525..87a2653 100644 --- a/src/ibusobservedpath.c +++ b/src/ibusobservedpath.c @@ -246,6 +246,7 @@ ibus_observed_path_traverse (IBusObservedPath *path) IBusObservedPath *sub; sub = g_object_new (IBUS_TYPE_OBSERVED_PATH, NULL); + g_object_ref_sink (sub); sub->path = g_build_filename (path->path, name, NULL); ibus_observed_path_fill_stat (sub); @@ -261,7 +262,7 @@ ibus_observed_path_traverse (IBusObservedPath *path) static gboolean ibus_observed_path_parse_xml_node (IBusObservedPath *path, - XMLNode *node) + XMLNode *node) { g_assert (IBUS_IS_OBSERVED_PATH (path)); g_assert (node); diff --git a/src/ibuspanelservice.c b/src/ibuspanelservice.c index 60690f0..4a8eb0e 100644 --- a/src/ibuspanelservice.c +++ b/src/ibuspanelservice.c @@ -211,7 +211,6 @@ ibus_panel_service_service_get_property (IBusPanelService *panel, else { g_value_set_object (value, NULL); } - g_list_foreach (connections, (GFunc) g_object_unref, NULL); g_list_free (connections); } break; @@ -364,6 +363,9 @@ ibus_panel_service_ibus_message (IBusPanelService *panel, else { reply = ibus_message_new_method_return (message); } + + if (prop_list != NULL && g_object_is_floating (prop_list)) + g_object_unref (prop_list); } else if (ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, "UpdateAuxiliaryText")) { IBusText *text = NULL; @@ -389,6 +391,9 @@ ibus_panel_service_ibus_message (IBusPanelService *panel, else { reply = ibus_message_new_method_return (message); } + + if (text != NULL && g_object_is_floating (text)) + g_object_unref (text); } else if (ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, "UpdateLookupTable")) { IBusLookupTable *table = NULL; @@ -414,6 +419,9 @@ ibus_panel_service_ibus_message (IBusPanelService *panel, else { reply = ibus_message_new_method_return (message); } + + if (table != NULL && g_object_is_floating (table)) + g_object_unref (table); } else if (ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, "UpdatePreeditText")) { IBusText *text = NULL; @@ -442,6 +450,9 @@ ibus_panel_service_ibus_message (IBusPanelService *panel, else { reply = ibus_message_new_method_return (message); } + + if (text != NULL && g_object_is_floating (text)) + g_object_unref (text); } else if (ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, "UpdateProperty")) { IBusProperty *property = NULL; @@ -464,6 +475,9 @@ ibus_panel_service_ibus_message (IBusPanelService *panel, else { reply = ibus_message_new_method_return (message); } + + if (property != NULL && g_object_is_floating (property)) + g_object_unref (property); } else if (ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, "SetCursorLocation")) { guint x, y, w, h; diff --git a/src/ibusproperty.c b/src/ibusproperty.c index 491fd7a..8827a22 100644 --- a/src/ibusproperty.c +++ b/src/ibusproperty.c @@ -181,6 +181,7 @@ ibus_property_deserialize (IBusProperty *prop, ibus_message_iter_next (iter); retval = ibus_message_iter_get (iter, IBUS_TYPE_TEXT, &prop->label); + g_object_ref_sink (prop->label); g_return_val_if_fail (retval, FALSE); ibus_message_iter_next (iter); @@ -190,6 +191,7 @@ ibus_property_deserialize (IBusProperty *prop, prop->icon = g_strdup (p); retval = ibus_message_iter_get (iter, IBUS_TYPE_TEXT, &prop->tooltip); + g_object_ref_sink (prop->tooltip); g_return_val_if_fail (retval, FALSE); ibus_message_iter_next (iter); @@ -206,6 +208,7 @@ ibus_property_deserialize (IBusProperty *prop, ibus_message_iter_next (iter); retval = ibus_message_iter_get (iter, IBUS_TYPE_PROP_LIST, &prop->sub_props); + g_object_ref_sink (prop->sub_props); g_return_val_if_fail (retval, FALSE); ibus_message_iter_next (iter); @@ -296,7 +299,7 @@ ibus_property_set_label (IBusProperty *prop, prop->label = ibus_text_new_from_static_string (""); } else { - prop->label = g_object_ref (label); + prop->label = g_object_ref_sink (label); } } @@ -323,9 +326,11 @@ ibus_property_set_tooltip (IBusProperty *prop, if (tooltip == NULL) { prop->tooltip = ibus_text_new_from_static_string (""); + g_object_ref_sink (prop->tooltip); } else { - prop->tooltip = g_object_ref (tooltip); + prop->tooltip = tooltip; + g_object_ref_sink (prop->tooltip); } } @@ -369,11 +374,13 @@ ibus_property_set_sub_props (IBusProperty *prop, } if (prop_list) { - g_object_ref (prop_list); prop->sub_props = prop_list; + g_object_ref_sink (prop_list); } - else + else { prop->sub_props = ibus_prop_list_new (); + g_object_ref_sink (prop->sub_props); + } } gboolean @@ -393,12 +400,12 @@ ibus_property_update (IBusProperty *prop, if (prop->label) { g_object_unref (prop->label); } - prop->label = (IBusText *) g_object_ref (prop_update->label); + prop->label = (IBusText *) g_object_ref_sink (prop_update->label); if (prop->tooltip) { g_object_unref (prop->tooltip); } - prop->tooltip = (IBusText *) g_object_ref (prop_update->tooltip); + prop->tooltip = (IBusText *) g_object_ref_sink (prop_update->tooltip); prop->visible = prop_update->visible; prop->state = prop_update->state; prop->sensitive = prop_update->sensitive; diff --git a/src/ibusproplist.c b/src/ibusproplist.c index fc96c8b..b3a2dc0 100644 --- a/src/ibusproplist.c +++ b/src/ibusproplist.c @@ -134,7 +134,7 @@ ibus_prop_list_deserialize (IBusPropList *prop_list, { gboolean retval; IBusMessageIter array_iter; - IBusSerializable *object; + IBusProperty *prop; retval = parent_class->deserialize ((IBusSerializable *) prop_list, iter); g_return_val_if_fail (retval, FALSE); @@ -145,12 +145,11 @@ ibus_prop_list_deserialize (IBusPropList *prop_list, g_return_val_if_fail (retval, FALSE); while (ibus_message_iter_get_arg_type (&array_iter) != G_TYPE_INVALID) { - retval = ibus_message_iter_get (&array_iter, IBUS_TYPE_PROPERTY, &object); + retval = ibus_message_iter_get (&array_iter, IBUS_TYPE_PROPERTY, &prop); g_return_val_if_fail (retval, FALSE); ibus_message_iter_next (&array_iter); - ibus_prop_list_append (prop_list, (IBusProperty *)object); - g_object_unref (object); + ibus_prop_list_append (prop_list, prop); } ibus_message_iter_next (iter); @@ -179,7 +178,6 @@ ibus_prop_list_copy (IBusPropList *dest, while ((prop = ibus_prop_list_get ((IBusPropList *)src, i)) != NULL) { prop = (IBusProperty *) ibus_serializable_copy ((IBusSerializable *) prop); ibus_prop_list_append (dest, prop); - g_object_unref (prop); i ++; } return TRUE; @@ -203,7 +201,7 @@ ibus_prop_list_append (IBusPropList *prop_list, g_assert (IBUS_IS_PROP_LIST (prop_list)); g_assert (IBUS_IS_PROPERTY (prop)); - g_object_ref (prop); + g_object_ref_sink (prop); g_array_append_val (prop_list->properties, prop); } diff --git a/src/ibusproxy.c b/src/ibusproxy.c index b605cb9..2798738 100644 --- a/src/ibusproxy.c +++ b/src/ibusproxy.c @@ -455,7 +455,7 @@ ibus_proxy_set_property (IBusProxy *proxy, case PROP_CONNECTION: g_assert (priv->connection == NULL); priv->connection = IBUS_CONNECTION (g_value_get_object (value)); - g_object_ref (priv->connection); + g_object_ref_sink (priv->connection); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (proxy, prop_id, pspec); diff --git a/src/ibusserver.c b/src/ibusserver.c index 06f73cc..079da8f 100644 --- a/src/ibusserver.c +++ b/src/ibusserver.c @@ -252,7 +252,11 @@ _new_connection_cb (DBusServer *dbus_server, ibus_connection_set_connection (connection, new_connection, FALSE); g_signal_emit (server, server_signals[NEW_CONNECTION], 0, connection); - g_object_unref (connection); + + if (g_object_is_floating (connection)) { + /* release connection if it is still floating */ + g_object_unref (connection); + } } static gboolean diff --git a/src/ibusservice.c b/src/ibusservice.c index 0a96ca8..c194c07 100644 --- a/src/ibusservice.c +++ b/src/ibusservice.c @@ -315,7 +315,7 @@ ibus_service_add_to_connection (IBusService *service, IBusConnection *connection g_return_val_if_fail (priv->path != NULL, FALSE); g_return_val_if_fail (g_list_find (priv->connections, connection) == NULL, FALSE); - g_object_ref (connection); + g_object_ref_sink (connection); retval = ibus_connection_register_object_path (connection, priv->path, (IBusMessageFunc) _service_message_function, service); @@ -341,11 +341,7 @@ ibus_service_get_connections (IBusService *service) IBusServicePrivate *priv; priv = IBUS_SERVICE_GET_PRIVATE (service); - GList *l; - - l = g_list_copy (priv->connections); - g_list_foreach (l, (GFunc) g_object_ref, NULL); - return l; + return g_list_copy (priv->connections); } gboolean diff --git a/src/ibustext.c b/src/ibustext.c index 74d1f6c..b13b17b 100644 --- a/src/ibustext.c +++ b/src/ibustext.c @@ -113,8 +113,10 @@ ibus_text_serialize (IBusText *text, retval = ibus_message_iter_append (iter, G_TYPE_STRING, &text->text); g_return_val_if_fail (retval, FALSE); - if (text->attrs == NULL) + if (text->attrs == NULL) { text->attrs = ibus_attr_list_new (); + g_object_ref_sink (text->attrs); + } retval = ibus_message_iter_append (iter, IBUS_TYPE_ATTR_LIST, &text->attrs); g_return_val_if_fail (retval, FALSE); @@ -145,6 +147,7 @@ ibus_text_deserialize (IBusText *text, } retval = ibus_message_iter_get (iter, IBUS_TYPE_ATTR_LIST, &text->attrs); + g_object_ref_sink (text->attrs); g_return_val_if_fail (retval, FALSE); ibus_message_iter_next (iter); @@ -166,8 +169,10 @@ ibus_text_copy (IBusText *dest, dest->text = g_strdup (src->text); dest->is_static = FALSE; - if (src->attrs) + if (src->attrs) { dest->attrs = (IBusAttrList *)ibus_serializable_copy ((IBusSerializable *)src->attrs); + g_object_ref_sink (dest->attrs); + } return TRUE; } @@ -293,7 +298,6 @@ ibus_text_append_attribute (IBusText *text, attr = ibus_attribute_new (type, value, start_index, end_index); ibus_attr_list_append (text->attrs, attr); - g_object_unref (attr); } guint diff --git a/src/test-keymap.c b/src/test-keymap.c index e4168e6..63b2147 100644 --- a/src/test-keymap.c +++ b/src/test-keymap.c @@ -23,7 +23,7 @@ int main (int argc, char **argv) g_type_init (); - IBusKeymap *keymap = ibus_keymap_new (argc > 1 ? argv[1] : "us"); + IBusKeymap *keymap = ibus_keymap_get (argc > 1 ? argv[1] : "us"); g_object_unref (keymap); return 0; -- 2.7.4