Re: gtk_builder_add_from_file error handling



On Wed, Jan 13, 2010 at 05:18:04PM +0100, Gabriele Greco wrote:

I think, and I'm used to see in almost every framework documentations, that
every time a function allocates something that the API user must free
himself the documentation should explicitly say so. Documentation should be
redundant when it may cause errors the fact it is not.

This is the case of GError and for
instance gtk_ui_manager_add_ui_from_file/string
and gtk_builder_add_from_file/string.

I'm sorry but this is nonsense.

1) The problem was not whether you had to free the error or not.  You
just used the wrong function to free it.

Very few data structures used in GLib can be freed by mere g_free(), the
only common exception is the raw C string -- but that's not a GLib data
type.  GErrors are no exception in that.

2) GError is the try/catch mechanism (well, a rough approximation of
that it permitted by C semantics).  You must read the GError
documentation to use it properly.

If you don't know how try/catch works in any language, the only thing
you can do is to ignore the possibility of failure.  That's exactly what
passing NULL for the error acomplishes with GLib and it works
flawlessly.

Yeti




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]