mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-24 14:36:13 +01:00
Merge branch 'girepository-api-tweaks' into 'main'
girepository: Various small API cleanups See merge request GNOME/glib!3805
This commit is contained in:
commit
c804bd781c
@ -580,7 +580,6 @@ gi_base_info_get_name (GIBaseInfo *info)
|
||||
case GI_INFO_TYPE_OBJECT:
|
||||
case GI_INFO_TYPE_INTERFACE:
|
||||
case GI_INFO_TYPE_CONSTANT:
|
||||
case GI_INFO_TYPE_INVALID_0:
|
||||
case GI_INFO_TYPE_UNION:
|
||||
{
|
||||
CommonBlob *blob = (CommonBlob *)&rinfo->typelib->data[rinfo->offset];
|
||||
@ -705,7 +704,6 @@ gi_base_info_is_deprecated (GIBaseInfo *info)
|
||||
case GI_INFO_TYPE_OBJECT:
|
||||
case GI_INFO_TYPE_INTERFACE:
|
||||
case GI_INFO_TYPE_CONSTANT:
|
||||
case GI_INFO_TYPE_INVALID_0:
|
||||
{
|
||||
CommonBlob *blob = (CommonBlob *)&rinfo->typelib->data[rinfo->offset];
|
||||
|
||||
|
@ -615,15 +615,13 @@ gi_type_info_extract_ffi_return_value (GITypeInfo *return_info,
|
||||
* @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
|
||||
* @is_method: `TRUE` if @info is a method
|
||||
* @throws: `TRUE` if @info may throw a [type@GLib.Error]
|
||||
* @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
|
||||
* introspected type of the `GICallableInfo`, using @in_args, @out_args,
|
||||
* @is_method, @throws and @error.
|
||||
* introspected type of the `GICallableInfo`, using @in_args, @out_args
|
||||
* and @error.
|
||||
*
|
||||
* Returns: `TRUE` if the callable was executed successfully and didn’t throw
|
||||
* a [type@GLib.Error]; `FALSE` if @error is set
|
||||
@ -634,11 +632,9 @@ gi_callable_info_invoke (GICallableInfo *info,
|
||||
gpointer function,
|
||||
const GIArgument *in_args,
|
||||
gsize n_in_args,
|
||||
const GIArgument *out_args,
|
||||
GIArgument *out_args,
|
||||
gsize n_out_args,
|
||||
GIArgument *return_value,
|
||||
gboolean is_method,
|
||||
gboolean throws,
|
||||
GError **error)
|
||||
{
|
||||
ffi_cif cif;
|
||||
@ -655,10 +651,13 @@ gi_callable_info_invoke (GICallableInfo *info,
|
||||
gpointer error_address = &local_error;
|
||||
GIFFIReturnValue ffi_return_value;
|
||||
gpointer return_value_p; /* Will point inside the union return_value */
|
||||
gboolean is_method, throws;
|
||||
|
||||
rinfo = gi_callable_info_get_return_type ((GICallableInfo *)info);
|
||||
rtype = gi_type_info_get_ffi_type (rinfo);
|
||||
rtag = gi_type_info_get_tag(rinfo);
|
||||
is_method = gi_callable_info_is_method (info);
|
||||
throws = gi_callable_info_can_throw_gerror (info);
|
||||
|
||||
in_pos = 0;
|
||||
out_pos = 0;
|
||||
|
@ -96,11 +96,9 @@ gboolean gi_callable_info_invoke (GICallableInfo *info
|
||||
gpointer function,
|
||||
const GIArgument *in_args,
|
||||
gsize n_in_args,
|
||||
const GIArgument *out_args,
|
||||
GIArgument *out_args,
|
||||
gsize n_out_args,
|
||||
GIArgument *return_value,
|
||||
gboolean is_method,
|
||||
gboolean throws,
|
||||
GError **error);
|
||||
|
||||
GI_AVAILABLE_IN_ALL
|
||||
|
@ -334,7 +334,6 @@ gi_field_info_get_field (GIFieldInfo *field_info,
|
||||
case GI_INFO_TYPE_INTERFACE:
|
||||
case GI_INFO_TYPE_FUNCTION:
|
||||
case GI_INFO_TYPE_CONSTANT:
|
||||
case GI_INFO_TYPE_INVALID_0:
|
||||
case GI_INFO_TYPE_VALUE:
|
||||
case GI_INFO_TYPE_SIGNAL:
|
||||
case GI_INFO_TYPE_PROPERTY:
|
||||
@ -517,7 +516,6 @@ gi_field_info_set_field (GIFieldInfo *field_info,
|
||||
case GI_INFO_TYPE_INTERFACE:
|
||||
case GI_INFO_TYPE_FUNCTION:
|
||||
case GI_INFO_TYPE_CONSTANT:
|
||||
case GI_INFO_TYPE_INVALID_0:
|
||||
case GI_INFO_TYPE_VALUE:
|
||||
case GI_INFO_TYPE_SIGNAL:
|
||||
case GI_INFO_TYPE_PROPERTY:
|
||||
|
@ -267,15 +267,13 @@ gboolean
|
||||
gi_function_info_invoke (GIFunctionInfo *info,
|
||||
const GIArgument *in_args,
|
||||
gsize n_in_args,
|
||||
const GIArgument *out_args,
|
||||
GIArgument *out_args,
|
||||
gsize n_out_args,
|
||||
GIArgument *return_value,
|
||||
GError **error)
|
||||
{
|
||||
const gchar *symbol;
|
||||
gpointer func;
|
||||
gboolean is_method;
|
||||
gboolean throws;
|
||||
|
||||
symbol = gi_function_info_get_symbol (info);
|
||||
|
||||
@ -290,10 +288,6 @@ gi_function_info_invoke (GIFunctionInfo *info,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
is_method = (gi_function_info_get_flags (info) & GI_FUNCTION_IS_METHOD) != 0
|
||||
&& (gi_function_info_get_flags (info) & GI_FUNCTION_IS_CONSTRUCTOR) == 0;
|
||||
throws = gi_function_info_get_flags (info) & GI_FUNCTION_THROWS;
|
||||
|
||||
return gi_callable_info_invoke ((GICallableInfo*) info,
|
||||
func,
|
||||
in_args,
|
||||
@ -301,8 +295,6 @@ gi_function_info_invoke (GIFunctionInfo *info,
|
||||
out_args,
|
||||
n_out_args,
|
||||
return_value,
|
||||
is_method,
|
||||
throws,
|
||||
error);
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,7 @@ GI_AVAILABLE_IN_ALL
|
||||
gboolean gi_function_info_invoke (GIFunctionInfo *info,
|
||||
const GIArgument *in_args,
|
||||
gsize n_in_args,
|
||||
const GIArgument *out_args,
|
||||
GIArgument *out_args,
|
||||
gsize n_out_args,
|
||||
GIArgument *return_value,
|
||||
GError **error);
|
||||
|
@ -278,10 +278,10 @@ gi_cclosure_marshal_generic (GClosure *closure,
|
||||
GIArgument return_ffi_value = { 0, };
|
||||
ffi_type *rtype;
|
||||
void *rvalue;
|
||||
int n_args;
|
||||
unsigned int n_args;
|
||||
ffi_type **atypes;
|
||||
void **args;
|
||||
int i;
|
||||
unsigned int i;
|
||||
ffi_cif cif;
|
||||
GCClosure *cc = (GCClosure*) closure;
|
||||
|
||||
|
@ -92,6 +92,9 @@ struct _GIRepositoryPrivate
|
||||
GHashTable *info_by_error_domain; /* GQuark -> GIBaseInfo */
|
||||
GHashTable *interfaces_for_gtype; /* GType -> GTypeInterfaceCache */
|
||||
GHashTable *unknown_gtypes; /* hashset of GType */
|
||||
|
||||
char **cached_shared_libraries; /* (owned) (nullable) (array zero-terminated=1) */
|
||||
size_t cached_n_shared_libraries; /* length of @cached_shared_libraries, not including NULL terminator */
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (GIRepository, gi_repository, G_TYPE_OBJECT, G_ADD_PRIVATE (GIRepository));
|
||||
@ -170,6 +173,8 @@ gi_repository_finalize (GObject *object)
|
||||
g_hash_table_destroy (repository->priv->interfaces_for_gtype);
|
||||
g_hash_table_destroy (repository->priv->unknown_gtypes);
|
||||
|
||||
g_clear_pointer (&repository->priv->cached_shared_libraries, g_strfreev);
|
||||
|
||||
(* G_OBJECT_CLASS (gi_repository_parent_class)->finalize) (G_OBJECT (repository));
|
||||
}
|
||||
|
||||
@ -780,10 +785,10 @@ gi_repository_get_n_infos (GIRepository *repository,
|
||||
*
|
||||
* The namespace must have already been loaded before calling this function.
|
||||
* See [method@GIRepository.Repository.get_n_infos] to find the maximum number
|
||||
* of entries.
|
||||
* of entries. It is an error to pass an invalid @idx to this function.
|
||||
*
|
||||
* Returns: (transfer full) (nullable): [class@GIRepository.BaseInfo] containing
|
||||
* metadata, or `NULL` if @idx was too high
|
||||
* Returns: (transfer full) (not nullable): [class@GIRepository.BaseInfo]
|
||||
* containing metadata
|
||||
* Since: 2.80
|
||||
*/
|
||||
GIBaseInfo *
|
||||
@ -803,8 +808,8 @@ gi_repository_get_info (GIRepository *repository,
|
||||
g_return_val_if_fail (typelib != NULL, NULL);
|
||||
|
||||
entry = gi_typelib_get_dir_entry (typelib, idx + 1);
|
||||
if (entry == NULL)
|
||||
return NULL;
|
||||
g_return_val_if_fail (entry != NULL, NULL);
|
||||
|
||||
return gi_info_new_full (entry->blob_type,
|
||||
repository,
|
||||
NULL, typelib, entry->offset);
|
||||
@ -1201,12 +1206,14 @@ gi_repository_get_version (GIRepository *repository,
|
||||
}
|
||||
|
||||
/**
|
||||
* gi_repository_get_shared_library:
|
||||
* gi_repository_get_shared_libraries:
|
||||
* @repository: (nullable): A #GIRepository, or `NULL` for the singleton
|
||||
* process-global default #GIRepository
|
||||
* @namespace_: Namespace to inspect
|
||||
* @out_n_elements: (out) (optional): Return location for the number of elements
|
||||
* in the returned array
|
||||
*
|
||||
* This function returns a comma-separated list of paths to the
|
||||
* This function returns an array of paths to the
|
||||
* shared C libraries associated with the given namespace @namespace_.
|
||||
*
|
||||
* There may be no shared library path associated, in which case this
|
||||
@ -1216,13 +1223,17 @@ gi_repository_get_version (GIRepository *repository,
|
||||
* such as [method@GIRepository.Repository.require] before calling this
|
||||
* function.
|
||||
*
|
||||
* Returns: (nullable): Comma-separated list of paths to shared libraries,
|
||||
* or `NULL` if none are associated
|
||||
* The list is internal to [class@GIRepository.Repository] and should not be
|
||||
* freed, nor should its string elements.
|
||||
*
|
||||
* Returns: (nullable) (array length=out_n_elements) (transfer none): Array of
|
||||
* paths to shared libraries, or `NULL` if none are associated
|
||||
* Since: 2.80
|
||||
*/
|
||||
const gchar *
|
||||
gi_repository_get_shared_library (GIRepository *repository,
|
||||
const gchar *namespace)
|
||||
const char * const *
|
||||
gi_repository_get_shared_libraries (GIRepository *repository,
|
||||
const gchar *namespace,
|
||||
size_t *out_n_elements)
|
||||
{
|
||||
GITypelib *typelib;
|
||||
Header *header;
|
||||
@ -1236,10 +1247,29 @@ gi_repository_get_shared_library (GIRepository *repository,
|
||||
g_return_val_if_fail (typelib != NULL, NULL);
|
||||
|
||||
header = (Header *) typelib->data;
|
||||
if (header->shared_library)
|
||||
return gi_typelib_get_string (typelib, header->shared_library);
|
||||
else
|
||||
return NULL;
|
||||
if (!header->shared_library)
|
||||
{
|
||||
if (out_n_elements != NULL)
|
||||
*out_n_elements = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Populate the cache. */
|
||||
if (repository->priv->cached_shared_libraries == NULL)
|
||||
{
|
||||
const char *comma_separated = gi_typelib_get_string (typelib, header->shared_library);
|
||||
|
||||
if (comma_separated != NULL && *comma_separated != '\0')
|
||||
{
|
||||
repository->priv->cached_shared_libraries = g_strsplit (comma_separated, ",", -1);
|
||||
repository->priv->cached_n_shared_libraries = g_strv_length (repository->priv->cached_shared_libraries);
|
||||
}
|
||||
}
|
||||
|
||||
if (out_n_elements != NULL)
|
||||
*out_n_elements = repository->priv->cached_n_shared_libraries;
|
||||
|
||||
return (const char * const *) repository->priv->cached_shared_libraries;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -185,8 +185,9 @@ GI_AVAILABLE_IN_ALL
|
||||
const gchar * gi_repository_get_typelib_path (GIRepository *repository,
|
||||
const gchar *namespace_);
|
||||
GI_AVAILABLE_IN_ALL
|
||||
const gchar * gi_repository_get_shared_library (GIRepository *repository,
|
||||
const gchar *namespace_);
|
||||
const gchar * const *gi_repository_get_shared_libraries (GIRepository *repository,
|
||||
const gchar *namespace_,
|
||||
size_t *out_n_elements);
|
||||
GI_AVAILABLE_IN_ALL
|
||||
const gchar * gi_repository_get_c_prefix (GIRepository *repository,
|
||||
const gchar *namespace_);
|
||||
|
@ -171,11 +171,12 @@ gi_type_info_get_ffi_type (GITypeInfo *info)
|
||||
*/
|
||||
static ffi_type **
|
||||
gi_callable_info_get_ffi_arg_types (GICallableInfo *callable_info,
|
||||
int *n_args_p)
|
||||
size_t *n_args_p)
|
||||
{
|
||||
ffi_type **arg_types;
|
||||
gboolean is_method, throws;
|
||||
gint n_args, n_invoke_args, i, offset;
|
||||
size_t n_invoke_args;
|
||||
guint n_args, i, offset;
|
||||
|
||||
g_return_val_if_fail (callable_info != NULL, NULL);
|
||||
|
||||
@ -321,7 +322,7 @@ gi_function_invoker_new_for_address (gpointer addr,
|
||||
GError **error)
|
||||
{
|
||||
ffi_type **atypes;
|
||||
gint n_args;
|
||||
size_t n_args;
|
||||
|
||||
g_return_val_if_fail (info != NULL, FALSE);
|
||||
g_return_val_if_fail (invoker != NULL, FALSE);
|
||||
@ -379,7 +380,7 @@ gi_callable_info_create_closure (GICallableInfo *callable_info,
|
||||
gpointer user_data)
|
||||
{
|
||||
gpointer exec_ptr;
|
||||
int n_args;
|
||||
size_t n_args;
|
||||
ffi_type **atypes;
|
||||
GIClosureWrapper *closure;
|
||||
ffi_status status;
|
||||
|
@ -1390,7 +1390,7 @@ gi_ir_writer_write (const char *filename,
|
||||
|
||||
if (TRUE)
|
||||
{
|
||||
const gchar *shared_library;
|
||||
const char * const *shared_libraries;
|
||||
const gchar *c_prefix;
|
||||
const char *cur_ns = ns;
|
||||
const char *cur_version;
|
||||
@ -1398,12 +1398,16 @@ gi_ir_writer_write (const char *filename,
|
||||
|
||||
cur_version = gi_repository_get_version (repository, cur_ns);
|
||||
|
||||
shared_library = gi_repository_get_shared_library (repository, cur_ns);
|
||||
shared_libraries = gi_repository_get_shared_libraries (repository, cur_ns, NULL);
|
||||
c_prefix = gi_repository_get_c_prefix (repository, cur_ns);
|
||||
xml_start_element (xml, "namespace");
|
||||
xml_printf (xml, " name=\"%s\" version=\"%s\"", cur_ns, cur_version);
|
||||
if (shared_library)
|
||||
xml_printf (xml, " shared-library=\"%s\"", shared_library);
|
||||
if (shared_libraries != NULL)
|
||||
{
|
||||
char *shared_libraries_str = g_strjoinv (",", (char **) shared_libraries);
|
||||
xml_printf (xml, " shared-library=\"%s\"", shared_libraries_str);
|
||||
g_free (shared_libraries_str);
|
||||
}
|
||||
if (c_prefix)
|
||||
xml_printf (xml, " c:prefix=\"%s\"", c_prefix);
|
||||
|
||||
|
@ -1338,7 +1338,7 @@ gboolean gi_typelib_matches_gtype_name_prefix (GITypelib *typelib,
|
||||
|
||||
|
||||
GI_AVAILABLE_IN_ALL
|
||||
void gi_typelib_check_sanity (void);
|
||||
void gi_typelib_check_format (void);
|
||||
|
||||
/**
|
||||
* gi_typelib_get_string:
|
||||
|
@ -426,7 +426,7 @@ gi_typelib_get_dir_entry_by_error_domain (GITypelib *typelib,
|
||||
}
|
||||
|
||||
/**
|
||||
* gi_typelib_check_sanity:
|
||||
* gi_typelib_check_format:
|
||||
*
|
||||
* Check compile-time sizes of various typelib file format types are as
|
||||
* expected.
|
||||
@ -434,7 +434,7 @@ gi_typelib_get_dir_entry_by_error_domain (GITypelib *typelib,
|
||||
* Since: 2.80
|
||||
*/
|
||||
void
|
||||
gi_typelib_check_sanity (void)
|
||||
gi_typelib_check_format (void)
|
||||
{
|
||||
#ifndef G_DISABLE_ASSERT
|
||||
/* Check that struct layout is as we expect */
|
||||
@ -616,7 +616,7 @@ validate_header_basic (const guint8 *memory,
|
||||
/* This is a sanity check for a specific typelib; it
|
||||
* prevents us from loading an incompatible typelib.
|
||||
*
|
||||
* The hardcoded checks in gi_typelib_check_sanity to
|
||||
* The hardcoded checks in gi_typelib_check_format to
|
||||
* protect against inadvertent or buggy changes to the typelib format
|
||||
* itself.
|
||||
*/
|
||||
|
@ -179,7 +179,6 @@ typedef union _GIArgument GIArgument;
|
||||
* @GI_INFO_TYPE_OBJECT: object, see [class@GIRepository.ObjectInfo]
|
||||
* @GI_INFO_TYPE_INTERFACE: interface, see [class@GIRepository.InterfaceInfo]
|
||||
* @GI_INFO_TYPE_CONSTANT: constant, see [class@GIRepository.ConstantInfo]
|
||||
* @GI_INFO_TYPE_INVALID_0: deleted, used to be `GI_INFO_TYPE_ERROR_DOMAIN`.
|
||||
* @GI_INFO_TYPE_UNION: union, see [class@GIRepository.UnionInfo]
|
||||
* @GI_INFO_TYPE_VALUE: enum value, see [class@GIRepository.ValueInfo]
|
||||
* @GI_INFO_TYPE_SIGNAL: signal, see [class@GIRepository.SignalInfo]
|
||||
@ -214,23 +213,22 @@ typedef enum
|
||||
GI_INFO_TYPE_CALLBACK,
|
||||
GI_INFO_TYPE_STRUCT,
|
||||
GI_INFO_TYPE_BOXED,
|
||||
GI_INFO_TYPE_ENUM, /* 5 */
|
||||
GI_INFO_TYPE_ENUM, /* 5 */
|
||||
GI_INFO_TYPE_FLAGS,
|
||||
GI_INFO_TYPE_OBJECT,
|
||||
GI_INFO_TYPE_INTERFACE,
|
||||
GI_INFO_TYPE_CONSTANT,
|
||||
GI_INFO_TYPE_INVALID_0, /* 10 */
|
||||
GI_INFO_TYPE_UNION,
|
||||
GI_INFO_TYPE_UNION, /* 10 */
|
||||
GI_INFO_TYPE_VALUE,
|
||||
GI_INFO_TYPE_SIGNAL,
|
||||
GI_INFO_TYPE_VFUNC,
|
||||
GI_INFO_TYPE_PROPERTY, /* 15 */
|
||||
GI_INFO_TYPE_FIELD,
|
||||
GI_INFO_TYPE_PROPERTY,
|
||||
GI_INFO_TYPE_FIELD, /* 15 */
|
||||
GI_INFO_TYPE_ARG,
|
||||
GI_INFO_TYPE_TYPE,
|
||||
GI_INFO_TYPE_UNRESOLVED,
|
||||
GI_INFO_TYPE_CALLABLE, /* 20 */
|
||||
GI_INFO_TYPE_REGISTERED_TYPE,
|
||||
GI_INFO_TYPE_CALLABLE,
|
||||
GI_INFO_TYPE_REGISTERED_TYPE, /* 20 */
|
||||
/* keep GI_INFO_TYPE_N_TYPES in sync with this */
|
||||
} GIInfoType;
|
||||
|
||||
|
@ -342,7 +342,7 @@ gi_vfunc_info_invoke (GIVFuncInfo *info,
|
||||
GType implementor,
|
||||
const GIArgument *in_args,
|
||||
gsize n_in_args,
|
||||
const GIArgument *out_args,
|
||||
GIArgument *out_args,
|
||||
gsize n_out_args,
|
||||
GIArgument *return_value,
|
||||
GError **error)
|
||||
@ -370,8 +370,6 @@ gi_vfunc_info_invoke (GIVFuncInfo *info,
|
||||
out_args,
|
||||
n_out_args,
|
||||
return_value,
|
||||
TRUE,
|
||||
FALSE,
|
||||
error);
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ gboolean gi_vfunc_info_invoke (GIVFuncInfo *info,
|
||||
GType implementor,
|
||||
const GIArgument *in_args,
|
||||
gsize n_in_args,
|
||||
const GIArgument *out_args,
|
||||
GIArgument *out_args,
|
||||
gsize n_out_args,
|
||||
GIArgument *return_value,
|
||||
GError **error);
|
||||
|
Loading…
Reference in New Issue
Block a user