]> git.sur5r.net Git - openldap/commitdiff
ITS#8117 Fix MDB_INTEGERDUP keysize doc + md_dcmp
authorHallvard Furuseth <hallvard@openldap.org>
Tue, 19 May 2015 18:33:35 +0000 (20:33 +0200)
committerHallvard Furuseth <hallvard@openldap.org>
Wed, 27 May 2015 22:08:51 +0000 (00:08 +0200)
libraries/liblmdb/lmdb.h
libraries/liblmdb/mdb.c

index 871f07d1e711661f545309c3566d56dcd5de8ac1..e8aed94418cd57e38eb38ce8e509f5636f428199 100644 (file)
@@ -296,12 +296,12 @@ typedef void (MDB_rel_func)(MDB_val *item, void *oldptr, void *newptr, void *rel
 #define MDB_REVERSEKEY 0x02
        /** use sorted duplicates */
 #define MDB_DUPSORT            0x04
-       /** numeric keys in native byte order.
+       /** numeric keys in native byte order: either unsigned int or size_t.
         *  The keys must all be of the same size. */
 #define MDB_INTEGERKEY 0x08
        /** with #MDB_DUPSORT, sorted dup items have fixed size */
 #define MDB_DUPFIXED   0x10
-       /** with #MDB_DUPSORT, dups are numeric in native byte order */
+       /** with #MDB_DUPSORT, dups are #MDB_INTEGERKEY-style integers */
 #define MDB_INTEGERDUP 0x20
        /** with #MDB_DUPSORT, use reverse string dups */
 #define MDB_REVERSEDUP 0x40
@@ -1052,9 +1052,9 @@ int  mdb_txn_renew(MDB_txn *txn);
         *              keys may have multiple data items, stored in sorted order.) By default
         *              keys must be unique and may have only a single data item.
         *      <li>#MDB_INTEGERKEY
-        *              Keys are binary integers in native byte order. Setting this option
-        *              requires all keys to be the same size, typically sizeof(int)
-        *              or sizeof(size_t).
+        *              Keys are binary integers in native byte order, either unsigned int
+        *              or size_t, and will be sorted as such.
+        *              The keys must all be of the same size.
         *      <li>#MDB_DUPFIXED
         *              This flag may only be used in combination with #MDB_DUPSORT. This option
         *              tells the library that the data items for this database are all the same
@@ -1062,8 +1062,8 @@ int  mdb_txn_renew(MDB_txn *txn);
         *              all data items are the same size, the #MDB_GET_MULTIPLE and #MDB_NEXT_MULTIPLE
         *              cursor operations may be used to retrieve multiple items at once.
         *      <li>#MDB_INTEGERDUP
-        *              This option specifies that duplicate data items are also integers, and
-        *              should be sorted as such.
+        *              This option specifies that duplicate data items are binary integers,
+        *              similar to #MDB_INTEGERKEY keys.
         *      <li>#MDB_REVERSEDUP
         *              This option specifies that duplicate data items should be compared as
         *              strings in reverse order.
index 7439dd015b79c9b5e4028631bfc08cd7a5740552..86635bfea63fe80b1437c266261780fe7bf74186 100644 (file)
@@ -1245,6 +1245,13 @@ static void mdb_default_cmp(MDB_txn *txn, MDB_dbi dbi);
 static MDB_cmp_func    mdb_cmp_memn, mdb_cmp_memnr, mdb_cmp_int, mdb_cmp_cint, mdb_cmp_long;
 /** @endcond */
 
+/** Compare two items pointing at size_t's of unknown alignment. */
+#ifdef MISALIGNED_OK
+# define mdb_cmp_clong mdb_cmp_long
+#else
+# define mdb_cmp_clong mdb_cmp_cint
+#endif
+
 #ifdef _WIN32
 static SECURITY_DESCRIPTOR mdb_null_sd;
 static SECURITY_ATTRIBUTES mdb_all_sa;
@@ -1558,7 +1565,12 @@ mdb_cmp(MDB_txn *txn, MDB_dbi dbi, const MDB_val *a, const MDB_val *b)
 int
 mdb_dcmp(MDB_txn *txn, MDB_dbi dbi, const MDB_val *a, const MDB_val *b)
 {
-       return txn->mt_dbxs[dbi].md_dcmp(a, b);
+       MDB_cmp_func *dcmp = txn->mt_dbxs[dbi].md_dcmp;
+#if UINT_MAX < SIZE_MAX
+       if (dcmp == mdb_cmp_int && a->mv_size == sizeof(size_t))
+               dcmp = mdb_cmp_clong;
+#endif
+       return dcmp(a, b);
 }
 
 /** Allocate memory for a page.
@@ -4772,7 +4784,11 @@ mdb_cmp_long(const MDB_val *a, const MDB_val *b)
                *(size_t *)a->mv_data > *(size_t *)b->mv_data;
 }
 
-/** Compare two items pointing at aligned unsigned int's */
+/** Compare two items pointing at aligned unsigned int's.
+ *
+ *     This is also set as #MDB_INTEGERDUP|#MDB_DUPFIXED's #MDB_dbx.%md_dcmp,
+ *     but #mdb_cmp_clong() is called instead if the data type is size_t.
+ */
 static int
 mdb_cmp_int(const MDB_val *a, const MDB_val *b)
 {
@@ -4810,13 +4826,6 @@ mdb_cmp_cint(const MDB_val *a, const MDB_val *b)
 #endif
 }
 
-/** Compare two items pointing at size_t's of unknown alignment. */
-#ifdef MISALIGNED_OK
-# define mdb_cmp_clong mdb_cmp_long
-#else
-# define mdb_cmp_clong mdb_cmp_cint
-#endif
-
 /** Compare two items lexically */
 static int
 mdb_cmp_memn(const MDB_val *a, const MDB_val *b)