Archive

Author Archive

Learning how to draw

June 3rd, 2010

 I can’t draw. I’ve never been able to. Yet, for some reason, I decided to give it a serious try, buy a book to guide me in that journey (listening to an advice from pippin, yeah I know, crazy). The first step was, like a pilgrim walking to a sacred place, to go and buy some art supplies, which turned out to be a really enjoyable experience.

The first thing you have to do is a snapshot of your skills before reading more of the book to be able to do a “before/after” comparison. I thought it was quite hard, but was surprised that the result was all right, by my low standards anyway. You have to do 3 drawings: a self-portrait, looking at yourself in a mirror, a person/character drawn from memory without a visual help and your hand.

The next exercise is there to make you realize that you’ll have to forget everything you know and re-learn how to see to draw. It’s about copying drawings upside down, copying it curve by curve without associating any meaning to what you are doing. The result is quite surprising as you can see on the left. Now it’s a matter to learn how to do that without resorting to the upside down trick.

It’s only the beginning of a long journey, so many things can go wrong, but worth giving it a try!

damien drawing

Using glib.py and gobject.py GDB scripts

March 23rd, 2010

Some time ago, Alexander Larson blogged about using gdb python macros when debugging Glib and GObject projects. I’ve wanted to try those for ages, so I spent part of the week-end looking at what you could do with the new python enabled GDB, result: quite a lot of neat stuff!

Let’s start by making the script that now comes with glib work on stock gdb 7.0 and 7.1 (ie not the archer branch that contains more of the python work). If those two scripts don’t work for you yet (because your distribution is not packaging them, or is packaging a stock gdb 7.0. 7.1), here are a few hints you can follow:

  • glib’s GDB macros rely on GDB’s auto-load feature, ie, every time GDB load a library your program uses, it’ll look for a corresponding python script to execute:
open("/lib/libglib-2.0.so.0.2200.4-gdb.py", O_RDONLY)
open("/usr/lib/debug/lib/libglib-2.0.so.0.2200.4-gdb.py", O_RDONLY)
open("/usr/share/gdb/auto-load/lib/libglib-2.0.so.0.2200.4-gdb.py", O_RDONLY)

Some distributions have decided not to ship glib’s and gobject’s auto-load helpers, if you are in that case, you’d need to load gobject.py and glib.py by hand. For that purpose I’ve added a small python command in my ~/.gdbinit:

python
import os.path
import sys
import gdb

# Update module path.
dir = os.path.join(os.path.expanduser("~"), ".gdb")
if not dir in sys.path:
    sys.path.insert(0, dir)

class RegisterCommand (gdb.Command):
    """Register GLib and GObject modules"""

    def __init__ (self):
        super (RegisterCommand, self).__init__ ("gregister",
                                                gdb.COMMAND_DATA,
                                                gdb.COMPLETE_NONE)

    def invoke (self, arg, from_tty):
        objects = gdb.objfiles ()
        for object in objects:
            if object.filename.find ("libglib-2.0.so.") != -1:
                from glib import register
                register (object)
            elif object.filename.find ("libgobject-2.0.so.") != -1:
                from gobject import register
                register (object)

RegisterCommand ()
end

What I do is put glib.py and gobject.py in a ~/.gdb directory and don’t forget to call gregister inside GDB (once gdb has loaded glib and gobject)

  • The scripts that are inside glib’s repository were written with the archer branch of gdb (which bring all the python stuff). Unfortunately stock GDB (7.0 and 7.1) does not have everything the archer gdb has. I have a couple of patches to fix that in the queue. Meanwhile you can grab them in my survival kit repository. This will disable the back trace filters as they are still not in stock GDB.

You’re all set! it’s time to enjoy pretty printing and gforeach. Hopefully people will join the fun at some point and add more GDB python macro goodness both inside glib and in other projects (for instance a ClutterActor could print its name).

int main (int argc, char **argv)
{
	glist = g_list_append (glist, "first");
	glist = g_list_append (glist, "second");

	return breeeaaak_oooon_meeeee ();
}

gives:

(gdb) b breeeaaak_oooon_meeeee
Breakpoint 1 at 0x80484b7: file glib.c, line 9.
(gdb) r
Starting program: /home/damien/src/test-gdb/glib
Breakpoint 1, breeeaaak_oooon_meeeee () at glib.c:9
9        return 0;
(gdb) gregister
(gdb) gforeach s in glistp: print ((char *)$s)
No symbol "glistp" in current context.
(gdb) gforeach s in glist: print ((char *)$s)
$2 = 0x80485d0 "first"
$3 = 0x80485d6 "second"

damien GNOME

AS_AM_STFU

February 3rd, 2010

Writing m4 macro is fun, it really is.

If you want to have make be a “make -s” without doing boring stuff like aliases and actually respect the default verbosity of automake >= 1.11, use this small m4 macro I wrote.

damien cool hacks

Aligning C function parameters with vim

December 7th, 2009

updated: now saves/retores the paste register

It has bothered me for a while, some coding styles, most notably in the GNOME world try to enforce good looking alignment of functions parameters such as:

static UniqueResponse
on_unique_message_received (UniqueApp         *unique_app,
                            gint               command,
                            UniqueMessageData *message_data,
                            guint              time_,
                            gpointer           user_data)
{
}

Until now, I aligned the arguments by hand, but that time is over! Please welcome my first substantial vim plugin: it defines a GNOMEAlignArguments command to help you in that task. All you have to do is to add this file in your ~/.vim/plugin directory and define a macro in your ~/.vimrc to invoke it just like this:

" Align arguments
nmap ,a :GNOMEAlignArguments<CR>

HTH.

damien GNOME

Cogl + JS = Love

September 21st, 2009

