From 9377a0dd54f6355eb841d5a32ad2e0536dfee1ae Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 17 Jan 2024 13:43:58 +0000 Subject: [PATCH 01/14] girepository: Split GIValueInfo out of gienuminfo.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It’s a separate type, so it would be less confusing if it were in its own file. This doesn’t change any API. Signed-off-by: Philip Withnall Helps: #3155 --- girepository/gienuminfo.c | 48 ---------------------- girepository/gienuminfo.h | 15 ------- girepository/girepository.h | 1 + girepository/givalueinfo.c | 81 +++++++++++++++++++++++++++++++++++++ girepository/givalueinfo.h | 50 +++++++++++++++++++++++ girepository/meson.build | 2 + 6 files changed, 134 insertions(+), 63 deletions(-) create mode 100644 girepository/givalueinfo.c create mode 100644 girepository/givalueinfo.h diff --git a/girepository/gienuminfo.c b/girepository/gienuminfo.c index 6f30ea08e..1848e8fd7 100644 --- a/girepository/gienuminfo.c +++ b/girepository/gienuminfo.c @@ -221,51 +221,3 @@ gi_enum_info_class_init (gpointer g_class, info_class->info_type = GI_INFO_TYPE_ENUM; } - -/** - * GIValueInfo: - * - * A `GIValueInfo` represents a value in an enumeration. - * - * The `GIValueInfo` is fetched by calling - * [method@GIRepository.EnumInfo.get_value] on a [class@GIRepository.EnumInfo]. - * - * Since: 2.80 - */ - -/** - * gi_value_info_get_value: - * @info: a #GIValueInfo - * - * Obtain the enumeration value of the `GIValueInfo`. - * - * Returns: the enumeration value. This will always be representable - * as a 32-bit signed or unsigned value. The use of `int64_t` as the - * return type is to allow both. - * Since: 2.80 - */ -int64_t -gi_value_info_get_value (GIValueInfo *info) -{ - GIRealInfo *rinfo = (GIRealInfo *)info; - ValueBlob *blob; - - g_return_val_if_fail (info != NULL, -1); - g_return_val_if_fail (GI_IS_VALUE_INFO (info), -1); - - blob = (ValueBlob *)&rinfo->typelib->data[rinfo->offset]; - - if (blob->unsigned_value) - return (int64_t)(uint32_t)blob->value; - else - return (int64_t)blob->value; -} - -void -gi_value_info_class_init (gpointer g_class, - gpointer class_data) -{ - GIBaseInfoClass *info_class = g_class; - - info_class->info_type = GI_INFO_TYPE_VALUE; -} diff --git a/girepository/gienuminfo.h b/girepository/gienuminfo.h index ba1d33d09..2f2546f30 100644 --- a/girepository/gienuminfo.h +++ b/girepository/gienuminfo.h @@ -44,17 +44,6 @@ G_BEGIN_DECLS ((gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_ENUM) || \ (gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_FLAGS)) -/** - * GI_IS_VALUE_INFO: - * @info: an info structure - * - * Checks if @info is a [class@GIRepository.ValueInfo]. - * - * Since: 2.80 - */ -#define GI_IS_VALUE_INFO(info) \ - (gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_VALUE) - GI_AVAILABLE_IN_ALL unsigned int gi_enum_info_get_n_values (GIEnumInfo *info); @@ -76,8 +65,4 @@ GITypeTag gi_enum_info_get_storage_type (GIEnumInfo *info); GI_AVAILABLE_IN_ALL const char * gi_enum_info_get_error_domain (GIEnumInfo *info); - -GI_AVAILABLE_IN_ALL -int64_t gi_value_info_get_value (GIValueInfo *info); - G_END_DECLS diff --git a/girepository/girepository.h b/girepository/girepository.h index 52ef28a8d..6c687b19d 100644 --- a/girepository/girepository.h +++ b/girepository/girepository.h @@ -50,6 +50,7 @@ #include #include #include +#include #include G_BEGIN_DECLS diff --git a/girepository/givalueinfo.c b/girepository/givalueinfo.c new file mode 100644 index 000000000..b55cf670e --- /dev/null +++ b/girepository/givalueinfo.c @@ -0,0 +1,81 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * GObject introspection: Enum implementation + * + * Copyright (C) 2005 Matthias Clasen + * Copyright (C) 2008,2009 Red Hat, Inc. + * + * SPDX-License-Identifier: LGPL-2.1-or-later + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include + +#include +#include "gibaseinfo-private.h" +#include "girepository-private.h" +#include "gitypelib-internal.h" +#include "givalueinfo.h" + +/** + * GIValueInfo: + * + * A `GIValueInfo` represents a value in an enumeration. + * + * The `GIValueInfo` is fetched by calling + * [method@GIRepository.EnumInfo.get_value] on a [class@GIRepository.EnumInfo]. + * + * Since: 2.80 + */ + +/** + * gi_value_info_get_value: + * @info: a #GIValueInfo + * + * Obtain the enumeration value of the `GIValueInfo`. + * + * Returns: the enumeration value. This will always be representable + * as a 32-bit signed or unsigned value. The use of `int64_t` as the + * return type is to allow both. + * Since: 2.80 + */ +int64_t +gi_value_info_get_value (GIValueInfo *info) +{ + GIRealInfo *rinfo = (GIRealInfo *)info; + ValueBlob *blob; + + g_return_val_if_fail (info != NULL, -1); + g_return_val_if_fail (GI_IS_VALUE_INFO (info), -1); + + blob = (ValueBlob *)&rinfo->typelib->data[rinfo->offset]; + + if (blob->unsigned_value) + return (int64_t)(uint32_t)blob->value; + else + return (int64_t)blob->value; +} + +void +gi_value_info_class_init (gpointer g_class, + gpointer class_data) +{ + GIBaseInfoClass *info_class = g_class; + + info_class->info_type = GI_INFO_TYPE_VALUE; +} diff --git a/girepository/givalueinfo.h b/girepository/givalueinfo.h new file mode 100644 index 000000000..3cb20d43d --- /dev/null +++ b/girepository/givalueinfo.h @@ -0,0 +1,50 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * GObject introspection: Enum and Enum values + * + * Copyright (C) 2005 Matthias Clasen + * Copyright (C) 2008,2009 Red Hat, Inc. + * + * SPDX-License-Identifier: LGPL-2.1-or-later + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#pragma once + +#if !defined (__GIREPOSITORY_H_INSIDE__) && !defined (GI_COMPILATION) +#error "Only can be included directly." +#endif + +#include + +G_BEGIN_DECLS + +/** + * GI_IS_VALUE_INFO: + * @info: an info structure + * + * Checks if @info is a [class@GIRepository.ValueInfo]. + * + * Since: 2.80 + */ +#define GI_IS_VALUE_INFO(info) \ + (gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_VALUE) + + +GI_AVAILABLE_IN_ALL +int64_t gi_value_info_get_value (GIValueInfo *info); + +G_END_DECLS diff --git a/girepository/meson.build b/girepository/meson.build index c39efa618..be45a9bc5 100644 --- a/girepository/meson.build +++ b/girepository/meson.build @@ -62,6 +62,7 @@ girepo_headers = files( 'gitypes.h', 'giunioninfo.h', 'giunresolvedinfo.h', + 'givalueinfo.h', 'givfuncinfo.h', ) @@ -162,6 +163,7 @@ girepo_sources = files( 'gitypelib.c', 'giunioninfo.c', 'giunresolvedinfo.c', + 'givalueinfo.c', 'givfuncinfo.c', ) From 8e3d98fc98f3165d5a7dc858582daa0fd99f2914 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 17 Jan 2024 14:15:23 +0000 Subject: [PATCH 02/14] girepository: Add get_type() wrapper macros This makes `GIBaseInfo` and derived types more consistent with GObject convention, and thus a bit more comfortable to use. Signed-off-by: Philip Withnall Helps: #3216 --- girepository/giarginfo.h | 2 ++ girepository/gicallableinfo.h | 2 ++ girepository/gicallbackinfo.h | 2 ++ girepository/giconstantinfo.h | 2 ++ girepository/gienuminfo.h | 2 ++ girepository/gifieldinfo.h | 2 ++ girepository/gifunctioninfo.h | 2 ++ girepository/giinterfaceinfo.h | 2 ++ girepository/giobjectinfo.h | 2 ++ girepository/gipropertyinfo.h | 2 ++ girepository/giregisteredtypeinfo.h | 2 ++ girepository/gisignalinfo.h | 2 ++ girepository/gistructinfo.h | 2 ++ girepository/gitypeinfo.h | 2 ++ girepository/giunioninfo.h | 2 ++ girepository/giunresolvedinfo.h | 2 ++ girepository/givalueinfo.h | 2 ++ girepository/givfuncinfo.h | 2 ++ 18 files changed, 36 insertions(+) diff --git a/girepository/giarginfo.h b/girepository/giarginfo.h index 2fec04216..316ad1b84 100644 --- a/girepository/giarginfo.h +++ b/girepository/giarginfo.h @@ -32,6 +32,8 @@ G_BEGIN_DECLS +#define GI_TYPE_ARG_INFO (gi_arg_info_get_type ()) + /** * GI_IS_ARG_INFO: * @info: an info structure diff --git a/girepository/gicallableinfo.h b/girepository/gicallableinfo.h index 5f057ab8a..95717fd44 100644 --- a/girepository/gicallableinfo.h +++ b/girepository/gicallableinfo.h @@ -32,6 +32,8 @@ G_BEGIN_DECLS +#define GI_TYPE_CALLABLE_INFO (gi_callable_info_get_type ()) + /** * GI_IS_CALLABLE_INFO: * @info: an info structure diff --git a/girepository/gicallbackinfo.h b/girepository/gicallbackinfo.h index ee035f525..f678d9f20 100644 --- a/girepository/gicallbackinfo.h +++ b/girepository/gicallbackinfo.h @@ -31,6 +31,8 @@ G_BEGIN_DECLS +#define GI_TYPE_CALLBACK_INFO (gi_callback_info_get_type ()) + /** * GI_IS_CALLBACK_INFO: * @info: an info structure diff --git a/girepository/giconstantinfo.h b/girepository/giconstantinfo.h index 5885d5465..5bfbde5a4 100644 --- a/girepository/giconstantinfo.h +++ b/girepository/giconstantinfo.h @@ -32,6 +32,8 @@ G_BEGIN_DECLS +#define GI_TYPE_CONSTANT_INFO (gi_constant_info_get_type ()) + /** * GI_IS_CONSTANT_INFO: * @info: an info structure diff --git a/girepository/gienuminfo.h b/girepository/gienuminfo.h index 2f2546f30..8320e3e26 100644 --- a/girepository/gienuminfo.h +++ b/girepository/gienuminfo.h @@ -32,6 +32,8 @@ G_BEGIN_DECLS +#define GI_TYPE_ENUM_INFO (gi_enum_info_get_type ()) + /** * GI_IS_ENUM_INFO: * @info: an info structure diff --git a/girepository/gifieldinfo.h b/girepository/gifieldinfo.h index 9ac6449b6..c42a4d221 100644 --- a/girepository/gifieldinfo.h +++ b/girepository/gifieldinfo.h @@ -32,6 +32,8 @@ G_BEGIN_DECLS +#define GI_TYPE_FIELD_INFO (gi_field_info_get_type ()) + /** * GI_IS_FIELD_INFO: * @info: an info structure diff --git a/girepository/gifunctioninfo.h b/girepository/gifunctioninfo.h index 9a9f52551..98aec1c82 100644 --- a/girepository/gifunctioninfo.h +++ b/girepository/gifunctioninfo.h @@ -32,6 +32,8 @@ G_BEGIN_DECLS +#define GI_TYPE_FUNCTION_INFO (gi_function_info_get_type ()) + /** * GI_IS_FUNCTION_INFO: * @info: an info structure diff --git a/girepository/giinterfaceinfo.h b/girepository/giinterfaceinfo.h index 798d8bc84..0d6c7519b 100644 --- a/girepository/giinterfaceinfo.h +++ b/girepository/giinterfaceinfo.h @@ -32,6 +32,8 @@ G_BEGIN_DECLS +#define GI_TYPE_INTERFACE_INFO (gi_interface_info_get_type ()) + /** * GI_IS_INTERFACE_INFO: * @info: an info structure diff --git a/girepository/giobjectinfo.h b/girepository/giobjectinfo.h index c8b071d67..af85fa9d3 100644 --- a/girepository/giobjectinfo.h +++ b/girepository/giobjectinfo.h @@ -75,6 +75,8 @@ typedef void (*GIObjectInfoSetValueFunction) (GValue *value, void *object); */ typedef void * (*GIObjectInfoGetValueFunction) (const GValue *value); +#define GI_TYPE_OBJECT_INFO (gi_object_info_get_type ()) + /** * GI_IS_OBJECT_INFO: * @info: an info structure diff --git a/girepository/gipropertyinfo.h b/girepository/gipropertyinfo.h index cff5faab9..34144953e 100644 --- a/girepository/gipropertyinfo.h +++ b/girepository/gipropertyinfo.h @@ -32,6 +32,8 @@ G_BEGIN_DECLS +#define GI_TYPE_PROPERTY_INFO (gi_property_info_get_type ()) + /** * GI_IS_PROPERTY_INFO: * @info: an info structure diff --git a/girepository/giregisteredtypeinfo.h b/girepository/giregisteredtypeinfo.h index 4bdc9dbef..6a5a2508f 100644 --- a/girepository/giregisteredtypeinfo.h +++ b/girepository/giregisteredtypeinfo.h @@ -33,6 +33,8 @@ G_BEGIN_DECLS +#define GI_TYPE_REGISTERED_TYPE_INFO (gi_registered_type_info_get_type ()) + /** * GI_IS_REGISTERED_TYPE_INFO: * @info: an info structure diff --git a/girepository/gisignalinfo.h b/girepository/gisignalinfo.h index 705cc6820..b07ad303d 100644 --- a/girepository/gisignalinfo.h +++ b/girepository/gisignalinfo.h @@ -33,6 +33,8 @@ G_BEGIN_DECLS +#define GI_TYPE_SIGNAL_INFO (gi_signal_info_get_type ()) + /** * GI_IS_SIGNAL_INFO: * @info: an info structure diff --git a/girepository/gistructinfo.h b/girepository/gistructinfo.h index eaab4f42e..97ccf15f8 100644 --- a/girepository/gistructinfo.h +++ b/girepository/gistructinfo.h @@ -32,6 +32,8 @@ G_BEGIN_DECLS +#define GI_TYPE_STRUCT_INFO (gi_struct_info_get_type ()) + /** * GI_IS_STRUCT_INFO: * @info: an info structure diff --git a/girepository/gitypeinfo.h b/girepository/gitypeinfo.h index 0d01e69e4..df249e330 100644 --- a/girepository/gitypeinfo.h +++ b/girepository/gitypeinfo.h @@ -32,6 +32,8 @@ G_BEGIN_DECLS +#define GI_TYPE_TYPE_INFO (gi_type_info_get_type ()) + /** * GI_IS_TYPE_INFO: * @info: an info structure diff --git a/girepository/giunioninfo.h b/girepository/giunioninfo.h index 30ebc9549..0341bff21 100644 --- a/girepository/giunioninfo.h +++ b/girepository/giunioninfo.h @@ -32,6 +32,8 @@ G_BEGIN_DECLS +#define GI_TYPE_UNION_INFO (gi_union_info_get_type ()) + /** * GI_IS_UNION_INFO: * @info: an info structure diff --git a/girepository/giunresolvedinfo.h b/girepository/giunresolvedinfo.h index e2f68e2d6..29c629f48 100644 --- a/girepository/giunresolvedinfo.h +++ b/girepository/giunresolvedinfo.h @@ -31,6 +31,8 @@ G_BEGIN_DECLS +#define GI_TYPE_UNRESOLVED_INFO (gi_unresolved_info_get_type ()) + /** * GI_IS_UNRESOLVED_INFO: * @info: an info structure diff --git a/girepository/givalueinfo.h b/girepository/givalueinfo.h index 3cb20d43d..7f1ebb275 100644 --- a/girepository/givalueinfo.h +++ b/girepository/givalueinfo.h @@ -32,6 +32,8 @@ G_BEGIN_DECLS +#define GI_TYPE_VALUE_INFO (gi_value_info_get_type ()) + /** * GI_IS_VALUE_INFO: * @info: an info structure diff --git a/girepository/givfuncinfo.h b/girepository/givfuncinfo.h index 540e80666..31fea50bf 100644 --- a/girepository/givfuncinfo.h +++ b/girepository/givfuncinfo.h @@ -32,6 +32,8 @@ G_BEGIN_DECLS +#define GI_TYPE_VFUNC_INFO (gi_vfunc_info_get_type ()) + /** * GI_IS_VFUNC_INFO: * @info: an info structure From 71a19a6f65a0281779a9dad58d95982c773b750a Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 17 Jan 2024 14:21:07 +0000 Subject: [PATCH 03/14] gibaseinfo: Allow type flags to be specified for derived types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This doesn’t change any of the flags for now (i.e. it introduces no functional changes), but it will allow us to make some of the types abstract in an upcoming commit. Signed-off-by: Philip Withnall Helps: #3216 --- girepository/gibaseinfo-private.h | 3 +- girepository/gibaseinfo.c | 46 +++++++++++++++++-------------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/girepository/gibaseinfo-private.h b/girepository/gibaseinfo-private.h index a756f7072..ae82b43a4 100644 --- a/girepository/gibaseinfo-private.h +++ b/girepository/gibaseinfo-private.h @@ -46,6 +46,7 @@ void gi_base_info_init_types (void); GType gi_base_info_type_register_static (const char *type_name, size_t instance_size, - GClassInitFunc class_init); + GClassInitFunc class_init, + GTypeFlags type_flags); G_END_DECLS diff --git a/girepository/gibaseinfo.c b/girepository/gibaseinfo.c index 031635c3a..6691936fc 100644 --- a/girepository/gibaseinfo.c +++ b/girepository/gibaseinfo.c @@ -204,6 +204,7 @@ gi_base_info_get_type (void) * @type_name: the name of the type * @instance_size: size (in bytes) of the type’s instance struct * @class_init: class init function for the type + * @type_flags: flags for the type * * Registers a new [type@GIRepository.BaseInfo] type for the given @type_name * using the type information provided. @@ -214,7 +215,8 @@ gi_base_info_get_type (void) GType gi_base_info_type_register_static (const char *type_name, size_t instance_size, - GClassInitFunc class_init) + GClassInitFunc class_init, + GTypeFlags type_flags) { GTypeInfo info; @@ -228,7 +230,7 @@ gi_base_info_type_register_static (const char *type_name, info.instance_init = NULL; info.value_table = NULL; - return g_type_register_static (GI_TYPE_BASE_INFO, type_name, &info, 0); + return g_type_register_static (GI_TYPE_BASE_INFO, type_name, &info, type_flags); } static GType gi_base_info_types[GI_INFO_TYPE_N_TYPES]; @@ -274,34 +276,36 @@ gi_base_info_init_types (void) const char *type_name; size_t instance_size; GClassInitFunc class_init; + GTypeFlags type_flags; } types[] = { - { GI_INFO_TYPE_CALLABLE, "GICallableInfo", sizeof (GICallableInfo), gi_callable_info_class_init }, - { GI_INFO_TYPE_FUNCTION, "GIFunctionInfo", sizeof (GIFunctionInfo), gi_function_info_class_init }, - { GI_INFO_TYPE_CALLBACK, "GICallbackInfo", sizeof (GICallbackInfo), gi_callback_info_class_init }, - { GI_INFO_TYPE_REGISTERED_TYPE, "GIRegisteredTypeInfo", sizeof (GIRegisteredTypeInfo), gi_registered_type_info_class_init }, - { GI_INFO_TYPE_STRUCT, "GIStructInfo", sizeof (GIStructInfo), gi_struct_info_class_init }, - { GI_INFO_TYPE_UNION, "GIUnionInfo", sizeof (GIUnionInfo), gi_union_info_class_init }, - { GI_INFO_TYPE_ENUM, "GIEnumInfo", sizeof (GIEnumInfo), gi_enum_info_class_init }, - { GI_INFO_TYPE_OBJECT, "GIObjectInfo", sizeof (GIObjectInfo), gi_object_info_class_init }, - { GI_INFO_TYPE_INTERFACE, "GIInterfaceInfo", sizeof (GIInterfaceInfo), gi_interface_info_class_init }, - { GI_INFO_TYPE_CONSTANT, "GIConstantInfo", sizeof (GIConstantInfo), gi_constant_info_class_init }, - { GI_INFO_TYPE_VALUE, "GIValueInfo", sizeof (GIValueInfo), gi_value_info_class_init }, - { GI_INFO_TYPE_SIGNAL, "GISignalInfo", sizeof (GISignalInfo), gi_signal_info_class_init }, - { GI_INFO_TYPE_VFUNC, "GIVFuncInfo", sizeof (GIVFuncInfo), gi_vfunc_info_class_init }, - { GI_INFO_TYPE_PROPERTY, "GIPropertyInfo", sizeof (GIPropertyInfo), gi_property_info_class_init }, - { GI_INFO_TYPE_FIELD, "GIFieldInfo", sizeof (GIFieldInfo), gi_field_info_class_init }, - { GI_INFO_TYPE_ARG, "GIArgInfo", sizeof (GIArgInfo), gi_arg_info_class_init }, - { GI_INFO_TYPE_TYPE, "GITypeInfo", sizeof (GITypeInfo), gi_type_info_class_init }, - { GI_INFO_TYPE_UNRESOLVED, "GIUnresolvedInfo", sizeof (GIUnresolvedInfo), gi_unresolved_info_class_init }, + { GI_INFO_TYPE_CALLABLE, "GICallableInfo", sizeof (GICallableInfo), gi_callable_info_class_init, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_FUNCTION, "GIFunctionInfo", sizeof (GIFunctionInfo), gi_function_info_class_init, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_CALLBACK, "GICallbackInfo", sizeof (GICallbackInfo), gi_callback_info_class_init, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_REGISTERED_TYPE, "GIRegisteredTypeInfo", sizeof (GIRegisteredTypeInfo), gi_registered_type_info_class_init, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_STRUCT, "GIStructInfo", sizeof (GIStructInfo), gi_struct_info_class_init, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_UNION, "GIUnionInfo", sizeof (GIUnionInfo), gi_union_info_class_init, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_ENUM, "GIEnumInfo", sizeof (GIEnumInfo), gi_enum_info_class_init, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_OBJECT, "GIObjectInfo", sizeof (GIObjectInfo), gi_object_info_class_init, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_INTERFACE, "GIInterfaceInfo", sizeof (GIInterfaceInfo), gi_interface_info_class_init, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_CONSTANT, "GIConstantInfo", sizeof (GIConstantInfo), gi_constant_info_class_init, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_VALUE, "GIValueInfo", sizeof (GIValueInfo), gi_value_info_class_init, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_SIGNAL, "GISignalInfo", sizeof (GISignalInfo), gi_signal_info_class_init, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_VFUNC, "GIVFuncInfo", sizeof (GIVFuncInfo), gi_vfunc_info_class_init, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_PROPERTY, "GIPropertyInfo", sizeof (GIPropertyInfo), gi_property_info_class_init, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_FIELD, "GIFieldInfo", sizeof (GIFieldInfo), gi_field_info_class_init, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_ARG, "GIArgInfo", sizeof (GIArgInfo), gi_arg_info_class_init, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_TYPE, "GITypeInfo", sizeof (GITypeInfo), gi_type_info_class_init, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_UNRESOLVED, "GIUnresolvedInfo", sizeof (GIUnresolvedInfo), gi_unresolved_info_class_init, G_TYPE_FLAG_NONE }, }; for (size_t i = 0; i < G_N_ELEMENTS (types); i++) { GType registered_type = gi_base_info_type_register_static (g_intern_static_string (types[i].type_name), types[i].instance_size, - types[i].class_init); + types[i].class_init, + types[i].type_flags); gi_base_info_types[types[i].info_type] = registered_type; } From 4d5b6599fc6b28bb734368f1eb179a7d5e82297c Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 17 Jan 2024 14:32:23 +0000 Subject: [PATCH 04/14] gibaseinfo: Allow parent types to be specified for derived types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This doesn’t change the type hierarchy for now (i.e. it introduces no functional changes), but it will allow us to add some intermediate types into the `GIBaseInfo` hierarchy in an upcoming commit. Signed-off-by: Philip Withnall Helps: #3216 --- girepository/gibaseinfo-private.h | 1 + girepository/gibaseinfo.c | 56 ++++++++++++++++++------------- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/girepository/gibaseinfo-private.h b/girepository/gibaseinfo-private.h index ae82b43a4..aba0e19ed 100644 --- a/girepository/gibaseinfo-private.h +++ b/girepository/gibaseinfo-private.h @@ -47,6 +47,7 @@ void gi_base_info_init_types (void); GType gi_base_info_type_register_static (const char *type_name, size_t instance_size, GClassInitFunc class_init, + GType parent_type, GTypeFlags type_flags); G_END_DECLS diff --git a/girepository/gibaseinfo.c b/girepository/gibaseinfo.c index 6691936fc..2bc1206e2 100644 --- a/girepository/gibaseinfo.c +++ b/girepository/gibaseinfo.c @@ -204,6 +204,8 @@ gi_base_info_get_type (void) * @type_name: the name of the type * @instance_size: size (in bytes) of the type’s instance struct * @class_init: class init function for the type + * @parent_type: [type@GObject.Type] for the parent type; this will typically be + * `GI_TYPE_BASE_INFO` * @type_flags: flags for the type * * Registers a new [type@GIRepository.BaseInfo] type for the given @type_name @@ -216,6 +218,7 @@ GType gi_base_info_type_register_static (const char *type_name, size_t instance_size, GClassInitFunc class_init, + GType parent_type, GTypeFlags type_flags) { GTypeInfo info; @@ -230,7 +233,7 @@ gi_base_info_type_register_static (const char *type_name, info.instance_init = NULL; info.value_table = NULL; - return g_type_register_static (GI_TYPE_BASE_INFO, type_name, &info, type_flags); + return g_type_register_static (parent_type, type_name, &info, type_flags); } static GType gi_base_info_types[GI_INFO_TYPE_N_TYPES]; @@ -276,36 +279,43 @@ gi_base_info_init_types (void) const char *type_name; size_t instance_size; GClassInitFunc class_init; + GIInfoType parent_info_type; /* 0 for GIBaseInfo */ GTypeFlags type_flags; } types[] = { - { GI_INFO_TYPE_CALLABLE, "GICallableInfo", sizeof (GICallableInfo), gi_callable_info_class_init, G_TYPE_FLAG_NONE }, - { GI_INFO_TYPE_FUNCTION, "GIFunctionInfo", sizeof (GIFunctionInfo), gi_function_info_class_init, G_TYPE_FLAG_NONE }, - { GI_INFO_TYPE_CALLBACK, "GICallbackInfo", sizeof (GICallbackInfo), gi_callback_info_class_init, G_TYPE_FLAG_NONE }, - { GI_INFO_TYPE_REGISTERED_TYPE, "GIRegisteredTypeInfo", sizeof (GIRegisteredTypeInfo), gi_registered_type_info_class_init, G_TYPE_FLAG_NONE }, - { GI_INFO_TYPE_STRUCT, "GIStructInfo", sizeof (GIStructInfo), gi_struct_info_class_init, G_TYPE_FLAG_NONE }, - { GI_INFO_TYPE_UNION, "GIUnionInfo", sizeof (GIUnionInfo), gi_union_info_class_init, G_TYPE_FLAG_NONE }, - { GI_INFO_TYPE_ENUM, "GIEnumInfo", sizeof (GIEnumInfo), gi_enum_info_class_init, G_TYPE_FLAG_NONE }, - { GI_INFO_TYPE_OBJECT, "GIObjectInfo", sizeof (GIObjectInfo), gi_object_info_class_init, G_TYPE_FLAG_NONE }, - { GI_INFO_TYPE_INTERFACE, "GIInterfaceInfo", sizeof (GIInterfaceInfo), gi_interface_info_class_init, G_TYPE_FLAG_NONE }, - { GI_INFO_TYPE_CONSTANT, "GIConstantInfo", sizeof (GIConstantInfo), gi_constant_info_class_init, G_TYPE_FLAG_NONE }, - { GI_INFO_TYPE_VALUE, "GIValueInfo", sizeof (GIValueInfo), gi_value_info_class_init, G_TYPE_FLAG_NONE }, - { GI_INFO_TYPE_SIGNAL, "GISignalInfo", sizeof (GISignalInfo), gi_signal_info_class_init, G_TYPE_FLAG_NONE }, - { GI_INFO_TYPE_VFUNC, "GIVFuncInfo", sizeof (GIVFuncInfo), gi_vfunc_info_class_init, G_TYPE_FLAG_NONE }, - { GI_INFO_TYPE_PROPERTY, "GIPropertyInfo", sizeof (GIPropertyInfo), gi_property_info_class_init, G_TYPE_FLAG_NONE }, - { GI_INFO_TYPE_FIELD, "GIFieldInfo", sizeof (GIFieldInfo), gi_field_info_class_init, G_TYPE_FLAG_NONE }, - { GI_INFO_TYPE_ARG, "GIArgInfo", sizeof (GIArgInfo), gi_arg_info_class_init, G_TYPE_FLAG_NONE }, - { GI_INFO_TYPE_TYPE, "GITypeInfo", sizeof (GITypeInfo), gi_type_info_class_init, G_TYPE_FLAG_NONE }, - { GI_INFO_TYPE_UNRESOLVED, "GIUnresolvedInfo", sizeof (GIUnresolvedInfo), gi_unresolved_info_class_init, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_CALLABLE, "GICallableInfo", sizeof (GICallableInfo), gi_callable_info_class_init, 0, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_FUNCTION, "GIFunctionInfo", sizeof (GIFunctionInfo), gi_function_info_class_init, 0, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_CALLBACK, "GICallbackInfo", sizeof (GICallbackInfo), gi_callback_info_class_init, 0, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_REGISTERED_TYPE, "GIRegisteredTypeInfo", sizeof (GIRegisteredTypeInfo), gi_registered_type_info_class_init, 0, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_STRUCT, "GIStructInfo", sizeof (GIStructInfo), gi_struct_info_class_init, 0, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_UNION, "GIUnionInfo", sizeof (GIUnionInfo), gi_union_info_class_init, 0, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_ENUM, "GIEnumInfo", sizeof (GIEnumInfo), gi_enum_info_class_init, 0, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_OBJECT, "GIObjectInfo", sizeof (GIObjectInfo), gi_object_info_class_init, 0, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_INTERFACE, "GIInterfaceInfo", sizeof (GIInterfaceInfo), gi_interface_info_class_init, 0, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_CONSTANT, "GIConstantInfo", sizeof (GIConstantInfo), gi_constant_info_class_init, 0, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_VALUE, "GIValueInfo", sizeof (GIValueInfo), gi_value_info_class_init, 0, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_SIGNAL, "GISignalInfo", sizeof (GISignalInfo), gi_signal_info_class_init, 0, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_VFUNC, "GIVFuncInfo", sizeof (GIVFuncInfo), gi_vfunc_info_class_init, 0, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_PROPERTY, "GIPropertyInfo", sizeof (GIPropertyInfo), gi_property_info_class_init, 0, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_FIELD, "GIFieldInfo", sizeof (GIFieldInfo), gi_field_info_class_init, 0, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_ARG, "GIArgInfo", sizeof (GIArgInfo), gi_arg_info_class_init, 0, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_TYPE, "GITypeInfo", sizeof (GITypeInfo), gi_type_info_class_init, 0, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_UNRESOLVED, "GIUnresolvedInfo", sizeof (GIUnresolvedInfo), gi_unresolved_info_class_init, 0, G_TYPE_FLAG_NONE }, }; for (size_t i = 0; i < G_N_ELEMENTS (types); i++) { - GType registered_type = gi_base_info_type_register_static (g_intern_static_string (types[i].type_name), - types[i].instance_size, - types[i].class_init, - types[i].type_flags); + GType registered_type, parent_type; + + parent_type = (types[i].parent_info_type == 0) ? GI_TYPE_BASE_INFO : gi_base_info_types[types[i].parent_info_type]; + g_assert (parent_type != G_TYPE_INVALID); + + registered_type = gi_base_info_type_register_static (g_intern_static_string (types[i].type_name), + types[i].instance_size, + types[i].class_init, + parent_type, + types[i].type_flags); gi_base_info_types[types[i].info_type] = registered_type; } From d82675ffd3c5044e1c70b16aa8c6288becea0583 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 17 Jan 2024 14:42:29 +0000 Subject: [PATCH 05/14] gicallableinfo: Make abstract and add derived types Previously (and incorrectly), `GICallableInfo`, `GIFunctionInfo`, `GICallbackInfo`, `GISignalInfo` and `GIVFuncInfo` were all derived directly from `GIBaseInfo`. `GICallableInfo` is supposed to represent all of the other types, though, so that type hierarchy was incorrect. It dated from when all the types were aliases of each other and the type management was done entirely at runtime. Fix that by making the other four types derive from `GICallableInfo`, and marking `GICallableInfo` as abstract. Signed-off-by: Philip Withnall Helps: #3216 --- girepository/gibaseinfo.c | 10 +++++----- girepository/girepository-private.h | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/girepository/gibaseinfo.c b/girepository/gibaseinfo.c index 2bc1206e2..7ff568cf2 100644 --- a/girepository/gibaseinfo.c +++ b/girepository/gibaseinfo.c @@ -284,9 +284,9 @@ gi_base_info_init_types (void) } types[] = { - { GI_INFO_TYPE_CALLABLE, "GICallableInfo", sizeof (GICallableInfo), gi_callable_info_class_init, 0, G_TYPE_FLAG_NONE }, - { GI_INFO_TYPE_FUNCTION, "GIFunctionInfo", sizeof (GIFunctionInfo), gi_function_info_class_init, 0, G_TYPE_FLAG_NONE }, - { GI_INFO_TYPE_CALLBACK, "GICallbackInfo", sizeof (GICallbackInfo), gi_callback_info_class_init, 0, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_CALLABLE, "GICallableInfo", sizeof (GICallableInfo), gi_callable_info_class_init, 0, G_TYPE_FLAG_ABSTRACT }, + { GI_INFO_TYPE_FUNCTION, "GIFunctionInfo", sizeof (GIFunctionInfo), gi_function_info_class_init, GI_INFO_TYPE_CALLABLE, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_CALLBACK, "GICallbackInfo", sizeof (GICallbackInfo), gi_callback_info_class_init, GI_INFO_TYPE_CALLABLE, G_TYPE_FLAG_NONE }, { GI_INFO_TYPE_REGISTERED_TYPE, "GIRegisteredTypeInfo", sizeof (GIRegisteredTypeInfo), gi_registered_type_info_class_init, 0, G_TYPE_FLAG_NONE }, { GI_INFO_TYPE_STRUCT, "GIStructInfo", sizeof (GIStructInfo), gi_struct_info_class_init, 0, G_TYPE_FLAG_NONE }, { GI_INFO_TYPE_UNION, "GIUnionInfo", sizeof (GIUnionInfo), gi_union_info_class_init, 0, G_TYPE_FLAG_NONE }, @@ -295,8 +295,8 @@ gi_base_info_init_types (void) { GI_INFO_TYPE_INTERFACE, "GIInterfaceInfo", sizeof (GIInterfaceInfo), gi_interface_info_class_init, 0, G_TYPE_FLAG_NONE }, { GI_INFO_TYPE_CONSTANT, "GIConstantInfo", sizeof (GIConstantInfo), gi_constant_info_class_init, 0, G_TYPE_FLAG_NONE }, { GI_INFO_TYPE_VALUE, "GIValueInfo", sizeof (GIValueInfo), gi_value_info_class_init, 0, G_TYPE_FLAG_NONE }, - { GI_INFO_TYPE_SIGNAL, "GISignalInfo", sizeof (GISignalInfo), gi_signal_info_class_init, 0, G_TYPE_FLAG_NONE }, - { GI_INFO_TYPE_VFUNC, "GIVFuncInfo", sizeof (GIVFuncInfo), gi_vfunc_info_class_init, 0, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_SIGNAL, "GISignalInfo", sizeof (GISignalInfo), gi_signal_info_class_init, GI_INFO_TYPE_CALLABLE, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_VFUNC, "GIVFuncInfo", sizeof (GIVFuncInfo), gi_vfunc_info_class_init, GI_INFO_TYPE_CALLABLE, G_TYPE_FLAG_NONE }, { GI_INFO_TYPE_PROPERTY, "GIPropertyInfo", sizeof (GIPropertyInfo), gi_property_info_class_init, 0, G_TYPE_FLAG_NONE }, { GI_INFO_TYPE_FIELD, "GIFieldInfo", sizeof (GIFieldInfo), gi_field_info_class_init, 0, G_TYPE_FLAG_NONE }, { GI_INFO_TYPE_ARG, "GIArgInfo", sizeof (GIArgInfo), gi_arg_info_class_init, 0, G_TYPE_FLAG_NONE }, diff --git a/girepository/girepository-private.h b/girepository/girepository-private.h index f0f700744..a6d843063 100644 --- a/girepository/girepository-private.h +++ b/girepository/girepository-private.h @@ -68,7 +68,7 @@ void gi_callable_info_class_init (gpointer g_class, struct _GIFunctionInfo { - GIBaseInfo parent; + GICallableInfo parent; }; void gi_function_info_class_init (gpointer g_class, @@ -76,7 +76,7 @@ void gi_function_info_class_init (gpointer g_class, struct _GICallbackInfo { - GIBaseInfo parent; + GICallableInfo parent; }; void gi_callback_info_class_init (gpointer g_class, @@ -148,7 +148,7 @@ void gi_value_info_class_init (gpointer g_class, struct _GISignalInfo { - GIBaseInfo parent; + GICallableInfo parent; }; void gi_signal_info_class_init (gpointer g_class, @@ -156,7 +156,7 @@ void gi_signal_info_class_init (gpointer g_class, struct _GIVFuncInfo { - GIBaseInfo parent; + GICallableInfo parent; }; void gi_vfunc_info_class_init (gpointer g_class, From eafc35e5ed519a62a204fcbca12f8ad3a29ba347 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 17 Jan 2024 15:02:05 +0000 Subject: [PATCH 06/14] gienuminfo: Split out GIFlagsInfo as a derived type Flag enums are already treated as a special kind of enum within `GIInfoType`, so it would be tidier to give it its own `GType` too, with a subtype relation to `GI_TYPE_ENUM_INFO`. This will simplify implementing `GI_IS_ENUM_INFO` in a following commit too. Signed-off-by: Philip Withnall Helps: #3216 --- girepository/gibaseinfo.c | 2 ++ girepository/giflagsinfo.c | 56 +++++++++++++++++++++++++++++ girepository/giflagsinfo.h | 46 ++++++++++++++++++++++++ girepository/girepository-private.h | 8 +++++ girepository/girepository.h | 1 + girepository/gitypes.h | 4 +++ girepository/meson.build | 2 ++ 7 files changed, 119 insertions(+) create mode 100644 girepository/giflagsinfo.c create mode 100644 girepository/giflagsinfo.h diff --git a/girepository/gibaseinfo.c b/girepository/gibaseinfo.c index 7ff568cf2..e3c5db016 100644 --- a/girepository/gibaseinfo.c +++ b/girepository/gibaseinfo.c @@ -254,6 +254,7 @@ GI_DEFINE_BASE_INFO_TYPE (gi_registered_type_info, GI_INFO_TYPE_REGISTERED_TYPE) GI_DEFINE_BASE_INFO_TYPE (gi_struct_info, GI_INFO_TYPE_STRUCT) GI_DEFINE_BASE_INFO_TYPE (gi_union_info, GI_INFO_TYPE_UNION) GI_DEFINE_BASE_INFO_TYPE (gi_enum_info, GI_INFO_TYPE_ENUM) +GI_DEFINE_BASE_INFO_TYPE (gi_flags_info, GI_INFO_TYPE_FLAGS) GI_DEFINE_BASE_INFO_TYPE (gi_object_info, GI_INFO_TYPE_OBJECT) GI_DEFINE_BASE_INFO_TYPE (gi_interface_info, GI_INFO_TYPE_INTERFACE) GI_DEFINE_BASE_INFO_TYPE (gi_constant_info, GI_INFO_TYPE_CONSTANT) @@ -291,6 +292,7 @@ gi_base_info_init_types (void) { GI_INFO_TYPE_STRUCT, "GIStructInfo", sizeof (GIStructInfo), gi_struct_info_class_init, 0, G_TYPE_FLAG_NONE }, { GI_INFO_TYPE_UNION, "GIUnionInfo", sizeof (GIUnionInfo), gi_union_info_class_init, 0, G_TYPE_FLAG_NONE }, { GI_INFO_TYPE_ENUM, "GIEnumInfo", sizeof (GIEnumInfo), gi_enum_info_class_init, 0, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_FLAGS, "GIFlagsInfo", sizeof (GIFlagsInfo), gi_flags_info_class_init, GI_INFO_TYPE_ENUM, G_TYPE_FLAG_NONE }, { GI_INFO_TYPE_OBJECT, "GIObjectInfo", sizeof (GIObjectInfo), gi_object_info_class_init, 0, G_TYPE_FLAG_NONE }, { GI_INFO_TYPE_INTERFACE, "GIInterfaceInfo", sizeof (GIInterfaceInfo), gi_interface_info_class_init, 0, G_TYPE_FLAG_NONE }, { GI_INFO_TYPE_CONSTANT, "GIConstantInfo", sizeof (GIConstantInfo), gi_constant_info_class_init, 0, G_TYPE_FLAG_NONE }, diff --git a/girepository/giflagsinfo.c b/girepository/giflagsinfo.c new file mode 100644 index 000000000..34a3e0029 --- /dev/null +++ b/girepository/giflagsinfo.c @@ -0,0 +1,56 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * GObject introspection: Enum implementation + * + * Copyright 2024 GNOME Foundation, Inc. + * + * SPDX-License-Identifier: LGPL-2.1-or-later + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include + +#include +#include "gibaseinfo-private.h" +#include "girepository-private.h" +#include "gitypelib-internal.h" +#include "giflagsinfo.h" + +/** + * GIFlagsInfo: + * + * A `GIFlagsInfo` represents an enumeration which defines flag values + * (independently set bits). + * + * The `GIFlagsInfo` contains a set of values (each a + * [class@GIRepository.ValueInfo]) and a type. + * + * The [class@GIRepository.ValueInfo] for a value is fetched by calling + * [method@GIRepository.EnumInfo.get_value] on a `GIFlagsInfo`. + * + * Since: 2.80 + */ + +void +gi_flags_info_class_init (gpointer g_class, + gpointer class_data) +{ + GIBaseInfoClass *info_class = g_class; + + info_class->info_type = GI_INFO_TYPE_FLAGS; +} diff --git a/girepository/giflagsinfo.h b/girepository/giflagsinfo.h new file mode 100644 index 000000000..9dc76a822 --- /dev/null +++ b/girepository/giflagsinfo.h @@ -0,0 +1,46 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * GObject introspection: Flags type + * + * Copyright 2024 GNOME Foundation, Inc. + * + * SPDX-License-Identifier: LGPL-2.1-or-later + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#pragma once + +#if !defined (__GIREPOSITORY_H_INSIDE__) && !defined (GI_COMPILATION) +#error "Only can be included directly." +#endif + +#include + +G_BEGIN_DECLS + +#define GI_TYPE_FLAGS_INFO (gi_flags_info_get_type ()) + +/** + * GI_IS_FLAGS_INFO: + * @info: an info structure + * + * Checks if @info is a [class@GIRepository.FlagsInfo] (or a derived type). + * + * Since: 2.80 + */ +#define GI_IS_FLAGS_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_FLAGS_INFO)) + +G_END_DECLS diff --git a/girepository/girepository-private.h b/girepository/girepository-private.h index a6d843063..5c7c1fb3f 100644 --- a/girepository/girepository-private.h +++ b/girepository/girepository-private.h @@ -114,6 +114,14 @@ struct _GIEnumInfo void gi_enum_info_class_init (gpointer g_class, gpointer class_data); +struct _GIFlagsInfo +{ + GIEnumInfo parent; +}; + +void gi_flags_info_class_init (gpointer g_class, + gpointer class_data); + struct _GIObjectInfo { GIBaseInfo parent; diff --git a/girepository/girepository.h b/girepository/girepository.h index 6c687b19d..4588ca981 100644 --- a/girepository/girepository.h +++ b/girepository/girepository.h @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include diff --git a/girepository/gitypes.h b/girepository/gitypes.h index b9b4b9faa..7ddd1a906 100644 --- a/girepository/gitypes.h +++ b/girepository/gitypes.h @@ -69,6 +69,10 @@ GI_AVAILABLE_IN_ALL GType gi_union_info_get_type (void); typedef struct _GIEnumInfo GIEnumInfo; GI_AVAILABLE_IN_ALL GType gi_enum_info_get_type (void); +/* Documented in giflagsinfo.c */ +typedef struct _GIFlagsInfo GIFlagsInfo; +GI_AVAILABLE_IN_ALL GType gi_flags_info_get_type (void); + /* Documented in giobjectinfo.c */ typedef struct _GIObjectInfo GIObjectInfo; GI_AVAILABLE_IN_ALL GType gi_object_info_get_type (void); diff --git a/girepository/meson.build b/girepository/meson.build index be45a9bc5..3f03a8c03 100644 --- a/girepository/meson.build +++ b/girepository/meson.build @@ -49,6 +49,7 @@ girepo_headers = files( 'giconstantinfo.h', 'gienuminfo.h', 'gifieldinfo.h', + 'giflagsinfo.h', 'gifunctioninfo.h', 'giinterfaceinfo.h', 'giobjectinfo.h', @@ -149,6 +150,7 @@ girepo_sources = files( 'giconstantinfo.c', 'gienuminfo.c', 'gifieldinfo.c', + 'giflagsinfo.c', 'gifunctioninfo.c', 'ginvoke.c', 'giinterfaceinfo.c', From 7228c6d3e0613b5b4660371c90da62d045312177 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 17 Jan 2024 15:37:47 +0000 Subject: [PATCH 07/14] giboxedinfo: Add a tag type for boxed types Boxed types are already represented within `GIInfoType`, so they should have a `GType` representation as well. In an upcoming commit, this will allow us to represent the subtype relation between `GIBoxedInfo` and `GIRegisteredTypeInfo` too. Signed-off-by: Philip Withnall Helps: #3216 --- girepository/gibaseinfo.c | 2 ++ girepository/giboxedinfo.c | 52 +++++++++++++++++++++++++++++ girepository/giboxedinfo.h | 46 +++++++++++++++++++++++++ girepository/girepository-private.h | 10 +++++- girepository/girepository.h | 1 + girepository/gitypes.h | 4 +++ girepository/meson.build | 2 ++ 7 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 girepository/giboxedinfo.c create mode 100644 girepository/giboxedinfo.h diff --git a/girepository/gibaseinfo.c b/girepository/gibaseinfo.c index e3c5db016..3427a17b5 100644 --- a/girepository/gibaseinfo.c +++ b/girepository/gibaseinfo.c @@ -257,6 +257,7 @@ GI_DEFINE_BASE_INFO_TYPE (gi_enum_info, GI_INFO_TYPE_ENUM) GI_DEFINE_BASE_INFO_TYPE (gi_flags_info, GI_INFO_TYPE_FLAGS) GI_DEFINE_BASE_INFO_TYPE (gi_object_info, GI_INFO_TYPE_OBJECT) GI_DEFINE_BASE_INFO_TYPE (gi_interface_info, GI_INFO_TYPE_INTERFACE) +GI_DEFINE_BASE_INFO_TYPE (gi_boxed_info, GI_INFO_TYPE_BOXED) GI_DEFINE_BASE_INFO_TYPE (gi_constant_info, GI_INFO_TYPE_CONSTANT) GI_DEFINE_BASE_INFO_TYPE (gi_value_info, GI_INFO_TYPE_VALUE) GI_DEFINE_BASE_INFO_TYPE (gi_signal_info, GI_INFO_TYPE_SIGNAL) @@ -295,6 +296,7 @@ gi_base_info_init_types (void) { GI_INFO_TYPE_FLAGS, "GIFlagsInfo", sizeof (GIFlagsInfo), gi_flags_info_class_init, GI_INFO_TYPE_ENUM, G_TYPE_FLAG_NONE }, { GI_INFO_TYPE_OBJECT, "GIObjectInfo", sizeof (GIObjectInfo), gi_object_info_class_init, 0, G_TYPE_FLAG_NONE }, { GI_INFO_TYPE_INTERFACE, "GIInterfaceInfo", sizeof (GIInterfaceInfo), gi_interface_info_class_init, 0, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_BOXED, "GIBoxedInfo", sizeof (GIBoxedInfo), gi_boxed_info_class_init, 0, G_TYPE_FLAG_NONE }, { GI_INFO_TYPE_CONSTANT, "GIConstantInfo", sizeof (GIConstantInfo), gi_constant_info_class_init, 0, G_TYPE_FLAG_NONE }, { GI_INFO_TYPE_VALUE, "GIValueInfo", sizeof (GIValueInfo), gi_value_info_class_init, 0, G_TYPE_FLAG_NONE }, { GI_INFO_TYPE_SIGNAL, "GISignalInfo", sizeof (GISignalInfo), gi_signal_info_class_init, GI_INFO_TYPE_CALLABLE, G_TYPE_FLAG_NONE }, diff --git a/girepository/giboxedinfo.c b/girepository/giboxedinfo.c new file mode 100644 index 000000000..36921e31a --- /dev/null +++ b/girepository/giboxedinfo.c @@ -0,0 +1,52 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * GObject introspection: Boxed type implementation + * + * Copyright 2024 GNOME Foundation, Inc. + * + * SPDX-License-Identifier: LGPL-2.1-or-later + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include + +#include +#include "gibaseinfo-private.h" +#include "girepository-private.h" +#include "gitypelib-internal.h" +#include "giboxedinfo.h" + +/** + * GIBoxedInfo: + * + * A `GIBoxedInfo` represents a boxed type. + * + * There isn’t much you can do with a boxed type; `GIBoxedInfo` exists mainly to + * tag the type. + * + * Since: 2.80 + */ + +void +gi_boxed_info_class_init (gpointer g_class, + gpointer class_data) +{ + GIBaseInfoClass *info_class = g_class; + + info_class->info_type = GI_INFO_TYPE_BOXED; +} diff --git a/girepository/giboxedinfo.h b/girepository/giboxedinfo.h new file mode 100644 index 000000000..0136b065e --- /dev/null +++ b/girepository/giboxedinfo.h @@ -0,0 +1,46 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * GObject introspection: Boxed types + * + * Copyright 2024 GNOME Foundation, Inc. + * + * SPDX-License-Identifier: LGPL-2.1-or-later + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#pragma once + +#if !defined (__GIREPOSITORY_H_INSIDE__) && !defined (GI_COMPILATION) +#error "Only can be included directly." +#endif + +#include + +G_BEGIN_DECLS + +#define GI_TYPE_BOXED_INFO (gi_boxed_info_get_type ()) + +/** + * GI_IS_BOXED_INFO: + * @info: an info structure + * + * Checks if @info is a [class@GIRepository.BoxedInfo] (or a derived type). + * + * Since: 2.80 + */ +#define GI_IS_BOXED_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_BOXED_INFO)) + +G_END_DECLS diff --git a/girepository/girepository-private.h b/girepository/girepository-private.h index 5c7c1fb3f..7fe8211dd 100644 --- a/girepository/girepository-private.h +++ b/girepository/girepository-private.h @@ -132,12 +132,20 @@ void gi_object_info_class_init (gpointer g_class, struct _GIInterfaceInfo { - GIBaseInfo parent; + GIRegisteredTypeInfo parent; }; void gi_interface_info_class_init (gpointer g_class, gpointer class_data); +struct _GIBoxedInfo +{ + GIBaseInfo parent; +}; + +void gi_boxed_info_class_init (gpointer g_class, + gpointer class_data); + struct _GIConstantInfo { GIBaseInfo parent; diff --git a/girepository/girepository.h b/girepository/girepository.h index 4588ca981..f430e95aa 100644 --- a/girepository/girepository.h +++ b/girepository/girepository.h @@ -33,6 +33,7 @@ #include #include +#include #include #include #include diff --git a/girepository/gitypes.h b/girepository/gitypes.h index 7ddd1a906..587b8ec7f 100644 --- a/girepository/gitypes.h +++ b/girepository/gitypes.h @@ -81,6 +81,10 @@ GI_AVAILABLE_IN_ALL GType gi_object_info_get_type (void); typedef struct _GIInterfaceInfo GIInterfaceInfo; GI_AVAILABLE_IN_ALL GType gi_interface_info_get_type (void); +/* Documented in giboxedinfo.c */ +typedef struct _GIBoxedInfo GIBoxedInfo; +GI_AVAILABLE_IN_ALL GType gi_boxed_info_get_type (void); + /* Documented in giconstantinfo.c */ typedef struct _GIConstantInfo GIConstantInfo; GI_AVAILABLE_IN_ALL GType gi_constant_info_get_type (void); diff --git a/girepository/meson.build b/girepository/meson.build index 3f03a8c03..f6086305a 100644 --- a/girepository/meson.build +++ b/girepository/meson.build @@ -44,6 +44,7 @@ gi_visibility_h = custom_target( girepo_headers = files( 'giarginfo.h', 'gibaseinfo.h', + 'giboxedinfo.h', 'gicallableinfo.h', 'gicallbackinfo.h', 'giconstantinfo.h', @@ -145,6 +146,7 @@ girepo_sources = files( 'gdump.c', 'giarginfo.c', 'gibaseinfo.c', + 'giboxedinfo.c', 'gicallableinfo.c', 'gicallbackinfo.c', 'giconstantinfo.c', From a99a35ab398a62ae0bae222b40e5ef2140a3f798 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 17 Jan 2024 15:39:48 +0000 Subject: [PATCH 08/14] giregisteredtypeinfo: Make abstract and add subtypes There are various info types which were previously treated as subtypes of `GIRegisteredTypeInfo` by the runtime type system in the old version of libgirepository. Change the new type tree to reflect that, making several types now be subtypes of `GIRegisteredTypeInfo`, and making `GIRegisteredTypeInfo` abstract. Signed-off-by: Philip Withnall Helps: #3216 --- girepository/gibaseinfo.c | 14 +++++++------- girepository/girepository-private.h | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/girepository/gibaseinfo.c b/girepository/gibaseinfo.c index 3427a17b5..e6454c100 100644 --- a/girepository/gibaseinfo.c +++ b/girepository/gibaseinfo.c @@ -289,14 +289,14 @@ gi_base_info_init_types (void) { GI_INFO_TYPE_CALLABLE, "GICallableInfo", sizeof (GICallableInfo), gi_callable_info_class_init, 0, G_TYPE_FLAG_ABSTRACT }, { GI_INFO_TYPE_FUNCTION, "GIFunctionInfo", sizeof (GIFunctionInfo), gi_function_info_class_init, GI_INFO_TYPE_CALLABLE, G_TYPE_FLAG_NONE }, { GI_INFO_TYPE_CALLBACK, "GICallbackInfo", sizeof (GICallbackInfo), gi_callback_info_class_init, GI_INFO_TYPE_CALLABLE, G_TYPE_FLAG_NONE }, - { GI_INFO_TYPE_REGISTERED_TYPE, "GIRegisteredTypeInfo", sizeof (GIRegisteredTypeInfo), gi_registered_type_info_class_init, 0, G_TYPE_FLAG_NONE }, - { GI_INFO_TYPE_STRUCT, "GIStructInfo", sizeof (GIStructInfo), gi_struct_info_class_init, 0, G_TYPE_FLAG_NONE }, - { GI_INFO_TYPE_UNION, "GIUnionInfo", sizeof (GIUnionInfo), gi_union_info_class_init, 0, G_TYPE_FLAG_NONE }, - { GI_INFO_TYPE_ENUM, "GIEnumInfo", sizeof (GIEnumInfo), gi_enum_info_class_init, 0, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_REGISTERED_TYPE, "GIRegisteredTypeInfo", sizeof (GIRegisteredTypeInfo), gi_registered_type_info_class_init, 0, G_TYPE_FLAG_ABSTRACT }, + { GI_INFO_TYPE_STRUCT, "GIStructInfo", sizeof (GIStructInfo), gi_struct_info_class_init, GI_INFO_TYPE_REGISTERED_TYPE, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_UNION, "GIUnionInfo", sizeof (GIUnionInfo), gi_union_info_class_init, GI_INFO_TYPE_REGISTERED_TYPE, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_ENUM, "GIEnumInfo", sizeof (GIEnumInfo), gi_enum_info_class_init, GI_INFO_TYPE_REGISTERED_TYPE, G_TYPE_FLAG_NONE }, { GI_INFO_TYPE_FLAGS, "GIFlagsInfo", sizeof (GIFlagsInfo), gi_flags_info_class_init, GI_INFO_TYPE_ENUM, G_TYPE_FLAG_NONE }, - { GI_INFO_TYPE_OBJECT, "GIObjectInfo", sizeof (GIObjectInfo), gi_object_info_class_init, 0, G_TYPE_FLAG_NONE }, - { GI_INFO_TYPE_INTERFACE, "GIInterfaceInfo", sizeof (GIInterfaceInfo), gi_interface_info_class_init, 0, G_TYPE_FLAG_NONE }, - { GI_INFO_TYPE_BOXED, "GIBoxedInfo", sizeof (GIBoxedInfo), gi_boxed_info_class_init, 0, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_OBJECT, "GIObjectInfo", sizeof (GIObjectInfo), gi_object_info_class_init, GI_INFO_TYPE_REGISTERED_TYPE, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_INTERFACE, "GIInterfaceInfo", sizeof (GIInterfaceInfo), gi_interface_info_class_init, GI_INFO_TYPE_REGISTERED_TYPE, G_TYPE_FLAG_NONE }, + { GI_INFO_TYPE_BOXED, "GIBoxedInfo", sizeof (GIBoxedInfo), gi_boxed_info_class_init, GI_INFO_TYPE_REGISTERED_TYPE, G_TYPE_FLAG_NONE }, { GI_INFO_TYPE_CONSTANT, "GIConstantInfo", sizeof (GIConstantInfo), gi_constant_info_class_init, 0, G_TYPE_FLAG_NONE }, { GI_INFO_TYPE_VALUE, "GIValueInfo", sizeof (GIValueInfo), gi_value_info_class_init, 0, G_TYPE_FLAG_NONE }, { GI_INFO_TYPE_SIGNAL, "GISignalInfo", sizeof (GISignalInfo), gi_signal_info_class_init, GI_INFO_TYPE_CALLABLE, G_TYPE_FLAG_NONE }, diff --git a/girepository/girepository-private.h b/girepository/girepository-private.h index 7fe8211dd..c1e16eb0e 100644 --- a/girepository/girepository-private.h +++ b/girepository/girepository-private.h @@ -92,7 +92,7 @@ void gi_registered_type_info_class_init (gpointer g_class, struct _GIStructInfo { - GIBaseInfo parent; + GIRegisteredTypeInfo parent; }; void gi_struct_info_class_init (gpointer g_class, @@ -100,7 +100,7 @@ void gi_struct_info_class_init (gpointer g_class, struct _GIUnionInfo { - GIBaseInfo parent; + GIRegisteredTypeInfo parent; }; void gi_union_info_class_init (gpointer g_class, @@ -108,7 +108,7 @@ void gi_union_info_class_init (gpointer g_class, struct _GIEnumInfo { - GIBaseInfo parent; + GIRegisteredTypeInfo parent; }; void gi_enum_info_class_init (gpointer g_class, @@ -124,7 +124,7 @@ void gi_flags_info_class_init (gpointer g_class, struct _GIObjectInfo { - GIBaseInfo parent; + GIRegisteredTypeInfo parent; }; void gi_object_info_class_init (gpointer g_class, @@ -140,7 +140,7 @@ void gi_interface_info_class_init (gpointer g_class, struct _GIBoxedInfo { - GIBaseInfo parent; + GIRegisteredTypeInfo parent; }; void gi_boxed_info_class_init (gpointer g_class, From 5423bf4df7fa5a60a0dac4d1d7885f1f4b74db92 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 17 Jan 2024 15:43:47 +0000 Subject: [PATCH 09/14] girepository: Rework IS_(type) macros to use G_TYPE_CHECK_INSTANCE_TYPE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This means they’re now using the `GType` type system rather than the old `GIInfoType` type system. Given the preceding few commits, these two systems should now be equivalent. This makes the type handling more conventional and hence a bit simpler for people to use if they have experience with GObject. Signed-off-by: Philip Withnall Helps: #3216 --- girepository/giarginfo.h | 5 ++--- girepository/gibaseinfo.h | 10 ++++++++++ girepository/gicallableinfo.h | 6 +----- girepository/gicallbackinfo.h | 3 +-- girepository/giconstantinfo.h | 5 ++--- girepository/gienuminfo.h | 6 ++---- girepository/gifieldinfo.h | 5 ++--- girepository/gifunctioninfo.h | 5 ++--- girepository/giinterfaceinfo.h | 5 ++--- girepository/giobjectinfo.h | 5 ++--- girepository/gipropertyinfo.h | 5 ++--- girepository/giregisteredtypeinfo.h | 10 +--------- girepository/gisignalinfo.h | 5 ++--- girepository/gistructinfo.h | 5 ++--- girepository/gitypeinfo.h | 5 ++--- girepository/giunioninfo.h | 5 ++--- girepository/giunresolvedinfo.h | 3 +-- girepository/givalueinfo.h | 5 ++--- girepository/givfuncinfo.h | 5 ++--- 19 files changed, 42 insertions(+), 61 deletions(-) diff --git a/girepository/giarginfo.h b/girepository/giarginfo.h index 316ad1b84..55d521f67 100644 --- a/girepository/giarginfo.h +++ b/girepository/giarginfo.h @@ -38,12 +38,11 @@ G_BEGIN_DECLS * GI_IS_ARG_INFO: * @info: an info structure * - * Checks if @info is a [class@GIRepository.ArgInfo]. + * Checks if @info is a [class@GIRepository.ArgInfo] (or a derived type). * * Since: 2.80 */ -#define GI_IS_ARG_INFO(info) \ - (gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_ARG) +#define GI_IS_ARG_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_ARG_INFO)) GI_AVAILABLE_IN_ALL diff --git a/girepository/gibaseinfo.h b/girepository/gibaseinfo.h index 25a61d52b..c28fcb7ba 100644 --- a/girepository/gibaseinfo.h +++ b/girepository/gibaseinfo.h @@ -50,6 +50,16 @@ typedef struct { #define GI_TYPE_BASE_INFO (gi_base_info_get_type ()) +/** + * GI_IS_BASE_INFO: + * @info: Instance to check for being a `GI_TYPE_BASE_INFO`. + * + * Checks whether a valid [type@GObject.TypeInstance] pointer is of type + * `GI_TYPE_BASE_INFO` (or a derived type). + * + * Since: 2.80 + */ +#define GI_IS_BASE_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_BASE_INFO)) GI_AVAILABLE_IN_ALL GType gi_base_info_get_type (void) G_GNUC_CONST; diff --git a/girepository/gicallableinfo.h b/girepository/gicallableinfo.h index 95717fd44..359655583 100644 --- a/girepository/gicallableinfo.h +++ b/girepository/gicallableinfo.h @@ -42,11 +42,7 @@ G_BEGIN_DECLS * * Since: 2.80 */ -#define GI_IS_CALLABLE_INFO(info) \ - ((gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_FUNCTION) || \ - (gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_CALLBACK) || \ - (gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_SIGNAL) || \ - (gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_VFUNC)) +#define GI_IS_CALLABLE_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_CALLABLE_INFO)) GI_AVAILABLE_IN_ALL diff --git a/girepository/gicallbackinfo.h b/girepository/gicallbackinfo.h index f678d9f20..aebfd3353 100644 --- a/girepository/gicallbackinfo.h +++ b/girepository/gicallbackinfo.h @@ -41,7 +41,6 @@ G_BEGIN_DECLS * * Since: 2.80 */ -#define GI_IS_CALLBACK_INFO(info) \ - (gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_CALLBACK) +#define GI_IS_CALLBACK_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_CALLBACK_INFO)) G_END_DECLS diff --git a/girepository/giconstantinfo.h b/girepository/giconstantinfo.h index 5bfbde5a4..43cb7a803 100644 --- a/girepository/giconstantinfo.h +++ b/girepository/giconstantinfo.h @@ -38,12 +38,11 @@ G_BEGIN_DECLS * GI_IS_CONSTANT_INFO: * @info: an info structure * - * Checks if @info is a [class@GIRepository.ConstantInfo]. + * Checks if @info is a [class@GIRepository.ConstantInfo] (or a derived type). * * Since: 2.80 */ -#define GI_IS_CONSTANT_INFO(info) \ - (gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_CONSTANT) +#define GI_IS_CONSTANT_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_CONSTANT_INFO)) GI_AVAILABLE_IN_ALL diff --git a/girepository/gienuminfo.h b/girepository/gienuminfo.h index 8320e3e26..8590e3b1e 100644 --- a/girepository/gienuminfo.h +++ b/girepository/gienuminfo.h @@ -38,13 +38,11 @@ G_BEGIN_DECLS * GI_IS_ENUM_INFO: * @info: an info structure * - * Checks if @info is a [class@GIRepository.EnumInfo]. + * Checks if @info is a [class@GIRepository.EnumInfo] (or a derived type). * * Since: 2.80 */ -#define GI_IS_ENUM_INFO(info) \ - ((gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_ENUM) || \ - (gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_FLAGS)) +#define GI_IS_ENUM_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_ENUM_INFO)) GI_AVAILABLE_IN_ALL diff --git a/girepository/gifieldinfo.h b/girepository/gifieldinfo.h index c42a4d221..d8e61c0c4 100644 --- a/girepository/gifieldinfo.h +++ b/girepository/gifieldinfo.h @@ -38,12 +38,11 @@ G_BEGIN_DECLS * GI_IS_FIELD_INFO: * @info: an info structure * - * Checks if @info is a [class@GIRepository.FieldInfo]. + * Checks if @info is a [class@GIRepository.FieldInfo] (or a derived type). * * Since: 2.80 */ -#define GI_IS_FIELD_INFO(info) \ - (gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_FIELD) +#define GI_IS_FIELD_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_FIELD_INFO)) GI_AVAILABLE_IN_ALL diff --git a/girepository/gifunctioninfo.h b/girepository/gifunctioninfo.h index 98aec1c82..8bf18f761 100644 --- a/girepository/gifunctioninfo.h +++ b/girepository/gifunctioninfo.h @@ -38,12 +38,11 @@ G_BEGIN_DECLS * GI_IS_FUNCTION_INFO: * @info: an info structure * - * Checks if @info is a [class@GIRepository.FunctionInfo]. + * Checks if @info is a [class@GIRepository.FunctionInfo] (or a derived type). * * Since: 2.80 */ -#define GI_IS_FUNCTION_INFO(info) \ - (gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_FUNCTION) +#define GI_IS_FUNCTION_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_FUNCTION_INFO)) GI_AVAILABLE_IN_ALL diff --git a/girepository/giinterfaceinfo.h b/girepository/giinterfaceinfo.h index 0d6c7519b..2d44aa816 100644 --- a/girepository/giinterfaceinfo.h +++ b/girepository/giinterfaceinfo.h @@ -38,12 +38,11 @@ G_BEGIN_DECLS * GI_IS_INTERFACE_INFO: * @info: an info structure * - * Checks if @info is a [class@GIRepository.InterfaceInfo]. + * Checks if @info is a [class@GIRepository.InterfaceInfo] (or a derived type). * * Since: 2.80 */ -#define GI_IS_INTERFACE_INFO(info) \ - (gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_INTERFACE) +#define GI_IS_INTERFACE_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_INTERFACE_INFO)) GI_AVAILABLE_IN_ALL diff --git a/girepository/giobjectinfo.h b/girepository/giobjectinfo.h index af85fa9d3..33666ceba 100644 --- a/girepository/giobjectinfo.h +++ b/girepository/giobjectinfo.h @@ -81,12 +81,11 @@ typedef void * (*GIObjectInfoGetValueFunction) (const GValue *value); * GI_IS_OBJECT_INFO: * @info: an info structure * - * Checks if @info is a [class@GIRepository.ObjectInfo]. + * Checks if @info is a [class@GIRepository.ObjectInfo] (or a derived type). * * Since: 2.80 */ -#define GI_IS_OBJECT_INFO(info) \ - (gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_OBJECT) +#define GI_IS_OBJECT_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_OBJECT_INFO)) GI_AVAILABLE_IN_ALL diff --git a/girepository/gipropertyinfo.h b/girepository/gipropertyinfo.h index 34144953e..bff8d1b8f 100644 --- a/girepository/gipropertyinfo.h +++ b/girepository/gipropertyinfo.h @@ -38,12 +38,11 @@ G_BEGIN_DECLS * GI_IS_PROPERTY_INFO: * @info: an info structure * - * Checks if @info is a [class@GIRepository.PropertyInfo]. + * Checks if @info is a [class@GIRepository.PropertyInfo] (or a derived type). * * Since: 2.80 */ -#define GI_IS_PROPERTY_INFO(info) \ - (gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_PROPERTY) +#define GI_IS_PROPERTY_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_PROPERTY_INFO)) GI_AVAILABLE_IN_ALL diff --git a/girepository/giregisteredtypeinfo.h b/girepository/giregisteredtypeinfo.h index 6a5a2508f..4eee5cf74 100644 --- a/girepository/giregisteredtypeinfo.h +++ b/girepository/giregisteredtypeinfo.h @@ -44,15 +44,7 @@ G_BEGIN_DECLS * * Since: 2.80 */ -#define GI_IS_REGISTERED_TYPE_INFO(info) \ - ((gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_BOXED) || \ - (gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_ENUM) || \ - (gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_FLAGS) || \ - (gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_INTERFACE) || \ - (gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_OBJECT) || \ - (gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_STRUCT) || \ - (gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_UNION) || \ - (gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_BOXED)) +#define GI_IS_REGISTERED_TYPE_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_OBJECT_INFO)) GI_AVAILABLE_IN_ALL const char * gi_registered_type_info_get_type_name (GIRegisteredTypeInfo *info); diff --git a/girepository/gisignalinfo.h b/girepository/gisignalinfo.h index b07ad303d..48e74cbec 100644 --- a/girepository/gisignalinfo.h +++ b/girepository/gisignalinfo.h @@ -39,12 +39,11 @@ G_BEGIN_DECLS * GI_IS_SIGNAL_INFO: * @info: an info structure * - * Checks if @info is a [class@GIRepository.SignalInfo]. + * Checks if @info is a [class@GIRepository.SignalInfo] (or a derived type). * * Since: 2.80 */ -#define GI_IS_SIGNAL_INFO(info) \ - (gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_SIGNAL) +#define GI_IS_SIGNAL_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_SIGNAL_INFO)) GI_AVAILABLE_IN_ALL diff --git a/girepository/gistructinfo.h b/girepository/gistructinfo.h index 97ccf15f8..35a88ad80 100644 --- a/girepository/gistructinfo.h +++ b/girepository/gistructinfo.h @@ -38,12 +38,11 @@ G_BEGIN_DECLS * GI_IS_STRUCT_INFO: * @info: an info structure * - * Checks if @info is a [class@GIRepository.StructInfo]. + * Checks if @info is a [class@GIRepository.StructInfo] (or a derived type). * * Since: 2.80 */ -#define GI_IS_STRUCT_INFO(info) \ - (gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_STRUCT) +#define GI_IS_STRUCT_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_STRUCT_INFO)) GI_AVAILABLE_IN_ALL diff --git a/girepository/gitypeinfo.h b/girepository/gitypeinfo.h index df249e330..0e29feec5 100644 --- a/girepository/gitypeinfo.h +++ b/girepository/gitypeinfo.h @@ -38,12 +38,11 @@ G_BEGIN_DECLS * GI_IS_TYPE_INFO: * @info: an info structure * - * Checks if @info is a [alias@GIRepository.TypeInfo]. + * Checks if @info is a [alias@GIRepository.TypeInfo] (or a derived type). * * Since: 2.80 */ -#define GI_IS_TYPE_INFO(info) \ - (gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_TYPE) +#define GI_IS_TYPE_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_TYPE_INFO)) /** * GI_TYPE_TAG_IS_BASIC: diff --git a/girepository/giunioninfo.h b/girepository/giunioninfo.h index 0341bff21..bbc3b976e 100644 --- a/girepository/giunioninfo.h +++ b/girepository/giunioninfo.h @@ -38,12 +38,11 @@ G_BEGIN_DECLS * GI_IS_UNION_INFO: * @info: an info structure * - * Checks if @info is a [struct@GIRepository.UnionInfo]. + * Checks if @info is a [struct@GIRepository.UnionInfo] (or a derived type). * * Since: 2.80 */ -#define GI_IS_UNION_INFO(info) \ - (gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_UNION) +#define GI_IS_UNION_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_UNION_INFO)) GI_AVAILABLE_IN_ALL unsigned int gi_union_info_get_n_fields (GIUnionInfo *info); diff --git a/girepository/giunresolvedinfo.h b/girepository/giunresolvedinfo.h index 29c629f48..e0d7ea8b6 100644 --- a/girepository/giunresolvedinfo.h +++ b/girepository/giunresolvedinfo.h @@ -41,7 +41,6 @@ G_BEGIN_DECLS * * Since: 2.80 */ -#define GI_IS_UNRESOLVED_INFO(info) \ - (gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_UNRESOLVED) +#define GI_IS_UNRESOLVED_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_UNRESOLVED_INFO)) G_END_DECLS diff --git a/girepository/givalueinfo.h b/girepository/givalueinfo.h index 7f1ebb275..52bc4c845 100644 --- a/girepository/givalueinfo.h +++ b/girepository/givalueinfo.h @@ -38,12 +38,11 @@ G_BEGIN_DECLS * GI_IS_VALUE_INFO: * @info: an info structure * - * Checks if @info is a [class@GIRepository.ValueInfo]. + * Checks if @info is a [class@GIRepository.ValueInfo] (or a derived type). * * Since: 2.80 */ -#define GI_IS_VALUE_INFO(info) \ - (gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_VALUE) +#define GI_IS_VALUE_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_VALUE_INFO)) GI_AVAILABLE_IN_ALL diff --git a/girepository/givfuncinfo.h b/girepository/givfuncinfo.h index 31fea50bf..79f164c4a 100644 --- a/girepository/givfuncinfo.h +++ b/girepository/givfuncinfo.h @@ -38,12 +38,11 @@ G_BEGIN_DECLS * GI_IS_VFUNC_INFO: * @info: an info structure * - * Checks if @info is a [struct@GIRepository.VFuncInfo]. + * Checks if @info is a [struct@GIRepository.VFuncInfo] (or a derived type). * * Since: 2.80 */ -#define GI_IS_VFUNC_INFO(info) \ - (gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_VFUNC) +#define GI_IS_VFUNC_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_VFUNC_INFO)) GI_AVAILABLE_IN_ALL GIVFuncInfoFlags gi_vfunc_info_get_flags (GIVFuncInfo *info); From 9debaffe0e77e5bb7732a47205c73362f79d77bf Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 17 Jan 2024 12:30:35 +0000 Subject: [PATCH 10/14] gibaseinfo: Remove need for casting for gi_base_info_ref() and unref() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Helps: #3216 --- girepository/gibaseinfo.c | 12 ++++++++---- girepository/gibaseinfo.h | 4 ++-- girepository/tests/repository.c | 8 ++++---- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/girepository/gibaseinfo.c b/girepository/gibaseinfo.c index e6454c100..19406ac83 100644 --- a/girepository/gibaseinfo.c +++ b/girepository/gibaseinfo.c @@ -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)) diff --git a/girepository/gibaseinfo.h b/girepository/gibaseinfo.h index c28fcb7ba..eb4fff9b1 100644 --- a/girepository/gibaseinfo.h +++ b/girepository/gibaseinfo.h @@ -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); diff --git a/girepository/tests/repository.c b/girepository/tests/repository.c index c74d66605..eb8c2208d 100644 --- a/girepository/tests/repository.c +++ b/girepository/tests/repository.c @@ -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); } From 57d64b111f12cbb6d97642eaba0ac3735b9281db Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Wed, 17 Jan 2024 16:40:18 +0000 Subject: [PATCH 11/14] girepository: Add type-checking cast macros MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Fixes: #3216 --- girepository/giarginfo.h | 14 ++++++++++++++ girepository/gibaseinfo.h | 14 ++++++++++++++ girepository/giboxedinfo.h | 14 ++++++++++++++ girepository/gicallableinfo.h | 14 ++++++++++++++ girepository/gicallbackinfo.h | 14 ++++++++++++++ girepository/giconstantinfo.h | 14 ++++++++++++++ girepository/gienuminfo.h | 14 ++++++++++++++ girepository/gifieldinfo.h | 14 ++++++++++++++ girepository/giflagsinfo.h | 14 ++++++++++++++ girepository/gifunctioninfo.h | 14 ++++++++++++++ girepository/giinterfaceinfo.h | 14 ++++++++++++++ girepository/giobjectinfo.h | 14 ++++++++++++++ girepository/gipropertyinfo.h | 14 ++++++++++++++ girepository/giregisteredtypeinfo.h | 14 ++++++++++++++ girepository/gisignalinfo.h | 14 ++++++++++++++ girepository/gistructinfo.h | 14 ++++++++++++++ girepository/gitypeinfo.h | 14 ++++++++++++++ girepository/giunioninfo.h | 14 ++++++++++++++ girepository/giunresolvedinfo.h | 14 ++++++++++++++ girepository/givalueinfo.h | 14 ++++++++++++++ girepository/givfuncinfo.h | 14 ++++++++++++++ 21 files changed, 294 insertions(+) diff --git a/girepository/giarginfo.h b/girepository/giarginfo.h index 55d521f67..5223f2517 100644 --- a/girepository/giarginfo.h +++ b/girepository/giarginfo.h @@ -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 diff --git a/girepository/gibaseinfo.h b/girepository/gibaseinfo.h index eb4fff9b1..3a96076da 100644 --- a/girepository/gibaseinfo.h +++ b/girepository/gibaseinfo.h @@ -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`. diff --git a/girepository/giboxedinfo.h b/girepository/giboxedinfo.h index 0136b065e..f94987e13 100644 --- a/girepository/giboxedinfo.h +++ b/girepository/giboxedinfo.h @@ -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 diff --git a/girepository/gicallableinfo.h b/girepository/gicallableinfo.h index 359655583..293f52104 100644 --- a/girepository/gicallableinfo.h +++ b/girepository/gicallableinfo.h @@ -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 diff --git a/girepository/gicallbackinfo.h b/girepository/gicallbackinfo.h index aebfd3353..8f5590230 100644 --- a/girepository/gicallbackinfo.h +++ b/girepository/gicallbackinfo.h @@ -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 diff --git a/girepository/giconstantinfo.h b/girepository/giconstantinfo.h index 43cb7a803..eda69895b 100644 --- a/girepository/giconstantinfo.h +++ b/girepository/giconstantinfo.h @@ -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 diff --git a/girepository/gienuminfo.h b/girepository/gienuminfo.h index 8590e3b1e..fcd220590 100644 --- a/girepository/gienuminfo.h +++ b/girepository/gienuminfo.h @@ -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 diff --git a/girepository/gifieldinfo.h b/girepository/gifieldinfo.h index d8e61c0c4..e3d13724a 100644 --- a/girepository/gifieldinfo.h +++ b/girepository/gifieldinfo.h @@ -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 diff --git a/girepository/giflagsinfo.h b/girepository/giflagsinfo.h index 9dc76a822..1070eff87 100644 --- a/girepository/giflagsinfo.h +++ b/girepository/giflagsinfo.h @@ -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 diff --git a/girepository/gifunctioninfo.h b/girepository/gifunctioninfo.h index 8bf18f761..ce7dd9e3c 100644 --- a/girepository/gifunctioninfo.h +++ b/girepository/gifunctioninfo.h @@ -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 diff --git a/girepository/giinterfaceinfo.h b/girepository/giinterfaceinfo.h index 2d44aa816..9cb0d4e6e 100644 --- a/girepository/giinterfaceinfo.h +++ b/girepository/giinterfaceinfo.h @@ -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 diff --git a/girepository/giobjectinfo.h b/girepository/giobjectinfo.h index 33666ceba..8065612ce 100644 --- a/girepository/giobjectinfo.h +++ b/girepository/giobjectinfo.h @@ -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 diff --git a/girepository/gipropertyinfo.h b/girepository/gipropertyinfo.h index bff8d1b8f..a21831a70 100644 --- a/girepository/gipropertyinfo.h +++ b/girepository/gipropertyinfo.h @@ -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 diff --git a/girepository/giregisteredtypeinfo.h b/girepository/giregisteredtypeinfo.h index 4eee5cf74..4ee6455e4 100644 --- a/girepository/giregisteredtypeinfo.h +++ b/girepository/giregisteredtypeinfo.h @@ -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 diff --git a/girepository/gisignalinfo.h b/girepository/gisignalinfo.h index 48e74cbec..ebac506c7 100644 --- a/girepository/gisignalinfo.h +++ b/girepository/gisignalinfo.h @@ -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 diff --git a/girepository/gistructinfo.h b/girepository/gistructinfo.h index 35a88ad80..c9e82cea2 100644 --- a/girepository/gistructinfo.h +++ b/girepository/gistructinfo.h @@ -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 diff --git a/girepository/gitypeinfo.h b/girepository/gitypeinfo.h index 0e29feec5..65cb78238 100644 --- a/girepository/gitypeinfo.h +++ b/girepository/gitypeinfo.h @@ -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 diff --git a/girepository/giunioninfo.h b/girepository/giunioninfo.h index bbc3b976e..6826c7b1f 100644 --- a/girepository/giunioninfo.h +++ b/girepository/giunioninfo.h @@ -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 diff --git a/girepository/giunresolvedinfo.h b/girepository/giunresolvedinfo.h index e0d7ea8b6..9eeb7618a 100644 --- a/girepository/giunresolvedinfo.h +++ b/girepository/giunresolvedinfo.h @@ -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 diff --git a/girepository/givalueinfo.h b/girepository/givalueinfo.h index 52bc4c845..7eb7cce54 100644 --- a/girepository/givalueinfo.h +++ b/girepository/givalueinfo.h @@ -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 diff --git a/girepository/givfuncinfo.h b/girepository/givfuncinfo.h index 79f164c4a..cbb8abec8 100644 --- a/girepository/givfuncinfo.h +++ b/girepository/givfuncinfo.h @@ -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 From 9aea530ac04a490648eda73ee5452a9385e33bdd Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 18 Jan 2024 12:27:46 +0000 Subject: [PATCH 12/14] gibaseinfo: Add initialiser macro for GIAttributeIter Makes it a little easier to use. Signed-off-by: Philip Withnall --- girepository/gibaseinfo.c | 4 ++-- girepository/gibaseinfo.h | 10 ++++++++++ girepository/gicallableinfo.c | 2 +- girepository/girwriter.c | 4 ++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/girepository/gibaseinfo.c b/girepository/gibaseinfo.c index 19406ac83..f656367a0 100644 --- a/girepository/gibaseinfo.c +++ b/girepository/gibaseinfo.c @@ -784,7 +784,7 @@ const char * gi_base_info_get_attribute (GIBaseInfo *info, const char *name) { - GIAttributeIter iter = { 0, }; + GIAttributeIter iter = GI_ATTRIBUTE_ITER_INIT; const char *curname, *curvalue; while (gi_base_info_iterate_attributes (info, &iter, &curname, &curvalue)) { @@ -872,7 +872,7 @@ _attribute_blob_find_first (GIBaseInfo *info, * void * print_attributes (GIBaseInfo *info) * { - * GIAttributeIter iter = { 0, }; + * GIAttributeIter iter = GI_ATTRIBUTE_ITER_INIT; * const char *name; * const char *value; * while (gi_base_info_iterate_attributes (info, &iter, &name, &value)) diff --git a/girepository/gibaseinfo.h b/girepository/gibaseinfo.h index 3a96076da..4e152fca6 100644 --- a/girepository/gibaseinfo.h +++ b/girepository/gibaseinfo.h @@ -48,6 +48,16 @@ typedef struct { void *_dummy[4]; } GIAttributeIter; +/** + * GI_ATTRIBUTE_ITER_INIT: + * + * Initialise a stack-allocated [type@GIRepository.AttributeIter] to a value + * suitable for passing to the first call to an ‘iterate’ function. + * + * Since: 2.80 + */ +#define GI_ATTRIBUTE_ITER_INIT { NULL, { NULL, } } + #define GI_TYPE_BASE_INFO (gi_base_info_get_type ()) /** diff --git a/girepository/gicallableinfo.c b/girepository/gicallableinfo.c index 17dbc50bd..098a1d3a0 100644 --- a/girepository/gicallableinfo.c +++ b/girepository/gicallableinfo.c @@ -426,7 +426,7 @@ const char * gi_callable_info_get_return_attribute (GICallableInfo *info, const char *name) { - GIAttributeIter iter = { 0, }; + GIAttributeIter iter = GI_ATTRIBUTE_ITER_INIT; const char *curname, *curvalue; while (gi_callable_info_iterate_return_attributes (info, &iter, &curname, &curvalue)) { diff --git a/girepository/girwriter.c b/girepository/girwriter.c index 0116795e4..84169f9d7 100644 --- a/girepository/girwriter.c +++ b/girepository/girwriter.c @@ -350,7 +350,7 @@ static void write_attributes (Xml *file, GIBaseInfo *info) { - GIAttributeIter iter = { 0, }; + GIAttributeIter iter = GI_ATTRIBUTE_ITER_INIT; const char *name, *value; while (gi_base_info_iterate_attributes (info, &iter, &name, &value)) @@ -365,7 +365,7 @@ static void write_return_value_attributes (Xml *file, GICallableInfo *info) { - GIAttributeIter iter = { 0, }; + GIAttributeIter iter = GI_ATTRIBUTE_ITER_INIT; const char *name, *value; while (gi_callable_info_iterate_return_attributes (info, &iter, &name, &value)) From 9cbe5ae67d0df1fcd3f601cab042e72f338cf9f4 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 18 Jan 2024 12:28:12 +0000 Subject: [PATCH 13/14] tests: Add tests for several GIBaseInfo subclasses They get at least these `GIBaseInfo` subclasses up to a reasonable (but not complete) coverage level. Signed-off-by: Philip Withnall --- girepository/tests/repository.c | 199 ++++++++++++++++++++++++++++++++ 1 file changed, 199 insertions(+) diff --git a/girepository/tests/repository.c b/girepository/tests/repository.c index eb8c2208d..d1ac86541 100644 --- a/girepository/tests/repository.c +++ b/girepository/tests/repository.c @@ -22,6 +22,30 @@ #include "glib.h" #include "girepository.h" +static GIRepository * +load_typelib_from_builddir (const char *name, + const char *version) +{ + GIRepository *repository; + char *gobject_typelib_dir = NULL; + GITypelib *typelib = NULL; + GError *local_error = NULL; + + gobject_typelib_dir = g_test_build_filename (G_TEST_BUILT, "..", "..", "introspection", NULL); + g_test_message ("Using GI_TYPELIB_DIR = %s", gobject_typelib_dir); + gi_repository_prepend_search_path (gobject_typelib_dir); + g_free (gobject_typelib_dir); + + repository = gi_repository_new (); + g_assert_nonnull (repository); + + typelib = gi_repository_require (repository, name, version, 0, &local_error); + g_assert_no_error (local_error); + g_assert_nonnull (typelib); + + return g_steal_pointer (&repository); +} + static void test_repository_basic (void) { @@ -161,6 +185,177 @@ test_repository_dependencies (void) g_clear_pointer (&dependencies, g_strfreev); } +static void +test_repository_arg_info (void) +{ + GIRepository *repository; + GIObjectInfo *object_info = NULL; + GIStructInfo *struct_info = NULL; + GIFunctionInfo *method_info = NULL; + GIArgInfo *arg_info = NULL; + GITypeInfo *type_info = NULL; + unsigned int idx; + + g_test_summary ("Test retrieving GIArgInfos from a typelib"); + + repository = load_typelib_from_builddir ("GObject", "2.0"); + + /* Test all the methods of GIArgInfo. Here we’re looking at the + * `const char *property_name` argument of g_object_get_property(). (The + * ‘self’ argument is not exposed through gi_callable_info_get_arg().) */ + object_info = (GIObjectInfo *) gi_repository_find_by_name (repository, "GObject", "Object"); + g_assert_nonnull (object_info); + + method_info = gi_object_info_find_method (object_info, "get_property"); + g_assert_nonnull (method_info); + + arg_info = gi_callable_info_get_arg (GI_CALLABLE_INFO (method_info), 0); + g_assert_nonnull (arg_info); + + g_assert_cmpint (gi_arg_info_get_direction (arg_info), ==, GI_DIRECTION_IN); + g_assert_false (gi_arg_info_is_return_value (arg_info)); + g_assert_false (gi_arg_info_is_optional (arg_info)); + g_assert_false (gi_arg_info_is_caller_allocates (arg_info)); + g_assert_false (gi_arg_info_may_be_null (arg_info)); + g_assert_false (gi_arg_info_is_skip (arg_info)); + g_assert_cmpint (gi_arg_info_get_ownership_transfer (arg_info), ==, GI_TRANSFER_NOTHING); + g_assert_cmpint (gi_arg_info_get_scope (arg_info), ==, GI_SCOPE_TYPE_INVALID); + g_assert_false (gi_arg_info_get_closure_index (arg_info, NULL)); + g_assert_false (gi_arg_info_get_closure_index (arg_info, &idx)); + g_assert_cmpuint (idx, ==, 0); + g_assert_false (gi_arg_info_get_destroy_index (arg_info, NULL)); + g_assert_false (gi_arg_info_get_destroy_index (arg_info, &idx)); + g_assert_cmpuint (idx, ==, 0); + + type_info = gi_arg_info_get_type_info (arg_info); + g_assert_nonnull (type_info); + g_assert_true (gi_type_info_is_pointer (type_info)); + g_assert_cmpint (gi_type_info_get_tag (type_info), ==, GI_TYPE_TAG_UTF8); + + g_clear_pointer (&type_info, gi_base_info_unref); + g_clear_pointer (&arg_info, gi_base_info_unref); + g_clear_pointer (&method_info, gi_base_info_unref); + g_clear_pointer (&object_info, gi_base_info_unref); + + /* Test an (out) argument. Here it’s the `guint *n_properties` from + * g_object_class_list_properties(). */ + struct_info = (GIStructInfo *) gi_repository_find_by_name (repository, "GObject", "ObjectClass"); + g_assert_nonnull (struct_info); + + method_info = gi_struct_info_find_method (struct_info, "list_properties"); + g_assert_nonnull (method_info); + + arg_info = gi_callable_info_get_arg (GI_CALLABLE_INFO (method_info), 0); + g_assert_nonnull (arg_info); + + g_assert_cmpint (gi_arg_info_get_direction (arg_info), ==, GI_DIRECTION_OUT); + g_assert_false (gi_arg_info_is_optional (arg_info)); + g_assert_false (gi_arg_info_is_caller_allocates (arg_info)); + g_assert_cmpint (gi_arg_info_get_ownership_transfer (arg_info), ==, GI_TRANSFER_EVERYTHING); + + g_clear_pointer (&arg_info, gi_base_info_unref); + g_clear_pointer (&method_info, gi_base_info_unref); + g_clear_pointer (&struct_info, gi_base_info_unref); + + g_clear_object (&repository); +} + +static void +test_repository_boxed_info (void) +{ + GIRepository *repository; + GIBoxedInfo *boxed_info = NULL; + + g_test_summary ("Test retrieving GIBoxedInfos from a typelib"); + + repository = load_typelib_from_builddir ("GObject", "2.0"); + + /* Test all the methods of GIBoxedInfo. This is simple, because there are none. */ + boxed_info = (GIBoxedInfo *) gi_repository_find_by_name (repository, "GObject", "BookmarkFile"); + g_assert_nonnull (boxed_info); + + g_clear_pointer (&boxed_info, gi_base_info_unref); + + g_clear_object (&repository); +} + +static void +test_repository_callable_info (void) +{ + GIRepository *repository; + GIObjectInfo *object_info = NULL; + GIFunctionInfo *method_info = NULL; + GICallableInfo *callable_info; + GITypeInfo *type_info = NULL; + GIAttributeIter iter = GI_ATTRIBUTE_ITER_INIT; + const char *name, *value; + GIArgInfo *arg_info = NULL; + + g_test_summary ("Test retrieving GICallableInfos from a typelib"); + + repository = load_typelib_from_builddir ("GObject", "2.0"); + + /* Test all the methods of GICallableInfo. Here we’re looking at + * g_object_get_qdata(). */ + object_info = (GIObjectInfo *) gi_repository_find_by_name (repository, "GObject", "Object"); + g_assert_nonnull (object_info); + + method_info = gi_object_info_find_method (object_info, "get_qdata"); + g_assert_nonnull (method_info); + + callable_info = GI_CALLABLE_INFO (method_info); + + g_assert_true (gi_callable_info_is_method (callable_info)); + g_assert_false (gi_callable_info_can_throw_gerror (callable_info)); + + type_info = gi_callable_info_get_return_type (callable_info); + g_assert_nonnull (type_info); + g_assert_true (gi_type_info_is_pointer (type_info)); + g_assert_cmpint (gi_type_info_get_tag (type_info), ==, GI_TYPE_TAG_VOID); + g_clear_pointer (&type_info, gi_base_info_unref); + + /* This method has no attributes */ + g_assert_false (gi_callable_info_iterate_return_attributes (callable_info, &iter, &name, &value)); + + g_assert_null (gi_callable_info_get_return_attribute (callable_info, "doesnt-exist")); + + g_assert_false (gi_callable_info_get_caller_owns (callable_info)); + g_assert_true (gi_callable_info_may_return_null (callable_info)); + g_assert_false (gi_callable_info_skip_return (callable_info)); + + g_assert_cmpuint (gi_callable_info_get_n_args (callable_info), ==, 1); + + arg_info = gi_callable_info_get_arg (callable_info, 0); + g_assert_nonnull (arg_info); + g_clear_pointer (&arg_info, gi_base_info_unref); + + g_assert_cmpint (gi_callable_info_get_instance_ownership_transfer (callable_info), ==, GI_TRANSFER_NOTHING); + + g_clear_pointer (&method_info, gi_base_info_unref); + g_clear_pointer (&object_info, gi_base_info_unref); + + g_clear_object (&repository); +} + +static void +test_repository_callback_info (void) +{ + GIRepository *repository; + GICallbackInfo *callback_info = NULL; + + g_test_summary ("Test retrieving GICallbackInfos from a typelib"); + + repository = load_typelib_from_builddir ("GObject", "2.0"); + + /* Test all the methods of GICallbackInfo. This is simple, because there are none. */ + callback_info = (GICallbackInfo *) gi_repository_find_by_name (repository, "GObject", "ObjectFinalizeFunc"); + g_assert_nonnull (callback_info); + + g_clear_pointer (&callback_info, gi_base_info_unref); + + g_clear_object (&repository); +} + int main (int argc, char *argv[]) @@ -174,6 +369,10 @@ main (int argc, g_test_add_func ("/repository/basic", test_repository_basic); g_test_add_func ("/repository/info", test_repository_info); g_test_add_func ("/repository/dependencies", test_repository_dependencies); + g_test_add_func ("/repository/arg-info", test_repository_arg_info); + g_test_add_func ("/repository/boxed-info", test_repository_boxed_info); + g_test_add_func ("/repository/callable-info", test_repository_callable_info); + g_test_add_func ("/repository/callback-info", test_repository_callback_info); return g_test_run (); } From 993eae63abd9f1c021abcb7bfacf3de036eb423f Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 18 Jan 2024 13:02:57 +0000 Subject: [PATCH 14/14] tests: Use g_assert_*() rather than g_assert() in gthash tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It won’t get compiled out with `G_DISABLE_ASSERT`. Signed-off-by: Philip Withnall --- girepository/tests/gthash.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/girepository/tests/gthash.c b/girepository/tests/gthash.c index 6c674c1da..8d927927d 100644 --- a/girepository/tests/gthash.c +++ b/girepository/tests/gthash.c @@ -39,8 +39,7 @@ test_build_retrieve (void) gi_typelib_hash_builder_add_string (builder, "VolumeMonitor", 9); gi_typelib_hash_builder_add_string (builder, "FileMonitorFlags", 31); - if (!gi_typelib_hash_builder_prepare (builder)) - g_assert_not_reached (); + g_assert_true (gi_typelib_hash_builder_prepare (builder)); bufsize = gi_typelib_hash_builder_get_buffer_size (builder); @@ -50,10 +49,10 @@ test_build_retrieve (void) gi_typelib_hash_builder_destroy (builder); - g_assert (gi_typelib_hash_search (buf, "Action", 4) == 0); - g_assert (gi_typelib_hash_search (buf, "ZLibDecompressor", 4) == 42); - g_assert (gi_typelib_hash_search (buf, "VolumeMonitor", 4) == 9); - g_assert (gi_typelib_hash_search (buf, "FileMonitorFlags", 4) == 31); + g_assert_cmpuint (gi_typelib_hash_search (buf, "Action", 4), ==, 0); + g_assert_cmpuint (gi_typelib_hash_search (buf, "ZLibDecompressor", 4), ==, 42); + g_assert_cmpuint (gi_typelib_hash_search (buf, "VolumeMonitor", 4), ==, 9); + g_assert_cmpuint (gi_typelib_hash_search (buf, "FileMonitorFlags", 4), ==, 31); g_free (buf); }