From a46cfd3ff4120c377900374ed660e7299e380914 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 26 Jul 2020 16:25:12 -0400 Subject: [PATCH] sortlistmodel: Make constructor transfer full This is for consistency with other wrapping list constructors. We want them all to be transfer full, allow-none. Update all callers. --- demos/gtk-demo/listview_settings.c | 3 +-- gtk/gtkcolumnview.c | 4 ++-- gtk/gtkprintunixdialog.c | 2 -- gtk/gtksortlistmodel.c | 8 ++++++-- gtk/inspector/actions.c | 12 ++++++------ gtk/inspector/controllers.c | 2 -- gtk/inspector/prop-list.c | 1 - gtk/inspector/resource-list.c | 3 +-- tests/testcolumnview.c | 1 - tests/testlistview-animating.c | 3 --- tests/testlistview.c | 7 +------ testsuite/gtk/sorter.c | 6 ++++-- testsuite/gtk/sortlistmodel-exhaustive.c | 4 ++-- testsuite/gtk/sortlistmodel.c | 3 +-- testsuite/gtk/treesorter.c | 2 -- 15 files changed, 24 insertions(+), 37 deletions(-) diff --git a/demos/gtk-demo/listview_settings.c b/demos/gtk-demo/listview_settings.c index 9df0218f7c..981a068010 100644 --- a/demos/gtk-demo/listview_settings.c +++ b/demos/gtk-demo/listview_settings.c @@ -242,8 +242,7 @@ transform_settings_to_keys (GBinding *binding, g_object_unref (settings); sort_model = gtk_sort_list_model_new (G_LIST_MODEL (store), - gtk_column_view_get_sorter (GTK_COLUMN_VIEW (data))); - g_object_unref (store); + g_object_ref (gtk_column_view_get_sorter (GTK_COLUMN_VIEW (data)))); filter = gtk_string_filter_new (gtk_property_expression_new (SETTINGS_TYPE_KEY, NULL, "name")); g_set_object (¤t_filter, filter); diff --git a/gtk/gtkcolumnview.c b/gtk/gtkcolumnview.c index 6ad2580c25..691c18e6ed 100644 --- a/gtk/gtkcolumnview.c +++ b/gtk/gtkcolumnview.c @@ -1500,8 +1500,8 @@ gtk_column_view_get_list_view (GtkColumnView *self) * |[ * gtk_column_view_column_set_sorter (column, sorter); * gtk_column_view_append_column (view, column); - * model = gtk_sort_list_model_new (store, - * gtk_column_view_get_sorter (view)); + * sorter = g_object_ref (gtk_column_view_get_sorter (view))); + * model = gtk_sort_list_model_new (store, sorter); * selection = gtk_no_selection_new (model); * gtk_column_view_set_model (view, selection); * ]| diff --git a/gtk/gtkprintunixdialog.c b/gtk/gtkprintunixdialog.c index 09e7c1ea8b..2305d3d4ed 100644 --- a/gtk/gtkprintunixdialog.c +++ b/gtk/gtkprintunixdialog.c @@ -813,7 +813,6 @@ gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog) model = load_print_backends (dialog); sorter = gtk_custom_sorter_new (default_printer_list_sort_func, NULL, NULL); sorted = G_LIST_MODEL (gtk_sort_list_model_new (model, sorter)); - g_object_unref (sorter); filter = gtk_every_filter_new (); @@ -839,7 +838,6 @@ gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog) g_signal_connect_swapped (selection, "notify::selected", G_CALLBACK (selected_printer_changed), dialog); g_object_unref (selection); g_object_unref (filtered); - g_object_unref (model); gtk_print_load_custom_papers (dialog->custom_paper_list); diff --git a/gtk/gtksortlistmodel.c b/gtk/gtksortlistmodel.c index 64bd038bcc..24c2b5271d 100644 --- a/gtk/gtksortlistmodel.c +++ b/gtk/gtksortlistmodel.c @@ -828,8 +828,8 @@ gtk_sort_list_model_init (GtkSortListModel *self) /** * gtk_sort_list_model_new: - * @model: (allow-none): the model to sort - * @sorter: (allow-none): the #GtkSorter to sort @model with + * @model: (allow-none) (transfer full): the model to sort, or %NULL + * @sorter: (allow-none) (transfer full): the #GtkSorter to sort @model with, or %NULL * * Creates a new sort list model that uses the @sorter to sort @model. * @@ -849,6 +849,10 @@ gtk_sort_list_model_new (GListModel *model, "sorter", sorter, NULL); + /* consume the references */ + g_clear_object (&model); + g_clear_object (&sorter); + return result; } diff --git a/gtk/inspector/actions.c b/gtk/inspector/actions.c index 4965bb6349..9f68ded33e 100644 --- a/gtk/inspector/actions.c +++ b/gtk/inspector/actions.c @@ -46,7 +46,7 @@ struct _GtkInspectorActions GObject *object; - GListModel *actions; + GListStore *actions; GtkColumnViewColumn *name; }; @@ -79,7 +79,7 @@ action_added (GObject *owner, GtkInspectorActions *sl) { ActionHolder *holder = action_holder_new (owner, action_name); - g_list_store_append (G_LIST_STORE (sl->actions), holder); + g_list_store_append (sl->actions, holder); g_object_unref (holder); } @@ -283,7 +283,7 @@ add_muxer (GtkInspectorActions *sl, static gboolean reload (GtkInspectorActions *sl) { - g_list_store_remove_all (G_LIST_STORE (sl->actions)); + g_list_store_remove_all (sl->actions); if (GTK_IS_APPLICATION (sl->object)) { @@ -395,9 +395,9 @@ constructed (GObject *object) gtk_column_view_column_set_sorter (sl->name, sorter); g_object_unref (sorter); - sl->actions = G_LIST_MODEL (g_list_store_new (ACTION_TYPE_HOLDER)); - sorted = G_LIST_MODEL (gtk_sort_list_model_new (sl->actions, - gtk_column_view_get_sorter (GTK_COLUMN_VIEW (sl->list)))); + sl->actions = g_list_store_new (ACTION_TYPE_HOLDER); + sorted = G_LIST_MODEL (gtk_sort_list_model_new (g_object_ref (G_LIST_MODEL (sl->actions)), + g_object_ref (gtk_column_view_get_sorter (GTK_COLUMN_VIEW (sl->list))))); model = G_LIST_MODEL (gtk_no_selection_new (sorted)); gtk_column_view_set_model (GTK_COLUMN_VIEW (sl->list), model); g_object_unref (sorted); diff --git a/gtk/inspector/controllers.c b/gtk/inspector/controllers.c index 9d1ef7ffaf..bb658a2c74 100644 --- a/gtk/inspector/controllers.c +++ b/gtk/inspector/controllers.c @@ -249,7 +249,6 @@ gtk_inspector_controllers_set_object (GtkInspectorControllers *self, sorter = gtk_custom_sorter_new (compare_controllers, NULL, NULL); sort_model = gtk_sort_list_model_new (G_LIST_MODEL (flatten_model), sorter); - g_object_unref (sorter); gtk_list_box_bind_model (GTK_LIST_BOX (self->listbox), G_LIST_MODEL (sort_model), @@ -258,7 +257,6 @@ gtk_inspector_controllers_set_object (GtkInspectorControllers *self, NULL); g_object_unref (sort_model); - g_object_unref (flatten_model); } static void diff --git a/gtk/inspector/prop-list.c b/gtk/inspector/prop-list.c index a5b12d9a52..e7d2aeb21b 100644 --- a/gtk/inspector/prop-list.c +++ b/gtk/inspector/prop-list.c @@ -634,7 +634,6 @@ gtk_inspector_prop_list_set_object (GtkInspectorPropList *pl, g_object_unref (list); g_object_unref (sorted); - g_object_unref (filtered); return TRUE; } diff --git a/gtk/inspector/resource-list.c b/gtk/inspector/resource-list.c index 57be9a049f..1cb3770bd4 100644 --- a/gtk/inspector/resource-list.c +++ b/gtk/inspector/resource-list.c @@ -712,11 +712,10 @@ constructed (GObject *object) column_sorter = gtk_column_view_get_sorter (GTK_COLUMN_VIEW (rl->list)); sorter = gtk_tree_list_row_sorter_new (g_object_ref (column_sorter)); - sort_model = G_LIST_MODEL (gtk_sort_list_model_new (G_LIST_MODEL (rl->tree_model), sorter)); + sort_model = G_LIST_MODEL (gtk_sort_list_model_new (g_object_ref (G_LIST_MODEL (rl->tree_model)), sorter)); rl->selection = gtk_single_selection_new (sort_model); g_object_unref (root_model); g_object_unref (sort_model); - g_object_unref (sorter); gtk_column_view_set_model (GTK_COLUMN_VIEW (rl->list), G_LIST_MODEL (rl->selection)); diff --git a/tests/testcolumnview.c b/tests/testcolumnview.c index bf9fb83572..a77c93ca0b 100644 --- a/tests/testcolumnview.c +++ b/tests/testcolumnview.c @@ -770,7 +770,6 @@ main (int argc, char *argv[]) gtk_box_append (GTK_BOX (vbox), statusbar); g_object_unref (filter); - g_object_unref (tree); list = gtk_list_view_new_with_factory ( gtk_builder_list_item_factory_new_from_bytes (scope, g_bytes_new_static (factory_ui, strlen (factory_ui)))); diff --git a/tests/testlistview-animating.c b/tests/testlistview-animating.c index d824118d78..7902948ab2 100644 --- a/tests/testlistview-animating.c +++ b/tests/testlistview-animating.c @@ -127,7 +127,6 @@ main (int argc, add (store); sorter = gtk_numeric_sorter_new (gtk_cclosure_expression_new (G_TYPE_UINT, NULL, 0, NULL, (GCallback)get_number, NULL, NULL)); sort = gtk_sort_list_model_new (G_LIST_MODEL (store), sorter); - g_object_unref (sorter); win = gtk_window_new (); gtk_window_set_default_size (GTK_WINDOW (win), 400, 600); @@ -182,7 +181,5 @@ main (int argc, while (g_list_model_get_n_items (toplevels)) g_main_context_iteration (NULL, TRUE); - g_object_unref (store); - return 0; } diff --git a/tests/testlistview.c b/tests/testlistview.c index a8b3cc84aa..6eea54d593 100644 --- a/tests/testlistview.c +++ b/tests/testlistview.c @@ -318,7 +318,6 @@ get_file_path (GFileInfo *info) static GListModel * create_list_model_for_directory (gpointer file) { - GtkSortListModel *sort; GtkDirectoryList *dir; GtkSorter *sorter; @@ -327,12 +326,8 @@ create_list_model_for_directory (gpointer file) dir = create_directory_list (file); sorter = gtk_string_sorter_new (gtk_cclosure_expression_new (G_TYPE_STRING, NULL, 0, NULL, (GCallback) get_file_path, NULL, NULL)); - sort = gtk_sort_list_model_new (G_LIST_MODEL (dir), sorter); - g_object_unref (sorter); - g_object_unref (dir); - - return G_LIST_MODEL (sort); + return G_LIST_MODEL (gtk_sort_list_model_new (G_LIST_MODEL (dir), sorter)); } typedef struct _RowData RowData; diff --git a/testsuite/gtk/sorter.c b/testsuite/gtk/sorter.c index e8e3e56d6e..ddd17d8baf 100644 --- a/testsuite/gtk/sorter.c +++ b/testsuite/gtk/sorter.c @@ -247,6 +247,8 @@ new_model (guint size, { GtkSortListModel *result; + if (sorter) + g_object_ref (sorter); result = gtk_sort_list_model_new (G_LIST_MODEL (fisher_yates_shuffle (new_store (1, size, 1))), sorter); return result; @@ -630,8 +632,8 @@ test_stable (void) gtk_multi_sorter_append (GTK_MULTI_SORTER (multi), b); model1 = new_model (20, multi); g_object_unref (multi); - model2b = gtk_sort_list_model_new (gtk_sort_list_model_get_model (model1), b); - model2 = gtk_sort_list_model_new (G_LIST_MODEL (model2b), a); + model2b = gtk_sort_list_model_new (g_object_ref (gtk_sort_list_model_get_model (model1)), g_object_ref (b)); + model2 = gtk_sort_list_model_new (g_object_ref (G_LIST_MODEL (model2b)), g_object_ref (a)); assert_model_equal (model1, model2); modify_sorter (a); diff --git a/testsuite/gtk/sortlistmodel-exhaustive.c b/testsuite/gtk/sortlistmodel-exhaustive.c index 049df6b295..9b4fd7f20f 100644 --- a/testsuite/gtk/sortlistmodel-exhaustive.c +++ b/testsuite/gtk/sortlistmodel-exhaustive.c @@ -200,9 +200,9 @@ create_sort_list_model (gconstpointer model_id, guint id = GPOINTER_TO_UINT (model_id); if (track_changes) - model = sort_list_model_new (id & 1 ? NULL : source, id & 2 ? NULL : sorter); + model = sort_list_model_new (((id & 1) || !source) ? NULL : g_object_ref (source), ((id & 2) || !sorter) ? NULL : g_object_ref (sorter)); else - model = gtk_sort_list_model_new (id & 1 ? NULL : source, id & 2 ? NULL : sorter); + model = gtk_sort_list_model_new (((id & 1) || !source) ? NULL : g_object_ref (source), ((id & 2) || !sorter) ? NULL : g_object_ref (sorter)); switch (id >> 2) { diff --git a/testsuite/gtk/sortlistmodel.c b/testsuite/gtk/sortlistmodel.c index 8f323a5fb8..4a84b36a88 100644 --- a/testsuite/gtk/sortlistmodel.c +++ b/testsuite/gtk/sortlistmodel.c @@ -220,8 +220,7 @@ new_model (gpointer model) GtkSorter *sorter; sorter = gtk_custom_sorter_new (compare, NULL, NULL); - result = gtk_sort_list_model_new (model, sorter); - g_object_unref (sorter); + result = gtk_sort_list_model_new (g_object_ref (model), sorter); } else result = gtk_sort_list_model_new (NULL, NULL); diff --git a/testsuite/gtk/treesorter.c b/testsuite/gtk/treesorter.c index 59a32b5e25..73bdb4c9ae 100644 --- a/testsuite/gtk/treesorter.c +++ b/testsuite/gtk/treesorter.c @@ -179,9 +179,7 @@ test_simple (void) sort = gtk_sort_list_model_new (model, sorter); assert_model (sort, "1 2 21 3 31 32 321"); - g_object_unref (sorter); g_object_unref (sort); - g_object_unref (model); } static GtkSorter *