diff options
author | Emmanuele Bassi <ebassi@gnome.org> | 2018-07-03 15:46:11 +0100 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gnome.org> | 2018-07-09 10:11:42 +0100 |
commit | 7c4ac58938187a431db0651e383dda6e098cff07 (patch) | |
tree | 7b09808219df3b0697a8a9f7920559a43b040208 /glib | |
parent | 68304ae583b7f633742420a0fa014accc8eec379 (diff) | |
download | glib-7c4ac58938187a431db0651e383dda6e098cff07.tar.gz |
Allow NULL clear function when releasing references
Both g_rc_box_release_full() and g_atomic_rc_box_release_full() should
allow passing NULL as the clear function, to conform to the existing
coding practices in GLib.
Additionally, this allows us to reimplement release() in terms of
release_full(), and improve test coverage.
Diffstat (limited to 'glib')
-rw-r--r-- | glib/garcbox.c | 14 | ||||
-rw-r--r-- | glib/grcbox.c | 14 |
2 files changed, 6 insertions, 22 deletions
diff --git a/glib/garcbox.c b/glib/garcbox.c index b423248da..4182e986e 100644 --- a/glib/garcbox.c +++ b/glib/garcbox.c @@ -307,15 +307,7 @@ gpointer void g_atomic_rc_box_release (gpointer mem_block) { - GArcBox *real_box = G_ARC_BOX (mem_block); - - g_return_if_fail (mem_block != NULL); -#ifndef G_DISABLE_ASSERT - g_return_if_fail (real_box->magic == G_BOX_MAGIC); -#endif - - if (g_atomic_ref_count_dec (&real_box->ref_count)) - g_free (real_box); + g_atomic_rc_box_release_full (mem_block, NULL); } /** @@ -338,14 +330,14 @@ g_atomic_rc_box_release_full (gpointer mem_block, GArcBox *real_box = G_ARC_BOX (mem_block); g_return_if_fail (mem_block != NULL); - g_return_if_fail (clear_func != NULL); #ifndef G_DISABLE_ASSERT g_return_if_fail (real_box->magic == G_BOX_MAGIC); #endif if (g_atomic_ref_count_dec (&real_box->ref_count)) { - clear_func (mem_block); + if (clear_func != NULL) + clear_func (mem_block); g_free (real_box); } } diff --git a/glib/grcbox.c b/glib/grcbox.c index 16ff06d2f..5a4d87424 100644 --- a/glib/grcbox.c +++ b/glib/grcbox.c @@ -377,15 +377,7 @@ gpointer void g_rc_box_release (gpointer mem_block) { - GRcBox *real_box = G_RC_BOX (mem_block); - - g_return_if_fail (mem_block != NULL); -#ifndef G_DISABLE_ASSERT - g_return_if_fail (real_box->magic == G_BOX_MAGIC); -#endif - - if (g_ref_count_dec (&real_box->ref_count)) - g_free (real_box); + g_rc_box_release_full (mem_block, NULL); } /** @@ -408,14 +400,14 @@ g_rc_box_release_full (gpointer mem_block, GRcBox *real_box = G_RC_BOX (mem_block); g_return_if_fail (mem_block != NULL); - g_return_if_fail (clear_func != NULL); #ifndef G_DISABLE_ASSERT g_return_if_fail (real_box->magic == G_BOX_MAGIC); #endif if (g_ref_count_dec (&real_box->ref_count)) { - clear_func (mem_block); + if (clear_func != NULL) + clear_func (mem_block); g_free (real_box); } } |