This is a difficult language bindings question mostly for the experts Droege and Bassi.
For the “heavy” entities like Widgets, other GObject based objects or structs like GChecksum we are using proxy objects in Nim. For the gobject based ones we use the toggle-ref stuff, others are processed as gtk-boxed types. All that seems to work fine with automatic memory handling.
But then there are the simple structs like GCond, GMutex, Rectangle, TextIter and many more which are generally allocated on the stack in C code. These types need no special initialization, filling with plain binary zero is sufficient. For these types we do not really need proxy objects in Nim. Nim can allocate them on the stack in the same way as C can, so no need for advanced memory management. And even when these types are embedded in Nim’s objects it works the same, no proxy needed.
All fine, but how can we differ these two classes by querying gobject-introspection?
Currently we have a list of the light stack allocated objects, see below. Works OK, but I recently noticed that GCond and GMutex was missing, which resulted in the fact that simple translating a C code example to Nim did not work out of the box. I added both to the list, regenerated bindings and it was working.
So the question is how I can find the light stack allocated objects automatically? Well, for the heavy symbols there may exist generator functions like gtk_button_new() which may not exist for the light entities. But is that a good way to differentiate the two classes, or is there a better way?
const callerAlloc: HashSet[string] = """ gobject.Value gobject.ValueDataUnion atk.Rectangle pango.Color gtk.PageRange gdk.KeymapKey glib.Error glib.MarkupParser glib.TimeVal gtk.TextIter gdk.Rectangle gobject.SignalQuery gobject.TypeQuery gtk.TreeIter gtk.StockItem glib.String rsvg.PositionData rsvg.DimensionData gdk.Color gdk.Geometry gtk.Border atk.TextRectangle gdk.RGBA pango.Rectangle gtk.Requisition graphene.Size graphene.Point graphene.Point3D graphene.Rect graphene.Box graphene.Sphere graphene.Vec2 graphene.Vec3 graphene.Vec4 graphene.Quaternion graphene.Quad graphene.Matrix graphene.Plane graphene.Ray graphene.Euler #cairo.Matrix cairo.Rectangle cairo.RectangleInt gsk.RoundedRect glib.Mutex # we should try to detect these stack based types automatically! glib.Cond """.split.toHashSet