On 21-01-2019 22:47, yes9111 wrote:
Noob to Gtk programming in general so please bear with me. I'm trying to write D bindings for the VIPS library which uses the gobject library internally.
Since libvips uses/supports goject introspection you could use gir-to-d
to generate the binding:
girtod -i /usr/share/gir-1.0/Vips-8.0.gir
This will generate a libvips binding that depends on GlibD or GtkD (in
the future GtkD will depend on GlibD but that still a work in progress).
I wanted to subclass ObjectG for objects specific to the library, but I couldn't quite figure out when to pass in
true for ObjectG class's constructor (the
ownedRef parameter). Am I correct in guessing that we're supposed to pass in
true when the gobject already has a linked ObjectG object to it?
ObjectG does the reference counting for you, with GTK some functions
will pass the ownership of the Object to the caller, so you don't have
to ref the object yourself. In these cases you would pass true to
ObjectG to tell it to not add an extra reference to the object.
One of those cases is
since it's annotated with
transfer full in the documentation.
Another question is if I am having the GObject generated by a third party and I am responsible for unreffing it, do I have to unref it myself or does the ObjectG class handle everything? It looks like the ObjectG class increments the refCount by 2 already, so I'm guessing I have to unref the GObject manually.
Thanks in advance!
Unless there is a bug somewhere you shouldn't have to unref the object
ObjectG will add a
toggle reference to the object, and if we already
owned the object (ownedRef = true) it will remove the regular reference.
So it should 1 or 0 references in the constructor, and it will remove 1
reference in the destructor.