Hi,

I'm having troubles to compile the vala file attached to this e-mail.
The command line is:

    valac --pkg=gio-2.0 --pkg=glib-2.0 email.vala

When the lines containing `buffer += c` are commented out (lines 67 and
70), the program compiles.

I use vala 0.9.3 as packaged by the Fedora distribution.
The vala compiler gives me the following errors:

----------------------------------------------------------------------

email.vala:25.13-25.37: warning: unhandled error `GLib.Error'
        if (parent.read (&c, 1, null) == 0){
            ^^^^^^^^^^^^^^^^^^^^^^^^^
email.vala:41.5-41.32: warning: method
`Email.EmailInputStream.push_back_buffer' never used
    public void push_back_buffer (uint8[] buffer) {
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
email.vala:51.5-51.25: warning: method
`Email.EmailInputStream.read_line' never used
    public bool read_line(ref uint8[] buffer){
    ^^^^^^^^^^^^^^^^^^^^^
**
ERROR:valaccodearraymodule.c:1407:vala_ccode_array_module_real_get_array_size_cexpression:
code should not be reached
zsh: abort (core dumped)  valac --pkg=gio-2.0 --pkg=glib-2.0 email.vala

----------------------------------------------------------------------

Apparently, this is an assertion failure in the compiler code that
causes this error.

What do you think of this error? Am I doing wrong things?

By the way, I couldn't find any reference on the built-in operations
available on the vala arrays (buffer.length, buffer.resize(int), buffer
+=, ...)
Where do you think I could find documentation on that ?

Note: I'm using uint8[] instead of string because I just want to
manipulate a stream of bytes that very often looks like a string. I
don't want to deal with encoding problems. Is there a better solution?

Thanks.

Mildred


-- 
Mildred Ki'Lya
╭───────── mildred593@online.fr ──────────
│ Jabber, GoogleTalk: <[email protected]>
│ Website: <http://ki.lya.online.fr>           GPG ID: 9A7D 2E2B
│ Fingerprint: 197C A7E6 645B 4299 6D37 684B 6F9D A8D6 9A7D 2E2B
using GLib;

namespace Email {

  class EmailInputStream : Object {
  
    private InputStream parent;
    
    public EmailInputStream(InputStream parent) {
      this.parent = parent;
    }
    
    public  bool    eof { get; private set; default = false; }
    private uint8[] push_back = {};
    private bool    push_back_eof = false;
    
    public bool read_char(out uint8 c){
      if (push_back.length > 0) {
        c = push_back[push_back.length - 1];
        push_back.length--;
        if(push_back.length == 0) {
          eof = push_back_eof;
        }
      } else {
        if (parent.read (&c, 1, null) == 0){
          eof = true;
          return false;
        }
      }
      return true;
    }
    
    public void unread_char(uint8 c){
      if (push_back.length == 0){
        push_back_eof = eof;
        eof = false;
      }
      push_back += c;
    }
    
    public void push_back_buffer (uint8[] buffer) {
      if (buffer.length > 0 && push_back.length == 0){
        push_back_eof = eof;
        eof = false;
      }
      for(int i = buffer.length - 1; i >= 0; --i){
        push_back += buffer[i];
      }
    }
    
    public bool read_line(ref uint8[] buffer){
      uint8 c;
      uint8 CR = 0x0D;
      uint8 LF = 0x0A;
      bool crlf = false;
      buffer.resize(0);
      while (read_char(out c)) {
        //
        // CRLF management:
        //
        // ?? LF  ->  append, break
        // ?? CR  ->  append, wait for the LF
        // CR LF  ->  append, break
        // CR ??  ->  push back, break
        // ?? ??  ->  append, continue
        //
        if (c == LF) { buffer += c;    break; }
        if (crlf)    { unread_char(c); break; }
        if (c == CR) { crlf = true; }
        buffer += c;
      }
      return !eof;
    }
  
  }

}

static void main(string[] args) {
  stdout.puts("Hello\n");
}

Attachment: 0x9A7D2E2B.asc
Description: application/pgp-keys

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to