Function Macro

GObjectset_object

since: 2.44

Declaration [src]

#define g_set_object (
  object_ptr,
  new_object
)

Description [src]

Updates a GObject pointer to refer to new_object.

It increments the reference count of new_object (if non-NULL), decrements the reference count of the current value of object_ptr (if non-NULL), and assigns new_object to object_ptr. The assignment is not atomic.

object_ptr must not be NULL, but can point to a NULL value.

A macro is also included that allows this function to be used without pointer casts. The function itself is static inline, so its address may vary between compilation units.

One convenient usage of this function is in implementing property setters:

  void
  foo_set_bar (Foo *foo,
               Bar *new_bar)
  {
    g_return_if_fail (IS_FOO (foo));
    g_return_if_fail (new_bar == NULL || IS_BAR (new_bar));

    if (g_set_object (&foo->bar, new_bar))
      g_object_notify (foo, "bar");
  }

Available since: 2.44

This function is not directly available to language bindings.

Parameters

object_ptr

Type: -

A pointer to a GObject reference.

new_object

Type: -

A pointer to the new GObject to assign to object_ptr, or NULL to clear the pointer.