[gtkada] Heap corruption and other problems
Dmitry A. Kazakov
mailbox at dmitry-kazakov.de
Mon Aug 12 10:36:10 CEST 2013
On Mon, 12 Aug 2013 09:37:45 +0200, you wrote:
>> 1. It seems that Gtk3 up to version 3.8 (Glib 2.36) has serious problem
>> which corrupts Ada's memory pool sooner or later. The bug is sporadic and I
>> cannot track it down, especially without building Glib from sources, which
>> is a problem itself.
>
> I don't think we have seen that one ourselves. What is the symptom, a Storage_Error
> or something that could help recognize it better ?
Sometimes Storage_Error, even when GNAT debug pool is used and has 0 bytes
allocated in it. Sometimes application crashes silently (access violation).
I cannot track it down.
I discovered the problem first with text buffer. GtkAda implementation of
Insert is this:
procedure Insert
(Buffer : not null access Gtk_Text_Buffer_Record;
Iter : in out Gtk.Text_Iter.Gtk_Text_Iter;
Text : UTF8_String)
is
procedure Internal
(Buffer : System.Address;
Iter : in out Gtk.Text_Iter.Gtk_Text_Iter;
Text : Interfaces.C.Strings.chars_ptr;
Len : Gint);
pragma Import (C, Internal, "gtk_text_buffer_insert");
Tmp_Iter : aliased Gtk.Text_Iter.Gtk_Text_Iter := Iter;
Tmp_Text : Interfaces.C.Strings.chars_ptr := New_String (Text);
begin
Internal (Get_Object (Buffer), Tmp_Iter, Tmp_Text, -1);
Free (Tmp_Text);
Iter := Tmp_Iter;
end Insert;
It allocates and frees each time when called and that causes the problem
relatively soon. When I replaced it with:
procedure Insert
(Buffer : not null access Gtk_Text_Buffer_Record'Class;
Iter : in out Gtk.Text_Iter.Gtk_Text_Iter;
Text : UTF8_String)
is
procedure Internal
(Buffer : System.Address;
Iter : in out Gtk.Text_Iter.Gtk_Text_Iter;
Text : Interfaces.C.char_array;
Len : Gint);
pragma Import (C, Internal, "gtk_text_buffer_insert");
begin
Internal (Get_Object (Buffer), Iter, Interfaces.C.To_C (Text),
Text'Length);
end Insert;
The issue was gone. Now it keep on crashing but elsewhere, usually in some
random Gtk_New.
> Are you able to run your application in valgrind, maybe there is a bug that can be found
> much earlier than waiting for the memory corruption...
I didn't test it under Linux yet. Maybe it is a Win32 problem.
>> 2. Another serious problem is in GDK which shows itself as:
>>
>> Gdk-CRITICAL **: gdk_device_get_source: assertion `GDK_IS_DEVICE
>> (device)' failed
>>
>> on many occasions. E.g. in combo boxes after resizing them.
>
> We have seen that one at some point, but it is gone in the development
> versions now.
Create a window with combo box in it:
with Gtk.Box; use Gtk.Box;
with Gtk.Main;
with Gtk.Window; use Gtk.Window;
with Gtk.Combo_Box_Text; use Gtk.Combo_Box_Text;
procedure Simple is
Window : Gtk_Window;
Combo : Gtk_Combo_Box_Text;
Box : Gtk_VBox;
begin
Gtk.Main.Init;
Gtk_New (Window);
Gtk_New_VBox (Box);
Window.Add (Box);
Window.Set_Title ("Test");
Gtk_New (Combo);
Box.Pack_Start (Combo, False, False);
Combo.Append_Text ("A");
Combo.Append_Text ("B");
Combo.Append_Text ("C");
Window.Show_All;
Gtk.Main.Main;
end Simple;
Start program. Resize window so that combo box resizes. Select something in
the box. Done.
> I think it is part of our own patches to gtk+, did you apply these ?
> They are in the contrib/ directory (of course, that's in case you recompile your
> own gtk+, I don't remember what system you are working on).
I don't know how to do it under MinGW. The Gtk I am using I took from
mingw32 Fedora packages (Gtk 3.8.2). I simply copied /bin /lib etc and
changed Path environment variable. That resolved some issues, e.g.
GtkColorButton crash.
>> So far Gtk3 looks barely usable for any serious application. Sorry for all
>> efforts AdaCore spent on GtkAda.
>
> We do use it very successfully for the upcoming version of GPS in fact. The
> transition is indeed somewhat painful, but then things seem to work as expected
> for us. Of course, we may have made progress or fixes since the last GPL release.
I hope you are right. The problem is difficult is reproduce. In my
application I need a lot of clicking (creating and removing widgets) for
the problem to show. Which suggests a race condition somewhere.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
More information about the gtkada
mailing list