Re: [Vala] embedding c code snippet in vala source.



On Fri, 2008-08-22 at 10:44 +0200, Jürg Billeter wrote:
Hi Yu,

On Fri, 2008-08-22 at 02:58 -0400, Yu Feng wrote:
Which do you prefer if you want to split a string? mysplit or split?

    [CCode (cname = "g_strmysplit", snippet = "gchar ** rt = g_strsplit(this,
delimiter, max_tokens); *result_length1 = rt?g_strv_length(rt):0; return rt;")]
    public string[] mysplit (string delimiter, int max_tokens = 0);

    [CCode (cname = "g_strsplit")]
    [NoArrayLength]
    public string[] split (string delimiter, int max_tokens = 0);

While mysplit is more comfortable to use right now as it correctly
handles the null-terminated array, reading C code snippets embedded into
a string in a .vapi file is not what I'm looking forward to.

Support for null-terminated arrays is planned, so the second split
binding will work the same way without major additions in the .vapi file
as soon as this is implemented.

As far as I understand it, you're proposing to not handle this at all in
the compiler and just add a snippet attribute to any function that
doesn't conform exactly to the default translation. 
Exactly. In my opinion, the less a compiler embeds for gluing, the more
it can binds to.

While this would
probably make it possible to drop some other attributes, reading and
writing bindings like this would be a major pain.
I am not sure which is more pain. Begging hard for vala to change as one
wishes or to write some little workaround as one wishes? I would like to
emphasis again the snippets (or cexpressions, if snippet lead to a image
of copy-pasting code) are for rare cases where 
(1) no current vala quirks can work,
(2) no way to modify the library being bound.


I don't want to have dozens of g_strv_length calls in my .vapi file if I
can fix this just once in the compiler. Also, this would require a lot
more complicated metadata for generated bindings.
There won't be dozens. I understand you wish the vapi to be all built
from vapigen. But this is impossible in a near future, right? (At least
what we have seen so far is ABI for GLib2 is unsuitable)


Maybe I'm just missing an interesting use case, however, I currently
fail to see where the snippet approach makes it more comfortable to
write or use bindings. Can you provide examples where you think that it
makes more sense to handle it in a snippet instead of the compiler code?
I'm not convinced by the g_strv_length example as this would clutter the
bindings too much, in my opinion.

Again it is for rare cases. I am thinking hard to make the snipples
working well, and I'll collect more cases later. I don't expect there to
be much though. Should it be much fewer than [NoArrayLength] stuff.

BTW: I found a way to kill the vast number static wrappers in DBus
dynamic methods. File a new bug?

Best,

Yu

Jürg






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