Re: [gtk-list] Re: question about resizing & combos



i think you have right Gustavo, but this code is just a sample from
a part of a program i'm writing
in my real programm the strings are `dynamic` so there
must be another problem

On Wed, 27 Oct 1999, [ISO-8859-1] Gustavo Jo&ggr;o Alves Marques Carneiro wrote:

> 	Ok. I think I found another problem. You have created a glist that
> contains a list of 'static' strings. Those strings are embedded in the
> program code by the compiler and can't be freed. Each item of glist->data
> is a pointer to one of those static strings. It's not dynamic memory
> allocation, so you don't have to bother releasing it -- it will be done
> automatically. Just remove the g_free. 
> 
> 
> On Wed, 27 Oct 1999, Giaslas Georgios wrote:
> 
> > Thank you Gustavo for replying so quick 
> > 
> > i tried to put g_free(l->data) before g_list_remove
> > but i get a segmentation fault when the program tries to execute g_free
> > 
> > i also checked with gdb that 'while' doesn't ever result 
> > in an endless loop.
> > 
> > So, there must be another problem
> > 
> > Thanx anyway
> > -----------------------------------------
> > > 2) i have a combo box and when the user selects
> > >    a string i want all the strings before this to be removed.
> > >    i've done it and when i change the comboentry using
> > >    arrow keys it's ok. but when it's changed using the
> > >    mouse i get a segmentation fault.
> > >    Is it a bug or it's my fault?
> > >    please try the following little program to see what
> > >    i mean exactly.
> > >
> > > (I use gtk+ version 1.2.6)
> > >
> > > Please reply this time...
> > >
> > > Thank you all
> > >
> > > -----------------------------
> > > #include <gtk/gtk.h>
> > >
> > > GList *glist=NULL;
> > >    gint active=0;
> > >    GtkWidget *combo;
> > >    GtkWidget *window;
> > >
> > >    static gint delete_callback(GtkWidget *widget, gpointer data)
> > >    {
> > >        gtk_main_quit();
> > >        return(FALSE);
> > >    }
> > >
> > >    void callback(GtkEntry *comboentry, gpointer data)
> > >    {
> > >        GList *l;
> > >        gint cnt=0;
> > >        if (active)
> > >        {
> > >            l=g_list_first(glist);
> > >            while (g_strcasecmp(l->data, gtk_entry_get_text(comboentry)))
> > >            {
> > >                g_print("data %s deleted\n", (gchar *) l->data);
> > >                glist=g_list_remove(glist, l->data);
> > >                g_free(l->data);
> > 
> > >        g_free(l->data) should come before g_list_remove because it is
> > >not guaranteed that the location pointed by 'l' is valid after you remove
> > 
> > >it from the list.
> > 
> > >                cnt++;
> > >                l=g_list_first(glist);
> > >            }
> > >        Also, you should take care that this previous 'while' doesn't
> > ever
> > >result in an endless loop.
> > 
> > >            gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist);
> > >        }
> > >    }
> > >
> > >    int main (int argc, char *argv[])
> > >    {
> > >        gtk_init(&argc, &argv);
> > >        window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
> > >        gtk_signal_connect(GTK_OBJECT(window), "delete_event",
> > >                            GTK_SIGNAL_FUNC(delete_callback), NULL);
> > >        combo=gtk_combo_new();
> > >        glist = g_list_append(glist, "String 1");
> > >        glist = g_list_append(glist, "String 2");
> > >        glist = g_list_append(glist, "String 3");
> > >        glist = g_list_append(glist, "String 4");
> > >        gtk_signal_connect(GTK_OBJECT(GTK_COMBO(combo)->entry),
> > "changed",
> > >  GTK_SIGNAL_FUNC(callback), NULL);
> > >
> > >        gtk_combo_set_popdown_strings( GTK_COMBO(combo), glist);
> > >        gtk_container_add(GTK_CONTAINER(window), combo);
> > >        gtk_widget_show_all(window);
> > >        active=1;
> > >        gtk_main();
> > >        return 0;
> > >    }
> > > --------------------------
> > >
> > 
> > 
> > 
> 
> -- 
> Gustavo J.A.M. Carneiro
> World::Portugal::FEUP::DEEC::LEEC::TEC
> [reinolinux.fe.up.pt/~ee96090]
>                                        
> 
> -- 
> To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null
> 
> 



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