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.
This commit is contained in:
Matthias Clasen 2020-07-26 16:25:12 -04:00
parent 706d464ae6
commit a46cfd3ff4
15 changed files with 24 additions and 37 deletions

View File

@ -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 (&current_filter, filter);

View File

@ -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);
* ]|

View File

@ -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);

View File

@ -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;
}

View File

@ -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);

View File

@ -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

View File

@ -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;
}

View File

@ -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));

View File

@ -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))));

View File

@ -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;
}

View File

@ -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;

View File

@ -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);

View File

@ -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)
{

View File

@ -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);

View File

@ -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 *