Function Macro

GObjectset_weak_pointer

since: 2.56

Declaration

#define g_set_weak_pointer (
  weak_pointer_location,
  new_object
)

Description

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:

  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_weak_pointer (&foo->bar, new_bar))
      g_object_notify (foo, "bar");
  }

Available since: 2.56

This function is not directly available to language bindings.

Parameters

weak_pointer_location

Type: -

The memory address of a pointer.

new_object

Type: -

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