From c082eb7d8a6b089feb49ed734203223ade08f4d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Sat, 11 Jun 2022 17:39:36 +0300 Subject: [PATCH] mdbx: use `_tlv_atexit()` on Darwin/MacOSX. --- src/base.h | 3 +++ src/core.c | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/base.h b/src/base.h index 4482b71a..09f3133d 100644 --- a/src/base.h +++ b/src/base.h @@ -158,6 +158,9 @@ #endif #ifdef __APPLE__ +#ifndef MAC_OS_X_VERSION_MIN_REQUIRED +#define MAC_OS_X_VERSION_MIN_REQUIRED 1070 /* Mac OS X 10.7, 2011 */ +#endif #include #endif /* Apple OSX & iOS */ diff --git a/src/core.c b/src/core.c index f3db7435..6b4becfa 100644 --- a/src/core.c +++ b/src/core.c @@ -1259,6 +1259,23 @@ static __inline int rthc_atexit(void (*dtor)(void *), void *obj, void *dso_symbol) { int rc = MDBX_ENOSYS; +#if defined(__APPLE__) || defined(_DARWIN_C_SOURCE) +#if !defined(MAC_OS_X_VERSION_MIN_REQUIRED) || !defined(MAC_OS_X_VERSION_10_7) +#error \ + "The should be included and MAC_OS_X_VERSION_MIN_REQUIRED must be defined" +#elif MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7 + extern void _tlv_atexit(void (*termfunc)(void *objAddr), void *objAddr) + __attribute__((__weak__, __weak_import__)); + if (rc && &_tlv_atexit) { + (void)dso_symbol; + _tlv_atexit(dtor, obj); + rc = 0; + } +#elif !defined(MDBX_HAVE_CXA_THREAD_ATEXIT) +#define MDBX_HAVE_CXA_THREAD_ATEXIT 1 +#endif /* MAC_OS_X_VERSION_MIN_REQUIRED */ +#endif /* Apple */ + #if defined(MDBX_HAVE_CXA_THREAD_ATEXIT) && MDBX_HAVE_CXA_THREAD_ATEXIT extern int __cxa_thread_atexit(void (*dtor)(void *), void *obj, void *dso_symbol)