Re: [Vala] How to properly define struct in manually written VAPI?
- From: Ben <iofelben gmail com>
- To: "marcin saepia net" <marcin saepia net>
- Cc: vala <vala-list gnome org>
- Subject: Re: [Vala] How to properly define struct in manually written VAPI?
- Date: Wed, 02 Mar 2016 09:28:13 -0500
FYI, Vala already has binding for json-glib
http://valadoc.org/#!api=json-glib-1.0/Json
It has nice features like deserialization with GObject properties
On Wed, Mar 2, 2016 at 5:19 AM, marcin saepia net <marcin saepia net>
wrote:
Hello,
I need to write VAPI for jansson JSON library. I have already started
(
https://github.com/akheron/jansson/pull/273) and generally speaking it
works fine but I have an issue with covering one struct.
In C code there's the following struct:
#define JSON_ERROR_TEXT_LENGTH 160
#define JSON_ERROR_SOURCE_LENGTH 80
typedef struct {
int line;
int column;
int position;
char source[JSON_ERROR_SOURCE_LENGTH];
char text[JSON_ERROR_TEXT_LENGTH];
} json_error_t;
it is an output parameter to function that should have the following
syntax
in Vala:
loads(string input, LoadFlags flags, out Error error)
I struggle to properly define it in VAPI. When I define it like this:
[CCode (cname = "json_error_t", has_type_id = false)]
public struct Error {
public string text;
public string source;
public int line;
public int column;
public size_t position;
}
it complains about missing copy function during C compilation phase
when I add
[CCode (cname = "json_error_t", has_copy_function = false,
has_type_id =
false)]
public struct Error {
public string text;
public string source;
public int line;
public int column;
public size_t position;
}
it then throws
api/auth/oauth2.c:939:2: error: array type 'char [160]' is not
assignable
_g_free0 ((*dest).text);
^ ~~~~~~~~~~~~
api/auth/oauth2.c:51:28: note: expanded from macro '_g_free0'
api/auth/oauth2.c:940:15: error: array type 'char [160]' is not
assignable
(*dest).text = _tmp1_;
~~~~~~~~~~~~ ^
api/auth/oauth2.c:943:2: error: array type 'char [80]' is not
assignable
_g_free0 ((*dest).source);
^ ~~~~~~~~~~~~~~
How to define it properly? Underlying API does not provide any
destroy/copy
functions.
I also tried to convert it to the compact class but then Vala Compiler
creates pointer-to-pointer for underlying C code for the parameter
which is
improper.
Thanks,
Marcin
_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]