Re: g_object_add_toggle_ref
On Sun, 2017-06-25 at 10:59 +0100, Emmanuele Bassi wrote: > I very much doubt anybody here has knowledge of toggle reference and > language bindings. Yes, I guess that is true, the original authors seems all to be retired. For IRC or devel list, I fear situation is not really better, and I do not really want to make noise there, the few remaining developers may have to do more important stuff. > All GC language bindings will immediately sink the floating reference, > as it makes memory management harder for them (it's a C feature, after > all). So my suggestion is to immediately and automatically sink the > floating reference inside your wrapper around g_object_new() before it > returns the instance to the non-C side. That is an interesting hint. Indeed I did that in my first draft about a year ago, before I discovered g_object_add_toggle_ref() function. Of course it makes sense to use it in combination. At least basically my Nim wrapper is working already -- maybe for details I will have to look at wrappers for other languages. Maybe I should consider contacting the Rust developers, as Rust is also a compiled language, and they have some GTK bindings. ___ gtk-list mailing list gtk-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-list
Re: g_object_add_toggle_ref
On Sat, 2017-06-03 at 15:37 +0200, Stefan Salewski wrote: What is a bit strange is void g_object_add_toggle_ref (GObject *object, GToggleNotify notify, gpointer data) { ToggleRefStack *tstack; guint i; g_return_if_fail (G_IS_OBJECT (object)); g_return_if_fail (notify != NULL); g_return_if_fail (object->ref_count >= 1); g_object_ref (object); So after a call of g_object_add_toggle_ref() ref_count of an object is always greater or equal to two? But how can now that value drop ever again below 2? When a new references is added, it increases, and when that references is removed, the value is decreased. But never below 2 this way? It is a bit confusing indeed. More confusing is, that g_object_ref_sink () seems to exist since gobject release 2.10, while g_object_add_toggle_ref () seems to exists already since 2.8. And, for my understanding of English wording, the documentation of g_object_ref_sink() contradicts even itself: https://developer.gnome.org/gobject/stable/gobject-The-Base-Object-Type .html#g-object-ref-sink "Increase the reference count of object , and possibly remove the floating reference, if object has a floating reference. In other words, if the object is floating, then this call "assumes ownership" of the floating reference, converting it to a normal reference by clearing the floating flag while leaving the reference count unchanged. If the object is not floating, then this call adds a new normal reference increasing the reference count by one." I assume, that the second part is correct. Maybe the first sentence should be something like "Increase the reference count of object , OR possibly" So it will be not that easy to get fully working Garbage Collector support. ___ gtk-list mailing list gtk-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-list
g_object_add_toggle_ref
My high level Nim wrapper (https://github.com/StefanSalewski/nim-gi2) is indeed basically working. Currently I am using g_object_add_toggle_ref() and g_object_set_qdata(). The first for the garbage collection tasks, and the later for retrieving the proxy object from the associated GTK GObject, for example when functions like gtk_widget_get_parent() are used. That seems to work, but I have the feeling of some redundancy. Both gobject functions are passed the address of my proxy object. But g_object_add_toggle_ref() seems to offer no support to get the address back, that is why I use additional g_object_set_qdata() which allows me to get back the proxy address with g_object_get_qdata(). proc gtk_button_new*(): ptr Button00 {. importc: "gtk_button_new", libprag.} proc newButton*(): Button = new(result, finalizeGObject) result.impl = gtk_button_new() GC_ref(result) g_object_add_toggle_ref(result.impl, toggleNotify, addr(result[])) assert(g_object_get_qdata(result.impl, Quark) == nil) g_object_set_qdata(result.impl, Quark, addr(result[])) ___ gtk-list mailing list gtk-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-list