Some vala for Midgard2
Posted on 2009-09-10 11:53:33 EEST.
Recently I decided to start some Midgard2 developing work using vala. I needed to implement simple GLib's GKeyFile wrapper, so vala seemed best choice.
First of all, vala is perfect (and sexy excellent) for boring and time consuming routines like GObject class' macros and standard hooks initialization. But with real, non standard code I started to hit the wall.
GLib.KeyFile
kf.set_comment (group, key, comment);
generates:
g_key_file_set_comment (self->priv->_keyfile, group, key, comment);
Obviosuly error pointer (or NULL) is missed so code won't compile.
kf.get_groups ();
generates:
return (_tmp1 = g_key_file_get_groups (self->priv->_keyfile, &_tmp0), *result_length1 = _tmp0, _tmp1);
&_tmp0 is expected to be size_t so code doesn't compile too.
Those are minor issues as you can always edit autogenerated code and fix bugs. But this is not the point.
GLib.List
GLib.List list = new GLib.List<string> ();
list.prepend (some_string_var);
generates code which doesn't compile cause of self->priv->g_dup_func missed member.
string
I created string array property, like this:
private string[] cfgs;
and constructor:
this.cfgs = new string[0];
this.cfgs = {};
and added more elements:
this.cfgs += some_string_var;
Code compiles and runs but greatly segfaults with 'double free or corruption'
I am using valac 0.5.7-1 on 64bit Ubuntu 9.04. Might be that all issues are on mine side.
Updated:
var arr = new GLib.Array<string> (false, false, (uint)sizeof (string));
arr.append_val (abspath.ndup(abspath.length));
doesn't compile:
error: lvalue required as unary ‘&’ operand
and C code:
g_array_append_val (arr, _tmp7 = g_strndup (abspath, (gsize) string_get_length (abspath)));