girepository: Make GIInfoType private

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 <pwithnall@gnome.org>

Helps: #3155
This commit is contained in:
Philip Withnall 2024-02-08 12:35:23 +00:00
parent 86cd95f1ae
commit 343027d5de
15 changed files with 110 additions and 112 deletions

View File

@ -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_get_type` | [method@GIRepository.ArgInfo.get_type_info] |
| `g_arg_info_load_type` | [method@GIRepository.ArgInfo.load_type_info] | | `g_arg_info_load_type` | [method@GIRepository.ArgInfo.load_type_info] |
| - | [method@GIRepository.BaseInfo.ref] and [method@GIRepository.BaseInfo.unref] | | - | [method@GIRepository.BaseInfo.ref] and [method@GIRepository.BaseInfo.unref] |
| `g_base_info_get_type` | [method@GIRepository.BaseInfo.get_info_type] | | `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` | [ctor@GIRepository.BaseInfo.new] | | `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_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_constant_info_get_type` | [method@GIRepository.ConstantInfo.get_type_info] |
| `g_field_info_get_type` | [method@GIRepository.FieldInfo.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_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_copy_function` | [method@GIRepository.UnionInfo.get_copy_function_name] |
| `g_union_info_get_free_function` | [method@GIRepository.UnionInfo.get_free_function_name] | | `g_union_info_get_free_function` | [method@GIRepository.UnionInfo.get_free_function_name] |
| `GIInfoType` | Use [type@GObject.Type] directly |

View File

@ -26,6 +26,7 @@
#include <glib.h> #include <glib.h>
#include <glib-object.h> #include <glib-object.h>
#include "girepository-private.h"
#include "gitypes.h" #include "gitypes.h"
G_BEGIN_DECLS G_BEGIN_DECLS
@ -50,4 +51,11 @@ GType gi_base_info_type_register_static (const char *type_name,
GType parent_type, GType parent_type,
GTypeFlags type_flags); 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 G_END_DECLS

View File

@ -650,7 +650,7 @@ gi_base_info_get_info_type (GIBaseInfo *info)
* *
* Obtain the name of the @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 * @info. For instance for [class@GIRepository.FunctionInfo] it is the name of
* the function. * the function.
* *

View File

@ -97,9 +97,6 @@ void gi_base_info_unref (void *info);
GI_AVAILABLE_IN_ALL GI_AVAILABLE_IN_ALL
void gi_base_info_clear (void *info); void gi_base_info_clear (void *info);
GI_AVAILABLE_IN_ALL
GIInfoType gi_base_info_get_info_type (GIBaseInfo *info);
GI_AVAILABLE_IN_ALL GI_AVAILABLE_IN_ALL
const char * gi_base_info_get_name (GIBaseInfo *info); const char * gi_base_info_get_name (GIBaseInfo *info);
@ -129,10 +126,4 @@ GI_AVAILABLE_IN_ALL
gboolean gi_base_info_equal (GIBaseInfo *info1, gboolean gi_base_info_equal (GIBaseInfo *info1,
GIBaseInfo *info2); GIBaseInfo *info2);
GI_AVAILABLE_IN_ALL
GIBaseInfo * gi_base_info_new (GIInfoType type,
GIBaseInfo *container,
GITypelib *typelib,
size_t offset);
G_END_DECLS G_END_DECLS

View File

