mdb_dbi_open tweak

Always save the terminating NUL of the incoming DB name
Stop using the old mdb_open/mdb_close function names
 .. should consider renaming mdb_stat/mdb_drop to mdb_dbi_... too.
mdb.master3
Howard Chu 7 years ago
parent 3585a1eb97
commit e4cf950264
  1. 12
      libraries/liblmdb/mdb.c
  2. 19
      libraries/liblmdb/mdb_dump.c
  3. 4
      libraries/liblmdb/mdb_load.c
  4. 19
      libraries/liblmdb/mdb_stat.c

@ -11110,7 +11110,7 @@ int mdb_dbi_open(MDB_txn *txn, const char *name, unsigned int flags, MDB_dbi *db
int rc, dbflag, exact;
unsigned int unused = 0, seq;
char *namedup;
size_t len;
size_t size;
if (flags & ~VALID_FLAGS)
return EINVAL;
@ -11137,15 +11137,15 @@ int mdb_dbi_open(MDB_txn *txn, const char *name, unsigned int flags, MDB_dbi *db
}
/* Is the DB already open? */
len = strlen(name);
size = strlen(name) + 1;
for (i=CORE_DBS; i<txn->mt_numdbs; i++) {
if (!txn->mt_dbxs[i].md_name.mv_size) {
/* Remember this free slot */
if (!unused) unused = i;
continue;
}
if (len == txn->mt_dbxs[i].md_name.mv_size &&
!strncmp(name, txn->mt_dbxs[i].md_name.mv_data, len)) {
if (size == txn->mt_dbxs[i].md_name.mv_size &&
!strcmp(name, txn->mt_dbxs[i].md_name.mv_data)) {
*dbi = i;
return MDB_SUCCESS;
}
@ -11162,7 +11162,7 @@ int mdb_dbi_open(MDB_txn *txn, const char *name, unsigned int flags, MDB_dbi *db
/* Find the DB info */
dbflag = DB_NEW|DB_VALID|DB_USRVALID;
exact = 0;
key.mv_size = len;
key.mv_size = size;
key.mv_data = (void *)name;
mdb_cursor_init(&mc, txn, MAIN_DBI, NULL);
rc = mdb_cursor_set(&mc, &key, &data, MDB_SET, &exact);
@ -11197,7 +11197,7 @@ int mdb_dbi_open(MDB_txn *txn, const char *name, unsigned int flags, MDB_dbi *db
/* Got info, register DBI in this txn */
unsigned int slot = unused ? unused : txn->mt_numdbs;
txn->mt_dbxs[slot].md_name.mv_data = namedup;
txn->mt_dbxs[slot].md_name.mv_size = len;
txn->mt_dbxs[slot].md_name.mv_size = size;
txn->mt_dbxs[slot].md_rel = NULL;
txn->mt_dbflags[slot] = dbflag;
/* txn-> and env-> are the same in read txns, use

@ -254,9 +254,9 @@ int main(int argc, char *argv[])
goto env_close;
}
rc = mdb_open(txn, subname, 0, &dbi);
rc = mdb_dbi_open(txn, subname, 0, &dbi);
if (rc) {
fprintf(stderr, "mdb_open failed, error %d %s\n", rc, mdb_strerror(rc));
fprintf(stderr, "mdb_dbi_open failed, error %d %s\n", rc, mdb_strerror(rc));
goto txn_abort;
}
@ -271,27 +271,22 @@ int main(int argc, char *argv[])
goto txn_abort;
}
while ((rc = mdb_cursor_get(cursor, &key, NULL, MDB_NEXT_NODUP)) == 0) {
char *str;
MDB_dbi db2;
if (memchr(key.mv_data, '\0', key.mv_size))
if (memchr(key.mv_data, '\0', key.mv_size-1) || ((char *)key.mv_data)[key.mv_size=1] != '\0')
continue;
count++;
str = malloc(key.mv_size+1);
memcpy(str, key.mv_data, key.mv_size);
str[key.mv_size] = '\0';
rc = mdb_open(txn, str, 0, &db2);
rc = mdb_dbi_open(txn, key.mv_data, 0, &db2);
if (rc == MDB_SUCCESS) {
if (list) {
printf("%s\n", str);
printf("%s\n", (char *)key.mv_data);
list++;
} else {
rc = dumpit(txn, db2, str);
rc = dumpit(txn, db2, key.mv_data);
if (rc)
break;
}
mdb_close(env, db2);
mdb_dbi_close(env, db2);
}
free(str);
if (rc) continue;
}
mdb_cursor_close(cursor);

@ -384,9 +384,9 @@ int main(int argc, char *argv[])
goto env_close;
}
rc = mdb_open(txn, subname, flags|MDB_CREATE, &dbi);
rc = mdb_dbi_open(txn, subname, flags|MDB_CREATE, &dbi);
if (rc) {
fprintf(stderr, "mdb_open failed, error %d %s\n", rc, mdb_strerror(rc));
fprintf(stderr, "mdb_dbi_open failed, error %d %s\n", rc, mdb_strerror(rc));
goto txn_abort;
}

@ -204,9 +204,9 @@ int main(int argc, char *argv[])
printf(" Free pages: %"Yu"\n", pages);
}
rc = mdb_open(txn, subname, 0, &dbi);
rc = mdb_dbi_open(txn, subname, 0, &dbi);
if (rc) {
fprintf(stderr, "mdb_open failed, error %d %s\n", rc, mdb_strerror(rc));
fprintf(stderr, "mdb_dbi_open failed, error %d %s\n", rc, mdb_strerror(rc));
goto txn_abort;
}
@ -228,17 +228,12 @@ int main(int argc, char *argv[])
goto txn_abort;
}
while ((rc = mdb_cursor_get(cursor, &key, NULL, MDB_NEXT_NODUP)) == 0) {
char *str;
MDB_dbi db2;
if (memchr(key.mv_data, '\0', key.mv_size))
if (memchr(key.mv_data, '\0', key.mv_size-1) || ((char *)key.mv_data)[key.mv_size-1] != '\0')
continue;
str = malloc(key.mv_size+1);
memcpy(str, key.mv_data, key.mv_size);
str[key.mv_size] = '\0';
rc = mdb_open(txn, str, 0, &db2);
rc = mdb_dbi_open(txn, key.mv_data, 0, &db2);
if (rc == MDB_SUCCESS)
printf("Status of %s\n", str);
free(str);
printf("Status of %s\n", (char *)key.mv_data);
if (rc) continue;
rc = mdb_stat(txn, db2, &mst);
if (rc) {
@ -246,7 +241,7 @@ int main(int argc, char *argv[])
goto txn_abort;
}
prstat(&mst);
mdb_close(env, db2);
mdb_dbi_close(env, db2);
}
mdb_cursor_close(cursor);
}
@ -254,7 +249,7 @@ int main(int argc, char *argv[])
if (rc == MDB_NOTFOUND)
rc = MDB_SUCCESS;
mdb_close(env, dbi);
mdb_dbi_close(env, dbi);
txn_abort:
mdb_txn_abort(txn);
env_close:

Loading…
Cancel
Save