Re: buildable interface testers error

Kevin Ryde wrote:
So I think you'll have to do some version checking with Gtk2->CHECK_VERSION.

Is there a direct way to ask if something is an implementable interface?
I guess Gtk2::Buildable->can('_ADD_INTERFACE'), but if that's supposed
to be used.

That's relying too much on internals, I think.  Better ask Glib directly:

  grep { $_ eq 'Gtk2::Buildable' } Glib::Type->list_interfaces ('Gtk2::Widget')

Or maybe even better yet, ask perl:

  Gtk2::Widget->isa ('Gtk2::Buildable');

Or should the bindings behave differently in such a case?

The error message is fairly obscure.  But an error from
Glib::Object::Subclass is probably good.  For myself I'll want to
quietly drop Buildable when not available, but for other interfaces that
could be bad.

We could check that the interface is actually registered before calling _ADD_INTERFACE, as in the attached patch. Does this make sense? muppet?

Index: GType.xs
--- GType.xs    (revision 1033)
+++ GType.xs    (working copy)
@@ -1458,10 +1458,18 @@ add_interfaces (GType instance_type, AV 
                newSVpv (gperl_object_package_from_type (instance_type), 0);
         for (i = 0; i <= av_len (interfaces); i++) {
+               GType interface_type;
                SV ** svp = av_fetch (interfaces, i, FALSE);
                if (!svp || !gperl_sv_is_defined (*svp))
                        croak ("encountered undefined interface name");
+               interface_type = gperl_object_type_from_package (SvPV_nolen (*svp));
+               if (!interface_type) {
+                       croak ("encountered unregistered interface %s",
+                              SvPV_nolen (*svp));
+               }
                /* call the interface's setup function on this class. */

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