On Sun, Oct 4, 2009 at 7:25 AM, Philipp Zabel <[email protected]> wrote:

> Hi,
>
> Does anybody have example code that uses the ZLib bindings? I tried to
> implement the example described at http://zlib.net/zlib_how.html for
> inflation, but compilation failed with errors from gcc about STATUS_OK
> etc. symbols not being found. The following patch helped with that for
> some reason.
>
> Also, I don't understand how Vala can handle memory for the next_in and
> next_out pointers when the inflate call is changing those pointers under
> its nose. Wouldn't it be more realistic not to wrap them as an array?
>
>
I believe old vapi binding for next_in and next_out still works. Vala don't
manage the memory of struct types declared in vapi files.

If you are sure the buffer is not owned by the struct and you want to
explicitly mention this in the vapi file, use 'unowned'. Change the
signature to 'unowned uchar[]' in this case.

Please avoid pointers if possible in vapi bindings. Pointers forces
programers write '->'s and makes the code C++-ish.

Remember your vapi file is going to be used by others and will affect their
programming styles. The influence might be permanent.


Yu



> I attached test code that works with this VAPI change (to be compiled
> with -X -lz). Any way to make it work without it?
>
> thanks
> Philipp
>
> diff --git a/vapi/zlib.vapi b/vapi/zlib.vapi
> index b615f6f..14cc973 100644
> --- a/vapi/zlib.vapi
> +++ b/vapi/zlib.vapi
> @@ -49,16 +49,24 @@ namespace ZLib {
>                public const int BLOCK;
>        }
>
> -       [CCode (cprefix = "Z_")]
>        namespace Status {
> +               [CCode (cname = "Z_OK")]
>                public const int OK;
> +               [CCode (cname = "Z_STREAM_END")]
>                public const int STREAM_END;
> +               [CCode (cname = "Z_NEED_DICT")]
>                public const int NEED_DICT;
> +               [CCode (cname = "Z_ERRNO")]
>                public const int ERRNO;
> +               [CCode (cname = "Z_STREAM_ERROR")]
>                public const int STREAM_ERROR;
> +               [CCode (cname = "Z_DATA_ERROR")]
>                public const int DATA_ERROR;
> +               [CCode (cname = "Z_MEM_ERROR")]
>                public const int MEM_ERROR;
> +               [CCode (cname = "Z_BUF_ERROR")]
>                public const int BUF_ERROR;
> +               [CCode (cname = "Z_VERSION_ERROR")]
>                public const int VERSION_ERROR;
>        }
>
> @@ -98,12 +106,12 @@ namespace ZLib {
>
>        [CCode (cname = "z_stream", destroy_function = "deflateEnd")]
>        public struct Stream {
> -               [CCode (array_length_cname = "avail_in", array_length_type
> = "guint")]
> -               public uchar[] next_in;
> +               public uchar* next_in;
> +               public uint avail_in;
>                public ulong total_in;
>
> -               [CCode (array_length_cname = "avail_out", array_length_type
> = "guint")]
> -               public uchar[] next_out;
> +               public uchar* next_out;
> +               public uint avail_out;
>                public ulong total_out;
>
>                public string? msg;
>
>
> _______________________________________________
> Vala-list mailing list
> [email protected]
> http://mail.gnome.org/mailman/listinfo/vala-list
>
>
_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to