From d4ff0ef999bb819085a2b060a79e41eecd5fce63 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Sun, 5 Nov 2000 17:02:37 +0000 Subject: [PATCH] Free the src error if the dest location is NULL - I'm pretty sure that's 2000-11-05 Havoc Pennington * gerror.c (g_propagate_error): Free the src error if the dest location is NULL - I'm pretty sure that's what this function was supposed to do. 2000-11-05 Havoc Pennington * glib/tmpl/error_reporting.sgml: fixes --- ChangeLog | 6 +++++ ChangeLog.pre-2-0 | 6 +++++ ChangeLog.pre-2-10 | 6 +++++ ChangeLog.pre-2-12 | 6 +++++ ChangeLog.pre-2-2 | 6 +++++ ChangeLog.pre-2-4 | 6 +++++ ChangeLog.pre-2-6 | 6 +++++ ChangeLog.pre-2-8 | 6 +++++ docs/reference/ChangeLog | 4 +++ docs/reference/glib/tmpl/error_reporting.sgml | 26 ++++++++++--------- gerror.c | 22 ++++++++++------ glib/gerror.c | 22 ++++++++++------ 12 files changed, 94 insertions(+), 28 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3f857f54..c184cf28 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2000-11-05 Havoc Pennington + + * gerror.c (g_propagate_error): Free the src error if the dest + location is NULL - I'm pretty sure that's what this function was + supposed to do. + 2000-11-05 Havoc Pennington * gutils.c (g_find_program_in_path): cleanup docs, sync param diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 3f857f54..c184cf28 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,9 @@ +2000-11-05 Havoc Pennington + + * gerror.c (g_propagate_error): Free the src error if the dest + location is NULL - I'm pretty sure that's what this function was + supposed to do. + 2000-11-05 Havoc Pennington * gutils.c (g_find_program_in_path): cleanup docs, sync param diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 3f857f54..c184cf28 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,9 @@ +2000-11-05 Havoc Pennington + + * gerror.c (g_propagate_error): Free the src error if the dest + location is NULL - I'm pretty sure that's what this function was + supposed to do. + 2000-11-05 Havoc Pennington * gutils.c (g_find_program_in_path): cleanup docs, sync param diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 3f857f54..c184cf28 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,9 @@ +2000-11-05 Havoc Pennington + + * gerror.c (g_propagate_error): Free the src error if the dest + location is NULL - I'm pretty sure that's what this function was + supposed to do. + 2000-11-05 Havoc Pennington * gutils.c (g_find_program_in_path): cleanup docs, sync param diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 3f857f54..c184cf28 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,9 @@ +2000-11-05 Havoc Pennington + + * gerror.c (g_propagate_error): Free the src error if the dest + location is NULL - I'm pretty sure that's what this function was + supposed to do. + 2000-11-05 Havoc Pennington * gutils.c (g_find_program_in_path): cleanup docs, sync param diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 3f857f54..c184cf28 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,9 @@ +2000-11-05 Havoc Pennington + + * gerror.c (g_propagate_error): Free the src error if the dest + location is NULL - I'm pretty sure that's what this function was + supposed to do. + 2000-11-05 Havoc Pennington * gutils.c (g_find_program_in_path): cleanup docs, sync param diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 3f857f54..c184cf28 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,9 @@ +2000-11-05 Havoc Pennington + + * gerror.c (g_propagate_error): Free the src error if the dest + location is NULL - I'm pretty sure that's what this function was + supposed to do. + 2000-11-05 Havoc Pennington * gutils.c (g_find_program_in_path): cleanup docs, sync param diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 3f857f54..c184cf28 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,9 @@ +2000-11-05 Havoc Pennington + + * gerror.c (g_propagate_error): Free the src error if the dest + location is NULL - I'm pretty sure that's what this function was + supposed to do. + 2000-11-05 Havoc Pennington * gutils.c (g_find_program_in_path): cleanup docs, sync param diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index 4da41bf3..c0d74595 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,7 @@ +2000-11-05 Havoc Pennington + + * glib/tmpl/error_reporting.sgml: fixes + 2000-11-05 Havoc Pennington * glib/tmpl/spawn.sgml, glib/tmpl/markup.sgml, diff --git a/docs/reference/glib/tmpl/error_reporting.sgml b/docs/reference/glib/tmpl/error_reporting.sgml index adc7f8f3..1132ec1a 100644 --- a/docs/reference/glib/tmpl/error_reporting.sgml +++ b/docs/reference/glib/tmpl/error_reporting.sgml @@ -53,7 +53,7 @@ if (err != NULL) { /* Report error to user, and free error */ g_assert (contents == NULL); - fprintf (stderr, "Unable to read file foo.txt: %s\n", err->message); + fprintf (stderr, "Unable to read file: %s\n", err->message); g_error_free (err); } else @@ -63,9 +63,10 @@ else } Note that err != NULL in this example is a -reliable indicator of whether g_file_get_contents() -failed. Also, g_file_get_contents() uses the convention that a NULL return value -means an error occurred (but not all functions use this convention). +reliable indicator of whether +g_file_get_contents() failed. Also, g_file_get_contents() uses the +convention that a NULL return value means an error occurred (but not +all functions use this convention). @@ -93,7 +94,8 @@ function will receive it), and g_clear_error() clears an error location by freeing the error and resetting the location to NULL. To display an error to the user, simply display error->message, perhaps along with additional context known only to the calling function (the file being opened, or -whatever). +whatever -- though in the g_file_get_contents() case, +error->message already contains a filename). @@ -248,12 +250,12 @@ The error domain is called The error codes are in an enumeration called <Namespace>_<Module>_Error; for example, -#GThreadError or #GExecError. +#GThreadError or #GSpawnError. -Members of the error code enumeration are called <NAMESPACE>_<MODULE>_ERROR_<CODE>, for example %G_EXEC_ERROR_FORK or %G_THREAD_ERROR_AGAIN. +Members of the error code enumeration are called <NAMESPACE>_<MODULE>_ERROR_<CODE>, for example %G_SPAWN_ERROR_FORK or %G_THREAD_ERROR_AGAIN. @@ -261,7 +263,7 @@ Members of the error code enumeration are called <NAMESPACE>_< If there's a "generic" or "unknown" error code for unrecoverable errors it doesn't make sense to distinguish with specific codes, it should be called <NAMESPACE>_<MODULE>_ERROR_FAILED, for -example %G_EXEC_ERROR_FAILED or %G_THREAD_ERROR_FAILED. +example %G_SPAWN_ERROR_FAILED or %G_THREAD_ERROR_FAILED. @@ -309,7 +311,7 @@ Summary of rules for use of #GError: and you should not report it. If it was fatal, then you must report it and discontinue whatever you were doing immediately. - + @@ -373,9 +375,9 @@ Summary of rules for use of #GError: -@domain: -@code: -@message: +@domain: error domain, e.g. #G_FILE_ERROR +@code: error code, e.g. %G_FILE_ERROR_NOENT +@message: human-readable informative error message diff --git a/gerror.c b/gerror.c index 1a032e73..c365bd2a 100644 --- a/gerror.c +++ b/gerror.c @@ -207,7 +207,7 @@ g_set_error (GError **err, * @dest: error return location * @src: error to move into the return location * - * Does nothing if @dest is NULL; otherwise, + * If @dest is NULL, free @src; otherwise, * moves @src into *@dest. *@dest must be NULL. **/ void @@ -215,14 +215,20 @@ g_propagate_error (GError **dest, GError *src) { g_return_if_fail (src != NULL); - - if (dest == NULL) - return; - if (*dest != NULL) - g_warning (ERROR_OVERWRITTEN_WARNING); - - *dest = src; + if (dest == NULL) + { + if (src) + g_error_free (src); + return; + } + else + { + if (*dest != NULL) + g_warning (ERROR_OVERWRITTEN_WARNING); + + *dest = src; + } } /** diff --git a/glib/gerror.c b/glib/gerror.c index 1a032e73..c365bd2a 100644 --- a/glib/gerror.c +++ b/glib/gerror.c @@ -207,7 +207,7 @@ g_set_error (GError **err, * @dest: error return location * @src: error to move into the return location * - * Does nothing if @dest is NULL; otherwise, + * If @dest is NULL, free @src; otherwise, * moves @src into *@dest. *@dest must be NULL. **/ void @@ -215,14 +215,20 @@ g_propagate_error (GError **dest, GError *src) { g_return_if_fail (src != NULL); - - if (dest == NULL) - return; - if (*dest != NULL) - g_warning (ERROR_OVERWRITTEN_WARNING); - - *dest = src; + if (dest == NULL) + { + if (src) + g_error_free (src); + return; + } + else + { + if (*dest != NULL) + g_warning (ERROR_OVERWRITTEN_WARNING); + + *dest = src; + } } /** -- 2.34.1