Re: GtkTreeIter comparison



Daniel Elstner <daniel elstner gmx net> writes:

> Hi,
> 
> in order to wrap GtkTreeIter as C++ STL-like iterator in gtkmm, we have
> to be able to compare Gtk::TreeIters for equality.  Unfortunately, GTK+
> doesn't provide an API to do this.
> 
> Currently, we solved the problem by comparing the
> user_data/user_data2/user_data3 pointers in struct GtkTreeIter.  This is
> obviously a hack and means relying on GTK+ internals.  Unfortunately, it
> breaks because GtkListStore and GtkTreeStore don't zero-initialize the
> unused user_data[23] pointers.
> 
> We definitely need a solution to this problem.
> I see two possible ways to go:
> 
> 1) Adding a GtkTreeModel::iter_equal vfunc.  One for GTK+-2.2.
> 
> 2) Declare in the API docs, that when implementing a custom
> GtkTreeModel, the GtkTreeIter must be comparable by testing the pointers
> for equality.  Also, define a policy that unused GtkTreeIter fields
> always have to be zero-initialized, and fix GTK+ to do so.  (I would
> provide a patch.)
> 
> I'd prefer 1), either in combination with 2) for GTK+-2.0, or with the
> promise that GtkTreeStore and GtkListStore will never use user_data2 and
> user_data3.
> 
> Comments?

[ I replied to this in #81380 ]

I'm trying to keep the number of vfuncs down to an absolute minimum
right now, and I break ABI compat by adding one.  As a result, option 2
seems to make the most sense, and I think it's a fine way to test
equality on its own (it's all the vfunc would do, for the most part.)
Of course the 'real' way to test for it is to convert the two iters to
paths and compare those, but this is excessive.

A patch that zero'ed out the unused fields in get_iter would be great.

Thanks,
-Jonathan



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