Re: question of uListSearch

Brandon Long <[email protected]> Thu, 30 Apr 2009 14:55:37 -0700
Newsgroups gmane.text.clearsilver.general
Organization Fiction L Networks
Message-ID <20090430215537.GD19144@bl1>
On 04/30/09 [email protected] uttered the following other thing:
> 
> Hi, my process core dump when I using uListSearch, i found that the
> 2st parameter for bsearch SHOULD BE ul->items[0], or *ul->items in
> line 225 of ulist.c
> 
> return bsearch(key, ul->items, ul->num, sizeof(void *), compareFunc);

No, its correct as is.  The usage of uList and the compareFunc's isn't
very obvious.  In fact, its possible that the "bug" is that the above
should be:

return bsearch(&key, ul->items, ul->num, sizeof(void *), compareFunc);

With the current code, you need to pass in the pointer to what you want,
which isn't very obvious.  See the attached expanded ulist_test.c code
for an example usage.

I feel like I should fix the code, but that would break anyone currently
using it, so no dice with that.

> BTW, string_array_split() should judge doese strduped string is empty,
> 
> e.g. string_array_split(&list, "/home/bigmaliang", "/") will strdup a empty
>  string in line 235 of neo_str.c
> 
> n = strdup(f);

You're asking that it doesn't include the empty string?  The above
behavior does match python split, for instance:

# python -c 'print "/home/bigmaliang".split("/")'
['', 'home', 'bigmaliang']

Brandon
-- 
  "The meek shall inherit the earth; now let's check out who gets heaven."
        -- J. Neil Shulman
                                           http://www.fiction.net/blong/