Free the src error if the dest location is NULL - I'm pretty sure that's

2000-11-05  Havoc Pennington  <hp@pobox.com>

* 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  <hp@pobox.com>

* glib/tmpl/error_reporting.sgml: fixes
This commit is contained in:
Havoc Pennington 2000-11-05 17:02:37 +00:00 committed by Havoc Pennington
parent 110c6cbac8
commit d4ff0ef999
12 changed files with 94 additions and 28 deletions

View File

@ -1,3 +1,9 @@
2000-11-05 Havoc Pennington <hp@pobox.com>
* 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 <hp@pobox.com> 2000-11-05 Havoc Pennington <hp@pobox.com>
* gutils.c (g_find_program_in_path): cleanup docs, sync param * gutils.c (g_find_program_in_path): cleanup docs, sync param

View File

@ -1,3 +1,9 @@
2000-11-05 Havoc Pennington <hp@pobox.com>
* 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 <hp@pobox.com> 2000-11-05 Havoc Pennington <hp@pobox.com>
* gutils.c (g_find_program_in_path): cleanup docs, sync param * gutils.c (g_find_program_in_path): cleanup docs, sync param

View File

@ -1,3 +1,9 @@
2000-11-05 Havoc Pennington <hp@pobox.com>
* 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 <hp@pobox.com> 2000-11-05 Havoc Pennington <hp@pobox.com>
* gutils.c (g_find_program_in_path): cleanup docs, sync param * gutils.c (g_find_program_in_path): cleanup docs, sync param

View File

@ -1,3 +1,9 @@
2000-11-05 Havoc Pennington <hp@pobox.com>
* 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 <hp@pobox.com> 2000-11-05 Havoc Pennington <hp@pobox.com>
* gutils.c (g_find_program_in_path): cleanup docs, sync param * gutils.c (g_find_program_in_path): cleanup docs, sync param

View File

@ -1,3 +1,9 @@
2000-11-05 Havoc Pennington <hp@pobox.com>
* 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 <hp@pobox.com> 2000-11-05 Havoc Pennington <hp@pobox.com>
* gutils.c (g_find_program_in_path): cleanup docs, sync param * gutils.c (g_find_program_in_path): cleanup docs, sync param

View File

@ -1,3 +1,9 @@
2000-11-05 Havoc Pennington <hp@pobox.com>
* 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 <hp@pobox.com> 2000-11-05 Havoc Pennington <hp@pobox.com>
* gutils.c (g_find_program_in_path): cleanup docs, sync param * gutils.c (g_find_program_in_path): cleanup docs, sync param

View File

@ -1,3 +1,9 @@
2000-11-05 Havoc Pennington <hp@pobox.com>
* 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 <hp@pobox.com> 2000-11-05 Havoc Pennington <hp@pobox.com>
* gutils.c (g_find_program_in_path): cleanup docs, sync param * gutils.c (g_find_program_in_path): cleanup docs, sync param

View File

@ -1,3 +1,9 @@
2000-11-05 Havoc Pennington <hp@pobox.com>
* 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 <hp@pobox.com> 2000-11-05 Havoc Pennington <hp@pobox.com>
* gutils.c (g_find_program_in_path): cleanup docs, sync param * gutils.c (g_find_program_in_path): cleanup docs, sync param

View File

@ -1,3 +1,7 @@
2000-11-05 Havoc Pennington <hp@pobox.com>
* glib/tmpl/error_reporting.sgml: fixes
2000-11-05 Havoc Pennington <hp@pobox.com> 2000-11-05 Havoc Pennington <hp@pobox.com>
* glib/tmpl/spawn.sgml, glib/tmpl/markup.sgml, * glib/tmpl/spawn.sgml, glib/tmpl/markup.sgml,

View File

