~ubuntu-branches/ubuntu/natty/gobject-introspection/natty-201101211713

« back to all changes in this revision

Viewing changes to girepository/girepository.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Ancell
  • Date: 2010-08-10 17:55:47 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20100810175547-vurvcv4o1k3ij201
Tags: 0.9.3-0ubuntu1
* New upstream release
* debian/control:
  - Added Vcs-Bzr link
* debian/patches/01_fix_arm_ftbfs.patch:
  - Applied upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include <gmodule.h>
31
31
#include "girepository.h"
32
32
#include "gitypelib-internal.h"
33
 
#include "ginfo.h"
 
33
#include "girepository-private.h"
34
34
#include "glib-compat.h"
35
35
 
36
36
#include "config.h"
131
131
          g_free (custom_dirs);
132
132
        }
133
133
 
 
134
      if (override_search_path != NULL)
 
135
        override_search_path = g_slist_reverse (override_search_path);
 
136
 
134
137
      libdir = GOBJECT_INTROSPECTION_LIBDIR;
135
138
 
136
139
      typelib_dir = g_build_filename (libdir, "girepository-1.0", NULL);
606
609
  if (index != 0)
607
610
    {
608
611
      entry = g_typelib_get_dir_entry (typelib, index);
609
 
      iface_data->iface = g_info_new_full (entry->blob_type,
610
 
                                           iface_data->repo,
611
 
                                           NULL, typelib, entry->offset);
 
612
      iface_data->iface = _g_info_new_full (entry->blob_type,
 
613
                                            iface_data->repo,
 
614
                                            NULL, typelib, entry->offset);
612
615
    }
613
616
}
614
617
 
926
929
static GMappedFile *
927
930
find_namespace_version (const gchar  *namespace,
928
931
                        const gchar  *version,
 
932
                        GSList       *search_path,
929
933
                        gchar       **path_ret)
930
934
{
931
 
  GSList *tmp_path;
932
935
  GSList *ldir;
933
936
  GError *error = NULL;
934
937
  GMappedFile *mfile = NULL;
936
939
 
937
940
  fname = g_strdup_printf ("%s-%s.typelib", namespace, version);
938
941
 
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)
941
943
    {
942
944
      char *path = g_build_filename (ldir->data, fname, NULL);
943
945
 
952
954
      break;
953
955
    }
954
956
  g_free (fname);
955
 
  g_slist_free (tmp_path);
956
957
  return mfile;
957
958
}
958
959
 
1046
1047
  g_slice_free (struct NamespaceVersionCandidadate, candidate);
1047
1048
}
1048
1049
 
1049
 
static GMappedFile *
1050
 
find_namespace_latest (const gchar  *namespace,
1051
 
                       gchar       **version_ret,
1052
 
                       gchar       **path_ret)
 
1050
static GSList *
 
1051
enumerate_namespace_versions (const gchar *namespace,
 
1052
                              GSList      *search_path)
1053
1053
{
1054
 
  GSList *tmp_path;
1055
 
  GSList *ldir;
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;
 
1058
  GSList *ldir;
 
1059
  GError *error = NULL;
1061
1060
  int index;
1062
1061
 
1063
 
  *version_ret = NULL;
1064
 
  *path_ret = NULL;
1065
 
 
1066
1062
  namespace_dash = g_strdup_printf ("%s-", namespace);
1067
1063
  namespace_typelib = g_strdup_printf ("%s.typelib", namespace);
1068
1064
 
1069
1065
  index = 0;
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)
1072
1067
    {
1073
1068
      GDir *dir;
1074
1069
      const char *dirname;
1102
1097
          else
1103
1098
            continue;
1104
1099
 
 
1100
          if (g_hash_table_lookup (found_versions, version) != NULL)
 
1101
            continue;
 
1102
          g_hash_table_insert (found_versions, version, version);
 
1103
 
1105
1104
          path = g_build_filename (dirname, entry, NULL);
1106
1105
          mfile = g_mapped_file_new (path, FALSE, &error);
1107
1106
          if (mfile == NULL)
1122
1121
      index++;
1123
1122
    }
1124
1123
 
 
1124
  g_free (namespace_dash);
 
1125
  g_free (namespace_typelib);
 
1126
  g_hash_table_destroy (found_versions);
 
1127
 
 
1128
  return candidates;
 
1129
}
 
1130
 
 
1131
static GMappedFile *
 
1132
find_namespace_latest (const gchar  *namespace,
 
1133
                       GSList       *search_path,
 
1134
                       gchar       **version_ret,
 
1135
                       gchar       **path_ret)
 
