mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-01 15:03:39 +02:00
gibaseinfo: Remove need for casting for gi_base_info_ref() and unref()
Just like is done with `g_object_{ref,unref}()`, make these functions take a `void*` rather than a `GIBaseInfo*`, since they’ll most likely be called with a type which is derived from `GIBaseInfo*` rather than a `GIBaseInfo*` itself. Add some runtime type checks to make up for lowering the compile time type safety. Signed-off-by: Philip Withnall <pwithnall@gnome.org> Helps: #3216
This commit is contained in:
@@ -517,7 +517,7 @@ gi_type_info_init (GIBaseInfo *info,
|
||||
|
||||
/**
|
||||
* gi_base_info_ref:
|
||||
* @info: a #GIBaseInfo
|
||||
* @info: (type GIRepository.BaseInfo): a #GIBaseInfo
|
||||
*
|
||||
* Increases the reference count of @info.
|
||||
*
|
||||
@@ -525,10 +525,12 @@ gi_type_info_init (GIBaseInfo *info,
|
||||
* Since: 2.80
|
||||
*/
|
||||
GIBaseInfo *
|
||||
gi_base_info_ref (GIBaseInfo *info)
|
||||
gi_base_info_ref (void *info)
|
||||
{
|
||||
GIRealInfo *rinfo = (GIRealInfo*)info;
|
||||
|
||||
g_return_val_if_fail (GI_IS_BASE_INFO (info), NULL);
|
||||
|
||||
g_assert (rinfo->ref_count != INVALID_REFCOUNT);
|
||||
g_atomic_ref_count_inc (&rinfo->ref_count);
|
||||
|
||||
@@ -537,7 +539,7 @@ gi_base_info_ref (GIBaseInfo *info)
|
||||
|
||||
/**
|
||||
* gi_base_info_unref:
|
||||
* @info: (transfer full): a #GIBaseInfo
|
||||
* @info: (type GIRepository.BaseInfo) (transfer full): a #GIBaseInfo
|
||||
*
|
||||
* Decreases the reference count of @info. When its reference count
|
||||
* drops to 0, the info is freed.
|
||||
@@ -545,10 +547,12 @@ gi_base_info_ref (GIBaseInfo *info)
|
||||
* Since: 2.80
|
||||
*/
|
||||
void
|
||||
gi_base_info_unref (GIBaseInfo *info)
|
||||
gi_base_info_unref (void *info)
|
||||
{
|
||||
GIRealInfo *rinfo = (GIRealInfo*)info;
|
||||
|
||||
g_return_if_fail (GI_IS_BASE_INFO (info));
|
||||
|
||||
g_assert (rinfo->ref_count > 0 && rinfo->ref_count != INVALID_REFCOUNT);
|
||||
|
||||
if (g_atomic_ref_count_dec (&rinfo->ref_count))
|
||||
|
Reference in New Issue
Block a user