Skip to content

Commit

Permalink
Fixup RENAME_DB() macro
Browse files Browse the repository at this point in the history
Make sure target DB's record is on a writable page
  • Loading branch information
hyc committed Sep 25, 2018
1 parent 8bf5a00 commit fe12564
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/blockchain_db/lmdb/db_lmdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3490,7 +3490,17 @@ void BlockchainLMDB::fixup()
BlockchainDB::fixup();
}

#define RENAME_DB(name) \
#define RENAME_DB(name) do { \
char n2[] = name; \
MDB_dbi tdbi; \
n2[sizeof(n2)-2]--; \
/* play some games to put (name) on a writable page */ \
result = mdb_dbi_open(txn, n2, MDB_CREATE, &tdbi); \
if (result) \
throw0(DB_ERROR(lmdb_error("Failed to create " + std::string(n2) + ": ", result).c_str())); \
result = mdb_drop(txn, tdbi, 1); \
if (result) \
throw0(DB_ERROR(lmdb_error("Failed to delete " + std::string(n2) + ": ", result).c_str())); \
k.mv_data = (void *)name; \
k.mv_size = sizeof(name)-1; \
result = mdb_cursor_open(txn, 1, &c_cur); \
Expand All @@ -3500,7 +3510,7 @@ void BlockchainLMDB::fixup()
if (result) \
throw0(DB_ERROR(lmdb_error("Failed to get DB record for " name ": ", result).c_str())); \
ptr = (char *)k.mv_data; \
ptr[sizeof(name)-2]++
ptr[sizeof(name)-2]++; } while(0)

#define LOGIF(y) if (ELPP->vRegistry()->allowed(y, "global"))

Expand Down

0 comments on commit fe12564

Please sign in to comment.