Fixes in cl-gtk2-gobject memory managment

September 7, 2009

I’ve been debugging and fixing several bugs related to memory management of cl-gtk2.
There were two main bugs that required fixing:

Object denaturation. Object denaturation means that we pass a reference to an object of some type derived from GObject type but then we receive object of some other base type. E.g., we create a custom-window deriving from gtk-window with some fields containing application data. And if there are no references to custom-window and we receive a pointer to corresponding object, we receive it as a gtk-window, not custom-window.
GObject’s toggle references are designed exactly to avoid this problem in language bindings. Toggle references let the binding know when the “foreign” side has no more references to an object (and this means that we will now never receive pointer to this object) and when the “foreign” side has some references (and may potentially pass object back to us).

References leak. There were cases when references were leaked: the cl-gtk2-gobject increased the objects’ refcount more than it should. Several generic cases of it have been fixed (references were increased twice when receiving the pointer from foreign code for the first time; functions that return already g_object_ref’ed objects).

Simplification of creation of GObject instances and instances of lisp-implemented GObject classes.