g_clear_signal_handler() in GLib 2.61.1

It’s been a long time since I’ve blogged, so I thought I’d do a quick series on new APIs in the upcoming 2.62 release series of GLib.

Today, it’s the g_clear_signal_handler() function added by Marco Trevisan. This is a simple helper function along the same lines as g_clear_pointer(), g_clear_error() and g_clear_handle_id(). Given a GObject and a signal handler ID, it disconnects the signal handler and clears the signal handler ID variable to zero.

This turns the following standard pattern of code:

if (obj != NULL && handler_id != 0)
  {
    g_signal_handler_disconnect (obj, handler_id);
    handler_id = 0;
  }

to this:

g_clear_signal_handler (&handler_id, obj);

Nothing earth-shattering, but it does allow code to become a little more compact.

5 thoughts on “g_clear_signal_handler() in GLib 2.61.1

  1. Pingback: g_queue_insert_before_link() in GLib 2.61.1 | drboblog

  2. Pingback: Array copying and extending in GLib 2.61.2 | drboblog

  3. Pingback: g_array_binary_search in GLib 2.61.2 | drboblog

  4. Pingback: g_assert_finalize_object() in GLib 2.61.2 | drboblog

Leave a Reply to Marco Trevisan Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.