mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-27 07:56:14 +01:00
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:
parent
68304ae583
commit
7c4ac58938
@ -307,15 +307,7 @@ gpointer
|
|||||||
void
|
void
|
||||||
g_atomic_rc_box_release (gpointer mem_block)
|
g_atomic_rc_box_release (gpointer mem_block)
|
||||||
{
|
{
|
||||||
GArcBox *real_box = G_ARC_BOX (mem_block);
|
g_atomic_rc_box_release_full (mem_block, NULL);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -338,14 +330,14 @@ g_atomic_rc_box_release_full (gpointer mem_block,
|
|||||||
GArcBox *real_box = G_ARC_BOX (mem_block);
|
GArcBox *real_box = G_ARC_BOX (mem_block);
|
||||||
|
|
||||||
g_return_if_fail (mem_block != NULL);
|
g_return_if_fail (mem_block != NULL);
|
||||||
g_return_if_fail (clear_func != NULL);
|
|
||||||
#ifndef G_DISABLE_ASSERT
|
#ifndef G_DISABLE_ASSERT
|
||||||
g_return_if_fail (real_box->magic == G_BOX_MAGIC);
|
g_return_if_fail (real_box->magic == G_BOX_MAGIC);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (g_atomic_ref_count_dec (&real_box->ref_count))
|
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);
|
g_free (real_box);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -377,15 +377,7 @@ gpointer
|
|||||||
void
|
void
|
||||||
g_rc_box_release (gpointer mem_block)
|
g_rc_box_release (gpointer mem_block)
|
||||||
{
|
{
|
||||||
GRcBox *real_box = G_RC_BOX (mem_block);
|
g_rc_box_release_full (mem_block, NULL);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -408,14 +400,14 @@ g_rc_box_release_full (gpointer mem_block,
|
|||||||
GRcBox *real_box = G_RC_BOX (mem_block);
|
GRcBox *real_box = G_RC_BOX (mem_block);
|
||||||
|
|
||||||
g_return_if_fail (mem_block != NULL);
|
g_return_if_fail (mem_block != NULL);
|
||||||
g_return_if_fail (clear_func != NULL);
|
|
||||||
#ifndef G_DISABLE_ASSERT
|
#ifndef G_DISABLE_ASSERT
|
||||||
g_return_if_fail (real_box->magic == G_BOX_MAGIC);
|
g_return_if_fail (real_box->magic == G_BOX_MAGIC);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (g_ref_count_dec (&real_box->ref_count))
|
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);
|
g_free (real_box);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user