Re: storing iterators in GValue



On Thu, 2008-01-03 at 10:15 +0100, ole nielsby pils org wrote:
> My language binding needs to be able to deal with text and tree
> iterators.

> How does ... other languages deal with these beasts?

They are indeed best treated as GBoxeds.

++

It took me a long time to figure out just what the heck was going on
with GtkTreeIters and GValues for that matter. It turns out that in C
the API is blindingly simple to use in this regard: one stack allocates
a local variable and then passes it in by reference. Ta da.

Language binding these, however, makes a big mess. We have to create and
register a Proxy object (which is both the alloc'd struct C side and a
full Object Java side pointing at it) which all involves several round
trips... just to create a throw away boxed struct. And then worse: since
it was alloc'd and not stack, we have to wait WAY longer before it gets
cleaned up (relative to it being discarded on function return.

In most cases there's not much I can do about this. The occasional hand
coded override gets around this, but by in large you need them a few
times in a row in GTK terms, and, well, that's that. Oh well.

Interesting case study in the API design impact of making a C library
bindable by other languages, though. One of the rare cases I've come
across where the C code is more straight forward than the higher level
language. I rather suspect that if things like GtkTreeIter and GValue
hadn't predated language bindings the whole concept might have been done
differently. Something to mull over for the future.

AfC
Hobart

Attachment: signature.asc
Description: This is a digitally signed message part



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