Re: warning about invalid tree model iterators



Tim Janik wrote:

hi all.

tree model iterators are easily advanced/setup/created in a way that yields an invalid iterator, because the denoted location doesn't exist (anymore). to cath those cases, the tree model API returns booleans indicating success,
but testing those booleans is easily forgotton and a common error source.

to help the compiler catch these mistakes, i've prepared a patch that adds
G_GNUC_WARN_UNUSED_RESULT to all relevant iterator functions, and intend
to commit that next week unless objections pop up. in principle it does:
...

@@ -191,14 +191,14 @@ GType             gtk_tree_model_get_col
/* Iterator movement */
gboolean          gtk_tree_model_get_iter        (GtkTreeModel *tree_model,
						  GtkTreeIter  *iter,
-						  GtkTreePath  *path);
+						  GtkTreePath  *path) G_GNUC_WARN_UNUSED_RESULT;
Here's code I have here:

GtkTreeRowReference *row = i_store_it_somewhere ();
if (gtk_tree_row_reference_valid (row))
{
      GtkTreePath *path = gtk_tree_row_reference_get_path (row);
      gtk_tree_model_get_iter (model, &iter, path);
      ...
}

Or I do

path = gtk_tree_row_reference_get_path (row);
if (path)
{
      /* it is valid */
      gtk_tree_model_get_iter (model, &iter, path);
      ...
}

In either case I have a valid path, and there's no need to heck return
value of gtk_tree_model_get_iter. This code is real code from my
application, I guess one could make up examples where warnings are
not needed for other cases too.

Best regards,
Yevgen




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]