Re: [Vala] CCode array length field name



On Mon, 2009-11-30 at 15:09 -0800, Evan Nemerson wrote:
On Mon, 2009-11-30 at 23:45 +0100, pHilipp Zabel wrote:
On Mon, Nov 30, 2009 at 10:19 PM, Jan-Jaap van der Geer
<jjvdgeer inbox com> wrote:
I have something related. I have the following struct in C:

typedef struct
{
 int errnum;
 char errmess[252];
} os_error;

Right now I have this vapified like this:

[CCode (cname == "os_error")]
public struct error
{
 public unowned int errnum;
 public unowned char[] errmess;
}

However, when accessing the error.errmess.length I get compilation
errors (in C,, not in Vala. error: 'os_error' has no member named
'errmess_length1'). I suppose this is due to a problem in the vapi, but
I am not really sure how to tell Vala the length is 252 bytes.

I tried prefixing the errmess member with:
[CCode (array_length_name = "252", array_length_type = "int")]
but that did not seem to make a difference.

Any ideas?

[CCode (array_length = false)] will make Vala turn errmess.length into
constant -1 instead of errmess_length1. I don't know of any way to
make that constant 252 instead.

IIRC this should do the trick:

[CCode (cname == "os_error")]
public struct error {
  public unowned int errnum;
  public unowned char errmess[252];
}

I am afraid I need to come back at this. Although your solution works
fine in the situation I provided, I did not get it working for
multidimensional arrays. I get compilation errors trying to do something
like this:

[CCode (cname == "os_error")]
public struct error {
  public unowned int errnum;
  public unowned char errmess[42,42];
}

Is this not supported?

Cheers,
Jan-Jaap





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