Re: [gtk-list] Re: Found: Shortest way to trigger core-dump :-(
- From: Lars Hallberg <lah micropp se>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] Re: Found: Shortest way to trigger core-dump :-(
- Date: Wed, 21 Apr 1999 22:52:37 +0200
On Wed, Apr 21, 1999 at 10:09:01PM +0200, Andreas Tille wrote:
> On Wed, 21 Apr 1999 Bertrand.Guiheneuf@inria.fr wrote:
>
> > static void Function(void *data, GtkSignalFunc func, char *question)
> > {
> > GtkWidget *window, *button;
> >
> > window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
> > gtk_signal_connect(GTK_OBJECT(window), "destroy", GTK_SIGNAL_FUNC(gtk_widget_destroyed), &window);
> >
> > &window is a pointer to somerthing in the stack....
> >
> > put GtkWidget *window, *button; outside you r function, this
> > will resolve youe segmentation fault.
> Why shouldn't I use internal variables in this case?
> I really didn't see any reason and I want to avoid global variables
> because I consider it to be bad style.
>
> OK, it would solve the Problem, but declaring the variables static would
> solve the problem, too.
>
> But could you explain, why for instance this
>
> static void MainCallback(GtkWidget *button, char *dummy)
> {
> char *file, *buf;
>
> file = g_strdup("");
> /* buf = g_strdup(""); */
> Function(file, GTK_SIGNAL_FUNC(Callback), NULL);
> /* if ( buf ) g_free(buf); */
> }
>
> solves the problem as well??? What has this really unneeded pointer
> to do with *window and *button??
Well, in the exampel You send the adress (&window) of the pointer
to GTK. The pointer is alocated on the stack wich means GTK will
manipulate/read values on the stack.
gtk_signal_connect is likly to keep the values pased to it in some
GTK datastructure and it is likely that GTK uses the value somtime
later (after "Function" returns) when the keept part of the stack
may be used for somthing else. The effekt of this is farly random,
so random changes of the program will trigger / hide the error.
I do not think You can do much usefull without triggering the error
thou ;-) It will take some good (?) luck att least....
HTH /Lars
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]