git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] string-list: make compare function compatible with qsort(3)

From
Jeff King <peff@peff.net>
Date
Dec 21, 2016, 16:12 UTC
Message-ID
<20161221161220.x3qkcwmuangcdc2l@sigill.intra.peff.net>
In-Reply-To
<c7bac0b7-c555-162f-7880-0355831cee48@web.de>
On Wed, Dec 21, 2016 at 10:36:41AM +0100, René Scharfe wrote:
> One shortcoming is that the comparison function is restricted to working
> with the string members of items; util is inaccessible to it.  Another
> one is that the value of cmp is passed in a global variable to
> cmp_items(), making string_list_sort() non-reentrant.

I think this approach is OK for string_list, but it doesn't help the general case that wants qsort_s() to actually access global data. I don't know how common that is in our codebase, though.

So I'm fine with it, but I think we might eventually need to revisit the qsort_s() thing anyway.

Show 5 quoted lines
> Remove the intermediate layer, i.e. cmp_items(), make the comparison
> functions compatible with qsort(3) and pass them pointers to full items.
> This allows comparisons to also take the util member into account, and
> avoids the need to pass the real comparison function to an intermediate
> function, removing the need for a global function.

I'm not sure if access to the util field is really of any value, after looking at it in:

  http://public-inbox.org/git/20161125171546.fa3zpapbjngjcl26@sigill.intra.peff.net/

Though note that if we do take this patch, there are probably one or two spots that could switch from QSORT() to string_list_sort().

-Peff
Previous: René ScharfeNext: René Scharfe
Message 2 of 5 in “string-list: make compare function compatible with qsort(3)”
  1. string-list: make compare function compatible with qsort(3)René Scharfe, Dec 21, 2016
  2. Jeff KingDec 21, 2016
  3. René ScharfeDec 29, 2016
  4. Junio C HamanoDec 21, 2016
  5. Junio C HamanoDec 21, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.