Skip to content

Commit 5952a1f

Browse files
committed
Check running macOS version at runtime
1 parent c8b414b commit 5952a1f

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

dln.c

+27-8
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
#define dln_memerror rb_memerror
1616
#define dln_exit rb_exit
1717
#define dln_loaderror rb_loaderror
18+
#define dln_fatalerror rb_fatal
1819
#else
1920
#define dln_notimplement --->>> dln not implemented <<<---
2021
#define dln_memerror abort
2122
#define dln_exit exit
2223
static void dln_loaderror(const char *format, ...);
24+
#define dln_fatalerror dln_loaderror
2325
#endif
2426
#include "dln.h"
2527
#include "internal.h"
@@ -281,6 +283,24 @@ dln_incompatible_library_p(void *handle)
281283
COMPILER_WARNING_POP
282284
#endif
283285

286+
#if defined(MAC_OS_X_VERSION_MIN_REQUIRED) && \
287+
(MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_11)
288+
# include <sys/sysctl.h>
289+
290+
static bool
291+
dln_disable_dlclose(void)
292+
{
293+
int mib[] = {CTL_KERN, KERN_OSREV};
294+
int32_t rev;
295+
size_t size = sizeof(rev);
296+
if (sysctl(mib, numberof(mib), &rev, &size, NULL, 0)) return true;
297+
if (rev < MAC_OS_X_VERSION_10_11) return true;
298+
return false;
299+
}
300+
#else
301+
# define dln_disable_dlclose() false
302+
#endif
303+
284304
#if defined(_WIN32) || defined(USE_DLN_DLOPEN)
285305
static void *
286306
dln_open(const char *file)
@@ -335,20 +355,19 @@ dln_open(const char *file)
335355
}
336356

337357
# if defined(RUBY_EXPORT)
338-
{
339-
if (dln_incompatible_library_p(handle)) {
340-
# if defined(__APPLE__) && \
341-
defined(MAC_OS_X_VERSION_MIN_REQUIRED) && \
342-
(MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_11)
358+
{
359+
if (dln_incompatible_library_p(handle)) {
360+
if (dln_disable_dlclose()) {
343361
/* dlclose() segfaults */
344-
rb_fatal("%s - %s", incompatible, file);
345-
# else
362+
dln_fatalerror("%s - %s", incompatible, file);
363+
}
364+
else {
346365
dlclose(handle);
347366
error = incompatible;
348367
goto failed;
349-
# endif
350368
}
351369
}
370+
}
352371
# endif
353372
#endif
354373

0 commit comments

Comments
 (0)