[Vala] Floating references



Hi all,
  I have defined (in C) a GObject subclass which defines a virtual
method which should create a new GtkWidget:

========
/**
 * ap_application_plugin_build_widget:
 * @self: the #ApApplicationPlugin.
 *
 * Returns: (transfer floating): a #GtkWidget, or %NULL.
 */
GtkWidget *
ap_application_plugin_build_widget (ApApplicationPlugin *self)
{
    g_return_val_if_fail (AP_IS_APPLICATION_PLUGIN (self), NULL);
    return AP_APPLICATION_PLUGIN_GET_CLASS (self)->build_widget (self);
}
========

Then, I have a subclass of ApApplicationPlugin, written in Vala, which
should reimplement the build_widget() virtual method. But is it possible
to write it so that it returns a floating reference?
I tried:

========
    [ CCode ( returns_floating_reference = true ) ]
    public override unowned Gtk.Widget build_widget () {
        return new Gtk.Label ("Hello world!");
    }
========

but the code doesn't compile: "Return value transfers ownership but
method return type hasn't been declared to transfer ownership". If I
introduce a member variable to hold the GtkWidget then it works, but the
generated C code still calls g_object_ref_sink().

It seems that the "returns_floating_reference" does nothing, or I didn't
understand how to use it?

Ciao,
  Alberto



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