Re: oversensible assertion
- From: Owen Taylor <otaylor redhat com>
- To: Tim Janik <timj gtk org>
- Cc: Gtk+ Developers <gtk-devel-list gnome org>
- Subject: Re: oversensible assertion
- Date: Sat, 24 Aug 2002 09:16:34 -0400 (EDT)
Tim Janik <timj gtk org> writes:
> On Fri, 23 Aug 2002, Owen Taylor wrote:
>
> > Tim Janik <timj gtk org> writes:
> > > maybe that assertion should be (length < 1 || text != NULL) ?
> >
> > I don't think so. There are two cases:
> >
> > A) length < 0; text is nul terminated string.
> > B) length >= 0; text is an array of characters of length 'length'.
> >
> > NULL is valid for B, not for A). If the canvas wants to support
> >
> > set (item, "text", NULL);
> >
> > To mean "", it needs to do it explicitely.
>
> i don't see the point here, there's really no good reason to demand
> extra code from the canvas and every other pango_layout_set_text()
> user at this point *if* you already support text==NULL
> with length=0.
If you support, a length argument, you *have* to support text==NULL,
length==0. That's because g_malloc (gchar, 0); gives you NULL.
But the string that is represented by (NULL, 0) is "". The empty
string. We've been very clear throughout the years that "" is
distinct from NULL.
> > (Just changing
> > pango_layout_set_text() wouldn't make this stuff work in
> > general:
> >
> > if (len < 0)
> > len = strlen (text);
>
> i didn't claim that this is going to work, i'm well aware of
> strlen() not handling NULL, but this is completely besides the point.
> in your API, you chosed to allow text=NULL and not demand text to
> be a valid 0-terminated string if length=0. at that point, it's
> simply ridiculous for length<0 to not mean "i don't know the size,
> find out yourself" but instead "i don't know the size, however i checked
> that text is not NULL since i'm not passing length==0".
length == -1, doesn't mean "I don't know the length", it means
"the text is a NUL terminated string".
> > Is certainly present in lots and lots of places;
>
> bad code seen elsewhere is not an excuse, and for the record,
> i come across this rather seldomly (if at all, it's usually
> surrounded by other code telling me the author either has a
> global "don't check for NULL" policy, or didn't know his
> pointers anyway).
I've written this code in quite a few places, and I'd
defend at as being 100% correct.
> > and in fact,
> > it wouldn't make it work in particular, since you'd just
> > transfer the problem to g_utf8_validate().)
>
> really? wow, i actually expected this to be an issue as
> simple as length = !text && length < 1 ? 0 : length; since
> you already support length==0 && text==NULL, i'm sorry
> i didn't grasp the problem in it's full complexity.
Yep, you aren't grasping the problem, I think. :-)
While this may sound pedantic:
- I actually don't have a real problem with making
pango_layout_set_text() support NULL for text
as an API addition. NULL frequently means "reset
to initial state", and we do support
gtk_label_set_text (label, NULL) g_string_new (NULL)
- But I would strongly object to the idea that anywhere
that we have a text/len pair we should support
NULL/-1.
NULL/-1 => represents NULL
NULL/0 => represents ""
Regards,
Owen
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]