Re: [Vala] out, ref and GError parameters.



On 3/14/07, Jürg Billeter <j bitron ch> wrote:
On Mit, 2007-03-14 at 10:12 -0300, Alexandre Moreira wrote:
> I'd like to know what is the "ref" keyword supposed to do in
> parameters, I thought it would make the said parameter a pointer to
> the type, but it made no change, at least not with class types.
>
> So, right now I'm using out for that matter. Unfortunately, I can't
> seem to use the GError stuff with that because it always tries to
> dereference the pointer... and it is very likely that users of the
> code will once in a while pass null as a parameter.
>
> Do you guys have any idea on how to make this kind of code work ? It
> is the last thing preventing me from using Vala and I'd really like to
> use it :)

The plan is to use try, catch, and throw statements to handle GErrors;
that hasn't been implemented yet, though.

ref parameters are not yet supported with reference types, using out is
correct for the moment but that's not the problem. It's not possible to
pass null to ref and out parameters in C#; Vala follows this rule. The
reason is that it always dereferences the pointer; you can't check
whether the pointer itself is null with the current syntax, as there is
nothing like error and *error in C.

It probably makes sense to add support for real pointers like in C or
unsafe C#, this would fix the problem in this case.

There is still one possibility how to work around this limitation with
the current version, you may use something like the following:

if (out error != null) {
        // set error
}

Support for this syntax will be removed in future Vala versions but
we'll try to keep it as long as neither exceptions nor pointers are
supported.

I truly believe that there should be a pointer support. At first it
shouldn't be hard to implement (once we have ref and out, ptr
shouldn't be that much different) and it would be very good for
interface with Other C-based code, it is a way to let the user
interface with bare C code with not much fuss...

I'd love to have pointer support, this is basically "THE" thing I miss
in Vala, not that I would use it that much... just that I like the
Error support in GLib and wouldn't feel like using an exception
handling mechanism ...

If I'm allowed to ask: PLEASE, add pointer support :) It shouldn't be
the preferred way to do things but I'd love to have it available to
solve the problems one might face.

Regards,
Alexandre Moreira.

HTH,

Jürg





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