Re: [Vala] How to properly define struct in manually written VAPI?
It was long time ago, indeed: https://bugzilla.gnome.org/show_bug.cgi?id=651271 Wow, how fast the time passes. Ok, maybe I will give it another try :) m. 2016-03-02 17:59 GMT+01:00 Ben Iofel : > If you can make it segfault, please file a bug or at least post the code > here > > > On Wed, Mar 2, 2016, 11:09 AM mar...@saepia.net wrote: > >> Hello, >> >> thank you for suggestions. I'll try to implement them. >> >> But should I keep it as struct or rather compact class? >> >> Regarding json-glib: I intentionally try to avoid it. I was able to make >> segfault even with a few simple attempts that should be tested in properly >> written library, I don't need mapping for GObject properties, and I think I >> encountered also some issues with big integers, I don't remember now. In my >> use case more low level, better-tested library will a be better choice. >> >> m. >> >> 2016-03-02 15:28 GMT+01:00 Ben : >> >>> 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, mar...@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 >>> >>> >> ___ vala-list mailing list vala-list@gnome.org https://mail.gnome.org/mailman/listinfo/vala-list
Re: [Vala] How to properly define struct in manually written VAPI?
If you can make it segfault, please file a bug or at least post the code here On Wed, Mar 2, 2016, 11:09 AM mar...@saepia.net wrote: > Hello, > > thank you for suggestions. I'll try to implement them. > > But should I keep it as struct or rather compact class? > > Regarding json-glib: I intentionally try to avoid it. I was able to make > segfault even with a few simple attempts that should be tested in properly > written library, I don't need mapping for GObject properties, and I think I > encountered also some issues with big integers, I don't remember now. In my > use case more low level, better-tested library will a be better choice. > > m. > > 2016-03-02 15:28 GMT+01:00 Ben : > >> 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, mar...@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 >> >> > ___ vala-list mailing list vala-list@gnome.org https://mail.gnome.org/mailman/listinfo/vala-list
Re: [Vala] How to properly define struct in manually written VAPI?
> From: "mar...@saepia.net" >Sent: Wednesday, 2 March 2016, 16:08 >Subject: Re: [Vala] How to properly define struct in manually written VAPI? > >thank you for suggestions. I'll try to implement them. > >But should I keep it as struct or rather compact class? As a struct. A compact class in Vala is used to bind a set of function calls that operate on a struct, the struct being the instance data. For a compact class Vala will automatically generate the first parameter of the function call to be a struct of the right type to pass the instance data. > >Regarding json-glib: I intentionally try to avoid it. I was able to make >segfault even with a few simple attempts that should be tested in properly >written library, I don't need mapping for GObject properties, and I think I >encountered also some issues with big integers, I don't remember now. In my >use case more low level, better-tested library will a be better choice. json-glib is perfectly stable for the uses I'm putting it to. I remember it took a while to get used to the API. Here's an example that prints out a JSON array in JSON. The format is: { "script" : [] } It is in Genie, so meaningful whitespace and types are after identifiers: def print_script( script:Json.Node ) print "about to create JSON generator" var test = new Json.Generator test.set_pretty( true ) print "about to create root node" var root = new Json.Node( Json.NodeType.OBJECT ) print "about to create script object" var script_object = new Json.Object print "about to set script member" script_object.set_member( "script", script ) print "about to add script object to root node" root.set_object( script_object ) print "about to set root" test.set_root( root ) length:size_t print "about to print JSON" print test.to_data( out length ) Regards, Al ___ vala-list mailing list vala-list@gnome.org https://mail.gnome.org/mailman/listinfo/vala-list
Re: [Vala] How to properly define struct in manually written VAPI?
Hello, thank you for suggestions. I'll try to implement them. But should I keep it as struct or rather compact class? Regarding json-glib: I intentionally try to avoid it. I was able to make segfault even with a few simple attempts that should be tested in properly written library, I don't need mapping for GObject properties, and I think I encountered also some issues with big integers, I don't remember now. In my use case more low level, better-tested library will a be better choice. m. 2016-03-02 15:28 GMT+01:00 Ben : > 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, mar...@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 > > ___ vala-list mailing list vala-list@gnome.org https://mail.gnome.org/mailman/listinfo/vala-list
Re: [Vala] How to properly define struct in manually written VAPI?
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, mar...@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_LENGTH160 #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 ___ vala-list mailing list vala-list@gnome.org https://mail.gnome.org/mailman/listinfo/vala-list
Re: [Vala] How to properly define struct in manually written VAPI?
From: "mar...@saepia.net" Sent: Wednesday, 2 March 2016, 10:19 Subject: [Vala] How to properly define struct in manually written VAPI? 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 Bind as:[CCode (cname = "int", cprefix = "JSON_ERROR_", has_type_id = false)] public enum JsonErrorLengths { TEXT_LENGTH, SOURCE_LENGTH }See: https://wiki.gnome.org/Projects/Vala/LegacyBindings#Enums_and_Flags typedef struct { int line; int column; int position; char source[JSON_ERROR_SOURCE_LENGTH]; char text[JSON_ERROR_TEXT_LENGTH]; } json_error_t; Try binding as:[CCode( cname = "json_error_t", has_type_id = false )]public struct JsonError { public int line; public int column; public int position; public uint8 source[ JsonErrorLengths.SOURCE_LENGTH ]; public uint8 text[ JsonErrorLengths.TEXT_LENGTH ]; } or you could try using:[CCode (array_length_cexpr = "JSON_ERROR_SOURCE_LENGTH")]See: https://wiki.gnome.org/Projects/Vala/LegacyBindings#Arrays-1 I hope that helps, Al ___ vala-list mailing list vala-list@gnome.org https://mail.gnome.org/mailman/listinfo/vala-list
[Vala] How to properly define struct in manually written VAPI?
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_LENGTH160 #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