1136
{
 
1137
  GSList *candidates;
 
1138
  GMappedFile *result = NULL;
 
1139
 
 
1140
  *version_ret = NULL;
 
1141
  *path_ret = NULL;
 
1142
 
 
1143
  candidates = enumerate_namespace_versions (namespace, search_path);
 
1144
 
1125
1145
  if (candidates != NULL)
1126
1146
    {
1127
1147
      struct NamespaceVersionCandidadate *elected;
1138
1158
      g_slist_foreach (candidates, (GFunc) free_candidate, NULL);
1139
1159
      g_slist_free (candidates);
1140
1160
    }
1141
 
  g_free (namespace_dash);
1142
 
  g_free (namespace_typelib);
1143
 
  g_slist_free (tmp_path);
1144
1161
  return result;
1145
1162
}
1146
1163
 
1147
1164
/**
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.
1154
 
 *
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.
1160
 
 *
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"
 
1168
 *
 
1169
 * Obtain a list of versions for @namespace_ in this @repository.
 
1170
 *
 
1171
 * Returns: (element-type utf8) (transfer full): the array of versions.
1162
1172
 */
1163
 
GTypelib *
1164
 
g_irepository_require (GIRepository  *repository,
1165
 
                       const gchar   *namespace,
1166
 
                       const gchar   *version,
1167
 
                       GIRepositoryLoadFlags flags,
1168
 
                       GError       **error)
 
1173
GList *
 
1174
g_irepository_enumerate_versions (GIRepository *repository,
 
1175
                         const gchar  *namespace_)
 
1176
{
 
1177
  GList *ret = NULL;
 
1178
  GSList *search_path;
 
1179
  GSList *candidates, *link;
 
1180
 
 
1181
  search_path = build_search_path_with_overrides ();
 
1182
  candidates = enumerate_namespace_versions (namespace_, search_path);
 
1183
  g_slist_free (search_path);
 
1184
 
 
1185
  for (link = candidates; link; link = link->next)
 
1186
    {
 
1187
      struct NamespaceVersionCandidadate *candidate = link->data;
 
1188
      ret = g_list_append (ret, g_strdup (candidate->version));
 
1189
      free_candidate (candidate);
 
1190
    }
 
1191
  g_slist_free (candidates);
 
1192
  return ret;
 
1193
}
 
1194
 
 
1195
static GTypelib *
 
1196
require_internal (GIRepository  *repository,
 
1197
                  const gchar   *namespace,
 
1198
                  const gchar   *version,
 
1199
                  GIRepositoryLoadFlags flags,
 
1200
                  GSList        *search_path,
 
1201
                  GError       **error)
1169
1202
{
1170
1203
  GMappedFile *mfile;
1171
1204
  GTypelib *ret = NULL;
1198
1231
 
1199
1232
  if (version != NULL)
1200
1233
    {
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);
1203
1237
    }
1204
1238
  else
1205
1239
    {
1206
 
      mfile = find_namespace_latest (namespace, &tmp_version, &path);
 
1240
      mfile = find_namespace_latest (namespace, search_path,
 
1241
                                     &tmp_version, &path);
1207
1242
    }
1208
1243
 
1209
1244
  if (mfile == NULL)
1221
1256
      goto out;
1222
1257
    }
1223
1258
 
1224
 
  typelib = g_typelib_new_from_mapped_file (mfile);
 
1259
  {
 
1260
    GError *temp_error = NULL;
 
1261
    typelib = g_typelib_new_from_mapped_file (mfile, &temp_error);
 
1262
    if (!typelib)
 
1263
      {
 
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);
 
1269
        goto out;
 
1270
      }
 
1271
  }
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);
1236
1284
      goto out;
1237
1285
    }
1238
1286
  if (version != NULL && strcmp (typelib_version, version) != 0)
1242
1290
                   "Typelib file %s for namespace '%s' contains "
1243
1291
                   "version '%s' which doesn't match the expected version '%s'",
1244
1292
                   path, namespace, typelib_version, version);
 
1293
      g_typelib_free (typelib);
1245
1294
      goto out;
1246
1295
    }
1247
1296
 
1258
1307
  return ret;
1259
1308
}
1260
1309
 
 
1310
/**
 
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.
 
1317
 *
 
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.
 
1323
 *
 
1324
 * Returns: a pointer to the #GTypelib if successful, %NULL otherwise
 
1325
 */
 
1326
GTypelib *
 
1327
g_irepository_require (GIRepository  *repository,
 
1328
                       const gchar   *namespace,
 
1329
                       const gchar   *version,
 
1330
                       GIRepositoryLoadFlags flags,
 
1331
                       GError       **error)
 
1332
{
 
1333
  GSList *search_path;
 
1334
  GTypelib *typelib;
 
1335
 
 
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);
 
1340
 
 
1341
  return typelib;
 
1342
}
 
1343
 
 
1344
/**
 
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.
 
1352
 *
 
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.
 
1358
 *
 
1359
 * Returns: a pointer to the #GTypelib if successful, %NULL otherwise
 
1360
 */
 
1361
GTypelib *
 
