[Vala] Derived types don't seem to get properly initialized in libpeas plugins.



Hi, I have come across some weird behavior that should either get fixed or
be included in a guide, along with a fix.

If you have a class that is derived from another class, you can't use it in
signals until at least one instance of it has been created. (Inheriting
from Object works, but inheriting from a class that itself inherits from
Object does not work.)
As far as I know this only happens in plugins.

An easy way to demonstrate it is to download the following sample code from
https://github.com/voldyman/plugin-app and add a few signals and classes to
plug.vala:

using PlugApp;

public class Really : Peas.ExtensionBase,  Peas.Activatable
{
    ...

    public signal void base_signal (TestClass test);
    public signal void derived_signal (TestTestClass test);

    ...
}

public class TestClass {}

public class TestTestClass : TestClass {}

[ModuleInit]
public void peas_register_types (GLib.TypeModule module)
{
    var objmodule = module as Peas.ObjectModule;
    objmodule.register_extension_type (typeof (Peas.Activatable),
                                       typeof (Really));
}

Will output "(process:6182): GLib-GObject-WARNING **:
/build/buildd/glib2.0-2.42.2/./gobject/gsignal.c:1631: parameter 1 of type
'TestTestClass' for signal "Really::derived_signal" is not a value type".

Creating an instance before anything that needs it in a signal is created
just to have the type properly initialized doesn't seem right to me.

typeof (ClassName) returns the same Type as the Type returned by running
Type.from_instance (new ClassName ()) after it.

What's a good way to deal with this?

Sorry if my mail is a bit messy.

     Jonathan Moerman


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