Re: signal_add_emission_hook first in program



Kevin Ryde wrote:
The program below gets an error

  Unknown signal realize for object of type  at /usr/lib/perl5/Glib.pm line 211.

where I hoped it would print "realized something".

I wonder if signal_add_emission_hook() has to cope with lazy loading of
types or something.  Calling the commented-out find_property() just as a
dummy first seems to drag in whatever's needed to make it work.

Actually, the problem is not the lazy loader.  It's that the type class
corresponding to the package name just doesn't exist yet.  The failure
occurs because g_signal_parse_name apparently doesn't work when the type
class hasn't been created yet.

The attached patch fixes this in the bindings.  (It also fixes the error
message, which tried to get a string from a GType.)

But I wonder if it's not actually g_signal_parse_name's fault.
Shouldn't it work even for types whose type class doesn't exist yet?

-- 
Bye,
-Torsten
Index: GSignal.xs
===================================================================
RCS file: /cvsroot/gtk2-perl/gtk2-perl-xs/Glib/GSignal.xs,v
retrieving revision 1.31
diff -u -d -p -r1.31 GSignal.xs
--- GSignal.xs  7 Jan 2008 18:50:06 -0000       1.31
+++ GSignal.xs  20 May 2008 20:16:58 -0000
@@ -416,7 +416,7 @@ parse_signal_name_or_croak (const char *
        if (!g_signal_parse_name (detailed_name, instance_type, &signal_id,
                                  detail, TRUE))
                croak ("Unknown signal %s for object of type %s", 
-                       detailed_name, instance_type);
+                       detailed_name, g_type_name (instance_type));
        return signal_id;
 }
 
@@ -709,16 +709,24 @@ g_signal_add_emission_hook (object_or_cl
        SV * hook_data
     PREINIT:
        GType           itype;
+       GObjectClass *  object_class;
        guint           signal_id;
        GQuark          quark;
        GPerlCallback * callback;
     CODE:
        itype = get_gtype_or_croak (object_or_class_name);
+
+       /* See the xsub for g_object_find_property in GObject.xs for why the
+        * class ref/unref stunt is necessary. */
+       object_class = g_type_class_ref (itype);
+
        signal_id = parse_signal_name_or_croak (detailed_signal, itype, &quark);
        callback = gperl_signal_emission_hook_create (hook_func, hook_data);
        RETVAL = g_signal_add_emission_hook
                        (signal_id, quark, gperl_signal_emission_hook,
                         callback, (GDestroyNotify)gperl_callback_destroy);
+
+       g_type_class_unref (object_class);
     OUTPUT:
        RETVAL
 


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