Replace EINVALs with generalized MDB_INCOMPATIBLE.

Also check xcursor instead of DUPSORT, it's slightly briefer.
vmware
Hallvard Furuseth 11 years ago
parent ef899fe84e
commit 9beea541e1
  1. 2
      libraries/liblmdb/lmdb.h
  2. 60
      libraries/liblmdb/mdb.c

@ -383,7 +383,7 @@ typedef enum MDB_cursor_op {
#define MDB_PAGE_FULL (-30786) #define MDB_PAGE_FULL (-30786)
/** Database contents grew beyond environment mapsize */ /** Database contents grew beyond environment mapsize */
#define MDB_MAP_RESIZED (-30785) #define MDB_MAP_RESIZED (-30785)
/** Database flags changed or would change */ /** MDB_INCOMPATIBLE: Operation and DB incompatible, or DB flags changed */
#define MDB_INCOMPATIBLE (-30784) #define MDB_INCOMPATIBLE (-30784)
/** Invalid reuse of reader locktable slot */ /** Invalid reuse of reader locktable slot */
#define MDB_BAD_RSLOT (-30783) #define MDB_BAD_RSLOT (-30783)

@ -1125,7 +1125,7 @@ static char *const mdb_errstr[] = {
"MDB_CURSOR_FULL: Internal error - cursor stack limit reached", "MDB_CURSOR_FULL: Internal error - cursor stack limit reached",
"MDB_PAGE_FULL: Internal error - page has no more space", "MDB_PAGE_FULL: Internal error - page has no more space",
"MDB_MAP_RESIZED: Database contents grew beyond environment mapsize", "MDB_MAP_RESIZED: Database contents grew beyond environment mapsize",
"MDB_INCOMPATIBLE: Database flags changed or would change", "MDB_INCOMPATIBLE: Operation and DB incompatible, or DB flags changed",
"MDB_BAD_RSLOT: Invalid reuse of reader locktable slot", "MDB_BAD_RSLOT: Invalid reuse of reader locktable slot",
"MDB_BAD_TXN: Transaction cannot recover - it must be aborted", "MDB_BAD_TXN: Transaction cannot recover - it must be aborted",
"MDB_BAD_VALSIZE: Too big key/data, key is empty, or wrong DUPFIXED size", "MDB_BAD_VALSIZE: Too big key/data, key is empty, or wrong DUPFIXED size",
@ -5313,6 +5313,7 @@ mdb_cursor_get(MDB_cursor *mc, MDB_val *key, MDB_val *data,
{ {
int rc; int rc;
int exact = 0; int exact = 0;
int (*mfunc)(MDB_cursor *mc, MDB_val *key, MDB_val *data);
assert(mc); assert(mc);
@ -5346,10 +5347,14 @@ mdb_cursor_get(MDB_cursor *mc, MDB_val *key, MDB_val *data,
break; break;
case MDB_GET_BOTH: case MDB_GET_BOTH:
case MDB_GET_BOTH_RANGE: case MDB_GET_BOTH_RANGE:
if (data == NULL || mc->mc_xcursor == NULL) { if (data == NULL) {
rc = EINVAL; rc = EINVAL;
break; break;
} }
if (mc->mc_xcursor == NULL) {
rc = MDB_INCOMPATIBLE;
break;
}
/* FALLTHRU */ /* FALLTHRU */
case MDB_SET: case MDB_SET:
case MDB_SET_KEY: case MDB_SET_KEY:
@ -5364,23 +5369,28 @@ mdb_cursor_get(MDB_cursor *mc, MDB_val *key, MDB_val *data,
rc = mdb_cursor_set(mc, key, data, op, &exact); rc = mdb_cursor_set(mc, key, data, op, &exact);
break; break;
case MDB_GET_MULTIPLE: case MDB_GET_MULTIPLE:
if (data == NULL || if (data == NULL || !(mc->mc_flags & C_INITIALIZED)) {
!(mc->mc_db->md_flags & MDB_DUPFIXED) ||
!(mc->mc_flags & C_INITIALIZED)) {
rc = EINVAL; rc = EINVAL;
break; break;
} }
if (!(mc->mc_db->md_flags & MDB_DUPFIXED)) {
rc = MDB_INCOMPATIBLE;
break;
}
rc = MDB_SUCCESS; rc = MDB_SUCCESS;
if (!(mc->mc_xcursor->mx_cursor.mc_flags & C_INITIALIZED) || if (!(mc->mc_xcursor->mx_cursor.mc_flags & C_INITIALIZED) ||
(mc->mc_xcursor->mx_cursor.mc_flags & C_EOF)) (mc->mc_xcursor->mx_cursor.mc_flags & C_EOF))
break; break;
goto fetchm; goto fetchm;
case MDB_NEXT_MULTIPLE: case MDB_NEXT_MULTIPLE:
if (data == NULL || if (data == NULL) {
!(mc->mc_db->md_flags & MDB_DUPFIXED)) {
rc = EINVAL; rc = EINVAL;
break; break;
} }
if (!(mc->mc_db->md_flags & MDB_DUPFIXED)) {
rc = MDB_INCOMPATIBLE;
break;
}
if (!(mc->mc_flags & C_INITIALIZED)) if (!(mc->mc_flags & C_INITIALIZED))
rc = mdb_cursor_first(mc, key, data); rc = mdb_cursor_first(mc, key, data);
else else
@ -5423,28 +5433,28 @@ fetchm:
rc = mdb_cursor_first(mc, key, data); rc = mdb_cursor_first(mc, key, data);
break; break;
case MDB_FIRST_DUP: case MDB_FIRST_DUP:
if (data == NULL || mfunc = mdb_cursor_first;
!(mc->mc_db->md_flags & MDB_DUPSORT) || mmove:
!(mc->mc_flags & C_INITIALIZED) || if (data == NULL || !(mc->mc_flags & C_INITIALIZED)) {
!(mc->mc_xcursor->mx_cursor.mc_flags & C_INITIALIZED)) {
rc = EINVAL; rc = EINVAL;
break; break;
} }
rc = mdb_cursor_first(&mc->mc_xcursor->mx_cursor, data, NULL); if (mc->mc_xcursor == NULL) {
break; rc = MDB_INCOMPATIBLE;
case MDB_LAST:
rc = mdb_cursor_last(mc, key, data);
break; break;
case MDB_LAST_DUP: }
if (data == NULL || if (!(mc->mc_xcursor->mx_cursor.mc_flags & C_INITIALIZED)) {
!(mc->mc_db->md_flags & MDB_DUPSORT) ||
!(mc->mc_flags & C_INITIALIZED) ||
!(mc->mc_xcursor->mx_cursor.mc_flags & C_INITIALIZED)) {
rc = EINVAL; rc = EINVAL;
break; break;
} }
rc = mdb_cursor_last(&mc->mc_xcursor->mx_cursor, data, NULL); rc = mfunc(&mc->mc_xcursor->mx_cursor, data, NULL);
break;
case MDB_LAST:
rc = mdb_cursor_last(mc, key, data);
break; break;
case MDB_LAST_DUP:
mfunc = mdb_cursor_last;
goto mmove;
default: default:
DPRINTF("unhandled/unimplemented cursor operation %u", op); DPRINTF("unhandled/unimplemented cursor operation %u", op);
rc = EINVAL; rc = EINVAL;
@ -5509,7 +5519,7 @@ mdb_cursor_put(MDB_cursor *mc, MDB_val *key, MDB_val *data,
dcount = data[1].mv_size; dcount = data[1].mv_size;
data[1].mv_size = 0; data[1].mv_size = 0;
if (!F_ISSET(mc->mc_db->md_flags, MDB_DUPFIXED)) if (!F_ISSET(mc->mc_db->md_flags, MDB_DUPFIXED))
return EINVAL; return MDB_INCOMPATIBLE;
} }
nospill = flags & MDB_NOSPILL; nospill = flags & MDB_NOSPILL;
@ -6505,8 +6515,8 @@ mdb_cursor_count(MDB_cursor *mc, size_t *countp)
if (mc == NULL || countp == NULL) if (mc == NULL || countp == NULL)
return EINVAL; return EINVAL;
if (!(mc->mc_db->md_flags & MDB_DUPSORT)) if (mc->mc_xcursor == NULL)
return EINVAL; return MDB_INCOMPATIBLE;
leaf = NODEPTR(mc->mc_pg[mc->mc_top], mc->mc_ki[mc->mc_top]); leaf = NODEPTR(mc->mc_pg[mc->mc_top], mc->mc_ki[mc->mc_top]);
if (!F_ISSET(leaf->mn_flags, F_DUPDATA)) { if (!F_ISSET(leaf->mn_flags, F_DUPDATA)) {
@ -7850,7 +7860,7 @@ int mdb_dbi_open(MDB_txn *txn, const char *name, unsigned int flags, MDB_dbi *db
/* make sure this is actually a DB */ /* make sure this is actually a DB */
MDB_node *node = NODEPTR(mc.mc_pg[mc.mc_top], mc.mc_ki[mc.mc_top]); MDB_node *node = NODEPTR(mc.mc_pg[mc.mc_top], mc.mc_ki[mc.mc_top]);
if (!(node->mn_flags & F_SUBDATA)) if (!(node->mn_flags & F_SUBDATA))
return EINVAL; return MDB_INCOMPATIBLE;
} else if (rc == MDB_NOTFOUND && (flags & MDB_CREATE)) { } else if (rc == MDB_NOTFOUND && (flags & MDB_CREATE)) {
/* Create if requested */ /* Create if requested */
MDB_db dummy; MDB_db dummy;

Loading…
Cancel
Save