diff options
-rw-r--r-- | src/include/intpack.i | 10 | ||||
-rw-r--r-- | src/os_win/os_alloc.c | 51 | ||||
-rw-r--r-- | src/os_win/os_filesize.c | 2 | ||||
-rw-r--r-- | src/os_win/os_open.c | 5 |
4 files changed, 14 insertions, 54 deletions
diff --git a/src/include/intpack.i b/src/include/intpack.i index 41f742d6364..01559657acd 100644 --- a/src/include/intpack.i +++ b/src/include/intpack.i @@ -54,8 +54,14 @@ #define WT_LEADING_ZEROS(x, i) \ (i = (x == 0) ? (int)sizeof (x) : __builtin_clzll(x) >> 3) #elif defined(_MSC_VER) -#define WT_LEADING_ZEROS(x, i) \ - (i = (x == 0) ? (int)sizeof (x) : (int)__lzcnt64(x) >> 3) +#define WT_LEADING_ZEROS(x, i) do { \ + if (x == 0) i = (int)sizeof(x); \ + else { \ + unsigned long __index; \ + _BitScanReverse64(&__index, x); \ + __index = 63 ^ __index; \ + i = (int)(__index >> 3); } \ + } while (0) #else #define WT_LEADING_ZEROS(x, i) do { \ uint64_t __x = (x); \ diff --git a/src/os_win/os_alloc.c b/src/os_win/os_alloc.c index 6b595436546..25f59d3e612 100644 --- a/src/os_win/os_alloc.c +++ b/src/os_win/os_alloc.c @@ -109,55 +109,8 @@ __wt_realloc_aligned(WT_SESSION_IMPL *session, size_t *bytes_allocated_ret, size_t bytes_to_allocate, void *retp) { /* - * !!! - * This function MUST handle a NULL WT_SESSION_IMPL handle. - */ - if (session != NULL && S2C(session)->buffer_alignment > 0) { - void *p, *newp; - size_t bytes_allocated; - - /* - * Sometimes we're allocating memory and we don't care about the - * final length -- bytes_allocated_ret may be NULL. - */ - p = *(void **)retp; - bytes_allocated = - (bytes_allocated_ret == NULL) ? 0 : *bytes_allocated_ret; - WT_ASSERT(session, - (p == NULL && bytes_allocated == 0) || - (p != NULL && - (bytes_allocated_ret == NULL || bytes_allocated != 0))); - WT_ASSERT(session, bytes_to_allocate != 0); - WT_ASSERT(session, bytes_allocated < bytes_to_allocate); - - if (session != NULL) - WT_STAT_FAST_CONN_INCR(session, memory_allocation); - - if ((newp = _aligned_malloc( - S2C(session)->buffer_alignment, - bytes_to_allocate)) != 0) - WT_RET_MSG(session, errno, "memory allocation"); - - if (p != NULL) - memcpy(newp, p, bytes_allocated); - __wt_free(session, p); - p = newp; - - /* Clear the allocated memory (see above). */ - memset((uint8_t *)p + bytes_allocated, 0, - bytes_to_allocate - bytes_allocated); - - /* Update caller's bytes allocated value. */ - if (bytes_allocated_ret != NULL) - *bytes_allocated_ret = bytes_to_allocate; - - *(void **)retp = p; - return (0); - } - - /* - * If there is no posix_memalign function, or no alignment configured, - * fall back to realloc. + * Visual C CRT memalign does not match posix behavior + * and would also double each allocation so it is bad for memory use */ return (__wt_realloc( session, bytes_allocated_ret, bytes_to_allocate, retp)); diff --git a/src/os_win/os_filesize.c b/src/os_win/os_filesize.c index 79c30e1d853..b34127bea72 100644 --- a/src/os_win/os_filesize.c +++ b/src/os_win/os_filesize.c @@ -42,7 +42,7 @@ __wt_filesize_name( WT_RET(__wt_filename(session, filename, &path)); - ret = GetFileAttributesEx(filename, GetFileExInfoStandard, &data); + ret = GetFileAttributesEx(path, GetFileExInfoStandard, &data); __wt_free(session, path); diff --git a/src/os_win/os_open.c b/src/os_win/os_open.c index 44e4190fa49..1b711299689 100644 --- a/src/os_win/os_open.c +++ b/src/os_win/os_open.c @@ -121,8 +121,9 @@ __wt_open(WT_SESSION_IMPL *session, OPEN_EXISTING, f, NULL); - WT_ERR_MSG(session, __wt_errno(), - "open failed for secondary handle: %s", path); + if (filehandle == INVALID_HANDLE_VALUE) + WT_ERR_MSG(session, __wt_errno(), + "open failed for secondary handle: %s", path); WT_ERR(__wt_calloc(session, 1, sizeof(WT_FH), &fh)); WT_ERR(__wt_strdup(session, name, &fh->name)); |