mdbx-windows: rework mdbx_memalign_alloc()/mdbx_memalign_free() to avoid dependency from CRT.

11 of 17 for https://github.com/leo-yuriev/libmdbx/issues/43

Change-Id: Id1a76f88588251cab9a93aa9753021b30159b09a
This commit is contained in:
Leonid Yuriev 2018-10-14 11:14:14 +03:00
parent f49741b4f8
commit b47badb3ee
2 changed files with 9 additions and 4 deletions

View File

@ -262,8 +262,9 @@ int mdbx_asprintf(char **strp, const char *fmt, ...) {
#ifndef mdbx_memalign_alloc
int mdbx_memalign_alloc(size_t alignment, size_t bytes, void **result) {
#if _MSC_VER
*result = _aligned_malloc(bytes, alignment);
#if defined(_WIN32) || defined(_WIN64)
(void)alignment;
*result = VirtualAlloc(NULL, bytes, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
return *result ? MDBX_SUCCESS : MDBX_ENOMEM /* ERROR_OUTOFMEMORY */;
#elif __GLIBC_PREREQ(2, 16) || __STDC_VERSION__ >= 201112L
*result = memalign(alignment, bytes);
@ -279,8 +280,8 @@ int mdbx_memalign_alloc(size_t alignment, size_t bytes, void **result) {
#ifndef mdbx_memalign_free
void mdbx_memalign_free(void *ptr) {
#if _MSC_VER
_aligned_free(ptr);
#if defined(_WIN32) || defined(_WIN64)
VirtualFree(ptr, 0, MEM_RELEASE);
#else
mdbx_free(ptr);
#endif

View File

@ -439,8 +439,12 @@ static __inline int mdbx_get_errno(void) {
return rc;
}
#ifndef mdbx_memalign_alloc
int mdbx_memalign_alloc(size_t alignment, size_t bytes, void **result);
#endif
#ifndef mdbx_memalign_free
void mdbx_memalign_free(void *ptr);
#endif
int mdbx_condmutex_init(mdbx_condmutex_t *condmutex);
int mdbx_condmutex_lock(mdbx_condmutex_t *condmutex);