Hi,
The following program:
-=-=—=-=—=-=—=-=–
require ‘gtk2’
Gtk::Window.new.show_all.signal_connect(“delete-event”) { |e,w|
w.window.cursor = Gdk::Cursor.new(Gdk::Cursor::WATCH) }
Gtk.main
-=-=—=-=—=-=—=-=–
crashes when trying to close the window, when used with gtk 2.18.0
runtime (or a late 2.17.x), but not with gtk 2.16.1 or 2.14.3 (glib
being 2.22.0). rg2 versions tried were 0.19.0, 0.19.1, and 019.2; we
also tried to recompile rg2 against gtk 2.18.0, all that make no
differences. export GDK_NATIVE_WINDOWS=1 also makes no difference.
Valgrind[1] says the crash is related to something in gdk/X:
==1833== Invalid read of size 4
==1833== at 0x4F091DD: XAddExtension (in /usr/lib/libX11.so.6.2.0)
==1833== by 0x5CDBDC6: _XcursorGetDisplayInfo (in
/usr/lib/libXcursor.so.1.0.2)
==1833== by 0x5CDC48A: XcursorGetDefaultSize (in
/usr/lib/libXcursor.so.1.0.2)
==1833== by 0x5CDEACD: XcursorLibraryLoadCursor (in
/usr/lib/libXcursor.so.1.0.2)
==1833== by 0x5CDEBAA: XcursorShapeLoadCursor (in
/usr/lib/libXcursor.so.1.0.2)
==1833== by 0x5B98111: _gdk_x11_cursor_update_theme
(gdkcursor-x11.c:587)
==1833== by 0x5BBB3DC: gdk_window_x11_set_cursor
(gdkwindow-x11.c:2738)
==1833== by 0x5B846B5: update_cursor (gdkwindow.c:8735)
==1833== by 0x5B8722F: gdk_window_set_cursor (gdkwindow.c:7666)
==1833== by 0x478A84F: g_object_set_property (in
/usr/lib/libgobject-2.0.so.0.2200.0)
==1833== by 0x4750734: ??? (in
/usr/lib/ruby/site_ruby/1.8/i586-linux/glib2.so)
==1833== by 0x4062CF1: call_cfunc (eval.c:5771)
==1833== Address 0x74050453 is not stack’d, malloc’d or (recently)
free’d
(libX11R6 is 1.2.1 and libXcursor is 1.1.9 but downgrading these makes
no difference)
but the equivalent program in C doesn’t crash:
-=-=—=-=—=-=—=-=–
#include <gtk/gtk.h>
static void setcursor( GtkWidget *widget, gpointer data ) {
GdkCursor *cursor = gdk_cursor_new(GDK_WATCH);
GdkWindow *win = widget->window;
gdk_window_set_cursor(win, cursor);
}
int main( int argc, char *argv[] ) {
GtkWidget *window;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_show_all(window);
g_signal_connect (G_OBJECT (window), “delete_event”, G_CALLBACK
(setcursor), NULL);
gtk_main ();
return 0;
}
-=-=—=-=—=-=—=-=–
I also tried to rewrite the setcursor function to use
g_object_set_property, but it makes no difference (it still doesn’t
crash in C):
-=-=—=-=—=-=—=-=–
GValue item = { 0, };
g_value_init (&item, G_TYPE_POINTER);
GdkCursor *cursor = gdk_cursor_new(GDK_WATCH);
GdkWindow *win = widget->window;
g_value_set_pointer(&item, cursor);
g_object_set_property(G_OBJECT(win), “cursor”, &item);
-=-=—=-=—=-=—=-=–
(though I am not sure how to choose the G_TYPE in such a case)
I guess there is something specific with how rg2 “uses” gtk but it’s
difficult to say from that point on… It would be useful to have a
means to automatically generate the exact equivalent of C calls to gtk
from a rg2-based program (I know, this is idealistic).
Anyway, any idea maybe, someone?
[1] valgrind --tool=memcheck --suppressions=/tmp/valgrind-ruby.supp[2]
ruby test.rb
[2]
http://cvs.m17n.org/viewcvs/ruby/valgrind-ruby/valgrind-ruby.supp?revision=1.3&view=markup
(don’t forget to have debugging symbols available for
suppressions to work properly)
–
Guillaume C. - http://zarb.org/~gc/