Re: gtk_label_get_text() string duping
- From: Tim Janik <timj gtk org>
- To: Federico Mena Quintero <federico helixcode com>
- Cc: Gtk+ Developers <gtk-devel-list gnome org>
- Subject: Re: gtk_label_get_text() string duping
- Date: Wed, 28 Jun 2000 22:27:05 +0200 (CEST)
On 28 Jun 2000, Federico Mena Quintero wrote:
> Tim Janik <timj@gtk.org> writes:
>
> > i don't hate you, in fact you're right ;)
> > just "const" can be a pain in the ass for C programers as some
> > code const-correct and others don't. those that do will use
> >
> > const char *my_label = gtk_label_get_text (foo);
> >
> > and are fine, while those that don't will do:
> >
> > char *my_label = gtk_label_get_text (foo);
> >
> > and get a warning if gtk_label_get_text() returns const gchar*.
>
> Well, in that case it is tough luck for them. I prefer to provide an
> API that is as self-documenting as possible, and moreover correct,
> than an API that caters to lazy users :-)
jup, that's why i brough up the gtk_label_get_text() duping issue.
however, even owen and me weren't there in the very beginning, and
later we decided we didn't want to convert everything over to return
const gchar*, because in contrast to the s/get/dup/ thingy, that can
not be fixed by a script in third party code.
> > > As Owen pointed out this has issues with threading, but hey, what the
> > > hell :-)
> >
> > that's a problem only occouring at the glib level and only needs to
> > be solved _there_ ;)
>
> Say two threads have a pointer to the label.
>
> Thread 1 is scheduled:
>
> const char *s = gtk_label_get_text (label);
>
> Thread 2 is scheduled:
>
> gtk_label_set_text (label, "squawk");
>
> Thread 1 is scheduled:
>
> printf ("%s is not what I think it is\n", s);
>
> I guess that is the application's problem, anyways, since it is
> futzing with the label on more than one thread.
right, if not, that argument could be made to copy *everything* returned
from accessors and never provide peek variants, since you'll have the
same problem with accessing a container's child from one thread and
removing it from the container in another, i.e.:
Thread 1 is scheduled:
GtkWidget *child = GTK_BIN (button)->child;
Thread 2 is scheduled:
gtk_widget_set (button, "label", "squawk", NULL);
Thread 1 is scheduled:
printf ("guess i'll segfault with this: %s\n",
gtk_label_get_text (GTK_LABEL (child)));
>
> Federico
>
---
ciaoTJ
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]