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_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