I would extend this idea to make it a little easier to write for the user:

Create a binding as follows:

[SimpleType]
[CCode(cname = "struct timeval")]
private struct TimeVal {
[CCode(cname = "*")]
public static TimeVal(Posix.timeval v);
}

private Redis.Context redisConnectWithTimeout(string ip, int port, TimeVal
tv);
public Redis.Context connect_with_timeout(string ip, int port,
Posix.timeval tv) {
  return redisConnectWithTimeout(ip, port, TimeVal(tv));
}

This will pass the time val as a pointer and then create a second struct
that is really just a dereference operation.

I don't know if there's an easy way to use GLib.TimeVal instead of
Posix.timeval or if they are guaranteed to be compatible of every machine.

On 22 November 2015 at 21:01, Evan Nemerson <e...@coeus-group.com> wrote:

> On Sun, 2015-11-22 at 16:07 +0800, Matrix wrote:
> > Hi :
> >
> > i'm writting hiredis vala's binding..
> >
> > here is a function like this:
> >
> > redisContext *redisConnectWithTimeout(const char *ip, int port, const
> > struct timeval tv);
> >
> > so, how to tell the valac that the 3rd param is struct value not
> > struct
> > pointer?
>
> Unfortunately, this is done on a per-type basis, and virtually everyone
> passes struct timeval as a pointer so that's what the bindings assume.
> Before seeing this function, I don't know that I've ever seen it passed
> as anything but a pointer.
>
> AFAIK the only way to do this would be to create a local binding for
> struct timeval (in the redis vapi) with a [SimpleType] annotation on
> it, and have redis use that type instead of the one in glib-2.0.
>
> FWIW it might be possible to add an annotation to allow for passing a
> non-SimpleType struct as a value.  I don't spend much time in the
> compiler, but I believe a small change to
> valaccodemethodcallmodule.vala would do the trick.
>
>
> -Evan
> _______________________________________________
> vala-list mailing list
> vala-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/vala-list
>
>


-- 
--Andre Masella<an...@masella.name>
http://www.masella.name/
_______________________________________________
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to