From d2bfb2e489d05977b195219fafb628dbf18778f3 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Sun, 14 Oct 2018 18:44:22 +0300 Subject: [PATCH] mdbx: allow pre-define mdbx_malloc/mdbx_free macros. Related to https://github.com/leo-yuriev/libmdbx/issues/43#issuecomment-429625047 Change-Id: Icaee4ba62003e6eacef9f938bdea19426623b5da --- src/osal.h | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/osal.h b/src/osal.h index 5aabc191..414bf19d 100644 --- a/src/osal.h +++ b/src/osal.h @@ -90,19 +90,39 @@ typedef struct { HANDLE event; } mdbx_condmutex_t; typedef CRITICAL_SECTION mdbx_fastmutex_t; + +#ifndef mdbx_malloc static inline void *mdbx_malloc(size_t bytes) { return LocalAlloc(LMEM_FIXED, bytes); } +#endif /* mdbx_malloc */ + +#ifndef mdbx_calloc static inline void *mdbx_calloc(size_t nelem, size_t size) { return LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT, nelem * size); } +#endif /* mdbx_calloc */ + +#ifndef mdbx_realloc static inline void *mdbx_realloc(void *ptr, size_t bytes) { return LocalReAlloc(ptr, bytes, LMEM_MOVEABLE); } +#endif /* mdbx_realloc */ + +#ifndef mdbx_free #define mdbx_free LocalFree -#define snprintf _snprintf /* ntdll */ +#endif /* mdbx_free */ + +#ifndef snprintf +#define snprintf _snprintf /* ntdll */ +#endif + +#ifndef vsnprintf #define vsnprintf _vsnprintf /* ntdll */ -#else +#endif + +#else /*----------------------------------------------------------------------*/ + #include #include #include