Re: [Vala] Problem with references



Hi Dominique,

On Fre, 2006-08-25 at 10:10 +0200, Dominique Würtz wrote:
First of all, thank you for resolving all those issues so quickly.

Anytime, thanks for pointing out important issues.

Now for my bindings, I need to pass references around (references to 
Cairo.Matrix). I tried to use the ref keyword like this

class X {
    public ref Cairo.Matrix transform;

    public ref Cairo.Matrix get_transform ()
    {
        return transform;
    }
}

in the belief "ref Cairo.Matrix" would translate to "cairo_matrix_t *". 
However, the ref attribute seems to have no effect on the generated code.

Vala mostly follows C#'s model of value- and reference-type semantics
with the exception that Vala allows to mark structs as reference-type to
better integrate with non-GObject based C libraries. Cairo.Matrix is
currently declared as a normal value-type struct which means that the
only place you can pass a reference is in a method parameter. Return
types can't be declared as `ref' for that purpose and the compiler
should have reported an error.

In that concrete case it would probably be best to just mark
Cairo.Matrix as a reference-type, so it will always be passed by
reference. That would make it impossible to ever pass it by value,
though. Do you see a problem with that or shall I change Cairo.Matrix as
afore said?

BTW, I had to add

[CCode (cname = "cairo_matrix_t")]

to cairo.vala in order to have Vala use the proper name of the cairo struct.

Right, fixed that here, thanks.

Regards,

Jürg




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