Re: [Vala] How to use the ZLib bindings?



Hi Philipp

I tested your patch and it works very fine for me.
I also attached a deflate example based on the code of your inflate
example to this mail. The example takes a dummyfile.txt file and outputs
in gzip file format.
It is compiled with 
valac --pkg gio-2.0 --pkg zlib -X -lz zlibtest_deflate.vala 

Maybe somebody with a gnome git account can merge the patch into vala
repository?

Regards
Jörn 



Am Sonntag, den 04.10.2009, 14:25 +0200 schrieb Philipp Zabel:
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 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
Vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list

Attachment: zlib_jm.patch
Description: Text Data

Attachment: zlibtest_deflate.vala
Description: Text Data



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