ITS#7828, #7793
authorHoward Chu <hyc@symas.com>
Wed, 26 Mar 2014 09:33:51 +0000 (02:33 -0700)
committerHoward Chu <hyc@symas.com>
Wed, 26 Mar 2014 09:35:56 +0000 (02:35 -0700)
Clarify MDB_CURRENT key usage, simplify freelist_save

libraries/liblmdb/lmdb.h
libraries/liblmdb/mdb.c

index 646943cab99e9b0fb1dbf6f3c98baabf2e704fe2..dc64b12c37a5ba68752fe60c995c971ea87c2edd 100644 (file)
@@ -1334,7 +1334,8 @@ int  mdb_cursor_get(MDB_cursor *cursor, MDB_val *key, MDB_val *data,
         * <ul>
         *      <li>#MDB_CURRENT - overwrite the data of the key/data pair to which
         *              the cursor refers with the specified data item. The \b key
-        *              parameter is ignored.
+        *              parameter is not used for positioning the cursor, but should
+        *              still be provided.
         *      <li>#MDB_NODUPDATA - enter the new key/data pair only if it does not
         *              already appear in the database. This flag may only be specified
         *              if the database was opened with #MDB_DUPSORT. The function will
index 64163fa5319e75bf95620e3cf1687ba1d616d7bc..487999abe0f4d44d415c8367cfa9463367879350 100644 (file)
@@ -2770,7 +2770,6 @@ mdb_freelist_save(MDB_txn *txn)
                mop += mop_len;
                rc = mdb_cursor_first(&mc, &key, &data);
                for (; !rc; rc = mdb_cursor_next(&mc, &key, &data, MDB_NEXT)) {
-                       unsigned flags = MDB_CURRENT;
                        txnid_t id = *(txnid_t *)key.mv_data;
                        ssize_t len = (ssize_t)(data.mv_size / sizeof(MDB_ID)) - 1;
                        MDB_ID save;
@@ -2780,12 +2779,11 @@ mdb_freelist_save(MDB_txn *txn)
                        if (len > mop_len) {
                                len = mop_len;
                                data.mv_size = (len + 1) * sizeof(MDB_ID);
-                               flags = 0;
                        }
                        data.mv_data = mop -= len;
                        save = mop[0];
                        mop[0] = len;
-                       rc = mdb_cursor_put(&mc, &key, &data, flags);
+                       rc = mdb_cursor_put(&mc, &key, &data, MDB_CURRENT);
                        mop[0] = save;
                        if (rc || !(mop_len -= len))
                                break;
@@ -6152,7 +6150,7 @@ current:
                         */
                        if (F_ISSET(flags, MDB_RESERVE))
                                data->mv_data = olddata.mv_data;
-                       else if (data->mv_size)
+                       else if (!(mc->mc_flags & C_SUB))
                                memcpy(olddata.mv_data, data->mv_data, data->mv_size);
                        else
                                memcpy(NODEKEY(leaf), key->mv_data, key->mv_size);