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

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