g_strdup() redux



Needing to close the issue of g_strdup(), I went back through the mails
on the earlier thread, and looked at some of the uses in g_strdup()
in the GNOME codebase.

After doing so, my opinion is that Darin's current patch attached to
#57633 is correct and we should apply it.

The behavior that it implements is:

 * The result is that of splitting the string on the delimeter, except
   that the empty string is special cased so that "" => []. 

 * Any remaining text after max_tokens tokens have been found is
   attached to the last token.

There are two changes here from the 1.2 behavior:

 * Trailing empty fields are preserved:  "a," => [ "a", "" ]

 * max_tokens is no longer off by one g_strsplit ("a,b,c", ",", 2)
   gives "a" "b,c", not "a" "b" "c".

I think the chances of anybody relying on either of these two behaviors
is small; they are essentially bugs, and when fixing a bug, you 
have to either cause problems for the people working around the bug,
or the people who didn't know about the bug in the first place. The
advantage of causing problems for the first group of people is that
you get rid of the bug instead of keeping it along forever. :-)

The special casing of "" => [] is perhaps a little peculiar, but I
think it is necessary:

 * Changing the handling of empty lists from 1.2 is much more likely
   to break existing programs than either of the above changes.

 * No matter how we handle "", we can't handle both empty lists and
   empty elements. My guess is that empty lists are more common
   than empty elements.

Unless I here objections soon, I'm going to go ahead and apply the patch
(with some documentation improvements.)

Regards,
                                        Owen




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