Re: Nautilus Gtk stuff inventory (for Gtk 2.0?)
- From: Owen Taylor <otaylor redhat com>
- To: gtk-devel-list redhat com
- Cc: darin eazel com
- Subject: Re: Nautilus Gtk stuff inventory (for Gtk 2.0?)
- Date: 28 Jun 2000 14:19:07 -0400
Darin Adler <darin@eazel.com> writes:
> I figured it might still be good to give an inventory of things in Nautilus
> that are Gtk+ extensions, or extensions to things in Gnome that someone is
> perhaps moving into Gtk+ for 2.0.
Thanks a lot for doing this. This will be very useful. It's going
to take quite a while to go through all this; but there was one
aspect of this stuff I feel I should respond to immediately:
> -----------------
> nautilus-string.h
> -----------------
> nautilus_strlen (returns 0 for NULL, following g_strdup's lead of
> allowing NULL)
> nautilus_strchr (returns NULL for NULL, following g_strdup's lead of
> allowing NULL)
> nautilus_strcmp (allows NULLs, following g_strdup's lead of allowing
> NULL, currently NULL == "", but we could change definition so that NULL ==
> NULL only instead)
> nautilus_strcasecmp (allows NULLs as nautilus_strcmp does)
> nautilus_str_compare (nautilus_strcmp with GCompareFunc-style
> parameters)
>
> nautilus_eat_strcmp (nautilus_strcmp with g_free on one of the two
> strings; not really so useful)
>
> nautilus_str_is_empty (s == NULL || s[0] == '\0'; provided so people
> won't do strlen (s) == 0 or something like that)
This is a horrible misunderstanding of why g_strdup() accepts NULL
and produces NULL.
NULL is NOT the same as "".
NULL is NOT the same as "".
NULL is NOT the same as "".
While confusing the two is a frequent novice mistake, I know of no
commonly accepted style of C programming that accepts this identity.
(I'm not saying that you couldn't invent such a style, but it would be
incompatible with GTK+, GNOME, and many other libraries.)
The convention used throughout GLib/GTK+/GNOME is that NULL used for a
'char *' is a special value indicating that the string is undefined,
unused or something of that sort. It's like 'undef' in Perl.
g_strdup() accepts NULL so that it can propagate this undefined
value without needing an extra conditional. Note that g_strdup(NULL)
gives NULL and g_strdup("") gives "".
With this convention, applying strlen() or strcmp() to a NULL string
indicates a logic error in the code.
I would STRONGLY advise getting rid of nautilus_strcmp and its ilk and
fixing any code that relies on a confusion of NULL and "".
Needless to say, we will not be adding such functions to GTK+. :-)
Owen
(The only case I can think of where we do allow NULL to be indicate
empty string is gtk_label_set_text (NULL) and some related
functions. This is just a convenience and does not indicate that NULL
is generally the same as "".)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]