Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/stdlib/bsort_r.c
- This file was added.
/* | |||||||||
* This file is in the public domain. | |||||||||
* | |||||||||
* $FreeBSD$ | |||||||||
*/ | |||||||||
#include "block_abi.h" | |||||||||
#define I_AM_BSORT_R | |||||||||
#include "bsort.c" | |||||||||
typedef DECLARE_BLOCK(int, bsort_block, const void *, const void *); | |||||||||
static int | |||||||||
bsort_b_compare(const void *pa, const void *pb, void *arg) | |||||||||
{ | |||||||||
bsort_block compar; | |||||||||
int (*cmp)(void *, const void *, const void *); | |||||||||
delphij: Please note that in this revision, `bsort_r` is using the GNU `qsort_r` style signature, and… | |||||||||
Done Inline ActionsIssues should be fixed now! I would like bsort() to stay apart from qsort() in the beginning. Then at some later point we can simply alias the two. This will allow proper testing, in the rare case bsort has any issue. Please review the latest version of this patch. hselasky: Issues should be fixed now!
I would like bsort() to stay apart from qsort() in the beginning. | |||||||||
compar = arg; | |||||||||
delphijUnsubmitted Done Inline Actions
Style: a blank line should be added between the variable definition and actual code. delphij: Style: a blank line should be added between the variable definition and actual code. | |||||||||
cmp = (void *)compar->invoke; | |||||||||
return (cmp(compar, pa, pb)); | |||||||||
} | |||||||||
void | |||||||||
bsort_b(void *base, size_t nel, size_t width, bsort_block compar) | |||||||||
{ | |||||||||
bsort_r(base, nel, width, &bsort_b_compare, compar); | |||||||||
} |
Please note that in this revision, bsort_r is using the GNU qsort_r style signature, and bsort_b will not work as presented. The reason is that the qsort_b implementation was using the historical BSD compar interface, which passed the context pointer as the first parameter, and that matches how block ABI passes the block context. With the API change, the first parameter of compar is no longer the context pointer, which breaks the assumption.
If the intention was to replace the qsort(3) implementation with bitonic sort, it would be easier to implement bsort_b using the historical qsort_r style interface (which needs to be made available anyway, if that's the goal). If that's not a goal, you can use a combination of DECLARE_BLOCK and CALL_BLOCK to implement the block function instead (in which case bsort_b would no longer need to be implemented as a wrapper).