@ -53,7 +53,7 @@ if (err != NULL)
{ {
/* Report error to user, and free error */ /* Report error to user, and free error */
g_assert (contents == NULL); 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); g_error_free (err);
} }
else else
@ -63,9 +63,10 @@ else
} }
</programlisting> </programlisting>
Note that <literal>err != NULL</literal> in this example is a Note that <literal>err != NULL</literal> in this example is a
<emphasis>reliable</emphasis> indicator of whether g_file_get_contents() <emphasis>reliable</emphasis> indicator of whether
failed. Also, g_file_get_contents() uses the convention that a NULL return value g_file_get_contents() failed. Also, g_file_get_contents() uses the
means an error occurred (but not all functions use this convention). convention that a NULL return value means an error occurred (but not
all functions use this convention).
</para> </para>
<para> <para>
@ -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 freeing the error and resetting the location to NULL. To display an error to the
user, simply display <literal>error-&gt;message</literal>, perhaps along with user, simply display <literal>error-&gt;message</literal>, perhaps along with
additional context known only to the calling function (the file being opened, or additional context known only to the calling function (the file being opened, or
whatever). whatever -- though in the g_file_get_contents() case,
<literal>error-&gt;message</literal> already contains a filename).
</para> </para>
<para> <para>
@ -248,12 +250,12 @@ The error domain is called
<para> <para>
The error codes are in an enumeration called The error codes are in an enumeration called
<literal>&lt;Namespace&gt;_&lt;Module&gt;_Error</literal>; for example, <literal>&lt;Namespace&gt;_&lt;Module&gt;_Error</literal>; for example,
#GThreadError or #GExecError. #GThreadError or #GSpawnError.
</para> </para>
</listitem> </listitem>
<listitem> <listitem>
<para> <para>
Members of the error code enumeration are called <literal>&lt;NAMESPACE&gt;_&lt;MODULE&gt;_ERROR_&lt;CODE&gt;</literal>, for example %G_EXEC_ERROR_FORK or %G_THREAD_ERROR_AGAIN. Members of the error code enumeration are called <literal>&lt;NAMESPACE&gt;_&lt;MODULE&gt;_ERROR_&lt;CODE&gt;</literal>, for example %G_SPAWN_ERROR_FORK or %G_THREAD_ERROR_AGAIN.
</para> </para>
</listitem> </listitem>
<listitem> <listitem>
@ -261,7 +263,7 @@ Members of the error code enumeration are called <literal>&lt;NAMESPACE&gt;_&lt;
If there's a "generic" or "unknown" error code for unrecoverable errors it 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 doesn't make sense to distinguish with specific codes, it should be called
<literal>&lt;NAMESPACE&gt;_&lt;MODULE&gt;_ERROR_FAILED</literal>, for <literal>&lt;NAMESPACE&gt;_&lt;MODULE&gt;_ERROR_FAILED</literal>, for
example %G_EXEC_ERROR_FAILED or %G_THREAD_ERROR_FAILED. example %G_SPAWN_ERROR_FAILED or %G_THREAD_ERROR_FAILED.
</para> </para>
</listitem> </listitem>
</itemizedlist> </itemizedlist>
@ -373,9 +375,9 @@ Summary of rules for use of #GError:
</para> </para>
@domain: @domain: error domain, e.g. #G_FILE_ERROR
@code: @code: error code, e.g. %G_FILE_ERROR_NOENT
@message: @message: human-readable informative error message
<!-- ##### FUNCTION g_error_new ##### --> <!-- ##### FUNCTION g_error_new ##### -->
<para> <para>

View File

@ -207,7 +207,7 @@ g_set_error (GError **err,
* @dest: error return location * @dest: error return location
* @src: error to move into the 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. * moves @src into *@dest. *@dest must be NULL.
**/ **/
void void
@ -217,12 +217,18 @@ g_propagate_error (GError **dest,
g_return_if_fail (src != NULL); g_return_if_fail (src != NULL);
if (dest == NULL) if (dest == NULL)
return; {
if (src)
g_error_free (src);
return;
}
else
{
if (*dest != NULL)
g_warning (ERROR_OVERWRITTEN_WARNING);
if (*dest != NULL) *dest = src;
g_warning (ERROR_OVERWRITTEN_WARNING); }
*dest = src;
} }
/** /**

View File

@ -207,7 +207,7 @@ g_set_error (GError **err,
* @dest: error return location * @dest: error return location
* @src: error to move into the 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. * moves @src into *@dest. *@dest must be NULL.
**/ **/
void void
@ -217,12 +217,18 @@ g_propagate_error (GError **dest,
g_return_if_fail (src != NULL); g_return_if_fail (src != NULL);
if (dest == NULL) if (dest == NULL)
return; {
if (src)
g_error_free (src);
return;
}
else
{
if (*dest != NULL)
g_warning (ERROR_OVERWRITTEN_WARNING);
if (*dest != NULL) *dest = src;
g_warning (ERROR_OVERWRITTEN_WARNING); }
*dest = src;
} }
/** /**