Merge branch '3216-girepository-casting' into 'main'

girepository: Rearrange type hierarchy and add type casting and checking macros

Closes #3216

See merge request GNOME/glib!3836
This commit is contained in:
Philip Withnall
2024-01-18 14:53:43 +00:00
35 changed files with 1019 additions and 175 deletions

View File

@@ -32,16 +32,31 @@
G_BEGIN_DECLS 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: * GI_IS_ARG_INFO:
* @info: an info structure * @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 * Since: 2.80
*/ */
#define GI_IS_ARG_INFO(info) \ #define GI_IS_ARG_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_ARG_INFO))
(gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_ARG)
GI_AVAILABLE_IN_ALL GI_AVAILABLE_IN_ALL

View File

@@ -46,6 +46,8 @@ void gi_base_info_init_types (void);
GType gi_base_info_type_register_static (const char *type_name, GType gi_base_info_type_register_static (const char *type_name,
size_t instance_size, size_t instance_size,
GClassInitFunc class_init); GClassInitFunc class_init,
GType parent_type,
GTypeFlags type_flags);
G_END_DECLS G_END_DECLS

View File

@@ -204,6 +204,9 @@ gi_base_info_get_type (void)
* @type_name: the name of the type * @type_name: the name of the type
* @instance_size: size (in bytes) of the types instance struct * @instance_size: size (in bytes) of the types instance struct
* @class_init: class init function for the type * @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 * Registers a new [type@GIRepository.BaseInfo] type for the given @type_name
* using the type information provided. * using the type information provided.
@@ -214,7 +217,9 @@ gi_base_info_get_type (void)
GType GType
gi_base_info_type_register_static (const char *type_name, gi_base_info_type_register_static (const char *type_name,
size_t instance_size, size_t instance_size,
GClassInitFunc class_init) GClassInitFunc class_init,
GType parent_type,
GTypeFlags type_flags)
{ {
GTypeInfo info; GTypeInfo info;
@@ -228,7 +233,7 @@ gi_base_info_type_register_static (const char *type_name,
info.instance_init = NULL; info.instance_init = NULL;
info.value_table = NULL; info.value_table = NULL;
return g_type_register_static (GI_TYPE_BASE_INFO, type_name, &info, 0); return g_type_register_static (parent_type, type_name, &info, type_flags);
} }
static GType gi_base_info_types[GI_INFO_TYPE_N_TYPES]; static GType gi_base_info_types[GI_INFO_TYPE_N_TYPES];
@@ -249,8 +254,10 @@ 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_struct_info, GI_INFO_TYPE_STRUCT)
GI_DEFINE_BASE_INFO_TYPE (gi_union_info, GI_INFO_TYPE_UNION) 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_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_object_info, GI_INFO_TYPE_OBJECT)
GI_DEFINE_BASE_INFO_TYPE (gi_interface_info, GI_INFO_TYPE_INTERFACE) 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_constant_info, GI_INFO_TYPE_CONSTANT)
GI_DEFINE_BASE_INFO_TYPE (gi_value_info, GI_INFO_TYPE_VALUE) GI_DEFINE_BASE_INFO_TYPE (gi_value_info, GI_INFO_TYPE_VALUE)
GI_DEFINE_BASE_INFO_TYPE (gi_signal_info, GI_INFO_TYPE_SIGNAL) GI_DEFINE_BASE_INFO_TYPE (gi_signal_info, GI_INFO_TYPE_SIGNAL)
@@ -274,34 +281,45 @@ gi_base_info_init_types (void)
const char *type_name; const char *type_name;
size_t instance_size; size_t instance_size;
GClassInitFunc class_init; GClassInitFunc class_init;
GIInfoType parent_info_type; /* 0 for GIBaseInfo */
GTypeFlags type_flags;
} }
types[] = types[] =
{ {
{ GI_INFO_TYPE_CALLABLE, "GICallableInfo", sizeof (GICallableInfo), gi_callable_info_class_init }, { 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_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_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 }, { 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_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_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_ENUM, "GIEnumInfo", sizeof (GIEnumInfo), gi_enum_info_class_init, GI_INFO_TYPE_REGISTERED_TYPE, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_OBJECT, "GIObjectInfo", sizeof (GIObjectInfo), gi_object_info_class_init }, { GI_INFO_TYPE_FLAGS, "GIFlagsInfo", sizeof (GIFlagsInfo), gi_flags_info_class_init, GI_INFO_TYPE_ENUM, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_INTERFACE, "GIInterfaceInfo", sizeof (GIInterfaceInfo), gi_interface_info_class_init }, { GI_INFO_TYPE_OBJECT, "GIObjectInfo", sizeof (GIObjectInfo), gi_object_info_class_init, GI_INFO_TYPE_REGISTERED_TYPE, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_CONSTANT, "GIConstantInfo", sizeof (GIConstantInfo), gi_constant_info_class_init }, { GI_INFO_TYPE_INTERFACE, "GIInterfaceInfo", sizeof (GIInterfaceInfo), gi_interface_info_class_init, GI_INFO_TYPE_REGISTERED_TYPE, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_VALUE, "GIValueInfo", sizeof (GIValueInfo), gi_value_info_class_init }, { GI_INFO_TYPE_BOXED, "GIBoxedInfo", sizeof (GIBoxedInfo), gi_boxed_info_class_init, GI_INFO_TYPE_REGISTERED_TYPE, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_SIGNAL, "GISignalInfo", sizeof (GISignalInfo), gi_signal_info_class_init }, { GI_INFO_TYPE_CONSTANT, "GIConstantInfo", sizeof (GIConstantInfo), gi_constant_info_class_init, 0, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_VFUNC, "GIVFuncInfo", sizeof (GIVFuncInfo), gi_vfunc_info_class_init }, { GI_INFO_TYPE_VALUE, "GIValueInfo", sizeof (GIValueInfo), gi_value_info_class_init, 0, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_PROPERTY, "GIPropertyInfo", sizeof (GIPropertyInfo), gi_property_info_class_init }, { GI_INFO_TYPE_SIGNAL, "GISignalInfo", sizeof (GISignalInfo), gi_signal_info_class_init, GI_INFO_TYPE_CALLABLE, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_FIELD, "GIFieldInfo", sizeof (GIFieldInfo), gi_field_info_class_init }, { GI_INFO_TYPE_VFUNC, "GIVFuncInfo", sizeof (GIVFuncInfo), gi_vfunc_info_class_init, GI_INFO_TYPE_CALLABLE, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_ARG, "GIArgInfo", sizeof (GIArgInfo), gi_arg_info_class_init }, { GI_INFO_TYPE_PROPERTY, "GIPropertyInfo", sizeof (GIPropertyInfo), gi_property_info_class_init, 0, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_TYPE, "GITypeInfo", sizeof (GITypeInfo), gi_type_info_class_init }, { GI_INFO_TYPE_FIELD, "GIFieldInfo", sizeof (GIFieldInfo), gi_field_info_class_init, 0, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_UNRESOLVED, "GIUnresolvedInfo", sizeof (GIUnresolvedInfo), gi_unresolved_info_class_init }, { 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++) 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), GType registered_type, parent_type;
types[i].instance_size,
types[i].class_init); 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; gi_base_info_types[types[i].info_type] = registered_type;
} }
@@ -499,7 +517,7 @@ gi_type_info_init (GIBaseInfo *info,
/** /**
* gi_base_info_ref: * gi_base_info_ref:
* @info: a #GIBaseInfo * @info: (type GIRepository.BaseInfo): a #GIBaseInfo
* *
* Increases the reference count of @info. * Increases the reference count of @info.
* *
@@ -507,10 +525,12 @@ gi_type_info_init (GIBaseInfo *info,
* Since: 2.80 * Since: 2.80
*/ */
GIBaseInfo * GIBaseInfo *
gi_base_info_ref (GIBaseInfo *info) gi_base_info_ref (void *info)
{ {
GIRealInfo *rinfo = (GIRealInfo*)info; GIRealInfo *rinfo = (GIRealInfo*)info;
g_return_val_if_fail (GI_IS_BASE_INFO (info), NULL);
g_assert (rinfo->ref_count != INVALID_REFCOUNT); g_assert (rinfo->ref_count != INVALID_REFCOUNT);
g_atomic_ref_count_inc (&rinfo->ref_count); g_atomic_ref_count_inc (&rinfo->ref_count);
@@ -519,7 +539,7 @@ gi_base_info_ref (GIBaseInfo *info)
/** /**
* gi_base_info_unref: * 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 * Decreases the reference count of @info. When its reference count
* drops to 0, the info is freed. * drops to 0, the info is freed.
@@ -527,10 +547,12 @@ gi_base_info_ref (GIBaseInfo *info)
* Since: 2.80 * Since: 2.80
*/ */
void void
gi_base_info_unref (GIBaseInfo *info) gi_base_info_unref (void *info)
{ {
GIRealInfo *rinfo = (GIRealInfo*)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); g_assert (rinfo->ref_count > 0 && rinfo->ref_count != INVALID_REFCOUNT);
if (g_atomic_ref_count_dec (&rinfo->ref_count)) if (g_atomic_ref_count_dec (&rinfo->ref_count))
@@ -762,7 +784,7 @@ const char *
gi_base_info_get_attribute (GIBaseInfo *info, gi_base_info_get_attribute (GIBaseInfo *info,
const char *name) const char *name)
{ {
GIAttributeIter iter = { 0, }; GIAttributeIter iter = GI_ATTRIBUTE_ITER_INIT;
const char *curname, *curvalue; const char *curname, *curvalue;
while (gi_base_info_iterate_attributes (info, &iter, &curname, &curvalue)) while (gi_base_info_iterate_attributes (info, &iter, &curname, &curvalue))
{ {
@@ -850,7 +872,7 @@ _attribute_blob_find_first (GIBaseInfo *info,
* void * void
* print_attributes (GIBaseInfo *info) * print_attributes (GIBaseInfo *info)
* { * {
* GIAttributeIter iter = { 0, }; * GIAttributeIter iter = GI_ATTRIBUTE_ITER_INIT;
* const char *name; * const char *name;
* const char *value; * const char *value;
* while (gi_base_info_iterate_attributes (info, &iter, &name, &value)) * while (gi_base_info_iterate_attributes (info, &iter, &name, &value))

View File

@@ -48,17 +48,51 @@ typedef struct {
void *_dummy[4]; void *_dummy[4];
} GIAttributeIter; } 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 ()) #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`.
*
* 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 GI_AVAILABLE_IN_ALL
GType gi_base_info_get_type (void) G_GNUC_CONST; GType gi_base_info_get_type (void) G_GNUC_CONST;
GI_AVAILABLE_IN_ALL GI_AVAILABLE_IN_ALL
GIBaseInfo * gi_base_info_ref (GIBaseInfo *info); GIBaseInfo * gi_base_info_ref (void *info);
GI_AVAILABLE_IN_ALL GI_AVAILABLE_IN_ALL
void gi_base_info_unref (GIBaseInfo *info); void gi_base_info_unref (void *info);
GI_AVAILABLE_IN_ALL GI_AVAILABLE_IN_ALL
GIInfoType gi_base_info_get_info_type (GIBaseInfo *info); GIInfoType gi_base_info_get_info_type (GIBaseInfo *info);

View File

@@ -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 <glib.h>
#include <girepository/girepository.h>
#include "gibaseinfo-private.h"
#include "girepository-private.h"
#include "gitypelib-internal.h"
#include "giboxedinfo.h"
/**
* GIBoxedInfo:
*
* A `GIBoxedInfo` represents a boxed type.
*
* There isnt 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;
}

View File

@@ -0,0 +1,60 @@
/* -*- 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 <girepository.h> can be included directly."
#endif
#include <girepository/gitypes.h>
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
*
* 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

View File

@@ -426,7 +426,7 @@ const char *
gi_callable_info_get_return_attribute (GICallableInfo *info, gi_callable_info_get_return_attribute (GICallableInfo *info,
const char *name) const char *name)
{ {
GIAttributeIter iter = { 0, }; GIAttributeIter iter = GI_ATTRIBUTE_ITER_INIT;
const char *curname, *curvalue; const char *curname, *curvalue;
while (gi_callable_info_iterate_return_attributes (info, &iter, &curname, &curvalue)) while (gi_callable_info_iterate_return_attributes (info, &iter, &curname, &curvalue))
{ {

View File

@@ -32,6 +32,22 @@
G_BEGIN_DECLS 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: * GI_IS_CALLABLE_INFO:
* @info: an info structure * @info: an info structure
@@ -40,11 +56,7 @@ G_BEGIN_DECLS
* *
* Since: 2.80 * Since: 2.80
*/ */
#define GI_IS_CALLABLE_INFO(info) \ #define GI_IS_CALLABLE_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_CALLABLE_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))
GI_AVAILABLE_IN_ALL GI_AVAILABLE_IN_ALL

View File

@@ -31,6 +31,22 @@
G_BEGIN_DECLS 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: * GI_IS_CALLBACK_INFO:
* @info: an info structure * @info: an info structure
@@ -39,7 +55,6 @@ G_BEGIN_DECLS
* *
* Since: 2.80 * Since: 2.80
*/ */
#define GI_IS_CALLBACK_INFO(info) \ #define GI_IS_CALLBACK_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_CALLBACK_INFO))
(gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_CALLBACK)
G_END_DECLS G_END_DECLS

View File

@@ -32,16 +32,31 @@
G_BEGIN_DECLS 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: * GI_IS_CONSTANT_INFO:
* @info: an info structure * @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 * Since: 2.80
*/ */
#define GI_IS_CONSTANT_INFO(info) \ #define GI_IS_CONSTANT_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_CONSTANT_INFO))
(gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_CONSTANT)
GI_AVAILABLE_IN_ALL GI_AVAILABLE_IN_ALL

View File

@@ -221,51 +221,3 @@ gi_enum_info_class_init (gpointer g_class,
info_class->info_type = GI_INFO_TYPE_ENUM; 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;
}

View File

@@ -32,28 +32,31 @@
G_BEGIN_DECLS 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: * GI_IS_ENUM_INFO:
* @info: an info structure * @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 * Since: 2.80
*/ */
#define GI_IS_ENUM_INFO(info) \ #define GI_IS_ENUM_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_ENUM_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))
/**
* 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 GI_AVAILABLE_IN_ALL
@@ -76,8 +79,4 @@ GITypeTag gi_enum_info_get_storage_type (GIEnumInfo *info);
GI_AVAILABLE_IN_ALL GI_AVAILABLE_IN_ALL
const char * gi_enum_info_get_error_domain (GIEnumInfo *info); 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 G_END_DECLS

View File

@@ -32,16 +32,31 @@
G_BEGIN_DECLS 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: * GI_IS_FIELD_INFO:
* @info: an info structure * @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 * Since: 2.80
*/ */
#define GI_IS_FIELD_INFO(info) \ #define GI_IS_FIELD_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_FIELD_INFO))
(gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_FIELD)
GI_AVAILABLE_IN_ALL GI_AVAILABLE_IN_ALL

View File

@@ -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 <glib.h>
#include <girepository/girepository.h>
#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;
}

View File

@@ -0,0 +1,60 @@
/* -*- 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 <girepository.h> can be included directly."
#endif
#include <girepository/gitypes.h>
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
*
* 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

View File

@@ -32,16 +32,31 @@
G_BEGIN_DECLS 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: * GI_IS_FUNCTION_INFO:
* @info: an info structure * @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 * Since: 2.80
*/ */
#define GI_IS_FUNCTION_INFO(info) \ #define GI_IS_FUNCTION_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_FUNCTION_INFO))
(gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_FUNCTION)
GI_AVAILABLE_IN_ALL GI_AVAILABLE_IN_ALL

View File

@@ -32,16 +32,31 @@
G_BEGIN_DECLS 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: * GI_IS_INTERFACE_INFO:
* @info: an info structure * @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 * Since: 2.80
*/ */
#define GI_IS_INTERFACE_INFO(info) \ #define GI_IS_INTERFACE_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_INTERFACE_INFO))
(gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_INTERFACE)
GI_AVAILABLE_IN_ALL GI_AVAILABLE_IN_ALL

View File

@@ -75,16 +75,31 @@ typedef void (*GIObjectInfoSetValueFunction) (GValue *value, void *object);
*/ */
typedef void * (*GIObjectInfoGetValueFunction) (const GValue *value); 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: * GI_IS_OBJECT_INFO:
* @info: an info structure * @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 * Since: 2.80
*/ */
#define GI_IS_OBJECT_INFO(info) \ #define GI_IS_OBJECT_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_OBJECT_INFO))
(gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_OBJECT)
GI_AVAILABLE_IN_ALL GI_AVAILABLE_IN_ALL

View File

@@ -32,16 +32,31 @@
G_BEGIN_DECLS 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: * GI_IS_PROPERTY_INFO:
* @info: an info structure * @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 * Since: 2.80
*/ */
#define GI_IS_PROPERTY_INFO(info) \ #define GI_IS_PROPERTY_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_PROPERTY_INFO))
(gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_PROPERTY)
GI_AVAILABLE_IN_ALL GI_AVAILABLE_IN_ALL

View File

@@ -33,6 +33,22 @@
G_BEGIN_DECLS 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: * GI_IS_REGISTERED_TYPE_INFO:
* @info: an info structure * @info: an info structure
@@ -42,15 +58,7 @@ G_BEGIN_DECLS
* *
* Since: 2.80 * Since: 2.80
*/ */
#define GI_IS_REGISTERED_TYPE_INFO(info) \ #define GI_IS_REGISTERED_TYPE_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_OBJECT_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))
GI_AVAILABLE_IN_ALL GI_AVAILABLE_IN_ALL
const char * gi_registered_type_info_get_type_name (GIRegisteredTypeInfo *info); const char * gi_registered_type_info_get_type_name (GIRegisteredTypeInfo *info);

View File

@@ -68,7 +68,7 @@ void gi_callable_info_class_init (gpointer g_class,
struct _GIFunctionInfo struct _GIFunctionInfo
{ {
GIBaseInfo parent; GICallableInfo parent;
}; };
void gi_function_info_class_init (gpointer g_class, void gi_function_info_class_init (gpointer g_class,
@@ -76,7 +76,7 @@ void gi_function_info_class_init (gpointer g_class,
struct _GICallbackInfo struct _GICallbackInfo
{ {
GIBaseInfo parent; GICallableInfo parent;
}; };
void gi_callback_info_class_init (gpointer g_class, void gi_callback_info_class_init (gpointer g_class,
@@ -92,7 +92,7 @@ void gi_registered_type_info_class_init (gpointer g_class,
struct _GIStructInfo struct _GIStructInfo
{ {
GIBaseInfo parent; GIRegisteredTypeInfo parent;
}; };
void gi_struct_info_class_init (gpointer g_class, void gi_struct_info_class_init (gpointer g_class,
@@ -100,7 +100,7 @@ void gi_struct_info_class_init (gpointer g_class,
struct _GIUnionInfo struct _GIUnionInfo
{ {
GIBaseInfo parent; GIRegisteredTypeInfo parent;
}; };
void gi_union_info_class_init (gpointer g_class, void gi_union_info_class_init (gpointer g_class,
@@ -108,15 +108,23 @@ void gi_union_info_class_init (gpointer g_class,
struct _GIEnumInfo struct _GIEnumInfo
{ {
GIBaseInfo parent; GIRegisteredTypeInfo parent;
}; };
void gi_enum_info_class_init (gpointer g_class, void gi_enum_info_class_init (gpointer g_class,
gpointer class_data); gpointer class_data);
struct _GIFlagsInfo
{
GIEnumInfo parent;
};
void gi_flags_info_class_init (gpointer g_class,
gpointer class_data);
struct _GIObjectInfo struct _GIObjectInfo
{ {
GIBaseInfo parent; GIRegisteredTypeInfo parent;
}; };
void gi_object_info_class_init (gpointer g_class, void gi_object_info_class_init (gpointer g_class,
@@ -124,12 +132,20 @@ void gi_object_info_class_init (gpointer g_class,
struct _GIInterfaceInfo struct _GIInterfaceInfo
{ {
GIBaseInfo parent; GIRegisteredTypeInfo parent;
}; };
void gi_interface_info_class_init (gpointer g_class, void gi_interface_info_class_init (gpointer g_class,
gpointer class_data); gpointer class_data);
struct _GIBoxedInfo
{
GIRegisteredTypeInfo parent;
};
void gi_boxed_info_class_init (gpointer g_class,
gpointer class_data);
struct _GIConstantInfo struct _GIConstantInfo
{ {
GIBaseInfo parent; GIBaseInfo parent;
@@ -148,7 +164,7 @@ void gi_value_info_class_init (gpointer g_class,
struct _GISignalInfo struct _GISignalInfo
{ {
GIBaseInfo parent; GICallableInfo parent;
}; };
void gi_signal_info_class_init (gpointer g_class, void gi_signal_info_class_init (gpointer g_class,
@@ -156,7 +172,7 @@ void gi_signal_info_class_init (gpointer g_class,
struct _GIVFuncInfo struct _GIVFuncInfo
{ {
GIBaseInfo parent; GICallableInfo parent;
}; };
void gi_vfunc_info_class_init (gpointer g_class, void gi_vfunc_info_class_init (gpointer g_class,

View File

@@ -33,11 +33,13 @@
#include <girepository/giarginfo.h> #include <girepository/giarginfo.h>
#include <girepository/gibaseinfo.h> #include <girepository/gibaseinfo.h>
#include <girepository/giboxedinfo.h>
#include <girepository/gicallableinfo.h> #include <girepository/gicallableinfo.h>
#include <girepository/gicallbackinfo.h> #include <girepository/gicallbackinfo.h>
#include <girepository/giconstantinfo.h> #include <girepository/giconstantinfo.h>
#include <girepository/gienuminfo.h> #include <girepository/gienuminfo.h>
#include <girepository/gifieldinfo.h> #include <girepository/gifieldinfo.h>
#include <girepository/giflagsinfo.h>
#include <girepository/gifunctioninfo.h> #include <girepository/gifunctioninfo.h>
#include <girepository/giinterfaceinfo.h> #include <girepository/giinterfaceinfo.h>
#include <girepository/giobjectinfo.h> #include <girepository/giobjectinfo.h>
@@ -50,6 +52,7 @@
#include <girepository/gitypes.h> #include <girepository/gitypes.h>
#include <girepository/giunioninfo.h> #include <girepository/giunioninfo.h>
#include <girepository/giunresolvedinfo.h> #include <girepository/giunresolvedinfo.h>
#include <girepository/givalueinfo.h>
#include <girepository/givfuncinfo.h> #include <girepository/givfuncinfo.h>
G_BEGIN_DECLS G_BEGIN_DECLS

View File

@@ -350,7 +350,7 @@ static void
write_attributes (Xml *file, write_attributes (Xml *file,
GIBaseInfo *info) GIBaseInfo *info)
{ {
GIAttributeIter iter = { 0, }; GIAttributeIter iter = GI_ATTRIBUTE_ITER_INIT;
const char *name, *value; const char *name, *value;
while (gi_base_info_iterate_attributes (info, &iter, &name, &value)) while (gi_base_info_iterate_attributes (info, &iter, &name, &value))
@@ -365,7 +365,7 @@ static void
write_return_value_attributes (Xml *file, write_return_value_attributes (Xml *file,
GICallableInfo *info) GICallableInfo *info)
{ {
GIAttributeIter iter = { 0, }; GIAttributeIter iter = GI_ATTRIBUTE_ITER_INIT;
const char *name, *value; const char *name, *value;
while (gi_callable_info_iterate_return_attributes (info, &iter, &name, &value)) while (gi_callable_info_iterate_return_attributes (info, &iter, &name, &value))

View File

@@ -33,16 +33,31 @@
G_BEGIN_DECLS 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: * GI_IS_SIGNAL_INFO:
* @info: an info structure * @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 * Since: 2.80
*/ */
#define GI_IS_SIGNAL_INFO(info) \ #define GI_IS_SIGNAL_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_SIGNAL_INFO))
(gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_SIGNAL)
GI_AVAILABLE_IN_ALL GI_AVAILABLE_IN_ALL

View File

@@ -32,16 +32,31 @@
G_BEGIN_DECLS 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: * GI_IS_STRUCT_INFO:
* @info: an info structure * @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 * Since: 2.80
*/ */
#define GI_IS_STRUCT_INFO(info) \ #define GI_IS_STRUCT_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_STRUCT_INFO))
(gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_STRUCT)
GI_AVAILABLE_IN_ALL GI_AVAILABLE_IN_ALL

View File

@@ -32,16 +32,31 @@
G_BEGIN_DECLS 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: * GI_IS_TYPE_INFO:
* @info: an info structure * @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 * Since: 2.80
*/ */
#define GI_IS_TYPE_INFO(info) \ #define GI_IS_TYPE_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_TYPE_INFO))
(gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_TYPE)
/** /**
* GI_TYPE_TAG_IS_BASIC: * GI_TYPE_TAG_IS_BASIC:

View File

@@ -69,6 +69,10 @@ GI_AVAILABLE_IN_ALL GType gi_union_info_get_type (void);
typedef struct _GIEnumInfo GIEnumInfo; typedef struct _GIEnumInfo GIEnumInfo;
GI_AVAILABLE_IN_ALL GType gi_enum_info_get_type (void); 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 */ /* Documented in giobjectinfo.c */
typedef struct _GIObjectInfo GIObjectInfo; typedef struct _GIObjectInfo GIObjectInfo;
GI_AVAILABLE_IN_ALL GType gi_object_info_get_type (void); GI_AVAILABLE_IN_ALL GType gi_object_info_get_type (void);
@@ -77,6 +81,10 @@ GI_AVAILABLE_IN_ALL GType gi_object_info_get_type (void);
typedef struct _GIInterfaceInfo GIInterfaceInfo; typedef struct _GIInterfaceInfo GIInterfaceInfo;
GI_AVAILABLE_IN_ALL GType gi_interface_info_get_type (void); 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 */ /* Documented in giconstantinfo.c */
typedef struct _GIConstantInfo GIConstantInfo; typedef struct _GIConstantInfo GIConstantInfo;
GI_AVAILABLE_IN_ALL GType gi_constant_info_get_type (void); GI_AVAILABLE_IN_ALL GType gi_constant_info_get_type (void);

View File

@@ -32,16 +32,31 @@
G_BEGIN_DECLS 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: * GI_IS_UNION_INFO:
* @info: an info structure * @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 * Since: 2.80
*/ */
#define GI_IS_UNION_INFO(info) \ #define GI_IS_UNION_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_UNION_INFO))
(gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_UNION)
GI_AVAILABLE_IN_ALL GI_AVAILABLE_IN_ALL
unsigned int gi_union_info_get_n_fields (GIUnionInfo *info); unsigned int gi_union_info_get_n_fields (GIUnionInfo *info);

View File

@@ -31,6 +31,22 @@
G_BEGIN_DECLS 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: * GI_IS_UNRESOLVED_INFO:
* @info: an info structure * @info: an info structure
@@ -39,7 +55,6 @@ G_BEGIN_DECLS
* *
* Since: 2.80 * Since: 2.80
*/ */
#define GI_IS_UNRESOLVED_INFO(info) \ #define GI_IS_UNRESOLVED_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_UNRESOLVED_INFO))
(gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_UNRESOLVED)
G_END_DECLS G_END_DECLS

View File

@@ -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 <glib.h>
#include <girepository/girepository.h>
#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;
}

View File

@@ -0,0 +1,65 @@
/* -*- 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 <girepository.h> can be included directly."
#endif
#include <girepository/gitypes.h>
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
*
* Checks if @info is a [class@GIRepository.ValueInfo] (or a derived type).
*
* Since: 2.80
*/
#define GI_IS_VALUE_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_VALUE_INFO))
GI_AVAILABLE_IN_ALL
int64_t gi_value_info_get_value (GIValueInfo *info);
G_END_DECLS

View File

@@ -32,16 +32,31 @@
G_BEGIN_DECLS 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: * GI_IS_VFUNC_INFO:
* @info: an info structure * @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 * Since: 2.80
*/ */
#define GI_IS_VFUNC_INFO(info) \ #define GI_IS_VFUNC_INFO(info) (G_TYPE_CHECK_INSTANCE_TYPE ((info), GI_TYPE_VFUNC_INFO))
(gi_base_info_get_info_type ((GIBaseInfo*) info) == GI_INFO_TYPE_VFUNC)
GI_AVAILABLE_IN_ALL GI_AVAILABLE_IN_ALL
GIVFuncInfoFlags gi_vfunc_info_get_flags (GIVFuncInfo *info); GIVFuncInfoFlags gi_vfunc_info_get_flags (GIVFuncInfo *info);

View File

@@ -44,11 +44,13 @@ gi_visibility_h = custom_target(
girepo_headers = files( girepo_headers = files(
'giarginfo.h', 'giarginfo.h',
'gibaseinfo.h', 'gibaseinfo.h',
'giboxedinfo.h',
'gicallableinfo.h', 'gicallableinfo.h',
'gicallbackinfo.h', 'gicallbackinfo.h',
'giconstantinfo.h', 'giconstantinfo.h',
'gienuminfo.h', 'gienuminfo.h',
'gifieldinfo.h', 'gifieldinfo.h',
'giflagsinfo.h',
'gifunctioninfo.h', 'gifunctioninfo.h',
'giinterfaceinfo.h', 'giinterfaceinfo.h',
'giobjectinfo.h', 'giobjectinfo.h',
@@ -62,6 +64,7 @@ girepo_headers = files(
'gitypes.h', 'gitypes.h',
'giunioninfo.h', 'giunioninfo.h',
'giunresolvedinfo.h', 'giunresolvedinfo.h',
'givalueinfo.h',
'givfuncinfo.h', 'givfuncinfo.h',
) )
@@ -143,11 +146,13 @@ girepo_sources = files(
'gdump.c', 'gdump.c',
'giarginfo.c', 'giarginfo.c',
'gibaseinfo.c', 'gibaseinfo.c',
'giboxedinfo.c',
'gicallableinfo.c', 'gicallableinfo.c',
'gicallbackinfo.c', 'gicallbackinfo.c',
'giconstantinfo.c', 'giconstantinfo.c',
'gienuminfo.c', 'gienuminfo.c',
'gifieldinfo.c', 'gifieldinfo.c',
'giflagsinfo.c',
'gifunctioninfo.c', 'gifunctioninfo.c',
'ginvoke.c', 'ginvoke.c',
'giinterfaceinfo.c', 'giinterfaceinfo.c',
@@ -162,6 +167,7 @@ girepo_sources = files(
'gitypelib.c', 'gitypelib.c',
'giunioninfo.c', 'giunioninfo.c',
'giunresolvedinfo.c', 'giunresolvedinfo.c',
'givalueinfo.c',
'givfuncinfo.c', 'givfuncinfo.c',
) )

View File

@@ -39,8 +39,7 @@ test_build_retrieve (void)
gi_typelib_hash_builder_add_string (builder, "VolumeMonitor", 9); gi_typelib_hash_builder_add_string (builder, "VolumeMonitor", 9);
gi_typelib_hash_builder_add_string (builder, "FileMonitorFlags", 31); gi_typelib_hash_builder_add_string (builder, "FileMonitorFlags", 31);
if (!gi_typelib_hash_builder_prepare (builder)) g_assert_true (gi_typelib_hash_builder_prepare (builder));
g_assert_not_reached ();
bufsize = gi_typelib_hash_builder_get_buffer_size (builder); bufsize = gi_typelib_hash_builder_get_buffer_size (builder);
@@ -50,10 +49,10 @@ test_build_retrieve (void)
gi_typelib_hash_builder_destroy (builder); gi_typelib_hash_builder_destroy (builder);
g_assert (gi_typelib_hash_search (buf, "Action", 4) == 0); g_assert_cmpuint (gi_typelib_hash_search (buf, "Action", 4), ==, 0);
g_assert (gi_typelib_hash_search (buf, "ZLibDecompressor", 4) == 42); g_assert_cmpuint (gi_typelib_hash_search (buf, "ZLibDecompressor", 4), ==, 42);
g_assert (gi_typelib_hash_search (buf, "VolumeMonitor", 4) == 9); g_assert_cmpuint (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, "FileMonitorFlags", 4), ==, 31);
g_free (buf); g_free (buf);
} }

View File

@@ -22,6 +22,30 @@
#include "glib.h" #include "glib.h"
#include "girepository.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 static void
test_repository_basic (void) test_repository_basic (void)
{ {
@@ -116,16 +140,16 @@ test_repository_info (void)
g_assert_nonnull (method_info); g_assert_nonnull (method_info);
g_assert_true (gi_callable_info_is_method ((GICallableInfo *) 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_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, method_info = gi_object_info_get_method (object_info,
gi_object_info_get_n_methods (object_info) - 1); gi_object_info_get_n_methods (object_info) - 1);
g_assert_true (gi_callable_info_is_method ((GICallableInfo *) 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), >, 0); 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 (signal_info);
gi_base_info_unref ((GIBaseInfo *) object_info); gi_base_info_unref (object_info);
g_clear_object (&repository); g_clear_object (&repository);
} }
@@ -161,6 +185,177 @@ test_repository_dependencies (void)
g_clear_pointer (&dependencies, g_strfreev); 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 were 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 its 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 were 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 int
main (int argc, main (int argc,
char *argv[]) char *argv[])
@@ -174,6 +369,10 @@ main (int argc,
g_test_add_func ("/repository/basic", test_repository_basic); g_test_add_func ("/repository/basic", test_repository_basic);
g_test_add_func ("/repository/info", test_repository_info); g_test_add_func ("/repository/info", test_repository_info);
g_test_add_func ("/repository/dependencies", test_repository_dependencies); 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 (); return g_test_run ();
} }