2012-02-03 19:42:56 +01:00
|
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
|
|
|
|
* GObject introspection: Repository implementation
|
2008-02-08 16:31:03 +01:00
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2005 Matthias Clasen
|
2008-10-12 06:51:48 +02:00
|
|
|
|
* Copyright (C) 2008 Colin Walters <walters@verbum.org>
|
|
|
|
|
* Copyright (C) 2008 Red Hat, Inc.
|
2008-02-08 16:31:03 +01:00
|
|
|
|
*
|
2023-10-25 18:10:10 +02:00
|
|
|
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
|
*
|
2008-02-08 16:31:03 +01: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"
|
|
|
|
|
|
2008-02-08 16:31:03 +01:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
Bug 556543 – reduce compiler warnings
2008-10-16 Tommi Komulainen <tommi.komulainen@iki.fi>
Bug 556543 – reduce compiler warnings
* girepository/ginfo.c:
* girepository/girepository.c (register_internal,
count_interfaces, find_interface, find_namespace_version,
parse_version, g_irepository_require):
* girepository/girmodule.c (g_ir_module_build_typelib):
* girepository/girnode.c (init_stats, dump_stats,
_g_irnode_init_stats, _g_irnode_dump_stats,
g_ir_node_can_have_member):
* girepository/girparser.c (firstpass_end_element_handler,
locate_gir, parse_basic, parse_type_internal, resolve_aliases,
start_alias, start_type, end_type_top, parse_include, cleanup,
post_filter):
* girepository/gtypelib.c (validate_function_blob, validate_enum_blob):
* giscanner/giscannermodule.c (directive_get_options,
type_get_child_list):
* giscanner/scannerlexer.l (parse_gtkdoc):
* giscanner/scannerparser.y (ctype_free):
* giscanner/sourcescanner.c:
* giscanner/sourcescanner.h (gi_source_scanner_parse_macros):
* tests/types/gitesttypes.c:
* tools/compiler.c (main):
* tools/generate.c (write_repository): Remove unused variables
and code, add missing includes, declarations and case
statements.
svn path=/trunk/; revision=730
2008-10-16 19:07:05 +02:00
|
|
|
|
#include <stdlib.h>
|
2008-02-08 16:31:03 +01:00
|
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
#include <glib/gprintf.h>
|
|
|
|
|
#include <gmodule.h>
|
2024-02-08 13:35:23 +01:00
|
|
|
|
#include "gibaseinfo-private.h"
|
2008-02-08 16:31:03 +01:00
|
|
|
|
#include "girepository.h"
|
2010-05-31 22:44:46 +02:00
|
|
|
|
#include "gitypelib-internal.h"
|
2010-06-05 17:11:58 +02:00
|
|
|
|
#include "girepository-private.h"
|
2008-02-08 16:31:03 +01:00
|
|
|
|
|
2013-10-10 22:21:18 +02:00
|
|
|
|
/**
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* GIRepository:
|
2013-10-10 22:21:18 +02:00
|
|
|
|
*
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* `GIRepository` is used to manage repositories of namespaces. Namespaces
|
|
|
|
|
* are represented on disk by type libraries (`.typelib` files).
|
2018-01-30 15:01:06 +01:00
|
|
|
|
*
|
2024-01-25 23:03:57 +01:00
|
|
|
|
* The individual pieces of API within a type library are represented by
|
|
|
|
|
* subclasses of [class@GIRepository.BaseInfo]. These can be found using
|
|
|
|
|
* methods like [method@GIRepository.Repository.find_by_name] or
|
|
|
|
|
* [method@GIRepository.Repository.get_info].
|
|
|
|
|
*
|
|
|
|
|
* You are responsible for ensuring that the lifetime of the
|
|
|
|
|
* [class@GIRepository.Repository] exceeds that of the lifetime of any of its
|
|
|
|
|
* [class@GIRepository.BaseInfo]s. This cannot be guaranteed by using internal
|
|
|
|
|
* references within libgirepository as that would affect performance.
|
|
|
|
|
*
|
2018-01-30 15:01:06 +01:00
|
|
|
|
* ### Discovery of type libraries
|
|
|
|
|
*
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* `GIRepository` will typically look for a `girepository-1.0` directory
|
|
|
|
|
* under the library directory used when compiling gobject-introspection. On a
|
|
|
|
|
* standard Linux system this will end up being `/usr/lib/girepository-1.0`.
|
2018-01-30 15:01:06 +01:00
|
|
|
|
*
|
|
|
|
|
* It is possible to control the search paths programmatically, using
|
2024-01-26 11:21:23 +01:00
|
|
|
|
* [method@GIRepository.Repository.prepend_search_path]. It is also possible to
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* modify the search paths by using the `GI_TYPELIB_PATH` environment variable.
|
2018-01-30 15:01:06 +01:00
|
|
|
|
* The environment variable takes precedence over the default search path
|
2024-01-26 11:21:23 +01:00
|
|
|
|
* and the [method@GIRepository.Repository.prepend_search_path] calls.
|
2023-12-13 14:24:40 +01:00
|
|
|
|
*
|
|
|
|
|
* Since: 2.80
|
2013-10-10 22:21:18 +02:00
|
|
|
|
*/
|
|
|
|
|
|
2023-12-29 15:10:22 +01:00
|
|
|
|
/* The namespace and version corresponding to libgirepository itself, so
|
|
|
|
|
* that we can refuse to load typelibs corresponding to the older,
|
|
|
|
|
* incompatible version of this same library in gobject-introspection. */
|
|
|
|
|
#define GIREPOSITORY_TYPELIB_NAME "GIRepository"
|
|
|
|
|
#define GIREPOSITORY_TYPELIB_VERSION "3.0"
|
|
|
|
|
#define GIREPOSITORY_TYPELIB_FILENAME \
|
|
|
|
|
GIREPOSITORY_TYPELIB_NAME "-" GIREPOSITORY_TYPELIB_VERSION ".typelib"
|
|
|
|
|
|
2010-10-23 00:08:15 +02:00
|
|
|
|
typedef struct {
|
2024-01-16 02:11:41 +01:00
|
|
|
|
size_t n_interfaces;
|
2010-10-23 00:08:15 +02:00
|
|
|
|
GIBaseInfo *interfaces[];
|
|
|
|
|
} GTypeInterfaceCache;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtype_interface_cache_free (gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GTypeInterfaceCache *cache = data;
|
|
|
|
|
|
2024-01-16 02:11:41 +01:00
|
|
|
|
for (size_t i = 0; i < cache->n_interfaces; i++)
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_base_info_unref ((GIBaseInfo*) cache->interfaces[i]);
|
2010-10-23 00:08:15 +02:00
|
|
|
|
g_free (cache);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-26 00:09:16 +01:00
|
|
|
|
struct _GIRepository
|
2008-02-08 16:31:03 +01:00
|
|
|
|
{
|
2024-01-26 00:09:16 +01:00
|
|
|
|
GObject parent;
|
|
|
|
|
|
2024-01-26 11:21:23 +01:00
|
|
|
|
GPtrArray *typelib_search_path; /* (element-type filename) (owned) */
|
|
|
|
|
GPtrArray *library_paths; /* (element-type filename) (owned) */
|
|
|
|
|
|
2010-08-31 22:36:06 +02:00
|
|
|
|
GHashTable *typelibs; /* (string) namespace -> GITypelib */
|
|
|
|
|
GHashTable *lazy_typelibs; /* (string) namespace-version -> GITypelib */
|
2008-12-10 18:53:09 +01:00
|
|
|
|
GHashTable *info_by_gtype; /* GType -> GIBaseInfo */
|
2011-05-19 23:46:36 +02:00
|
|
|
|
GHashTable *info_by_error_domain; /* GQuark -> GIBaseInfo */
|
2010-10-23 00:08:15 +02:00
|
|
|
|
GHashTable *interfaces_for_gtype; /* GType -> GTypeInterfaceCache */
|
2019-11-13 19:37:00 +01:00
|
|
|
|
GHashTable *unknown_gtypes; /* hashset of GType */
|
2024-01-05 13:33:02 +01:00
|
|
|
|
|
|
|
|
|
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 */
|
2008-02-08 16:31:03 +01:00
|
|
|
|
};
|
|
|
|
|
|
2024-01-26 00:09:16 +01:00
|
|
|
|
G_DEFINE_TYPE (GIRepository, gi_repository, G_TYPE_OBJECT);
|
2008-02-08 16:31:03 +01:00
|
|
|
|
|
2011-09-05 17:19:39 +02:00
|
|
|
|
#ifdef G_PLATFORM_WIN32
|
|
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
|
|
static HMODULE girepository_dll = NULL;
|
|
|
|
|
|
|
|
|
|
#ifdef DLL_EXPORT
|
|
|
|
|
|
2019-01-01 18:06:47 +01:00
|
|
|
|
BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);
|
|
|
|
|
|
2011-09-05 17:19:39 +02:00
|
|
|
|
BOOL WINAPI
|
|
|
|
|
DllMain (HINSTANCE hinstDLL,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
DWORD fdwReason,
|
|
|
|
|
LPVOID lpvReserved)
|
2011-09-05 17:19:39 +02:00
|
|
|
|
{
|
|
|
|
|
if (fdwReason == DLL_PROCESS_ATTACH)
|
|
|
|
|
girepository_dll = hinstDLL;
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#undef GOBJECT_INTROSPECTION_LIBDIR
|
|
|
|
|
|
|
|
|
|
/* GOBJECT_INTROSPECTION_LIBDIR is used only in code called just once,
|
|
|
|
|
* so no problem leaking this
|
|
|
|
|
*/
|
|
|
|
|
#define GOBJECT_INTROSPECTION_LIBDIR \
|
|
|
|
|
g_build_filename (g_win32_get_package_installation_directory_of_module (girepository_dll), \
|
2024-01-16 17:30:37 +01:00
|
|
|
|
"lib", \
|
|
|
|
|
NULL)
|
2011-09-05 17:19:39 +02:00
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2010-03-24 19:00:06 +01:00
|
|
|
|
static void
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_repository_init (GIRepository *repository)
|
2008-02-08 16:31:03 +01:00
|
|
|
|
{
|
2024-01-26 11:21:23 +01:00
|
|
|
|
/* typelib search path */
|
|
|
|
|
{
|
|
|
|
|
const char *libdir;
|
|
|
|
|
char *typelib_dir;
|
|
|
|
|
const char *type_lib_path_env;
|
|
|
|
|
|
|
|
|
|
/* This variable is intended to take precedence over both:
|
|
|
|
|
* - the default search path;
|
|
|
|
|
* - all gi_repository_prepend_search_path() calls.
|
|
|
|
|
*/
|
|
|
|
|
type_lib_path_env = g_getenv ("GI_TYPELIB_PATH");
|
|
|
|
|
|
|
|
|
|
if (type_lib_path_env)
|
|
|
|
|
{
|
|
|
|
|
char **custom_dirs;
|
|
|
|
|
|
|
|
|
|
custom_dirs = g_strsplit (type_lib_path_env, G_SEARCHPATH_SEPARATOR_S, 0);
|
|
|
|
|
repository->typelib_search_path =
|
|
|
|
|
g_ptr_array_new_take_null_terminated ((gpointer) g_steal_pointer (&custom_dirs), g_free);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
repository->typelib_search_path = g_ptr_array_new_null_terminated (1, g_free, TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
libdir = GOBJECT_INTROSPECTION_LIBDIR;
|
|
|
|
|
|
|
|
|
|
typelib_dir = g_build_filename (libdir, "girepository-1.0", NULL);
|
|
|
|
|
|
|
|
|
|
g_ptr_array_add (repository->typelib_search_path, g_steal_pointer (&typelib_dir));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
repository->library_paths = g_ptr_array_new_null_terminated (1, g_free, TRUE);
|
|
|
|
|
|
2024-01-26 00:09:16 +01:00
|
|
|
|
repository->typelibs
|
2008-08-30 22:31:12 +02:00
|
|
|
|
= g_hash_table_new_full (g_str_hash, g_str_equal,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
(GDestroyNotify) g_free,
|
2024-02-07 15:38:05 +01:00
|
|
|
|
(GDestroyNotify) gi_typelib_unref);
|
2024-01-26 00:09:16 +01:00
|
|
|
|
repository->lazy_typelibs
|
2012-02-03 17:11:59 +01:00
|
|
|
|
= g_hash_table_new_full (g_str_hash, g_str_equal,
|
|
|
|
|
(GDestroyNotify) g_free,
|
2024-02-07 15:38:05 +01:00
|
|
|
|
(GDestroyNotify) gi_typelib_unref);
|
2024-01-26 00:09:16 +01:00
|
|
|
|
repository->info_by_gtype
|
2008-12-10 18:53:09 +01:00
|
|
|
|
= g_hash_table_new_full (g_direct_hash, g_direct_equal,
|
|
|
|
|
(GDestroyNotify) NULL,
|
2023-11-08 15:17:52 +01:00
|
|
|
|
(GDestroyNotify) gi_base_info_unref);
|
2024-01-26 00:09:16 +01:00
|
|
|
|
repository->info_by_error_domain
|
2011-05-19 23:46:36 +02:00
|
|
|
|
= g_hash_table_new_full (g_direct_hash, g_direct_equal,
|
|
|
|
|
(GDestroyNotify) NULL,
|
2023-11-08 15:17:52 +01:00
|
|
|
|
(GDestroyNotify) gi_base_info_unref);
|
2024-01-26 00:09:16 +01:00
|
|
|
|
repository->interfaces_for_gtype
|
2010-10-23 00:08:15 +02:00
|
|
|
|
= g_hash_table_new_full (g_direct_hash, g_direct_equal,
|
|
|
|
|
(GDestroyNotify) NULL,
|
|
|
|
|
(GDestroyNotify) gtype_interface_cache_free);
|
2024-01-26 00:09:16 +01:00
|
|
|
|
repository->unknown_gtypes = g_hash_table_new (NULL, NULL);
|
2008-02-08 16:31:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_repository_finalize (GObject *object)
|
2008-02-08 16:31:03 +01:00
|
|
|
|
{
|
2023-11-08 15:17:52 +01:00
|
|
|
|
GIRepository *repository = GI_REPOSITORY (object);
|
2008-02-08 16:31:03 +01:00
|
|
|
|
|
2024-01-26 00:09:16 +01:00
|
|
|
|
g_hash_table_destroy (repository->typelibs);
|
|
|
|
|
g_hash_table_destroy (repository->lazy_typelibs);
|
|
|
|
|
g_hash_table_destroy (repository->info_by_gtype);
|
|
|
|
|
g_hash_table_destroy (repository->info_by_error_domain);
|
|
|
|
|
g_hash_table_destroy (repository->interfaces_for_gtype);
|
|
|
|
|
g_hash_table_destroy (repository->unknown_gtypes);
|
2010-03-24 19:00:06 +01:00
|
|
|
|
|
2024-01-26 00:09:16 +01:00
|
|
|
|
g_clear_pointer (&repository->cached_shared_libraries, g_strfreev);
|
2024-01-05 13:33:02 +01:00
|
|
|
|
|
2024-01-26 11:21:23 +01:00
|
|
|
|
g_clear_pointer (&repository->library_paths, g_ptr_array_unref);
|
|
|
|
|
g_clear_pointer (&repository->typelib_search_path, g_ptr_array_unref);
|
|
|
|
|
|
2023-11-08 15:17:52 +01:00
|
|
|
|
(* G_OBJECT_CLASS (gi_repository_parent_class)->finalize) (G_OBJECT (repository));
|
2008-02-08 16:31:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_repository_class_init (GIRepositoryClass *class)
|
2008-02-08 16:31:03 +01:00
|
|
|
|
{
|
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (class);
|
|
|
|
|
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gobject_class->finalize = gi_repository_finalize;
|
2008-02-08 16:31:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-10 22:21:18 +02:00
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_repository_prepend_search_path:
|
2024-01-26 11:44:09 +01:00
|
|
|
|
* @repository: A #GIRepository
|
2013-10-10 22:21:18 +02:00
|
|
|
|
* @directory: (type filename): directory name to prepend to the typelib
|
|
|
|
|
* search path
|
|
|
|
|
*
|
|
|
|
|
* Prepends @directory to the typelib search path.
|
2018-01-30 15:01:06 +01:00
|
|
|
|
*
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* See also: gi_repository_get_search_path().
|
2023-12-13 14:24:40 +01:00
|
|
|
|
*
|
|
|
|
|
* Since: 2.80
|
2013-10-10 22:21:18 +02:00
|
|
|
|
*/
|
2008-08-30 22:31:07 +02:00
|
|
|
|
void
|
2024-01-26 11:21:23 +01:00
|
|
|
|
gi_repository_prepend_search_path (GIRepository *repository,
|
|
|
|
|
const char *directory)
|
2008-08-30 22:31:07 +02:00
|
|
|
|
{
|
2024-01-26 11:44:09 +01:00
|
|
|
|
g_return_if_fail (GI_IS_REPOSITORY (repository));
|
|
|
|
|
|
2024-01-26 11:21:23 +01:00
|
|
|
|
g_ptr_array_insert (repository->typelib_search_path, 0, g_strdup (directory));
|
2008-08-30 22:31:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
2008-11-12 13:40:34 +01:00
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_repository_get_search_path:
|
2024-01-26 11:44:09 +01:00
|
|
|
|
* @repository: A #GIRepository
|
2023-12-20 06:29:40 +01:00
|
|
|
|
* @n_paths_out: (optional) (out): The number of search paths returned.
|
2008-11-12 13:40:34 +01:00
|
|
|
|
*
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* Returns the current search path [class@GIRepository.Repository] will use when
|
|
|
|
|
* loading typelib files.
|
|
|
|
|
*
|
|
|
|
|
* The list is internal to [class@GIRepository.Repository] and should not be
|
|
|
|
|
* freed, nor should its string elements.
|
2008-11-12 13:40:34 +01:00
|
|
|
|
*
|
2024-02-07 16:45:28 +01:00
|
|
|
|
* The list is guaranteed to be `NULL` terminated. The `NULL` terminator is not
|
|
|
|
|
* counted in @n_paths_out.
|
|
|
|
|
*
|
2023-12-20 06:29:40 +01:00
|
|
|
|
* Returns: (element-type filename) (transfer none) (array length=n_paths_out): list of search paths, most
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* important first
|
|
|
|
|
* Since: 2.80
|
2008-11-12 13:40:34 +01:00
|
|
|
|
*/
|
2023-12-20 06:29:40 +01:00
|
|
|
|
const char * const *
|
2024-01-26 11:21:23 +01:00
|
|
|
|
gi_repository_get_search_path (GIRepository *repository,
|
|
|
|
|
size_t *n_paths_out)
|
2008-11-12 13:40:34 +01:00
|
|
|
|
{
|
2024-01-26 11:44:09 +01:00
|
|
|
|
g_return_val_if_fail (GI_IS_REPOSITORY (repository), NULL);
|
2024-01-26 11:21:23 +01:00
|
|
|
|
|
|
|
|
|
if G_UNLIKELY (!repository->typelib_search_path ||
|
|
|
|
|
!repository->typelib_search_path->pdata)
|
2023-12-20 06:29:40 +01:00
|
|
|
|
{
|
|
|
|
|
static const char * const empty_search_path[] = {NULL};
|
|
|
|
|
|
|
|
|
|
if (n_paths_out)
|
|
|
|
|
*n_paths_out = 0;
|
|
|
|
|
|
|
|
|
|
return empty_search_path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (n_paths_out)
|
2024-01-26 11:21:23 +01:00
|
|
|
|
*n_paths_out = repository->typelib_search_path->len;
|
2023-12-20 06:29:40 +01:00
|
|
|
|
|
2024-01-26 11:21:23 +01:00
|
|
|
|
return (const char * const *) repository->typelib_search_path->pdata;
|
2008-11-12 13:40:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-24 00:53:59 +01:00
|
|
|
|
/**
|
|
|
|
|
* gi_repository_prepend_library_path:
|
2024-01-26 11:44:09 +01:00
|
|
|
|
* @repository: A #GIRepository
|
2024-01-24 00:53:59 +01:00
|
|
|
|
* @directory: (type filename): a single directory to scan for shared libraries
|
|
|
|
|
*
|
|
|
|
|
* Prepends @directory to the search path that is used to
|
|
|
|
|
* search shared libraries referenced by imported namespaces.
|
|
|
|
|
*
|
|
|
|
|
* Multiple calls to this function all contribute to the final
|
|
|
|
|
* list of paths.
|
|
|
|
|
*
|
2024-01-26 11:21:23 +01:00
|
|
|
|
* The list of paths is unique to @repository. When a typelib is loaded by the
|
|
|
|
|
* repository, the list of paths from the @repository at that instant is used
|
|
|
|
|
* by the typelib for loading its modules.
|
2024-01-24 00:53:59 +01:00
|
|
|
|
*
|
|
|
|
|
* If the library is not found in the directories configured
|
|
|
|
|
* in this way, loading will fall back to the system library
|
|
|
|
|
* path (i.e. `LD_LIBRARY_PATH` and `DT_RPATH` in ELF systems).
|
|
|
|
|
* See the documentation of your dynamic linker for full details.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.80
|
|
|
|
|
*/
|
|
|
|
|
void
|
2024-01-26 11:21:23 +01:00
|
|
|
|
gi_repository_prepend_library_path (GIRepository *repository,
|
|
|
|
|
const char *directory)
|
2024-01-24 00:53:59 +01:00
|
|
|
|
{
|
2024-01-26 11:44:09 +01:00
|
|
|
|
g_return_if_fail (GI_IS_REPOSITORY (repository));
|
|
|
|
|
|
2024-01-26 11:21:23 +01:00
|
|
|
|
g_ptr_array_insert (repository->library_paths, 0, g_strdup (directory));
|
2024-01-24 00:53:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gi_repository_get_library_path:
|
2024-01-26 11:44:09 +01:00
|
|
|
|
* @repository: A #GIRepository
|
2024-01-24 00:53:59 +01:00
|
|
|
|
* @n_paths_out: (optional) (out): The number of library paths returned.
|
|
|
|
|
*
|
|
|
|
|
* Returns the current search path [class@GIRepository.Repository] will use when
|
|
|
|
|
* loading shared libraries referenced by imported namespaces.
|
|
|
|
|
*
|
|
|
|
|
* The list is internal to [class@GIRepository.Repository] and should not be
|
|
|
|
|
* freed, nor should its string elements.
|
|
|
|
|
*
|
2024-02-07 16:45:28 +01:00
|
|
|
|
* The list is guaranteed to be `NULL` terminated. The `NULL` terminator is not
|
|
|
|
|
* counted in @n_paths_out.
|
|
|
|
|
*
|
2024-01-24 00:53:59 +01:00
|
|
|
|
* Returns: (element-type filename) (transfer none) (array length=n_paths_out): list of search paths, most
|
|
|
|
|
* important first
|
|
|
|
|
* Since: 2.80
|
|
|
|
|
*/
|
|
|
|
|
const char * const *
|
2024-01-26 11:21:23 +01:00
|
|
|
|
gi_repository_get_library_path (GIRepository *repository,
|
|
|
|
|
size_t *n_paths_out)
|
2024-01-24 00:53:59 +01:00
|
|
|
|
{
|
2024-01-26 11:44:09 +01:00
|
|
|
|
g_return_val_if_fail (GI_IS_REPOSITORY (repository), NULL);
|
2024-01-26 11:21:23 +01:00
|
|
|
|
|
|
|
|
|
if G_UNLIKELY (!repository->library_paths || !repository->library_paths->pdata)
|
2024-01-24 00:53:59 +01:00
|
|
|
|
{
|
|
|
|
|
static const char * const empty_search_path[] = {NULL};
|
|
|
|
|
|
|
|
|
|
if (n_paths_out)
|
|
|
|
|
*n_paths_out = 0;
|
|
|
|
|
|
|
|
|
|
return empty_search_path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (n_paths_out)
|
2024-01-26 11:21:23 +01:00
|
|
|
|
*n_paths_out = repository->library_paths->len;
|
2024-01-24 00:53:59 +01:00
|
|
|
|
|
2024-01-26 11:21:23 +01:00
|
|
|
|
return (const char * const *) repository->library_paths->pdata;
|
2024-01-24 00:53:59 +01:00
|
|
|
|
}
|
|
|
|
|
|
2008-08-21 05:06:13 +02:00
|
|
|
|
static char *
|
|
|
|
|
build_typelib_key (const char *name, const char *source)
|
|
|
|
|
{
|
|
|
|
|
GString *str = g_string_new (name);
|
|
|
|
|
g_string_append_c (str, '\0');
|
|
|
|
|
g_string_append (str, source);
|
|
|
|
|
return g_string_free (str, FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-31 23:22:16 +01:00
|
|
|
|
/* Note: Returns %NULL (not an empty %NULL-terminated array) if there are no
|
|
|
|
|
* dependencies. */
|
2008-08-30 22:31:07 +02:00
|
|
|
|
static char **
|
2010-08-31 22:36:06 +02:00
|
|
|
|
get_typelib_dependencies (GITypelib *typelib)
|
2008-02-08 16:31:03 +01:00
|
|
|
|
{
|
|
|
|
|
Header *header;
|
2008-08-30 22:31:07 +02:00
|
|
|
|
const char *dependencies_glob;
|
|
|
|
|
|
2008-08-09 14:55:32 +02:00
|
|
|
|
header = (Header *)typelib->data;
|
2008-02-08 16:31:03 +01:00
|
|
|
|
|
2008-08-30 22:31:07 +02:00
|
|
|
|
if (header->dependencies == 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2023-11-08 15:17:52 +01:00
|
|
|
|
dependencies_glob = gi_typelib_get_string (typelib, header->dependencies);
|
2008-08-30 22:31:07 +02:00
|
|
|
|
return g_strsplit (dependencies_glob, "|", 0);
|
|
|
|
|
}
|
2008-02-08 16:31:03 +01:00
|
|
|
|
|
2010-08-31 22:36:06 +02:00
|
|
|
|
static GITypelib *
|
|
|
|
|
check_version_conflict (GITypelib *typelib,
|
2024-01-15 20:20:47 +01:00
|
|
|
|
const char *namespace,
|
|
|
|
|
const char *expected_version,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
char **version_conflict)
|
2008-10-12 06:51:48 +02:00
|
|
|
|
{
|
|
|
|
|
Header *header;
|
|
|
|
|
const char *loaded_version;
|
|
|
|
|
|
|
|
|
|
if (expected_version == NULL)
|
|
|
|
|
{
|
|
|
|
|
if (version_conflict)
|
2024-01-16 17:30:37 +01:00
|
|
|
|
*version_conflict = NULL;
|
2008-10-12 06:51:48 +02:00
|
|
|
|
return typelib;
|
|
|
|
|
}
|
2010-03-24 19:00:06 +01:00
|
|
|
|
|
2008-10-12 06:51:48 +02:00
|
|
|
|
header = (Header*)typelib->data;
|
2023-11-08 15:17:52 +01:00
|
|
|
|
loaded_version = gi_typelib_get_string (typelib, header->nsversion);
|
2008-10-12 06:51:48 +02:00
|
|
|
|
g_assert (loaded_version != NULL);
|
2010-03-24 19:00:06 +01:00
|
|
|
|
|
2008-10-12 06:51:48 +02:00
|
|
|
|
if (strcmp (expected_version, loaded_version) != 0)
|
|
|
|
|
{
|
|
|
|
|
if (version_conflict)
|
2024-01-16 17:30:37 +01:00
|
|
|
|
*version_conflict = (char*)loaded_version;
|
2008-10-12 06:51:48 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
if (version_conflict)
|
|
|
|
|
*version_conflict = NULL;
|
|
|
|
|
return typelib;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-31 22:36:06 +02:00
|
|
|
|
static GITypelib *
|
2008-08-30 22:31:12 +02:00
|
|
|
|
get_registered_status (GIRepository *repository,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
const char *namespace,
|
|
|
|
|
const char *version,
|
|
|
|
|
gboolean allow_lazy,
|
|
|
|
|
gboolean *lazy_status,
|
|
|
|
|
char **version_conflict)
|
2008-08-30 22:31:07 +02:00
|
|
|
|
{
|
2010-08-31 22:36:06 +02:00
|
|
|
|
GITypelib *typelib;
|
2024-01-26 11:44:09 +01:00
|
|
|
|
|
2008-08-30 22:31:12 +02:00
|
|
|
|
if (lazy_status)
|
|
|
|
|
*lazy_status = FALSE;
|
2024-01-26 00:09:16 +01:00
|
|
|
|
typelib = g_hash_table_lookup (repository->typelibs, namespace);
|
2010-03-24 19:00:06 +01:00
|
|
|
|
if (typelib)
|
2008-10-12 06:51:48 +02:00
|
|
|
|
return check_version_conflict (typelib, namespace, version, version_conflict);
|
2024-01-26 00:09:16 +01:00
|
|
|
|
typelib = g_hash_table_lookup (repository->lazy_typelibs, namespace);
|
2008-08-30 22:31:12 +02:00
|
|
|
|
if (!typelib)
|
|
|
|
|
return NULL;
|
|
|
|
|
if (lazy_status)
|
|
|
|
|
*lazy_status = TRUE;
|
|
|
|
|
if (!allow_lazy)
|
|
|
|
|
return NULL;
|
2008-10-12 06:51:48 +02:00
|
|
|
|
return check_version_conflict (typelib, namespace, version, version_conflict);
|
2008-08-30 22:31:12 +02:00
|
|
|
|
}
|
2008-08-30 22:31:07 +02:00
|
|
|
|
|
2010-08-31 22:36:06 +02:00
|
|
|
|
static GITypelib *
|
2008-08-30 22:31:12 +02:00
|
|
|
|
get_registered (GIRepository *repository,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
const char *namespace,
|
|
|
|
|
const char *version)
|
2008-08-30 22:31:12 +02:00
|
|
|
|
{
|
2008-10-12 06:51:48 +02:00
|
|
|
|
return get_registered_status (repository, namespace, version, TRUE, NULL, NULL);
|
2008-08-30 22:31:12 +02:00
|
|
|
|
}
|
2008-02-08 16:31:03 +01:00
|
|
|
|
|
2008-08-30 22:31:12 +02:00
|
|
|
|
static gboolean
|
|
|
|
|
load_dependencies_recurse (GIRepository *repository,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
GITypelib *typelib,
|
|
|
|
|
GError **error)
|
2008-08-30 22:31:12 +02:00
|
|
|
|
{
|
|
|
|
|
char **dependencies;
|
2008-02-08 16:31:03 +01:00
|
|
|
|
|
2008-08-30 22:31:07 +02:00
|
|
|
|
dependencies = get_typelib_dependencies (typelib);
|
2008-08-30 22:31:12 +02:00
|
|
|
|
|
2008-08-30 22:31:07 +02:00
|
|
|
|
if (dependencies != NULL)
|
2008-02-08 16:31:03 +01:00
|
|
|
|
{
|
2008-08-30 22:31:07 +02:00
|
|
|
|
int i;
|
2010-03-24 19:00:06 +01:00
|
|
|
|
|
2008-08-30 22:31:07 +02:00
|
|
|
|
for (i = 0; dependencies[i]; i++)
|
2024-01-16 17:30:37 +01:00
|
|
|
|
{
|
|
|
|
|
char *dependency = dependencies[i];
|
|
|
|
|
const char *last_dash;
|
|
|
|
|
char *dependency_namespace;
|
|
|
|
|
const char *dependency_version;
|
|
|
|
|
|
|
|
|
|
last_dash = strrchr (dependency, '-');
|
|
|
|
|
dependency_namespace = g_strndup (dependency, last_dash - dependency);
|
|
|
|
|
dependency_version = last_dash+1;
|
|
|
|
|
|
|
|
|
|
if (!gi_repository_require (repository, dependency_namespace, dependency_version,
|
|
|
|
|
0, error))
|
|
|
|
|
{
|
|
|
|
|
g_free (dependency_namespace);
|
|
|
|
|
g_strfreev (dependencies);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
g_free (dependency_namespace);
|
|
|
|
|
}
|
2008-08-30 22:31:07 +02:00
|
|
|
|
g_strfreev (dependencies);
|
2008-02-08 16:31:03 +01:00
|
|
|
|
}
|
2008-08-30 22:31:12 +02:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2008-10-12 06:51:48 +02:00
|
|
|
|
|
2008-08-30 22:31:12 +02:00
|
|
|
|
static const char *
|
|
|
|
|
register_internal (GIRepository *repository,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
const char *source,
|
|
|
|
|
gboolean lazy,
|
|
|
|
|
GITypelib *typelib,
|
|
|
|
|
GError **error)
|
2008-08-30 22:31:12 +02:00
|
|
|
|
{
|
|
|
|
|
Header *header;
|
2024-01-15 20:20:47 +01:00
|
|
|
|
const char *namespace;
|
2008-08-30 22:31:12 +02:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (typelib != NULL, FALSE);
|
2010-03-24 19:00:06 +01:00
|
|
|
|
|
2008-08-30 22:31:12 +02:00
|
|
|
|
header = (Header *)typelib->data;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (header != NULL, FALSE);
|
|
|
|
|
|
2023-11-08 15:17:52 +01:00
|
|
|
|
namespace = gi_typelib_get_string (typelib, header->namespace);
|
2008-08-30 22:31:12 +02:00
|
|
|
|
|
|
|
|
|
if (lazy)
|
|
|
|
|
{
|
2024-01-26 00:09:16 +01:00
|
|
|
|
g_assert (!g_hash_table_lookup (repository->lazy_typelibs,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
namespace));
|
2024-01-26 00:09:16 +01:00
|
|
|
|
g_hash_table_insert (repository->lazy_typelibs,
|
2024-02-07 15:38:05 +01:00
|
|
|
|
build_typelib_key (namespace, source), gi_typelib_ref (typelib));
|
2008-08-30 22:31:12 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
gpointer value;
|
|
|
|
|
char *key;
|
2008-08-30 22:31:07 +02:00
|
|
|
|
|
2008-08-30 22:31:12 +02:00
|
|
|
|
/* First, try loading all the dependencies */
|
|
|
|
|
if (!load_dependencies_recurse (repository, typelib, error))
|
2024-01-16 17:30:37 +01:00
|
|
|
|
return NULL;
|
2010-03-24 19:00:06 +01:00
|
|
|
|
|
2008-08-30 22:31:12 +02:00
|
|
|
|
/* Check if we are transitioning from lazily loaded state */
|
2024-01-26 00:09:16 +01:00
|
|
|
|
if (g_hash_table_lookup_extended (repository->lazy_typelibs,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
namespace,
|
|
|
|
|
(gpointer)&key, &value))
|
2024-01-26 00:09:16 +01:00
|
|
|
|
g_hash_table_remove (repository->lazy_typelibs, key);
|
2008-08-30 22:31:12 +02:00
|
|
|
|
else
|
2024-01-16 17:30:37 +01:00
|
|
|
|
key = build_typelib_key (namespace, source);
|
2008-08-30 22:31:12 +02:00
|
|
|
|
|
2024-01-26 00:09:16 +01:00
|
|
|
|
g_hash_table_insert (repository->typelibs,
|
2023-11-24 00:22:01 +01:00
|
|
|
|
g_steal_pointer (&key),
|
2024-02-07 15:38:05 +01:00
|
|
|
|
gi_typelib_ref (typelib));
|
2008-08-30 22:31:12 +02:00
|
|
|
|
}
|
2008-02-08 16:31:03 +01:00
|
|
|
|
|
2019-11-13 19:37:00 +01:00
|
|
|
|
/* These types might be resolved now, clear the cache */
|
2024-01-26 00:09:16 +01:00
|
|
|
|
g_hash_table_remove_all (repository->unknown_gtypes);
|
2019-11-13 19:37:00 +01:00
|
|
|
|
|
2008-08-30 22:31:12 +02:00
|
|
|
|
return namespace;
|
2008-02-08 16:31:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-31 23:48:56 +01:00
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_repository_get_immediate_dependencies:
|
2024-01-26 11:44:09 +01:00
|
|
|
|
* @repository: A #GIRepository
|
2015-01-31 23:48:56 +01:00
|
|
|
|
* @namespace_: Namespace of interest
|
2024-02-07 16:44:21 +01:00
|
|
|
|
* @n_dependencies_out: (optional) (out): Return location for the number of
|
|
|
|
|
* dependencies
|
2015-01-31 23:48:56 +01:00
|
|
|
|
*
|
|
|
|
|
* Return an array of the immediate versioned dependencies for @namespace_.
|
2022-02-13 15:20:51 +01:00
|
|
|
|
* Returned strings are of the form `namespace-version`.
|
2015-01-31 23:48:56 +01:00
|
|
|
|
*
|
|
|
|
|
* Note: @namespace_ must have already been loaded using a function
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* such as [method@GIRepository.Repository.require] before calling this
|
|
|
|
|
* function.
|
2015-01-31 23:48:56 +01:00
|
|
|
|
*
|
|
|
|
|
* To get the transitive closure of dependencies for @namespace_, use
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* [method@GIRepository.Repository.get_dependencies].
|
2015-01-31 23:48:56 +01:00
|
|
|
|
*
|
2024-02-07 16:44:21 +01:00
|
|
|
|
* The list is guaranteed to be `NULL` terminated. The `NULL` terminator is not
|
|
|
|
|
* counted in @n_dependencies_out.
|
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer full) (array length=n_dependencies_out): String array of
|
|
|
|
|
* immediate versioned dependencies
|
2023-11-09 00:24:11 +01:00
|
|
|
|
* Since: 2.80
|
2015-01-31 23:48:56 +01:00
|
|
|
|
*/
|
|
|
|
|
char **
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_repository_get_immediate_dependencies (GIRepository *repository,
|
2024-02-07 16:44:21 +01:00
|
|
|
|
const char *namespace,
|
|
|
|
|
size_t *n_dependencies_out)
|
2015-01-31 23:48:56 +01:00
|
|
|
|
{
|
|
|
|
|
GITypelib *typelib;
|
2024-01-15 20:20:47 +01:00
|
|
|
|
char **deps;
|
2015-01-31 23:48:56 +01:00
|
|
|
|
|
2024-01-26 11:44:09 +01:00
|
|
|
|
g_return_val_if_fail (GI_IS_REPOSITORY (repository), NULL);
|
2015-01-31 23:48:56 +01:00
|
|
|
|
g_return_val_if_fail (namespace != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
typelib = get_registered (repository, namespace, NULL);
|
|
|
|
|
g_return_val_if_fail (typelib != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
/* Ensure we always return a non-%NULL vector. */
|
|
|
|
|
deps = get_typelib_dependencies (typelib);
|
|
|
|
|
if (deps == NULL)
|
|
|
|
|
deps = g_strsplit ("", "|", 0);
|
|
|
|
|
|
2024-02-07 16:44:21 +01:00
|
|
|
|
if (n_dependencies_out != NULL)
|
|
|
|
|
*n_dependencies_out = g_strv_length (deps);
|
|
|
|
|
|
2015-01-31 23:48:56 +01:00
|
|
|
|
return deps;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Load the transitive closure of dependency namespace-version strings for the
|
|
|
|
|
* given @typelib. @repository must be non-%NULL. @transitive_dependencies must
|
|
|
|
|
* be a pre-existing GHashTable<owned utf8, owned utf8> set for storing the
|
|
|
|
|
* dependencies. */
|
|
|
|
|
static void
|
|
|
|
|
get_typelib_dependencies_transitive (GIRepository *repository,
|
|
|
|
|
GITypelib *typelib,
|
|
|
|
|
GHashTable *transitive_dependencies)
|
|
|
|
|
{
|
2024-01-15 20:20:47 +01:00
|
|
|
|
char **immediate_dependencies;
|
2015-01-31 23:48:56 +01:00
|
|
|
|
|
|
|
|
|
immediate_dependencies = get_typelib_dependencies (typelib);
|
|
|
|
|
|
2024-01-16 01:57:09 +01:00
|
|
|
|
for (size_t i = 0; immediate_dependencies != NULL && immediate_dependencies[i]; i++)
|
2015-01-31 23:48:56 +01:00
|
|
|
|
{
|
2024-01-15 20:20:47 +01:00
|
|
|
|
char *dependency;
|
|
|
|
|
const char *last_dash;
|
|
|
|
|
char *dependency_namespace;
|
2015-01-31 23:48:56 +01:00
|
|
|
|
|
|
|
|
|
dependency = immediate_dependencies[i];
|
|
|
|
|
|
|
|
|
|
/* Steal from the strv. */
|
|
|
|
|
g_hash_table_add (transitive_dependencies, dependency);
|
|
|
|
|
immediate_dependencies[i] = NULL;
|
|
|
|
|
|
|
|
|
|
/* Recurse for this namespace. */
|
|
|
|
|
last_dash = strrchr (dependency, '-');
|
|
|
|
|
dependency_namespace = g_strndup (dependency, last_dash - dependency);
|
|
|
|
|
|
|
|
|
|
typelib = get_registered (repository, dependency_namespace, NULL);
|
|
|
|
|
g_return_if_fail (typelib != NULL);
|
|
|
|
|
get_typelib_dependencies_transitive (repository, typelib,
|
|
|
|
|
transitive_dependencies);
|
|
|
|
|
|
|
|
|
|
g_free (dependency_namespace);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free (immediate_dependencies);
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-13 18:59:09 +02:00
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_repository_get_dependencies:
|
2024-01-26 11:44:09 +01:00
|
|
|
|
* @repository: A #GIRepository
|
2009-02-12 04:32:25 +01:00
|
|
|
|
* @namespace_: Namespace of interest
|
2024-02-07 16:44:21 +01:00
|
|
|
|
* @n_dependencies_out: (optional) (out): Return location for the number of
|
|
|
|
|
* dependencies
|
2008-10-13 18:59:09 +02:00
|
|
|
|
*
|
2022-02-13 15:20:51 +01:00
|
|
|
|
* Retrieves all (transitive) versioned dependencies for
|
|
|
|
|
* @namespace_.
|
|
|
|
|
*
|
2023-12-20 21:02:39 +01:00
|
|
|
|
* The returned strings are of the form `namespace-version`.
|
2008-10-13 18:59:09 +02:00
|
|
|
|
*
|
2013-10-10 22:21:18 +02:00
|
|
|
|
* Note: @namespace_ must have already been loaded using a function
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* such as [method@GIRepository.Repository.require] before calling this
|
|
|
|
|
* function.
|
2008-10-13 18:59:09 +02:00
|
|
|
|
*
|
2015-01-31 23:48:56 +01:00
|
|
|
|
* To get only the immediate dependencies for @namespace_, use
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* [method@GIRepository.Repository.get_immediate_dependencies].
|
2015-01-31 23:48:56 +01:00
|
|
|
|
*
|
2024-02-07 16:44:21 +01:00
|
|
|
|
* The list is guaranteed to be `NULL` terminated. The `NULL` terminator is not
|
|
|
|
|
* counted in @n_dependencies_out.
|
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer full) (array length=n_dependencies_out): String array of
|
|
|
|
|
* all versioned dependencies
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* Since: 2.80
|
2008-10-13 18:59:09 +02:00
|
|
|
|
*/
|
2008-08-30 22:31:07 +02:00
|
|
|
|
char **
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_repository_get_dependencies (GIRepository *repository,
|
2024-02-07 16:44:21 +01:00
|
|
|
|
const char *namespace,
|
|
|
|
|
size_t *n_dependencies_out)
|
2008-08-30 22:31:07 +02:00
|
|
|
|
{
|
2010-08-31 22:36:06 +02:00
|
|
|
|
GITypelib *typelib;
|
2015-01-31 23:48:56 +01:00
|
|
|
|
GHashTable *transitive_dependencies; /* set of owned utf8 */
|
|
|
|
|
GHashTableIter iter;
|
2024-01-15 20:20:47 +01:00
|
|
|
|
char *dependency;
|
2015-01-31 23:48:56 +01:00
|
|
|
|
GPtrArray *out; /* owned utf8 elements */
|
2008-08-30 22:31:07 +02:00
|
|
|
|
|
2024-01-26 11:44:09 +01:00
|
|
|
|
g_return_val_if_fail (GI_IS_REPOSITORY (repository), NULL);
|
2008-08-30 22:31:07 +02:00
|
|
|
|
g_return_val_if_fail (namespace != NULL, NULL);
|
|
|
|
|
|
2008-10-12 06:51:48 +02:00
|
|
|
|
typelib = get_registered (repository, namespace, NULL);
|
2008-08-30 22:31:07 +02:00
|
|
|
|
g_return_val_if_fail (typelib != NULL, NULL);
|
2015-11-21 08:01:21 +01:00
|
|
|
|
|
|
|
|
|
/* Load the dependencies. */
|
2019-01-31 22:44:13 +01:00
|
|
|
|
transitive_dependencies = g_hash_table_new_full (g_str_hash, g_str_equal,
|
|
|
|
|
g_free, NULL);
|
2015-01-31 23:48:56 +01:00
|
|
|
|
get_typelib_dependencies_transitive (repository, typelib,
|
|
|
|
|
transitive_dependencies);
|
2008-08-30 22:31:07 +02:00
|
|
|
|
|
2015-01-31 23:48:56 +01:00
|
|
|
|
/* Convert to a string array. */
|
2023-12-20 21:02:11 +01:00
|
|
|
|
out = g_ptr_array_new_null_terminated (g_hash_table_size (transitive_dependencies),
|
|
|
|
|
g_free, TRUE);
|
2015-01-31 23:48:56 +01:00
|
|
|
|
g_hash_table_iter_init (&iter, transitive_dependencies);
|
2015-01-31 23:22:16 +01:00
|
|
|
|
|
2015-01-31 23:48:56 +01:00
|
|
|
|
while (g_hash_table_iter_next (&iter, (gpointer) &dependency, NULL))
|
|
|
|
|
{
|
|
|
|
|
g_ptr_array_add (out, dependency);
|
|
|
|
|
g_hash_table_iter_steal (&iter);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-21 08:01:21 +01:00
|
|
|
|
g_hash_table_unref (transitive_dependencies);
|
|
|
|
|
|
2024-02-07 16:44:21 +01:00
|
|
|
|
if (n_dependencies_out != NULL)
|
|
|
|
|
*n_dependencies_out = out->len;
|
|
|
|
|
|
2024-01-15 20:20:47 +01:00
|
|
|
|
return (char **) g_ptr_array_free (out, FALSE);
|
2008-08-30 22:31:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-10 22:21:18 +02:00
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_repository_load_typelib:
|
2024-01-26 11:44:09 +01:00
|
|
|
|
* @repository: A #GIRepository
|
2024-02-07 15:38:05 +01:00
|
|
|
|
* @typelib: (transfer none): the typelib to load
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* @flags: flags affecting the loading operation
|
|
|
|
|
* @error: return location for a [type@GLib.Error], or `NULL`
|
2013-10-10 22:21:18 +02:00
|
|
|
|
*
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* Load the given @typelib into the repository.
|
|
|
|
|
*
|
|
|
|
|
* Returns: namespace of the loaded typelib
|
|
|
|
|
* Since: 2.80
|
2013-10-10 22:21:18 +02:00
|
|
|
|
*/
|
2008-08-30 22:31:07 +02:00
|
|
|
|
const char *
|
2024-01-16 02:34:02 +01:00
|
|
|
|
gi_repository_load_typelib (GIRepository *repository,
|
|
|
|
|
GITypelib *typelib,
|
|
|
|
|
GIRepositoryLoadFlags flags,
|
|
|
|
|
GError **error)
|
2008-08-21 05:06:13 +02:00
|
|
|
|
{
|
2008-08-30 22:31:07 +02:00
|
|
|
|
Header *header;
|
|
|
|
|
const char *namespace;
|
2008-10-12 06:51:48 +02:00
|
|
|
|
const char *nsversion;
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gboolean allow_lazy = flags & GI_REPOSITORY_LOAD_FLAG_LAZY;
|
2008-08-30 22:31:12 +02:00
|
|
|
|
gboolean is_lazy;
|
2008-10-12 06:51:48 +02:00
|
|
|
|
char *version_conflict;
|
2008-08-30 22:31:07 +02:00
|
|
|
|
|
2024-01-26 11:44:09 +01:00
|
|
|
|
g_return_val_if_fail (GI_IS_REPOSITORY (repository), NULL);
|
2008-08-30 22:31:07 +02:00
|
|
|
|
|
|
|
|
|
header = (Header *) typelib->data;
|
2023-11-08 15:17:52 +01:00
|
|
|
|
namespace = gi_typelib_get_string (typelib, header->namespace);
|
|
|
|
|
nsversion = gi_typelib_get_string (typelib, header->nsversion);
|
2008-08-30 22:31:07 +02:00
|
|
|
|
|
2010-03-24 19:00:06 +01:00
|
|
|
|
if (get_registered_status (repository, namespace, nsversion, allow_lazy,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
&is_lazy, &version_conflict))
|
2008-10-12 06:51:48 +02:00
|
|
|
|
{
|
|
|
|
|
if (version_conflict != NULL)
|
2024-01-16 17:30:37 +01:00
|
|
|
|
{
|
|
|
|
|
g_set_error (error, GI_REPOSITORY_ERROR,
|
|
|
|
|
GI_REPOSITORY_ERROR_NAMESPACE_VERSION_CONFLICT,
|
|
|
|
|
"Attempting to load namespace '%s', version '%s', but '%s' is already loaded",
|
|
|
|
|
namespace, nsversion, version_conflict);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2008-10-12 06:51:48 +02:00
|
|
|
|
return namespace;
|
|
|
|
|
}
|
2010-03-24 19:00:06 +01:00
|
|
|
|
return register_internal (repository, "<builtin>",
|
2024-01-16 17:30:37 +01:00
|
|
|
|
allow_lazy, typelib, error);
|
2008-02-08 16:31:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
2008-10-12 06:51:48 +02:00
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_repository_is_registered:
|
2024-01-26 11:44:09 +01:00
|
|
|
|
* @repository: A #GIRepository
|
2009-02-12 04:32:25 +01:00
|
|
|
|
* @namespace_: Namespace of interest
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* @version: (nullable): Required version, may be `NULL` for latest
|
2008-10-12 06:51:48 +02:00
|
|
|
|
*
|
|
|
|
|
* Check whether a particular namespace (and optionally, a specific
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* version thereof) is currently loaded.
|
2010-03-24 19:00:06 +01:00
|
|
|
|
*
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* This function is likely to only be useful in unusual circumstances; in order
|
|
|
|
|
* to act upon metadata in the namespace, you should call
|
|
|
|
|
* [method@GIRepository.Repository.require] instead which will ensure the
|
|
|
|
|
* namespace is loaded, and return as quickly as this function will if it has
|
|
|
|
|
* already been loaded.
|
|
|
|
|
*
|
|
|
|
|
* Returns: `TRUE` if namespace-version is loaded, `FALSE` otherwise
|
|
|
|
|
* Since: 2.80
|
2008-10-12 06:51:48 +02:00
|
|
|
|
*/
|
2008-02-08 16:31:03 +01:00
|
|
|
|
gboolean
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_repository_is_registered (GIRepository *repository,
|
2024-01-15 20:20:47 +01:00
|
|
|
|
const char *namespace,
|
|
|
|
|
const char *version)
|
2008-02-08 16:31:03 +01:00
|
|
|
|
{
|
2024-01-26 11:44:09 +01:00
|
|
|
|
g_return_val_if_fail (GI_IS_REPOSITORY (repository), FALSE);
|
2008-02-08 16:31:03 +01:00
|
|
|
|
|
2024-01-26 11:44:09 +01:00
|
|
|
|
return get_registered (repository, namespace, version) != NULL;
|
2008-02-08 16:31:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-24 00:22:55 +01:00
|
|
|
|
/**
|
|
|
|
|
* gi_repository_new:
|
|
|
|
|
*
|
2024-01-26 11:44:09 +01:00
|
|
|
|
* Create a new [class@GIRepository.Repository].
|
2023-11-24 00:22:55 +01:00
|
|
|
|
*
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* Returns: (transfer full): a new [class@GIRepository.Repository]
|
2023-11-24 00:22:55 +01:00
|
|
|
|
* Since: 2.80
|
|
|
|
|
*/
|
|
|
|
|
GIRepository *
|
|
|
|
|
gi_repository_new (void)
|
|
|
|
|
{
|
|
|
|
|
return g_object_new (GI_TYPE_REPOSITORY, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-12 06:51:48 +02:00
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_repository_get_n_infos:
|
2024-01-26 11:44:09 +01:00
|
|
|
|
* @repository: A #GIRepository
|
2009-02-12 04:32:25 +01:00
|
|
|
|
* @namespace_: Namespace to inspect
|
2008-10-12 06:51:48 +02:00
|
|
|
|
*
|
|
|
|
|
* This function returns the number of metadata entries in
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* given namespace @namespace_.
|
|
|
|
|
*
|
|
|
|
|
* The namespace must have already been loaded before calling this function.
|
2008-10-12 06:51:48 +02:00
|
|
|
|
*
|
|
|
|
|
* Returns: number of metadata entries
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* Since: 2.80
|
2008-10-12 06:51:48 +02:00
|
|
|
|
*/
|
2024-01-15 22:20:02 +01:00
|
|
|
|
unsigned int
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_repository_get_n_infos (GIRepository *repository,
|
2024-01-15 20:20:47 +01:00
|
|
|
|
const char *namespace)
|
2008-02-08 16:31:03 +01:00
|
|
|
|
{
|
2010-08-31 22:36:06 +02:00
|
|
|
|
GITypelib *typelib;
|
2024-01-15 22:20:02 +01:00
|
|
|
|
unsigned int n_interfaces = 0;
|
2008-08-30 22:31:07 +02:00
|
|
|
|
|
2024-01-26 11:44:09 +01:00
|
|
|
|
g_return_val_if_fail (GI_IS_REPOSITORY (repository), -1);
|
2008-10-12 06:51:48 +02:00
|
|
|
|
g_return_val_if_fail (namespace != NULL, -1);
|
|
|
|
|
|
|
|
|
|
typelib = get_registered (repository, namespace, NULL);
|
2008-02-08 16:31:03 +01:00
|
|
|
|
|
2008-10-12 06:51:48 +02:00
|
|
|
|
g_return_val_if_fail (typelib != NULL, -1);
|
2008-02-08 16:31:03 +01:00
|
|
|
|
|
2008-10-12 06:51:48 +02:00
|
|
|
|
n_interfaces = ((Header *)typelib->data)->n_local_entries;
|
2008-02-08 16:31:03 +01:00
|
|
|
|
|
|
|
|
|
return n_interfaces;
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-12 06:51:48 +02:00
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_repository_get_info:
|
2024-01-26 11:44:09 +01:00
|
|
|
|
* @repository: A #GIRepository
|
2009-02-12 04:32:25 +01:00
|
|
|
|
* @namespace_: Namespace to inspect
|
2023-12-12 19:12:17 +01:00
|
|
|
|
* @idx: 0-based offset into namespace metadata for entry
|
2008-10-12 06:51:48 +02:00
|
|
|
|
*
|
|
|
|
|
* This function returns a particular metadata entry in the
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* given namespace @namespace_.
|
2008-10-12 06:51:48 +02:00
|
|
|
|
*
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* The namespace must have already been loaded before calling this function.
|
|
|
|
|
* See [method@GIRepository.Repository.get_n_infos] to find the maximum number
|
2024-01-05 13:05:26 +01:00
|
|
|
|
* of entries. It is an error to pass an invalid @idx to this function.
|
2023-12-13 14:24:40 +01:00
|
|
|
|
*
|
2024-01-05 13:05:26 +01:00
|
|
|
|
* Returns: (transfer full) (not nullable): [class@GIRepository.BaseInfo]
|
|
|
|
|
* containing metadata
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* Since: 2.80
|
2008-10-12 06:51:48 +02:00
|
|
|
|
*/
|
2010-03-24 19:00:06 +01:00
|
|
|
|
GIBaseInfo *
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_repository_get_info (GIRepository *repository,
|
2024-01-15 20:20:47 +01:00
|
|
|
|
const char *namespace,
|
2024-01-15 22:20:02 +01:00
|
|
|
|
unsigned int idx)
|
2008-02-08 16:31:03 +01:00
|
|
|
|
{
|
2010-08-31 22:36:06 +02:00
|
|
|
|
GITypelib *typelib;
|
2010-10-18 18:04:08 +02:00
|
|
|
|
DirEntry *entry;
|
2008-10-12 06:51:48 +02:00
|
|
|
|
|
2024-01-26 11:44:09 +01:00
|
|
|
|
g_return_val_if_fail (GI_IS_REPOSITORY (repository), NULL);
|
2008-10-12 06:51:48 +02:00
|
|
|
|
g_return_val_if_fail (namespace != NULL, NULL);
|
2024-01-16 01:40:09 +01:00
|
|
|
|
g_return_val_if_fail (idx < G_MAXUINT16, NULL);
|
2008-02-08 16:31:03 +01:00
|
|
|
|
|
2008-10-12 06:51:48 +02:00
|
|
|
|
typelib = get_registered (repository, namespace, NULL);
|
2010-03-24 19:00:06 +01:00
|
|
|
|
|
2008-10-12 06:51:48 +02:00
|
|
|
|
g_return_val_if_fail (typelib != NULL, NULL);
|
|
|
|
|
|
2023-12-12 19:12:17 +01:00
|
|
|
|
entry = gi_typelib_get_dir_entry (typelib, idx + 1);
|
2024-01-05 13:05:26 +01:00
|
|
|
|
g_return_val_if_fail (entry != NULL, NULL);
|
|
|
|
|
|
2024-02-08 12:40:10 +01:00
|
|
|
|
return gi_info_new_full (gi_typelib_blob_type_to_info_type (entry->blob_type),
|
2023-11-08 16:23:31 +01:00
|
|
|
|
repository,
|
|
|
|
|
NULL, typelib, entry->offset);
|
2010-10-18 18:04:08 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2024-01-15 20:20:47 +01:00
|
|
|
|
const char *gtype_name;
|
2010-10-18 18:04:08 +02:00
|
|
|
|
GITypelib *result_typelib;
|
|
|
|
|
} FindByGTypeData;
|
2008-02-08 16:31:03 +01:00
|
|
|
|
|
Optimize g_irepository_find_by_gtype
When g_irepository_find_by_gtype() doesn't succeed on a simple prefix
match (the current 'fastpass' mechanism), it ends up taking a
considerable amount of CPU time, traversing the contents of all typelibs.
I imagine that the reasons to have the exhaustive search fallback are
not as strong as they used to be. For example, the case mentioned
(Clutter including Cogl) no longer seems to be true.
Also, typelibs (as generated by g-ir-scanner) now provide
comma-separated C prefix info for cases when the typelib includes
introspection info for multiple prefixes. For example, the Sugar typelib
has a c_prefix string of Sugar,EggSM,Gsm,Acme. So I imagine there are
not many remaining justified cases where the exhaustive search is needed.
With that in mind, I found two ways to optimize this function:
1. Support comma-separated C prefixes
2. Don't bother with an exhaustive search if we did find a typelib
claiming support for the prefix. For example, if we're looking for
GdkDeviceManagerXI2 (currently non-introspectable) and we already found
typelib files providing the 'Gdk' prefix that didn't offer this, lets
not bother with the exhaustive search, we aren't going to find anything.
2013-03-19 18:04:42 +01:00
|
|
|
|
static DirEntry *
|
|
|
|
|
find_by_gtype (GHashTable *table, FindByGTypeData *data, gboolean check_prefix)
|
2010-10-18 18:04:08 +02:00
|
|
|
|
{
|
Optimize g_irepository_find_by_gtype
When g_irepository_find_by_gtype() doesn't succeed on a simple prefix
match (the current 'fastpass' mechanism), it ends up taking a
considerable amount of CPU time, traversing the contents of all typelibs.
I imagine that the reasons to have the exhaustive search fallback are
not as strong as they used to be. For example, the case mentioned
(Clutter including Cogl) no longer seems to be true.
Also, typelibs (as generated by g-ir-scanner) now provide
comma-separated C prefix info for cases when the typelib includes
introspection info for multiple prefixes. For example, the Sugar typelib
has a c_prefix string of Sugar,EggSM,Gsm,Acme. So I imagine there are
not many remaining justified cases where the exhaustive search is needed.
With that in mind, I found two ways to optimize this function:
1. Support comma-separated C prefixes
2. Don't bother with an exhaustive search if we did find a typelib
claiming support for the prefix. For example, if we're looking for
GdkDeviceManagerXI2 (currently non-introspectable) and we already found
typelib files providing the 'Gdk' prefix that didn't offer this, lets
not bother with the exhaustive search, we aren't going to find anything.
2013-03-19 18:04:42 +01:00
|
|
|
|
GHashTableIter iter;
|
|
|
|
|
gpointer key, value;
|
|
|
|
|
DirEntry *ret;
|
2010-10-18 18:04:08 +02:00
|
|
|
|
|
Optimize g_irepository_find_by_gtype
When g_irepository_find_by_gtype() doesn't succeed on a simple prefix
match (the current 'fastpass' mechanism), it ends up taking a
considerable amount of CPU time, traversing the contents of all typelibs.
I imagine that the reasons to have the exhaustive search fallback are
not as strong as they used to be. For example, the case mentioned
(Clutter including Cogl) no longer seems to be true.
Also, typelibs (as generated by g-ir-scanner) now provide
comma-separated C prefix info for cases when the typelib includes
introspection info for multiple prefixes. For example, the Sugar typelib
has a c_prefix string of Sugar,EggSM,Gsm,Acme. So I imagine there are
not many remaining justified cases where the exhaustive search is needed.
With that in mind, I found two ways to optimize this function:
1. Support comma-separated C prefixes
2. Don't bother with an exhaustive search if we did find a typelib
claiming support for the prefix. For example, if we're looking for
GdkDeviceManagerXI2 (currently non-introspectable) and we already found
typelib files providing the 'Gdk' prefix that didn't offer this, lets
not bother with the exhaustive search, we aren't going to find anything.
2013-03-19 18:04:42 +01:00
|
|
|
|
g_hash_table_iter_init (&iter, table);
|
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value))
|
|
|
|
|
{
|
|
|
|
|
GITypelib *typelib = (GITypelib*)value;
|
|
|
|
|
if (check_prefix)
|
|
|
|
|
{
|
2023-11-08 15:17:52 +01:00
|
|
|
|
if (!gi_typelib_matches_gtype_name_prefix (typelib, data->gtype_name))
|
Optimize g_irepository_find_by_gtype
When g_irepository_find_by_gtype() doesn't succeed on a simple prefix
match (the current 'fastpass' mechanism), it ends up taking a
considerable amount of CPU time, traversing the contents of all typelibs.
I imagine that the reasons to have the exhaustive search fallback are
not as strong as they used to be. For example, the case mentioned
(Clutter including Cogl) no longer seems to be true.
Also, typelibs (as generated by g-ir-scanner) now provide
comma-separated C prefix info for cases when the typelib includes
introspection info for multiple prefixes. For example, the Sugar typelib
has a c_prefix string of Sugar,EggSM,Gsm,Acme. So I imagine there are
not many remaining justified cases where the exhaustive search is needed.
With that in mind, I found two ways to optimize this function:
1. Support comma-separated C prefixes
2. Don't bother with an exhaustive search if we did find a typelib
claiming support for the prefix. For example, if we're looking for
GdkDeviceManagerXI2 (currently non-introspectable) and we already found
typelib files providing the 'Gdk' prefix that didn't offer this, lets
not bother with the exhaustive search, we aren't going to find anything.
2013-03-19 18:04:42 +01:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-08 15:17:52 +01:00
|
|
|
|
ret = gi_typelib_get_dir_entry_by_gtype_name (typelib, data->gtype_name);
|
Optimize g_irepository_find_by_gtype
When g_irepository_find_by_gtype() doesn't succeed on a simple prefix
match (the current 'fastpass' mechanism), it ends up taking a
considerable amount of CPU time, traversing the contents of all typelibs.
I imagine that the reasons to have the exhaustive search fallback are
not as strong as they used to be. For example, the case mentioned
(Clutter including Cogl) no longer seems to be true.
Also, typelibs (as generated by g-ir-scanner) now provide
comma-separated C prefix info for cases when the typelib includes
introspection info for multiple prefixes. For example, the Sugar typelib
has a c_prefix string of Sugar,EggSM,Gsm,Acme. So I imagine there are
not many remaining justified cases where the exhaustive search is needed.
With that in mind, I found two ways to optimize this function:
1. Support comma-separated C prefixes
2. Don't bother with an exhaustive search if we did find a typelib
claiming support for the prefix. For example, if we're looking for
GdkDeviceManagerXI2 (currently non-introspectable) and we already found
typelib files providing the 'Gdk' prefix that didn't offer this, lets
not bother with the exhaustive search, we aren't going to find anything.
2013-03-19 18:04:42 +01:00
|
|
|
|
if (ret)
|
|
|
|
|
{
|
|
|
|
|
data->result_typelib = typelib;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
2008-02-08 16:31:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
2008-10-12 06:51:48 +02:00
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_repository_find_by_gtype:
|
2024-01-26 11:44:09 +01:00
|
|
|
|
* @repository: A #GIRepository
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* @gtype: [type@GObject.Type] to search for
|
|
|
|
|
*
|
|
|
|
|
* Searches all loaded namespaces for a particular [type@GObject.Type].
|
2008-10-12 06:51:48 +02:00
|
|
|
|
*
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* Note that in order to locate the metadata, the namespace corresponding to
|
2008-10-12 06:51:48 +02:00
|
|
|
|
* the type must first have been loaded. There is currently no
|
|
|
|
|
* mechanism for determining the namespace which corresponds to an
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* arbitrary [type@GObject.Type] — thus, this function will operate most
|
|
|
|
|
* reliably when you know the [type@GObject.Type] is from a loaded namespace.
|
2008-10-12 06:51:48 +02:00
|
|
|
|
*
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* Returns: (transfer full) (nullable): [class@GIRepository.BaseInfo]
|
|
|
|
|
* representing metadata about @type, or `NULL` if none found
|
|
|
|
|
* Since: 2.80
|
2008-10-12 06:51:48 +02:00
|
|
|
|
*/
|
2010-03-24 19:00:06 +01:00
|
|
|
|
GIBaseInfo *
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_repository_find_by_gtype (GIRepository *repository,
|
2022-01-12 00:01:08 +01:00
|
|
|
|
GType gtype)
|
2008-02-08 16:31:03 +01:00
|
|
|
|
{
|
2010-10-18 18:04:08 +02:00
|
|
|
|
FindByGTypeData data;
|
|
|
|
|
GIBaseInfo *cached;
|
Optimize g_irepository_find_by_gtype
When g_irepository_find_by_gtype() doesn't succeed on a simple prefix
match (the current 'fastpass' mechanism), it ends up taking a
considerable amount of CPU time, traversing the contents of all typelibs.
I imagine that the reasons to have the exhaustive search fallback are
not as strong as they used to be. For example, the case mentioned
(Clutter including Cogl) no longer seems to be true.
Also, typelibs (as generated by g-ir-scanner) now provide
comma-separated C prefix info for cases when the typelib includes
introspection info for multiple prefixes. For example, the Sugar typelib
has a c_prefix string of Sugar,EggSM,Gsm,Acme. So I imagine there are
not many remaining justified cases where the exhaustive search is needed.
With that in mind, I found two ways to optimize this function:
1. Support comma-separated C prefixes
2. Don't bother with an exhaustive search if we did find a typelib
claiming support for the prefix. For example, if we're looking for
GdkDeviceManagerXI2 (currently non-introspectable) and we already found
typelib files providing the 'Gdk' prefix that didn't offer this, lets
not bother with the exhaustive search, we aren't going to find anything.
2013-03-19 18:04:42 +01:00
|
|
|
|
DirEntry *entry;
|
2008-02-08 16:31:03 +01:00
|
|
|
|
|
2024-01-26 11:44:09 +01:00
|
|
|
|
g_return_val_if_fail (GI_IS_REPOSITORY (repository), NULL);
|
2022-01-12 00:01:08 +01:00
|
|
|
|
g_return_val_if_fail (gtype != G_TYPE_INVALID, NULL);
|
|
|
|
|
|
2024-01-26 00:09:16 +01:00
|
|
|
|
cached = g_hash_table_lookup (repository->info_by_gtype,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
(gpointer)gtype);
|
2008-12-10 18:53:09 +01:00
|
|
|
|
|
2010-10-18 18:04:08 +02:00
|
|
|
|
if (cached != NULL)
|
2023-11-08 15:17:52 +01:00
|
|
|
|
return gi_base_info_ref (cached);
|
2008-12-10 18:53:09 +01:00
|
|
|
|
|
2024-01-26 00:09:16 +01:00
|
|
|
|
if (g_hash_table_contains (repository->unknown_gtypes, (gpointer)gtype))
|
2019-11-13 19:37:00 +01:00
|
|
|
|
return NULL;
|
|
|
|
|
|
Optimize g_irepository_find_by_gtype
When g_irepository_find_by_gtype() doesn't succeed on a simple prefix
match (the current 'fastpass' mechanism), it ends up taking a
considerable amount of CPU time, traversing the contents of all typelibs.
I imagine that the reasons to have the exhaustive search fallback are
not as strong as they used to be. For example, the case mentioned
(Clutter including Cogl) no longer seems to be true.
Also, typelibs (as generated by g-ir-scanner) now provide
comma-separated C prefix info for cases when the typelib includes
introspection info for multiple prefixes. For example, the Sugar typelib
has a c_prefix string of Sugar,EggSM,Gsm,Acme. So I imagine there are
not many remaining justified cases where the exhaustive search is needed.
With that in mind, I found two ways to optimize this function:
1. Support comma-separated C prefixes
2. Don't bother with an exhaustive search if we did find a typelib
claiming support for the prefix. For example, if we're looking for
GdkDeviceManagerXI2 (currently non-introspectable) and we already found
typelib files providing the 'Gdk' prefix that didn't offer this, lets
not bother with the exhaustive search, we aren't going to find anything.
2013-03-19 18:04:42 +01:00
|
|
|
|
data.gtype_name = g_type_name (gtype);
|
2010-10-18 18:04:08 +02:00
|
|
|
|
data.result_typelib = NULL;
|
Optimize g_irepository_find_by_gtype
When g_irepository_find_by_gtype() doesn't succeed on a simple prefix
match (the current 'fastpass' mechanism), it ends up taking a
considerable amount of CPU time, traversing the contents of all typelibs.
I imagine that the reasons to have the exhaustive search fallback are
not as strong as they used to be. For example, the case mentioned
(Clutter including Cogl) no longer seems to be true.
Also, typelibs (as generated by g-ir-scanner) now provide
comma-separated C prefix info for cases when the typelib includes
introspection info for multiple prefixes. For example, the Sugar typelib
has a c_prefix string of Sugar,EggSM,Gsm,Acme. So I imagine there are
not many remaining justified cases where the exhaustive search is needed.
With that in mind, I found two ways to optimize this function:
1. Support comma-separated C prefixes
2. Don't bother with an exhaustive search if we did find a typelib
claiming support for the prefix. For example, if we're looking for
GdkDeviceManagerXI2 (currently non-introspectable) and we already found
typelib files providing the 'Gdk' prefix that didn't offer this, lets
not bother with the exhaustive search, we aren't going to find anything.
2013-03-19 18:04:42 +01:00
|
|
|
|
|
|
|
|
|
/* Inside each typelib, we include the "C prefix" which acts as
|
|
|
|
|
* a namespace mechanism. For GtkTreeView, the C prefix is Gtk.
|
|
|
|
|
* Given the assumption that GTypes for a library also use the
|
|
|
|
|
* C prefix, we know we can skip examining a typelib if our
|
|
|
|
|
* target type does not have this typelib's C prefix. Use this
|
|
|
|
|
* assumption as our first attempt at locating the DirEntry.
|
|
|
|
|
*/
|
2024-01-26 00:09:16 +01:00
|
|
|
|
entry = find_by_gtype (repository->typelibs, &data, TRUE);
|
Optimize g_irepository_find_by_gtype
When g_irepository_find_by_gtype() doesn't succeed on a simple prefix
match (the current 'fastpass' mechanism), it ends up taking a
considerable amount of CPU time, traversing the contents of all typelibs.
I imagine that the reasons to have the exhaustive search fallback are
not as strong as they used to be. For example, the case mentioned
(Clutter including Cogl) no longer seems to be true.
Also, typelibs (as generated by g-ir-scanner) now provide
comma-separated C prefix info for cases when the typelib includes
introspection info for multiple prefixes. For example, the Sugar typelib
has a c_prefix string of Sugar,EggSM,Gsm,Acme. So I imagine there are
not many remaining justified cases where the exhaustive search is needed.
With that in mind, I found two ways to optimize this function:
1. Support comma-separated C prefixes
2. Don't bother with an exhaustive search if we did find a typelib
claiming support for the prefix. For example, if we're looking for
GdkDeviceManagerXI2 (currently non-introspectable) and we already found
typelib files providing the 'Gdk' prefix that didn't offer this, lets
not bother with the exhaustive search, we aren't going to find anything.
2013-03-19 18:04:42 +01:00
|
|
|
|
if (entry == NULL)
|
2024-01-26 00:09:16 +01:00
|
|
|
|
entry = find_by_gtype (repository->lazy_typelibs, &data, TRUE);
|
2008-02-08 16:31:03 +01:00
|
|
|
|
|
Optimize g_irepository_find_by_gtype
When g_irepository_find_by_gtype() doesn't succeed on a simple prefix
match (the current 'fastpass' mechanism), it ends up taking a
considerable amount of CPU time, traversing the contents of all typelibs.
I imagine that the reasons to have the exhaustive search fallback are
not as strong as they used to be. For example, the case mentioned
(Clutter including Cogl) no longer seems to be true.
Also, typelibs (as generated by g-ir-scanner) now provide
comma-separated C prefix info for cases when the typelib includes
introspection info for multiple prefixes. For example, the Sugar typelib
has a c_prefix string of Sugar,EggSM,Gsm,Acme. So I imagine there are
not many remaining justified cases where the exhaustive search is needed.
With that in mind, I found two ways to optimize this function:
1. Support comma-separated C prefixes
2. Don't bother with an exhaustive search if we did find a typelib
claiming support for the prefix. For example, if we're looking for
GdkDeviceManagerXI2 (currently non-introspectable) and we already found
typelib files providing the 'Gdk' prefix that didn't offer this, lets
not bother with the exhaustive search, we aren't going to find anything.
2013-03-19 18:04:42 +01:00
|
|
|
|
/* Not ever class library necessarily specifies a correct c_prefix,
|
|
|
|
|
* so take a second pass. This time we will try a global lookup,
|
|
|
|
|
* ignoring prefixes.
|
|
|
|
|
* See http://bugzilla.gnome.org/show_bug.cgi?id=564016
|
|
|
|
|
*/
|
|
|
|
|
if (entry == NULL)
|
2024-01-26 00:09:16 +01:00
|
|
|
|
entry = find_by_gtype (repository->typelibs, &data, FALSE);
|
Optimize g_irepository_find_by_gtype
When g_irepository_find_by_gtype() doesn't succeed on a simple prefix
match (the current 'fastpass' mechanism), it ends up taking a
considerable amount of CPU time, traversing the contents of all typelibs.
I imagine that the reasons to have the exhaustive search fallback are
not as strong as they used to be. For example, the case mentioned
(Clutter including Cogl) no longer seems to be true.
Also, typelibs (as generated by g-ir-scanner) now provide
comma-separated C prefix info for cases when the typelib includes
introspection info for multiple prefixes. For example, the Sugar typelib
has a c_prefix string of Sugar,EggSM,Gsm,Acme. So I imagine there are
not many remaining justified cases where the exhaustive search is needed.
With that in mind, I found two ways to optimize this function:
1. Support comma-separated C prefixes
2. Don't bother with an exhaustive search if we did find a typelib
claiming support for the prefix. For example, if we're looking for
GdkDeviceManagerXI2 (currently non-introspectable) and we already found
typelib files providing the 'Gdk' prefix that didn't offer this, lets
not bother with the exhaustive search, we aren't going to find anything.
2013-03-19 18:04:42 +01:00
|
|
|
|
if (entry == NULL)
|
2024-01-26 00:09:16 +01:00
|
|
|
|
entry = find_by_gtype (repository->lazy_typelibs, &data, FALSE);
|
2009-02-13 00:42:47 +01:00
|
|
|
|
|
Optimize g_irepository_find_by_gtype
When g_irepository_find_by_gtype() doesn't succeed on a simple prefix
match (the current 'fastpass' mechanism), it ends up taking a
considerable amount of CPU time, traversing the contents of all typelibs.
I imagine that the reasons to have the exhaustive search fallback are
not as strong as they used to be. For example, the case mentioned
(Clutter including Cogl) no longer seems to be true.
Also, typelibs (as generated by g-ir-scanner) now provide
comma-separated C prefix info for cases when the typelib includes
introspection info for multiple prefixes. For example, the Sugar typelib
has a c_prefix string of Sugar,EggSM,Gsm,Acme. So I imagine there are
not many remaining justified cases where the exhaustive search is needed.
With that in mind, I found two ways to optimize this function:
1. Support comma-separated C prefixes
2. Don't bother with an exhaustive search if we did find a typelib
claiming support for the prefix. For example, if we're looking for
GdkDeviceManagerXI2 (currently non-introspectable) and we already found
typelib files providing the 'Gdk' prefix that didn't offer this, lets
not bother with the exhaustive search, we aren't going to find anything.
2013-03-19 18:04:42 +01:00
|
|
|
|
if (entry != NULL)
|
2010-10-18 18:04:08 +02:00
|
|
|
|
{
|
2024-02-08 12:40:10 +01:00
|
|
|
|
cached = gi_info_new_full (gi_typelib_blob_type_to_info_type (entry->blob_type),
|
2023-11-08 16:23:31 +01:00
|
|
|
|
repository,
|
|
|
|
|
NULL, data.result_typelib, entry->offset);
|
2010-10-18 18:04:08 +02:00
|
|
|
|
|
2024-01-26 00:09:16 +01:00
|
|
|
|
g_hash_table_insert (repository->info_by_gtype,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
(gpointer) gtype,
|
|
|
|
|
gi_base_info_ref (cached));
|
2010-10-18 18:04:08 +02:00
|
|
|
|
return cached;
|
|
|
|
|
}
|
2019-11-13 19:37:00 +01:00
|
|
|
|
else
|
|
|
|
|
{
|
2024-01-26 00:09:16 +01:00
|
|
|
|
g_hash_table_add (repository->unknown_gtypes, (gpointer) gtype);
|
2019-11-13 19:37:00 +01:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2008-02-08 16:31:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
2008-08-21 01:56:40 +02:00
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_repository_find_by_name:
|
2024-01-26 11:44:09 +01:00
|
|
|
|
* @repository: A #GIRepository
|
2009-02-12 04:32:25 +01:00
|
|
|
|
* @namespace_: Namespace which will be searched
|
2008-10-12 06:51:48 +02:00
|
|
|
|
* @name: Entry name to find
|
|
|
|
|
*
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* Searches for a particular entry in a namespace.
|
|
|
|
|
*
|
|
|
|
|
* Before calling this function for a particular namespace, you must call
|
|
|
|
|
* [method@GIRepository.Repository.require] to load the namespace, or otherwise
|
2008-10-12 06:51:48 +02:00
|
|
|
|
* ensure the namespace has already been loaded.
|
2008-08-21 01:56:40 +02:00
|
|
|
|
*
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* Returns: (transfer full) (nullable): [class@GIRepository.BaseInfo]
|
|
|
|
|
* representing metadata about @name, or `NULL` if none found
|
|
|
|
|
* Since: 2.80
|
2008-08-21 01:56:40 +02:00
|
|
|
|
*/
|
2010-03-24 19:00:06 +01:00
|
|
|
|
GIBaseInfo *
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_repository_find_by_name (GIRepository *repository,
|
2024-01-15 20:20:47 +01:00
|
|
|
|
const char *namespace,
|
|
|
|
|
const char *name)
|
2008-02-08 16:31:03 +01:00
|
|
|
|
{
|
2010-08-31 22:36:06 +02:00
|
|
|
|
GITypelib *typelib;
|
2010-10-18 18:04:08 +02:00
|
|
|
|
DirEntry *entry;
|
2008-10-12 06:51:48 +02:00
|
|
|
|
|
2024-01-26 11:44:09 +01:00
|
|
|
|
g_return_val_if_fail (GI_IS_REPOSITORY (repository), NULL);
|
2008-10-12 06:51:48 +02:00
|
|
|
|
g_return_val_if_fail (namespace != NULL, NULL);
|
2008-02-08 16:31:03 +01:00
|
|
|
|
|
2008-10-12 06:51:48 +02:00
|
|
|
|
typelib = get_registered (repository, namespace, NULL);
|
|
|
|
|
g_return_val_if_fail (typelib != NULL, NULL);
|
|
|
|
|
|
2023-11-08 15:17:52 +01:00
|
|
|
|
entry = gi_typelib_get_dir_entry_by_name (typelib, name);
|
2010-10-18 18:04:08 +02:00
|
|
|
|
if (entry == NULL)
|
|
|
|
|
return NULL;
|
2024-02-08 12:40:10 +01:00
|
|
|
|
return gi_info_new_full (gi_typelib_blob_type_to_info_type (entry->blob_type),
|
2023-11-08 16:23:31 +01:00
|
|
|
|
repository,
|
|
|
|
|
NULL, typelib, entry->offset);
|
2008-02-08 16:31:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-19 23:46:36 +02:00
|
|
|
|
typedef struct {
|
|
|
|
|
GIRepository *repository;
|
|
|
|
|
GQuark domain;
|
|
|
|
|
|
|
|
|
|
GITypelib *result_typelib;
|
|
|
|
|
DirEntry *result;
|
|
|
|
|
} FindByErrorDomainData;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
find_by_error_domain_foreach (gpointer key,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
gpointer value,
|
|
|
|
|
gpointer datap)
|
2011-05-19 23:46:36 +02:00
|
|
|
|
{
|
|
|
|
|
GITypelib *typelib = (GITypelib*)value;
|
|
|
|
|
FindByErrorDomainData *data = datap;
|
|
|
|
|
|
|
|
|
|
if (data->result != NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-11-08 15:17:52 +01:00
|
|
|
|
data->result = gi_typelib_get_dir_entry_by_error_domain (typelib, data->domain);
|
2011-05-19 23:46:36 +02:00
|
|
|
|
if (data->result)
|
|
|
|
|
data->result_typelib = typelib;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_repository_find_by_error_domain:
|
2024-01-26 11:44:09 +01:00
|
|
|
|
* @repository: A #GIRepository
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* @domain: a [type@GLib.Error] domain
|
|
|
|
|
*
|
|
|
|
|
* Searches for the enum type corresponding to the given [type@GLib.Error]
|
|
|
|
|
* domain.
|
2011-05-19 23:46:36 +02:00
|
|
|
|
*
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* Before calling this function for a particular namespace, you must call
|
|
|
|
|
* [method@GIRepository.Repository.require] to load the namespace, or otherwise
|
|
|
|
|
* ensure the namespace has already been loaded.
|
2011-05-19 23:46:36 +02:00
|
|
|
|
*
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* Returns: (transfer full) (nullable): [class@GIRepository.EnumInfo]
|
|
|
|
|
* representing metadata about @domain’s enum type, or `NULL` if none found
|
2023-11-09 00:24:11 +01:00
|
|
|
|
* Since: 2.80
|
2011-05-19 23:46:36 +02:00
|
|
|
|
*/
|
|
|
|
|
GIEnumInfo *
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_repository_find_by_error_domain (GIRepository *repository,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
GQuark domain)
|
2011-05-19 23:46:36 +02:00
|
|
|
|
{
|
|
|
|
|
FindByErrorDomainData data;
|
|
|
|
|
GIEnumInfo *cached;
|
|
|
|
|
|
2024-01-26 11:44:09 +01:00
|
|
|
|
g_return_val_if_fail (GI_IS_REPOSITORY (repository), NULL);
|
2011-05-19 23:46:36 +02:00
|
|
|
|
|
2024-01-26 00:09:16 +01:00
|
|
|
|
cached = g_hash_table_lookup (repository->info_by_error_domain,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
GUINT_TO_POINTER (domain));
|
2011-05-19 23:46:36 +02:00
|
|
|
|
|
|
|
|
|
if (cached != NULL)
|
2023-11-28 18:14:30 +01:00
|
|
|
|
return (GIEnumInfo *) gi_base_info_ref ((GIBaseInfo *)cached);
|
2011-05-19 23:46:36 +02:00
|
|
|
|
|
|
|
|
|
data.repository = repository;
|
|
|
|
|
data.domain = domain;
|
|
|
|
|
data.result_typelib = NULL;
|
|
|
|
|
data.result = NULL;
|
|
|
|
|
|
2024-01-26 00:09:16 +01:00
|
|
|
|
g_hash_table_foreach (repository->typelibs, find_by_error_domain_foreach, &data);
|
2011-05-19 23:46:36 +02:00
|
|
|
|
if (data.result == NULL)
|
2024-01-26 00:09:16 +01:00
|
|
|
|
g_hash_table_foreach (repository->lazy_typelibs, find_by_error_domain_foreach, &data);
|
2011-05-19 23:46:36 +02:00
|
|
|
|
|
|
|
|
|
if (data.result != NULL)
|
|
|
|
|
{
|
2024-02-08 12:40:10 +01:00
|
|
|
|
cached = (GIEnumInfo *) gi_info_new_full (gi_typelib_blob_type_to_info_type (data.result->blob_type),
|
2023-11-28 18:14:30 +01:00
|
|
|
|
repository,
|
|
|
|
|
NULL, data.result_typelib, data.result->offset);
|
2011-05-19 23:46:36 +02:00
|
|
|
|
|
2024-01-26 00:09:16 +01:00
|
|
|
|
g_hash_table_insert (repository->info_by_error_domain,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
GUINT_TO_POINTER (domain),
|
|
|
|
|
gi_base_info_ref ((GIBaseInfo *) cached));
|
2011-05-19 23:46:36 +02:00
|
|
|
|
return cached;
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-23 00:08:15 +02:00
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_repository_get_object_gtype_interfaces:
|
2024-01-26 11:44:09 +01:00
|
|
|
|
* @repository: a #GIRepository
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* @gtype: a [type@GObject.Type] whose fundamental type is `G_TYPE_OBJECT`
|
2019-01-16 21:04:26 +01:00
|
|
|
|
* @n_interfaces_out: (out): Number of interfaces
|
|
|
|
|
* @interfaces_out: (out) (transfer none) (array length=n_interfaces_out): Interfaces for @gtype
|
2010-10-23 00:08:15 +02:00
|
|
|
|
*
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* Look up the implemented interfaces for @gtype.
|
|
|
|
|
*
|
|
|
|
|
* This function cannot fail per se; but for a totally ‘unknown’
|
|
|
|
|
* [type@GObject.Type], it may return 0 implemented interfaces.
|
2010-10-23 00:08:15 +02:00
|
|
|
|
*
|
|
|
|
|
* The semantics of this function are designed for a dynamic binding,
|
|
|
|
|
* where in certain cases (such as a function which returns an
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* interface which may have ‘hidden’ implementation classes), not all
|
2010-10-23 00:08:15 +02:00
|
|
|
|
* data may be statically known, and will have to be determined from
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* the [type@GObject.Type] of the object. An example is
|
|
|
|
|
* [func@Gio.File.new_for_path] returning a concrete class of
|
|
|
|
|
* `GLocalFile`, which is a [type@GObject.Type] we see at runtime, but
|
|
|
|
|
* not statically.
|
2010-10-23 00:08:15 +02:00
|
|
|
|
*
|
2023-11-09 00:24:11 +01:00
|
|
|
|
* Since: 2.80
|
2010-10-23 00:08:15 +02:00
|
|
|
|
*/
|
|
|
|
|
void
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_repository_get_object_gtype_interfaces (GIRepository *repository,
|
2010-10-23 00:08:15 +02:00
|
|
|
|
GType gtype,
|
2024-01-16 00:35:23 +01:00
|
|
|
|
size_t *n_interfaces_out,
|
2019-06-20 09:18:13 +02:00
|
|
|
|
GIInterfaceInfo ***interfaces_out)
|
2010-10-23 00:08:15 +02:00
|
|
|
|
{
|
|
|
|
|
GTypeInterfaceCache *cache;
|
|
|
|
|
|
2024-01-26 11:44:09 +01:00
|
|
|
|
g_return_if_fail (GI_IS_REPOSITORY (repository));
|
2010-10-23 00:08:15 +02:00
|
|
|
|
g_return_if_fail (g_type_fundamental (gtype) == G_TYPE_OBJECT);
|
|
|
|
|
|
2024-01-26 00:09:16 +01:00
|
|
|
|
cache = g_hash_table_lookup (repository->interfaces_for_gtype,
|
2024-01-15 20:16:00 +01:00
|
|
|
|
(void *) gtype);
|
2010-10-23 00:08:15 +02:00
|
|
|
|
if (cache == NULL)
|
|
|
|
|
{
|
|
|
|
|
GType *interfaces;
|
2024-01-15 22:20:02 +01:00
|
|
|
|
unsigned int i;
|
|
|
|
|
unsigned int n_interfaces;
|
2010-10-23 00:08:15 +02:00
|
|
|
|
GList *interface_infos = NULL, *iter;
|
|
|
|
|
|
|
|
|
|
interfaces = g_type_interfaces (gtype, &n_interfaces);
|
|
|
|
|
for (i = 0; i < n_interfaces; i++)
|
|
|
|
|
{
|
|
|
|
|
GIBaseInfo *base_info;
|
|
|
|
|
|
2023-11-08 15:17:52 +01:00
|
|
|
|
base_info = gi_repository_find_by_gtype (repository, interfaces[i]);
|
2010-10-23 00:08:15 +02:00
|
|
|
|
if (base_info == NULL)
|
|
|
|
|
continue;
|
|
|
|
|
|
2023-12-12 17:16:30 +01:00
|
|
|
|
if (gi_base_info_get_info_type (base_info) != GI_INFO_TYPE_INTERFACE)
|
2010-10-23 00:08:15 +02:00
|
|
|
|
{
|
|
|
|
|
/* FIXME - could this really happen? */
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_base_info_unref (base_info);
|
2010-10-23 00:08:15 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!g_list_find (interface_infos, base_info))
|
|
|
|
|
interface_infos = g_list_prepend (interface_infos, base_info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cache = g_malloc (sizeof (GTypeInterfaceCache)
|
|
|
|
|
+ sizeof (GIBaseInfo*) * g_list_length (interface_infos));
|
|
|
|
|
cache->n_interfaces = g_list_length (interface_infos);
|
|
|
|
|
for (iter = interface_infos, i = 0; iter; iter = iter->next, i++)
|
|
|
|
|
cache->interfaces[i] = iter->data;
|
|
|
|
|
g_list_free (interface_infos);
|
|
|
|
|
|
2024-01-26 00:09:16 +01:00
|
|
|
|
g_hash_table_insert (repository->interfaces_for_gtype, (gpointer) gtype,
|
2010-10-23 00:08:15 +02:00
|
|
|
|
cache);
|
2019-10-10 22:34:23 +02:00
|
|
|
|
|
|
|
|
|
g_free (interfaces);
|
2010-10-23 00:08:15 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*n_interfaces_out = cache->n_interfaces;
|
2019-06-20 09:18:13 +02:00
|
|
|
|
*interfaces_out = (GIInterfaceInfo**)&cache->interfaces[0];
|
2010-10-23 00:08:15 +02:00
|
|
|
|
}
|
|
|
|
|
|
2008-02-08 16:31:03 +01:00
|
|
|
|
static void
|
|
|
|
|
collect_namespaces (gpointer key,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
gpointer value,
|
|
|
|
|
gpointer data)
|
2008-02-08 16:31:03 +01:00
|
|
|
|
{
|
|
|
|
|
GList **list = data;
|
|
|
|
|
|
|
|
|
|
*list = g_list_append (*list, key);
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-21 01:56:40 +02:00
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_repository_get_loaded_namespaces:
|
2024-01-26 11:44:09 +01:00
|
|
|
|
* @repository: A #GIRepository
|
2024-02-07 16:44:21 +01:00
|
|
|
|
* @n_namespaces_out: (optional) (out): Return location for the number of
|
|
|
|
|
* namespaces
|
2008-08-21 01:56:40 +02:00
|
|
|
|
*
|
2008-10-12 06:51:48 +02:00
|
|
|
|
* Return the list of currently loaded namespaces.
|
|
|
|
|
*
|
2024-02-07 16:44:21 +01:00
|
|
|
|
* The list is guaranteed to be `NULL` terminated. The `NULL` terminator is not
|
|
|
|
|
* counted in @n_namespaces_out.
|
|
|
|
|
*
|
|
|
|
|
* Returns: (element-type utf8) (transfer full) (array length=n_namespaces_out):
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* list of namespaces
|
|
|
|
|
* Since: 2.80
|
2008-08-21 01:56:40 +02:00
|
|
|
|
*/
|
2024-01-15 20:20:47 +01:00
|
|
|
|
char **
|
2024-02-07 16:44:21 +01:00
|
|
|
|
gi_repository_get_loaded_namespaces (GIRepository *repository,
|
|
|
|
|
size_t *n_namespaces_out)
|
2008-02-08 16:31:03 +01:00
|
|
|
|
{
|
|
|
|
|
GList *l, *list = NULL;
|
2024-01-15 20:20:47 +01:00
|
|
|
|
char **names;
|
2024-01-16 01:57:09 +01:00
|
|
|
|
size_t i;
|
2008-02-08 16:31:03 +01:00
|
|
|
|
|
2024-01-26 11:44:09 +01:00
|
|
|
|
g_return_val_if_fail (GI_IS_REPOSITORY (repository), NULL);
|
2008-08-30 22:31:07 +02:00
|
|
|
|
|
2024-01-26 00:09:16 +01:00
|
|
|
|
g_hash_table_foreach (repository->typelibs, collect_namespaces, &list);
|
|
|
|
|
g_hash_table_foreach (repository->lazy_typelibs, collect_namespaces, &list);
|
2008-02-08 16:31:03 +01:00
|
|
|
|
|
2024-01-15 20:20:47 +01:00
|
|
|
|
names = g_malloc0 (sizeof (char *) * (g_list_length (list) + 1));
|
2008-02-08 16:31:03 +01:00
|
|
|
|
i = 0;
|
|
|
|
|
for (l = list; l; l = l->next)
|
2010-03-24 19:00:06 +01:00
|
|
|
|
names[i++] = g_strdup (l->data);
|
2008-02-08 16:31:03 +01:00
|
|
|
|
g_list_free (list);
|
|
|
|
|
|
2024-02-07 16:44:21 +01:00
|
|
|
|
if (n_namespaces_out != NULL)
|
|
|
|
|
*n_namespaces_out = i;
|
|
|
|
|
|
2008-02-08 16:31:03 +01:00
|
|
|
|
return names;
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-12 06:51:48 +02:00
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_repository_get_version:
|
2024-01-26 11:44:09 +01:00
|
|
|
|
* @repository: A #GIRepository
|
2009-02-12 04:32:25 +01:00
|
|
|
|
* @namespace_: Namespace to inspect
|
2008-10-12 06:51:48 +02:00
|
|
|
|
*
|
|
|
|
|
* This function returns the loaded version associated with the given
|
2009-02-12 04:32:25 +01:00
|
|
|
|
* namespace @namespace_.
|
2008-10-12 06:51:48 +02:00
|
|
|
|
*
|
|
|
|
|
* Note: The namespace must have already been loaded using a function
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* such as [method@GIRepository.Repository.require] before calling this
|
|
|
|
|
* function.
|
2008-10-12 06:51:48 +02:00
|
|
|
|
*
|
|
|
|
|
* Returns: Loaded version
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* Since: 2.80
|
2008-10-12 06:51:48 +02:00
|
|
|
|
*/
|
2024-01-15 20:20:47 +01:00
|
|
|
|
const char *
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_repository_get_version (GIRepository *repository,
|
2024-01-15 20:20:47 +01:00
|
|
|
|
const char *namespace)
|
2008-10-12 06:51:48 +02:00
|
|
|
|
{
|
2010-08-31 22:36:06 +02:00
|
|
|
|
GITypelib *typelib;
|
2008-10-12 06:51:48 +02:00
|
|
|
|
Header *header;
|
|
|
|
|
|
2024-01-26 11:44:09 +01:00
|
|
|
|
g_return_val_if_fail (GI_IS_REPOSITORY (repository), NULL);
|
2008-10-12 06:51:48 +02:00
|
|
|
|
g_return_val_if_fail (namespace != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
typelib = get_registered (repository, namespace, NULL);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (typelib != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
header = (Header *) typelib->data;
|
2023-11-08 15:17:52 +01:00
|
|
|
|
return gi_typelib_get_string (typelib, header->nsversion);
|
2008-10-12 06:51:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-01-05 13:33:02 +01:00
|
|
|
|
* gi_repository_get_shared_libraries:
|
2024-01-26 11:44:09 +01:00
|
|
|
|
* @repository: A #GIRepository
|
2009-02-12 04:32:25 +01:00
|
|
|
|
* @namespace_: Namespace to inspect
|
2024-01-05 13:33:02 +01:00
|
|
|
|
* @out_n_elements: (out) (optional): Return location for the number of elements
|
|
|
|
|
* in the returned array
|
2008-10-12 06:51:48 +02:00
|
|
|
|
*
|
2024-01-05 13:33:02 +01:00
|
|
|
|
* This function returns an array of paths to the
|
2015-02-14 20:37:43 +01:00
|
|
|
|
* shared C libraries associated with the given namespace @namespace_.
|
2023-12-13 14:24:40 +01:00
|
|
|
|
*
|
2015-02-14 20:37:43 +01:00
|
|
|
|
* There may be no shared library path associated, in which case this
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* function will return `NULL`.
|
2008-10-12 06:51:48 +02:00
|
|
|
|
*
|
|
|
|
|
* Note: The namespace must have already been loaded using a function
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* such as [method@GIRepository.Repository.require] before calling this
|
|
|
|
|
* function.
|
2008-10-12 06:51:48 +02:00
|
|
|
|
*
|
2024-01-05 13:33:02 +01:00
|
|
|
|
* The list is internal to [class@GIRepository.Repository] and should not be
|
|
|
|
|
* freed, nor should its string elements.
|
|
|
|
|
*
|
2024-02-07 16:45:28 +01:00
|
|
|
|
* The list is guaranteed to be `NULL` terminated. The `NULL` terminator is not
|
|
|
|
|
* counted in @out_n_elements.
|
|
|
|
|
*
|
2024-01-05 13:33:02 +01:00
|
|
|
|
* Returns: (nullable) (array length=out_n_elements) (transfer none): Array of
|
|
|
|
|
* paths to shared libraries, or `NULL` if none are associated
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* Since: 2.80
|
2008-10-12 06:51:48 +02:00
|
|
|
|
*/
|
2024-01-05 13:33:02 +01:00
|
|
|
|
const char * const *
|
|
|
|
|
gi_repository_get_shared_libraries (GIRepository *repository,
|
2024-01-15 20:20:47 +01:00
|
|
|
|
const char *namespace,
|
2024-01-05 13:33:02 +01:00
|
|
|
|
size_t *out_n_elements)
|
2008-02-08 16:31:03 +01:00
|
|
|
|
{
|
2010-08-31 22:36:06 +02:00
|
|
|
|
GITypelib *typelib;
|
2008-02-08 16:31:03 +01:00
|
|
|
|
Header *header;
|
|
|
|
|
|
2024-01-26 11:44:09 +01:00
|
|
|
|
g_return_val_if_fail (GI_IS_REPOSITORY (repository), NULL);
|
2008-10-12 06:51:48 +02:00
|
|
|
|
g_return_val_if_fail (namespace != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
typelib = get_registered (repository, namespace, NULL);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (typelib != NULL, NULL);
|
|
|
|
|
|
2008-08-09 14:55:32 +02:00
|
|
|
|
header = (Header *) typelib->data;
|
2024-01-05 13:33:02 +01:00
|
|
|
|
if (!header->shared_library)
|
|
|
|
|
{
|
|
|
|
|
if (out_n_elements != NULL)
|
|
|
|
|
*out_n_elements = 0;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Populate the cache. */
|
2024-01-26 00:09:16 +01:00
|
|
|
|
if (repository->cached_shared_libraries == NULL)
|
2024-01-05 13:33:02 +01:00
|
|
|
|
{
|
|
|
|
|
const char *comma_separated = gi_typelib_get_string (typelib, header->shared_library);
|
|
|
|
|
|
|
|
|
|
if (comma_separated != NULL && *comma_separated != '\0')
|
|
|
|
|
{
|
2024-01-26 00:09:16 +01:00
|
|
|
|
repository->cached_shared_libraries = g_strsplit (comma_separated, ",", -1);
|
|
|
|
|
repository->cached_n_shared_libraries = g_strv_length (repository->cached_shared_libraries);
|
2024-01-05 13:33:02 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (out_n_elements != NULL)
|
2024-01-26 00:09:16 +01:00
|
|
|
|
*out_n_elements = repository->cached_n_shared_libraries;
|
2024-01-05 13:33:02 +01:00
|
|
|
|
|
2024-01-26 00:09:16 +01:00
|
|
|
|
return (const char * const *) repository->cached_shared_libraries;
|
2008-02-08 16:31:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
2008-08-21 05:06:13 +02:00
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_repository_get_c_prefix:
|
2024-01-26 11:44:09 +01:00
|
|
|
|
* @repository: A #GIRepository
|
2010-05-18 18:37:51 +02:00
|
|
|
|
* @namespace_: Namespace to inspect
|
2009-02-13 00:42:47 +01:00
|
|
|
|
*
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* This function returns the ‘C prefix’, or the C level namespace
|
|
|
|
|
* associated with the given introspection namespace.
|
|
|
|
|
*
|
|
|
|
|
* Each C symbol starts with this prefix, as well each [type@GObject.Type] in
|
|
|
|
|
* the library.
|
2009-02-13 00:42:47 +01:00
|
|
|
|
*
|
|
|
|
|
* Note: The namespace must have already been loaded using a function
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* such as [method@GIRepository.Repository.require] before calling this
|
|
|
|
|
* function.
|
2009-02-13 00:42:47 +01:00
|
|
|
|
*
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* Returns: (nullable): C namespace prefix, or `NULL` if none associated
|
|
|
|
|
* Since: 2.80
|
2009-02-13 00:42:47 +01:00
|
|
|
|
*/
|
2024-01-15 20:20:47 +01:00
|
|
|
|
const char *
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_repository_get_c_prefix (GIRepository *repository,
|
2024-01-15 20:20:47 +01:00
|
|
|
|
const char *namespace_)
|
2009-02-13 00:42:47 +01:00
|
|
|
|
{
|
2010-08-31 22:36:06 +02:00
|
|
|
|
GITypelib *typelib;
|
2009-02-13 00:42:47 +01:00
|
|
|
|
Header *header;
|
|
|
|
|
|
2024-01-26 11:44:09 +01:00
|
|
|
|
g_return_val_if_fail (GI_IS_REPOSITORY (repository), NULL);
|
2009-02-13 00:42:47 +01:00
|
|
|
|
g_return_val_if_fail (namespace_ != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
typelib = get_registered (repository, namespace_, NULL);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (typelib != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
header = (Header *) typelib->data;
|
2011-09-21 19:13:45 +02:00
|
|
|
|
if (header->c_prefix)
|
2023-11-08 15:17:52 +01:00
|
|
|
|
return gi_typelib_get_string (typelib, header->c_prefix);
|
2009-02-13 00:42:47 +01:00
|
|
|
|
else
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_repository_get_typelib_path:
|
2024-01-26 11:44:09 +01:00
|
|
|
|
* @repository: A #GIRepository
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* @namespace_: GI namespace to use, e.g. `Gtk`
|
2008-08-21 05:06:13 +02:00
|
|
|
|
*
|
2009-02-12 04:32:25 +01:00
|
|
|
|
* If namespace @namespace_ is loaded, return the full path to the
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* .typelib file it was loaded from.
|
|
|
|
|
*
|
|
|
|
|
* If the typelib for namespace @namespace_ was included in a shared library,
|
|
|
|
|
* return the special string `<builtin>`.
|
2008-08-21 05:06:13 +02:00
|
|
|
|
*
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* Returns: (type filename) (nullable): Filesystem path (or `<builtin>`) if
|
|
|
|
|
* successful, `NULL` if namespace is not loaded
|
|
|
|
|
* Since: 2.80
|
2008-08-21 05:06:13 +02:00
|
|
|
|
*/
|
2024-01-15 20:20:47 +01:00
|
|
|
|
const char *
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_repository_get_typelib_path (GIRepository *repository,
|
2024-01-15 20:20:47 +01:00
|
|
|
|
const char *namespace)
|
2008-02-08 16:31:03 +01:00
|
|
|
|
{
|
2008-08-21 05:06:13 +02:00
|
|
|
|
gpointer orig_key, value;
|
|
|
|
|
|
2024-01-26 11:44:09 +01:00
|
|
|
|
g_return_val_if_fail (GI_IS_REPOSITORY (repository), NULL);
|
2008-08-30 22:31:07 +02:00
|
|
|
|
|
2024-01-26 00:09:16 +01:00
|
|
|
|
if (!g_hash_table_lookup_extended (repository->typelibs, namespace,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
&orig_key, &value))
|
2008-08-30 22:31:12 +02:00
|
|
|
|
{
|
2024-01-26 00:09:16 +01:00
|
|
|
|
if (!g_hash_table_lookup_extended (repository->lazy_typelibs, namespace,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
&orig_key, &value))
|
2010-03-24 19:00:06 +01:00
|
|
|
|
|
2024-01-16 17:30:37 +01:00
|
|
|
|
return NULL;
|
2008-08-30 22:31:12 +02:00
|
|
|
|
}
|
2008-08-21 05:06:13 +02:00
|
|
|
|
return ((char*)orig_key) + strlen ((char *) orig_key) + 1;
|
2008-02-08 16:31:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
2008-10-12 06:51:48 +02:00
|
|
|
|
/* This simple search function looks for a specified namespace-version;
|
|
|
|
|
it's faster than the full directory listing required for latest version. */
|
|
|
|
|
static GMappedFile *
|
2023-12-20 06:29:40 +01:00
|
|
|
|
find_namespace_version (const char *namespace,
|
|
|
|
|
const char *version,
|
|
|
|
|
const char * const *search_paths,
|
|
|
|
|
size_t n_search_paths,
|
|
|
|
|
char **path_ret)
|
2008-10-12 06:51:48 +02:00
|
|
|
|
{
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
GMappedFile *mfile = NULL;
|
|
|
|
|
char *fname;
|
2010-03-24 19:00:06 +01:00
|
|
|
|
|
2023-12-29 15:10:22 +01:00
|
|
|
|
if (g_str_equal (namespace, GIREPOSITORY_TYPELIB_NAME) &&
|
|
|
|
|
!g_str_equal (version, GIREPOSITORY_TYPELIB_VERSION))
|
|
|
|
|
{
|
|
|
|
|
g_debug ("Ignoring %s-%s.typelib because this libgirepository "
|
|
|
|
|
"corresponds to %s-%s",
|
|
|
|
|
namespace, version,
|
|
|
|
|
namespace, GIREPOSITORY_TYPELIB_VERSION);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-12 06:51:48 +02:00
|
|
|
|
fname = g_strdup_printf ("%s-%s.typelib", namespace, version);
|
|
|
|
|
|
2023-12-20 06:29:40 +01:00
|
|
|
|
for (size_t i = 0; i < n_search_paths; ++i)
|
2008-10-12 06:51:48 +02:00
|
|
|
|
{
|
2023-12-20 06:29:40 +01:00
|
|
|
|
char *path = g_build_filename (search_paths[i], fname, NULL);
|
2010-03-24 19:00:06 +01:00
|
|
|
|
|
2008-10-12 06:51:48 +02:00
|
|
|
|
mfile = g_mapped_file_new (path, FALSE, &error);
|
|
|
|
|
if (error)
|
2024-01-16 17:30:37 +01:00
|
|
|
|
{
|
|
|
|
|
g_free (path);
|
|
|
|
|
g_clear_error (&error);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2008-10-12 06:51:48 +02:00
|
|
|
|
*path_ret = path;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
g_free (fname);
|
|
|
|
|
return mfile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
parse_version (const char *version,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
int *major,
|
|
|
|
|
int *minor)
|
2008-10-12 06:51:48 +02:00
|
|
|
|
{
|
|
|
|
|
const char *dot;
|
Bug 556543 – reduce compiler warnings
2008-10-16 Tommi Komulainen <tommi.komulainen@iki.fi>
Bug 556543 – reduce compiler warnings
* girepository/ginfo.c:
* girepository/girepository.c (register_internal,
count_interfaces, find_interface, find_namespace_version,
parse_version, g_irepository_require):
* girepository/girmodule.c (g_ir_module_build_typelib):
* girepository/girnode.c (init_stats, dump_stats,
_g_irnode_init_stats, _g_irnode_dump_stats,
g_ir_node_can_have_member):
* girepository/girparser.c (firstpass_end_element_handler,
locate_gir, parse_basic, parse_type_internal, resolve_aliases,
start_alias, start_type, end_type_top, parse_include, cleanup,
post_filter):
* girepository/gtypelib.c (validate_function_blob, validate_enum_blob):
* giscanner/giscannermodule.c (directive_get_options,
type_get_child_list):
* giscanner/scannerlexer.l (parse_gtkdoc):
* giscanner/scannerparser.y (ctype_free):
* giscanner/sourcescanner.c:
* giscanner/sourcescanner.h (gi_source_scanner_parse_macros):
* tests/types/gitesttypes.c:
* tools/compiler.c (main):
* tools/generate.c (write_repository): Remove unused variables
and code, add missing includes, declarations and case
statements.
svn path=/trunk/; revision=730
2008-10-16 19:07:05 +02:00
|
|
|
|
char *end;
|
2008-10-12 06:51:48 +02:00
|
|
|
|
|
|
|
|
|
*major = strtol (version, &end, 10);
|
|
|
|
|
dot = strchr (version, '.');
|
|
|
|
|
if (dot == NULL)
|
|
|
|
|
{
|
|
|
|
|
*minor = 0;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
if (dot != end)
|
|
|
|
|
return FALSE;
|
|
|
|
|
*minor = strtol (dot+1, &end, 10);
|
|
|
|
|
if (end != (version + strlen (version)))
|
|
|
|
|
return FALSE;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
compare_version (const char *v1,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
const char *v2)
|
2008-10-12 06:51:48 +02:00
|
|
|
|
{
|
2008-10-12 23:03:41 +02:00
|
|
|
|
gboolean success;
|
2008-10-12 06:51:48 +02:00
|
|
|
|
int v1_major, v1_minor;
|
|
|
|
|
int v2_major, v2_minor;
|
|
|
|
|
|
2008-10-12 23:03:41 +02:00
|
|
|
|
success = parse_version (v1, &v1_major, &v1_minor);
|
|
|
|
|
g_assert (success);
|
|
|
|
|
|
|
|
|
|
success = parse_version (v2, &v2_major, &v2_minor);
|
|
|
|
|
g_assert (success);
|
2008-10-12 06:51:48 +02:00
|
|
|
|
|
2023-11-14 11:36:51 +01:00
|
|
|
|
/* Avoid a compiler warning about `success` being unused with G_DISABLE_ASSERT */
|
|
|
|
|
(void) success;
|
|
|
|
|
|
2008-10-12 06:51:48 +02:00
|
|
|
|
if (v1_major > v2_major)
|
|
|
|
|
return 1;
|
|
|
|
|
else if (v2_major > v1_major)
|
|
|
|
|
return -1;
|
|
|
|
|
else if (v1_minor > v2_minor)
|
|
|
|
|
return 1;
|
|
|
|
|
else if (v2_minor > v1_minor)
|
|
|
|
|
return -1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct NamespaceVersionCandidadate
|
|
|
|
|
{
|
|
|
|
|
GMappedFile *mfile;
|
2008-10-21 20:41:36 +02:00
|
|
|
|
int path_index;
|
2008-10-12 06:51:48 +02:00
|
|
|
|
char *path;
|
|
|
|
|
char *version;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
compare_candidate_reverse (struct NamespaceVersionCandidadate *c1,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
struct NamespaceVersionCandidadate *c2)
|
2008-10-12 06:51:48 +02:00
|
|
|
|
{
|
|
|
|
|
int result = compare_version (c1->version, c2->version);
|
2008-10-21 20:41:36 +02:00
|
|
|
|
/* First, check the version */
|
2008-10-12 06:51:48 +02:00
|
|
|
|
if (result > 0)
|
|
|
|
|
return -1;
|
|
|
|
|
else if (result < 0)
|
|
|
|
|
return 1;
|
2010-03-24 19:00:06 +01:00
|
|
|
|
else
|
2008-10-21 20:41:36 +02:00
|
|
|
|
{
|
|
|
|
|
/* Now check the path index, which says how early in the search path
|
|
|
|
|
* we found it. This ensures that of equal version targets, we
|
|
|
|
|
* pick the earlier one.
|
|
|
|
|
*/
|
|
|
|
|
if (c1->path_index == c2->path_index)
|
2024-01-16 17:30:37 +01:00
|
|
|
|
return 0;
|
2008-10-21 20:41:36 +02:00
|
|
|
|
else if (c1->path_index > c2->path_index)
|
2024-01-16 17:30:37 +01:00
|
|
|
|
return 1;
|
2008-10-21 20:41:36 +02:00
|
|
|
|
else
|
2024-01-16 17:30:37 +01:00
|
|
|
|
return -1;
|
2008-10-21 20:41:36 +02:00
|
|
|
|
}
|
2008-10-12 06:51:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
free_candidate (struct NamespaceVersionCandidadate *candidate)
|
|
|
|
|
{
|
2009-12-03 21:35:23 +01:00
|
|
|
|
g_mapped_file_unref (candidate->mfile);
|
2008-10-12 06:51:48 +02:00
|
|
|
|
g_free (candidate->path);
|
|
|
|
|
g_free (candidate->version);
|
2010-05-20 16:33:49 +02:00
|
|
|
|
g_slice_free (struct NamespaceVersionCandidadate, candidate);
|
2008-10-12 06:51:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-27 13:06:54 +02:00
|
|
|
|
static GSList *
|
2023-12-20 06:29:40 +01:00
|
|
|
|
enumerate_namespace_versions (const char *namespace,
|
|
|
|
|
const char * const *search_paths,
|
|
|
|
|
size_t n_search_paths)
|
2008-10-12 06:51:48 +02:00
|
|
|
|
{
|
2010-07-27 13:06:54 +02:00
|
|
|
|
GSList *candidates = NULL;
|
|
|
|
|
GHashTable *found_versions = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
|
char *namespace_dash;
|
|
|
|
|
char *namespace_typelib;
|
2008-10-12 06:51:48 +02:00
|
|
|
|
GError *error = NULL;
|
2008-10-21 20:41:36 +02:00
|
|
|
|
int index;
|
2008-10-12 06:51:48 +02:00
|
|
|
|
|
|
|
|
|
namespace_dash = g_strdup_printf ("%s-", namespace);
|
|
|
|
|
namespace_typelib = g_strdup_printf ("%s.typelib", namespace);
|
2008-10-21 20:41:36 +02:00
|
|
|
|
|
|
|
|
|
index = 0;
|
2023-12-20 06:29:40 +01:00
|
|
|
|
for (size_t i = 0; i < n_search_paths; ++i)
|
2008-10-12 06:51:48 +02:00
|
|
|
|
{
|
|
|
|
|
GDir *dir;
|
|
|
|
|
const char *dirname;
|
|
|
|
|
const char *entry;
|
|
|
|
|
|
2023-12-20 06:29:40 +01:00
|
|
|
|
dirname = search_paths[i];
|
2008-10-12 06:51:48 +02:00
|
|
|
|
dir = g_dir_open (dirname, 0, NULL);
|
|
|
|
|
if (dir == NULL)
|
2024-01-16 17:30:37 +01:00
|
|
|
|
continue;
|
2010-03-24 19:00:06 +01:00
|
|
|
|
while ((entry = g_dir_read_name (dir)) != NULL)
|
2024-01-16 17:30:37 +01:00
|
|
|
|
{
|
|
|
|
|
GMappedFile *mfile;
|
|
|
|
|
char *path, *version;
|
|
|
|
|
struct NamespaceVersionCandidadate *candidate;
|
|
|
|
|
|
|
|
|
|
if (!g_str_has_suffix (entry, ".typelib"))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (g_str_has_prefix (entry, namespace_dash))
|
|
|
|
|
{
|
|
|
|
|
const char *last_dash;
|
|
|
|
|
const char *name_end;
|
|
|
|
|
int major, minor;
|
|
|
|
|
|
|
|
|
|
if (g_str_equal (namespace, GIREPOSITORY_TYPELIB_NAME) &&
|
|
|
|
|
!g_str_equal (entry, GIREPOSITORY_TYPELIB_FILENAME))
|
|
|
|
|
{
|
|
|
|
|
g_debug ("Ignoring %s because this libgirepository "
|
|
|
|
|
"corresponds to %s",
|
|
|
|
|
entry, GIREPOSITORY_TYPELIB_FILENAME);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
name_end = strrchr (entry, '.');
|
|
|
|
|
last_dash = strrchr (entry, '-');
|
|
|
|
|
version = g_strndup (last_dash+1, name_end-(last_dash+1));
|
|
|
|
|
if (!parse_version (version, &major, &minor))
|
|
|
|
|
{
|
|
|
|
|
g_free (version);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (g_hash_table_lookup (found_versions, version) != NULL)
|
|
|
|
|
{
|
|
|
|
|
g_free (version);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
path = g_build_filename (dirname, entry, NULL);
|
|
|
|
|
mfile = g_mapped_file_new (path, FALSE, &error);
|
|
|
|
|
if (mfile == NULL)
|
|
|
|
|
{
|
|
|
|
|
g_free (path);
|
|
|
|
|
g_free (version);
|
|
|
|
|
g_clear_error (&error);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
candidate = g_slice_new0 (struct NamespaceVersionCandidadate);
|
|
|
|
|
candidate->mfile = mfile;
|
|
|
|
|
candidate->path_index = index;
|
|
|
|
|
candidate->path = path;
|
|
|
|
|
candidate->version = version;
|
|
|
|
|
candidates = g_slist_prepend (candidates, candidate);
|
|
|
|
|
g_hash_table_add (found_versions, version);
|
|
|
|
|
}
|
2008-10-12 06:51:48 +02:00
|
|
|
|
g_dir_close (dir);
|
2008-10-21 20:41:36 +02:00
|
|
|
|
index++;
|
2008-10-12 06:51:48 +02:00
|
|
|
|
}
|
2010-07-28 13:52:05 +02:00
|
|
|
|
|
2010-07-27 13:06:54 +02:00
|
|
|
|
g_free (namespace_dash);
|
|
|
|
|
g_free (namespace_typelib);
|
|
|
|
|
g_hash_table_destroy (found_versions);
|
|
|
|
|
|
|
|
|
|
return candidates;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GMappedFile *
|
2023-12-20 06:29:40 +01:00
|
|
|
|
find_namespace_latest (const char *namespace,
|
|
|
|
|
const char * const *search_paths,
|
|
|
|
|
size_t n_search_paths,
|
|
|
|
|
char **version_ret,
|
|
|
|
|
char **path_ret)
|
2010-07-27 13:06:54 +02:00
|
|
|
|
{
|
|
|
|
|
GSList *candidates;
|
|
|
|
|
GMappedFile *result = NULL;
|
|
|
|
|
|
|
|
|
|
*version_ret = NULL;
|
|
|
|
|
*path_ret = NULL;
|
|
|
|
|
|
2023-12-20 06:29:40 +01:00
|
|
|
|
candidates = enumerate_namespace_versions (namespace, search_paths, n_search_paths);
|
2008-10-12 06:51:48 +02:00
|
|
|
|
|
|
|
|
|
if (candidates != NULL)
|
|
|
|
|
{
|
|
|
|
|
struct NamespaceVersionCandidadate *elected;
|
|
|
|
|
candidates = g_slist_sort (candidates, (GCompareFunc) compare_candidate_reverse);
|
2010-03-24 19:00:06 +01:00
|
|
|
|
|
2008-10-12 06:51:48 +02:00
|
|
|
|
elected = (struct NamespaceVersionCandidadate *) candidates->data;
|
2008-11-12 15:42:13 +01:00
|
|
|
|
/* Remove the elected one so we don't try to free its contents */
|
2008-10-12 06:51:48 +02:00
|
|
|
|
candidates = g_slist_delete_link (candidates, candidates);
|
2010-03-24 19:00:06 +01:00
|
|
|
|
|
2008-10-12 06:51:48 +02:00
|
|
|
|
result = elected->mfile;
|
|
|
|
|
*path_ret = elected->path;
|
|
|
|
|
*version_ret = elected->version;
|
2010-05-20 16:33:49 +02:00
|
|
|
|
g_slice_free (struct NamespaceVersionCandidadate, elected); /* just free the container */
|
2018-07-29 15:24:59 +02:00
|
|
|
|
g_slist_foreach (candidates, (GFunc) (void *) free_candidate, NULL);
|
2008-10-12 06:51:48 +02:00
|
|
|
|
g_slist_free (candidates);
|
2010-03-24 19:00:06 +01:00
|
|
|
|
}
|
2008-10-12 06:51:48 +02:00
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-27 13:06:54 +02:00
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_repository_enumerate_versions:
|
2024-01-26 11:44:09 +01:00
|
|
|
|
* @repository: A #GIRepository
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* @namespace_: GI namespace, e.g. `Gtk`
|
2023-12-20 05:11:38 +01:00
|
|
|
|
* @n_versions_out: (optional) (out): The number of versions returned.
|
2010-07-27 13:06:54 +02:00
|
|
|
|
*
|
2010-08-16 22:39:19 +02:00
|
|
|
|
* Obtain an unordered list of versions (either currently loaded or
|
|
|
|
|
* available) for @namespace_ in this @repository.
|
2010-07-28 13:52:05 +02:00
|
|
|
|
*
|
2024-02-07 16:45:28 +01:00
|
|
|
|
* The list is guaranteed to be `NULL` terminated. The `NULL` terminator is not
|
|
|
|
|
* counted in @n_versions_out.
|
|
|
|
|
*
|
2023-12-20 05:11:38 +01:00
|
|
|
|
* Returns: (element-type utf8) (transfer full) (array length=n_versions_out): the array of versions.
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* Since: 2.80
|
2010-07-27 13:06:54 +02:00
|
|
|
|
*/
|
2023-12-20 05:11:38 +01:00
|
|
|
|
char **
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_repository_enumerate_versions (GIRepository *repository,
|
2024-01-15 20:20:47 +01:00
|
|
|
|
const char *namespace_,
|
2023-12-20 05:11:38 +01:00
|
|
|
|
size_t *n_versions_out)
|
2010-07-27 13:06:54 +02:00
|
|
|
|
{
|
2023-12-20 05:11:38 +01:00
|
|
|
|
GPtrArray *versions;
|
2010-07-27 13:06:54 +02:00
|
|
|
|
GSList *candidates, *link;
|
2024-01-15 20:20:47 +01:00
|
|
|
|
const char *loaded_version;
|
2023-12-20 05:11:38 +01:00
|
|
|
|
char **ret;
|
2010-07-28 13:52:05 +02:00
|
|
|
|
|
2024-02-04 18:14:51 +01:00
|
|
|
|
g_return_val_if_fail (GI_IS_REPOSITORY (repository), NULL);
|
|
|
|
|
|
2023-12-20 06:29:40 +01:00
|
|
|
|
candidates = enumerate_namespace_versions (namespace_,
|
2024-01-26 11:21:23 +01:00
|
|
|
|
(const char * const *) repository->typelib_search_path->pdata,
|
|
|
|
|
repository->typelib_search_path->len);
|
2010-07-30 20:38:34 +02:00
|
|
|
|
|
2023-12-20 05:11:38 +01:00
|
|
|
|
if (!candidates)
|
|
|
|
|
{
|
|
|
|
|
if (n_versions_out)
|
|
|
|
|
*n_versions_out = 0;
|
|
|
|
|
return g_strdupv ((char *[]) {NULL});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
versions = g_ptr_array_new_null_terminated (1, g_free, TRUE);
|
2010-07-27 13:06:54 +02:00
|
|
|
|
for (link = candidates; link; link = link->next)
|
|
|
|
|
{
|
|
|
|
|
struct NamespaceVersionCandidadate *candidate = link->data;
|
2023-12-20 05:11:38 +01:00
|
|
|
|
g_ptr_array_add (versions, g_steal_pointer (&candidate->version));
|
2010-07-27 13:06:54 +02:00
|
|
|
|
free_candidate (candidate);
|
|
|
|
|
}
|
|
|
|
|
g_slist_free (candidates);
|
2010-08-16 22:39:19 +02:00
|
|
|
|
|
|
|
|
|
/* The currently loaded version of a namespace is also part of the
|
|
|
|
|
* available versions, as it could have been loaded using
|
|
|
|
|
* require_private().
|
|
|
|
|
*/
|
2023-11-08 15:17:52 +01:00
|
|
|
|
if (gi_repository_is_registered (repository, namespace_, NULL))
|
2010-08-18 22:26:48 +02:00
|
|
|
|
{
|
2023-11-08 15:17:52 +01:00
|
|
|
|
loaded_version = gi_repository_get_version (repository, namespace_);
|
2023-12-20 05:11:38 +01:00
|
|
|
|
if (loaded_version &&
|
|
|
|
|
!g_ptr_array_find_with_equal_func (versions, loaded_version, g_str_equal, NULL))
|
|
|
|
|
g_ptr_array_add (versions, g_strdup (loaded_version));
|
2010-08-18 22:26:48 +02:00
|
|
|
|
}
|
2010-08-16 22:39:19 +02:00
|
|
|
|
|
2023-12-20 05:11:38 +01:00
|
|
|
|
ret = (char **) g_ptr_array_steal (versions, n_versions_out);
|
|
|
|
|
g_ptr_array_unref (g_steal_pointer (&versions));
|
|
|
|
|
|
2010-07-27 13:06:54 +02:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-31 22:36:06 +02:00
|
|
|
|
static GITypelib *
|
2023-12-20 06:29:40 +01:00
|
|
|
|
require_internal (GIRepository *repository,
|
|
|
|
|
const char *namespace,
|
|
|
|
|
const char *version,
|
|
|
|
|
GIRepositoryLoadFlags flags,
|
|
|
|
|
const char * const *search_paths,
|
|
|
|
|
size_t n_search_paths,
|
|
|
|
|
GError **error)
|
2008-02-08 16:31:03 +01:00
|
|
|
|
{
|
|
|
|
|
GMappedFile *mfile;
|
2010-08-31 22:36:06 +02:00
|
|
|
|
GITypelib *ret = NULL;
|
2008-10-12 06:51:48 +02:00
|
|
|
|
Header *header;
|
2010-08-31 22:36:06 +02:00
|
|
|
|
GITypelib *typelib = NULL;
|
2024-02-07 15:38:05 +01:00
|
|
|
|
GITypelib *typelib_owned = NULL;
|
2024-01-15 20:20:47 +01:00
|
|
|
|
const char *typelib_namespace, *typelib_version;
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gboolean allow_lazy = (flags & GI_REPOSITORY_LOAD_FLAG_LAZY) > 0;
|
2008-08-30 22:31:12 +02:00
|
|
|
|
gboolean is_lazy;
|
2008-10-12 06:51:48 +02:00
|
|
|
|
char *version_conflict = NULL;
|
|
|
|
|
char *path = NULL;
|
|
|
|
|
char *tmp_version = NULL;
|
|
|
|
|
|
2024-01-26 11:44:09 +01:00
|
|
|
|
g_return_val_if_fail (GI_IS_REPOSITORY (repository), NULL);
|
2008-10-12 06:51:48 +02:00
|
|
|
|
g_return_val_if_fail (namespace != NULL, FALSE);
|
2008-02-08 16:31:03 +01:00
|
|
|
|
|
2010-03-24 19:00:06 +01:00
|
|
|
|
typelib = get_registered_status (repository, namespace, version, allow_lazy,
|
2008-10-25 17:48:50 +02:00
|
|
|
|
&is_lazy, &version_conflict);
|
|
|
|
|
if (typelib)
|
|
|
|
|
return typelib;
|
2008-02-08 16:31:03 +01:00
|
|
|
|
|
2008-10-12 06:51:48 +02:00
|
|
|
|
if (version_conflict != NULL)
|
2008-08-21 08:47:49 +02:00
|
|
|
|
{
|
2023-11-08 15:17:52 +01:00
|
|
|
|
g_set_error (error, GI_REPOSITORY_ERROR,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
GI_REPOSITORY_ERROR_NAMESPACE_VERSION_CONFLICT,
|
|
|
|
|
"Requiring namespace '%s' version '%s', but '%s' is already loaded",
|
|
|
|
|
namespace, version, version_conflict);
|
2008-10-25 17:48:50 +02:00
|
|
|
|
return NULL;
|
2008-10-12 06:51:48 +02:00
|
|
|
|
}
|
2008-08-21 08:47:49 +02:00
|
|
|
|
|
2008-10-12 06:51:48 +02:00
|
|
|
|
if (version != NULL)
|
|
|
|
|
{
|
2023-12-20 06:29:40 +01:00
|
|
|
|
mfile = find_namespace_version (namespace, version, search_paths,
|
|
|
|
|
n_search_paths, &path);
|
2008-10-12 06:51:48 +02:00
|
|
|
|
tmp_version = g_strdup (version);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-12-20 06:29:40 +01:00
|
|
|
|
mfile = find_namespace_latest (namespace, search_paths, n_search_paths,
|
|
|
|
|
&tmp_version, &path);
|
2008-10-12 06:51:48 +02:00
|
|
|
|
}
|
2010-03-24 19:00:06 +01:00
|
|
|
|
|
2008-10-12 06:51:48 +02:00
|
|
|
|
if (mfile == NULL)
|
|
|
|
|
{
|
|
|
|
|
if (version != NULL)
|
2024-01-16 17:30:37 +01:00
|
|
|
|
g_set_error (error, GI_REPOSITORY_ERROR,
|
|
|
|
|
GI_REPOSITORY_ERROR_TYPELIB_NOT_FOUND,
|
|
|
|
|
"Typelib file for namespace '%s', version '%s' not found",
|
|
|
|
|
namespace, version);
|
2008-10-12 06:51:48 +02:00
|
|
|
|
else
|
2024-01-16 17:30:37 +01:00
|
|
|
|
g_set_error (error, GI_REPOSITORY_ERROR,
|
|
|
|
|
GI_REPOSITORY_ERROR_TYPELIB_NOT_FOUND,
|
|
|
|
|
"Typelib file for namespace '%s' (any version) not found",
|
|
|
|
|
namespace);
|
2008-10-12 06:51:48 +02:00
|
|
|
|
goto out;
|
|
|
|
|
}
|
2008-08-21 08:47:49 +02:00
|
|
|
|
|
2010-07-22 19:46:33 +02:00
|
|
|
|
{
|
|
|
|
|
GError *temp_error = NULL;
|
2024-01-26 10:49:56 +01:00
|
|
|
|
GBytes *bytes = NULL;
|
|
|
|
|
|
|
|
|
|
bytes = g_mapped_file_get_bytes (mfile);
|
2024-02-07 15:38:05 +01:00
|
|
|
|
typelib_owned = typelib = gi_typelib_new_from_bytes (bytes, &temp_error);
|
2024-01-26 10:49:56 +01:00
|
|
|
|
g_bytes_unref (bytes);
|
2024-01-30 08:45:11 +01:00
|
|
|
|
g_clear_pointer (&mfile, g_mapped_file_unref);
|
2024-01-26 10:49:56 +01:00
|
|
|
|
|
2010-07-22 19:46:33 +02:00
|
|
|
|
if (!typelib)
|
|
|
|
|
{
|
2024-01-16 17:30:37 +01:00
|
|
|
|
g_set_error (error, GI_REPOSITORY_ERROR,
|
|
|
|
|
GI_REPOSITORY_ERROR_TYPELIB_NOT_FOUND,
|
|
|
|
|
"Failed to load typelib file '%s' for namespace '%s': %s",
|
|
|
|
|
path, namespace, temp_error->message);
|
|
|
|
|
g_clear_error (&temp_error);
|
|
|
|
|
goto out;
|
2010-07-22 19:46:33 +02:00
|
|
|
|
}
|
2024-01-26 11:21:23 +01:00
|
|
|
|
|
|
|
|
|
typelib->library_paths = (repository->library_paths != NULL) ? g_ptr_array_ref (repository->library_paths) : NULL;
|
2010-07-22 19:46:33 +02:00
|
|
|
|
}
|
2008-10-12 06:51:48 +02:00
|
|
|
|
header = (Header *) typelib->data;
|
2023-11-08 15:17:52 +01:00
|
|
|
|
typelib_namespace = gi_typelib_get_string (typelib, header->namespace);
|
|
|
|
|
typelib_version = gi_typelib_get_string (typelib, header->nsversion);
|
2010-03-24 19:00:06 +01:00
|
|
|
|
|
2008-10-12 06:51:48 +02:00
|
|
|
|
if (strcmp (typelib_namespace, namespace) != 0)
|
2008-08-21 08:47:49 +02:00
|
|
|
|
{
|
2023-11-08 15:17:52 +01:00
|
|
|
|
g_set_error (error, GI_REPOSITORY_ERROR,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
GI_REPOSITORY_ERROR_NAMESPACE_MISMATCH,
|
|
|
|
|
"Typelib file %s for namespace '%s' contains "
|
|
|
|
|
"namespace '%s' which doesn't match the file name",
|
|
|
|
|
path, namespace, typelib_namespace);
|
2008-10-12 06:51:48 +02:00
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
if (version != NULL && strcmp (typelib_version, version) != 0)
|
|
|
|
|
{
|
2023-11-08 15:17:52 +01:00
|
|
|
|
g_set_error (error, GI_REPOSITORY_ERROR,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
GI_REPOSITORY_ERROR_NAMESPACE_MISMATCH,
|
|
|
|
|
"Typelib file %s for namespace '%s' contains "
|
|
|
|
|
"version '%s' which doesn't match the expected version '%s'",
|
|
|
|
|
path, namespace, typelib_version, version);
|
2008-10-12 06:51:48 +02:00
|
|
|
|
goto out;
|
2008-02-08 16:31:03 +01:00
|
|
|
|
}
|
2008-08-21 08:47:49 +02:00
|
|
|
|
|
2010-03-24 19:00:06 +01:00
|
|
|
|
if (!register_internal (repository, path, allow_lazy,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
typelib, error))
|
2024-02-07 15:38:05 +01:00
|
|
|
|
goto out;
|
2008-10-25 17:48:50 +02:00
|
|
|
|
ret = typelib;
|
2008-10-12 06:51:48 +02:00
|
|
|
|
out:
|
2024-02-07 15:38:05 +01:00
|
|
|
|
g_clear_pointer (&typelib_owned, gi_typelib_unref);
|
2008-10-12 06:51:48 +02:00
|
|
|
|
g_free (tmp_version);
|
|
|
|
|
g_free (path);
|
2010-03-24 19:00:06 +01:00
|
|
|
|
return ret;
|
2008-02-08 16:31:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-30 20:38:34 +02:00
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_repository_require:
|
2024-01-26 11:44:09 +01:00
|
|
|
|
* @repository: A #GIRepository
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* @namespace_: GI namespace to use, e.g. `Gtk`
|
|
|
|
|
* @version: (nullable): Version of namespace, may be `NULL` for latest
|
|
|
|
|
* @flags: Set of [flags@GIRepository.RepositoryLoadFlags], may be 0
|
|
|
|
|
* @error: a [type@GLib.Error].
|
|
|
|
|
*
|
|
|
|
|
* Force the namespace @namespace_ to be loaded if it isn’t already.
|
2010-07-30 20:38:34 +02:00
|
|
|
|
*
|
|
|
|
|
* If @namespace_ is not loaded, this function will search for a
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* `.typelib` file using the repository search path. In addition, a
|
2010-07-30 20:38:34 +02:00
|
|
|
|
* version @version of namespace may be specified. If @version is
|
|
|
|
|
* not specified, the latest will be used.
|
|
|
|
|
*
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* Returns: (transfer none): a pointer to the [type@GIRepository.Typelib] if
|
|
|
|
|
* successful, `NULL` otherwise
|
|
|
|
|
* Since: 2.80
|
2010-07-30 20:38:34 +02:00
|
|
|
|
*/
|
2010-08-31 22:36:06 +02:00
|
|
|
|
GITypelib *
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_repository_require (GIRepository *repository,
|
2024-01-15 20:20:47 +01:00
|
|
|
|
const char *namespace,
|
|
|
|
|
const char *version,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
GIRepositoryLoadFlags flags,
|
|
|
|
|
GError **error)
|
2010-07-30 20:38:34 +02:00
|
|
|
|
{
|
2010-08-31 22:36:06 +02:00
|
|
|
|
GITypelib *typelib;
|
2010-07-30 20:38:34 +02:00
|
|
|
|
|
|
|
|
|
typelib = require_internal (repository, namespace, version, flags,
|
2024-01-26 11:21:23 +01:00
|
|
|
|
(const char * const *) repository->typelib_search_path->pdata,
|
|
|
|
|
repository->typelib_search_path->len, error);
|
2010-07-30 20:38:34 +02:00
|
|
|
|
|
|
|
|
|
return typelib;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_repository_require_private:
|
2024-01-26 11:44:09 +01:00
|
|
|
|
* @repository: A #GIRepository
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* @typelib_dir: (type filename): Private directory where to find the requested
|
|
|
|
|
* typelib
|
|
|
|
|
* @namespace_: GI namespace to use, e.g. `Gtk`
|
|
|
|
|
* @version: (nullable): Version of namespace, may be `NULL` for latest
|
|
|
|
|
* @flags: Set of [flags@GIRepository.RepositoryLoadFlags], may be 0
|
|
|
|
|
* @error: a [type@GLib.Error].
|
|
|
|
|
*
|
|
|
|
|
* Force the namespace @namespace_ to be loaded if it isn’t already.
|
2010-07-30 20:38:34 +02:00
|
|
|
|
*
|
|
|
|
|
* If @namespace_ is not loaded, this function will search for a
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* `.typelib` file within the private directory only. In addition, a
|
2010-07-30 20:38:34 +02:00
|
|
|
|
* version @version of namespace should be specified. If @version is
|
|
|
|
|
* not specified, the latest will be used.
|
|
|
|
|
*
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* Returns: (transfer none): a pointer to the [type@GIRepository.Typelib] if
|
|
|
|
|
* successful, `NULL` otherwise
|
|
|
|
|
* Since: 2.80
|
2010-07-30 20:38:34 +02:00
|
|
|
|
*/
|
2010-08-31 22:36:06 +02:00
|
|
|
|
GITypelib *
|
2024-01-16 02:34:02 +01:00
|
|
|
|
gi_repository_require_private (GIRepository *repository,
|
|
|
|
|
const char *typelib_dir,
|
|
|
|
|
const char *namespace,
|
|
|
|
|
const char *version,
|
|
|
|
|
GIRepositoryLoadFlags flags,
|
|
|
|
|
GError **error)
|
2010-07-30 20:38:34 +02:00
|
|
|
|
{
|
2023-12-20 06:29:40 +01:00
|
|
|
|
const char * const search_path[] = { typelib_dir, NULL };
|
2010-07-30 20:38:34 +02:00
|
|
|
|
|
|
|
|
|
return require_internal (repository, namespace, version, flags,
|
2023-12-20 06:29:40 +01:00
|
|
|
|
search_path, 1, error);
|
2010-07-30 20:38:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2008-11-13 20:57:09 +01:00
|
|
|
|
static gboolean
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_repository_introspect_cb (const char *option_name,
|
2024-01-16 17:30:37 +01:00
|
|
|
|
const char *value,
|
|
|
|
|
gpointer data,
|
|
|
|
|
GError **error)
|
2008-11-13 20:57:09 +01:00
|
|
|
|
{
|
2010-07-31 12:22:52 +02:00
|
|
|
|
GError *tmp_error = NULL;
|
2023-12-12 23:43:11 +01:00
|
|
|
|
char **args;
|
|
|
|
|
|
|
|
|
|
args = g_strsplit (value, ",", 2);
|
|
|
|
|
|
|
|
|
|
if (!gi_repository_dump (args[0], args[1], &tmp_error))
|
2010-07-31 12:22:52 +02:00
|
|
|
|
{
|
|
|
|
|
g_error ("Failed to extract GType data: %s",
|
2024-01-16 17:30:37 +01:00
|
|
|
|
tmp_error->message);
|
2010-07-31 12:22:52 +02:00
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
exit (0);
|
2008-11-13 20:57:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const GOptionEntry introspection_args[] = {
|
|
|
|
|
{ "introspect-dump", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_CALLBACK,
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_repository_introspect_cb, "Dump introspection information",
|
2008-11-13 20:57:09 +01:00
|
|
|
|
"infile.txt,outfile.xml" },
|
2023-10-25 20:03:07 +02:00
|
|
|
|
G_OPTION_ENTRY_NULL
|
2008-11-13 20:57:09 +01:00
|
|
|
|
};
|
|
|
|
|
|
2010-08-31 22:26:17 +02:00
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_repository_get_option_group:
|
2010-08-31 22:26:17 +02:00
|
|
|
|
*
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* Obtain the option group for girepository.
|
|
|
|
|
*
|
|
|
|
|
* It’s used by the dumper and for programs that want to provide introspection
|
|
|
|
|
* information
|
2010-08-31 22:26:17 +02:00
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer full): the option group
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* Since: 2.80
|
2010-08-31 22:26:17 +02:00
|
|
|
|
*/
|
2008-11-13 20:57:09 +01:00
|
|
|
|
GOptionGroup *
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_repository_get_option_group (void)
|
2008-11-13 20:57:09 +01:00
|
|
|
|
{
|
|
|
|
|
GOptionGroup *group;
|
|
|
|
|
group = g_option_group_new ("girepository", "Introspection Options", "Show Introspection Options", NULL, NULL);
|
|
|
|
|
|
|
|
|
|
g_option_group_add_entries (group, introspection_args);
|
|
|
|
|
return group;
|
|
|
|
|
}
|
2008-02-08 16:31:03 +01:00
|
|
|
|
|
|
|
|
|
GQuark
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_repository_error_quark (void)
|
2008-02-08 16:31:03 +01:00
|
|
|
|
{
|
|
|
|
|
static GQuark quark = 0;
|
|
|
|
|
if (quark == 0)
|
|
|
|
|
quark = g_quark_from_static_string ("g-irepository-error-quark");
|
|
|
|
|
return quark;
|
|
|
|
|
}
|
2008-08-18 10:52:47 +02:00
|
|
|
|
|
2010-07-28 13:52:45 +02:00
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_type_tag_to_string:
|
2010-07-28 13:52:45 +02:00
|
|
|
|
* @type: the type_tag
|
|
|
|
|
*
|
|
|
|
|
* Obtain a string representation of @type
|
|
|
|
|
*
|
|
|
|
|
* Returns: the string
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* Since: 2.80
|
2010-07-28 13:52:45 +02:00
|
|
|
|
*/
|
2024-01-15 20:20:47 +01:00
|
|
|
|
const char *
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_type_tag_to_string (GITypeTag type)
|
2008-08-18 10:52:47 +02:00
|
|
|
|
{
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case GI_TYPE_TAG_VOID:
|
|
|
|
|
return "void";
|
|
|
|
|
case GI_TYPE_TAG_BOOLEAN:
|
2010-07-22 03:06:17 +02:00
|
|
|
|
return "gboolean";
|
2008-08-18 10:52:47 +02:00
|
|
|
|
case GI_TYPE_TAG_INT8:
|
2010-07-22 03:06:17 +02:00
|
|
|
|
return "gint8";
|
2008-08-18 10:52:47 +02:00
|
|
|
|
case GI_TYPE_TAG_UINT8:
|
2010-07-22 03:06:17 +02:00
|
|
|
|
return "guint8";
|
2008-08-18 10:52:47 +02:00
|
|
|
|
case GI_TYPE_TAG_INT16:
|
2010-07-22 03:06:17 +02:00
|
|
|
|
return "gint16";
|
2008-08-18 10:52:47 +02:00
|
|
|
|
case GI_TYPE_TAG_UINT16:
|
2010-07-22 03:06:17 +02:00
|
|
|
|
return "guint16";
|
2008-08-18 10:52:47 +02:00
|
|
|
|
case GI_TYPE_TAG_INT32:
|
2010-07-22 03:06:17 +02:00
|
|
|
|
return "gint32";
|
2008-08-18 10:52:47 +02:00
|
|
|
|
case GI_TYPE_TAG_UINT32:
|
2010-07-22 03:06:17 +02:00
|
|
|
|
return "guint32";
|
2008-08-18 10:52:47 +02:00
|
|
|
|
case GI_TYPE_TAG_INT64:
|
2010-07-22 03:06:17 +02:00
|
|
|
|
return "gint64";
|
2008-08-18 10:52:47 +02:00
|
|
|
|
case GI_TYPE_TAG_UINT64:
|
2010-07-22 03:06:17 +02:00
|
|
|
|
return "guint64";
|
2008-08-18 10:52:47 +02:00
|
|
|
|
case GI_TYPE_TAG_FLOAT:
|
2010-07-22 03:06:17 +02:00
|
|
|
|
return "gfloat";
|
2008-08-18 10:52:47 +02:00
|
|
|
|
case GI_TYPE_TAG_DOUBLE:
|
2010-07-22 03:06:17 +02:00
|
|
|
|
return "gdouble";
|
2010-10-26 17:12:26 +02:00
|
|
|
|
case GI_TYPE_TAG_UNICHAR:
|
|
|
|
|
return "gunichar";
|
2008-10-02 15:25:46 +02:00
|
|
|
|
case GI_TYPE_TAG_GTYPE:
|
|
|
|
|
return "GType";
|
2008-08-18 10:52:47 +02:00
|
|
|
|
case GI_TYPE_TAG_UTF8:
|
|
|
|
|
return "utf8";
|
|
|
|
|
case GI_TYPE_TAG_FILENAME:
|
|
|
|
|
return "filename";
|
|
|
|
|
case GI_TYPE_TAG_ARRAY:
|
|
|
|
|
return "array";
|
|
|
|
|
case GI_TYPE_TAG_INTERFACE:
|
|
|
|
|
return "interface";
|
|
|
|
|
case GI_TYPE_TAG_GLIST:
|
|
|
|
|
return "glist";
|
|
|
|
|
case GI_TYPE_TAG_GSLIST:
|
|
|
|
|
return "gslist";
|
|
|
|
|
case GI_TYPE_TAG_GHASH:
|
|
|
|
|
return "ghash";
|
|
|
|
|
case GI_TYPE_TAG_ERROR:
|
|
|
|
|
return "error";
|
|
|
|
|
default:
|
|
|
|
|
return "unknown";
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-07-28 12:24:10 +02:00
|
|
|
|
|
|
|
|
|
/**
|
2023-11-08 15:17:52 +01:00
|
|
|
|
* gi_info_type_to_string:
|
2010-07-28 13:52:45 +02:00
|
|
|
|
* @type: the info type
|
|
|
|
|
*
|
|
|
|
|
* Obtain a string representation of @type
|
2010-07-28 12:24:10 +02:00
|
|
|
|
*
|
2010-07-28 13:52:45 +02:00
|
|
|
|
* Returns: the string
|
2023-12-13 14:24:40 +01:00
|
|
|
|
* Since: 2.80
|
2010-07-28 12:24:10 +02:00
|
|
|
|
*/
|
2024-01-15 20:20:47 +01:00
|
|
|
|
const char *
|
2023-11-08 15:17:52 +01:00
|
|
|
|
gi_info_type_to_string (GIInfoType type)
|
2010-07-28 12:24:10 +02:00
|
|
|
|
{
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case GI_INFO_TYPE_INVALID:
|
|
|
|
|
return "invalid";
|
|
|
|
|
case GI_INFO_TYPE_FUNCTION:
|
|
|
|
|
return "function";
|
|
|
|
|
case GI_INFO_TYPE_CALLBACK:
|
|
|
|
|
return "callback";
|
|
|
|
|
case GI_INFO_TYPE_STRUCT:
|
|
|
|
|
return "struct";
|
|
|
|
|
case GI_INFO_TYPE_ENUM:
|
|
|
|
|
return "enum";
|
|
|
|
|
case GI_INFO_TYPE_FLAGS:
|
|
|
|
|
return "flags";
|
|
|
|
|
case GI_INFO_TYPE_OBJECT:
|
|
|
|
|
return "object";
|
|
|
|
|
case GI_INFO_TYPE_INTERFACE:
|
|
|
|
|
return "interface";
|
|
|
|
|
case GI_INFO_TYPE_CONSTANT:
|
|
|
|
|
return "constant";
|
|
|
|
|
case GI_INFO_TYPE_UNION:
|
|
|
|
|
return "union";
|
|
|
|
|
case GI_INFO_TYPE_VALUE:
|
|
|
|
|
return "value";
|
|
|
|
|
case GI_INFO_TYPE_SIGNAL:
|
|
|
|
|
return "signal";
|
|
|
|
|
case GI_INFO_TYPE_VFUNC:
|
|
|
|
|
return "vfunc";
|
|
|
|
|
case GI_INFO_TYPE_PROPERTY:
|
|
|
|
|
return "property";
|
|
|
|
|
case GI_INFO_TYPE_FIELD:
|
|
|
|
|
return "field";
|
|
|
|
|
case GI_INFO_TYPE_ARG:
|
|
|
|
|
return "arg";
|
|
|
|
|
case GI_INFO_TYPE_TYPE:
|
|
|
|
|
return "type";
|
|
|
|
|
case GI_INFO_TYPE_UNRESOLVED:
|
|
|
|
|
return "unresolved";
|
|
|
|
|
default:
|
|
|
|
|
return "unknown";
|
|
|
|
|
}
|
|
|
|
|
}
|