Re: Glib::Object::Subclass, embedding and multiple interpreters



muppet wrote:


On Mar 31, 2005, at 6:58 AM, Eduardo M KALINOWSKI wrote:

I'm doing something like this:

package KCWin;
eval {
 Glib::Type->list_ancestors(__PACKAGE__);
 # if we're alive here, the package is already registered.
} or Glib::Type->register_object('Gtk2::Window',
                                __PACKAGE__,
                                signals => { activate => {} });

sub new {
 my $class = shift;

 my $self = bless Gtk2::Window->new, $class;


that's your problem. you're registering a new GType, but not using. re-blessing is not at all the same as creating a GType instance -- the reblessed Window is still a Window as far as glib is concerned. you want

sub new {
    return Glib::Object::new (__PACKAGE__);
}

which actually triggers the whole GObject instantiation process for your new subtype. the rest of your new impl would go into INIT_INSTANCE.

Thanks for the explanation, now I've got that working. There was one more thing that was necessary, the registering code must be in fact
eval {
 Glib::Type->list_ancestors(__PACKAGE__);
 # if we're alive here, the package is already registered.
 push(@ISA, qw/Some::Base::Class/);
} or Glib::Type->register_object('Gtk2::Window',
                                __PACKAGE__,
                                ...);

so that inheritance works.

With that, I could make some experiments with multiple interpreters.

My derived class includes only a new signal, and the signal specification has no parameters, so there wasn't the problem of references. I've found out that the code works properly even with more than one interpreter.

The problem arises when one interpreter is destructed. If I have two, destruct one, create another one and then try to load the package, I get a segmentation fault like this:
#0  0x40824873 in g_type_parent () from /usr/lib/libgobject-2.0.so.0
#1  0x410b6eac in gperl_register_object ()
  from /usr/lib/perl5/auto/Glib/Glib.so
#2  0x411a0128 in boot_Gtk2 () from /usr/lib/perl5/auto/Gtk2/Gtk2.so
#3  0x40948909 in Perl_pp_entersub () from /usr/lib/libperl.so.5.8
<lots more line about the Perl interpreter and the applications's GTK main loop>

If I create only one interpreter, destruct it, and then create another, I can load the file properly, and even display a window. But then I get a crash when I press enter in the Window's entry box (which would emit the activate signal for the derived class). This is the stack dump seems pretty much more complicated:
#0  0x40954f89 in Perl_vnewSVpvf () from /usr/lib/libperl.so.5.8
#1  0x40954f10 in Perl_newSVpvf_nocontext () from /usr/lib/libperl.so.5.8
#2  0x410ac7dc in newSVGChar () from /usr/lib/perl5/auto/Glib/Glib.so
#3  0x4080b686 in g_closure_invoke () from /usr/lib/libgobject-2.0.so.0
#4  0x4081c5a1 in g_signal_emit_by_name () from /usr/lib/libgobject-2.0.so.0
#5  0x4081b5af in g_signal_emitv () from /usr/lib/libgobject-2.0.so.0
#6  0x410bf3e9 in XS_Glib__Object_signal_emit ()
  from /usr/lib/perl5/auto/Glib/Glib.so
#7  0x40948909 in Perl_pp_entersub () from /usr/lib/libperl.so.5.8
#8  0x40940b09 in Perl_runops_standard () from /usr/lib/libperl.so.5.8
#9  0x408e3459 in Perl_call_sv () from /usr/lib/libperl.so.5.8
#10 0x408e323d in Perl_call_sv () from /usr/lib/libperl.so.5.8
#11 0x410bc2f4 in boot_Glib__Value () from /usr/lib/perl5/auto/Glib/Glib.so
#12 0x4080b686 in g_closure_invoke () from /usr/lib/libgobject-2.0.so.0
#13 0x4081cd1f in g_signal_emit_by_name () from /usr/lib/libgobject-2.0.so.0
#14 0x4081b5af in g_signal_emitv () from /usr/lib/libgobject-2.0.so.0
#15 0x4044404b in gtk_bin_get_child () from /usr/lib/libgtk-x11-2.0.so.0
#16 0x40444c9d in gtk_binding_set_add_path ()
  from /usr/lib/libgtk-x11-2.0.so.0
#17 0x40444f45 in gtk_binding_set_add_path ()
  from /usr/lib/libgtk-x11-2.0.so.0
#18 0x40445170 in gtk_bindings_activate_event ()
  from /usr/lib/libgtk-x11-2.0.so.0
#19 0x405fd528 in gtk_widget_mnemonic_activate ()
  from /usr/lib/libgtk-x11-2.0.so.0
#20 0x4049de3c in _gtk_entry_get_borders () from /usr/lib/libgtk-x11-2.0.so.0
#21 0x4050e6de in _gtk_marshal_BOOLEAN__BOXED ()
  from /usr/lib/libgtk-x11-2.0.so.0
#22 0x4080b919 in g_cclosure_new_swap () from /usr/lib/libgobject-2.0.so.0
#23 0x4080b686 in g_closure_invoke () from /usr/lib/libgobject-2.0.so.0
#24 0x4081c7a5 in g_signal_emit_by_name () from /usr/lib/libgobject-2.0.so.0
#25 0x4081bbdc in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0
#26 0x4081c076 in g_signal_emit () from /usr/lib/libgobject-2.0.so.0
#27 0x405fd8a7 in gtk_widget_send_expose () from /usr/lib/libgtk-x11-2.0.so.0
#28 0x4060a37f in gtk_window_propagate_key_event ()
  from /usr/lib/libgtk-x11-2.0.so.0
#29 0x4060a3fc in gtk_window_propagate_key_event ()
  from /usr/lib/libgtk-x11-2.0.so.0
#30 0x4050e6de in _gtk_marshal_BOOLEAN__BOXED ()
  from /usr/lib/libgtk-x11-2.0.so.0
#31 0x4080b919 in g_cclosure_new_swap () from /usr/lib/libgobject-2.0.so.0
#32 0x4080b686 in g_closure_invoke () from /usr/lib/libgobject-2.0.so.0
#33 0x4081c7a5 in g_signal_emit_by_name () from /usr/lib/libgobject-2.0.so.0
#34 0x4081bbdc in g_signal_emit_valist () from /usr/lib/libgobject-2.0.so.0
#35 0x4081c076 in g_signal_emit () from /usr/lib/libgobject-2.0.so.0
#36 0x405fd8a7 in gtk_widget_send_expose () from /usr/lib/libgtk-x11-2.0.so.0
#37 0x4050d29e in gtk_propagate_event () from /usr/lib/libgtk-x11-2.0.so.0
#38 0x4050c046 in gtk_main_do_event () from /usr/lib/libgtk-x11-2.0.so.0
#39 0x40730815 in _gdk_events_queue () from /usr/lib/libgdk-x11-2.0.so.0
#40 0x408634f2 in g_main_depth () from /usr/lib/libglib-2.0.so.0
#41 0x40864568 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
#42 0x408648a0 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
#43 0x40864e43 in g_main_loop_run () from /usr/lib/libglib-2.0.so.0
#44 0x4050b8f3 in gtk_main () from /usr/lib/libgtk-x11-2.0.so.0
#45 0x0805280e in main (argc=1, argv=0xbffffa94, env=0xbffffa9c) at main.c:91


I'm starting to wonder if it wouldn't be better for me to use the "simpler" way of inheritance (use Base...) and limit myself to that. That would make things less beautiful (I would need to connect a signal directly to the entry box inside the window), but it would probably cause much less problems.

--
Needs are a function of what other people have.

Eduardo M KALINOWSKI
ekalin bol com br
http://move.to/hpkb




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