2012-02-03 19:42:56 +01:00
|
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
|
|
|
|
* GObject introspection: Callable implementation
|
2010-06-05 17:11:58 +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-05 17:11:58 +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-15 17:01:37 +02:00
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
2010-06-05 17:11:58 +02:00
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
2023-10-25 18:45:42 +02:00
|
|
|
|
#include <girepository/girepository.h>
|
2023-11-28 18:24:20 +01:00
|
|
|
|
#include "gibaseinfo-private.h"
|
2010-06-05 17:11:58 +02:00
|
|
|
|
#include "girepository-private.h"
|
|
|
|
|
#include "gitypelib-internal.h"
|
2010-12-13 13:53:55 +01:00
|
|
|
|
#include "girffi.h"
|
2023-10-25 19:11:38 +02:00
|
|
|
|
#include "gicallableinfo.h"
|
2010-06-05 17:11:58 +02:00
|
|
|
|
|
2024-05-07 15:46:13 +02:00
|
|
|
|
#define GET_BLOB(Type, rinfo) ((Type *) &rinfo->typelib->data[rinfo->offset])
|
|
|
|
|
|
2010-06-05 17:11:58 +02:00
|
|
|
|
/* GICallableInfo functions */
|
|
|
|
|
|
|
|
|
|
/**
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* GICallableInfo:
|
2010-06-05 17:11:58 +02:00
|
|
|
|
*
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* `GICallableInfo` represents an entity which is callable.
|
2022-02-13 15:20:51 +01:00
|
|
|
|
*
|
|
|
|
|
* Examples of callable are:
|
|
|
|
|
*
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* - functions ([class@GIRepository.FunctionInfo])
|
|
|
|
|
* - virtual functions ([class@GIRepository.VFuncInfo])
|
|
|
|
|
* - callbacks ([class@GIRepository.CallbackInfo]).
|
2010-06-05 17:11:58 +02:00
|
|
|
|
*
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* A callable has a list of arguments ([class@GIRepository.ArgInfo]), a return
|
|
|
|
|
* type, direction and a flag which decides if it returns `NULL`.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.80
|
2010-06-05 17:11:58 +02:00
|
|
|
|
*/
|
|
|
|
|
|
2024-01-15 22:20:02 +01:00
|
|
|
|
static uint32_t
|
2010-06-05 17:11:58 +02:00
|
|
|
|
signature_offset (GICallableInfo *info)
|
|
|
|
|
{
|
|
|
|
|
GIRealInfo *rinfo = (GIRealInfo*)info;
|
|
|
|
|
int sigoff = -1;
|
|
|
|
|
|
2023-12-12 17:16:30 +01:00
|
|
|
|
switch (gi_base_info_get_info_type ((GIBaseInfo *) info))
|
2010-06-05 17:11:58 +02:00
|
|
|
|
{
|
|
|
|
|
case GI_INFO_TYPE_FUNCTION:
|
|
|
|
|
sigoff = G_STRUCT_OFFSET (FunctionBlob, signature);
|
|
|
|
|
break;
|
|
|
|
|
case GI_INFO_TYPE_VFUNC:
|
|
|
|
|
sigoff = G_STRUCT_OFFSET (VFuncBlob, signature);
|
|
|
|
|
break;
|
|
|
|
|
case GI_INFO_TYPE_CALLBACK:
|
|
|
|
|
sigoff = G_STRUCT_OFFSET (CallbackBlob, signature);
|
|
|
|
|
break;
|
|
|
|
|
case GI_INFO_TYPE_SIGNAL:
|
|
|
|
|
sigoff = G_STRUCT_OFFSET (SignalBlob, signature);
|
|
|
|
|
break;
|
2018-07-29 17:13:16 +02:00
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
2010-06-05 17:11:58 +02:00
|
|
|
|
}
|
|
|
|
|
if (sigoff >= 0)
|
2024-01-15 22:20:02 +01:00
|
|
|
|
return *(uint32_t *)&rinfo->typelib->data[rinfo->offset + sigoff];
|
2010-06-05 17:11:58 +02:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-09 20:41:39 +02:00
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_callable_info_can_throw_gerror:
|
2012-04-09 20:41:39 +02:00
|
|
|
|
* @info: a #GICallableInfo
|
|
|
|
|
*
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* Whether the callable can throw a [type@GLib.Error]
|
2012-04-09 20:41:39 +02:00
|
|
|
|
*
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* Returns: `TRUE` if this `GICallableInfo` can throw a [type@GLib.Error]
|
2023-11-09 00:24:11 +01:00
|
|
|
|
* Since: 2.80
|
2012-04-09 20:41:39 +02:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_callable_info_can_throw_gerror (GICallableInfo *info)
|
2012-04-09 20:41:39 +02:00
|
|
|
|
{
|
|
|
|
|
GIRealInfo *rinfo = (GIRealInfo*)info;
|
2015-06-03 14:24:21 +02:00
|
|
|
|
SignatureBlob *signature;
|
|
|
|
|
|
|
|
|
|
signature = (SignatureBlob *)&rinfo->typelib->data[signature_offset (info)];
|
|
|
|
|
if (signature->throws)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
/* Functions and VFuncs store "throws" in their own blobs.
|
|
|
|
|
* This info was additionally added to the SignatureBlob
|
|
|
|
|
* to support the other callables. For Functions and VFuncs,
|
|
|
|
|
* also check their legacy flag for compatibility.
|
|
|
|
|
*/
|
2023-12-12 17:16:30 +01:00
|
|
|
|
switch (gi_base_info_get_info_type ((GIBaseInfo *) info)) {
|
2012-04-09 20:41:39 +02:00
|
|
|
|
case GI_INFO_TYPE_FUNCTION:
|
|
|
|
|
{
|
|
|
|
|
FunctionBlob *blob;
|
|
|
|
|
blob = (FunctionBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
|
return blob->throws;
|
|
|
|
|
}
|
|
|
|
|
case GI_INFO_TYPE_VFUNC:
|
|
|
|
|
{
|
|
|
|
|
VFuncBlob *blob;
|
|
|
|
|
blob = (VFuncBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
|
return blob->throws;
|
|
|
|
|
}
|
|
|
|
|
case GI_INFO_TYPE_CALLBACK:
|
|
|
|
|
case GI_INFO_TYPE_SIGNAL:
|
|
|
|
|
return FALSE;
|
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_callable_info_is_method:
|
2012-04-09 20:41:39 +02:00
|
|
|
|
* @info: a #GICallableInfo
|
|
|
|
|
*
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* Determines if the callable info is a method.
|
2012-04-09 20:41:39 +02:00
|
|
|
|
*
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* For [class@GIRepository.VFuncInfo]s, [class@GIRepository.CallbackInfo]s, and
|
|
|
|
|
* [class@GIRepository.SignalInfo]s, this is always true. Otherwise, this looks
|
|
|
|
|
* at the `GI_FUNCTION_IS_METHOD` flag on the [class@GIRepository.FunctionInfo].
|
2012-04-09 20:41:39 +02:00
|
|
|
|
*
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* Concretely, this function returns whether
|
|
|
|
|
* [method@GIRepository.CallableInfo.get_n_args] matches the number of arguments
|
|
|
|
|
* in the raw C method. For methods, there is one more C argument than is
|
|
|
|
|
* exposed by introspection: the `self` or `this` object.
|
|
|
|
|
*
|
|
|
|
|
* Returns: `TRUE` if @info is a method, `FALSE` otherwise
|
2023-11-09 00:24:11 +01:00
|
|
|
|
* Since: 2.80
|
2012-04-09 20:41:39 +02:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_callable_info_is_method (GICallableInfo *info)
|
2012-04-09 20:41:39 +02:00
|
|
|
|
{
|
|
|
|
|
GIRealInfo *rinfo = (GIRealInfo*)info;
|
2023-12-12 17:16:30 +01:00
|
|
|
|
switch (gi_base_info_get_info_type ((GIBaseInfo *) info)) {
|
2012-04-09 20:41:39 +02:00
|
|
|
|
case GI_INFO_TYPE_FUNCTION:
|
|
|
|
|
{
|
|
|
|
|
FunctionBlob *blob;
|
|
|
|
|
blob = (FunctionBlob *)&rinfo->typelib->data[rinfo->offset];
|
|
|
|
|
return (!blob->constructor && !blob->is_static);
|
|
|
|
|
}
|
|
|
|
|
case GI_INFO_TYPE_VFUNC:
|
|
|
|
|
case GI_INFO_TYPE_SIGNAL:
|
|
|
|
|
return TRUE;
|
|
|
|
|
case GI_INFO_TYPE_CALLBACK:
|
|
|
|
|
return FALSE;
|
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-05 17:11:58 +02:00
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_callable_info_get_return_type:
|
2010-06-05 17:11:58 +02:00
|
|
|
|
* @info: a #GICallableInfo
|
|
|
|
|
*
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* Obtain the return type of a callable item as a [class@GIRepository.TypeInfo].
|
2010-06-05 17:11:58 +02:00
|
|
|
|
*
|
2024-02-07 16:59:56 +01:00
|
|
|
|
* If the callable doesn’t return anything, a [class@GIRepository.TypeInfo] of
|
|
|
|
|
* type [enum@GIRepository.TypeTag.VOID] will be returned.
|
|
|
|
|
*
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* Returns: (transfer full): the [class@GIRepository.TypeInfo]. Free the struct
|
|
|
|
|
* by calling [method@GIRepository.BaseInfo.unref] when done.
|
|
|
|
|
* Since: 2.80
|
2010-06-05 17:11:58 +02:00
|
|
|
|
*/
|
|
|
|
|
GITypeInfo *
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_callable_info_get_return_type (GICallableInfo *info)
|
2010-06-05 17:11:58 +02:00
|
|
|
|
{
|
|
|
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
2024-01-15 22:20:02 +01:00
|
|
|
|
uint32_t offset;
|
2010-06-05 17:11:58 +02:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail (GI_IS_CALLABLE_INFO (info), NULL);
|
|
|
|
|
|
|
|
|
|
offset = signature_offset (info);
|
|
|
|
|
|
2023-11-08 16:23:31 +01:00
|
|
|
|
return gi_type_info_new ((GIBaseInfo*)info, rinfo->typelib, offset);
|
2010-06-05 17:11:58 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_callable_info_load_return_type:
|
2010-06-05 17:11:58 +02:00
|
|
|
|
* @info: a #GICallableInfo
|
|
|
|
|
* @type: (out caller-allocates): Initialized with return type of @info
|
|
|
|
|
*
|
|
|
|
|
* Obtain information about a return value of callable; this
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* function is a variant of [method@GIRepository.CallableInfo.get_return_type]
|
|
|
|
|
* designed for stack allocation.
|
2010-06-05 17:11:58 +02:00
|
|
|
|
*
|
|
|
|
|
* The initialized @type must not be referenced after @info is deallocated.
|
2023-12-13 01:26:23 +01:00
|
|
|
|
*
|
2024-01-23 19:07:17 +01:00
|
|
|
|
* Once you are done with @type, it must be cleared using
|
|
|
|
|
* [method@GIRepository.BaseInfo.clear].
|
|
|
|
|
*
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* Since: 2.80
|
2010-06-05 17:11:58 +02:00
|
|
|
|
*/
|
|
|
|
|
void
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_callable_info_load_return_type (GICallableInfo *info,
|
|
|
|
|
GITypeInfo *type)
|
2010-06-05 17:11:58 +02:00
|
|
|
|
{
|
|
|
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
2024-01-15 22:20:02 +01:00
|
|
|
|
uint32_t offset;
|
2010-06-05 17:11:58 +02:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (info != NULL);
|
|
|
|
|
g_return_if_fail (GI_IS_CALLABLE_INFO (info));
|
|
|
|
|
|
|
|
|
|
offset = signature_offset (info);
|
|
|
|
|
|
2024-01-23 18:53:15 +01:00
|
|
|
|
gi_type_info_init (type, (GIBaseInfo*)info, rinfo->typelib, offset);
|
2010-06-05 17:11:58 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_callable_info_may_return_null:
|
2010-06-05 17:11:58 +02:00
|
|
|
|
* @info: a #GICallableInfo
|
|
|
|
|
*
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* See if a callable could return `NULL`.
|
2010-06-05 17:11:58 +02:00
|
|
|
|
*
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* Returns: `TRUE` if callable could return `NULL`
|
|
|
|
|
* Since: 2.80
|
2010-06-05 17:11:58 +02:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_callable_info_may_return_null (GICallableInfo *info)
|
2010-06-05 17:11:58 +02:00
|
|
|
|
{
|
|
|
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
|
|
|
SignatureBlob *blob;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (GI_IS_CALLABLE_INFO (info), FALSE);
|
|
|
|
|
|
|
|
|
|
blob = (SignatureBlob *)&rinfo->typelib->data[signature_offset (info)];
|
|
|
|
|
|
|
|
|
|
return blob->may_return_null;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-13 18:20:05 +02:00
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_callable_info_skip_return:
|
2011-05-13 18:20:05 +02:00
|
|
|
|
* @info: a #GICallableInfo
|
|
|
|
|
*
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* See if a callable’s return value is only useful in C.
|
2011-05-13 18:20:05 +02:00
|
|
|
|
*
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* Returns: `TRUE` if return value is only useful in C.
|
|
|
|
|
* Since: 2.80
|
2011-05-13 18:20:05 +02:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_callable_info_skip_return (GICallableInfo *info)
|
2011-05-13 18:20:05 +02:00
|
|
|
|
{
|
|
|
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
|
|
|
SignatureBlob *blob;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (GI_IS_CALLABLE_INFO (info), FALSE);
|
|
|
|
|
|
|
|
|
|
blob = (SignatureBlob *)&rinfo->typelib->data[signature_offset (info)];
|
|
|
|
|
|
|
|
|
|
return blob->skip_return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-05 17:11:58 +02:00
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_callable_info_get_caller_owns:
|
2010-06-05 17:11:58 +02:00
|
|
|
|
* @info: a #GICallableInfo
|
|
|
|
|
*
|
|
|
|
|
* See whether the caller owns the return value of this callable.
|
2023-12-13 01:26:23 +01:00
|
|
|
|
*
|
|
|
|
|
* [type@GIRepository.Transfer] contains a list of possible transfer values.
|
2010-06-05 17:11:58 +02:00
|
|
|
|
*
|
2016-05-19 00:10:46 +02:00
|
|
|
|
* Returns: the transfer mode for the return value of the callable
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* Since: 2.80
|
2010-06-05 17:11:58 +02:00
|
|
|
|
*/
|
|
|
|
|
GITransfer
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_callable_info_get_caller_owns (GICallableInfo *info)
|
2010-06-05 17:11:58 +02:00
|
|
|
|
{
|
|
|
|
|
GIRealInfo *rinfo = (GIRealInfo*) info;
|
|
|
|
|
SignatureBlob *blob;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (info != NULL, -1);
|
|
|
|
|
g_return_val_if_fail (GI_IS_CALLABLE_INFO (info), -1);
|
|
|
|
|
|
|
|
|
|
blob = (SignatureBlob *)&rinfo->typelib->data[signature_offset (info)];
|
|
|
|
|
|
|
|
|
|
if (blob->caller_owns_return_value)
|
|
|
|
|
return GI_TRANSFER_EVERYTHING;
|
|
|
|
|
else if (blob->caller_owns_return_container)
|
|
|
|
|
return GI_TRANSFER_CONTAINER;
|
|
|
|
|
else
|
|
|
|
|
return GI_TRANSFER_NOTHING;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-06 18:53:21 +02:00
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_callable_info_get_instance_ownership_transfer:
|
2014-05-06 18:53:21 +02:00
|
|
|
|
* @info: a #GICallableInfo
|
|
|
|
|
*
|
|
|
|
|
* Obtains the ownership transfer for the instance argument.
|
|
|
|
|
*
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* [type@GIRepository.Transfer] contains a list of possible transfer values.
|
|
|
|
|
*
|
2016-05-19 00:11:34 +02:00
|
|
|
|
* Returns: the transfer mode of the instance argument
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* Since: 2.80
|
2014-05-06 18:53:21 +02:00
|
|
|
|
*/
|
|
|
|
|
GITransfer
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_callable_info_get_instance_ownership_transfer (GICallableInfo *info)
|
2014-05-06 18:53:21 +02:00
|
|
|
|
{
|
|
|
|
|
GIRealInfo *rinfo = (GIRealInfo*) info;
|
|
|
|
|
SignatureBlob *blob;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (info != NULL, -1);
|
|
|
|
|
g_return_val_if_fail (GI_IS_CALLABLE_INFO (info), -1);
|
|
|
|
|
|
|
|
|
|
blob = (SignatureBlob *)&rinfo->typelib->data[signature_offset (info)];
|
|
|
|
|
|
|
|
|
|
if (blob->instance_transfer_ownership)
|
|
|
|
|
return GI_TRANSFER_EVERYTHING;
|
|
|
|
|
else
|
|
|
|
|
return GI_TRANSFER_NOTHING;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-05 17:11:58 +02:00
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_callable_info_get_n_args:
|
2010-06-05 17:11:58 +02:00
|
|
|
|
* @info: a #GICallableInfo
|
|
|
|
|
*
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* Obtain the number of arguments (both ‘in’ and ‘out’) for this callable.
|
2010-06-05 17:11:58 +02:00
|
|
|
|
*
|
|
|
|
|
* Returns: The number of arguments this callable expects.
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* Since: 2.80
|
2010-06-05 17:11:58 +02:00
|
|
|
|
*/
|
2024-01-15 22:20:02 +01:00
|
|
|
|
unsigned int
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_callable_info_get_n_args (GICallableInfo *info)
|
2010-06-05 17:11:58 +02:00
|
|
|
|
{
|
|
|
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
2024-01-15 22:20:02 +01:00
|
|
|
|
uint32_t offset;
|
2010-06-05 17:11:58 +02:00
|
|
|
|
SignatureBlob *blob;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (info != NULL, -1);
|
|
|
|
|
g_return_val_if_fail (GI_IS_CALLABLE_INFO (info), -1);
|
|
|
|
|
|
|
|
|
|
offset = signature_offset (info);
|
|
|
|
|
blob = (SignatureBlob *)&rinfo->typelib->data[offset];
|
|
|
|
|
|
|
|
|
|
return blob->n_arguments;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_callable_info_get_arg:
|
2010-06-05 17:11:58 +02:00
|
|
|
|
* @info: a #GICallableInfo
|
|
|
|
|
* @n: the argument index to fetch
|
|
|
|
|
*
|
|
|
|
|
* Obtain information about a particular argument of this callable.
|
|
|
|
|
*
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* Returns: (transfer full): the [class@GIRepository.ArgInfo]. Free it with
|
|
|
|
|
* [method@GIRepository.BaseInfo.unref] when done.
|
|
|
|
|
* Since: 2.80
|
2010-06-05 17:11:58 +02:00
|
|
|
|
*/
|
|
|
|
|
GIArgInfo *
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_callable_info_get_arg (GICallableInfo *info,
|
2024-01-15 22:20:02 +01:00
|
|
|
|
unsigned int n)
|
2010-06-05 17:11:58 +02:00
|
|
|
|
{
|
|
|
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
|
|
|
Header *header;
|
2024-01-15 22:20:02 +01:00
|
|
|
|
uint32_t offset;
|
2010-06-05 17:11:58 +02:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail (GI_IS_CALLABLE_INFO (info), NULL);
|
2024-01-16 01:40:09 +01:00
|
|
|
|
g_return_val_if_fail (n <= G_MAXUINT16, NULL);
|
2010-06-05 17:11:58 +02:00
|
|
|
|
|
|
|
|
|
offset = signature_offset (info);
|
|
|
|
|
header = (Header *)rinfo->typelib->data;
|
|
|
|
|
|
2024-02-08 11:34:40 +01:00
|
|
|
|
return (GIArgInfo *) gi_base_info_new (GI_INFO_TYPE_ARG, (GIBaseInfo*)info, rinfo->typelib,
|
|
|
|
|
offset + header->signature_blob_size + n * header->arg_blob_size);
|
2010-06-05 17:11:58 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_callable_info_load_arg:
|
2010-06-05 17:11:58 +02:00
|
|
|
|
* @info: a #GICallableInfo
|
|
|
|
|
* @n: the argument index to fetch
|
|
|
|
|
* @arg: (out caller-allocates): Initialize with argument number @n
|
|
|
|
|
*
|
|
|
|
|
* Obtain information about a particular argument of this callable; this
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* function is a variant of [method@GIRepository.CallableInfo.get_arg] designed
|
|
|
|
|
* for stack allocation.
|
2010-06-05 17:11:58 +02:00
|
|
|
|
*
|
|
|
|
|
* The initialized @arg must not be referenced after @info is deallocated.
|
2023-12-13 01:26:23 +01:00
|
|
|
|
*
|
2024-01-23 19:07:17 +01:00
|
|
|
|
* Once you are done with @arg, it must be cleared using
|
|
|
|
|
* [method@GIRepository.BaseInfo.clear].
|
|
|
|
|
*
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* Since: 2.80
|
2010-06-05 17:11:58 +02:00
|
|
|
|
*/
|
|
|
|
|
void
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_callable_info_load_arg (GICallableInfo *info,
|
2024-01-15 22:20:02 +01:00
|
|
|
|
unsigned int n,
|
2023-11-08 15:17:52 +01:00
|
|
|
|
GIArgInfo *arg)
|
2010-06-05 17:11:58 +02:00
|
|
|
|
{
|
|
|
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
|
|
|
Header *header;
|
2024-01-15 22:20:02 +01:00
|
|
|
|
uint32_t offset;
|
2010-06-05 17:11:58 +02:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (info != NULL);
|
|
|
|
|
g_return_if_fail (GI_IS_CALLABLE_INFO (info));
|
2024-01-16 01:40:09 +01:00
|
|
|
|
g_return_if_fail (n <= G_MAXUINT16);
|
2010-06-05 17:11:58 +02:00
|
|
|
|
|
|
|
|
|
offset = signature_offset (info);
|
|
|
|
|
header = (Header *)rinfo->typelib->data;
|
|
|
|
|
|
2024-01-23 19:06:08 +01:00
|
|
|
|
gi_info_init ((GIRealInfo*)arg, GI_TYPE_ARG_INFO, rinfo->repository, (GIBaseInfo*)info, rinfo->typelib,
|
2023-11-08 16:23:31 +01:00
|
|
|
|
offset + header->signature_blob_size + n * header->arg_blob_size);
|
2010-06-05 17:11:58 +02:00
|
|
|
|
}
|
2010-06-15 17:01:37 +02:00
|
|
|
|
|
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_callable_info_get_return_attribute:
|
2010-06-15 17:01:37 +02:00
|
|
|
|
* @info: a #GICallableInfo
|
|
|
|
|
* @name: a freeform string naming an attribute
|
|
|
|
|
*
|
|
|
|
|
* Retrieve an arbitrary attribute associated with the return value.
|
|
|
|
|
*
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* Returns: (nullable): The value of the attribute, or `NULL` if no such
|
|
|
|
|
* attribute exists
|
|
|
|
|
* Since: 2.80
|
2010-06-15 17:01:37 +02:00
|
|
|
|
*/
|
2024-01-15 20:20:47 +01:00
|
|
|
|
const char *
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_callable_info_get_return_attribute (GICallableInfo *info,
|
2024-01-15 20:20:47 +01:00
|
|
|
|
const char *name)
|
2010-06-15 17:01:37 +02:00
|
|
|
|
{
|
2024-01-18 13:27:46 +01:00
|
|
|
|
GIAttributeIter iter = GI_ATTRIBUTE_ITER_INIT;
|
2023-12-12 18:34:48 +01:00
|
|
|
|
const char *curname, *curvalue;
|
2023-11-08 15:17:52 +01:00
|
|
|
|
while (gi_callable_info_iterate_return_attributes (info, &iter, &curname, &curvalue))
|
2010-06-15 17:01:37 +02:00
|
|
|
|
{
|
|
|
|
|
if (g_strcmp0 (name, curname) == 0)
|
2024-01-15 20:20:47 +01:00
|
|
|
|
return (const char*) curvalue;
|
2010-06-15 17:01:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_callable_info_iterate_return_attributes:
|
2010-06-15 17:01:37 +02:00
|
|
|
|
* @info: a #GICallableInfo
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* @iterator: (inout): a [type@GIRepository.AttributeIter] structure, must be
|
|
|
|
|
* initialized; see below
|
2010-06-15 17:01:37 +02:00
|
|
|
|
* @name: (out) (transfer none): Returned name, must not be freed
|
|
|
|
|
* @value: (out) (transfer none): Returned name, must not be freed
|
|
|
|
|
*
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* Iterate over all attributes associated with the return value.
|
|
|
|
|
*
|
|
|
|
|
* The iterator structure is typically stack allocated, and must have its
|
|
|
|
|
* first member initialized to `NULL`.
|
2010-06-15 17:01:37 +02:00
|
|
|
|
*
|
|
|
|
|
* Both the @name and @value should be treated as constants
|
|
|
|
|
* and must not be freed.
|
|
|
|
|
*
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* See [method@GIRepository.BaseInfo.iterate_attributes] for an example of how
|
|
|
|
|
* to use a similar API.
|
2010-06-15 17:01:37 +02:00
|
|
|
|
*
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* Returns: `TRUE` if there are more attributes
|
|
|
|
|
* Since: 2.80
|
2010-06-15 17:01:37 +02:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_callable_info_iterate_return_attributes (GICallableInfo *info,
|
|
|
|
|
GIAttributeIter *iterator,
|
2023-12-12 18:34:48 +01:00
|
|
|
|
const char **name,
|
|
|
|
|
const char **value)
|
2010-06-15 17:01:37 +02:00
|
|
|
|
{
|
|
|
|
|
GIRealInfo *rinfo = (GIRealInfo *)info;
|
|
|
|
|
Header *header = (Header *)rinfo->typelib->data;
|
|
|
|
|
AttributeBlob *next, *after;
|
2024-01-15 22:20:02 +01:00
|
|
|
|
uint32_t blob_offset;
|
2010-06-15 17:01:37 +02:00
|
|
|
|
|
|
|
|
|
after = (AttributeBlob *) &rinfo->typelib->data[header->attributes +
|
|
|
|
|
header->n_attributes * header->attribute_blob_size];
|
|
|
|
|
|
|
|
|
|
blob_offset = signature_offset (info);
|
|
|
|
|
|
|
|
|
|
if (iterator->data != NULL)
|
|
|
|
|
next = (AttributeBlob *) iterator->data;
|
|
|
|
|
else
|
2023-11-28 18:14:30 +01:00
|
|
|
|
next = _attribute_blob_find_first ((GIBaseInfo *) info, blob_offset);
|
2010-06-15 17:01:37 +02:00
|
|
|
|
|
|
|
|
|
if (next == NULL || next->offset != blob_offset || next >= after)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2023-12-12 18:34:48 +01:00
|
|
|
|
*name = gi_typelib_get_string (rinfo->typelib, next->name);
|
|
|
|
|
*value = gi_typelib_get_string (rinfo->typelib, next->value);
|
2010-06-15 17:01:37 +02:00
|
|
|
|
iterator->data = next + 1;
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2010-12-13 13:53:55 +01:00
|
|
|
|
|
2013-10-10 22:21:18 +02:00
|
|
|
|
/**
|
2022-02-04 08:54:09 +01:00
|
|
|
|
* gi_type_tag_extract_ffi_return_value:
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* @return_tag: [type@GIRepository.TypeTag] of the return value
|
2024-02-08 13:35:23 +01:00
|
|
|
|
* @interface_type: [type@GObject.Type] of the underlying interface type
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* @ffi_value: pointer to [type@GIRepository.FFIReturnValue] union containing
|
|
|
|
|
* the return value from `ffi_call()`
|
|
|
|
|
* @arg: (out caller-allocates): pointer to an allocated
|
|
|
|
|
* [class@GIRepository.Argument]
|
2013-10-10 22:21:18 +02:00
|
|
|
|
*
|
2022-02-13 15:20:51 +01:00
|
|
|
|
* Extract the correct bits from an `ffi_arg` return value into
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* [class@GIRepository.Argument].
|
2012-02-16 17:25:55 +01:00
|
|
|
|
*
|
2022-02-13 15:20:51 +01:00
|
|
|
|
* See: https://bugzilla.gnome.org/show_bug.cgi?id=665152
|
|
|
|
|
*
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* Also see [`ffi_call()`](man:ffi_call(3)): the storage requirements for return
|
|
|
|
|
* values are ‘special’.
|
2022-02-04 08:54:09 +01:00
|
|
|
|
*
|
|
|
|
|
* The @interface_type argument only applies if @return_tag is
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* `GI_TYPE_TAG_INTERFACE`. Otherwise it is ignored.
|
2022-02-04 08:54:09 +01:00
|
|
|
|
*
|
2023-11-09 00:24:11 +01:00
|
|
|
|
* Since: 2.80
|
2012-02-16 17:25:55 +01:00
|
|
|
|
*/
|
2012-02-16 22:58:59 +01:00
|
|
|
|
void
|
2022-02-04 08:54:09 +01:00
|
|
|
|
gi_type_tag_extract_ffi_return_value (GITypeTag return_tag,
|
2024-02-08 13:35:23 +01:00
|
|
|
|
GType interface_type,
|
2022-02-04 08:54:09 +01:00
|
|
|
|
GIFFIReturnValue *ffi_value,
|
|
|
|
|
GIArgument *arg)
|
2012-02-16 17:25:55 +01:00
|
|
|
|
{
|
2022-02-04 08:54:09 +01:00
|
|
|
|
switch (return_tag) {
|
2012-02-16 17:25:55 +01:00
|
|
|
|
case GI_TYPE_TAG_INT8:
|
2024-01-15 22:20:02 +01:00
|
|
|
|
arg->v_int8 = (int8_t) ffi_value->v_long;
|
2012-02-16 17:25:55 +01:00
|
|
|
|
break;
|
|
|
|
|
case GI_TYPE_TAG_UINT8:
|
2024-01-15 22:20:02 +01:00
|
|
|
|
arg->v_uint8 = (uint8_t) ffi_value->v_ulong;
|
2012-02-16 17:25:55 +01:00
|
|
|
|
break;
|
|
|
|
|
case GI_TYPE_TAG_INT16:
|
2024-01-15 22:20:02 +01:00
|
|
|
|
arg->v_int16 = (int16_t) ffi_value->v_long;
|
2012-02-16 17:25:55 +01:00
|
|
|
|
break;
|
|
|
|
|
case GI_TYPE_TAG_UINT16:
|
2024-01-15 22:20:02 +01:00
|
|
|
|
arg->v_uint16 = (uint16_t) ffi_value->v_ulong;
|
2012-02-16 17:25:55 +01:00
|
|
|
|
break;
|
|
|
|
|
case GI_TYPE_TAG_INT32:
|
2024-01-15 22:20:02 +01:00
|
|
|
|
arg->v_int32 = (int32_t) ffi_value->v_long;
|
2012-02-16 17:25:55 +01:00
|
|
|
|
break;
|
|
|
|
|
case GI_TYPE_TAG_UINT32:
|
|
|
|
|
case GI_TYPE_TAG_BOOLEAN:
|
|
|
|
|
case GI_TYPE_TAG_UNICHAR:
|
2024-01-15 22:20:02 +01:00
|
|
|
|
arg->v_uint32 = (uint32_t) ffi_value->v_ulong;
|
2012-02-16 17:25:55 +01:00
|
|
|
|
break;
|
|
|
|
|
case GI_TYPE_TAG_INT64:
|
2024-01-15 22:20:02 +01:00
|
|
|
|
arg->v_int64 = (int64_t) ffi_value->v_int64;
|
2012-02-16 17:25:55 +01:00
|
|
|
|
break;
|
|
|
|
|
case GI_TYPE_TAG_UINT64:
|
2024-01-15 22:20:02 +01:00
|
|
|
|
arg->v_uint64 = (uint64_t) ffi_value->v_uint64;
|
2012-02-16 17:25:55 +01:00
|
|
|
|
break;
|
|
|
|
|
case GI_TYPE_TAG_FLOAT:
|
|
|
|
|
arg->v_float = ffi_value->v_float;
|
|
|
|
|
break;
|
|
|
|
|
case GI_TYPE_TAG_DOUBLE:
|
|
|
|
|
arg->v_double = ffi_value->v_double;
|
|
|
|
|
break;
|
|
|
|
|
case GI_TYPE_TAG_INTERFACE:
|
2024-02-08 13:35:23 +01:00
|
|
|
|
if (interface_type == GI_TYPE_ENUM_INFO ||
|
|
|
|
|
interface_type == GI_TYPE_FLAGS_INFO)
|
|
|
|
|
arg->v_int32 = (int32_t) ffi_value->v_long;
|
|
|
|
|
else
|
|
|
|
|
arg->v_pointer = (void *) ffi_value->v_pointer;
|
2012-02-16 17:25:55 +01:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2024-01-15 20:16:00 +01:00
|
|
|
|
arg->v_pointer = (void *) ffi_value->v_pointer;
|
2012-02-16 17:25:55 +01:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-04 08:54:09 +01:00
|
|
|
|
/**
|
|
|
|
|
* gi_type_info_extract_ffi_return_value:
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* @return_info: [type@GIRepository.TypeInfo] describing the return type
|
|
|
|
|
* @ffi_value: pointer to [type@GIRepository.FFIReturnValue] union containing
|
|
|
|
|
* the return value from `ffi_call()`
|
|
|
|
|
* @arg: (out caller-allocates): pointer to an allocated
|
|
|
|
|
* [class@GIRepository.Argument]
|
2022-02-04 08:54:09 +01:00
|
|
|
|
*
|
2022-02-13 15:20:51 +01:00
|
|
|
|
* Extract the correct bits from an `ffi_arg` return value into
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* [class@GIRepository.Argument].
|
2022-02-13 15:20:51 +01:00
|
|
|
|
*
|
|
|
|
|
* See: https://bugzilla.gnome.org/show_bug.cgi?id=665152
|
2022-02-04 08:54:09 +01:00
|
|
|
|
*
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* Also see [`ffi_call()`](man:ffi_call(3)): the storage requirements for return
|
|
|
|
|
* values are ‘special’.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.80
|
2022-02-04 08:54:09 +01:00
|
|
|
|
*/
|
|
|
|
|
void
|
2023-12-13 01:26:23 +01:00
|
|
|
|
gi_type_info_extract_ffi_return_value (GITypeInfo *return_info,
|
|
|
|
|
GIFFIReturnValue *ffi_value,
|
|
|
|
|
GIArgument *arg)
|
2022-02-04 08:54:09 +01:00
|
|
|
|
{
|
2023-11-08 15:17:52 +01:00
|
|
|
|
GITypeTag return_tag = gi_type_info_get_tag (return_info);
|
2024-02-08 13:35:23 +01:00
|
|
|
|
GType interface_type = G_TYPE_INVALID;
|
2022-02-04 08:54:09 +01:00
|
|
|
|
|
|
|
|
|
if (return_tag == GI_TYPE_TAG_INTERFACE)
|
|
|
|
|
{
|
2023-11-08 15:17:52 +01:00
|
|
|
|
GIBaseInfo *interface_info = gi_type_info_get_interface (return_info);
|
2024-02-08 13:35:23 +01:00
|
|
|
|
interface_type = G_TYPE_FROM_INSTANCE (interface_info);
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_base_info_unref (interface_info);
|
2022-02-04 08:54:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-10 11:11:05 +01:00
|
|
|
|
gi_type_tag_extract_ffi_return_value (return_tag, interface_type,
|
|
|
|
|
ffi_value, arg);
|
2022-02-04 08:54:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-10 22:21:18 +02:00
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_callable_info_invoke:
|
2023-12-13 01:26:23 +01:00
|
|
|
|
* @info: a #GICallableInfo
|
|
|
|
|
* @function: function pointer to call
|
|
|
|
|
* @in_args: (array length=n_in_args): array of ‘in’ arguments
|
|
|
|
|
* @n_in_args: number of arguments in @in_args
|
|
|
|
|
* @out_args: (array length=n_out_args): array of ‘out’ arguments allocated by
|
|
|
|
|
* the caller, to be populated with outputted values
|
|
|
|
|
* @n_out_args: number of arguments in @out_args
|
|
|
|
|
* @return_value: (out caller-allocates) (not optional) (nullable): return
|
|
|
|
|
* location for the return value from the callable; `NULL` may be returned if
|
|
|
|
|
* the callable returns that
|
|
|
|
|
* @error: return location for a [type@GLib.Error], or `NULL`
|
|
|
|
|
*
|
|
|
|
|
* Invoke the given `GICallableInfo` by calling the given @function pointer.
|
|
|
|
|
*
|
|
|
|
|
* The set of arguments passed to @function will be constructed according to the
|
2024-01-05 14:49:44 +01:00
|
|
|
|
* introspected type of the `GICallableInfo`, using @in_args, @out_args
|
|
|
|
|
* and @error.
|
2023-12-13 01:26:23 +01:00
|
|
|
|
*
|
|
|
|
|
* Returns: `TRUE` if the callable was executed successfully and didn’t throw
|
|
|
|
|
* a [type@GLib.Error]; `FALSE` if @error is set
|
|
|
|
|
* Since: 2.80
|
2013-10-10 22:21:18 +02:00
|
|
|
|
*/
|
2010-12-13 13:53:55 +01:00
|
|
|
|
gboolean
|
2023-11-28 18:20:42 +01:00
|
|
|
|
gi_callable_info_invoke (GICallableInfo *info,
|
2024-01-15 20:16:00 +01:00
|
|
|
|
void *function,
|
2023-11-08 15:17:52 +01:00
|
|
|
|
const GIArgument *in_args,
|
2024-01-16 00:35:23 +01:00
|
|
|
|
size_t n_in_args,
|
2024-01-05 14:57:35 +01:00
|
|
|
|
GIArgument *out_args,
|
2024-01-16 00:35:23 +01:00
|
|
|
|
size_t n_out_args,
|
2023-11-08 15:17:52 +01:00
|
|
|
|
GIArgument *return_value,
|
|
|
|
|
GError **error)
|
2010-12-13 13:53:55 +01:00
|
|
|
|
{
|
|
|
|
|
ffi_cif cif;
|
|
|
|
|
ffi_type *rtype;
|
|
|
|
|
ffi_type **atypes;
|
|
|
|
|
GITypeInfo *tinfo;
|
2012-02-16 17:25:55 +01:00
|
|
|
|
GITypeInfo *rinfo;
|
|
|
|
|
GITypeTag rtag;
|
2010-12-13 13:53:55 +01:00
|
|
|
|
GIArgInfo *ainfo;
|
2024-04-25 01:41:34 +02:00
|
|
|
|
unsigned int n_args, n_invoke_args, in_pos, out_pos, i;
|
2024-01-15 20:16:00 +01:00
|
|
|
|
void **args;
|
2010-12-13 13:53:55 +01:00
|
|
|
|
gboolean success = FALSE;
|
|
|
|
|
GError *local_error = NULL;
|
2024-01-15 20:16:00 +01:00
|
|
|
|
void *error_address = &local_error;
|
2012-02-16 17:25:55 +01:00
|
|
|
|
GIFFIReturnValue ffi_return_value;
|
2024-01-15 20:16:00 +01:00
|
|
|
|
void *return_value_p; /* Will point inside the union return_value */
|
2024-01-05 14:49:44 +01:00
|
|
|
|
gboolean is_method, throws;
|
2010-12-13 13:53:55 +01:00
|
|
|
|
|
2023-11-08 15:17:52 +01:00
|
|
|
|
rinfo = gi_callable_info_get_return_type ((GICallableInfo *)info);
|
|
|
|
|
rtype = gi_type_info_get_ffi_type (rinfo);
|
|
|
|
|
rtag = gi_type_info_get_tag(rinfo);
|
2024-01-05 14:49:44 +01:00
|
|
|
|
is_method = gi_callable_info_is_method (info);
|
|
|
|
|
throws = gi_callable_info_can_throw_gerror (info);
|
2010-12-13 13:53:55 +01:00
|
|
|
|
|
|
|
|
|
in_pos = 0;
|
|
|
|
|
out_pos = 0;
|
|
|
|
|
|
2023-11-08 15:17:52 +01:00
|
|
|
|
n_args = gi_callable_info_get_n_args ((GICallableInfo *)info);
|
2010-12-13 13:53:55 +01:00
|
|
|
|
if (is_method)
|
|
|
|
|
{
|
|
|
|
|
if (n_in_args == 0)
|
|
|
|
|
{
|
|
|
|
|
g_set_error (error,
|
2023-11-08 15:17:52 +01:00
|
|
|
|
GI_INVOKE_ERROR,
|
|
|
|
|
GI_INVOKE_ERROR_ARGUMENT_MISMATCH,
|
2010-12-13 13:53:55 +01:00
|
|
|
|
"Too few \"in\" arguments (handling this)");
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
n_invoke_args = n_args+1;
|
|
|
|
|
in_pos++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
n_invoke_args = n_args;
|
|
|
|
|
|
|
|
|
|
if (throws)
|
|
|
|
|
/* Add an argument for the GError */
|
|
|
|
|
n_invoke_args ++;
|
|
|
|
|
|
|
|
|
|
atypes = g_alloca (sizeof (ffi_type*) * n_invoke_args);
|
2024-01-15 20:16:00 +01:00
|
|
|
|
args = g_alloca (sizeof (void *) * n_invoke_args);
|
2010-12-13 13:53:55 +01:00
|
|
|
|
|
|
|
|
|
if (is_method)
|
|
|
|
|
{
|
|
|
|
|
atypes[0] = &ffi_type_pointer;
|
2024-01-15 20:16:00 +01:00
|
|
|
|
args[0] = (void *) &in_args[0];
|
2010-12-13 13:53:55 +01:00
|
|
|
|
}
|
|
|
|
|
for (i = 0; i < n_args; i++)
|
|
|
|
|
{
|
|
|
|
|
int offset = (is_method ? 1 : 0);
|
2023-11-08 15:17:52 +01:00
|
|
|
|
ainfo = gi_callable_info_get_arg ((GICallableInfo *)info, i);
|
|
|
|
|
switch (gi_arg_info_get_direction (ainfo))
|
2010-12-13 13:53:55 +01:00
|
|
|
|
{
|
|
|
|
|
case GI_DIRECTION_IN:
|
2023-11-28 18:09:26 +01:00
|
|
|
|
tinfo = gi_arg_info_get_type_info (ainfo);
|
2023-11-08 15:17:52 +01:00
|
|
|
|
atypes[i+offset] = gi_type_info_get_ffi_type (tinfo);
|
|
|
|
|
gi_base_info_unref ((GIBaseInfo *)ainfo);
|
|
|
|
|
gi_base_info_unref ((GIBaseInfo *)tinfo);
|
2010-12-13 13:53:55 +01:00
|
|
|
|
|
|
|
|
|
if (in_pos >= n_in_args)
|
|
|
|
|
{
|
|
|
|
|
g_set_error (error,
|
2023-11-08 15:17:52 +01:00
|
|
|
|
GI_INVOKE_ERROR,
|
|
|
|
|
GI_INVOKE_ERROR_ARGUMENT_MISMATCH,
|
2010-12-13 13:53:55 +01:00
|
|
|
|
"Too few \"in\" arguments (handling in)");
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-15 20:16:00 +01:00
|
|
|
|
args[i+offset] = (void *)&in_args[in_pos];
|
2010-12-13 13:53:55 +01:00
|
|
|
|
in_pos++;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case GI_DIRECTION_OUT:
|
|
|
|
|
atypes[i+offset] = &ffi_type_pointer;
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_base_info_unref ((GIBaseInfo *)ainfo);
|
2010-12-13 13:53:55 +01:00
|
|
|
|
|
|
|
|
|
if (out_pos >= n_out_args)
|
|
|
|
|
{
|
|
|
|
|
g_set_error (error,
|
2023-11-08 15:17:52 +01:00
|
|
|
|
GI_INVOKE_ERROR,
|
|
|
|
|
GI_INVOKE_ERROR_ARGUMENT_MISMATCH,
|
2010-12-13 13:53:55 +01:00
|
|
|
|
"Too few \"out\" arguments (handling out)");
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-15 20:16:00 +01:00
|
|
|
|
args[i+offset] = (void *)&out_args[out_pos];
|
2010-12-13 13:53:55 +01:00
|
|
|
|
out_pos++;
|
|
|
|
|
break;
|
|
|
|
|
case GI_DIRECTION_INOUT:
|
|
|
|
|
atypes[i+offset] = &ffi_type_pointer;
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_base_info_unref ((GIBaseInfo *)ainfo);
|
2010-12-13 13:53:55 +01:00
|
|
|
|
|
|
|
|
|
if (in_pos >= n_in_args)
|
|
|
|
|
{
|
|
|
|
|
g_set_error (error,
|
2023-11-08 15:17:52 +01:00
|
|
|
|
GI_INVOKE_ERROR,
|
|
|
|
|
GI_INVOKE_ERROR_ARGUMENT_MISMATCH,
|
2010-12-13 13:53:55 +01:00
|
|
|
|
"Too few \"in\" arguments (handling inout)");
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (out_pos >= n_out_args)
|
|
|
|
|
{
|
|
|
|
|
g_set_error (error,
|
2023-11-08 15:17:52 +01:00
|
|
|
|
GI_INVOKE_ERROR,
|
|
|
|
|
GI_INVOKE_ERROR_ARGUMENT_MISMATCH,
|
2010-12-13 13:53:55 +01:00
|
|
|
|
"Too few \"out\" arguments (handling inout)");
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-15 20:16:00 +01:00
|
|
|
|
args[i+offset] = (void *)&in_args[in_pos];
|
2010-12-13 13:53:55 +01:00
|
|
|
|
in_pos++;
|
|
|
|
|
out_pos++;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_base_info_unref ((GIBaseInfo *)ainfo);
|
2010-12-13 13:53:55 +01:00
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (throws)
|
|
|
|
|
{
|
|
|
|
|
args[n_invoke_args - 1] = &error_address;
|
|
|
|
|
atypes[n_invoke_args - 1] = &ffi_type_pointer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (in_pos < n_in_args)
|
|
|
|
|
{
|
|
|
|
|
g_set_error (error,
|
2023-11-08 15:17:52 +01:00
|
|
|
|
GI_INVOKE_ERROR,
|
|
|
|
|
GI_INVOKE_ERROR_ARGUMENT_MISMATCH,
|
2010-12-13 13:53:55 +01:00
|
|
|
|
"Too many \"in\" arguments (at end)");
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
if (out_pos < n_out_args)
|
|
|
|
|
{
|
|
|
|
|
g_set_error (error,
|
2023-11-08 15:17:52 +01:00
|
|
|
|
GI_INVOKE_ERROR,
|
|
|
|
|
GI_INVOKE_ERROR_ARGUMENT_MISMATCH,
|
2010-12-13 13:53:55 +01:00
|
|
|
|
"Too many \"out\" arguments (at end)");
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ffi_prep_cif (&cif, FFI_DEFAULT_ABI, n_invoke_args, rtype, atypes) != FFI_OK)
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (return_value, FALSE);
|
2012-02-16 17:25:55 +01:00
|
|
|
|
/* See comment for GIFFIReturnValue above */
|
|
|
|
|
switch (rtag)
|
|
|
|
|
{
|
|
|
|
|
case GI_TYPE_TAG_FLOAT:
|
|
|
|
|
return_value_p = &ffi_return_value.v_float;
|
|
|
|
|
break;
|
|
|
|
|
case GI_TYPE_TAG_DOUBLE:
|
|
|
|
|
return_value_p = &ffi_return_value.v_double;
|
|
|
|
|
break;
|
|
|
|
|
case GI_TYPE_TAG_INT64:
|
|
|
|
|
case GI_TYPE_TAG_UINT64:
|
|
|
|
|
return_value_p = &ffi_return_value.v_uint64;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return_value_p = &ffi_return_value.v_long;
|
|
|
|
|
}
|
|
|
|
|
ffi_call (&cif, function, return_value_p, args);
|
2010-12-13 13:53:55 +01:00
|
|
|
|
|
|
|
|
|
if (local_error)
|
|
|
|
|
{
|
|
|
|
|
g_propagate_error (error, local_error);
|
|
|
|
|
success = FALSE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-02-16 22:58:59 +01:00
|
|
|
|
gi_type_info_extract_ffi_return_value (rinfo, &ffi_return_value, return_value);
|
2010-12-13 13:53:55 +01:00
|
|
|
|
success = TRUE;
|
|
|
|
|
}
|
|
|
|
|
out:
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_base_info_unref ((GIBaseInfo *)rinfo);
|
2010-12-13 13:53:55 +01:00
|
|
|
|
return success;
|
|
|
|
|
}
|
2023-11-28 18:24:20 +01:00
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gi_callable_info_class_init (gpointer g_class,
|
|
|
|
|
gpointer class_data)
|
|
|
|
|
{
|
|
|
|
|
GIBaseInfoClass *info_class = g_class;
|
|
|
|
|
|
|
|
|
|
info_class->info_type = GI_INFO_TYPE_CALLABLE;
|
|
|
|
|
}
|
2024-05-07 15:46:13 +02:00
|
|
|
|
|
|
|
|
|
static GICallableInfo *
|
2024-07-24 18:35:34 +02:00
|
|
|
|
get_method_callable_info_for_index (GIBaseInfo *rinfo,
|
|
|
|
|
unsigned int index)
|
2024-05-07 15:46:13 +02:00
|
|
|
|
{
|
|
|
|
|
GIBaseInfo *container = rinfo->container;
|
|
|
|
|
|
|
|
|
|
g_assert (container);
|
|
|
|
|
|
|
|
|
|
if (GI_IS_OBJECT_INFO (container))
|
|
|
|
|
return (GICallableInfo *) gi_object_info_get_method ((GIObjectInfo *) container, index);
|
|
|
|
|
|
|
|
|
|
if (GI_IS_INTERFACE_INFO (container))
|
|
|
|
|
return (GICallableInfo *) gi_interface_info_get_method ((GIInterfaceInfo *) container,
|
|
|
|
|
index);
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GICallableInfo *
|
|
|
|
|
get_callable_info_for_index (GIBaseInfo *rinfo,
|
|
|
|
|
unsigned int index)
|
|
|
|
|
{
|
|
|
|
|
if (!rinfo->container)
|
|
|
|
|
{
|
|
|
|
|
GIBaseInfo *info = gi_info_from_entry (rinfo->repository, rinfo->typelib, index);
|
|
|
|
|
|
|
|
|
|
g_assert (GI_IS_CALLABLE_INFO (info));
|
|
|
|
|
|
|
|
|
|
return (GICallableInfo *) info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return get_method_callable_info_for_index (rinfo, index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gi_callable_info_get_async_function
|
|
|
|
|
* @info: a callable info structure
|
|
|
|
|
*
|
|
|
|
|
* Gets the callable info for the callable's asynchronous version
|
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer full) (nullable): a [class@GIRepository.CallableInfo] for the
|
|
|
|
|
* async function or `NULL` if not defined.
|
|
|
|
|
* Since: 2.80
|
|
|
|
|
*/
|
|
|
|
|
GICallableInfo *
|
|
|
|
|
gi_callable_info_get_async_function (GICallableInfo *info)
|
|
|
|
|
{
|
|
|
|
|
GIBaseInfo *rinfo = (GIBaseInfo *) info;
|
|
|
|
|
|
|
|
|
|
switch (gi_base_info_get_info_type (rinfo))
|
|
|
|
|
{
|
|
|
|
|
case GI_INFO_TYPE_FUNCTION:
|
|
|
|
|
{
|
|
|
|
|
FunctionBlob *blob = GET_BLOB (FunctionBlob, rinfo);
|
|
|
|
|
if (blob->is_async || blob->sync_or_async == ASYNC_SENTINEL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
return get_callable_info_for_index (rinfo, blob->sync_or_async);
|
|
|
|
|
}
|
|
|
|
|
case GI_INFO_TYPE_VFUNC:
|
|
|
|
|
{
|
|
|
|
|
VFuncBlob *blob = GET_BLOB (VFuncBlob, rinfo);
|
|
|
|
|
if (blob->is_async || blob->sync_or_async == ASYNC_SENTINEL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
return get_method_callable_info_for_index (rinfo, blob->sync_or_async);
|
|
|
|
|
}
|
|
|
|
|
case GI_INFO_TYPE_CALLBACK:
|
|
|
|
|
case GI_INFO_TYPE_SIGNAL:
|
|
|
|
|
return NULL;
|
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gi_callable_info_get_sync_function
|
|
|
|
|
* @info: a callable info structure
|
|
|
|
|
*
|
|
|
|
|
* Gets the callable info for the callable's synchronous version
|
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer full) (nullable): a [class@GIRepository.CallableInfo] for the
|
|
|
|
|
* sync function or `NULL` if not defined.
|
|
|
|
|
* Since: 2.80
|
|
|
|
|
*/
|
|
|
|
|
GICallableInfo *
|
|
|
|
|
gi_callable_info_get_sync_function (GICallableInfo *info)
|
|
|
|
|
{
|
|
|
|
|
GIBaseInfo *rinfo = (GIBaseInfo *) info;
|
|
|
|
|
|
|
|
|
|
switch (gi_base_info_get_info_type (rinfo))
|
|
|
|
|
{
|
|
|
|
|
case GI_INFO_TYPE_FUNCTION:
|
|
|
|
|
{
|
|
|
|
|
FunctionBlob *blob = GET_BLOB (FunctionBlob, rinfo);
|
|
|
|
|
if (!blob->is_async || blob->sync_or_async == ASYNC_SENTINEL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
return get_callable_info_for_index (rinfo, blob->sync_or_async);
|
|
|
|
|
}
|
|
|
|
|
case GI_INFO_TYPE_VFUNC:
|
|
|
|
|
{
|
|
|
|
|
VFuncBlob *blob = GET_BLOB (VFuncBlob, rinfo);
|
|
|
|
|
if (!blob->is_async || blob->sync_or_async == ASYNC_SENTINEL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
return get_method_callable_info_for_index (rinfo, blob->sync_or_async);
|
|
|
|
|
}
|
|
|
|
|
case GI_INFO_TYPE_CALLBACK:
|
|
|
|
|
case GI_INFO_TYPE_SIGNAL:
|
|
|
|
|
return NULL;
|
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gi_callable_info_get_finish_function
|
|
|
|
|
* @info: a callable info structure
|
|
|
|
|
*
|
|
|
|
|
* Gets the info for an async function's corresponding finish function
|
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer full) (nullable): a [class@GIRepository.CallableInfo] for the
|
|
|
|
|
* finish function or `NULL` if not defined.
|
|
|
|
|
* Since: 2.80
|
|
|
|
|
*/
|
|
|
|
|
GICallableInfo *
|
|
|
|
|
gi_callable_info_get_finish_function (GICallableInfo *info)
|
|
|
|
|
{
|
|
|
|
|
GIBaseInfo *rinfo = (GIBaseInfo *) info;
|
|
|
|
|
|
|
|
|
|
switch (gi_base_info_get_info_type (rinfo))
|
|
|
|
|
{
|
|
|
|
|
case GI_INFO_TYPE_FUNCTION:
|
|
|
|
|
{
|
|
|
|
|
FunctionBlob *blob = GET_BLOB (FunctionBlob, rinfo);
|
|
|
|
|
if (!blob->is_async || blob->finish == ASYNC_SENTINEL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
return get_callable_info_for_index (rinfo, blob->finish);
|
|
|
|
|
}
|
|
|
|
|
case GI_INFO_TYPE_VFUNC:
|
|
|
|
|
{
|
|
|
|
|
VFuncBlob *blob = GET_BLOB (VFuncBlob, rinfo);
|
|
|
|
|
if (!blob->is_async || blob->finish == ASYNC_SENTINEL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
return get_method_callable_info_for_index (rinfo, blob->finish);
|
|
|
|
|
}
|
|
|
|
|
case GI_INFO_TYPE_CALLBACK:
|
|
|
|
|
case GI_INFO_TYPE_SIGNAL:
|
|
|
|
|
return NULL;
|
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gi_callable_info_is_async
|
|
|
|
|
* @info: a callable info structure
|
|
|
|
|
*
|
|
|
|
|
* Gets whether a callable is ‘async’. Async callables have a
|
|
|
|
|
* [type@Gio.AsyncReadyCallback] parameter and user data.
|
|
|
|
|
*
|
|
|
|
|
* Returns: true if the callable is async
|
|
|
|
|
* Since: 2.80
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gi_callable_info_is_async (GICallableInfo *callable_info)
|
|
|
|
|
{
|
|
|
|
|
GIBaseInfo *info = (GIBaseInfo *) callable_info;
|
|
|
|
|
switch (gi_base_info_get_info_type ((GIBaseInfo *) callable_info))
|
|
|
|
|
{
|
|
|
|
|
case GI_INFO_TYPE_FUNCTION:
|
|
|
|
|
{
|
|
|
|
|
return GET_BLOB (FunctionBlob, info)->is_async;
|
|
|
|
|
}
|
|
|
|
|
case GI_INFO_TYPE_VFUNC:
|
|
|
|
|
{
|
|
|
|
|
return GET_BLOB (VFuncBlob, info)->is_async;
|
|
|
|
|
}
|
|
|
|
|
case GI_INFO_TYPE_CALLBACK:
|
|
|
|
|
case GI_INFO_TYPE_SIGNAL:
|
|
|
|
|
return FALSE;
|
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|