Function Macro


Declaration [src]

#define g_set_weak_pointer (

Description [src]

Updates a pointer to weakly refer to new_object.

It assigns new_object to weak_pointer_location and ensures that weak_pointer_location will automatically be set to NULL if new_object gets destroyed. The assignment is not atomic. The weak reference is not thread-safe, see g_object_add_weak_pointer() for details.

The weak_pointer_location argument must not be NULL.

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:

  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_weak_pointer (&foo->bar, new_bar))
      g_object_notify (foo, "bar");
Available since:2.56


weak_pointer_location -

The memory address of a pointer.

new_object -

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