[gtkada] Severe bug with Gtk_Tree_Iter

Dmitry A. Kazakov mailbox at dmitry-kazakov.de
Mon Oct 20 09:38:02 CEST 2014


This is not much GtkAda's as a GTK problem.

The issue is that when GTK updates a GtkTreeIter struct, e.g. upon
insertion of a row into a GtkTreeStore, the implementation overwrites only
the fields of the struct that the corresponding model actually uses. The
leftover is garbage.

E.g. in the case of GtkTreeStore Insert, it will update the first two
(Stamp and User_Data) and ignore User_Data1 and User_Data2.

Now, the GtkAda's binding to Insert looks like:

   procedure Insert
      (Tree_Store : not null access Gtk_Tree_Store_Record;
       Iter       : out Gtk.Tree_Model.Gtk_Tree_Iter;
       Parent     : Gtk.Tree_Model.Gtk_Tree_Iter;
       Position   : Gint)
   is
      procedure Internal
         (Tree_Store : System.Address;
          Iter       : out Gtk.Tree_Model.Gtk_Tree_Iter;
          Parent     : System.Address;
          Position   : Gint);
      pragma Import (C, Internal, "gtk_tree_store_insert");
      Tmp_Iter : aliased Gtk.Tree_Model.Gtk_Tree_Iter;
   begin
      Internal (Get_Object (Tree_Store), Tmp_Iter, Iter_Or_Null
(Parent'Address), Position);
      Iter := Tmp_Iter;
   end Insert;

Note that Tmp_Iter is not initialized, thus the returned result has garbage
User_Data1 and User_Data2.

The effect of this mess is that Gtk_Tree_Iter is basically not comparable
for equality although declared private.

It is surely possible to compare paths instead of iterators. But this would
impose a significant overhead because paths are dynamically allocated
objects. Furthermore it requires the model object to get path from
iterator.

We cannot expect this fixed in GTK. I found that the problem had been
reported back in 2002, more than 10 years ago.

My proposal is to initialize all intermediate Gtk_Tree_Iter objects with
Null_Iter throughout GtkAda. It is a lot of places, but I guess it should
be possible to adjust the API generation script to make this automatically.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


More information about the gtkada mailing list