girepository: Add type-checking cast macros

These follow GObject conventions, using `G_TYPE_CHECK_INSTANCE_CAST` to
cast to the given type, and potentially performing some runtime checks
of the type instance’s `GType` too.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Fixes: #3216
This commit is contained in:
Philip Withnall 2024-01-17 16:40:18 +00:00
parent 9debaffe0e
commit 57d64b111f
21 changed files with 294 additions and 0 deletions

View File

@ -34,6 +34,20 @@ G_BEGIN_DECLS
#define GI_TYPE_ARG_INFO (gi_arg_info_get_type ())
/**
* GI_ARG_INFO:
* @info: Info object which is subject to casting.
*
* Casts a [type@GIRepository.ArgInfo] or derived pointer into a
* `(GIArgInfo*)` pointer.
*
* Depending on the current debugging level, this function may invoke
* certain runtime checks to identify invalid casts.
*
* Since: 2.80
*/
#define GI_ARG_INFO(info) (G_TYPE_CHECK_INSTANCE_CAST ((info), GI_TYPE_ARG_INFO, GIArgInfo))
/**
* GI_IS_ARG_INFO:
* @info: an info structure

View File

@ -50,6 +50,20 @@ typedef struct {
#define GI_TYPE_BASE_INFO (gi_base_info_get_type ())
/**
* GI_BASE_INFO:
* @info: Info object which is subject to casting.
*
* Casts a [type@GIRepository.BaseInfo] or derived pointer into a
* `(GIBaseInfo*)` pointer.
*
* Depending on the current debugging level, this function may invoke
* certain runtime checks to identify invalid casts.
*
* Since: 2.80
*/
#define GI_BASE_INFO(info) (G_TYPE_CHECK_INSTANCE_CAST ((info), GI_TYPE_BASE_INFO, GIBaseInfo))
/**
* GI_IS_BASE_INFO:
* @info: Instance to check for being a `GI_TYPE_BASE_INFO`.

View File

@ -33,6 +33,20 @@ G_BEGIN_DECLS
#define GI_TYPE_BOXED_INFO (gi_boxed_info_get_type ())
/**
* GI_BOXED_INFO:
* @info: Info object which is subject to casting.
*
* Casts a [type@GIRepository.BoxedInfo] or derived pointer into a
* `(GIBoxedInfo*)` pointer.
*
* Depending on the current debugging level, this function may invoke
* certain runtime checks to identify invalid casts.
*
* Since: 2.80
*/
#define GI_BOXED_INFO(info) (G_TYPE_CHECK_INSTANCE_CAST ((info), GI_TYPE_BOXED_INFO, GIBoxedInfo))
/**
* GI_IS_BOXED_INFO:
* @info: an info structure

View File

@ -34,6 +34,20 @@ G_BEGIN_DECLS
#define GI_TYPE_CALLABLE_INFO (gi_callable_info_get_type ())
/**
* GI_CALLABLE_INFO:
* @info: Info object which is subject to casting.
*
* Casts a [type@GIRepository.CallableInfo] or derived pointer into a
* `(GICallableInfo*)` pointer.
*
* Depending on the current debugging level, this function may invoke
* certain runtime checks to identify invalid casts.
*
* Since: 2.80
*/
#define GI_CALLABLE_INFO(info) (G_TYPE_CHECK_INSTANCE_CAST ((info), GI_TYPE_CALLABLE_INFO, GICallableInfo))
/**
* GI_IS_CALLABLE_INFO:
* @info: an info structure

View File

@ -33,6 +33,20 @@ G_BEGIN_DECLS
#define GI_TYPE_CALLBACK_INFO (gi_callback_info_get_type ())
/**
* GI_CALLBACK_INFO:
* @info: Info object which is subject to casting.
*
* Casts a [type@GIRepository.CallbackInfo] or derived pointer into a
* `(GICallbackInfo*)` pointer.
*
* Depending on the current debugging level, this function may invoke
* certain runtime checks to identify invalid casts.
*
* Since: 2.80
*/
#define GI_CALLBACK_INFO(info) (G_TYPE_CHECK_INSTANCE_CAST ((info), GI_TYPE_CALLBACK_INFO, GICallbackInfo))
/**
* GI_IS_CALLBACK_INFO:
* @info: an info structure

View File

@ -34,6 +34,20 @@ G_BEGIN_DECLS
#define GI_TYPE_CONSTANT_INFO (gi_constant_info_get_type ())
/**
* GI_CONSTANT_INFO:
* @info: Info object which is subject to casting.
*
* Casts a [type@GIRepository.ConstantInfo] or derived pointer into a
* `(GIConstantInfo*)` pointer.
*
* Depending on the current debugging level, this function may invoke
* certain runtime checks to identify invalid casts.
*
* Since: 2.80
*/
#define GI_CONSTANT_INFO(info) (G_TYPE_CHECK_INSTANCE_CAST ((info), GI_TYPE_CONSTANT_INFO, GIConstantInfo))
/**
* GI_IS_CONSTANT_INFO:
* @info: an info structure

View File

@ -34,6 +34,20 @@ G_BEGIN_DECLS
#define GI_TYPE_ENUM_INFO (gi_enum_info_get_type ())
/**
* GI_ENUM_INFO:
* @info: Info object which is subject to casting.
*
* Casts a [type@GIRepository.EnumInfo] or derived pointer into a
* `(GIEnumInfo*)` pointer.
*
* Depending on the current debugging level, this function may invoke
* certain runtime checks to identify invalid casts.
*
* Since: 2.80
*/
#define GI_ENUM_INFO(info) (G_TYPE_CHECK_INSTANCE_CAST ((info), GI_TYPE_ENUM_INFO, GIEnumInfo))
/**
* GI_IS_ENUM_INFO:
* @info: an info structure

View File

@ -34,6 +34,20 @@ G_BEGIN_DECLS
#define GI_TYPE_FIELD_INFO (gi_field_info_get_type ())
/**
* GI_FIELD_INFO:
* @info: Info object which is subject to casting.
*
* Casts a [type@GIRepository.FieldInfo] or derived pointer into a
* `(GIFieldInfo*)` pointer.
*
* Depending on the current debugging level, this function may invoke
* certain runtime checks to identify invalid casts.
*
* Since: 2.80
*/
#define GI_FIELD_INFO(info) (G_TYPE_CHECK_INSTANCE_CAST ((info), GI_TYPE_FIELD_INFO, GIFieldInfo))
/**
* GI_IS_FIELD_INFO:
* @info: an info structure

View File

@ -33,6 +33,20 @@ G_BEGIN_DECLS
#define GI_TYPE_FLAGS_INFO (gi_flags_info_get_type ())
/**
* GI_FLAGS_INFO:
* @info: Info object which is subject to casting.
*
* Casts a [type@GIRepository.FlagsInfo] or derived pointer into a
* `(GIFlagsInfo*)` pointer.
*
* Depending on the current debugging level, this function may invoke
* certain runtime checks to identify invalid casts.
*
* Since: 2.80
*/
#define GI_FLAGS_INFO(info) (G_TYPE_CHECK_INSTANCE_CAST ((info), GI_TYPE_FLAGS_INFO, GIFlagsInfo))
/**
* GI_IS_FLAGS_INFO:
* @info: an info structure

View File

@ -34,6 +34,20 @@ G_BEGIN_DECLS
#define GI_TYPE_FUNCTION_INFO (gi_function_info_get_type ())
/**
* GI_FUNCTION_INFO:
* @info: Info object which is subject to casting.
*
* Casts a [type@GIRepository.FunctionInfo] or derived pointer into a
* `(GIFunctionInfo*)` pointer.
*
* Depending on the current debugging level, this function may invoke
* certain runtime checks to identify invalid casts.
*
* Since: 2.80
*/
#define GI_FUNCTION_INFO(info) (G_TYPE_CHECK_INSTANCE_CAST ((info), GI_TYPE_FUNCTION_INFO, GIFunctionInfo))
/**
* GI_IS_FUNCTION_INFO:
* @info: an info structure

View File

@ -34,6 +34,20 @@ G_BEGIN_DECLS
#define GI_TYPE_INTERFACE_INFO (gi_interface_info_get_type ())
/**
* GI_INTERFACE_INFO:
* @info: Info object which is subject to casting.
*
* Casts a [type@GIRepository.InterfaceInfo] or derived pointer into a
* `(GIInterfaceInfo*)` pointer.
*
* Depending on the current debugging level, this function may invoke
* certain runtime checks to identify invalid casts.
*
* Since: 2.80
*/
#define GI_INTERFACE_INFO(info) (G_TYPE_CHECK_INSTANCE_CAST ((info), GI_TYPE_INTERFACE_INFO, GIInterfaceInfo))
/**
* GI_IS_INTERFACE_INFO:
* @info: an info structure

View File

@ -77,6 +77,20 @@ typedef void * (*GIObjectInfoGetValueFunction) (const GValue *value);
#define GI_TYPE_OBJECT_INFO (gi_object_info_get_type ())
/**
* GI_OBJECT_INFO:
* @info: Info object which is subject to casting.
*
* Casts a [type@GIRepository.ObjectInfo] or derived pointer into a
* `(GIObjectInfo*)` pointer.
*
* Depending on the current debugging level, this function may invoke
* certain runtime checks to identify invalid casts.
*
* Since: 2.80
*/
#define GI_OBJECT_INFO(info) (G_TYPE_CHECK_INSTANCE_CAST ((info), GI_TYPE_OBJECT_INFO, GIObjectInfo))
/**
* GI_IS_OBJECT_INFO:
* @info: an info structure

View File

@ -34,6 +34,20 @@ G_BEGIN_DECLS
#define GI_TYPE_PROPERTY_INFO (gi_property_info_get_type ())
/**
* GI_PROPERTY_INFO:
* @info: Info object which is subject to casting.
*
* Casts a [type@GIRepository.PropertyInfo] or derived pointer into a
* `(GIPropertyInfo*)` pointer.
*
* Depending on the current debugging level, this function may invoke
* certain runtime checks to identify invalid casts.
*
* Since: 2.80
*/
#define GI_PROPERTY_INFO(info) (G_TYPE_CHECK_INSTANCE_CAST ((info), GI_TYPE_PROPERTY_INFO, GIPropertyInfo))
/**
* GI_IS_PROPERTY_INFO:
* @info: an info structure

View File

@ -35,6 +35,20 @@ G_BEGIN_DECLS
#define GI_TYPE_REGISTERED_TYPE_INFO (gi_registered_type_info_get_type ())
/**
* GI_REGISTERED_TYPE_INFO:
* @info: Info object which is subject to casting.
*
* Casts a [type@GIRepository.RegisteredTypeInfo] or derived pointer into a
* `(GIRegisteredTypeInfo*)` pointer.
*
* Depending on the current debugging level, this function may invoke
* certain runtime checks to identify invalid casts.
*
* Since: 2.80
*/
#define GI_REGISTERED_TYPE_INFO(info) (G_TYPE_CHECK_INSTANCE_CAST ((info), GI_TYPE_REGISTERED_TYPE_INFO, GIRegisteredTypeInfo))
/**
* GI_IS_REGISTERED_TYPE_INFO:
* @info: an info structure

View File

@ -35,6 +35,20 @@ G_BEGIN_DECLS
#define GI_TYPE_SIGNAL_INFO (gi_signal_info_get_type ())
/**
* GI_SIGNAL_INFO:
* @info: Info object which is subject to casting.
*
* Casts a [type@GIRepository.SignalInfo] or derived pointer into a
* `(GISignalInfo*)` pointer.
*
* Depending on the current debugging level, this function may invoke
* certain runtime checks to identify invalid casts.
*
* Since: 2.80
*/
#define GI_SIGNAL_INFO(info) (G_TYPE_CHECK_INSTANCE_CAST ((info), GI_TYPE_SIGNAL_INFO, GISignalInfo))
/**
* GI_IS_SIGNAL_INFO:
* @info: an info structure

View File

@ -34,6 +34,20 @@ G_BEGIN_DECLS
#define GI_TYPE_STRUCT_INFO (gi_struct_info_get_type ())
/**
* GI_STRUCT_INFO:
* @info: Info object which is subject to casting.
*
* Casts a [type@GIRepository.StructInfo] or derived pointer into a
* `(GIStructInfo*)` pointer.
*
* Depending on the current debugging level, this function may invoke
* certain runtime checks to identify invalid casts.
*
* Since: 2.80
*/
#define GI_STRUCT_INFO(info) (G_TYPE_CHECK_INSTANCE_CAST ((info), GI_TYPE_STRUCT_INFO, GIStructInfo))
/**
* GI_IS_STRUCT_INFO:
* @info: an info structure

View File

@ -34,6 +34,20 @@ G_BEGIN_DECLS
#define GI_TYPE_TYPE_INFO (gi_type_info_get_type ())
/**
* GI_TYPE_INFO:
* @info: Info object which is subject to casting.
*
* Casts a [type@GIRepository.TypeInfo] or derived pointer into a
* `(GITypeInfo*)` pointer.
*
* Depending on the current debugging level, this function may invoke
* certain runtime checks to identify invalid casts.
*
* Since: 2.80
*/
#define GI_TYPE_INFO(info) (G_TYPE_CHECK_INSTANCE_CAST ((info), GI_TYPE_TYPE_INFO, GITypeInfo))
/**
* GI_IS_TYPE_INFO:
* @info: an info structure

View File

@ -34,6 +34,20 @@ G_BEGIN_DECLS
#define GI_TYPE_UNION_INFO (gi_union_info_get_type ())
/**
* GI_UNION_INFO:
* @info: Info object which is subject to casting.
*
* Casts a [type@GIRepository.UnionInfo] or derived pointer into a
* `(GIUnionInfo*)` pointer.
*
* Depending on the current debugging level, this function may invoke
* certain runtime checks to identify invalid casts.
*
* Since: 2.80
*/
#define GI_UNION_INFO(info) (G_TYPE_CHECK_INSTANCE_CAST ((info), GI_TYPE_UNION_INFO, GIUnionInfo))
/**
* GI_IS_UNION_INFO:
* @info: an info structure

View File

@ -33,6 +33,20 @@ G_BEGIN_DECLS
#define GI_TYPE_UNRESOLVED_INFO (gi_unresolved_info_get_type ())
/**
* GI_UNRESOLVED_INFO:
* @info: Info object which is subject to casting.
*
* Casts a [type@GIRepository.UnresolvedInfo] or derived pointer into a
* `(GIUnresolvedInfo*)` pointer.
*
* Depending on the current debugging level, this function may invoke
* certain runtime checks to identify invalid casts.
*
* Since: 2.80
*/
#define GI_UNRESOLVED_INFO(info) (G_TYPE_CHECK_INSTANCE_CAST ((info), GI_TYPE_UNRESOLVED_INFO, GIUnresolvedInfo))
/**
* GI_IS_UNRESOLVED_INFO:
* @info: an info structure

View File

@ -34,6 +34,20 @@ G_BEGIN_DECLS
#define GI_TYPE_VALUE_INFO (gi_value_info_get_type ())
/**
* GI_VALUE_INFO:
* @info: Info object which is subject to casting.
*
* Casts a [type@GIRepository.ValueInfo] or derived pointer into a
* `(GIValueInfo*)` pointer.
*
* Depending on the current debugging level, this function may invoke
* certain runtime checks to identify invalid casts.
*
* Since: 2.80
*/
#define GI_VALUE_INFO(info) (G_TYPE_CHECK_INSTANCE_CAST ((info), GI_TYPE_VALUE_INFO, GIValueInfo))
/**
* GI_IS_VALUE_INFO:
* @info: an info structure

View File

@ -34,6 +34,20 @@ G_BEGIN_DECLS
#define GI_TYPE_VFUNC_INFO (gi_vfunc_info_get_type ())
/**
* GI_VFUNC_INFO:
* @info: Info object which is subject to casting.
*
* Casts a [type@GIRepository.VFuncInfo] or derived pointer into a
* `(GIVFuncInfo*)` pointer.
*
* Depending on the current debugging level, this function may invoke
* certain runtime checks to identify invalid casts.
*
* Since: 2.80
*/
#define GI_VFUNC_INFO(info) (G_TYPE_CHECK_INSTANCE_CAST ((info), GI_TYPE_VFUNC_INFO, GIVFuncInfo))
/**
* GI_IS_VFUNC_INFO:
* @info: an info structure