mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-09-07 00:18:44 +02:00
girepository: Make gi_repository_get_shared_library() return an array
And rename it to `gi_repository_get_shared_libraries()`. Previously it returned a comma-separated string, which wasn’t particularly typesafe or machine-friendly. Now it returns the same data as an array. This is an API break in libgirepository, but since it’s not been in a stable release yet, that’s fine. Signed-off-by: Philip Withnall <pwithnall@gnome.org> Helps: #3155
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user