Re: Rationale for change in behavior of g_strsplit when passed empty string?



On Wed, Jul 18, 2001 at 11:29:14PM -0400, Owen Taylor wrote:
> > 	How do you mean?  Under glib 1.2, strsplit can return NULL or 
> > {NULL}.  Granted, I should know that my passed string is non-null, but
> > it is a sanity check.  The day I assume that strsplit returned non-NULL,
> > it'd return NULL and segfault :-)
> 
> The day you assume that g_strsplit() will "safely" handle NULL
> with only a warning is the day that your user compiled GLib
> with --disable-debug. And g_strsplit() segfaults  immediately.

	I do not assume that it will handle NULL.  I always pass
non-NULL.  I still do the != NULL check for sanity.  Maybe it is
clutter (see below).

> For any defined input, g_strsplit() never returns NULL. You
> are, in no circumstances, allowed to call g_strsplit() with
> a NULL string.

	Even with the new overridable g_malloc vectors in 2.0?  /me
looks.  Ok, it looks as though the user_malloc must return non-NULL or
glib still abort()s.  I thought we were sort of going to allow
non-aborting (and my NULL checks were mostly for that future occurence),
but that isn't too big.  I suspect I can clean some stuff up then.
	
> And what if your allowed input allowed for exactly _three_ fields?
> 
> Just write:
> 
>  gchar **fields = g_strsplit (input, ":");
> 
>  gint field_count = 0;
>  while (fields[field_count])
>    field_count++;

	Heh.  The idea of having more than one pass of the fields just
bothers me intrinsicly.  Too much time thinking about optimization, I
guess.

> It's actually a pretty darn big mess since the intended behavior
> wasn't documented well and what was implemented was almost certainly
> buggy.  We just have to make some best guess idea of what to do.

	Which of course leads to the max_tokens thread.  :-)
	I guess I'm cool with this, now that I have a clear idea of what
it will do.  I'm off to fix things up for this.

Joel

-- 

Life's Little Instruction Book #157 

	"Take time to smell the roses."

			http://www.jlbec.org/
			jlbec evilplan org




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