static GSList *search_path = NULL;
static GSList *override_search_path = NULL;
-struct _GIRepositoryPrivate
+struct _GIRepositoryPrivate
{
GHashTable *typelibs; /* (string) namespace -> GTypelib */
GHashTable *lazy_typelibs; /* (string) namespace-version -> GTypelib */
G_DEFINE_TYPE (GIRepository, g_irepository, G_TYPE_OBJECT);
-static void
+static void
g_irepository_init (GIRepository *repository)
{
repository->priv = G_TYPE_INSTANCE_GET_PRIVATE (repository, G_TYPE_IREPOSITORY,
GIRepositoryPrivate);
- repository->priv->typelibs
+ repository->priv->typelibs
= g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify) NULL,
(GDestroyNotify) g_typelib_free);
- repository->priv->lazy_typelibs
+ repository->priv->lazy_typelibs
= g_hash_table_new (g_str_hash, g_str_equal);
repository->priv->info_by_gtype
= g_hash_table_new_full (g_direct_hash, g_direct_equal,
g_hash_table_destroy (repository->priv->typelibs);
g_hash_table_destroy (repository->priv->lazy_typelibs);
g_hash_table_destroy (repository->priv->info_by_gtype);
-
+
(* G_OBJECT_CLASS (g_irepository_parent_class)->finalize) (G_OBJECT (repository));
}
gobject_class->finalize = g_irepository_finalize;
- g_type_class_add_private (class, sizeof (GIRepositoryPrivate));
+ g_type_class_add_private (class, sizeof (GIRepositoryPrivate));
}
static void
build_search_path_with_overrides (void)
{
GSList *result;
- if (override_search_path != NULL)
+ if (override_search_path != NULL)
{
result = g_slist_copy (override_search_path);
g_slist_last (result)->next = g_slist_copy (search_path);
- }
+ }
else
result = g_slist_copy (search_path);
return result;
}
static GTypelib *
-check_version_conflict (GTypelib *typelib,
+check_version_conflict (GTypelib *typelib,
const gchar *namespace,
const gchar *expected_version,
char **version_conflict)
*version_conflict = NULL;
return typelib;
}
-
+
header = (Header*)typelib->data;
loaded_version = g_typelib_get_string (typelib, header->nsversion);
g_assert (loaded_version != NULL);
-
+
if (strcmp (expected_version, loaded_version) != 0)
{
if (version_conflict)
if (lazy_status)
*lazy_status = FALSE;
typelib = g_hash_table_lookup (repository->priv->typelibs, namespace);
- if (typelib)
+ if (typelib)
return check_version_conflict (typelib, namespace, version, version_conflict);
typelib = g_hash_table_lookup (repository->priv->lazy_typelibs, namespace);
if (!typelib)
if (dependencies != NULL)
{
int i;
-
+
for (i = 0; dependencies[i]; i++)
{
char *dependency = dependencies[i];
last_dash = strrchr (dependency, '-');
dependency_namespace = g_strndup (dependency, last_dash - dependency);
dependency_version = last_dash+1;
-
+
if (!g_irepository_require (repository, dependency_namespace, dependency_version,
0, error))
{
const gchar *version;
g_return_val_if_fail (typelib != NULL, FALSE);
-
+
header = (Header *)typelib->data;
g_return_val_if_fail (header != NULL, FALSE);
if (lazy)
{
- g_assert (!g_hash_table_lookup (repository->priv->lazy_typelibs,
+ g_assert (!g_hash_table_lookup (repository->priv->lazy_typelibs,
namespace));
- g_hash_table_insert (repository->priv->lazy_typelibs,
+ g_hash_table_insert (repository->priv->lazy_typelibs,
build_typelib_key (namespace, source), (void *)typelib);
}
else
/* First, try loading all the dependencies */
if (!load_dependencies_recurse (repository, typelib, error))
return NULL;
-
+
/* Check if we are transitioning from lazily loaded state */
- if (g_hash_table_lookup_extended (repository->priv->lazy_typelibs,
+ if (g_hash_table_lookup_extended (repository->priv->lazy_typelibs,
namespace,
(gpointer)&key, &value))
g_hash_table_remove (repository->priv->lazy_typelibs, key);
namespace = g_typelib_get_string (typelib, header->namespace);
nsversion = g_typelib_get_string (typelib, header->nsversion);
- if (get_registered_status (repository, namespace, nsversion, allow_lazy,
+ if (get_registered_status (repository, namespace, nsversion, allow_lazy,
&is_lazy, &version_conflict))
{
if (version_conflict != NULL)
}
return namespace;
}
- return register_internal (repository, "<builtin>",
+ return register_internal (repository, "<builtin>",
allow_lazy, typelib, error);
}
* metadata in the namespace, you should call #g_irepository_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
*/
gboolean
-g_irepository_is_registered (GIRepository *repository,
+g_irepository_is_registered (GIRepository *repository,
const gchar *namespace,
const gchar *version)
{
* All methods on #GIRepository also accept %NULL as an instance
* parameter to mean this default repository, which is usually more
* convenient for C.
- *
- * Returns: (transfer none): The global singleton #GIRepository
+ *
+ * Returns: (transfer none): The global singleton #GIRepository
*/
-GIRepository *
+GIRepository *
g_irepository_get_default (void)
{
return get_repository (NULL);
*
* Returns: number of metadata entries
*/
-gint
+gint
g_irepository_get_n_infos (GIRepository *repository,
const gchar *namespace)
{
g_return_val_if_fail (namespace != NULL, -1);
repository = get_repository (repository);
-
+
typelib = get_registered (repository, namespace, NULL);
g_return_val_if_fail (typelib != NULL, -1);
gint n_entries;
const gchar *name;
const gchar *type;
- DirEntry *entry;
+ DirEntry *entry;
index = 0;
n_entries = ((Header *)typelib->data)->n_local_entries;
*
* Returns: #GIBaseInfo containing metadata
*/
-GIBaseInfo *
+GIBaseInfo *
g_irepository_get_info (GIRepository *repository,
const gchar *namespace,
gint index)
data.iface = NULL;
typelib = get_registered (repository, namespace, NULL);
-
+
g_return_val_if_fail (typelib != NULL, NULL);
find_interface ((void *)namespace, typelib, &data);
- return data.iface;
+ return data.iface;
}
/**
*
* Returns: #GIBaseInfo representing metadata about @type, or %NULL
*/
-GIBaseInfo *
+GIBaseInfo *
g_irepository_find_by_gtype (GIRepository *repository,
GType gtype)
{
*
* Returns: #GIBaseInfo representing metadata about @name, or %NULL
*/
-GIBaseInfo *
+GIBaseInfo *
g_irepository_find_by_name (GIRepository *repository,
const gchar *namespace,
const gchar *name)
data.iface = NULL;
typelib = get_registered (repository, namespace, NULL);
-
+
g_return_val_if_fail (typelib != NULL, NULL);
find_interface ((void *)namespace, typelib, &data);
*
* Returns: (utf8) (transfer full): List of namespaces
*/
-gchar **
+gchar **
g_irepository_get_loaded_namespaces (GIRepository *repository)
{
GList *l, *list = NULL;
names = g_malloc0 (sizeof (gchar *) * (g_list_length (list) + 1));
i = 0;
for (l = list; l; l = l->next)
- names[i++] = g_strdup (l->data);
+ names[i++] = g_strdup (l->data);
g_list_free (list);
return names;
* @namespace_: GI namespace to use, e.g. "Gtk"
*
* If namespace @namespace_ is loaded, return the full path to the
- * .typelib file it was loaded from. If the typelib for
+ * .typelib file it was loaded from. If the typelib for
* namespace @namespace_ was included in a shared library, return
* the special string "$lt;builtin$gt;".
*
* Returns: Filesystem path (or $lt;builtin$gt;) if successful, %NULL if namespace is not loaded
*/
-const gchar *
+const gchar *
g_irepository_get_typelib_path (GIRepository *repository,
const gchar *namespace)
{
{
if (!g_hash_table_lookup_extended (repository->priv->lazy_typelibs, namespace,
&orig_key, &value))
-
+
return NULL;
}
return ((char*)orig_key) + strlen ((char *) orig_key) + 1;
GError *error = NULL;
GMappedFile *mfile = NULL;
char *fname;
-
+
fname = g_strdup_printf ("%s-%s.typelib", namespace, version);
tmp_path = build_search_path_with_overrides ();
for (ldir = tmp_path; ldir; ldir = ldir->next)
{
char *path = g_build_filename (ldir->data, fname, NULL);
-
+
mfile = g_mapped_file_new (path, FALSE, &error);
if (error)
{
return -1;
else if (result < 0)
return 1;
- else
+ else
{
/* Now check the path index, which says how early in the search path
* we found it. This ensures that of equal version targets, we
namespace_typelib = g_strdup_printf ("%s.typelib", namespace);
index = 0;
- tmp_path = build_search_path_with_overrides ();
+ tmp_path = build_search_path_with_overrides ();
for (ldir = tmp_path; ldir; ldir = ldir->next)
{
GDir *dir;
dir = g_dir_open (dirname, 0, NULL);
if (dir == NULL)
continue;
- while ((entry = g_dir_read_name (dir)) != NULL)
+ while ((entry = g_dir_read_name (dir)) != NULL)
{
GMappedFile *mfile;
char *path, *version;
if (!g_str_has_suffix (entry, ".typelib"))
continue;
-
+
if (g_str_has_prefix (entry, namespace_dash))
{
const char *last_dash;
{
struct NamespaceVersionCandidadate *elected;
candidates = g_slist_sort (candidates, (GCompareFunc) compare_candidate_reverse);
-
+
elected = (struct NamespaceVersionCandidadate *) candidates->data;
/* Remove the elected one so we don't try to free its contents */
candidates = g_slist_delete_link (candidates, candidates);
-
+
result = elected->mfile;
*path_ret = elected->path;
*version_ret = elected->version;
g_free (elected); /* just free the container */
g_slist_foreach (candidates, (GFunc) free_candidate, NULL);
g_slist_free (candidates);
- }
+ }
g_free (namespace_dash);
g_free (namespace_typelib);
- g_slist_free (tmp_path);
+ g_slist_free (tmp_path);
return result;
}
repository = get_repository (repository);
- typelib = get_registered_status (repository, namespace, version, allow_lazy,
+ typelib = get_registered_status (repository, namespace, version, allow_lazy,
&is_lazy, &version_conflict);
if (typelib)
return typelib;
{
mfile = find_namespace_latest (namespace, &tmp_version, &path);
}
-
+
if (mfile == NULL)
{
if (version != NULL)
header = (Header *) typelib->data;
typelib_namespace = g_typelib_get_string (typelib, header->namespace);
typelib_version = g_typelib_get_string (typelib, header->nsversion);
-
+
if (strcmp (typelib_namespace, namespace) != 0)
{
g_set_error (error, G_IREPOSITORY_ERROR,
goto out;
}
- if (!register_internal (repository, path, allow_lazy,
+ if (!register_internal (repository, path, allow_lazy,
typelib, error))
{
g_typelib_free (typelib);
out:
g_free (tmp_version);
g_free (path);
- return ret;
+ return ret;
}
static gboolean