2012-02-03 19:42:56 +01:00
|
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
|
|
|
|
* GObject introspection: Type implementation
|
2010-06-06 17:58:13 +02:00
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2005 Matthias Clasen
|
|
|
|
|
* Copyright (C) 2008,2009 Red Hat, Inc.
|
|
|
|
|
*
|
2023-10-25 18:10:10 +02:00
|
|
|
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
|
*
|
2010-06-06 17:58:13 +02:00
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2014-07-04 12:27:41 +02:00
|
|
|
|
#include "config.h"
|
|
|
|
|
|
2010-06-06 17:58:13 +02:00
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
2023-10-25 18:45:42 +02:00
|
|
|
|
#include <girepository/girepository.h>
|
2010-06-06 17:58:13 +02:00
|
|
|
|
#include "girepository-private.h"
|
|
|
|
|
#include "gitypelib-internal.h"
|
2023-10-25 19:11:38 +02:00
|
|
|
|
#include "gitypeinfo.h"
|
2010-06-06 17:58:13 +02:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* SECTION:gitypeinfo
|
2013-10-10 22:21:18 +02:00
|
|
|
|
* @title: GITypeInfo
|
|
|
|
|
* @short_description: Struct representing a type
|
2010-06-06 17:58:13 +02:00
|
|
|
|
*
|
2022-02-13 15:20:51 +01:00
|
|
|
|
* GITypeInfo represents a type.
|
|
|
|
|
*
|
|
|
|
|
* You can retrieve a type info from an argument (see #GIArgInfo), a
|
|
|
|
|
* functions return value (see #GIFunctionInfo), a field (see
|
|
|
|
|
* #GIFieldInfo), a property (see #GIPropertyInfo), a constant
|
2010-06-06 17:58:13 +02:00
|
|
|
|
* (see #GIConstantInfo) or for a union discriminator (see #GIUnionInfo).
|
|
|
|
|
*
|
|
|
|
|
* A type can either be a of a basic type which is a standard C primitive
|
|
|
|
|
* type or an interface type. For interface types you need to call
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_type_info_get_interface() to get a reference to the base info for that
|
2010-06-06 17:58:13 +02:00
|
|
|
|
* interface.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_type_info_is_pointer:
|
2010-06-06 17:58:13 +02:00
|
|
|
|
* @info: a #GITypeInfo
|
|
|
|
|
*
|
|
|
|
|
* Obtain if the type is passed as a reference.
|
|
|
|
|
*
|
2013-12-10 16:59:24 +01:00
|
|
|
|
* Note that the types of %GI_DIRECTION_OUT and %GI_DIRECTION_INOUT parameters
|
|
|
|
|
* will only be pointers if the underlying type being transferred is a pointer
|
|
|
|
|
* (i.e. only if the type of the C function’s formal parameter is a pointer to a
|
|
|
|
|
* pointer).
|
|
|
|
|
*
|
2010-06-06 17:58:13 +02:00
|
|
|
|
* Returns: %TRUE if it is a pointer
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_type_info_is_pointer (GITypeInfo *info)
|
2010-06-06 17:58:13 +02:00
|
|
|
|
{
|
|
|
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
|
|
|
SimpleTypeBlob *type;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (GI_IS_TYPE_INFO (info), FALSE);
|
|
|
|
|
|
|
|
|
|
type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
|
|
|
|
|
|
if (type->flags.reserved == 0 && type->flags.reserved2 == 0)
|
|
|
|
|
return type->flags.pointer;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
InterfaceTypeBlob *iface = (InterfaceTypeBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
|
|
|
|
|
|
return iface->pointer;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_type_info_get_tag:
|
2010-06-06 17:58:13 +02:00
|
|
|
|
* @info: a #GITypeInfo
|
|
|
|
|
*
|
|
|
|
|
* Obtain the type tag for the type. See #GITypeTag for a list
|
|
|
|
|
* of type tags.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the type tag
|
|
|
|
|
*/
|
|
|
|
|
GITypeTag
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_type_info_get_tag (GITypeInfo *info)
|
2010-06-06 17:58:13 +02:00
|
|
|
|
{
|
|
|
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
|
|
|
SimpleTypeBlob *type;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (info != NULL, GI_TYPE_TAG_BOOLEAN);
|
|
|
|
|
g_return_val_if_fail (GI_IS_TYPE_INFO (info), GI_TYPE_TAG_BOOLEAN);
|
|
|
|
|
|
|
|
|
|
type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
|
|
|
|
|
|
if (rinfo->type_is_embedded)
|
|
|
|
|
return GI_TYPE_TAG_INTERFACE;
|
|
|
|
|
else if (type->flags.reserved == 0 && type->flags.reserved2 == 0)
|
|
|
|
|
return type->flags.tag;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
InterfaceTypeBlob *iface = (InterfaceTypeBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
|
|
|
|
|
|
return iface->tag;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_type_info_get_param_type:
|
2010-06-06 17:58:13 +02:00
|
|
|
|
* @info: a #GITypeInfo
|
|
|
|
|
* @n: index of the parameter
|
|
|
|
|
*
|
2023-11-09 01:38:56 +01:00
|
|
|
|
* Obtain the parameter type @n, or `-1` if the type is not an array.
|
2010-06-06 17:58:13 +02:00
|
|
|
|
*
|
2023-11-09 01:38:56 +01:00
|
|
|
|
* Returns: (transfer full) (nullable): the param type info
|
2010-06-06 17:58:13 +02:00
|
|
|
|
*/
|
|
|
|
|
GITypeInfo *
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_type_info_get_param_type (GITypeInfo *info,
|
|
|
|
|
gint n)
|
2010-06-06 17:58:13 +02:00
|
|
|
|
{
|
|
|
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
|
|
|
SimpleTypeBlob *type;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail (GI_IS_TYPE_INFO (info), NULL);
|
|
|
|
|
|
|
|
|
|
type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
|
|
|
|
|
|
if (!(type->flags.reserved == 0 && type->flags.reserved2 == 0))
|
|
|
|
|
{
|
|
|
|
|
ParamTypeBlob *param = (ParamTypeBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
|
|
|
|
|
|
switch (param->tag)
|
|
|
|
|
{
|
|
|
|
|
case GI_TYPE_TAG_ARRAY:
|
|
|
|
|
case GI_TYPE_TAG_GLIST:
|
|
|
|
|
case GI_TYPE_TAG_GSLIST:
|
|
|
|
|
case GI_TYPE_TAG_GHASH:
|
2023-11-08 16:23:31 +01:00
|
|
|
|
return gi_type_info_new ((GIBaseInfo*)info, rinfo->typelib,
|
|
|
|
|
rinfo->offset + sizeof (ParamTypeBlob)
|
|
|
|
|
+ sizeof (SimpleTypeBlob) * n);
|
2010-06-06 17:58:13 +02:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_type_info_get_interface:
|
2010-06-06 17:58:13 +02:00
|
|
|
|
* @info: a #GITypeInfo
|
|
|
|
|
*
|
|
|
|
|
* For types which have #GI_TYPE_TAG_INTERFACE such as GObjects and boxed values,
|
|
|
|
|
* this function returns full information about the referenced type. You can then
|
|
|
|
|
* inspect the type of the returned #GIBaseInfo to further query whether it is
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* a concrete GObject, a GInterface, a structure, etc. using gi_base_info_get_type().
|
2010-06-06 17:58:13 +02:00
|
|
|
|
*
|
2023-11-09 01:38:56 +01:00
|
|
|
|
* Returns: (transfer full) (nullable): the #GIBaseInfo, or %NULL. Free it with
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_base_info_unref() when done.
|
2010-06-06 17:58:13 +02:00
|
|
|
|
*/
|
|
|
|
|
GIBaseInfo *
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_type_info_get_interface (GITypeInfo *info)
|
2010-06-06 17:58:13 +02:00
|
|
|
|
{
|
|
|
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail (GI_IS_TYPE_INFO (info), NULL);
|
|
|
|
|
|
|
|
|
|
/* For embedded types, the given offset is a pointer to the actual blob,
|
|
|
|
|
* after the end of the field. In that case we know it's a "subclass" of
|
|
|
|
|
* CommonBlob, so use that to determine the info type.
|
|
|
|
|
*/
|
|
|
|
|
if (rinfo->type_is_embedded)
|
|
|
|
|
{
|
|
|
|
|
CommonBlob *common = (CommonBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
|
GIInfoType info_type;
|
|
|
|
|
|
|
|
|
|
switch (common->blob_type)
|
|
|
|
|
{
|
|
|
|
|
case BLOB_TYPE_CALLBACK:
|
|
|
|
|
info_type = GI_INFO_TYPE_CALLBACK;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2023-11-08 15:17:52 +01:00
|
|
|
|
return (GIBaseInfo *) gi_info_new (info_type, (GIBaseInfo*)info, rinfo->typelib,
|
|
|
|
|
rinfo->offset);
|
2010-06-06 17:58:13 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SimpleTypeBlob *type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
|
if (!(type->flags.reserved == 0 && type->flags.reserved2 == 0))
|
|
|
|
|
{
|
|
|
|
|
InterfaceTypeBlob *blob = (InterfaceTypeBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
|
|
|
|
|
|
if (blob->tag == GI_TYPE_TAG_INTERFACE)
|
2023-11-08 16:23:31 +01:00
|
|
|
|
return gi_info_from_entry (rinfo->repository, rinfo->typelib, blob->interface);
|
2010-06-06 17:58:13 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_type_info_get_array_length:
|
2010-06-06 17:58:13 +02:00
|
|
|
|
* @info: a #GITypeInfo
|
|
|
|
|
*
|
2022-01-30 08:35:52 +01:00
|
|
|
|
* Obtain the position of the argument which gives the array length of the type.
|
|
|
|
|
* The type tag must be a #GI_TYPE_TAG_ARRAY or -1 will be returned.
|
2010-06-06 17:58:13 +02:00
|
|
|
|
*
|
|
|
|
|
* Returns: the array length, or -1 if the type is not an array
|
|
|
|
|
*/
|
|
|
|
|
gint
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_type_info_get_array_length (GITypeInfo *info)
|
2010-06-06 17:58:13 +02:00
|
|
|
|
{
|
|
|
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
|
|
|
SimpleTypeBlob *type;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (info != NULL, -1);
|
|
|
|
|
g_return_val_if_fail (GI_IS_TYPE_INFO (info), -1);
|
|
|
|
|
|
|
|
|
|
type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
|
|
|
|
|
|
if (!(type->flags.reserved == 0 && type->flags.reserved2 == 0))
|
|
|
|
|
{
|
|
|
|
|
ArrayTypeBlob *blob = (ArrayTypeBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
|
|
|
|
|
|
if (blob->tag == GI_TYPE_TAG_ARRAY)
|
|
|
|
|
{
|
|
|
|
|
if (blob->has_length)
|
|
|
|
|
return blob->dimensions.length;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_type_info_get_array_fixed_size:
|
2010-06-06 17:58:13 +02:00
|
|
|
|
* @info: a #GITypeInfo
|
|
|
|
|
*
|
|
|
|
|
* Obtain the fixed array size of the type. The type tag must be a
|
2022-01-30 08:35:52 +01:00
|
|
|
|
* #GI_TYPE_TAG_ARRAY or -1 will be returned.
|
2010-06-06 17:58:13 +02:00
|
|
|
|
*
|
|
|
|
|
* Returns: the size or -1 if it's not an array
|
|
|
|
|
*/
|
|
|
|
|
gint
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_type_info_get_array_fixed_size (GITypeInfo *info)
|
2010-06-06 17:58:13 +02:00
|
|
|
|
{
|
|
|
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
|
|
|
SimpleTypeBlob *type;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (info != NULL, 0);
|
|
|
|
|
g_return_val_if_fail (GI_IS_TYPE_INFO (info), 0);
|
|
|
|
|
|
|
|
|
|
type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
|
|
|
|
|
|
if (!(type->flags.reserved == 0 && type->flags.reserved2 == 0))
|
|
|
|
|
{
|
|
|
|
|
ArrayTypeBlob *blob = (ArrayTypeBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
|
|
|
|
|
|
if (blob->tag == GI_TYPE_TAG_ARRAY)
|
|
|
|
|
{
|
|
|
|
|
if (blob->has_size)
|
|
|
|
|
return blob->dimensions.size;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_type_info_is_zero_terminated:
|
2010-06-06 17:58:13 +02:00
|
|
|
|
* @info: a #GITypeInfo
|
|
|
|
|
*
|
|
|
|
|
* Obtain if the last element of the array is %NULL. The type tag must be a
|
2022-01-30 08:35:52 +01:00
|
|
|
|
* #GI_TYPE_TAG_ARRAY or %FALSE will be returned.
|
2010-06-06 17:58:13 +02:00
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if zero terminated
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_type_info_is_zero_terminated (GITypeInfo *info)
|
2010-06-06 17:58:13 +02:00
|
|
|
|
{
|
|
|
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
|
|
|
SimpleTypeBlob *type;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (GI_IS_TYPE_INFO (info), FALSE);
|
|
|
|
|
|
|
|
|
|
type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
|
|
|
|
|
|
if (!(type->flags.reserved == 0 && type->flags.reserved2 == 0))
|
|
|
|
|
{
|
|
|
|
|
ArrayTypeBlob *blob = (ArrayTypeBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
|
|
|
|
|
|
if (blob->tag == GI_TYPE_TAG_ARRAY)
|
|
|
|
|
return blob->zero_terminated;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_type_info_get_array_type:
|
2010-06-06 17:58:13 +02:00
|
|
|
|
* @info: a #GITypeInfo
|
|
|
|
|
*
|
|
|
|
|
* Obtain the array type for this type. See #GIArrayType for a list of
|
|
|
|
|
* possible values. If the type tag of this type is not array, -1 will be
|
|
|
|
|
* returned.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the array type or -1
|
|
|
|
|
*/
|
|
|
|
|
GIArrayType
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_type_info_get_array_type (GITypeInfo *info)
|
2010-06-06 17:58:13 +02:00
|
|
|
|
{
|
|
|
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
|
|
|
SimpleTypeBlob *type;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (info != NULL, -1);
|
|
|
|
|
g_return_val_if_fail (GI_IS_TYPE_INFO (info), -1);
|
|
|
|
|
|
|
|
|
|
type = (SimpleTypeBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
|
|
|
|
|
|
if (!(type->flags.reserved == 0 && type->flags.reserved2 == 0))
|
|
|
|
|
{
|
|
|
|
|
ArrayTypeBlob *blob = (ArrayTypeBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
|
g_return_val_if_fail (blob->tag == GI_TYPE_TAG_ARRAY, -1);
|
|
|
|
|
|
|
|
|
|
return blob->array_type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2020-04-11 23:22:18 +02:00
|
|
|
|
|
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_type_info_get_storage_type:
|
2020-04-11 23:22:18 +02:00
|
|
|
|
* @info: a #GITypeInfo
|
|
|
|
|
*
|
|
|
|
|
* Obtain the type tag corresponding to the underlying storage type in C for
|
|
|
|
|
* the type.
|
|
|
|
|
* See #GITypeTag for a list of type tags.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the type tag
|
|
|
|
|
*
|
2023-11-09 00:24:11 +01:00
|
|
|
|
* Since: 2.80
|
2020-04-11 23:22:18 +02:00
|
|
|
|
*/
|
|
|
|
|
GITypeTag
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_type_info_get_storage_type (GITypeInfo *info)
|
2020-04-11 23:22:18 +02:00
|
|
|
|
{
|
2023-11-08 15:17:52 +01:00
|
|
|
|
GITypeTag type_tag = gi_type_info_get_tag (info);
|
2020-04-11 23:22:18 +02:00
|
|
|
|
|
|
|
|
|
if (type_tag == GI_TYPE_TAG_INTERFACE)
|
|
|
|
|
{
|
2023-11-08 15:17:52 +01:00
|
|
|
|
GIBaseInfo *interface = gi_type_info_get_interface (info);
|
|
|
|
|
GIInfoType info_type = gi_base_info_get_type (interface);
|
2020-04-11 23:22:18 +02:00
|
|
|
|
if (info_type == GI_INFO_TYPE_ENUM || info_type == GI_INFO_TYPE_FLAGS)
|
2023-11-08 15:17:52 +01:00
|
|
|
|
type_tag = gi_enum_info_get_storage_type (interface);
|
|
|
|
|
gi_base_info_unref (interface);
|
2020-04-11 23:22:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return type_tag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-02-16 19:37:39 +01:00
|
|
|
|
* gi_type_tag_argument_from_hash_pointer:
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* @storage_type: a #GITypeTag obtained from gi_type_info_get_storage_type()
|
2020-04-11 23:22:18 +02:00
|
|
|
|
* @hash_pointer: A pointer, such as a #GHashTable data pointer
|
|
|
|
|
* @arg: A #GIArgument to fill in
|
|
|
|
|
*
|
|
|
|
|
* GLib data structures, such as #GList, #GSList, and #GHashTable, all store
|
|
|
|
|
* data pointers.
|
|
|
|
|
* In the case where the list or hash table is storing single types rather than
|
|
|
|
|
* structs, these data pointers may have values stuffed into them via macros
|
|
|
|
|
* such as %GPOINTER_TO_INT.
|
|
|
|
|
*
|
|
|
|
|
* Use this function to ensure that all values are correctly extracted from
|
|
|
|
|
* stuffed pointers, regardless of the machine's architecture or endianness.
|
|
|
|
|
*
|
|
|
|
|
* This function fills in the appropriate field of @arg with the value extracted
|
2022-02-16 19:37:39 +01:00
|
|
|
|
* from @hash_pointer, depending on @storage_type.
|
2020-04-11 23:22:18 +02:00
|
|
|
|
*
|
2023-11-09 00:24:11 +01:00
|
|
|
|
* Since: 2.80
|
2020-04-11 23:22:18 +02:00
|
|
|
|
*/
|
|
|
|
|
void
|
2022-02-16 19:37:39 +01:00
|
|
|
|
gi_type_tag_argument_from_hash_pointer (GITypeTag storage_type,
|
|
|
|
|
gpointer hash_pointer,
|
2020-04-11 23:22:18 +02:00
|
|
|
|
GIArgument *arg)
|
|
|
|
|
{
|
2022-02-16 19:37:39 +01:00
|
|
|
|
switch (storage_type)
|
2020-04-11 23:22:18 +02:00
|
|
|
|
{
|
|
|
|
|
case GI_TYPE_TAG_BOOLEAN:
|
|
|
|
|
arg->v_boolean = !!GPOINTER_TO_INT (hash_pointer);
|
|
|
|
|
break;
|
|
|
|
|
case GI_TYPE_TAG_INT8:
|
|
|
|
|
arg->v_int8 = (gint8)GPOINTER_TO_INT (hash_pointer);
|
|
|
|
|
break;
|
|
|
|
|
case GI_TYPE_TAG_UINT8:
|
|
|
|
|
arg->v_uint8 = (guint8)GPOINTER_TO_UINT (hash_pointer);
|
|
|
|
|
break;
|
|
|
|
|
case GI_TYPE_TAG_INT16:
|
|
|
|
|
arg->v_int16 = (gint16)GPOINTER_TO_INT (hash_pointer);
|
|
|
|
|
break;
|
|
|
|
|
case GI_TYPE_TAG_UINT16:
|
|
|
|
|
arg->v_uint16 = (guint16)GPOINTER_TO_UINT (hash_pointer);
|
|
|
|
|
break;
|
|
|
|
|
case GI_TYPE_TAG_INT32:
|
|
|
|
|
arg->v_int32 = (gint32)GPOINTER_TO_INT (hash_pointer);
|
|
|
|
|
break;
|
|
|
|
|
case GI_TYPE_TAG_UINT32:
|
|
|
|
|
case GI_TYPE_TAG_UNICHAR:
|
|
|
|
|
arg->v_uint32 = (guint32)GPOINTER_TO_UINT (hash_pointer);
|
|
|
|
|
break;
|
|
|
|
|
case GI_TYPE_TAG_GTYPE:
|
|
|
|
|
arg->v_size = GPOINTER_TO_SIZE (hash_pointer);
|
|
|
|
|
break;
|
|
|
|
|
case GI_TYPE_TAG_UTF8:
|
|
|
|
|
case GI_TYPE_TAG_FILENAME:
|
|
|
|
|
case GI_TYPE_TAG_INTERFACE:
|
|
|
|
|
case GI_TYPE_TAG_ARRAY:
|
|
|
|
|
case GI_TYPE_TAG_GLIST:
|
|
|
|
|
case GI_TYPE_TAG_GSLIST:
|
|
|
|
|
case GI_TYPE_TAG_GHASH:
|
|
|
|
|
case GI_TYPE_TAG_ERROR:
|
|
|
|
|
arg->v_pointer = hash_pointer;
|
|
|
|
|
break;
|
|
|
|
|
case GI_TYPE_TAG_INT64:
|
|
|
|
|
case GI_TYPE_TAG_UINT64:
|
|
|
|
|
case GI_TYPE_TAG_FLOAT:
|
|
|
|
|
case GI_TYPE_TAG_DOUBLE:
|
|
|
|
|
default:
|
2022-02-16 19:37:39 +01:00
|
|
|
|
g_critical ("Unsupported storage type for pointer-stuffing: %s",
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_type_tag_to_string (storage_type));
|
2020-04-11 23:22:18 +02:00
|
|
|
|
arg->v_pointer = hash_pointer;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_type_info_argument_from_hash_pointer:
|
2020-04-11 23:22:18 +02:00
|
|
|
|
* @info: a #GITypeInfo
|
2022-02-16 19:37:39 +01:00
|
|
|
|
* @hash_pointer: A pointer, such as a #GHashTable data pointer
|
|
|
|
|
* @arg: A #GIArgument to fill in
|
|
|
|
|
*
|
|
|
|
|
* GLib data structures, such as #GList, #GSList, and #GHashTable, all store
|
|
|
|
|
* data pointers.
|
|
|
|
|
* In the case where the list or hash table is storing single types rather than
|
|
|
|
|
* structs, these data pointers may have values stuffed into them via macros
|
|
|
|
|
* such as %GPOINTER_TO_INT.
|
|
|
|
|
*
|
|
|
|
|
* Use this function to ensure that all values are correctly extracted from
|
|
|
|
|
* stuffed pointers, regardless of the machine's architecture or endianness.
|
|
|
|
|
*
|
|
|
|
|
* This function fills in the appropriate field of @arg with the value extracted
|
|
|
|
|
* from @hash_pointer, depending on the storage type of @info.
|
|
|
|
|
*
|
2023-11-09 00:24:11 +01:00
|
|
|
|
* Since: 2.80
|
2022-02-16 19:37:39 +01:00
|
|
|
|
*/
|
|
|
|
|
void
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_type_info_argument_from_hash_pointer (GITypeInfo *info,
|
|
|
|
|
gpointer hash_pointer,
|
|
|
|
|
GIArgument *arg)
|
2022-02-16 19:37:39 +01:00
|
|
|
|
{
|
2023-11-08 15:17:52 +01:00
|
|
|
|
GITypeTag storage_type = gi_type_info_get_storage_type (info);
|
2022-03-10 11:11:05 +01:00
|
|
|
|
gi_type_tag_argument_from_hash_pointer (storage_type, hash_pointer,
|
|
|
|
|
arg);
|
2022-02-16 19:37:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gi_type_tag_hash_pointer_from_argument:
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* @storage_type: a #GITypeTag obtained from gi_get_storage_type()
|
2020-04-11 23:22:18 +02:00
|
|
|
|
* @arg: A #GIArgument with the value to stuff into a pointer
|
|
|
|
|
*
|
|
|
|
|
* GLib data structures, such as #GList, #GSList, and #GHashTable, all store
|
|
|
|
|
* data pointers.
|
|
|
|
|
* In the case where the list or hash table is storing single types rather than
|
|
|
|
|
* structs, these data pointers may have values stuffed into them via macros
|
|
|
|
|
* such as %GPOINTER_TO_INT.
|
|
|
|
|
*
|
|
|
|
|
* Use this function to ensure that all values are correctly stuffed into
|
|
|
|
|
* pointers, regardless of the machine's architecture or endianness.
|
|
|
|
|
*
|
|
|
|
|
* This function returns a pointer stuffed with the appropriate field of @arg,
|
2022-02-16 19:37:39 +01:00
|
|
|
|
* depending on @storage_type.
|
2020-04-11 23:22:18 +02:00
|
|
|
|
*
|
|
|
|
|
* Returns: A stuffed pointer, that can be stored in a #GHashTable, for example
|
|
|
|
|
*
|
2023-11-09 00:24:11 +01:00
|
|
|
|
* Since: 2.80
|
2020-04-11 23:22:18 +02:00
|
|
|
|
*/
|
|
|
|
|
gpointer
|
2022-02-16 19:37:39 +01:00
|
|
|
|
gi_type_tag_hash_pointer_from_argument (GITypeTag storage_type,
|
2020-04-11 23:22:18 +02:00
|
|
|
|
GIArgument *arg)
|
|
|
|
|
{
|
2022-02-16 19:37:39 +01:00
|
|
|
|
switch (storage_type)
|
2020-04-11 23:22:18 +02:00
|
|
|
|
{
|
|
|
|
|
case GI_TYPE_TAG_BOOLEAN:
|
|
|
|
|
return GINT_TO_POINTER (arg->v_boolean);
|
|
|
|
|
case GI_TYPE_TAG_INT8:
|
|
|
|
|
return GINT_TO_POINTER (arg->v_int8);
|
|
|
|
|
case GI_TYPE_TAG_UINT8:
|
|
|
|
|
return GUINT_TO_POINTER (arg->v_uint8);
|
|
|
|
|
case GI_TYPE_TAG_INT16:
|
|
|
|
|
return GINT_TO_POINTER (arg->v_int16);
|
|
|
|
|
case GI_TYPE_TAG_UINT16:
|
|
|
|
|
return GUINT_TO_POINTER (arg->v_uint16);
|
|
|
|
|
case GI_TYPE_TAG_INT32:
|
|
|
|
|
return GINT_TO_POINTER (arg->v_int32);
|
|
|
|
|
case GI_TYPE_TAG_UINT32:
|
|
|
|
|
case GI_TYPE_TAG_UNICHAR:
|
|
|
|
|
return GUINT_TO_POINTER (arg->v_uint32);
|
|
|
|
|
case GI_TYPE_TAG_GTYPE:
|
|
|
|
|
return GSIZE_TO_POINTER (arg->v_size);
|
|
|
|
|
case GI_TYPE_TAG_UTF8:
|
|
|
|
|
case GI_TYPE_TAG_FILENAME:
|
|
|
|
|
case GI_TYPE_TAG_INTERFACE:
|
|
|
|
|
case GI_TYPE_TAG_ARRAY:
|
|
|
|
|
case GI_TYPE_TAG_GLIST:
|
|
|
|
|
case GI_TYPE_TAG_GSLIST:
|
|
|
|
|
case GI_TYPE_TAG_GHASH:
|
|
|
|
|
case GI_TYPE_TAG_ERROR:
|
|
|
|
|
return arg->v_pointer;
|
|
|
|
|
case GI_TYPE_TAG_INT64:
|
|
|
|
|
case GI_TYPE_TAG_UINT64:
|
|
|
|
|
case GI_TYPE_TAG_FLOAT:
|
|
|
|
|
case GI_TYPE_TAG_DOUBLE:
|
|
|
|
|
default:
|
2022-02-16 19:37:39 +01:00
|
|
|
|
g_critical ("Unsupported storage type for pointer-stuffing: %s",
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_type_tag_to_string (storage_type));
|
2020-04-11 23:22:18 +02:00
|
|
|
|
return arg->v_pointer;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-16 19:37:39 +01:00
|
|
|
|
|
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_type_info_hash_pointer_from_argument:
|
2022-02-16 19:37:39 +01:00
|
|
|
|
* @info: a #GITypeInfo
|
|
|
|
|
* @arg: A #GIArgument with the value to stuff into a pointer
|
|
|
|
|
*
|
|
|
|
|
* GLib data structures, such as #GList, #GSList, and #GHashTable, all store
|
|
|
|
|
* data pointers.
|
|
|
|
|
* In the case where the list or hash table is storing single types rather than
|
|
|
|
|
* structs, these data pointers may have values stuffed into them via macros
|
|
|
|
|
* such as %GPOINTER_TO_INT.
|
|
|
|
|
*
|
|
|
|
|
* Use this function to ensure that all values are correctly stuffed into
|
|
|
|
|
* pointers, regardless of the machine's architecture or endianness.
|
|
|
|
|
*
|
|
|
|
|
* This function returns a pointer stuffed with the appropriate field of @arg,
|
|
|
|
|
* depending on the storage type of @info.
|
|
|
|
|
*
|
|
|
|
|
* Returns: A stuffed pointer, that can be stored in a #GHashTable, for example
|
|
|
|
|
*
|
2023-11-09 00:24:11 +01:00
|
|
|
|
* Since: 2.80
|
2022-02-16 19:37:39 +01:00
|
|
|
|
*/
|
|
|
|
|
gpointer
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_type_info_hash_pointer_from_argument (GITypeInfo *info,
|
|
|
|
|
GIArgument *arg)
|
2022-02-16 19:37:39 +01:00
|
|
|
|
{
|
2023-11-08 15:17:52 +01:00
|
|
|
|
GITypeTag storage_type = gi_type_info_get_storage_type (info);
|
2022-02-16 19:37:39 +01:00
|
|
|
|
return gi_type_tag_hash_pointer_from_argument (storage_type, arg);
|
|
|
|
|
}
|