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.
This commit is contained in:
Emmanuele Bassi 2018-07-03 15:46:11 +01:00
parent 68304ae583
commit 7c4ac58938
2 changed files with 6 additions and 22 deletions

View File

@ -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);
}
}

View File

@ -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);
}
}