From 46dfa9dfbdd7649cd8a71e9727aff830a58e4d55 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 13 Feb 2010 13:26:16 +1100 Subject: [PATCH] s4-ldb: added LDB_TYPESAFE_QSORT() Like TYPESAFE_QSORT() but for the ldb_qsort() function --- source4/lib/ldb/include/ldb.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h index 1958fd740b..26a196f311 100644 --- a/source4/lib/ldb/include/ldb.h +++ b/source4/lib/ldb/include/ldb.h @@ -1985,6 +1985,24 @@ time_t ldb_string_utc_to_time(const char *s); void ldb_qsort (void *const pbase, size_t total_elems, size_t size, void *opaque, ldb_qsort_cmp_fn_t cmp); +#ifndef discard_const +#define discard_const(ptr) ((void *)((uintptr_t)(ptr))) +#endif + +/* + a wrapper around ldb_qsort() that ensures the comparison function is + type safe. This will produce a compilation warning if the types + don't match + */ +#define LDB_TYPESAFE_QSORT(base, numel, opaque, comparison) \ +do { \ + if (numel > 1) { \ + ldb_qsort(base, numel, sizeof((base)[0]), discard_const(opaque), (ldb_qsort_cmp_fn_t)comparison); \ + comparison(&((base)[0]), &((base)[1]), opaque); \ + } \ +} while (0) + + /** Convert an array of string represention of a control into an array of ldb_control structures -- 2.34.1