608
611
entry = g_typelib_get_dir_entry (typelib, index);
609
iface_data->iface = g_info_new_full (entry->blob_type,
611
NULL, typelib, entry->offset);
612
iface_data->iface = _g_info_new_full (entry->blob_type,
614
NULL, typelib, entry->offset);
937
940
fname = g_strdup_printf ("%s-%s.typelib", namespace, version);
939
tmp_path = build_search_path_with_overrides ();
940
for (ldir = tmp_path; ldir; ldir = ldir->next)
942
for (ldir = search_path; ldir; ldir = ldir->next)
942
944
char *path = g_build_filename (ldir->data, fname, NULL);
1046
1047
g_slice_free (struct NamespaceVersionCandidadate, candidate);
1049
static GMappedFile *
1050
find_namespace_latest (const gchar *namespace,
1051
gchar **version_ret,
1051
enumerate_namespace_versions (const gchar *namespace,
1052
GSList *search_path)
1056
GError *error = NULL;
1054
GSList *candidates = NULL;
1055
GHashTable *found_versions = g_hash_table_new (g_str_hash, g_str_equal);
1057
1056
char *namespace_dash;
1058
1057
char *namespace_typelib;
1059
GSList *candidates = NULL;
1060
GMappedFile *result = NULL;
1059
GError *error = NULL;
1063
*version_ret = NULL;
1066
1062
namespace_dash = g_strdup_printf ("%s-", namespace);
1067
1063
namespace_typelib = g_strdup_printf ("%s.typelib", namespace);
1070
tmp_path = build_search_path_with_overrides ();
1071
for (ldir = tmp_path; ldir; ldir = ldir->next)
1066
for (ldir = search_path; ldir; ldir = ldir->next)
1074
1069
const char *dirname;
1100
if (g_hash_table_lookup (found_versions, version) != NULL)
1102
g_hash_table_insert (found_versions, version, version);
1105
1104
path = g_build_filename (dirname, entry, NULL);
1106
1105
mfile = g_mapped_file_new (path, FALSE, &error);
1107
1106
if (mfile == NULL)
1124
g_free (namespace_dash);
1125
g_free (namespace_typelib);
1126
g_hash_table_destroy (found_versions);
1131
static GMappedFile *
1132
find_namespace_latest (const gchar *namespace,
1133
GSList *search_path,
1134
gchar **version_ret,
1138
GMappedFile *result = NULL;
1140
*version_ret = NULL;
1143
candidates = enumerate_namespace_versions (namespace, search_path);
1125
1145
if (candidates != NULL)
1127
1147
struct NamespaceVersionCandidadate *elected;
1138
1158
g_slist_foreach (candidates, (GFunc) free_candidate, NULL);
1139
1159
g_slist_free (candidates);
1141
g_free (namespace_dash);
1142
g_free (namespace_typelib);
1143
g_slist_free (tmp_path);
1148
* g_irepository_require:
1149
* @repository: (allow-none): Repository, may be %NULL for the default
1150
* @namespace_: GI namespace to use, e.g. "Gtk"
1151
* @version: (allow-none): Version of namespace, may be %NULL for latest
1152
* @flags: Set of %GIRepositoryLoadFlags, may be 0
1153
* @error: a #GError.
1155
* Force the namespace @namespace_ to be loaded if it isn't already.
1156
* If @namespace_ is not loaded, this function will search for a
1157
* ".typelib" file using the repository search path. In addition, a
1158
* version @version of namespace may be specified. If @version is
1159
* not specified, the latest will be used.
1161
* Returns: a pointer to the #GTypelib if successful, %NULL otherwise
1165
* g_irepository_enumerate_versions:
1166
* @repository: (allow-none): the repository
1167
* @namespace_: GI namespace, e.g. "Gtk"
1169
* Obtain a list of versions for @namespace_ in this @repository.
1171
* Returns: (element-type utf8) (transfer full): the array of versions.
1164
g_irepository_require (GIRepository *repository,
1165
const gchar *namespace,
1166
const gchar *version,
1167
GIRepositoryLoadFlags flags,
1174
g_irepository_enumerate_versions (GIRepository *repository,
1175
const gchar *namespace_)
1178
GSList *search_path;
1179
GSList *candidates, *link;
1181
search_path = build_search_path_with_overrides ();
1182
candidates = enumerate_namespace_versions (namespace_, search_path);
1183
g_slist_free (search_path);
1185
for (link = candidates; link; link = link->next)
1187
struct NamespaceVersionCandidadate *candidate = link->data;
1188
ret = g_list_append (ret, g_strdup (candidate->version));
1189
free_candidate (candidate);
1191
g_slist_free (candidates);
1196
require_internal (GIRepository *repository,
1197
const gchar *namespace,
1198
const gchar *version,
1199
GIRepositoryLoadFlags flags,
1200
GSList *search_path,
1170
1203
GMappedFile *mfile;
1171
1204
GTypelib *ret = NULL;
1199
1232
if (version != NULL)
1201
mfile = find_namespace_version (namespace, version, &path);
1234
mfile = find_namespace_version (namespace, version,
1235
search_path, &path);
1202
1236
tmp_version = g_strdup (version);
1206
mfile = find_namespace_latest (namespace, &tmp_version, &path);
1240
mfile = find_namespace_latest (namespace, search_path,
1241
&tmp_version, &path);
1209
1244
if (mfile == NULL)
1224
typelib = g_typelib_new_from_mapped_file (mfile);
1260
GError *temp_error = NULL;
1261
typelib = g_typelib_new_from_mapped_file (mfile, &temp_error);
1264
g_set_error (error, G_IREPOSITORY_ERROR,
1265
G_IREPOSITORY_ERROR_TYPELIB_NOT_FOUND,
1266
"Failed to load typelib file '%s' for namespace '%s': %s",
1267
path, namespace, temp_error->message);
1268
g_clear_error (&temp_error);
1225
1272
header = (Header *) typelib->data;
1226
1273
typelib_namespace = g_typelib_get_string (typelib, header->namespace);
1227
1274
typelib_version = g_typelib_get_string (typelib, header->nsversion);
1233
1280
"Typelib file %s for namespace '%s' contains "
1234
1281
"namespace '%s' which doesn't match the file name",
1235
1282
path, namespace, typelib_namespace);
1283
g_typelib_free (typelib);
1238
1286
if (version != NULL && strcmp (typelib_version, version) != 0)
1311
* g_irepository_require:
1312
* @repository: (allow-none): Repository, may be %NULL for the default
1313
* @namespace_: GI namespace to use, e.g. "Gtk"
1314
* @version: (allow-none): Version of namespace, may be %NULL for latest
1315
* @flags: Set of %GIRepositoryLoadFlags, may be 0
1316
* @error: a #GError.
1318
* Force the namespace @namespace_ to be loaded if it isn't already.
1319
* If @namespace_ is not loaded, this function will search for a
1320
* ".typelib" file using the repository search path. In addition, a
1321
* version @version of namespace may be specified. If @version is
1322
* not specified, the latest will be used.
1324
* Returns: a pointer to the #GTypelib if successful, %NULL otherwise
1327
g_irepository_require (GIRepository *repository,
1328
const gchar *namespace,
1329
const gchar *version,
1330
GIRepositoryLoadFlags flags,
1333
GSList *search_path;
1336
search_path = build_search_path_with_overrides ();
1337
typelib = require_internal (repository, namespace, version, flags,
1338
search_path, error);
1339
g_slist_free (search_path);
1345
* g_irepository_require_private:
1346
* @repository: (allow-none): Repository, may be %NULL for the default
1347
* @typelib_dir: Private directory where to find the requested typelib
1348
* @namespace_: GI namespace to use, e.g. "Gtk"
1349
* @version: (allow-none): Version of namespace, may be %NULL for latest
1350
* @flags: Set of %GIRepositoryLoadFlags, may be 0
1351
* @error: a #GError.
1353
* Force the namespace @namespace_ to be loaded if it isn't already.
1354
* If @namespace_ is not loaded, this function will search for a
1355
* ".typelib" file within the private directory only. In addition, a
1356
* version @version of namespace should be specified. If @version is
1357
* not specified, the latest will be used.
1359
* Returns: a pointer to the #GTypelib if successful, %NULL otherwise
1362
g_irepository_require_private (GIRepository *repository,
1363
const gchar *typelib_dir,
1364
const gchar *namespace,
1365
const gchar *version,
1366
GIRepositoryLoadFlags flags,
1369
GSList search_path = { (gpointer) typelib_dir, NULL };
1371
return require_internal (repository, namespace, version, flags,
1372
&search_path, error);
1261
1375
static gboolean
1262
1376
g_irepository_introspect_cb (const char *option_name,
1263
1377
const char *value,
1363
1467
return "unknown";
1472
* g_info_type_to_string:
1473
* @type: the info type
1475
* Obtain a string representation of @type
1477
* Returns: the string
1480
g_info_type_to_string (GIInfoType type)
1484
case GI_INFO_TYPE_INVALID:
1486
case GI_INFO_TYPE_FUNCTION:
1488
case GI_INFO_TYPE_CALLBACK:
1490
case GI_INFO_TYPE_STRUCT:
1492
case GI_INFO_TYPE_BOXED:
1494
case GI_INFO_TYPE_ENUM:
1496
case GI_INFO_TYPE_FLAGS:
1498
case GI_INFO_TYPE_OBJECT:
1500
case GI_INFO_TYPE_INTERFACE:
1502
case GI_INFO_TYPE_CONSTANT:
1504
case GI_INFO_TYPE_ERROR_DOMAIN:
1505
return "error domain";
1506
case GI_INFO_TYPE_UNION:
1508
case GI_INFO_TYPE_VALUE:
1510
case GI_INFO_TYPE_SIGNAL:
1512
case GI_INFO_TYPE_VFUNC:
1514
case GI_INFO_TYPE_PROPERTY:
1516
case GI_INFO_TYPE_FIELD:
1518
case GI_INFO_TYPE_ARG:
1520
case GI_INFO_TYPE_TYPE:
1522
case GI_INFO_TYPE_UNRESOLVED:
1523
return "unresolved";