Re: how to test whether a Gtk::TreePath is null



I've checked the gtk+ source and it seems that at least Gtk+ API
always returns a valid GtkTreePath instance, but indices can be NULL.

That means for gtkmm it would be path.get_indices().data() == NULL. I
don't know what only path.get_indices() would return then, does
Glib::ArrayHandle<> handle a NULL?

But in any case such a TreePath is 'empty', but at the same time also
invalid (it can not be used to e.g. acquire a TreeIter). I guess an
invalid path would be if the entire thing is NULL (that is NULL was
returned instead of a TreePath), and an empty path would be one where
the indices are NULL.

Initialization of TreePath from Gtk+ code:

GtkTreePath *
gtk_tree_path_new (void)
{
  GtkTreePath *retval;
  retval = g_new (GtkTreePath, 1);
  retval->depth = 0;
  retval->indices = NULL;
  return retval;
}

I'm going to look now for the case in our code where i needed
::gobj(), maybe it was something that came from our code, it seems
Gtk+ never returns a plain nullptr for a treepath.

On 9/1/07, Murray Cumming <murrayc murrayc com> wrote:
>
> On Fri, 2007-08-31 at 19:28 +0200, Milosz Derezynski wrote:
> > Yeah i had discussed this in the IRC channel already once i think; in
> > our code we also need  to use gobj() to check if it's really NULL.
> >
> > As sidenote one should of course use the return value of path_at_pos()
> > but there are other cases where it's not always guaranteed that a path
> > is actually valid (i don't remember the case i needed it for now but
> > it seemed neccessary)
>
> Could you please check your code and tell us where this was necessary.
> I'd like to avoid adding unnecessary API and avoid creating the idea
> that the TreePath should be checked for validity excessively.
>
> I also don't like the idea of having both the empty-path idea and the
> invalid-path idea. I'd rather avoid crashes by making sure that we
> return an empty TreePath wherever we currently return a TreePath with a
> null gobj(). Hopefully an empty TreePath has no meaning such as "root
> item".
>
>
> --
> murrayc murrayc com
> www.murrayc.com
> www.openismus.com
>
>



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