mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-11 15:06:14 +01:00
Merge branch '3245-boxed-info-typing' into 'main'
gibaseinfo: Stop building GIBoxedInfo instances and use gi_registered_type_info_is_boxed() instead Closes #3245 See merge request GNOME/glib!3905
This commit is contained in:
commit
3a7dfb14c6
@ -81,6 +81,7 @@ your code if integer type warnings are enabled.
|
||||
| `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 |
|
||||
| `GI_INFO_TYPE_BOXED` | Dropped in favour of [method@GIRepository.RegisteredTypeInfo.is_boxed] |
|
||||
|
||||
## Utility program renames from version 1.0 to 2.0
|
||||
|
||||
|
@ -257,7 +257,6 @@ GI_DEFINE_BASE_INFO_TYPE (gi_enum_info, GI_INFO_TYPE_ENUM)
|
||||
GI_DEFINE_BASE_INFO_TYPE (gi_flags_info, GI_INFO_TYPE_FLAGS)
|
||||
GI_DEFINE_BASE_INFO_TYPE (gi_object_info, GI_INFO_TYPE_OBJECT)
|
||||
GI_DEFINE_BASE_INFO_TYPE (gi_interface_info, GI_INFO_TYPE_INTERFACE)
|
||||
GI_DEFINE_BASE_INFO_TYPE (gi_boxed_info, GI_INFO_TYPE_BOXED)
|
||||
GI_DEFINE_BASE_INFO_TYPE (gi_constant_info, GI_INFO_TYPE_CONSTANT)
|
||||
GI_DEFINE_BASE_INFO_TYPE (gi_value_info, GI_INFO_TYPE_VALUE)
|
||||
GI_DEFINE_BASE_INFO_TYPE (gi_signal_info, GI_INFO_TYPE_SIGNAL)
|
||||
@ -296,7 +295,6 @@ gi_base_info_init_types (void)
|
||||
{ GI_INFO_TYPE_FLAGS, "GIFlagsInfo", sizeof (GIFlagsInfo), gi_flags_info_class_init, GI_INFO_TYPE_ENUM, G_TYPE_FLAG_NONE },
|
||||
{ GI_INFO_TYPE_OBJECT, "GIObjectInfo", sizeof (GIObjectInfo), gi_object_info_class_init, GI_INFO_TYPE_REGISTERED_TYPE, G_TYPE_FLAG_NONE },
|
||||
{ GI_INFO_TYPE_INTERFACE, "GIInterfaceInfo", sizeof (GIInterfaceInfo), gi_interface_info_class_init, GI_INFO_TYPE_REGISTERED_TYPE, G_TYPE_FLAG_NONE },
|
||||
{ GI_INFO_TYPE_BOXED, "GIBoxedInfo", sizeof (GIBoxedInfo), gi_boxed_info_class_init, GI_INFO_TYPE_REGISTERED_TYPE, G_TYPE_FLAG_NONE },
|
||||
{ GI_INFO_TYPE_CONSTANT, "GIConstantInfo", sizeof (GIConstantInfo), gi_constant_info_class_init, 0, G_TYPE_FLAG_NONE },
|
||||
{ GI_INFO_TYPE_VALUE, "GIValueInfo", sizeof (GIValueInfo), gi_value_info_class_init, 0, G_TYPE_FLAG_NONE },
|
||||
{ GI_INFO_TYPE_SIGNAL, "GISignalInfo", sizeof (GISignalInfo), gi_signal_info_class_init, GI_INFO_TYPE_CALLABLE, G_TYPE_FLAG_NONE },
|
||||
@ -475,7 +473,8 @@ gi_info_from_entry (GIRepository *repository,
|
||||
DirEntry *entry = gi_typelib_get_dir_entry (typelib, index);
|
||||
|
||||
if (entry->local)
|
||||
result = gi_info_new_full (entry->blob_type, repository, NULL, typelib, entry->offset);
|
||||
result = gi_info_new_full (gi_typelib_blob_type_to_info_type (entry->blob_type),
|
||||
repository, NULL, typelib, entry->offset);
|
||||
else
|
||||
{
|
||||
const char *namespace = gi_typelib_get_string (typelib, entry->offset);
|
||||
@ -667,7 +666,6 @@ gi_base_info_get_name (GIBaseInfo *info)
|
||||
case GI_INFO_TYPE_FUNCTION:
|
||||
case GI_INFO_TYPE_CALLBACK:
|
||||
case GI_INFO_TYPE_STRUCT:
|
||||
case GI_INFO_TYPE_BOXED:
|
||||
case GI_INFO_TYPE_ENUM:
|
||||
case GI_INFO_TYPE_FLAGS:
|
||||
case GI_INFO_TYPE_OBJECT:
|
||||
@ -791,7 +789,6 @@ gi_base_info_is_deprecated (GIBaseInfo *info)
|
||||
case GI_INFO_TYPE_FUNCTION:
|
||||
case GI_INFO_TYPE_CALLBACK:
|
||||
case GI_INFO_TYPE_STRUCT:
|
||||
case GI_INFO_TYPE_BOXED:
|
||||
case GI_INFO_TYPE_ENUM:
|
||||
case GI_INFO_TYPE_FLAGS:
|
||||
case GI_INFO_TYPE_OBJECT:
|
||||
|
@ -1,52 +0,0 @@
|
||||
/* -*- 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 isn’t much you can do with a boxed type; `GIBoxedInfo` exists mainly to
|
||||
* tag the type.
|
||||
*
|
||||
* Since: 2.80
|
||||
*/
|
||||
|
||||
void
|
||||
gi_boxed_info_class_init (gpointer g_class,
|
||||
gpointer class_data)
|
||||
{
|
||||
GIBaseInfoClass *info_class = g_class;
|
||||
|
||||
info_class->info_type = GI_INFO_TYPE_BOXED;
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
/* -*- 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
|
@ -278,7 +278,6 @@ gi_field_info_get_field (GIFieldInfo *field_info,
|
||||
{
|
||||
case GI_INFO_TYPE_STRUCT:
|
||||
case GI_INFO_TYPE_UNION:
|
||||
case GI_INFO_TYPE_BOXED:
|
||||
/* Needs to be handled by the language binding directly */
|
||||
break;
|
||||
case GI_INFO_TYPE_OBJECT:
|
||||
@ -464,7 +463,6 @@ gi_field_info_set_field (GIFieldInfo *field_info,
|
||||
{
|
||||
case GI_INFO_TYPE_STRUCT:
|
||||
case GI_INFO_TYPE_UNION:
|
||||
case GI_INFO_TYPE_BOXED:
|
||||
/* Needs to be handled by the language binding directly */
|
||||
break;
|
||||
case GI_INFO_TYPE_OBJECT:
|
||||
|
@ -50,6 +50,13 @@
|
||||
* Most users want to call [method@GIRepository.RegisteredTypeInfo.get_g_type]
|
||||
* and don’t worry about the rest of the details.
|
||||
*
|
||||
* If the registered type is a subtype of `G_TYPE_BOXED`,
|
||||
* [method@GIRepository.RegisteredTypeInfo.is_boxed] will return true, and
|
||||
* [method@GIRepository.RegisteredTypeInfo.get_type_name] is guaranteed to
|
||||
* return a non-`NULL` value. This is relevant for the
|
||||
* [class@GIRepository.StructInfo] and [class@GIRepository.UnionInfo]
|
||||
* subclasses.
|
||||
*
|
||||
* Since: 2.80
|
||||
*/
|
||||
|
||||
@ -155,6 +162,63 @@ gi_registered_type_info_get_g_type (GIRegisteredTypeInfo *info)
|
||||
return (* get_type_func) ();
|
||||
}
|
||||
|
||||
/**
|
||||
* gi_registered_type_info_is_boxed:
|
||||
* @info: a #GIRegisteredTypeInfo
|
||||
*
|
||||
* Get whether the registered type is a boxed type.
|
||||
*
|
||||
* A boxed type is a subtype of the fundamental `G_TYPE_BOXED` type.
|
||||
* It’s a type which has registered a [type@GObject.Type], and which has
|
||||
* associated copy and free functions.
|
||||
*
|
||||
* Most boxed types are `struct`s; some are `union`s; and it’s possible for a
|
||||
* boxed type to be neither, but that is currently unsupported by
|
||||
* libgirepository. It’s also possible for a `struct` or `union` to have
|
||||
* associated copy and/or free functions *without* being a boxed type, by virtue
|
||||
* of not having registered a [type@GObject.Type].
|
||||
*
|
||||
* This function will return false for [type@GObject.Type]s which are not boxed,
|
||||
* such as classes or interfaces. It will also return false for the `struct`s
|
||||
* associated with a class or interface, which return true from
|
||||
* [method@GIRepository.StructInfo.is_gtype_struct].
|
||||
*
|
||||
* Returns: true if @info is a boxed type
|
||||
* Since: 2.80
|
||||
*/
|
||||
gboolean
|
||||
gi_registered_type_info_is_boxed (GIRegisteredTypeInfo *info)
|
||||
{
|
||||
GIBaseInfo *base_info = GI_BASE_INFO (info);
|
||||
const RegisteredTypeBlob *blob;
|
||||
|
||||
g_return_val_if_fail (GI_IS_REGISTERED_TYPE_INFO (info), G_TYPE_INVALID);
|
||||
|
||||
blob = (const RegisteredTypeBlob *) &base_info->typelib->data[base_info->offset];
|
||||
|
||||
if (blob->blob_type == BLOB_TYPE_BOXED)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
else if (blob->blob_type == BLOB_TYPE_STRUCT)
|
||||
{
|
||||
const StructBlob *struct_blob = (const StructBlob *) &base_info->typelib->data[base_info->offset];
|
||||
|
||||
return !struct_blob->unregistered;
|
||||
}
|
||||
else if (blob->blob_type == BLOB_TYPE_UNION)
|
||||
{
|
||||
const UnionBlob *union_blob = (const UnionBlob *) &base_info->typelib->data[base_info->offset];
|
||||
|
||||
return !union_blob->unregistered;
|
||||
}
|
||||
|
||||
/* We don’t currently support boxed ‘other’ types (boxed types which aren’t
|
||||
* a struct or union. */
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
gi_registered_type_info_class_init (gpointer g_class,
|
||||
gpointer class_data)
|
||||
|
@ -69,4 +69,7 @@ const char * gi_registered_type_info_get_type_init_function_name (GIRe
|
||||
GI_AVAILABLE_IN_ALL
|
||||
GType gi_registered_type_info_get_g_type (GIRegisteredTypeInfo *info);
|
||||
|
||||
GI_AVAILABLE_IN_ALL
|
||||
gboolean gi_registered_type_info_is_boxed (GIRegisteredTypeInfo *info);
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -23,7 +23,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ffi.h>
|
||||
#include <glib.h>
|
||||
|
||||
#define __GIREPOSITORY_H_INSIDE__
|
||||
@ -72,8 +71,6 @@ G_STATIC_ASSERT (G_ALIGNOF (GIBaseInfo) == G_ALIGNOF (GIBaseInfoStack));
|
||||
* @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]
|
||||
@ -113,12 +110,13 @@ typedef enum
|
||||
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,
|
||||
/* 4 is skipped, it used to be BOXED, but was removed in girepository 2.80.
|
||||
* It is still part of the binary format in GITypelibBlobType. */
|
||||
GI_INFO_TYPE_ENUM = 5, /* 5 */
|
||||
GI_INFO_TYPE_FLAGS = 6,
|
||||
GI_INFO_TYPE_OBJECT = 7,
|
||||
GI_INFO_TYPE_INTERFACE = 8,
|
||||
GI_INFO_TYPE_CONSTANT = 9,
|
||||
/* 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,
|
||||
@ -227,14 +225,6 @@ struct _GIInterfaceInfo
|
||||
void gi_interface_info_class_init (gpointer g_class,
|
||||
gpointer class_data);
|
||||
|
||||
struct _GIBoxedInfo
|
||||
{
|
||||
GIRegisteredTypeInfo parent;
|
||||
};
|
||||
|
||||
void gi_boxed_info_class_init (gpointer g_class,
|
||||
gpointer class_data);
|
||||
|
||||
struct _GIConstantInfo
|
||||
{
|
||||
GIBaseInfo parent;
|
||||
|
@ -865,7 +865,7 @@ gi_repository_get_info (GIRepository *repository,
|
||||
entry = gi_typelib_get_dir_entry (typelib, idx + 1);
|
||||
g_return_val_if_fail (entry != NULL, NULL);
|
||||
|
||||
return gi_info_new_full (entry->blob_type,
|
||||
return gi_info_new_full (gi_typelib_blob_type_to_info_type (entry->blob_type),
|
||||
repository,
|
||||
NULL, typelib, entry->offset);
|
||||
}
|
||||
@ -966,7 +966,7 @@ gi_repository_find_by_gtype (GIRepository *repository,
|
||||
|
||||
if (entry != NULL)
|
||||
{
|
||||
cached = gi_info_new_full (entry->blob_type,
|
||||
cached = gi_info_new_full (gi_typelib_blob_type_to_info_type (entry->blob_type),
|
||||
repository,
|
||||
NULL, data.result_typelib, entry->offset);
|
||||
|
||||
@ -1015,7 +1015,7 @@ gi_repository_find_by_name (GIRepository *repository,
|
||||
entry = gi_typelib_get_dir_entry_by_name (typelib, name);
|
||||
if (entry == NULL)
|
||||
return NULL;
|
||||
return gi_info_new_full (entry->blob_type,
|
||||
return gi_info_new_full (gi_typelib_blob_type_to_info_type (entry->blob_type),
|
||||
repository,
|
||||
NULL, typelib, entry->offset);
|
||||
}
|
||||
@ -1086,7 +1086,7 @@ gi_repository_find_by_error_domain (GIRepository *repository,
|
||||
|
||||
if (data.result != NULL)
|
||||
{
|
||||
cached = (GIEnumInfo *) gi_info_new_full (data.result->blob_type,
|
||||
cached = (GIEnumInfo *) gi_info_new_full (gi_typelib_blob_type_to_info_type (data.result->blob_type),
|
||||
repository,
|
||||
NULL, data.result_typelib, data.result->offset);
|
||||
|
||||
@ -2065,8 +2065,6 @@ gi_info_type_to_string (GIInfoType type)
|
||||
return "callback";
|
||||
case GI_INFO_TYPE_STRUCT:
|
||||
return "struct";
|
||||
case GI_INFO_TYPE_BOXED:
|
||||
return "boxed";
|
||||
case GI_INFO_TYPE_ENUM:
|
||||
return "enum";
|
||||
case GI_INFO_TYPE_FLAGS:
|
||||
|
@ -33,7 +33,6 @@
|
||||
|
||||
#include <girepository/giarginfo.h>
|
||||
#include <girepository/gibaseinfo.h>
|
||||
#include <girepository/giboxedinfo.h>
|
||||
#include <girepository/gicallableinfo.h>
|
||||
#include <girepository/gicallbackinfo.h>
|
||||
#include <girepository/giconstantinfo.h>
|
||||
|
@ -660,7 +660,7 @@ write_struct_info (const char *ns,
|
||||
type_name = gi_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info);
|
||||
type_init = gi_registered_type_info_get_type_init_function_name ((GIRegisteredTypeInfo*)info);
|
||||
|
||||
if (GI_IS_BOXED_INFO (info))
|
||||
if (gi_registered_type_info_is_boxed (GI_REGISTERED_TYPE_INFO (info)))
|
||||
{
|
||||
xml_start_element (file, "glib:boxed");
|
||||
xml_printf (file, " glib:name=\"%s\"", name);
|
||||
@ -1257,6 +1257,7 @@ write_union_info (const char *ns,
|
||||
type_name = gi_registered_type_info_get_type_name ((GIRegisteredTypeInfo*)info);
|
||||
type_init = gi_registered_type_info_get_type_init_function_name ((GIRegisteredTypeInfo*)info);
|
||||
|
||||
/* FIXME: Add support for boxed unions */
|
||||
xml_start_element (file, "union");
|
||||
xml_printf (file, " name=\"%s\"", name);
|
||||
|
||||
@ -1420,8 +1421,7 @@ gi_ir_writer_write (const char *filename,
|
||||
write_function_info (ns, (GIFunctionInfo *)info, xml);
|
||||
else if (GI_IS_CALLBACK_INFO (info))
|
||||
write_callback_info (ns, (GICallbackInfo *)info, xml);
|
||||
else if (GI_IS_STRUCT_INFO (info) ||
|
||||
GI_IS_BOXED_INFO (info))
|
||||
else if (GI_IS_STRUCT_INFO (info))
|
||||
write_struct_info (ns, (GIStructInfo *)info, xml);
|
||||
else if (GI_IS_UNION_INFO (info))
|
||||
write_union_info (ns, (GIUnionInfo *)info, xml);
|
||||
|
@ -27,6 +27,7 @@
|
||||
|
||||
#include <gmodule.h>
|
||||
#include "girepository.h"
|
||||
#include "girepository-private.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -194,6 +195,8 @@ typedef enum {
|
||||
BLOB_TYPE_UNION
|
||||
} GITypelibBlobType;
|
||||
|
||||
GIInfoType gi_typelib_blob_type_to_info_type (GITypelibBlobType blob_type);
|
||||
|
||||
|
||||
#if defined (G_CAN_INLINE) && defined (G_ALWAYS_INLINE)
|
||||
|
||||
|
@ -43,6 +43,24 @@
|
||||
|
||||
G_DEFINE_BOXED_TYPE (GITypelib, gi_typelib, gi_typelib_ref, gi_typelib_unref)
|
||||
|
||||
GIInfoType
|
||||
gi_typelib_blob_type_to_info_type (GITypelibBlobType blob_type)
|
||||
{
|
||||
switch (blob_type)
|
||||
{
|
||||
case BLOB_TYPE_BOXED:
|
||||
/* `BLOB_TYPE_BOXED` now always refers to a `StructBlob`, and
|
||||
* `GIRegisteredTypeInfo` (the parent type of `GIStructInfo`) has a method
|
||||
* for distinguishing whether the struct is a boxed type. So presenting
|
||||
* `BLOB_TYPE_BOXED` as its own `GIBaseInfo` subclass is not helpful.
|
||||
* See commit e28078c70cbf4a57c7dbd39626f43f9bd2674145 and
|
||||
* https://gitlab.gnome.org/GNOME/glib/-/issues/3245. */
|
||||
return GI_INFO_TYPE_STRUCT;
|
||||
default:
|
||||
return (GIInfoType) blob_type;
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
GITypelib *typelib;
|
||||
GSList *context_stack;
|
||||
|
@ -92,10 +92,6 @@ GI_AVAILABLE_IN_ALL GType gi_object_info_get_type (void);
|
||||
typedef struct _GIInterfaceInfo GIInterfaceInfo;
|
||||
GI_AVAILABLE_IN_ALL GType gi_interface_info_get_type (void);
|
||||
|
||||
/* Documented in giboxedinfo.c */
|
||||
typedef struct _GIBoxedInfo GIBoxedInfo;
|
||||
GI_AVAILABLE_IN_ALL GType gi_boxed_info_get_type (void);
|
||||
|
||||
/* Documented in giconstantinfo.c */
|
||||
typedef struct _GIConstantInfo GIConstantInfo;
|
||||
GI_AVAILABLE_IN_ALL GType gi_constant_info_get_type (void);
|
||||
|
@ -44,7 +44,6 @@ gi_visibility_h = custom_target(
|
||||
girepo_headers = files(
|
||||
'giarginfo.h',
|
||||
'gibaseinfo.h',
|
||||
'giboxedinfo.h',
|
||||
'gicallableinfo.h',
|
||||
'gicallbackinfo.h',
|
||||
'giconstantinfo.h',
|
||||
@ -148,7 +147,6 @@ girepo_sources = files(
|
||||
'gdump.c',
|
||||
'giarginfo.c',
|
||||
'gibaseinfo.c',
|
||||
'giboxedinfo.c',
|
||||
'gicallableinfo.c',
|
||||
'gicallbackinfo.c',
|
||||
'giconstantinfo.c',
|
||||
|
@ -20,6 +20,9 @@ if enable_gir
|
||||
'object-info' : {
|
||||
'depends': [gio_gir],
|
||||
},
|
||||
'registered-type-info' : {
|
||||
'depends': [gobject_gir],
|
||||
},
|
||||
'repository' : {
|
||||
'depends': [glib_gir, gio_gir, gobject_gir],
|
||||
},
|
||||
|
137
girepository/tests/registered-type-info.c
Normal file
137
girepository/tests/registered-type-info.c
Normal file
@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright 2024 GNOME Foundation
|
||||
*
|
||||
* 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.1 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "girepository.h"
|
||||
#include "test-common.h"
|
||||
|
||||
static void
|
||||
test_boxed (RepositoryFixture *fx,
|
||||
const void *unused)
|
||||
{
|
||||
const struct
|
||||
{
|
||||
const char *name;
|
||||
GType expect_info_type;
|
||||
gboolean expect_nonnull_gtype_info;
|
||||
gboolean expect_is_gtype_struct;
|
||||
gboolean expect_boxed;
|
||||
}
|
||||
types[] =
|
||||
{
|
||||
{
|
||||
/* POD struct */
|
||||
.name = "CClosure",
|
||||
.expect_info_type = GI_TYPE_STRUCT_INFO,
|
||||
.expect_nonnull_gtype_info = FALSE,
|
||||
.expect_is_gtype_struct = FALSE,
|
||||
.expect_boxed = FALSE,
|
||||
},
|
||||
{
|
||||
/* POD union */
|
||||
.name = "TypeCValue",
|
||||
.expect_info_type = GI_TYPE_UNION_INFO,
|
||||
.expect_nonnull_gtype_info = FALSE,
|
||||
.expect_is_gtype_struct = FALSE,
|
||||
.expect_boxed = FALSE,
|
||||
},
|
||||
{
|
||||
/* struct for a different non-boxed GType */
|
||||
.name = "InitiallyUnownedClass",
|
||||
.expect_info_type = GI_TYPE_STRUCT_INFO,
|
||||
.expect_nonnull_gtype_info = FALSE,
|
||||
.expect_is_gtype_struct = TRUE,
|
||||
.expect_boxed = FALSE,
|
||||
},
|
||||
{
|
||||
/* boxed struct */
|
||||
.name = "BookmarkFile",
|
||||
.expect_info_type = GI_TYPE_STRUCT_INFO,
|
||||
.expect_nonnull_gtype_info = TRUE,
|
||||
.expect_is_gtype_struct = FALSE,
|
||||
.expect_boxed = TRUE,
|
||||
},
|
||||
{
|
||||
/* boxed struct */
|
||||
.name = "Closure",
|
||||
.expect_info_type = GI_TYPE_STRUCT_INFO,
|
||||
.expect_nonnull_gtype_info = TRUE,
|
||||
.expect_is_gtype_struct = FALSE,
|
||||
.expect_boxed = TRUE,
|
||||
},
|
||||
{
|
||||
/* non-boxed GType */
|
||||
.name = "Object",
|
||||
.expect_info_type = GI_TYPE_OBJECT_INFO,
|
||||
.expect_nonnull_gtype_info = TRUE,
|
||||
.expect_is_gtype_struct = FALSE,
|
||||
.expect_boxed = FALSE,
|
||||
},
|
||||
};
|
||||
|
||||
g_test_summary ("Test various boxed and non-boxed types for GIRegisteredTypeInfo");
|
||||
|
||||
for (size_t i = 0; i < G_N_ELEMENTS (types); i++)
|
||||
{
|
||||
GIRegisteredTypeInfo *type_info = GI_REGISTERED_TYPE_INFO (gi_repository_find_by_name (fx->repository, "GObject", types[i].name));
|
||||
g_assert_nonnull (type_info);
|
||||
|
||||
g_test_message ("Expecting %s to %s", types[i].name, types[i].expect_boxed ? "be boxed" : "not be boxed");
|
||||
|
||||
g_assert_cmpuint (G_TYPE_FROM_INSTANCE (type_info), ==, types[i].expect_info_type);
|
||||
|
||||
if (types[i].expect_nonnull_gtype_info)
|
||||
{
|
||||
g_assert_nonnull (gi_registered_type_info_get_type_name (type_info));
|
||||
g_assert_nonnull (gi_registered_type_info_get_type_init_function_name (type_info));
|
||||
}
|
||||
else
|
||||
{
|
||||
g_assert_null (gi_registered_type_info_get_type_name (type_info));
|
||||
g_assert_null (gi_registered_type_info_get_type_init_function_name (type_info));
|
||||
}
|
||||
|
||||
if (GI_IS_STRUCT_INFO (type_info))
|
||||
{
|
||||
if (types[i].expect_is_gtype_struct)
|
||||
g_assert_true (gi_struct_info_is_gtype_struct (GI_STRUCT_INFO (type_info)));
|
||||
else
|
||||
g_assert_false (gi_struct_info_is_gtype_struct (GI_STRUCT_INFO (type_info)));
|
||||
}
|
||||
|
||||
if (types[i].expect_boxed)
|
||||
g_assert_true (gi_registered_type_info_is_boxed (type_info));
|
||||
else
|
||||
g_assert_false (gi_registered_type_info_is_boxed (type_info));
|
||||
|
||||
g_clear_pointer (&type_info, gi_base_info_unref);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc,
|
||||
char *argv[])
|
||||
{
|
||||
repository_init (&argc, &argv);
|
||||
|
||||
ADD_REPOSITORY_TEST ("/registered-type-info/boxed", test_boxed, &typelib_load_spec_gobject);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
@ -234,21 +234,6 @@ test_repository_arg_info (RepositoryFixture *fx,
|
||||
g_clear_pointer (&struct_info, gi_base_info_unref);
|
||||
}
|
||||
|
||||
static void
|
||||
test_repository_boxed_info (RepositoryFixture *fx,
|
||||
const void *unused)
|
||||
{
|
||||
GIBoxedInfo *boxed_info = NULL;
|
||||
|
||||
g_test_summary ("Test retrieving GIBoxedInfos from a typelib");
|
||||
|
||||
/* Test all the methods of GIBoxedInfo. This is simple, because there are none. */
|
||||
boxed_info = GI_BOXED_INFO (gi_repository_find_by_name (fx->repository, "GObject", "BookmarkFile"));
|
||||
g_assert_nonnull (boxed_info);
|
||||
|
||||
g_clear_pointer (&boxed_info, gi_base_info_unref);
|
||||
}
|
||||
|
||||
static void
|
||||
test_repository_callable_info (RepositoryFixture *fx,
|
||||
const void *unused)
|
||||
@ -766,7 +751,6 @@ main (int argc,
|
||||
ADD_REPOSITORY_TEST ("/repository/info", test_repository_info, &typelib_load_spec_gobject);
|
||||
ADD_REPOSITORY_TEST ("/repository/dependencies", test_repository_dependencies, &typelib_load_spec_gobject);
|
||||
ADD_REPOSITORY_TEST ("/repository/arg-info", test_repository_arg_info, &typelib_load_spec_gobject);
|
||||
ADD_REPOSITORY_TEST ("/repository/boxed-info", test_repository_boxed_info, &typelib_load_spec_gobject);
|
||||
ADD_REPOSITORY_TEST ("/repository/callable-info", test_repository_callable_info, &typelib_load_spec_gobject);
|
||||
ADD_REPOSITORY_TEST ("/repository/callback-info", test_repository_callback_info, &typelib_load_spec_gobject);
|
||||
ADD_REPOSITORY_TEST ("/repository/char-types", test_repository_char_types, &typelib_load_spec_gobject);
|
||||
|
@ -106,6 +106,21 @@ test_is_pointer_for_struct_method_arg (RepositoryFixture *fx,
|
||||
g_clear_pointer (&variant_info, gi_base_info_unref);
|
||||
}
|
||||
|
||||
static void
|
||||
test_boxed (RepositoryFixture *fx,
|
||||
const void *unused)
|
||||
{
|
||||
GIStructInfo *struct_info = NULL;
|
||||
|
||||
g_test_summary ("Test that a boxed struct is recognised as such");
|
||||
|
||||
struct_info = GI_STRUCT_INFO (gi_repository_find_by_name (fx->repository, "GObject", "BookmarkFile"));
|
||||
g_assert_nonnull (struct_info);
|
||||
g_assert_true (gi_registered_type_info_is_boxed (GI_REGISTERED_TYPE_INFO (struct_info)));
|
||||
|
||||
g_clear_pointer (&struct_info, gi_base_info_unref);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc,
|
||||
char *argv[])
|
||||
@ -115,6 +130,7 @@ main (int argc,
|
||||
ADD_REPOSITORY_TEST ("/struct-info/field-iterators", test_field_iterators, &typelib_load_spec_gobject);
|
||||
ADD_REPOSITORY_TEST ("/struct-info/sizeof-gvalue", test_size_of_gvalue, &typelib_load_spec_gobject);
|
||||
ADD_REPOSITORY_TEST ("/struct-info/is-pointer-for-struct-method-arg", test_is_pointer_for_struct_method_arg, &typelib_load_spec_glib);
|
||||
ADD_REPOSITORY_TEST ("/struct-info/boxed", test_boxed, &typelib_load_spec_gobject);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user