diff options
author | Dom Lachowicz <cinamod@hotmail.com> | 2006-04-19 23:45:26 +0000 |
---|---|---|
committer | Dom Lachowicz <doml@src.gnome.org> | 2006-04-19 23:45:26 +0000 |
commit | 95b463d9999ca742e608bce2b80337715d2eba86 (patch) | |
tree | 529fca9bd15def8b6f0df0874ef16a7eba8e0b70 | |
parent | 775b40432cf879f54b1cb1599ed75ef6b92d16cc (diff) | |
download | librsvg-95b463d9999ca742e608bce2b80337715d2eba86.tar.gz |
Use rsvg_return_if_fail where appropriate, to make life easier for
2006-04-19 Dom Lachowicz <cinamod@hotmail.com>
* *.[ch]: Use rsvg_return_if_fail where appropriate, to make life
easier for language bindings and to report errors more consistently
(bug #338881)
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | rsvg-base-file-util.c | 6 | ||||
-rw-r--r-- | rsvg-base.c | 21 | ||||
-rw-r--r-- | rsvg-convert.c | 28 | ||||
-rw-r--r-- | rsvg-image.c | 8 | ||||
-rw-r--r-- | rsvg-private.h | 20 | ||||
-rw-r--r-- | test-display.c | 6 |
7 files changed, 75 insertions, 20 deletions
@@ -1,3 +1,9 @@ +2006-04-19 Dom Lachowicz <cinamod@hotmail.com> + + * *.[ch]: Use rsvg_return_if_fail where appropriate, to make life + easier for language bindings and to report errors more consistently + (bug #338881) + 2006-04-17 Sebastian Rittau <srittau@jroger.in-berlin.de> * Update API documentation to match deprecated symbol list diff --git a/rsvg-base-file-util.c b/rsvg-base-file-util.c index 674c55b0..3fd049c1 100644 --- a/rsvg-base-file-util.c +++ b/rsvg-base-file-util.c @@ -33,8 +33,8 @@ rsvg_handle_fill_with_data (RsvgHandle * handle, gsize data_len, GError **error) { - g_return_val_if_fail(data != NULL, FALSE); - g_return_val_if_fail(data_len != 0, FALSE); + rsvg_return_val_if_fail(data != NULL, FALSE, error); + rsvg_return_val_if_fail(data_len != 0, FALSE, error); if(!rsvg_handle_write (handle, data, data_len, error)) return FALSE; @@ -90,7 +90,7 @@ RsvgHandle * rsvg_handle_new_from_file (const gchar *file_name, GByteArray *f; RsvgHandle * handle = NULL; - g_return_val_if_fail(file_name != NULL, NULL); + rsvg_return_val_if_fail(file_name != NULL, NULL, error); base_uri = rsvg_get_base_uri_from_filename(file_name); f = _rsvg_acquire_xlink_href_resource (file_name, base_uri, error); diff --git a/rsvg-base.c b/rsvg-base.c index a1694d00..11398469 100644 --- a/rsvg-base.c +++ b/rsvg-base.c @@ -785,7 +785,7 @@ rsvg_handle_write_impl (RsvgHandle *handle, GError *real_error = NULL; int result; - g_return_val_if_fail (handle != NULL, FALSE); + rsvg_return_val_if_fail (handle != NULL, FALSE, error); handle->priv->error = &real_error; if (handle->priv->ctxt == NULL) @@ -1082,9 +1082,10 @@ rsvg_handle_get_dimensions(RsvgHandle * handle, RsvgDimensionData * dimension_da RsvgNodeSvg * sself; RsvgBbox bbox; + g_return_if_fail(handle); g_return_if_fail(dimension_data); + memset(dimension_data, 0, sizeof(RsvgDimensionData)); - g_return_if_fail(handle); sself = (RsvgNodeSvg *)handle->priv->treebase; if(!sself) @@ -1253,7 +1254,7 @@ rsvg_handle_write (RsvgHandle *handle, gsize count, GError **error) { - g_return_val_if_fail(handle, FALSE); + rsvg_return_val_if_fail(handle, FALSE, error); if (handle->priv->first_write) { handle->priv->first_write = FALSE; @@ -1296,7 +1297,7 @@ gboolean rsvg_handle_close (RsvgHandle *handle, GError **error) { - g_return_val_if_fail(handle, FALSE); + rsvg_return_val_if_fail(handle, FALSE, error); #if HAVE_SVGZ if (handle->priv->is_gzipped) { @@ -1563,3 +1564,15 @@ void _rsvg_pop_view_box(RsvgDrawingCtx *ctx) g_free(ctx->vb_stack->data); ctx->vb_stack = g_slist_delete_link(ctx->vb_stack, ctx->vb_stack); } + +void rsvg_return_if_fail_warning (const char *pretty_function, + const char *expression, + GError **error) +{ + g_set_error (error, + RSVG_ERROR, + 0, + _("%s: assertion `%s' failed"), + pretty_function, + expression); +} diff --git a/rsvg-convert.c b/rsvg-convert.c index 7677b3fb..1db2ef5f 100644 --- a/rsvg-convert.c +++ b/rsvg-convert.c @@ -48,6 +48,16 @@ #include <cairo-svg.h> #endif +static void +display_error(GError *err) +{ + if (err) + { + g_print ("%s", err->message); + g_error_free (err); + } +} + static RsvgHandle * rsvg_handle_new_from_stdio_file (FILE * f, GError **error) @@ -125,6 +135,7 @@ main (int argc, char **argv) int keep_aspect_ratio = FALSE; char * base_uri = NULL; gboolean using_stdin = FALSE; + GError *error = NULL; int i; char **args; @@ -155,7 +166,8 @@ main (int argc, char **argv) g_option_context = g_option_context_new (_("- SVG Converter")); g_option_context_add_main_entries (g_option_context, options_table, NULL); g_option_context_set_help_enabled (g_option_context, TRUE); - if(!g_option_context_parse (g_option_context, &argc, &argv, NULL)) { + if(!g_option_context_parse (g_option_context, &argc, &argv, &error)) { + display_error (error); exit(1); } @@ -172,7 +184,7 @@ main (int argc, char **argv) output_file = fopen (output, "wb"); if (!output_file) { - fprintf (stderr, _("Error saving to file %s\n"), output); + fprintf (stderr, _("Error saving to file: %s\n"), output); exit (1); } } @@ -186,9 +198,9 @@ main (int argc, char **argv) n_args = 1; using_stdin = TRUE; } - else if (n_args > 1 && (!format || !strcmp (format, "png"))) + else if (n_args > 1 && (!format || !(!strcmp (format, "ps") || !strcmp (format, "pdf")))) { - fprintf (stderr, _("Multiple SVG files are only allowed for PDF, PS and SVG output.\n")); + fprintf (stderr, _("Multiple SVG files are only allowed for PDF and PS output.\n")); exit (1); } @@ -201,12 +213,14 @@ main (int argc, char **argv) for(i = 0; i < n_args; i++) { if (using_stdin) - rsvg = rsvg_handle_new_from_stdio_file (stdin, NULL); + rsvg = rsvg_handle_new_from_stdio_file (stdin, &error); else - rsvg = rsvg_handle_new_from_file (args[i], NULL); + rsvg = rsvg_handle_new_from_file (args[i], &error); if(!rsvg) { - fprintf (stderr, _("Error reading SVG.\n")); + fprintf (stderr, _("Error reading SVG:")); + display_error (error); + fprintf (stderr, "\n"); exit (1); } diff --git a/rsvg-image.c b/rsvg-image.c index 5f989389..0aad1092 100644 --- a/rsvg-image.c +++ b/rsvg-image.c @@ -205,7 +205,7 @@ rsvg_acquire_base64_resource (const char *data, guchar *bufptr; size_t buffer_len, buffer_max_len, data_len; - g_return_val_if_fail (data != NULL, NULL); + rsvg_return_val_if_fail (data != NULL, NULL, error); while (*data) if (*data++ == ',') break; @@ -261,7 +261,7 @@ rsvg_acquire_file_resource (const char *filename, int length; FILE *f; - g_return_val_if_fail (filename != NULL, NULL); + rsvg_return_val_if_fail (filename != NULL, NULL, error); path = rsvg_get_file_path (filename, base_uri); f = fopen (path, "rb"); @@ -315,8 +315,8 @@ rsvg_acquire_vfs_resource (const char *filename, GnomeVFSHandle *f = NULL; GnomeVFSResult res; - g_return_val_if_fail (filename != NULL, NULL); - g_return_val_if_fail (gnome_vfs_initialized (), NULL); + rsvg_return_val_if_fail (filename != NULL, NULL, error); + rsvg_return_val_if_fail (gnome_vfs_initialized (), NULL, error); res = gnome_vfs_open (&f, filename, GNOME_VFS_OPEN_READ); diff --git a/rsvg-private.h b/rsvg-private.h index 220e182b..012d0cf3 100644 --- a/rsvg-private.h +++ b/rsvg-private.h @@ -342,6 +342,26 @@ void _rsvg_pop_view_box(RsvgDrawingCtx *ctx); void rsvg_SAX_handler_struct_init (void); +void rsvg_return_if_fail_warning (const char *pretty_function, + const char *expression, + GError **error); + +#define rsvg_return_if_fail(expr, error) G_STMT_START{ \ + if G_LIKELY(expr) { } else \ + { \ + rsvg_return_if_fail_warning (__PRETTY_FUNCTION__, \ + #expr, error); \ + return; \ + }; }G_STMT_END + +#define rsvg_return_val_if_fail(expr,val,error) G_STMT_START{ \ + if G_LIKELY(expr) { } else \ + { \ + rsvg_return_if_fail_warning (__PRETTY_FUNCTION__, \ + #expr, error); \ + return (val); \ + }; }G_STMT_END + G_END_DECLS #endif diff --git a/test-display.c b/test-display.c index 2beaa9de..1056e951 100644 --- a/test-display.c +++ b/test-display.c @@ -820,14 +820,16 @@ main (int argc, char **argv) if (!info.pixbuf) { - g_print (_("Error displaying pixbuf!\n")); + g_print (_("Error displaying image: ")); if (err) { - g_print ("%s\n", err->message); + g_print ("%s", err->message); g_error_free (err); } + g_print ("\n"); + return 1; } |