~ubuntu-branches/ubuntu/trusty/gobject-introspection/trusty

« back to all changes in this revision

Viewing changes to girepository/gdump.c

  • Committer: Bazaar Package Importer
  • Author(s): Emilio Pozuelo Monfort
  • Date: 2011-03-22 00:32:36 UTC
  • mfrom: (1.4.1 upstream) (3.3.33 multiarch)
  • Revision ID: james.westby@ubuntu.com-20110322003236-4spdgfk1vai6xay1
Tags: 0.10.4-2
Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <glib-object.h>
25
25
#include <gio/gio.h>
26
26
 
 
27
/* This file is both compiled into libgirepository.so, and installed
 
28
 * on the filesystem.  But for the dumper, we want to avoid linking
 
29
 * to libgirepository; see
 
30
 * https://bugzilla.gnome.org/show_bug.cgi?id=630342
 
31
 */
 
32
#ifdef G_IREPOSITORY_COMPILATION
 
33
#include "config.h"
27
34
#include "girepository.h"
28
 
#include "config.h"
 
35
#endif
29
36
 
30
37
#include <string.h>
31
38
 
68
75
invoke_get_type (GModule *self, const char *symbol, GError **error)
69
76
{
70
77
  GetTypeFunc sym;
 
78
  GType ret;
71
79
 
72
80
  if (!g_module_symbol (self, symbol, (void**)&sym))
73
81
    {
78
86
      return G_TYPE_INVALID;
79
87
    }
80
88
 
81
 
  return sym ();
 
89
  ret = sym ();
 
90
  if (ret == G_TYPE_INVALID)
 
91
    {
 
92
      g_set_error (error,
 
93
                   G_IO_ERROR,
 
94
                   G_IO_ERROR_FAILED,
 
95
                   "Function '%s' returned G_TYPE_INVALID", symbol);
 
96
    }
 
97
  return ret;
82
98
}
83
99
 
84
100
static void
159
175
      GType parent;
160
176
      gboolean first = TRUE;
161
177
 
162
 
      parent = type;
 
178
      parent = g_type_parent (type);
163
179
      parent_str = g_string_new ("");
164
 
      do
 
180
      while (parent != G_TYPE_OBJECT && parent != G_TYPE_INVALID)
165
181
        {
166
 
          parent = g_type_parent (parent);
167
182
          if (first)
168
183
            first = FALSE;
169
184
          else
170
185
            g_string_append_c (parent_str, ',');
171
186
          g_string_append (parent_str, g_type_name (parent));
172
 
        } while (parent != G_TYPE_OBJECT && parent != G_TYPE_INVALID);
 
187
          parent = g_type_parent (parent);
 
188
        }
173
189
 
174
190
      escaped_printf (out, " parents=\"%s\"", parent_str->str);
175
191
 
271
287
}
272
288
 
273
289
static void
 
290
dump_fundamental_type (GType type, const char *symbol, GOutputStream *out)
 
291
{
 
292
  guint n_interfaces;
 
293
  guint i;
 
294
  GType *interfaces;
 
295
  GString *parent_str;
 
296
  GType parent;
 
297
  gboolean first = TRUE;
 
298
 
 
299
 
 
300
  escaped_printf (out, "  <fundamental name=\"%s\" get-type=\"%s\"",
 
301
                  g_type_name (type), symbol);
 
302
 
 
303
  if (G_TYPE_IS_ABSTRACT (type))
 
304
    escaped_printf (out, " abstract=\"1\"");
 
305
 
 
306
  if (G_TYPE_IS_INSTANTIATABLE (type))
 
307
    escaped_printf (out, " instantiatable=\"1\"");
 
308
 
 
309
  parent = g_type_parent (type);
 
310
  parent_str = g_string_new ("");
 
311
  while (parent != G_TYPE_INVALID)
 
312
    {
 
313
      if (first)
 
314
        first = FALSE;
 
315
      else
 
316
        g_string_append_c (parent_str, ',');
 
317
      if (!g_type_name (parent))
 
318
        break;
 
319
      g_string_append (parent_str, g_type_name (parent));
 
320
      parent = g_type_parent (parent);
 
321
    }
 
322
 
 
323
  if (parent_str->len > 0)
 
324
    escaped_printf (out, " parents=\"%s\"", parent_str->str);
 
325
  g_string_free (parent_str, TRUE);
 
326
 
 
327
  goutput_write (out, ">\n");
 
328
 
 
329
  interfaces = g_type_interfaces (type, &n_interfaces);
 
330
  for (i = 0; i < n_interfaces; i++)
 
331
    {
 
332
      GType itype = interfaces[i];
 
333
      escaped_printf (out, "    <implements name=\"%s\"/>\n",
 
334
                      g_type_name (itype));
 
335
    }
 
336
  goutput_write (out, "  </fundamental>\n");
 
337
}
 
338
 
 
339
static void
274
340
dump_type (GType type, const char *symbol, GOutputStream *out)
275
341
{
276
342
  switch (g_type_fundamental (type))
294
360
      /* GValue, etc.  Just skip them. */
295
361
      break;
296
362
    default:
297
 
      /* Other fundamental types such as the once GStreamer and Clutter registers
298
 
       * are not yet interesting from an introspection perspective and should be
299
 
       * ignored
300
 
       */
 
363
      dump_fundamental_type (type, symbol, out);
301
364
      break;
302
365
    }
303
366
}
317
380
 *
318
381
 * Returns: %TRUE on success, %FALSE on error
319
382
 */
 
383
#ifndef G_IREPOSITORY_COMPILATION
 
384
static gboolean
 
385
dump_irepository (const char *arg, GError **error)
 
386
#else
320
387
gboolean
321
388
g_irepository_dump (const char *arg, GError **error)
 
389
#endif
322
390
{
323
391
  GHashTable *output_types;
324
392
  char **args;
382
450
 
383
451
      if (type == G_TYPE_INVALID)
384
452
        {
385
 
          g_printerr ("Invalid GType: '%s'\n", line);
386
453
          caught_error = TRUE;
387
454
          g_free (line);
388
455
          break;