mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01: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:
parent
5423bf4df7
commit
9debaffe0e
@ -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))
|
||||
|
@ -65,10 +65,10 @@ GI_AVAILABLE_IN_ALL
|
||||
GType gi_base_info_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GI_AVAILABLE_IN_ALL
|
||||
GIBaseInfo * gi_base_info_ref (GIBaseInfo *info);
|
||||
GIBaseInfo * gi_base_info_ref (void *info);
|
||||
|
||||
GI_AVAILABLE_IN_ALL
|
||||
void gi_base_info_unref (GIBaseInfo *info);
|
||||
void gi_base_info_unref (void *info);
|
||||
|
||||
GI_AVAILABLE_IN_ALL
|
||||
GIInfoType gi_base_info_get_info_type (GIBaseInfo *info);
|
||||
|
@ -116,16 +116,16 @@ test_repository_info (void)
|
||||
g_assert_nonnull (method_info);
|
||||
g_assert_true (gi_callable_info_is_method ((GICallableInfo *) method_info));
|
||||
g_assert_cmpuint (gi_callable_info_get_n_args ((GICallableInfo *) method_info), ==, 2);
|
||||
g_clear_pointer ((GIBaseInfo **) &method_info, gi_base_info_unref);
|
||||
g_clear_pointer (&method_info, gi_base_info_unref);
|
||||
|
||||
method_info = gi_object_info_get_method (object_info,
|
||||
gi_object_info_get_n_methods (object_info) - 1);
|
||||
g_assert_true (gi_callable_info_is_method ((GICallableInfo *) method_info));
|
||||
g_assert_cmpuint (gi_callable_info_get_n_args ((GICallableInfo *) method_info), >, 0);
|
||||
g_clear_pointer ((GIBaseInfo **) &method_info, gi_base_info_unref);
|
||||
g_clear_pointer (&method_info, gi_base_info_unref);
|
||||
|
||||
gi_base_info_unref ((GIBaseInfo *) signal_info);
|
||||
gi_base_info_unref ((GIBaseInfo *) object_info);
|
||||
gi_base_info_unref (signal_info);
|
||||
gi_base_info_unref (object_info);
|
||||
g_clear_object (&repository);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user