Re: Writable array returned from gtk_tree_path_get_indices()

2010-10-07 Thread Federico Mena Quintero
On Thu, 2010-10-07 at 09:18 -0500, Stef Walter wrote:
 Is the integer array returned from gtk_tree_path_get_indices() writable
 by design? Or should it be treated as readonly?

It depends.

Sometimes you get a GtkTreePath from the treeview API when you ask for
something (e.g. gtk_icon_view_get_path_at_pos()).  Since that is a
newly-generated path that you own, you can do anything you want with it.
People may use it as a counter and increment the index to iterate over
the model, or whatever.

Sometimes you get the GtkTreePath as an argument to a callback (e.g.
GtkTreeModelForeachFunc).  Generally you shouldn't modify the path in
that case.

  Federico

___
gtk-devel-list mailing list
gtk-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-devel-list


Re: Writable array returned from gtk_tree_path_get_indices()

2010-10-07 Thread Tadej Borovšak
Hi.

2010/10/7 Stef Walter stef-l...@memberwebs.com:
 Is the integer array returned from gtk_tree_path_get_indices() writable
 by design? Or should it be treated as readonly?

You should definitely not modify values in returned array, since this
central part of GtkTreePath. Currently, modifying parts of this array
is the same as moving your path using gtk_tree_path_(next|prev)(), but
if internal structure of GtkTreePath changes, you'll be in trouble.

 Some stuff like GtkTreeModelSort and GtkTreeModelFilter write to this
 index array, but those may be liberties taken by gtk+ internally.

Quickly looking at the code I would say that this is indeed the case
here. Directly modifying values avoids some type checking, which
speeds up some of the operations.

 Perhaps we would change the return values for the following to 'const
 gint*':

 gtk_tree_path_get_indices ()
 gtk_tree_path_get_indices_with_depth ()

 If not by design, I'll file a bug, and patch.

I think that minimal thing to do here is to update docs to something
like this: Returns the current indices of path. This is an array of
integers, each representing a node in a tree. This value should not be
freed and members of array should not be modified. Filling a bug is
definitely the way to go IMHO.

Cheers,

Tadej

-- 
Tadej Borovšak
tadeboro.blogspot.com
tadeb...@gmail.com
tadej.borov...@gmail.com
___
gtk-devel-list mailing list
gtk-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-devel-list


Re: Writable array returned from gtk_tree_path_get_indices()

2010-10-07 Thread Stef Walter
On 2010-10-07 16:29, Tadej Borovšak wrote:
 You should definitely not modify values in returned array, since this
 central part of GtkTreePath. Currently, modifying parts of this array
 is the same as moving your path using gtk_tree_path_(next|prev)(), but
 if internal structure of GtkTreePath changes, you'll be in trouble.

That's true, unless GtkTreePath is essentially a gint array, and exposed
as such. This concept would be part of the ABI, and the internal
structure could never be changed.

I guess that was the essence of my question. Is that the case?

 I think that minimal thing to do here is to update docs to something
 like this: Returns the current indices of path. This is an array of
 integers, each representing a node in a tree. This value should not be
 freed and members of array should not be modified. 

The best way of documenting 'don't modify' is to const the return value.
I've done both in my patch.

Filling a bug is
 definitely the way to go IMHO.

Here it is: https://bugzilla.gnome.org/show_bug.cgi?id=631659

Cheers,

Stef
___
gtk-devel-list mailing list
gtk-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-devel-list