2011-06-17

Vala 0.13.0 released

Hello,
after two months of active development, the Vala programming language has reached version 0.13.0.

Changes

  • More refactoring in the code generator.
  • Improvements to the .gir reader.
  • Switch JSON-GLib bindings to .gir.
  • Drop deprecated support for D-Bus GLib in favor of GDBus.
  • Many bug fixes and binding updates.

Some numbers: 314 commits and 94 bug fixes since version 0.12.0. So this new development release is a mix of enhancements and fixes.

A noteworthy change is the deprecation of copying delegates. A delegate is copied when it is assigned to an owned delegate variable like this:

SourceFunc a = () => false;
SourceFunc b = a;

You will get a warning: "copying delegates is discouraged" or "copying delegates it not supported". This is because of the nature of delegates in glib. Owned delegate variables have a related target and a GDestroyNotify, but it's not known how to copy/ref the target. Therefore, it's impossible to copy/ref a delegate target.

So, how do we shut the warning? There are two ways:

1) If you don't need owned delegate, you can assign to an unowned variable like this: unowned SourceFunc b = a;
2) If you want to transfer the ownership: SourceFunc b = (owned) a; After this, you can still invoke a() but the target will not be destroyed anymore when a runs out of the scope.

You might experience the same warning for delegate properties as well, like this:

public SourceFunc func { get; set; }

Here there are two solutions:
1) If you need owned delegate, use owned set like this: public SourceFunc func { get; owned set; }, while keeping the getter unowned.
2) If you don't need owned delegate: public unowned SourceFunc func { get; set }

It must be noted that due to a bug (now fixed in this release), although you defined an owned delegate property, it was practically unowned.

3 comments:

  1. Thanks for this summary of changes.

    ReplyDelete
  2. There's also a third way: if the delegate does not require a target (i.e. it's not necessary for it to be associated with an object instance), then declare it as such:

    [CCode (has_target=false)]
    delegate void Delegate();

    These types of delegates are less useful, obviously, but one more technique to be aware of.

    ReplyDelete
  3. This comment maybe out off topic but I want to ask for your opinion, What is your Development environment? what distribution you use and how to get this environment whith cutting edge libraries as gtk+ 3 and so. Because when i want to use by example gtk3 I need to install a new box virtual o fisical but I am so busy of doing that.

    ReplyDelete