[Vala] GLib.List again



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:

C header:
-------------------------------------------------------------------
typedef struct { int a; } X;
X*   x_new();
void x_destroy(X *self);

typedef struct { int b; } FooBar;
FooBar* foo_bar_new();
void   foo_bar_destroy(FooBar *self);
GList* foo_bar_run(FooBar *self, GList *list);
-------------------------------------------------------------------

C usage:
-------------------------------------------------------------------
...
GList *list = oldlib_make_xlist();
list = foo_bar_run(foobar, list);
...
oldlib_destroy_xlist(list);
...
-------------------------------------------------------------------

VAPI:
-------------------------------------------------------------------
[Compact]
[CCode (cheader_filename = "oldlib.h",
        free_function    = "x_destroy")]
public class X {
    public X();
}

[Compact]
[CCode (cheader_filename = "oldlib.h",
        free_function    = "foo_bar_destroy")]
public class FooBar {
    public FooBar();

    // 1. WRONG version:
    public GLib.List<X>? run(GLib.List<X>? list);

    // 2. WRONG version:
    [ReturnsModifiedPointer]
    public void run(GLib.List<X>? list);
}
-------------------------------------------------------------------

Thanks for any help or suggestions.

Regards,
Jan Spurny




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