mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-09-28 01:57:14 +02:00
Make g_set_object more symmetric
As argued in bug 748633, and order of ref, assign, unref is preferable.
This commit is contained in:
@@ -690,21 +690,25 @@ static inline gboolean
|
|||||||
(g_set_object) (GObject **object_ptr,
|
(g_set_object) (GObject **object_ptr,
|
||||||
GObject *new_object)
|
GObject *new_object)
|
||||||
{
|
{
|
||||||
|
GObject *old_object = *object_ptr;
|
||||||
|
|
||||||
/* rely on g_object_[un]ref() to check the pointers are actually GObjects;
|
/* rely on g_object_[un]ref() to check the pointers are actually GObjects;
|
||||||
* elide a (object_ptr != NULL) check because most of the time we will be
|
* elide a (object_ptr != NULL) check because most of the time we will be
|
||||||
* operating on struct members with a constant offset, so a NULL check would
|
* operating on struct members with a constant offset, so a NULL check would
|
||||||
* not catch bugs */
|
* not catch bugs
|
||||||
|
*/
|
||||||
|
|
||||||
if (*object_ptr == new_object)
|
if (old_object == new_object)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (new_object != NULL)
|
if (new_object != NULL)
|
||||||
g_object_ref (new_object);
|
g_object_ref (new_object);
|
||||||
if (*object_ptr != NULL)
|
|
||||||
g_object_unref (*object_ptr);
|
|
||||||
|
|
||||||
*object_ptr = new_object;
|
*object_ptr = new_object;
|
||||||
|
|
||||||
|
if (old_object != NULL)
|
||||||
|
g_object_unref (old_object);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user