Re: strange gtk_set_data_full behavior ...

Sven LUTHER <> writes:

> On Tue, Jun 08, 1999 at 01:51:07PM -0400, Owen Taylor wrote:
> > 
> > Sven LUTHER <> writes:

> > >   gtk_object_set_data_full (GTK_OBJECT (drawing_area), "Sven_data",\
> > >     (gpointer)NULL, (GtkDestroyNotify)&sven_free);


> > > 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.
> Why not just ignore the function then, and remove the data ? Why give an error
> for that ?

I think the reason that there is a warning there is so that
people won't expect the destroy function to be called if
that key is subsequently set again. Ignoring that argument
would be another approach, but in general, GTK+/Glib try
to be noisy when the application writer is doing something

>  This mean that i cannot have a generic gtk_object_set_data_full
> wrapper wich will set the function, and use it transparently as
> gtk_object_set_data.

Why not just make your wrapper do:

 gtk_object_set_data_full (object, key, data, data ? destroy : NULL);

> > 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...
> Huh ??? could you send me the program ? i simply put this stuff in the
> scribble-simple.c example, but then maybe the scribble-simple example is buggy
> ?

> PS : is this kind of mail correct for this list, or should it go to
> gtk-list ?  I am not sure where to address my mails. I am writting a
> binding for the ocaml language, not an application.

This mail would be more appropriate on gtk-list, since it
doesn't really deal with development plans for future versions
of GTK+.


#include <gtk/gtk.h>
#include <stdio.h>

 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);

int main (int argc, char **argv)
  GtkWidget *window;

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  printf ("Data1 = %u.\n", data1);
  printf ("Data2 = %u.\n", data2);
  printf ("Data3 = %u.\n", data3);
  gtk_object_set_data_full (GTK_OBJECT (window), "Sven_data",\
			    (gpointer)data1, (GtkDestroyNotify)&sven_free);
  gtk_object_set_data_full (GTK_OBJECT (window), "Sven_data",\
			    (gpointer)data2, (GtkDestroyNotify)&sven_free);
  gtk_object_set_data_full (GTK_OBJECT (window), "Sven_data",\
			    (gpointer)data3, (GtkDestroyNotify)&sven_free);
  gtk_object_set_data_full (GTK_OBJECT (window), "Sven_data",\
			    (gpointer)NULL, (GtkDestroyNotify)&sven_free);

  gtk_widget_show (window);

  gtk_widget_destroy (window);

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