[Cogl] [PATCH 2/2] error: Don't allocate a new CoglError when propagating

Robert Bragg robert at sixbynine.org
Mon Nov 26 09:31:48 PST 2012


This looks good to land to me:

Reviewed-by: Robert Bragg <robert at linux.intel.com>

thanks,
- Robert


On Thu, Nov 22, 2012 at 5:07 PM, Neil Roberts <neil at linux.intel.com> wrote:

> The _cogl_propagate_error() function takes ownership of the incoming
> error pointer so there's no need to allocate a new error when passing
> it on. The errors can potentially be passed up from a number of layers
> so it seems worthwhile to avoid the allocation.
>
> The _cogl_propagate_gerror() function was previously using
> _cogl_propagate_error(). Presumably this would not have worked because
> that function would try to free the error from glib using
> cogl_error_free but that would use the wrong free function and thus
> the wrong slice allocator. The GError propagating function is only
> used when gdk-pixbuf is enabled which now requires glib support anyway
> so we can just avoid defining the function when compiling without
> glib.
> ---
>  cogl/cogl-error-private.h |  2 ++
>  cogl/cogl-error.c         | 17 ++++++++++++++---
>  2 files changed, 16 insertions(+), 3 deletions(-)
>
> diff --git a/cogl/cogl-error-private.h b/cogl/cogl-error-private.h
> index 31b2eab..a886084 100644
> --- a/cogl/cogl-error-private.h
> +++ b/cogl/cogl-error-private.h
> @@ -43,9 +43,11 @@ void
>  _cogl_propagate_error (CoglError **dest,
>                         CoglError *src);
>
> +#ifdef COGL_HAS_GLIB_SUPPORT
>  void
>  _cogl_propagate_gerror (CoglError **dest,
>                          GError *src);
> +#endif /* COGL_HAS_GLIB_SUPPORT */
>
>  #define _cogl_clear_error(X) g_clear_error ((GError **)X)
>
> diff --git a/cogl/cogl-error.c b/cogl/cogl-error.c
> index 4ef3681..753e4c8 100644
> --- a/cogl/cogl-error.c
> +++ b/cogl/cogl-error.c
> @@ -104,13 +104,24 @@ _cogl_propagate_error (CoglError **dest,
>  {
>    _COGL_RETURN_IF_FAIL (src != NULL);
>
> -  _cogl_set_error_literal (dest, src->domain, src->code, src->message);
> -  cogl_error_free (src);
> +  if (dest == NULL)
> +    cogl_error_free (src);
> +  else if (*dest)
> +    g_warning (ERROR_OVERWRITTEN_WARNING, src->message);
> +  else
> +    *dest = src;
>  }
>
> +/* This function is only used from the gdk-pixbuf image backend so it
> + * should only be called if we are using the system GLib. It would be
> + * difficult to get this to work without the system glib because we
> + * would need to somehow call the same g_error_free function that
> + * gdk-pixbuf is using */
> +#ifdef COGL_HAS_GLIB_SUPPORT
>  void
>  _cogl_propagate_gerror (CoglError **dest,
>                          GError *src)
>  {
> -  _cogl_propagate_error (dest, (CoglError *)src);
> +  _cogl_propagate_error (dest, (CoglError *) src);
>  }
> +#endif /* COGL_HAS_GLIB_SUPPORT */
> --
> 1.7.11.3.g3c3efa5
>
> _______________________________________________
> Cogl mailing list
> Cogl at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/cogl
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/cogl/attachments/20121126/5620e42e/attachment-0001.html>


More information about the Cogl mailing list