1 /* -*- Mode: C; c-file-style: "gnu"; -*- */
2 /* GObject introspection: Repository implementation
4 * Copyright (C) 2005 Matthias Clasen
5 * Copyright (C) 2008 Colin Walters <walters@verbum.org>
6 * Copyright (C) 2008 Red Hat, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
29 #include <glib/gprintf.h>
31 #include "girepository.h"
34 static GStaticMutex globals_lock = G_STATIC_MUTEX_INIT;
35 static GIRepository *default_repository = NULL;
36 static GSList *search_path = NULL;
38 struct _GIRepositoryPrivate
40 GHashTable *typelibs; /* (string) namespace -> GTypelib */
41 GHashTable *lazy_typelibs; /* (string) namespace-version -> GTypelib */
44 G_DEFINE_TYPE (GIRepository, g_irepository, G_TYPE_OBJECT);
47 g_irepository_init (GIRepository *repository)
49 repository->priv = G_TYPE_INSTANCE_GET_PRIVATE (repository, G_TYPE_IREPOSITORY,
51 repository->priv->typelibs
52 = g_hash_table_new_full (g_str_hash, g_str_equal,
53 (GDestroyNotify) NULL,
54 (GDestroyNotify) g_typelib_free);
55 repository->priv->lazy_typelibs
56 = g_hash_table_new (g_str_hash, g_str_equal);
60 g_irepository_finalize (GObject *object)
62 GIRepository *repository = G_IREPOSITORY (object);
64 g_hash_table_destroy (repository->priv->typelibs);
65 g_hash_table_destroy (repository->priv->lazy_typelibs);
67 (* G_OBJECT_CLASS (g_irepository_parent_class)->finalize) (G_OBJECT (repository));
71 g_irepository_class_init (GIRepositoryClass *class)
73 GObjectClass *gobject_class;
75 gobject_class = G_OBJECT_CLASS (class);
77 gobject_class->finalize = g_irepository_finalize;
79 g_type_class_add_private (class, sizeof (GIRepositoryPrivate));
85 g_static_mutex_lock (&globals_lock);
87 if (default_repository == NULL)
89 default_repository = g_object_new (G_TYPE_IREPOSITORY, NULL);
92 if (search_path == NULL)
94 const gchar *const *datadirs;
95 const gchar *const *dir;
96 const gchar *type_lib_path_env;
98 type_lib_path_env = g_getenv ("GI_TYPELIB_PATH");
101 if (type_lib_path_env)
106 custom_dirs = g_strsplit (type_lib_path_env, G_SEARCHPATH_SEPARATOR_S, 0);
111 search_path = g_slist_prepend (search_path, *d);
115 /* ownership of the array content was passed to the list */
116 g_free (custom_dirs);
119 datadirs = g_get_system_data_dirs ();
121 for (dir = datadirs; *dir; dir++)
123 char *path = g_build_filename (*dir, "girepository", NULL);
124 search_path = g_slist_prepend (search_path, path);
127 search_path = g_slist_reverse (search_path);
130 g_static_mutex_unlock (&globals_lock);
134 g_irepository_prepend_search_path (const char *directory)
137 search_path = g_slist_prepend (search_path, g_strdup (directory));
141 build_typelib_key (const char *name, const char *source)
143 GString *str = g_string_new (name);
144 g_string_append_c (str, '\0');
145 g_string_append (str, source);
146 return g_string_free (str, FALSE);
150 get_typelib_dependencies (GTypelib *typelib)
153 const char *dependencies_glob;
155 header = (Header *)typelib->data;
157 if (header->dependencies == 0)
160 dependencies_glob = g_typelib_get_string (typelib, header->dependencies);
161 return g_strsplit (dependencies_glob, "|", 0);
164 static GIRepository *
165 get_repository (GIRepository *repository)
167 if (repository != NULL)
172 return default_repository;
177 check_version_conflict (GTypelib *typelib,
178 const gchar *namespace,
179 const gchar *expected_version,
180 char **version_conflict)
183 const char *loaded_version;
185 if (expected_version == NULL)
187 if (version_conflict)
188 *version_conflict = NULL;
192 header = (Header*)typelib->data;
193 loaded_version = g_typelib_get_string (typelib, header->nsversion);
194 g_assert (loaded_version != NULL);
196 if (strcmp (expected_version, loaded_version) != 0)
198 if (version_conflict)
199 *version_conflict = (char*)loaded_version;
202 if (version_conflict)
203 *version_conflict = NULL;
208 get_registered_status (GIRepository *repository,
209 const char *namespace,
212 gboolean *lazy_status,
213 char **version_conflict)
216 repository = get_repository (repository);
218 *lazy_status = FALSE;
219 typelib = g_hash_table_lookup (repository->priv->typelibs, namespace);
221 return check_version_conflict (typelib, namespace, version, version_conflict);
222 typelib = g_hash_table_lookup (repository->priv->lazy_typelibs, namespace);
229 return check_version_conflict (typelib, namespace, version, version_conflict);
233 get_registered (GIRepository *repository,
234 const char *namespace,
237 return get_registered_status (repository, namespace, version, TRUE, NULL, NULL);
241 load_dependencies_recurse (GIRepository *repository,
247 dependencies = get_typelib_dependencies (typelib);
249 if (dependencies != NULL)
253 for (i = 0; dependencies[i]; i++)
255 char *dependency = dependencies[i];
256 const char *last_dash;
257 char *dependency_namespace;
258 const char *dependency_version;
260 last_dash = strrchr (dependency, '-');
261 dependency_namespace = g_strndup (dependency, last_dash - dependency);
262 dependency_version = last_dash+1;
264 if (!g_irepository_require (repository, dependency_namespace, dependency_version,
267 g_free (dependency_namespace);
268 g_strfreev (dependencies);
271 g_free (dependency_namespace);
273 g_strfreev (dependencies);
279 register_internal (GIRepository *repository,
286 const gchar *namespace;
287 const gchar *version;
289 g_return_val_if_fail (typelib != NULL, FALSE);
291 header = (Header *)typelib->data;
293 g_return_val_if_fail (header != NULL, FALSE);
295 namespace = g_typelib_get_string (typelib, header->namespace);
296 version = g_typelib_get_string (typelib, header->nsversion);
300 g_assert (!g_hash_table_lookup (repository->priv->lazy_typelibs,
302 g_hash_table_insert (repository->priv->lazy_typelibs,
303 build_typelib_key (namespace, source), (void *)typelib);
310 /* First, try loading all the dependencies */
311 if (!load_dependencies_recurse (repository, typelib, error))
314 /* Check if we are transitioning from lazily loaded state */
315 if (g_hash_table_lookup_extended (repository->priv->lazy_typelibs,
317 (gpointer)&key, &value))
318 g_hash_table_remove (repository->priv->lazy_typelibs, key);
320 key = build_typelib_key (namespace, source);
322 g_hash_table_insert (repository->priv->typelibs, key, (void *)typelib);
325 if (typelib->modules == NULL)
326 typelib->modules = g_list_append(typelib->modules, g_module_open (NULL, 0));
332 * g_irepository_get_dependencies
333 * @repository: A #GIRepository, may be %NULL for the default
334 * @namespace: Namespace of interest
336 * Return an array of all (transitive) dependencies for namespace
337 * @namespace, including version. The returned strings are of the
338 * form <code>namespace-version</code>.
340 * Note: The namespace must have already been loaded using a function
341 * such as #g_irepository_require before calling this function.
343 * Returns: Zero-terminated string array of versioned dependencies
346 g_irepository_get_dependencies (GIRepository *repository,
347 const char *namespace)
351 g_return_val_if_fail (namespace != NULL, NULL);
353 repository = get_repository (repository);
355 typelib = get_registered (repository, namespace, NULL);
356 g_return_val_if_fail (typelib != NULL, NULL);
358 return get_typelib_dependencies (typelib);
362 g_irepository_load_typelib (GIRepository *repository,
364 GIRepositoryLoadFlags flags,
368 const char *namespace;
369 const char *nsversion;
370 gboolean allow_lazy = flags & G_IREPOSITORY_LOAD_FLAG_LAZY;
372 char *version_conflict;
374 repository = get_repository (repository);
376 header = (Header *) typelib->data;
377 namespace = g_typelib_get_string (typelib, header->namespace);
378 nsversion = g_typelib_get_string (typelib, header->nsversion);
380 if (get_registered_status (repository, namespace, nsversion, allow_lazy,
381 &is_lazy, &version_conflict))
383 if (version_conflict != NULL)
385 g_set_error (error, G_IREPOSITORY_ERROR,
386 G_IREPOSITORY_ERROR_NAMESPACE_VERSION_CONFLICT,
387 "Attempting to load namespace '%s', version '%s', but '%s' is already loaded",
388 namespace, nsversion, version_conflict);
393 return register_internal (repository, "<builtin>",
394 allow_lazy, typelib, error);
398 * g_irepository_is_registered
399 * @repository: A #GIRepository, may be %NULL for the default
400 * @namespace: Namespace of interest
401 * @version: <allow-none>: Required version, may be %NULL for latest
403 * Check whether a particular namespace (and optionally, a specific
404 * version thereof) is currently loaded. This function is likely to
405 * only be useful in unusual circumstances; in order to act upon
406 * metadata in the namespace, you should call #g_irepository_require
407 * instead which will ensure the namespace is loaded, and return as
408 * quickly as this function will if it has already been loaded.
410 * Returns: %TRUE if namespace-version is loaded, %FALSE otherwise
413 g_irepository_is_registered (GIRepository *repository,
414 const gchar *namespace,
415 const gchar *version)
417 repository = get_repository (repository);
418 return get_registered (repository, namespace, version) != NULL;
422 * g_irepository_get_default
424 * Returns the singleton process-global default #GIRepository. It is
425 * not currently supported to have multiple repositories in a
426 * particular process, but this function is provided in the unlikely
427 * eventuality that it would become possible, and as a convenience for
428 * higher level language bindings to conform to the GObject method
431 * All methods on #GIRepository also accept %NULL as an instance
432 * parameter to mean this default repository, which is usually more
435 * Returns: The global singleton #GIRepository
438 g_irepository_get_default (void)
440 return get_repository (NULL);
444 * g_irepository_get_n_infos
445 * @repository: A #GIRepository, may be %NULL for the default
446 * @namespace: Namespace to inspect
448 * This function returns the number of metadata entries in
449 * given namespace @namespace. The namespace must have
450 * already been loaded before calling this function.
452 * Returns: number of metadata entries
455 g_irepository_get_n_infos (GIRepository *repository,
456 const gchar *namespace)
459 gint n_interfaces = 0;
461 g_return_val_if_fail (namespace != NULL, -1);
463 repository = get_repository (repository);
465 typelib = get_registered (repository, namespace, NULL);
467 g_return_val_if_fail (typelib != NULL, -1);
469 n_interfaces = ((Header *)typelib->data)->n_local_entries;
483 find_interface (gpointer key,
488 GTypelib *typelib = (GTypelib *)value;
489 IfaceData *iface_data = (IfaceData *)data;
497 n_entries = ((Header *)typelib->data)->n_local_entries;
499 if (iface_data->name)
501 for (i = 1; i <= n_entries; i++)
503 entry = g_typelib_get_dir_entry (typelib, i);
504 name = g_typelib_get_string (typelib, entry->name);
505 if (strcmp (name, iface_data->name) == 0)
512 else if (iface_data->type)
514 for (i = 1; i <= n_entries; i++)
516 RegisteredTypeBlob *blob;
518 entry = g_typelib_get_dir_entry (typelib, i);
519 if (!BLOB_IS_REGISTERED_TYPE (entry))
522 blob = (RegisteredTypeBlob *)(&typelib->data[entry->offset]);
523 if (!blob->gtype_name)
526 type = g_typelib_get_string (typelib, blob->gtype_name);
527 if (strcmp (type, iface_data->type) == 0)
534 else if (iface_data->index > n_entries)
535 iface_data->index -= n_entries;
536 else if (iface_data->index > 0)
538 index = iface_data->index;
539 iface_data->index = 0;
544 entry = g_typelib_get_dir_entry (typelib, index);
545 iface_data->iface = g_info_new (entry->blob_type, NULL,
546 typelib, entry->offset);
551 * g_irepository_get_info
552 * @repository: A #GIRepository, may be %NULL for the default
553 * @namespace: Namespace to inspect
554 * @index: Offset into namespace metadata for entry
556 * This function returns a particular metadata entry in the
557 * given namespace @namespace. The namespace must have
558 * already been loaded before calling this function.
560 * Returns: #GIBaseInfo containing metadata
563 g_irepository_get_info (GIRepository *repository,
564 const gchar *namespace,
570 g_return_val_if_fail (namespace != NULL, NULL);
572 repository = get_repository (repository);
576 data.index = index + 1;
579 typelib = get_registered (repository, namespace, NULL);
581 g_return_val_if_fail (typelib != NULL, NULL);
583 find_interface ((void *)namespace, typelib, &data);
589 * g_irepository_find_by_gtype
590 * @repository: A #GIRepository, may be %NULL for the default
591 * @type: GType to search for
593 * Searches all loaded namespaces for a particular #GType. Note that
594 * in order to locate the metadata, the namespace corresponding to
595 * the type must first have been loaded. There is currently no
596 * mechanism for determining the namespace which corresponds to an
597 * arbitrary GType - thus, this function will function most reliably
598 * when you have expect the GType to be from a known namespace.
600 * Returns: #GIBaseInfo representing metadata about @type, or %NULL
603 g_irepository_find_by_gtype (GIRepository *repository,
608 repository = get_repository (repository);
611 data.type = g_type_name (type);
615 g_hash_table_foreach (repository->priv->typelibs, find_interface, &data);
616 g_hash_table_foreach (repository->priv->lazy_typelibs, find_interface, &data);
622 * g_irepository_find_by_name
623 * @repository: A #GIRepository, may be %NULL for the default
624 * @namespace: Namespace which will be searched
625 * @name: Entry name to find
627 * Searches for a particular entry in a namespace. Before calling
628 * this function for a particular namespace, you must call
629 * #g_irepository_require once to load the namespace, or otherwise
630 * ensure the namespace has already been loaded.
632 * Returns: #GIBaseInfo representing metadata about @name, or %NULL
635 g_irepository_find_by_name (GIRepository *repository,
636 const gchar *namespace,
642 g_return_val_if_fail (namespace != NULL, NULL);
644 repository = get_repository (repository);
651 typelib = get_registered (repository, namespace, NULL);
653 g_return_val_if_fail (typelib != NULL, NULL);
655 find_interface ((void *)namespace, typelib, &data);
661 collect_namespaces (gpointer key,
667 *list = g_list_append (*list, key);
671 * g_irepository_get_namespaces
672 * @repository: A #GIRepository, may be %NULL for the default
674 * Return the list of currently loaded namespaces.
676 * Returns: <utf8,transfer>: List of namespaces
679 g_irepository_get_loaded_namespaces (GIRepository *repository)
681 GList *l, *list = NULL;
685 repository = get_repository (repository);
687 g_hash_table_foreach (repository->priv->typelibs, collect_namespaces, &list);
688 g_hash_table_foreach (repository->priv->lazy_typelibs, collect_namespaces, &list);
690 names = g_malloc0 (sizeof (gchar *) * (g_list_length (list) + 1));
692 for (l = list; l; l = l->next)
693 names[i++] = g_strdup (l->data);
700 * g_irepository_get_version
701 * @repository: A #GIRepository, may be %NULL for the default
702 * @namespace: Namespace to inspect
704 * This function returns the loaded version associated with the given
705 * namespace @namespace.
707 * Note: The namespace must have already been loaded using a function
708 * such as #g_irepository_require before calling this function.
710 * Returns: Loaded version
713 g_irepository_get_version (GIRepository *repository,
714 const gchar *namespace)
719 g_return_val_if_fail (namespace != NULL, NULL);
721 repository = get_repository (repository);
723 typelib = get_registered (repository, namespace, NULL);
725 g_return_val_if_fail (typelib != NULL, NULL);
727 header = (Header *) typelib->data;
728 return g_typelib_get_string (typelib, header->nsversion);
732 * g_irepository_get_shared_library
733 * @repository: A #GIRepository, may be %NULL for the default
734 * @namespace: Namespace to inspect
736 * This function returns the full path to the shared C library
737 * associated with the given namespace @namespace. There may be no
738 * shared library path associated, in which case this function will
741 * Note: The namespace must have already been loaded using a function
742 * such as #g_irepository_require before calling this function.
744 * Returns: Full path to shared library, or %NULL if none associated
747 g_irepository_get_shared_library (GIRepository *repository,
748 const gchar *namespace)
753 g_return_val_if_fail (namespace != NULL, NULL);
755 repository = get_repository (repository);
757 typelib = get_registered (repository, namespace, NULL);
759 g_return_val_if_fail (typelib != NULL, NULL);
761 header = (Header *) typelib->data;
762 if (header->shared_library)
763 return g_typelib_get_string (typelib, header->shared_library);
769 * g_irepository_get_typelib_path
770 * @repository: Repository, may be %NULL for the default
771 * @namespace: GI namespace to use, e.g. "Gtk"
772 * @version: <allow-none>: Version of namespace to use, e.g. "0.8", may be %NULL
774 * If namespace @namespace is loaded, return the full path to the
775 * .typelib file it was loaded from. If the typelib for
776 * namespace @namespace was included in a shared library, return
777 * the special string "<builtin>".
779 * Returns: Filesystem path (or <builtin>) if successful, %NULL if namespace is not loaded
783 g_irepository_get_typelib_path (GIRepository *repository,
784 const gchar *namespace)
786 gpointer orig_key, value;
788 repository = get_repository (repository);
790 if (!g_hash_table_lookup_extended (repository->priv->typelibs, namespace,
793 if (!g_hash_table_lookup_extended (repository->priv->lazy_typelibs, namespace,
798 return ((char*)orig_key) + strlen ((char *) orig_key) + 1;
801 /* This simple search function looks for a specified namespace-version;
802 it's faster than the full directory listing required for latest version. */
804 find_namespace_version (const gchar *namespace,
805 const gchar *version,
809 GError *error = NULL;
810 GMappedFile *mfile = NULL;
813 fname = g_strdup_printf ("%s-%s.typelib", namespace, version);
815 for (ldir = search_path; ldir; ldir = ldir->next)
817 char *path = g_build_filename (ldir->data, fname, NULL);
819 mfile = g_mapped_file_new (path, FALSE, &error);
823 g_clear_error (&error);
834 parse_version (const char *version,
841 *major = strtol (version, &end, 10);
842 dot = strchr (version, '.');
850 *minor = strtol (dot+1, &end, 10);
851 if (end != (version + strlen (version)))
857 compare_version (const char *v1,
861 int v1_major, v1_minor;
862 int v2_major, v2_minor;
864 success = parse_version (v1, &v1_major, &v1_minor);
867 success = parse_version (v2, &v2_major, &v2_minor);
870 if (v1_major > v2_major)
872 else if (v2_major > v1_major)
874 else if (v1_minor > v2_minor)
876 else if (v2_minor > v1_minor)
881 struct NamespaceVersionCandidadate
890 compare_candidate_reverse (struct NamespaceVersionCandidadate *c1,
891 struct NamespaceVersionCandidadate *c2)
893 int result = compare_version (c1->version, c2->version);
894 /* First, check the version */
901 /* Now check the path index, which says how early in the search path
902 * we found it. This ensures that of equal version targets, we
903 * pick the earlier one.
905 if (c1->path_index == c2->path_index)
907 else if (c1->path_index > c2->path_index)
915 free_candidate (struct NamespaceVersionCandidadate *candidate)
917 g_mapped_file_free (candidate->mfile);
918 g_free (candidate->path);
919 g_free (candidate->version);
924 find_namespace_latest (const gchar *namespace,
929 GError *error = NULL;
930 char *namespace_dash;
931 char *namespace_typelib;
932 GSList *candidates = NULL;
933 GMappedFile *result = NULL;
939 namespace_dash = g_strdup_printf ("%s-", namespace);
940 namespace_typelib = g_strdup_printf ("%s.typelib", namespace);
943 for (ldir = search_path; ldir; ldir = ldir->next)
949 dirname = (const char*)ldir->data;
950 dir = g_dir_open (dirname, 0, NULL);
953 while ((entry = g_dir_read_name (dir)) != NULL)
956 char *path, *version;
957 struct NamespaceVersionCandidadate *candidate;
959 if (!g_str_has_suffix (entry, ".typelib"))
962 if (g_str_has_prefix (entry, namespace_dash))
964 const char *last_dash;
965 const char *name_end;
968 name_end = strrchr (entry, '.');
969 last_dash = strrchr (entry, '-');
970 version = g_strndup (last_dash+1, name_end-(last_dash+1));
971 if (!parse_version (version, &major, &minor))
977 path = g_build_filename (dirname, entry, NULL);
978 mfile = g_mapped_file_new (path, FALSE, &error);
983 g_clear_error (&error);
986 candidate = g_new0 (struct NamespaceVersionCandidadate, 1);
987 candidate->mfile = mfile;
988 candidate->path_index = index;
989 candidate->path = path;
990 candidate->version = version;
991 candidates = g_slist_prepend (candidates, candidate);
997 if (candidates != NULL)
999 struct NamespaceVersionCandidadate *elected;
1000 candidates = g_slist_sort (candidates, (GCompareFunc) compare_candidate_reverse);
1002 elected = (struct NamespaceVersionCandidadate *) candidates->data;
1003 /* Remove the elected one so we don't try to free it */
1004 candidates = g_slist_delete_link (candidates, candidates);
1006 result = elected->mfile;
1007 *path_ret = elected->path;
1008 *version_ret = elected->version;
1009 g_slist_foreach (candidates, (GFunc) free_candidate, NULL);
1010 g_slist_free (candidates);
1013 g_free (namespace_dash);
1014 g_free (namespace_typelib);
1019 * g_irepository_require
1020 * @repository: <allow-none>: Repository, may be %NULL for the default
1021 * @namespace: GI namespace to use, e.g. "Gtk"
1022 * @version: <allow-none>: Version of namespace, may be %NULL for latest
1023 * @flags: Set of %GIRepositoryLoadFlags, may be %0
1024 * @error: a #GError.
1026 * Force the namespace @namespace to be loaded if it isn't already.
1027 * If @namespace is not loaded, this function will search for a
1028 * ".typelib" file using the repository search path. In addition, a
1029 * version @version of namespace may be specified. If @version is
1030 * not specified, the latest will be used.
1032 * Returns: %TRUE if successful, %NULL otherwise
1035 g_irepository_require (GIRepository *repository,
1036 const gchar *namespace,
1037 const gchar *version,
1038 GIRepositoryLoadFlags flags,
1042 gboolean ret = FALSE;
1044 GTypelib *typelib = NULL;
1045 const gchar *typelib_namespace, *typelib_version;
1046 gboolean allow_lazy = (flags & G_IREPOSITORY_LOAD_FLAG_LAZY) > 0;
1048 char *version_conflict = NULL;
1050 char *tmp_version = NULL;
1052 g_return_val_if_fail (namespace != NULL, FALSE);
1054 repository = get_repository (repository);
1056 if (get_registered_status (repository, namespace, version, allow_lazy,
1057 &is_lazy, &version_conflict))
1060 if (version_conflict != NULL)
1062 g_set_error (error, G_IREPOSITORY_ERROR,
1063 G_IREPOSITORY_ERROR_NAMESPACE_VERSION_CONFLICT,
1064 "Requiring namespace '%s' version '%s', but '%s' is already loaded",
1065 namespace, version, version_conflict);
1069 if (version != NULL)
1071 mfile = find_namespace_version (namespace, version, &path);
1072 tmp_version = g_strdup (version);
1076 mfile = find_namespace_latest (namespace, &tmp_version, &path);
1081 if (version != NULL)
1082 g_set_error (error, G_IREPOSITORY_ERROR,
1083 G_IREPOSITORY_ERROR_TYPELIB_NOT_FOUND,
1084 "Typelib file for namespace '%s', version '%s' not found",
1085 namespace, version);
1087 g_set_error (error, G_IREPOSITORY_ERROR,
1088 G_IREPOSITORY_ERROR_TYPELIB_NOT_FOUND,
1089 "Typelib file for namespace '%s' (any version) not found",
1094 typelib = g_typelib_new_from_mapped_file (mfile);
1095 header = (Header *) typelib->data;
1096 typelib_namespace = g_typelib_get_string (typelib, header->namespace);
1097 typelib_version = g_typelib_get_string (typelib, header->nsversion);
1099 if (strcmp (typelib_namespace, namespace) != 0)
1101 g_set_error (error, G_IREPOSITORY_ERROR,
1102 G_IREPOSITORY_ERROR_NAMESPACE_MISMATCH,
1103 "Typelib file %s for namespace '%s' contains "
1104 "namespace '%s' which doesn't match the file name",
1105 path, namespace, typelib_namespace);
1108 if (version != NULL && strcmp (typelib_version, version) != 0)
1110 g_set_error (error, G_IREPOSITORY_ERROR,
1111 G_IREPOSITORY_ERROR_NAMESPACE_MISMATCH,
1112 "Typelib file %s for namespace '%s' contains "
1113 "version '%s' which doesn't match the expected version '%s'",
1114 path, namespace, typelib_version, version);
1118 if (!register_internal (repository, path, allow_lazy,
1121 g_typelib_free (typelib);
1126 g_free (tmp_version);
1133 g_irepository_error_quark (void)
1135 static GQuark quark = 0;
1137 quark = g_quark_from_static_string ("g-irepository-error-quark");
1142 g_type_tag_to_string (GITypeTag type)
1146 case GI_TYPE_TAG_VOID:
1148 case GI_TYPE_TAG_BOOLEAN:
1150 case GI_TYPE_TAG_INT8:
1152 case GI_TYPE_TAG_UINT8:
1154 case GI_TYPE_TAG_INT16:
1156 case GI_TYPE_TAG_UINT16:
1158 case GI_TYPE_TAG_INT32:
1160 case GI_TYPE_TAG_UINT32:
1162 case GI_TYPE_TAG_INT64:
1164 case GI_TYPE_TAG_UINT64:
1166 case GI_TYPE_TAG_INT:
1168 case GI_TYPE_TAG_UINT:
1170 case GI_TYPE_TAG_LONG:
1172 case GI_TYPE_TAG_ULONG:
1174 case GI_TYPE_TAG_SSIZE:
1176 case GI_TYPE_TAG_SIZE:
1178 case GI_TYPE_TAG_FLOAT:
1180 case GI_TYPE_TAG_DOUBLE:
1182 case GI_TYPE_TAG_TIME_T:
1184 case GI_TYPE_TAG_GTYPE:
1186 case GI_TYPE_TAG_UTF8:
1188 case GI_TYPE_TAG_FILENAME:
1190 case GI_TYPE_TAG_ARRAY:
1192 case GI_TYPE_TAG_INTERFACE:
1194 case GI_TYPE_TAG_GLIST:
1196 case GI_TYPE_TAG_GSLIST:
1198 case GI_TYPE_TAG_GHASH:
1200 case GI_TYPE_TAG_ERROR: