Re: [Vala] GLib.List again



Hello,

2011/5/20, Jan Spurný <JSpurny seznam cz>:
Hi,

I have another question regarding manual writing VAPI files for existing
C libraries using GLib.List. Now I have troubles with a method which acts
similarly like many of the GList's methods - it takes "GList *" parameter
and
returns it's "new value" - which may or may not be the same as the given
parameter, but it MUST be used.

The only difference is that in my case the metod belongs to some
other "Compact class" - so I can't use [ReturnsModifiedPointer] attribute
and
without it vala will think that return value is something new and at the end
of the scope it will try to free them both. It looks like this:

I think this is something valac can't do for you, so you need to write
some ugly code: Using the same notation as your example, you'd need to
define your method as:

public GLib.List<X> run(owned GLib.List<X> list);

(owned tells valac that a value passed to this function doesn't need
to be freed) and then you call it as:

list = foo_bar.run ((owned) list);

(and if you forget the (owned) cast, you'll get an error telling you
to explicitly copy)

HTH,
Abderrahim



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