After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 58777 - gtk_entry_set_text () doesn't allow NULL as the 2nd parameter
gtk_entry_set_text () doesn't allow NULL as the 2nd parameter
Status: RESOLVED WONTFIX
Product: gtk+
Classification: Platform
Component: Widget: GtkEntry
1.3.x
Other All
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2001-08-09 14:10 UTC by Vitaly Tishkov
Modified: 2014-04-11 08:59 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Trivial patch (544 bytes, patch)
2011-11-04 15:43 UTC, Matthew Barnes
none Details | Review
Revised trivial patch (932 bytes, patch)
2012-03-14 13:20 UTC, Matthew Barnes
none Details | Review

Description Vitaly Tishkov 2001-08-09 14:10:50 UTC
GtkEntry doesn't allow setting text to NULL.
However GtkLabel allows that.

This looks inconsistent. I assume that they both should whether allow or
disallow NULL.

Test case:

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

int
main (int argc, char** argv)
{
    GtkWidget* entry;
    GtkWidget* label;

    gtk_init (&argc, &argv);

    label = gtk_label_new("");
    gtk_label_set_text (GTK_LABEL(label), NULL);

    entry = gtk_entry_new ();
    gtk_entry_set_text (GTK_ENTRY(entry), NULL);
    
    gtk_widget_destroy (entry);
    gtk_widget_destroy (label);

}


Outputest (pid:3019): Gtk-CRITICAL **: file gtkentry.c: line 3112
(gtk_entry_set_text): assertion `text != NULL' failed
t:
Comment 1 Owen Taylor 2001-08-11 14:07:59 UTC
GtkLabel needs to allow it for backwards compat. It doesn't
make any particular sense, however, and I don't think
we should change GtkEntry.
Comment 2 Christian Dywan 2008-10-09 17:38:45 UTC
Would you consider this for a second time perhaps? I find myself special-casing NULL in various occasions, where my code simply doesn't differentiate between NULL and "". All the extra effort in code can be tedious. I don't really see how this behaviour might be useful.
Comment 3 Matthew Barnes 2011-11-04 15:43:41 UTC
Created attachment 200694 [details] [review]
Trivial patch

+1 for silently converting a NULL argument to an empty string.

I frequently bind GtkEntry:text to other string properties and always have to be mindful of the NULL issue to avoid runtime warnings.
Comment 4 Christian Dywan 2011-11-04 19:15:23 UTC
Please add a line to the documentation along "Since 3.4 @text can be %NULL".
Comment 5 Matthias Clasen 2011-11-04 22:45:08 UTC
I still don't think it makes any sense to mix up NULL and ""
Comment 6 Matthew Barnes 2012-03-14 13:20:34 UTC
Created attachment 209713 [details] [review]
Revised trivial patch

Mentions the change in the API docs and adds an (allow-none) annotation to @text.
Comment 7 Martyn Russell 2012-03-14 14:10:39 UTC
(In reply to comment #5)
> I still don't think it makes any sense to mix up NULL and ""

We've had a similar discussion before:

  https://bugzilla.gnome.org/show_bug.cgi?id=399880

While there is clearly a difference, in real terms, there isn't.
The string is either empty or it isn't.

In this particular case, it's really just a courtesy to help the app developer.
I would advocate consistency too where possible.

Just my 2p ;)
Comment 8 Matthias Clasen 2012-03-15 12:03:17 UTC
the inconsistency here is that gtklabel silently allows NULL, not that gtkentry doesn't.
Comment 9 André Klapper 2012-10-30 19:50:21 UTC
Could some GTK+ developer comment whether this inconsistency is wanted, and if it makes sense?
Comment 10 Matthias Clasen 2012-10-30 20:59:24 UTC
comment 1 contains that information
Comment 11 Matthew Barnes 2013-09-05 03:44:26 UTC
*** Bug 684425 has been marked as a duplicate of this bug. ***