gtk_builder_add_from_file error handling

2010-01-13 Thread Gabriele Greco
I just found that with a builder file with a syntax error my app crashed
with:

*** glibc detected *** ./packager: double free or corruption (out):
0x09aa33d0 ***

I think I'm using gtkbuilder error handling in the right way and
documentation does not suggest my how to use it:

GError *err = NULL;
if (!gtk_builder_add_from_file(builder_, myfile.xml, erro)) {

}

-- 
Ing. Gabriele Greco, DARTS Engineering
Tel: +39-0105761240  Fax: +39-0105760224
s-mail: Via G.T. Invrea 14 - 16129 GENOVA (ITALY)
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


gtk_builder_add_from_file error handling

2010-01-13 Thread Gabriele Greco
Sorry last message was sent by accident pushing an hotkey while editing...

This should be the complete version of my question:


I just found that with a builder file with a syntax error my app crashed
with:

*** glibc detected *** ./packager: double free or corruption (out):
0x09aa33d0 ***

I think I'm using gtkbuilder error handling in the right way and
documentation does not suggest my how to use it:

GError *err = NULL;
if (!gtk_builder_add_from_file(builder_, myfile.xml, err)) {
   if (err) {
  cerr  builder load fail:   err-message  '\n';
  g_free(err); // commenting this solves the crash but other gtk apis
  // and examples I've found always free error handling
pointers
   }
   else
  cerr  builder load fail, unknown error\n;

   return false;
}

-- 
Bye,
 Gabry
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: gtk_builder_add_from_file error handling

2010-01-13 Thread Florian Müllner
On Wed, 2010-01-13 at 11:52 +0100, Gabriele Greco wrote:
 GError *err = NULL;
 if (!gtk_builder_add_from_file(builder_, myfile.xml, err)) {
if (err) {
   cerr  builder load fail:   err-message  '\n';
   g_free(err); // commenting this solves the crash but other gtk apis
   // and examples I've found always free error handling
 pointers

I don't know gtkmm, but at least in C GErrors are freed with
g_error_free(err).
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: gtk_builder_add_from_file error handling

2010-01-13 Thread Gabriele Greco
 GError *err = NULL;
  if (!gtk_builder_add_from_file(builder_, myfile.xml, err)) {
 if (err) {
g_free(err); // commenting this solves the crash but other gtk apis

 I don't know gtkmm, but at least in C GErrors are freed with
 g_error_free(err).


You are obviously right. I always used g_free() to free errors, my fault.
I've grepped tons of sources and I had everywhere the code bugged, then I
googled around to search some more examples and I've found there are a lot
of other sources in the net where a GError is freed with g_free, I think
improving the documentation of the functions that use a GError as input
parameter may help programmers do not write wrong code in this situation.

-- 
Bye,
 Gabry
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: gtk_builder_add_from_file error handling

2010-01-13 Thread David Nečas
On Wed, Jan 13, 2010 at 04:48:29PM +0100, Gabriele Greco wrote:
 ... I've found there are a lot
 of other sources in the net where a GError is freed with g_free, I think
 improving the documentation of the functions that use a GError as input
 parameter may help programmers do not write wrong code in this situation.

The proper handling of GErrors is described in great detail in the
GError documentation.

I don't think it is reasonable to explain this in the documentation of
every function that uses GError to report errors as there are almost 80
of them just in Gtk+ (and over 400 in GLib, and many more elsewhere).

Yeti

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: gtk_builder_add_from_file error handling

2010-01-13 Thread Gabriele Greco


 The proper handling of GErrors is described in great detail in the
 GError documentation.

 I don't think it is reasonable to explain this in the documentation of
 every function that uses GError to report errors as there are almost 80
 of them just in Gtk+ (and over 400 in GLib, and many more elsewhere).


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.

It's not a case that in UI toolkit debates one of the most common criticism
to GTK is the lack of documentation.

-- 
Bye,
 Gabry
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: gtk_builder_add_from_file error handling

2010-01-13 Thread Emmanuele Bassi
On Wed, 2010-01-13 at 17:18 +0100, Gabriele Greco wrote:
 
 
  The proper handling of GErrors is described in great detail in the
  GError documentation.
 
  I don't think it is reasonable to explain this in the documentation of
  every function that uses GError to report errors as there are almost 80
  of them just in Gtk+ (and over 400 in GLib, and many more elsewhere).
 
 
 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.

that's why gtk-doc creates cross-links for each data type.

 This is the case of GError and for
 instance gtk_ui_manager_add_ui_from_file/string
 and gtk_builder_add_from_file/string.
 
 It's not a case that in UI toolkit debates one of the most common criticism
 to GTK is the lack of documentation.

the lack of documentation refers to empty (or FIXME) sections of the
API reference and to high-level documentation. the fact that a non-NULL
GError must be freed using the corresponding GError free function is
documented in great detail and that documentation linked by every
function in a gtk-doc-generated API reference and part of the behavior
of the framework.

the API reference does not gain anything by adding:

  @error: a return location for a #GError or %NULL.
+   Use g_error_free() to free the #GError if @error is not %NULL
+   after calling this function

for each and every GError-using function. you'd just be writing
redundant documentation.

if you can't be bothered to follow through a link then you're probably
using g_free() on every single data structure, which yields
interesting results when done on, say, GString or worse GObject.

ciao,
 Emmanuele.

-- 
W: http://www.emmanuelebassi.name
B: http://blogs.gnome.org/ebassi

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: gtk_builder_add_from_file error handling

2010-01-13 Thread David Nečas
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

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list