1362
g_irepository_require_private (GIRepository  *repository,
 
1363
                               const gchar   *typelib_dir,
 
1364
                               const gchar   *namespace,
 
1365
                               const gchar   *version,
 
1366
                               GIRepositoryLoadFlags flags,
 
1367
                               GError       **error)
 
1368
{
 
1369
  GSList search_path = { (gpointer) typelib_dir, NULL };
 
1370
 
 
1371
  return require_internal (repository, namespace, version, flags,
 
1372
                           &search_path, error);
 
1373
}
 
1374
 
1261
1375
static gboolean
1262
1376
g_irepository_introspect_cb (const char *option_name,
1263
1377
                             const char *value,
1294
1408
  return quark;
1295
1409
}
1296
1410
 
 
1411
/**
 
1412
 * g_type_tag_to_string:
 
1413
 * @type: the type_tag
 
1414
 *
 
1415
 * Obtain a string representation of @type
 
1416
 *
 
1417
 * Returns: the string
 
1418
 */
1297
1419
const gchar*
1298
1420
g_type_tag_to_string (GITypeTag type)
1299
1421
{
1319
1441
      return "int64";
1320
1442
    case GI_TYPE_TAG_UINT64:
1321
1443
      return "uint64";
1322
 
    case GI_TYPE_TAG_SHORT:
1323
 
      return "short";
1324
 
    case GI_TYPE_TAG_USHORT:
1325
 
      return "ushort";
1326
 
    case GI_TYPE_TAG_INT:
1327
 
      return "int";
1328
 
    case GI_TYPE_TAG_UINT:
1329
 
      return "uint";
1330
 
    case GI_TYPE_TAG_LONG:
1331
 
      return "long";
1332
 
    case GI_TYPE_TAG_ULONG:
1333
 
      return "ulong";
1334
 
    case GI_TYPE_TAG_SSIZE:
1335
 
      return "ssize";
1336
 
    case GI_TYPE_TAG_SIZE:
1337
 
      return "size";
1338
1444
    case GI_TYPE_TAG_FLOAT:
1339
1445
      return "float";
1340
1446
    case GI_TYPE_TAG_DOUBLE:
1341
1447
      return "double";
1342
 
    case GI_TYPE_TAG_TIME_T:
1343
 
      return "time_t";
1344
1448
    case GI_TYPE_TAG_GTYPE:
1345
1449
      return "GType";
1346
1450
    case GI_TYPE_TAG_UTF8:
1363
1467
      return "unknown";
1364
1468
    }
1365
1469
}
 
1470
 
 
1471
/**
 
1472
 * g_info_type_to_string:
 
1473
 * @type: the info type
 
1474
 *
 
1475
 * Obtain a string representation of @type
 
1476
 *
 
1477
 * Returns: the string
 
1478
 */
 
1479
const gchar*
 
1480
g_info_type_to_string (GIInfoType type)
 
1481
{
 
1482
  switch (type)
 
1483
    {
 
1484
    case GI_INFO_TYPE_INVALID:
 
1485
      return "invalid";
 
1486
    case GI_INFO_TYPE_FUNCTION:
 
1487
      return "function";
 
1488
    case GI_INFO_TYPE_CALLBACK:
 
1489
      return "callback";
 
1490
    case GI_INFO_TYPE_STRUCT:
 
1491
      return "struct";
 
1492
    case GI_INFO_TYPE_BOXED:
 
1493
      return "boxed";
 
1494
    case GI_INFO_TYPE_ENUM:
 
1495
      return "enum";
 
1496
    case GI_INFO_TYPE_FLAGS:
 
1497
      return "flags";
 
1498
    case GI_INFO_TYPE_OBJECT:
 
1499
      return "object";
 
1500
    case GI_INFO_TYPE_INTERFACE:
 
1501
      return "interface";
 
1502
    case GI_INFO_TYPE_CONSTANT:
 
1503
      return "constant";
 
1504
    case GI_INFO_TYPE_ERROR_DOMAIN:
 
1505
      return "error domain";
 
1506
    case GI_INFO_TYPE_UNION:
 
1507
      return "union";
 
1508
    case GI_INFO_TYPE_VALUE:
 
1509
      return "value";
 
1510
    case GI_INFO_TYPE_SIGNAL:
 
1511
      return "signal";
 
1512
    case GI_INFO_TYPE_VFUNC:
 
1513
      return "vfunc";
 
1514
    case GI_INFO_TYPE_PROPERTY:
 
1515
      return "property";
 
1516
    case GI_INFO_TYPE_FIELD:
 
1517
      return "field";
 
1518
    case GI_INFO_TYPE_ARG:
 
1519
      return "arg";
 
1520
    case GI_INFO_TYPE_TYPE:
 
1521
      return "type";
 
1522
    case GI_INFO_TYPE_UNRESOLVED:
 
1523
      return "unresolved";
 
1524
    default:
 
1525
      return "unknown";
 
1526
  }
 
1527
}