And life gets a little better

You know the feeling. You’re happily sitting there, coding away at some graphics or other code in C+GObject, and then comes the point where you need to add a signal to your object. But your object doesn’t have any signals yet, so you have to go find and copy the boilerplate. Ok, not a big deal, you say to yourself, it only takes a minute or two. Then you notice your signal takes multiple parameters, and thus you need to generate a marshaler.

At that point you go to add one to your foo-marshal.list file, only to realize you don’t have one yet! Now you need to copy a chunk Automake boilerplate, and apparently if you want to do it really correctly it involves three times as much boilerplate involving stamp files and other monsters.

It’s around this point you’re probably thinking that finding medieval torture devices and using them on yourself on live television would be a less painful remunerative occupation than programming. But there is hope – the awesome jdahlin wrote a patch. The problem – it’s not in GLib yet, and it’s unclear when it will be.

So maybe you don’t buy into the the pitch about polyglot applications yet, but the new GObject Introspection release, because it already depends on libffi, contains a slightly tweaked version of jdahlin’s patch, known as gi_cclosure_marshal_generic. Depend on introspection, and never deal with marshalers and other torture devices again!

From Here To There

From Here To There is a quick introductory tutorial for people interested in building multi-level applications using the GObject stack, and having your own application be split between C and your choice of runtime. This tutorial uses Clutter and JavaScript, as we’re using for gnome-shell.

I’ve been working for a while now on two applications using the system (gnome-shell, and a personal project not yet ready for announcement), and while there is still a fair bit more introspection system work to do, so far I’m pretty happy with how it’s worked out for both projects. My personal project is actually a mashup of C for some graphics and system stuff, Java (JGIR) for the core application logic, and Groovy for some scripting and extensions. It’s quite polyglot; I’m practicing what I preach.

Tomorrow

While traveling post-GUADEC in Turkey, I ended up after dinner one night walking next to a man speaking English to his wife, and like most people in a foreign country I was interested to talk to someone of similar culture. It turned out though he was Iranian, now living in Dubai with his American wife. He was a very intelligent person, a businessman of some sort and we had a discussion about world affairs as we walked back to our respective hotels.

He obviously had a broad world view and experience, so it was a good conversation. Of course the presidental run came up, and when I mentioned I supported Obama, he shook his head and I remember he said to me confidently and with some cynicism, “John McCain will be your next president”. I had felt so sure that America would warm to this eloquent, charismatic scholar of constitutional law, but at that moment I experienced some lingering doubt which stayed for a week at least.

Not that he’s likely to be reading this blog, but I’d just like to say – told you so!

Today

A rare nontechnical blog entry from me today; I have had some technical ones queued up in the back of my mind for a bit, but it was hard to spend today thinking about technology. Or, at least other than as a delivery mechanism for election results.

Before Obama decided to run for president, I read an article about possible presidential contenders which included him. The article linked to this YouTube video of Obama. I was struck by his charisma and, doing a bit more research, his extraordinary intelligence and hopeful message. This guy didn’t get into an ivy league school via the old boy network like Bush did. I decided within that hour that if he did run, I would contribute to his campaign, the first time I’d ever really done anything approaching active participation in politics beyond voting.

I have a feeling that’s true for a lot of Americans right now. Anyways, I planned to keep this blog short. I just had to write something though – it’s an immensely inspiring day today.

finding algorithms

Dear lazyweb, I recently found myself having a set of Unicode strings (in main memory) and the desire to search all of them for a particular prefix (not substring). For bonus points, let’s say I want to do it in parallel (seems like an easily parallelizable problem, although at worst you can divide-and-conquer for a given number N of processors). The constraints are that the set of strings can change, but not very often usually. I don’t want too large of a hit to compute tables and the like though.

The real question is – how do you find papers (and implementations thereof) for computer science problems like this? My first instinct was to get an ACM subscription, which I did. Their search turns out to be mediocre, and then I discovered Wikipedia has useful pages on these kinds of things. Wikipedia also has the winning feature of linking to quality free software implementations thereof.

On this particular problem, a lot of the literature is around substring matching which isn’t what I want, at least not directly. Still looking.

Dear GObject/C library authors

Get ready – it’s coming. At the GNOME Summit this weekend we’re having a hackfest on introspection. As a programmer working on a GObject library, here’s what you need to understand:

Using gtk-doc annotations

Just parsing the C code isn’t enough – we sometimes need additional metadata. Here’s an example:

/**
* gtk_list_store_set_column_types: 
* @store: a #GtkListStore
* @n_columns:
* @types: <array,length=n_columns>: List of types
*/
void
gtk_list_store_set_column_types (GtkListStore *list_store,
gint          n_columns,
GType        *types);

There are more examples here. This syntax hasn’t really seen much bikeshedding yet, and to be honest it’s grown rather organically. So things could change. But the goal is for the annotations to be concise, fit in with gtk-doc, and support a variety of attributes; we don’t want to require a totally different IDL format.

Add your library to gir-repository and check it

The current thought on deploying introspection is to have two phases. In the first “unstable” phase, we will also have two separate modules: gobject-introspection and gir-repository. It’s unclear yet whether the former will remain separate from glib or not in the long term, but expect it to exist separately for now. For gir-repository, the long term plan is to integrate everything into the relevant modules themselves, but for the next 6 months or so while we’re finalizing bits, we will keep annotations and code to invoke the scanner inside this centralized module.

So for now, you can add your library (if it isn’t there already) to gir-repository by filing a patch in Bugzilla (glib/introspection), or pastebin on irc.gimp.org:#introspection. After you have your library successfully parsed by the scanner, the first task is to inspect the generated .gir file. This XML file describes the parsed API. Try searching in particular for any APIs you think are tricky.

Try out your library in a binding

After inspecting the .gir file, you can try out your API from one of the bindings such as PyBank or JGIR, with more coming. We expect to do some PyBank hacking in particular at the summit, and hopefully get the Spidermonkey and Mono bindings further along. There is a lot to do for all the bindings, but I hope that introspection can be a strong focus point for collaboration between the bindings.

Writing bindable APIs

I’ve started a wiki page about how you can keep your C code easily bindable. More content appreciated! This page will likely be a bit fluid as we determine both what is supported in the introspection core, and how its concepts map to languages.

That’s it for now – remember if you’re in the Boston to come to the summit!