s4-ldb: use TYPESAFE_QSORT() in the rest of the ldb code
authorAndrew Tridgell <tridge@samba.org>
Sat, 13 Feb 2010 23:37:20 +0000 (10:37 +1100)
committerAndrew Tridgell <tridge@samba.org>
Sun, 14 Feb 2010 07:44:20 +0000 (18:44 +1100)
lib/util/tsort.h
source4/lib/ldb/common/ldb_dn.c
source4/lib/ldb/common/ldb_msg.c
source4/lib/ldb/include/ldb.h
source4/lib/ldb/ldb_tdb/ldb_index.c
source4/lib/ldb/tools/ldbdel.c

index 236b3699123bb6f95788878b465c4db3c2d80f2b..811d6cd2f77c734c8c9c28acd9d661e4d0cd9978 100644 (file)
   a wrapper around qsort() that ensures the comparison function is
   type safe.
  */
   a wrapper around qsort() that ensures the comparison function is
   type safe.
  */
+#ifndef TYPESAFE_QSORT
 #define TYPESAFE_QSORT(base, numel, comparison) \
 do { \
        if (numel > 1) { \
 #define TYPESAFE_QSORT(base, numel, comparison) \
 do { \
        if (numel > 1) { \
-               qsort(base, numel, sizeof((base)[0]), QSORT_CAST comparison); \
+               qsort(base, numel, sizeof((base)[0]), (int (*)(const void *, const void *))comparison); \
                assert(comparison(&((base)[0]), &((base)[1])) <= 0); \
        } \
 } while (0)
                assert(comparison(&((base)[0]), &((base)[1])) <= 0); \
        } \
 } while (0)
+#endif
 
 #endif
 
 #endif
index 252a0c632b16178277b5ab3e14c4d603f5c9b69a..c395be29007813ad365114422f0152f94cc3f5fd 100644 (file)
@@ -824,8 +824,8 @@ char *ldb_dn_get_extended_linearized(void *mem_ctx, struct ldb_dn *dn, int mode)
         * the resulting DNs consistent, plus to ensure that we put
         * 'DELETED' first, so it can be very quickly recognised
         */
         * the resulting DNs consistent, plus to ensure that we put
         * 'DELETED' first, so it can be very quickly recognised
         */
-       qsort(dn->ext_components, dn->ext_comp_num, sizeof(dn->ext_components[0]),
-             ldb_dn_extended_component_compare);
+       TYPESAFE_QSORT(dn->ext_components, dn->ext_comp_num,
+                      ldb_dn_extended_component_compare);
 
        for (i = 0; i < dn->ext_comp_num; i++) {
                const struct ldb_dn_extended_syntax *ext_syntax;
 
        for (i = 0; i < dn->ext_comp_num; i++) {
                const struct ldb_dn_extended_syntax *ext_syntax;
index 9f90f3340562d8676c77a4403b09bb60a5a0a5b9..f4adb560b1dfe8521b478bee670f339013946745 100644 (file)
@@ -464,8 +464,8 @@ struct ldb_dn *ldb_msg_find_attr_as_dn(struct ldb_context *ldb,
 */
 void ldb_msg_sort_elements(struct ldb_message *msg)
 {
 */
 void ldb_msg_sort_elements(struct ldb_message *msg)
 {
-       qsort(msg->elements, msg->num_elements, sizeof(struct ldb_message_element), 
-             (comparison_fn_t)ldb_msg_element_compare_name);
+       TYPESAFE_QSORT(msg->elements, msg->num_elements,
+                      ldb_msg_element_compare_name);
 }
 
 /*
 }
 
 /*
index 26a196f311321f43237013af6a1eb334659187c0..fc5d47ac32187fbbca21ac23f0a5600d5316c759 100644 (file)
@@ -2002,6 +2002,17 @@ do { \
        } \
 } while (0)
 
        } \
 } while (0)
 
+/* allow ldb to also call TYPESAFE_QSORT() */
+#ifndef TYPESAFE_QSORT
+#define TYPESAFE_QSORT(base, numel, comparison) \
+do { \
+       if (numel > 1) { \
+               qsort(base, numel, sizeof((base)[0]), (int (*)(const void *, const void *))comparison); \
+               comparison(&((base)[0]), &((base)[1])); \
+       } \
+} while (0)
+#endif
+
 
 
 /**
 
 
 /**
index 4b31021001115e2f32f3e4518479eb0f8bdb119c..bb4617db0907ee1c02a74acf591cad58922c4f07 100644 (file)
@@ -973,7 +973,7 @@ static void ltdb_dn_list_remove_duplicates(struct dn_list *list)
                return;
        }
 
                return;
        }
 
-       qsort(list->dn, list->count, sizeof(struct ldb_val), (comparison_fn_t) dn_list_cmp);
+       TYPESAFE_QSORT(list->dn, list->count, dn_list_cmp);
 
        new_count = 1;
        for (i=1; i<list->count; i++) {
 
        new_count = 1;
        for (i=1; i<list->count; i++) {
index 6de15ee042a50f63efc30613c9052bd774d35562..1b8adf714c9e44cb6d9dba5a828709af7bd29d3c 100644 (file)
 #include "ldb.h"
 #include "tools/cmdline.h"
 #include "ldbutil.h"
 #include "ldb.h"
 #include "tools/cmdline.h"
 #include "ldbutil.h"
+#include "replace.h"
 
 
-static int dn_cmp(const void *p1, const void *p2)
+static int dn_cmp(struct ldb_message **msg1, struct ldb_message **msg2)
 {
 {
-       const struct ldb_message *msg1, *msg2;
-       msg1 = *(const struct ldb_message * const *)p1;
-       msg2 = *(const struct ldb_message * const *)p2;
-       return ldb_dn_compare(msg1->dn, msg2->dn);
+       return ldb_dn_compare((*msg1)->dn, (*msg2)->dn);
 }
 
 static int ldb_delete_recursive(struct ldb_context *ldb, struct ldb_dn *dn,struct ldb_control **req_ctrls)
 }
 
 static int ldb_delete_recursive(struct ldb_context *ldb, struct ldb_dn *dn,struct ldb_control **req_ctrls)
@@ -53,7 +51,7 @@ static int ldb_delete_recursive(struct ldb_context *ldb, struct ldb_dn *dn,struc
        if (ret != LDB_SUCCESS) return -1;
 
        /* sort the DNs, deepest first */
        if (ret != LDB_SUCCESS) return -1;
 
        /* sort the DNs, deepest first */
-       qsort(res->msgs, res->count, sizeof(res->msgs[0]), dn_cmp);
+       TYPESAFE_QSORT(res->msgs, res->count, dn_cmp);
 
        for (i = 0; i < res->count; i++) {
                if (ldb_delete_ctrl(ldb, res->msgs[i]->dn,req_ctrls) == 0) {
 
        for (i = 0; i < res->count; i++) {
                if (ldb_delete_ctrl(ldb, res->msgs[i]->dn,req_ctrls) == 0) {