@ -502,7 +502,7 @@ gi_callable_info_iterate_return_attributes (GICallableInfo *info,
/** /**
* gi_type_tag_extract_ffi_return_value: * gi_type_tag_extract_ffi_return_value:
* @return_tag: [type@GIRepository.TypeTag] of the 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 * @ffi_value: pointer to [type@GIRepository.FFIReturnValue] union containing
* the return value from `ffi_call()` * the return value from `ffi_call()`
* @arg: (out caller-allocates): pointer to an allocated * @arg: (out caller-allocates): pointer to an allocated
@ -523,7 +523,7 @@ gi_callable_info_iterate_return_attributes (GICallableInfo *info,
*/ */
void void
gi_type_tag_extract_ffi_return_value (GITypeTag return_tag, gi_type_tag_extract_ffi_return_value (GITypeTag return_tag,
GIInfoType interface_type, GType interface_type,
GIFFIReturnValue *ffi_value, GIFFIReturnValue *ffi_value,
GIArgument *arg) GIArgument *arg)
{ {
@ -561,15 +561,11 @@ gi_type_tag_extract_ffi_return_value (GITypeTag return_tag,
arg->v_double = ffi_value->v_double; arg->v_double = ffi_value->v_double;
break; break;
case GI_TYPE_TAG_INTERFACE: case GI_TYPE_TAG_INTERFACE:
switch(interface_type) { if (interface_type == GI_TYPE_ENUM_INFO ||
case GI_INFO_TYPE_ENUM: interface_type == GI_TYPE_FLAGS_INFO)
case GI_INFO_TYPE_FLAGS: arg->v_int32 = (int32_t) ffi_value->v_long;
arg->v_int32 = (int32_t) ffi_value->v_long; else
break; arg->v_pointer = (void *) ffi_value->v_pointer;
default:
arg->v_pointer = (void *) ffi_value->v_pointer;
break;
}
break; break;
default: default:
arg->v_pointer = (void *) ffi_value->v_pointer; arg->v_pointer = (void *) ffi_value->v_pointer;
@ -601,12 +597,12 @@ gi_type_info_extract_ffi_return_value (GITypeInfo *return_info,
GIArgument *arg) GIArgument *arg)
{ {
GITypeTag return_tag = gi_type_info_get_tag (return_info); 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) if (return_tag == GI_TYPE_TAG_INTERFACE)
{ {
GIBaseInfo *interface_info = gi_type_info_get_interface (return_info); 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); gi_base_info_unref (interface_info);
} }

View File

@ -66,6 +66,86 @@ struct _GIBaseInfo
G_STATIC_ASSERT (sizeof (GIBaseInfo) == sizeof (GIBaseInfoStack)); G_STATIC_ASSERT (sizeof (GIBaseInfo) == sizeof (GIBaseInfoStack));
G_STATIC_ASSERT (G_ALIGNOF (GIBaseInfo) == G_ALIGNOF (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 */ /* Subtypes */
struct _GICallableInfo struct _GICallableInfo
{ {

View File

@ -32,6 +32,7 @@
#include <glib.h> #include <glib.h>
#include <glib/gprintf.h> #include <glib/gprintf.h>
#include <gmodule.h> #include <gmodule.h>
#include "gibaseinfo-private.h"
#include "girepository.h" #include "girepository.h"
#include "gitypelib-internal.h" #include "gitypelib-internal.h"
#include "girepository-private.h" #include "girepository-private.h"

View File

@ -32,6 +32,7 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
#include "girffi.h" #include "girffi.h"
#include "gibaseinfo-private.h"
#include "girepository.h" #include "girepository.h"
#include "girepository-private.h" #include "girepository-private.h"

View File

@ -92,7 +92,7 @@ void gi_type_info_extract_ffi_return_value (GITypeInfo
GI_AVAILABLE_IN_ALL GI_AVAILABLE_IN_ALL
void gi_type_tag_extract_ffi_return_value (GITypeTag return_tag, void gi_type_tag_extract_ffi_return_value (GITypeTag return_tag,
GIInfoType interface_type, GType interface_type,
GIFFIReturnValue *ffi_value, GIFFIReturnValue *ffi_value,
GIArgument *arg); GIArgument *arg);

View File

@ -25,7 +25,7 @@
#include "config.h" #include "config.h"
#include "girnode-private.h" #include "girnode-private.h"
#include "girepository-private.h"
#include "gitypelib-internal.h" #include "gitypelib-internal.h"
#include <stdio.h> #include <stdio.h>

View File

@ -26,7 +26,9 @@
#include "girwriter-private.h" #include "girwriter-private.h"
#include "gibaseinfo-private.h"
#include "girepository.h" #include "girepository.h"
#include "girepository-private.h"
#include "gitypelib-internal.h" #include "gitypelib-internal.h"
#include <errno.h> #include <errno.h>

View File

@ -178,8 +178,9 @@ gi_type_info_get_param_type (GITypeInfo *info,
* *
* You can then inspect the type of the returned [class@GIRepository.BaseInfo] * You can then inspect the type of the returned [class@GIRepository.BaseInfo]
* to further query whether it is a concrete [class@GObject.Object], an * to further query whether it is a concrete [class@GObject.Object], an
* interface, a structure, etc., using * interface, a structure, etc., using the type checking macros like
* [method@GIRepository.BaseInfo.get_info_type]. * [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 * Returns: (transfer full) (nullable): The [class@GIRepository.BaseInfo], or
* `NULL`. Free it with gi_base_info_unref() when done. * `NULL`. Free it with gi_base_info_unref() when done.

View File

@ -93,10 +93,6 @@ G_BEGIN_DECLS
GI_AVAILABLE_IN_ALL GI_AVAILABLE_IN_ALL
const char * gi_type_tag_to_string (GITypeTag type); 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 GI_AVAILABLE_IN_ALL
gboolean gi_type_info_is_pointer (GITypeInfo *info); gboolean gi_type_info_is_pointer (GITypeInfo *info);

View File

@ -199,84 +199,6 @@ union _GIArgument
*/ */
typedef union _GIArgument 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: * GITransfer:
* @GI_TRANSFER_NOTHING: Transfer nothing from the callee (function or the type * @GI_TRANSFER_NOTHING: Transfer nothing from the callee (function or the type

View File

@ -96,7 +96,6 @@ test_repository_info (RepositoryFixture *fx,
g_assert_true (GI_IS_REGISTERED_TYPE_INFO (object_info)); g_assert_true (GI_IS_REGISTERED_TYPE_INFO (object_info));
g_assert_true (GI_IS_BASE_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_name (GI_BASE_INFO (object_info)), ==, "Object");
g_assert_cmpstr (gi_base_info_get_namespace (GI_BASE_INFO (object_info)), ==, "GObject"); g_assert_cmpstr (gi_base_info_get_namespace (GI_BASE_INFO (object_info)), ==, "GObject");