From: Geoff Y. <g...@in...> - 2004-12-11 13:33:05
|
Hi, On Sat, 2004-12-11 at 22:50 +1300, leon breedt wrote: > basically, i use the Ruby/GTK2 just to get to the Glib main loop > (because my DBus/Ruby binding uses the D-BUS library, and the D-BUS > library integrates with the Glib main loop under the covers). > the only part of it that i use is: > Gtk.main > with 0.11.0, i get a segfault with a backtrace as follows: [snip] > the segfault always occurs at the same place. [snip] > oh, and running my code with GC.disable, stops the problem from happening. I presume you're talking about the ruby-dbus project on rubyforge.org? I can't actually replicate the crash you describe... but I think the problem may be as follows: dbus-ruby is using rb_gc_register_address() on function arguments. rb_gc_(un)register_address references the address which contains a pointer *to* the VALUE pointer (ie. not the VALUE pointer), so it may only be used on global pointers. The addresses in which function arguments are stored (potentially) change with every function call. I'd suggest one of the following approaches: 1/ You could simulate the behaviour you're expecting with something like: in ruby-dbus.h ----8<----- #define rb_gc_register_address(ptr) _rbdb_remember_value(*(ptr)) #define rb_gc_unregister_address(ptr) _rbdb_forget_value(*(ptr)) void _rbdb_remember_value(VALUE ptr); void _rbdb_forget_value(VALUE ptr); ----8<----- in ruby-dbus-common.c: ----8<----- static VALUE callbacks = Qnil; #undef rb_gc_register_address #undef rb_gc_unregister_address void _rbdb_remember_value(VALUE ptr) { if (callbacks == Qnil) { rb_gc_register_address(&callbacks); callbacks = rb_ary_new(); } rb_ary_push(callbacks, ptr); } void _rbdb_forget_value(VALUE ptr) { Check_Type(callbacks, T_ARRAY); rb_ary_delete(callbacks, ptr); /* If paranoid about memory usage... */ if (RARRAY(callbacks)->len == 0) { callbacks = Qnil; rb_gc_unregister_address(&callbacks); } } ----8<----- 2/ or, you could store the callbacks relative to the connection and use a mark function. HTH, -- Geoff Youngs <g...@in...> |