gobject: Add g_set_object() convenience function to set GObject pointers
authorPhilip Withnall <philip.withnall@collabora.co.uk>
Tue, 16 Dec 2014 11:29:03 +0000 (11:29 +0000)
committerPhilip Withnall <philip.withnall@collabora.co.uk>
Thu, 18 Dec 2014 11:32:56 +0000 (11:32 +0000)
commitd951db4236146efd8f4f343740d50433739526c8
treeded6b1370cfb1f86bcba20c91a66d3475bcf7254
parent4f3ab40c042d8c53e8540188a7508e91301baa41
gobject: Add g_set_object() convenience function to set GObject pointers

Along the same lines as g_clear_object(), g_set_object() is a
convenience function to update a GObject pointer, handling reference
counting transparently and correctly.

Specifically, it handles the case where a pointer is set to its current
value. If handled naïvely, that could result in the object instance
being finalised. In the following code, that happens when
(my_obj == new_value) and the object has a single reference:
    g_clear_object (&my_obj);
    my_obj = g_object_ref (new_value);

It also simplifies boilerplate code such as set_property()
implementations, which are otherwise long and boring.

Test cases included.

https://bugzilla.gnome.org/show_bug.cgi?id=741589
docs/reference/gobject/gobject-sections.txt
gobject/gobject.h
gobject/tests/reference.c