From 343027d5de38214932b04227a3a067879340eea1 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 8 Feb 2024 12:35:23 +0000 Subject: [PATCH] girepository: Make GIInfoType private MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Eventually, we want to move to using `GType` directly for everything, since `GIBaseInfo` and its subclasses are all using `GTypeInstance`. However, that requires quite a lot of changes and we’re about to hit the API freeze. So do the smallest set of changes possible to remove `GIInfoType` and related functions from the public API, which gives us freedom to make more changes later without breaking API. Signed-off-by: Philip Withnall Helps: #3155 --- docs/reference/girepository/migrating-gi.md | 5 +- girepository/gibaseinfo-private.h | 8 +++ girepository/gibaseinfo.c | 2 +- girepository/gibaseinfo.h | 9 --- girepository/gicallableinfo.c | 22 +++--- girepository/girepository-private.h | 80 +++++++++++++++++++++ girepository/girepository.c | 1 + girepository/girffi.c | 1 + girepository/girffi.h | 2 +- girepository/girnode.c | 2 +- girepository/girwriter.c | 2 + girepository/gitypeinfo.c | 5 +- girepository/gitypeinfo.h | 4 -- girepository/gitypes.h | 78 -------------------- girepository/tests/repository.c | 1 - 15 files changed, 110 insertions(+), 112 deletions(-) diff --git a/docs/reference/girepository/migrating-gi.md b/docs/reference/girepository/migrating-gi.md index db1226dca..28659afff 100644 --- a/docs/reference/girepository/migrating-gi.md +++ b/docs/reference/girepository/migrating-gi.md @@ -49,8 +49,8 @@ your code if integer type warnings are enabled. | `g_arg_info_get_type` | [method@GIRepository.ArgInfo.get_type_info] | | `g_arg_info_load_type` | [method@GIRepository.ArgInfo.load_type_info] | | - | [method@GIRepository.BaseInfo.ref] and [method@GIRepository.BaseInfo.unref] | -| `g_base_info_get_type` | [method@GIRepository.BaseInfo.get_info_type] | -| `g_info_new` | [ctor@GIRepository.BaseInfo.new] | +| `g_base_info_get_type` | Use type checking macros like [func@GIRepository.IS_OBJECT_INFO], or raw [type@GObject.Type]s with [func@GObject.TYPE_FROM_INSTANCE] | +| `g_info_new` | Removed with no replacement, use [method@GIRepository.find_by_name] and related APIs | | `g_callable_info_invoke` arguments | `is_method` and `throws` dropped in [method@GIRepository.CallableInfo.invoke] | | `g_constant_info_get_type` | [method@GIRepository.ConstantInfo.get_type_info] | | `g_field_info_get_type` | [method@GIRepository.FieldInfo.get_type_info] | @@ -79,3 +79,4 @@ your code if integer type warnings are enabled. | `g_union_info_get_discriminator_offset` | Split success and failure return values out into a new out-argument and return value | | `g_union_info_get_copy_function` | [method@GIRepository.UnionInfo.get_copy_function_name] | | `g_union_info_get_free_function` | [method@GIRepository.UnionInfo.get_free_function_name] | +| `GIInfoType` | Use [type@GObject.Type] directly | diff --git a/girepository/gibaseinfo-private.h b/girepository/gibaseinfo-private.h index aba0e19ed..96c77155a 100644 --- a/girepository/gibaseinfo-private.h +++ b/girepository/gibaseinfo-private.h @@ -26,6 +26,7 @@ #include #include +#include "girepository-private.h" #include "gitypes.h" G_BEGIN_DECLS @@ -50,4 +51,11 @@ GType gi_base_info_type_register_static (const char *type_name, GType parent_type, GTypeFlags type_flags); +GIInfoType gi_base_info_get_info_type (GIBaseInfo *info); + +GIBaseInfo * gi_base_info_new (GIInfoType type, + GIBaseInfo *container, + GITypelib *typelib, + size_t offset); + G_END_DECLS diff --git a/girepository/gibaseinfo.c b/girepository/gibaseinfo.c index 7351c8382..79f6a16e4 100644 --- a/girepository/gibaseinfo.c +++ b/girepository/gibaseinfo.c @@ -650,7 +650,7 @@ gi_base_info_get_info_type (GIBaseInfo *info) * * Obtain the name of the @info. * - * What the name represents depends on the [type@GIRepository.InfoType] of the + * What the name represents depends on the type of the * @info. For instance for [class@GIRepository.FunctionInfo] it is the name of * the function. * diff --git a/girepository/gibaseinfo.h b/girepository/gibaseinfo.h index 5787f9458..4f87b9f50 100644 --- a/girepository/gibaseinfo.h +++ b/girepository/gibaseinfo.h @@ -97,9 +97,6 @@ void gi_base_info_unref (void *info); GI_AVAILABLE_IN_ALL void gi_base_info_clear (void *info); -GI_AVAILABLE_IN_ALL -GIInfoType gi_base_info_get_info_type (GIBaseInfo *info); - GI_AVAILABLE_IN_ALL const char * gi_base_info_get_name (GIBaseInfo *info); @@ -129,10 +126,4 @@ GI_AVAILABLE_IN_ALL gboolean gi_base_info_equal (GIBaseInfo *info1, GIBaseInfo *info2); -GI_AVAILABLE_IN_ALL -GIBaseInfo * gi_base_info_new (GIInfoType type, - GIBaseInfo *container, - GITypelib *typelib, - size_t offset); - G_END_DECLS diff --git a/girepository/gicallableinfo.c b/girepository/gicallableinfo.c index 077ae4723..49430e9a8 100644 --- a/girepository/gicallableinfo.c +++ b/girepository/gicallableinfo.c @@ -502,7 +502,7 @@ gi_callable_info_iterate_return_attributes (GICallableInfo *info, /** * gi_type_tag_extract_ffi_return_value: * @return_tag: [type@GIRepository.TypeTag] of the return value - * @interface_type: [type@GIRepository.InfoType] of the underlying interface type + * @interface_type: [type@GObject.Type] of the underlying interface type * @ffi_value: pointer to [type@GIRepository.FFIReturnValue] union containing * the return value from `ffi_call()` * @arg: (out caller-allocates): pointer to an allocated @@ -523,7 +523,7 @@ gi_callable_info_iterate_return_attributes (GICallableInfo *info, */ void gi_type_tag_extract_ffi_return_value (GITypeTag return_tag, - GIInfoType interface_type, + GType interface_type, GIFFIReturnValue *ffi_value, GIArgument *arg) { @@ -561,15 +561,11 @@ gi_type_tag_extract_ffi_return_value (GITypeTag return_tag, arg->v_double = ffi_value->v_double; break; case GI_TYPE_TAG_INTERFACE: - switch(interface_type) { - case GI_INFO_TYPE_ENUM: - case GI_INFO_TYPE_FLAGS: - arg->v_int32 = (int32_t) ffi_value->v_long; - break; - default: - arg->v_pointer = (void *) ffi_value->v_pointer; - break; - } + if (interface_type == GI_TYPE_ENUM_INFO || + interface_type == GI_TYPE_FLAGS_INFO) + arg->v_int32 = (int32_t) ffi_value->v_long; + else + arg->v_pointer = (void *) ffi_value->v_pointer; break; default: arg->v_pointer = (void *) ffi_value->v_pointer; @@ -601,12 +597,12 @@ gi_type_info_extract_ffi_return_value (GITypeInfo *return_info, GIArgument *arg) { GITypeTag return_tag = gi_type_info_get_tag (return_info); - GIInfoType interface_type = GI_INFO_TYPE_INVALID; + GType interface_type = G_TYPE_INVALID; if (return_tag == GI_TYPE_TAG_INTERFACE) { GIBaseInfo *interface_info = gi_type_info_get_interface (return_info); - interface_type = gi_base_info_get_info_type (interface_info); + interface_type = G_TYPE_FROM_INSTANCE (interface_info); gi_base_info_unref (interface_info); } diff --git a/girepository/girepository-private.h b/girepository/girepository-private.h index b33c70149..8245e566c 100644 --- a/girepository/girepository-private.h +++ b/girepository/girepository-private.h @@ -66,6 +66,86 @@ struct _GIBaseInfo G_STATIC_ASSERT (sizeof (GIBaseInfo) == sizeof (GIBaseInfoStack)); G_STATIC_ASSERT (G_ALIGNOF (GIBaseInfo) == G_ALIGNOF (GIBaseInfoStack)); +/** + * GIInfoType: + * @GI_INFO_TYPE_INVALID: invalid type + * @GI_INFO_TYPE_FUNCTION: function, see [class@GIRepository.FunctionInfo] + * @GI_INFO_TYPE_CALLBACK: callback, see [class@GIRepository.FunctionInfo] + * @GI_INFO_TYPE_STRUCT: struct, see [class@GIRepository.StructInfo] + * @GI_INFO_TYPE_BOXED: boxed, see [class@GIRepository.StructInfo] or + * [class@GIRepository.UnionInfo] + * @GI_INFO_TYPE_ENUM: enum, see [class@GIRepository.EnumInfo] + * @GI_INFO_TYPE_FLAGS: flags, see [class@GIRepository.EnumInfo] + * @GI_INFO_TYPE_OBJECT: object, see [class@GIRepository.ObjectInfo] + * @GI_INFO_TYPE_INTERFACE: interface, see [class@GIRepository.InterfaceInfo] + * @GI_INFO_TYPE_CONSTANT: constant, see [class@GIRepository.ConstantInfo] + * @GI_INFO_TYPE_UNION: union, see [class@GIRepository.UnionInfo] + * @GI_INFO_TYPE_VALUE: enum value, see [class@GIRepository.ValueInfo] + * @GI_INFO_TYPE_SIGNAL: signal, see [class@GIRepository.SignalInfo] + * @GI_INFO_TYPE_VFUNC: virtual function, see [class@GIRepository.VFuncInfo] + * @GI_INFO_TYPE_PROPERTY: [class@GObject.Object] property, see + * [class@GIRepository.PropertyInfo] + * @GI_INFO_TYPE_FIELD: struct or union field, see + * [class@GIRepository.FieldInfo] + * @GI_INFO_TYPE_ARG: argument of a function or callback, see + * [class@GIRepository.ArgInfo] + * @GI_INFO_TYPE_TYPE: type information, see [class@GIRepository.TypeInfo] + * @GI_INFO_TYPE_UNRESOLVED: unresolved type, a type which is not present in + * the typelib, or any of its dependencies, see + * [class@GIRepository.UnresolvedInfo] + * @GI_INFO_TYPE_CALLABLE: an abstract type representing any callable (function, + * callback, vfunc), see [class@GIRepository.CallableInfo] + * @GI_INFO_TYPE_REGISTERED_TYPE: an abstract type representing any registered + * type (enum, interface, object, struct, union), see + * [class@GIRepository.RegisteredTypeInfo] + * + * The type of a [class@GIRepository.BaseInfo] struct. + * + * See [const@GIRepository.INFO_TYPE_N_TYPES] for the total number of elements + * in this enum. + * + * Since: 2.80 + */ +typedef enum +{ + /* The values here must be kept in sync with GITypelibBlobType */ + GI_INFO_TYPE_INVALID, + GI_INFO_TYPE_FUNCTION, + GI_INFO_TYPE_CALLBACK, + GI_INFO_TYPE_STRUCT, + GI_INFO_TYPE_BOXED, + GI_INFO_TYPE_ENUM, /* 5 */ + GI_INFO_TYPE_FLAGS, + GI_INFO_TYPE_OBJECT, + GI_INFO_TYPE_INTERFACE, + GI_INFO_TYPE_CONSTANT, + /* 10 is skipped, it used to be used, but was removed before girepository-2.0 + * It is, however, part of the binary format in GITypelibBlobType */ + GI_INFO_TYPE_UNION = 11, + GI_INFO_TYPE_VALUE = 12, + GI_INFO_TYPE_SIGNAL = 13, + GI_INFO_TYPE_VFUNC = 14, + GI_INFO_TYPE_PROPERTY = 15, + GI_INFO_TYPE_FIELD = 16, + GI_INFO_TYPE_ARG = 17, + GI_INFO_TYPE_TYPE = 18, + GI_INFO_TYPE_UNRESOLVED = 19, + GI_INFO_TYPE_CALLABLE = 20, + GI_INFO_TYPE_REGISTERED_TYPE = 21, + /* keep GI_INFO_TYPE_N_TYPES in sync with this */ +} GIInfoType; + +/** + * GI_INFO_TYPE_N_TYPES: + * + * Number of entries in [enum@GIRepository.InfoType]. + * + * Since: 2.80 + */ +#define GI_INFO_TYPE_N_TYPES (GI_INFO_TYPE_REGISTERED_TYPE + 1) + +const char * gi_info_type_to_string (GIInfoType type); + /* Subtypes */ struct _GICallableInfo { diff --git a/girepository/girepository.c b/girepository/girepository.c index 1185ff2ba..0365be812 100644 --- a/girepository/girepository.c +++ b/girepository/girepository.c @@ -32,6 +32,7 @@ #include #include #include +#include "gibaseinfo-private.h" #include "girepository.h" #include "gitypelib-internal.h" #include "girepository-private.h" diff --git a/girepository/girffi.c b/girepository/girffi.c index 4040b32b2..053fd3439 100644 --- a/girepository/girffi.c +++ b/girepository/girffi.c @@ -32,6 +32,7 @@ #include #endif #include "girffi.h" +#include "gibaseinfo-private.h" #include "girepository.h" #include "girepository-private.h" diff --git a/girepository/girffi.h b/girepository/girffi.h index 90bf07602..85197d87d 100644 --- a/girepository/girffi.h +++ b/girepository/girffi.h @@ -92,7 +92,7 @@ void gi_type_info_extract_ffi_return_value (GITypeInfo GI_AVAILABLE_IN_ALL void gi_type_tag_extract_ffi_return_value (GITypeTag return_tag, - GIInfoType interface_type, + GType interface_type, GIFFIReturnValue *ffi_value, GIArgument *arg); diff --git a/girepository/girnode.c b/girepository/girnode.c index 6ba72c23c..3a0983014 100644 --- a/girepository/girnode.c +++ b/girepository/girnode.c @@ -25,7 +25,7 @@ #include "config.h" #include "girnode-private.h" - +#include "girepository-private.h" #include "gitypelib-internal.h" #include diff --git a/girepository/girwriter.c b/girepository/girwriter.c index 069d8adcf..245084d5c 100644 --- a/girepository/girwriter.c +++ b/girepository/girwriter.c @@ -26,7 +26,9 @@ #include "girwriter-private.h" +#include "gibaseinfo-private.h" #include "girepository.h" +#include "girepository-private.h" #include "gitypelib-internal.h" #include diff --git a/girepository/gitypeinfo.c b/girepository/gitypeinfo.c index ac99b7bc8..e07ab8e9d 100644 --- a/girepository/gitypeinfo.c +++ b/girepository/gitypeinfo.c @@ -178,8 +178,9 @@ gi_type_info_get_param_type (GITypeInfo *info, * * You can then inspect the type of the returned [class@GIRepository.BaseInfo] * to further query whether it is a concrete [class@GObject.Object], an - * interface, a structure, etc., using - * [method@GIRepository.BaseInfo.get_info_type]. + * interface, a structure, etc., using the type checking macros like + * [func@GIRepository.IS_OBJECT_INFO], or raw [type@GObject.Type]s with + * [func@GObject.TYPE_FROM_INSTANCE]. * * Returns: (transfer full) (nullable): The [class@GIRepository.BaseInfo], or * `NULL`. Free it with gi_base_info_unref() when done. diff --git a/girepository/gitypeinfo.h b/girepository/gitypeinfo.h index 65cb78238..73f0ce423 100644 --- a/girepository/gitypeinfo.h +++ b/girepository/gitypeinfo.h @@ -93,10 +93,6 @@ G_BEGIN_DECLS GI_AVAILABLE_IN_ALL const char * gi_type_tag_to_string (GITypeTag type); -GI_AVAILABLE_IN_ALL -const char * gi_info_type_to_string (GIInfoType type); - - GI_AVAILABLE_IN_ALL gboolean gi_type_info_is_pointer (GITypeInfo *info); diff --git a/girepository/gitypes.h b/girepository/gitypes.h index a2f925152..c3e9fd673 100644 --- a/girepository/gitypes.h +++ b/girepository/gitypes.h @@ -199,84 +199,6 @@ union _GIArgument */ typedef union _GIArgument GIArgument; -/** - * GIInfoType: - * @GI_INFO_TYPE_INVALID: invalid type - * @GI_INFO_TYPE_FUNCTION: function, see [class@GIRepository.FunctionInfo] - * @GI_INFO_TYPE_CALLBACK: callback, see [class@GIRepository.FunctionInfo] - * @GI_INFO_TYPE_STRUCT: struct, see [class@GIRepository.StructInfo] - * @GI_INFO_TYPE_BOXED: boxed, see [class@GIRepository.StructInfo] or - * [class@GIRepository.UnionInfo] - * @GI_INFO_TYPE_ENUM: enum, see [class@GIRepository.EnumInfo] - * @GI_INFO_TYPE_FLAGS: flags, see [class@GIRepository.EnumInfo] - * @GI_INFO_TYPE_OBJECT: object, see [class@GIRepository.ObjectInfo] - * @GI_INFO_TYPE_INTERFACE: interface, see [class@GIRepository.InterfaceInfo] - * @GI_INFO_TYPE_CONSTANT: constant, see [class@GIRepository.ConstantInfo] - * @GI_INFO_TYPE_UNION: union, see [class@GIRepository.UnionInfo] - * @GI_INFO_TYPE_VALUE: enum value, see [class@GIRepository.ValueInfo] - * @GI_INFO_TYPE_SIGNAL: signal, see [class@GIRepository.SignalInfo] - * @GI_INFO_TYPE_VFUNC: virtual function, see [class@GIRepository.VFuncInfo] - * @GI_INFO_TYPE_PROPERTY: [class@GObject.Object] property, see - * [class@GIRepository.PropertyInfo] - * @GI_INFO_TYPE_FIELD: struct or union field, see - * [class@GIRepository.FieldInfo] - * @GI_INFO_TYPE_ARG: argument of a function or callback, see - * [class@GIRepository.ArgInfo] - * @GI_INFO_TYPE_TYPE: type information, see [class@GIRepository.TypeInfo] - * @GI_INFO_TYPE_UNRESOLVED: unresolved type, a type which is not present in - * the typelib, or any of its dependencies, see - * [class@GIRepository.UnresolvedInfo] - * @GI_INFO_TYPE_CALLABLE: an abstract type representing any callable (function, - * callback, vfunc), see [class@GIRepository.CallableInfo] - * @GI_INFO_TYPE_REGISTERED_TYPE: an abstract type representing any registered - * type (enum, interface, object, struct, union), see - * [class@GIRepository.RegisteredTypeInfo] - * - * The type of a [class@GIRepository.BaseInfo] struct. - * - * See [const@GIRepository.INFO_TYPE_N_TYPES] for the total number of elements - * in this enum. - * - * Since: 2.80 - */ -typedef enum -{ - /* The values here must be kept in sync with GITypelibBlobType */ - GI_INFO_TYPE_INVALID, - GI_INFO_TYPE_FUNCTION, - GI_INFO_TYPE_CALLBACK, - GI_INFO_TYPE_STRUCT, - GI_INFO_TYPE_BOXED, - GI_INFO_TYPE_ENUM, /* 5 */ - GI_INFO_TYPE_FLAGS, - GI_INFO_TYPE_OBJECT, - GI_INFO_TYPE_INTERFACE, - GI_INFO_TYPE_CONSTANT, - /* 10 is skipped, it used to be used, but was removed before girepository-2.0 - * It is, however, part of the binary format in GITypelibBlobType */ - GI_INFO_TYPE_UNION = 11, - GI_INFO_TYPE_VALUE = 12, - GI_INFO_TYPE_SIGNAL = 13, - GI_INFO_TYPE_VFUNC = 14, - GI_INFO_TYPE_PROPERTY = 15, - GI_INFO_TYPE_FIELD = 16, - GI_INFO_TYPE_ARG = 17, - GI_INFO_TYPE_TYPE = 18, - GI_INFO_TYPE_UNRESOLVED = 19, - GI_INFO_TYPE_CALLABLE = 20, - GI_INFO_TYPE_REGISTERED_TYPE = 21, - /* keep GI_INFO_TYPE_N_TYPES in sync with this */ -} GIInfoType; - -/** - * GI_INFO_TYPE_N_TYPES: - * - * Number of entries in [enum@GIRepository.InfoType]. - * - * Since: 2.80 - */ -#define GI_INFO_TYPE_N_TYPES (GI_INFO_TYPE_REGISTERED_TYPE + 1) - /** * GITransfer: * @GI_TRANSFER_NOTHING: Transfer nothing from the callee (function or the type diff --git a/girepository/tests/repository.c b/girepository/tests/repository.c index e5df0427a..2b5d96a53 100644 --- a/girepository/tests/repository.c +++ b/girepository/tests/repository.c @@ -96,7 +96,6 @@ test_repository_info (RepositoryFixture *fx, g_assert_true (GI_IS_REGISTERED_TYPE_INFO (object_info)); g_assert_true (GI_IS_BASE_INFO (object_info)); - g_assert_cmpint (gi_base_info_get_info_type (GI_BASE_INFO (object_info)), ==, GI_INFO_TYPE_OBJECT); g_assert_cmpstr (gi_base_info_get_name (GI_BASE_INFO (object_info)), ==, "Object"); g_assert_cmpstr (gi_base_info_get_namespace (GI_BASE_INFO (object_info)), ==, "GObject");