Skip to content
This repository has been archived by the owner on Nov 17, 2020. It is now read-only.

Commit

Permalink
[g-ir-compiler] Slightly less lame error messages
Browse files Browse the repository at this point in the history
To make things really better we should track the line origin of
element from the .gir file (and actually we need to do better
checking in the scanner), but this is slightly less lame.
  • Loading branch information
cgwalters committed Feb 11, 2010
1 parent aaef493 commit a9e6ae8
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
34 changes: 34 additions & 0 deletions girepository/girmodule.c
Expand Up @@ -20,6 +20,7 @@

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "girmodule.h"
#include "girnode.h"
Expand Down Expand Up @@ -75,6 +76,39 @@ g_ir_module_free (GIrModule *module)
g_free (module);
}

/**
* g_ir_module_fatal:
* @module: Current module
* @line: Origin line number, or 0 if unknown
* @msg: printf-format string
* @args: Remaining arguments
*
* Report a fatal error, then exit.
*/
void
g_ir_module_fatal (GIrModule *module,
guint line,
const char *msg,
...)
{
char *formatted;

va_list args;

va_start (args, msg);

formatted = g_strdup_vprintf (msg, args);

if (line)
g_printerr ("%s-%s.gir:%d: error: %s\n", module->name, module->version, line, formatted);
else
g_printerr ("%s-%s.gir: error: %s\n", module->name, module->version, formatted);

exit (1);

va_end (args);
}

static void
add_alias_foreach (gpointer key,
gpointer value,
Expand Down
2 changes: 2 additions & 0 deletions girepository/girmodule.h
Expand Up @@ -61,6 +61,8 @@ void g_ir_module_add_include_module (GIrModule *module,
GTypelib * g_ir_module_build_typelib (GIrModule *module,
GList *modules);

void g_ir_module_fatal (GIrModule *module, guint line, const char *msg, ...) G_GNUC_PRINTF (3, 4) G_GNUC_NORETURN;

void _g_irnode_init_stats (void);
void _g_irnode_dump_stats (void);

Expand Down
2 changes: 1 addition & 1 deletion girepository/girnode.c
Expand Up @@ -1090,7 +1090,7 @@ find_entry_node (GIrModule *module,
goto out;
}

g_warning ("Entry '%s' not found", name);
g_ir_module_fatal (module, 0, "Type reference '%s' not found", name);

out:

Expand Down
2 changes: 1 addition & 1 deletion girepository/giroffsets.c
Expand Up @@ -156,7 +156,7 @@ get_interface_size_alignment (GIrNodeType *type,

if (!g_ir_find_node (module, modules, type->interface, &iface, &iface_module))
{
g_warning ("Can't resolve type '%s' for %s", type->interface, who);
g_ir_module_fatal (module, 0, "Can't resolve type '%s' for %s", type->interface, who);
*size = -1;
*alignment = -1;
return FALSE;
Expand Down

0 comments on commit a9e6ae8

Please sign in to comment.