Re: strange gtk_set_data_full behavior ...

Sven LUTHER <> writes:

> i think i did found a bug in glib, don't know where to report it, so i will
> write here.

GLib bug reports should be entered into the GNOME bug tracker
for the package glib. See README file in GTK+ for more
> i do the following :
> char data1[] = "Hello";
> char data2[] = "Bye";
> char data3[] = "XXX";
> void sven_free (gpointer data)
> {
>   printf ("Hello you %u.\n", data);
>   printf ("Data is %s.\n", data);
> }
> ...
>   printf ("Data1 = %u.\n", data1);
>   printf ("Data2 = %u.\n", data2);
>   printf ("Data3 = %u.\n", data3);
>   gtk_object_set_data_full (GTK_OBJECT (drawing_area), "Sven_data",\
>     (gpointer)data1, (GtkDestroyNotify)&sven_free);
>   gtk_object_set_data_full (GTK_OBJECT (drawing_area), "Sven_data",\
>     (gpointer)data2, (GtkDestroyNotify)&sven_free);
>   gtk_object_set_data_full (GTK_OBJECT (drawing_area), "Sven_data",\
>     (gpointer)data3, (GtkDestroyNotify)&sven_free);
>   gtk_object_set_data_full (GTK_OBJECT (drawing_area), "Sven_data",\
>     (gpointer)NULL, (GtkDestroyNotify)&sven_free);
> and get the following output :
> Data1 = 138616.
> Data2 = 138624.
> Data3 = 138632.
> Hello you 138616.
> Data is Hello.
> Hello you 138624.
> Data is Bye.
> GLib-CRITICAL **: file gdataset.c: line 349 (g_datalist_id_set_data_full):
> assertion `destroy_func == NULL' failed.
> So : 
> 1) sven_free does not get called when i exit the application (is it a modified
>    scribble-simple, i quit hitting the Quit button who has a
>    gtk_widget_destroy callback fixed to it.
> 2) the last call to gtk_object_set_data_full should free the data, and is
>    perfectly legal, or at least the tutorial and the header file claims so, but
> 	does no such thing, and i get an error about NULL destroy function.

The warning is indicating that you can't set a destroy function
for a NULL data pointer. (The reason for this is that
gtk_object_set_data (object, key, NULL) actually removes
that key from the list attached to the widget.

I'm not quite sure why your destroy function isn't being
called when the widget is destroyed; the fourth call
should have absolutely no effect. (Other than printing
the warning)

In fact, I tried putting your code into an example
program, and the destroy function is in fact called...


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