Re: [Vala] [PATCH] Add libarchive bindings.



Am Sonntag, den 22.11.2009, 11:18 -0800 schrieb Evan Nemerson:
On Sun, 2009-11-22 at 18:37 +0100, Julian Andres Klode wrote:
On Sun, Nov 22, 2009 at 05:32:36PM +0100, Michael 'Mickey' Lauer wrote:
Hi Julian,

this looks mostly good, however please do not use
[CCode (has_target = false)] unless the upstream API does not provide a
user_data or client_data pointer. In the case of your delegates, it
seems all provide such a client_data pointer, so rather use
[CCode (instance_pos = ...)] for it, otherwise you would limit callbacks
to being static only.

Any more exact ideas? All delegates take the Archive instance as their
first parameter and userdata as their second:
    public delegate off_t SkipCallback (Archive archive, void* client_data, off_t request);

I believe this is what you want:

[CCode (instance_pos = 1.9)]
public delegate off_t SkipCallback (Archive archive, off_t request);
Yes, this seems to work.


Now, one method of Read (a sublcass of Archive) is:
    public Result open (void* client_data, OpenCallback ocb, ReadCallback rcb, CloseCallback ccb);
And "client_data" shall be passed to all callbacks.

Ah, that is more tricky. AFAIK there isn't really an elegant way to do
this, since Vala assumes one user data argument per callback. You could
try something along the like:

public Result open (
  [CCode (delegate_target_pos = 0.9)] OpenCallback ocb,
  [CCode (delegate_target_pos = 0.9)] ReadCallback rcb,
  [CCode (delegate_target_pos = 0.9)] CloseCallback ccb);

Which I believe will generate correct code, but there is likely to be a
problem if the user data argument for the three callbacks would have
been different. For example,

archive.open (Foo.open_cb, Bar.read_cb, Baz.close_cb);

Will most likely break horribly at runtime, though it probably won't
emit any errors or warnings at compile time.
This is Bug #602712, by the way.



I want have the delegate be:
    public delegate off_t SkipCallback (off_t request);
and the method:
    public Result open (OpenCallback ocb, ReadCallback rcb, CloseCallback ccb);

How should I do this?

I don't think you can do that for the delegate signature because there
is no Archive parameter.
Yes, the listed parameters are incomplete.


Also, can you please not use "using Posix" in the bindings? Lots of
people use the vapi as a reference, and it's a bit disorienting.

Done.

I attached the patch with the changes included. I was not able to do a
in-depth test of the bindings, but I expect them to work (I tested the
read part and verified all functions 2 times against their C
definition). The bindings are against libarchive 2.6.2, upstream is
already at 2.7.1, but I was basing this against the version in Ubuntu
9.10 "karmic".

Regards,
Julian

-- 
Julian Andres Klode  - Debian Developer, Ubuntu Member

See http://wiki.debian.org/JulianAndresKlode and http://jak-linux.org/.

Attachment: 0001-Add-libarchive-bindings.patch
Description: Text Data



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