]> git.sur5r.net Git - openldap/commitdiff
Fix search_node, add cintcmp
authorHoward Chu <hyc@symas.com>
Tue, 6 Sep 2011 22:22:53 +0000 (15:22 -0700)
committerHoward Chu <hyc@symas.com>
Tue, 6 Sep 2011 22:22:53 +0000 (15:22 -0700)
libraries/libmdb/mdb.c

index 126827c21a59d46e57b9062ddd7e5be1d89578b9..2796d2740b893de8e7a30beca58a9ab1287df816 100644 (file)
@@ -539,7 +539,7 @@ static size_t       mdb_branch_size(MDB_env *env, MDB_val *key);
 
 static void mdb_default_cmp(MDB_txn *txn, MDB_dbi dbi);
 
 
 static void mdb_default_cmp(MDB_txn *txn, MDB_dbi dbi);
 
-static MDB_cmp_func    memncmp, memnrcmp, intcmp;
+static MDB_cmp_func    memncmp, memnrcmp, intcmp, cintcmp;
 
 #ifdef _WIN32
 static SECURITY_DESCRIPTOR mdb_null_sd;
 
 #ifdef _WIN32
 static SECURITY_DESCRIPTOR mdb_null_sd;
@@ -1937,6 +1937,7 @@ mdb_env_close(MDB_env *env)
        free(env);
 }
 
        free(env);
 }
 
+/* only for aligned ints */
 static int
 intcmp(const MDB_val *a, const MDB_val *b)
 {
 static int
 intcmp(const MDB_val *a, const MDB_val *b)
 {
@@ -1954,6 +1955,26 @@ intcmp(const MDB_val *a, const MDB_val *b)
        }
 }
 
        }
 }
 
+/* ints must always be the same size */
+static int
+cintcmp(const MDB_val *a, const MDB_val *b)
+{
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+       unsigned char *u, *c;
+       int x;
+
+       u = a->mv_data + a->mv_size;
+       c = b->mv_data + a->mv_size;
+       while(u > (unsigned char *)a->mv_data) {
+               x = *--u - *--c;
+               if (x) break;
+       }
+       return x;
+#else
+       return memcmp(a->mv_data, b->mv_data, a->mv_size);
+#endif
+}
+
 static int
 memncmp(const MDB_val *a, const MDB_val *b)
 {
 static int
 memncmp(const MDB_val *a, const MDB_val *b)
 {
@@ -2065,6 +2086,8 @@ mdb_search_node(MDB_txn *txn, MDB_dbi dbi, MDB_page *mp, MDB_val *key,
 
        if (rc > 0) {   /* Found entry is less than the key. */
                i++;    /* Skip to get the smallest entry larger than key. */
 
        if (rc > 0) {   /* Found entry is less than the key. */
                i++;    /* Skip to get the smallest entry larger than key. */
+               if (!IS_LEAF2(mp))
+                       node = NODEPTR(mp, i);
        }
        if (exactp)
                *exactp = (rc == 0);
        }
        if (exactp)
                *exactp = (rc == 0);
@@ -4337,12 +4360,10 @@ mdb_env_stat(MDB_env *env, MDB_stat *arg)
 static void
 mdb_default_cmp(MDB_txn *txn, MDB_dbi dbi)
 {
 static void
 mdb_default_cmp(MDB_txn *txn, MDB_dbi dbi)
 {
-       if (txn->mt_dbs[dbi].md_flags & (MDB_REVERSEKEY
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-               |MDB_INTEGERKEY
-#endif
-       ))
+       if (txn->mt_dbs[dbi].md_flags & MDB_REVERSEKEY)
                txn->mt_dbxs[dbi].md_cmp = memnrcmp;
                txn->mt_dbxs[dbi].md_cmp = memnrcmp;
+       else if (txn->mt_dbs[dbi].md_flags & MDB_INTEGERKEY)
+               txn->mt_dbxs[dbi].md_cmp = cintcmp;
        else
                txn->mt_dbxs[dbi].md_cmp = memncmp;
 
        else
                txn->mt_dbxs[dbi].md_cmp = memncmp;
 
@@ -4351,11 +4372,7 @@ mdb_default_cmp(MDB_txn *txn, MDB_dbi dbi)
                        if (txn->mt_dbs[dbi].md_flags & MDB_DUPFIXED)
                                txn->mt_dbxs[dbi].md_dcmp = intcmp;
                        else
                        if (txn->mt_dbs[dbi].md_flags & MDB_DUPFIXED)
                                txn->mt_dbxs[dbi].md_dcmp = intcmp;
                        else
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-                               txn->mt_dbxs[dbi].md_dcmp = memnrcmp;
-#else
-                               txn->mt_dbxs[dbi].md_dcmp = memncmp;
-#endif
+                               txn->mt_dbxs[dbi].md_dcmp = cintcmp;
                } else if (txn->mt_dbs[dbi].md_flags & MDB_REVERSEDUP) {
                        txn->mt_dbxs[dbi].md_dcmp = memnrcmp;
                } else {
                } else if (txn->mt_dbs[dbi].md_flags & MDB_REVERSEDUP) {
                        txn->mt_dbxs[dbi].md_dcmp = memnrcmp;
                } else {