Played a bit with Gjs and Cogl this weekend and ended up rewriting Clutter’s test-cogl-primitives in JavaScript. In the unlikely case someone is interested in trying it, you’ll need a patch to support arrays of float as argument in introspected functions and another small patch to add introspection annotations for a few Cogl symbols. As usual you can grab the code in its git repository:

cogl-primitives-js

damien Clutter

Blending two RGBA 5551 layers

June 6th, 2009

I’ve just stumbled accross a small piece of code, written one year and a half ago, that blends two 512×512 RGBA 5551 images. It was originally written for a (good!) GIS, so the piece of code blends roads with rivers (and displays the result in a GdkPixbuf). The only thing interesting is that it uses some MMX, SSE2 and rdtsc instructions. You can have a look at the code in its git repository.
screenshot-layer-fusion

damien cool hacks

shave 0.1.0

April 13th, 2009

After a month without anyone shouting at shave in despair or horror, it’s time to tag something to have a “stable” branch so people can rely on a stable interface (yes, it’s important even for a 100 lines macro!).

What’s the most amazing is that quite a few projects have adopted shave in the GNOME and freedesktop.org communities : Clutter, Niepce Digital, Giggle, GStreamer, GObject introspection, PulseAudio, ConnMan, Json-glib, libunique, gnote, seed, gnome-utils, libccss, xorg ? and maybe some more I’ve forgotten or I don’t even know about.

You can grab the tarball or clone the git repositoy (git clone git://git.lespiau.name/shave) and have a look at the README file.

Time to celebrate.

damien cool hacks

Per project .vimrc

March 18th, 2009

My natural C indentation style is basically kernel-like and my ~/.vimrc reflects that. Unfortunately I have to hack on GNUish-style projects and I really don’t want to edit my ~/.vimrc every single time I switch between different indentation styles.

Modelines are evil.

To solve that terrible issue, vim can use per directory configuration files. To enable that neat feature only two little lines are needed in your ~/.vimrc:

set exrc			" enable per-directory .vimrc files
set secure			" disable unsafe commands in local .vimrc files

Then it’s just a matter of writing a per project .vimrc like this one:

set tabstop=8
set softtabstop=2
set shiftwidth=2
set expandtab
set cinoptions=>4,n-2,{2,^-2,:0,=2,g0,h2,t0,+2,(0,u0,w1,m1

You can find help with the wonderful cinoptions variable in the Vim documentation. As sane persons open files from the project’s root directory, this works like a charm. As for the Makefiles, they are special anyway, you really should add an autocmd in your ~/.vimrc.

" add list lcs=tab:>-,trail:x for tab/trailing space visuals
autocmd BufEnter ?akefile* set noet ts=8 sw=8 nocindent

damien misc

Still some hair left

February 24th, 2009

I’ve been asked to give more input on make V=1 Vs. --disable-shave, so here it is: once again, before shipping your package with shave enabled by default, there is something crucial to understand: make V=1 (when having configured your package with --enable-shave) is NOT equivalent to no shave at all (ie --disable-shave). This is because the shave m4 macro is setting MAKEFLAGS=-s in every single Makefile. This means that make won’t print the commands as is used to, and that the only way to print something on the screen is to echo it. It’s precisely what the shave wrappers do, they echo the CC/CXX and LIBTOOL commands when V=1. So in short custom rules and a few automake commands won’t be displayed with make V=1.

That said, it’s possible to craft a rule that would display the command with shaved enabled and make V=1. The following rule:

 lib-file2.h: Makefile
        $(SHAVE_GEN)echo "#define FOO_DEFINE 0xbabe" > lib-file2.h

would become:

 lib-file2.h: Makefile
        @cmd='echo "#define FOO_DEFINE 0xbabe" > lib-file2.h'; \
        if test x"$$V" = x1; then echo $$cmd; fi
        $(SHAVE_GEN)echo "#define FOO_DEFINE 0xbabe" > lib-file2.h

which is quite ugly, to say the least. (if you find a smarter way, please enlighten me!).

On the development side, shave is slowly becoming more mature:

  • Thanks to Jan Schmidt, shave works with non GNU sed and echo that do not support -n. It now works on Solaris, hopefully on BSDs and various Unixes as well (not tested though).
  • SHAVE_INIT has a new, optional, parameter which empowers the programmer to define shave’s default behaviour (when ./configure is run without shave any related option): either enable or disable. ie. SHAVE_INIT([autootols], [enable]) will instruct shave to find its wrapper scripts in the autotools directory and that running ./configure will actually enable the beast. SHAVE_INIT without parameters at all is supposed to mean that the wrapper scripts are in $top_builddir and that ./configure will not enable shave without the --enable-shave option.
  • however, shave has been reported to fail miserably with scratchbox.

damien cool hacks

After-shave

February 23rd, 2009

A few concerns have been raised by shave, namely not being able to debug build failure in an automated environment as easily as before, or users giving  useless bug reports of failed builds.

One capital thing to realize is that, even when compiling with make V=1, everything that was not echoed was not showed (MAKEFLAGS=-s).

Thus, I’ve made a few changes:

  • Add CXX support (yes, that’s unrelated, but the question was raised, thanks to Tommi Komulainen for the initial patch),
  • add a –enable-shave option to the configure script,
  • make the Good Old Behaviour the default one,
  • as a side effect, the V and Q variables are now defined in the m4 macro, please remove them from your Makefile.am files.

The rationale for the last point can be summarized as follow:

  • the default behaviour is as portable as before (for non GNU make that is), which is not the case is shave is activated by default,
  • you can still add –enable-shave to you autogen.sh script, bootstraping your project from a SCM will enable shave and that’s cool!
  • don’t break tools that were relying on automake’s output.

Grab the latest version! (git://git.lespiau.name/shave)

damien cool hacks