Merge remote-tracking branch 'origin/mdb.master' into vl32bm

Conflicts:
	libraries/liblmdb/mdb.c
vl32b
Howard Chu 9 years ago
commit 4ab86e3b39
  1. 67
      libraries/liblmdb/mdb.c

@ -4140,23 +4140,31 @@ mdb_env_map(MDB_env *env, void *addr)
int access = SECTION_MAP_READ;
HANDLE mh;
void *map;
SIZE_T msize = 0;
ULONG pageprot = PAGE_READONLY;
SIZE_T msize;
ULONG pageprot = PAGE_READONLY, secprot, alloctype;
if (flags & MDB_WRITEMAP) {
access |= SECTION_MAP_WRITE;
pageprot = PAGE_READWRITE;
}
if (flags & MDB_RDONLY) {
secprot = PAGE_READONLY;
msize = 0;
alloctype = 0;
} else {
secprot = PAGE_READWRITE;
msize = env->me_mapsize;
alloctype = MEM_RESERVE;
}
rc = NtCreateSection(&mh, access, NULL, NULL, PAGE_READWRITE, SEC_RESERVE, env->me_fd);
rc = NtCreateSection(&mh, access, NULL, NULL, secprot, SEC_RESERVE, env->me_fd);
if (rc)
return rc;
map = addr;
#ifdef MDB_VL32
msize = 2 * env->me_psize;
#else
msize = env->me_mapsize;
#endif
rc = NtMapViewOfSection(mh, GetCurrentProcess(), &map, 0, 0, NULL, &msize, ViewUnmap, MEM_RESERVE, pageprot);
rc = NtMapViewOfSection(mh, GetCurrentProcess(), &map, 0, 0, NULL, &msize, ViewUnmap, alloctype, pageprot);
#ifdef MDB_VL32
env->me_fmh = mh;
#else
@ -4745,7 +4753,9 @@ mdb_env_setup_locks(MDB_env *env, char *lpath, int mode, int *excl)
#ifdef _WIN32
wchar_t *wlpath;
utf8_to_utf16(lpath, -1, &wlpath, NULL);
rc = utf8_to_utf16(lpath, -1, &wlpath, NULL);
if (rc)
return rc;
env->me_lfd = CreateFileW(wlpath, GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);
@ -5093,7 +5103,9 @@ mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode
len = OPEN_ALWAYS;
}
mode = FILE_ATTRIBUTE_NORMAL;
utf8_to_utf16(dpath, -1, &wpath, NULL);
rc = utf8_to_utf16(dpath, -1, &wpath, NULL);
if (rc)
goto leave;
env->me_fd = CreateFileW(wpath, oflags, FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL, len, mode, NULL);
free(wpath);
@ -5125,7 +5137,9 @@ mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode
*/
#ifdef _WIN32
len = OPEN_EXISTING;
utf8_to_utf16(dpath, -1, &wpath, NULL);
rc = utf8_to_utf16(dpath, -1, &wpath, NULL);
if (rc)
goto leave;
env->me_mfd = CreateFileW(wpath, oflags,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, len,
mode | FILE_FLAG_WRITE_THROUGH, NULL);
@ -5934,7 +5948,11 @@ mdb_page_search_root(MDB_cursor *mc, MDB_val *key, int flags)
indx_t i;
DPRINTF(("branch page %"Y"u has %u keys", mp->mp_pgno, NUMKEYS(mp)));
mdb_cassert(mc, NUMKEYS(mp) > 1);
/* Don't assert on branch pages in the FreeDB. We can get here
* while in the process of rebalancing a FreeDB branch page; we must
* let that proceed. ITS#8336
*/
mdb_cassert(mc, !mc->mc_dbi || NUMKEYS(mp) > 1);
DPRINTF(("found index 0 to page %"Y"u", NODEPGNO(NODEPTR(mp, 0))));
if (flags & (MDB_PS_FIRST|MDB_PS_LAST)) {
@ -7204,7 +7222,7 @@ more:
#endif
/* does data match? */
if (!dcmp(data, &olddata)) {
if (flags & MDB_NODUPDATA)
if (flags & (MDB_NODUPDATA|MDB_APPENDDUP))
return MDB_KEYEXIST;
/* overwrite it */
goto current;
@ -10004,7 +10022,9 @@ mdb_env_copy2(MDB_env *env, const char *path, unsigned int flags)
* already in the OS cache.
*/
#ifdef _WIN32
utf8_to_utf16(lpath, -1, &wpath, NULL);
rc = utf8_to_utf16(lpath, -1, &wpath, NULL);
if (rc)
return rc;
newfd = CreateFileW(wpath, GENERIC_WRITE, 0, NULL, CREATE_NEW,
FILE_FLAG_NO_BUFFERING|FILE_FLAG_WRITE_THROUGH, NULL);
free(wpath);
@ -10199,6 +10219,7 @@ int mdb_dbi_open(MDB_txn *txn, const char *name, unsigned int flags, MDB_dbi *db
MDB_db dummy;
int rc, dbflag, exact;
unsigned int unused = 0, seq;
char *namedup;
size_t len;
if (flags & ~VALID_FLAGS)
@ -10260,8 +10281,16 @@ int mdb_dbi_open(MDB_txn *txn, const char *name, unsigned int flags, MDB_dbi *db
MDB_node *node = NODEPTR(mc.mc_pg[mc.mc_top], mc.mc_ki[mc.mc_top]);
if ((node->mn_flags & (F_DUPDATA|F_SUBDATA)) != F_SUBDATA)
return MDB_INCOMPATIBLE;
} else if (rc == MDB_NOTFOUND && (flags & MDB_CREATE)) {
/* Create if requested */
} else if (! (rc == MDB_NOTFOUND && (flags & MDB_CREATE))) {
return rc;
}
/* Done here so we cannot fail after creating a new DB */
if ((namedup = strdup(name)) == NULL)
return ENOMEM;
if (rc) {
/* MDB_NOTFOUND and MDB_CREATE: Create new DB */
data.mv_size = sizeof(MDB_db);
data.mv_data = &dummy;
memset(&dummy, 0, sizeof(dummy));
@ -10271,10 +10300,12 @@ int mdb_dbi_open(MDB_txn *txn, const char *name, unsigned int flags, MDB_dbi *db
dbflag |= DB_DIRTY;
}
/* OK, got info, add to table */
if (rc == MDB_SUCCESS) {
if (rc) {
free(namedup);
} else {
/* Got info, register DBI in this txn */
unsigned int slot = unused ? unused : txn->mt_numdbs;
txn->mt_dbxs[slot].md_name.mv_data = strdup(name);
txn->mt_dbxs[slot].md_name.mv_data = namedup;
txn->mt_dbxs[slot].md_name.mv_size = len;
txn->mt_dbxs[slot].md_rel = NULL;
txn->mt_dbflags[slot] = dbflag;
@ -10735,6 +10766,8 @@ static int utf8_to_utf16(const char *src, int srcsize, wchar_t **dst, int *dstsi
if (need == 0)
return EINVAL;
result = malloc(sizeof(wchar_t) * need);
if (!result)
return ENOMEM;
MultiByteToWideChar(CP_UTF8, 0, src, srcsize, result, need);
if (dstsize)
*dstsize = need;

Loading…
Cancel
Save