[前][次][番号順一覧][スレッド一覧]

ruby-changes:71199

From: Nobuyoshi <ko1@a...>
Date: Thu, 17 Feb 2022 20:30:19 +0900 (JST)
Subject: [ruby-changes:71199] 5952a1f201 (master): Check running macOS version at runtime

https://git.ruby-lang.org/ruby.git/commit/?id=5952a1f201

From 5952a1f201cfed38277b4fafa0624c1a048edb6d Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Thu, 17 Feb 2022 17:35:38 +0900
Subject: Check running macOS version at runtime

---
 dln.c | 35 +++++++++++++++++++++++++++--------
 1 file changed, 27 insertions(+), 8 deletions(-)

diff --git a/dln.c b/dln.c
index 48bebb824b..5c1e6f8c02 100644
--- a/dln.c
+++ b/dln.c
@@ -15,11 +15,13 @@ https://github.com/ruby/ruby/blob/trunk/dln.c#L15
 #define dln_memerror rb_memerror
 #define dln_exit rb_exit
 #define dln_loaderror rb_loaderror
+#define dln_fatalerror rb_fatal
 #else
 #define dln_notimplement --->>> dln not implemented <<<---
 #define dln_memerror abort
 #define dln_exit exit
 static void dln_loaderror(const char *format, ...);
+#define dln_fatalerror dln_loaderror
 #endif
 #include "dln.h"
 #include "internal.h"
@@ -281,6 +283,24 @@ dln_incompatible_library_p(void *handle) https://github.com/ruby/ruby/blob/trunk/dln.c#L283
 COMPILER_WARNING_POP
 #endif
 
+#if defined(MAC_OS_X_VERSION_MIN_REQUIRED) && \
+    (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_11)
+# include <sys/sysctl.h>
+
+static bool
+dln_disable_dlclose(void)
+{
+    int mib[] = {CTL_KERN, KERN_OSREV};
+    int32_t rev;
+    size_t size = sizeof(rev);
+    if (sysctl(mib, numberof(mib), &rev, &size, NULL, 0)) return true;
+    if (rev < MAC_OS_X_VERSION_10_11) return true;
+    return false;
+}
+#else
+# define dln_disable_dlclose() false
+#endif
+
 #if defined(_WIN32) || defined(USE_DLN_DLOPEN)
 static void *
 dln_open(const char *file)
@@ -335,20 +355,19 @@ dln_open(const char *file) https://github.com/ruby/ruby/blob/trunk/dln.c#L355
     }
 
 # if defined(RUBY_EXPORT)
-	{
-	    if (dln_incompatible_library_p(handle)) {
-#  if defined(__APPLE__) && \
-    defined(MAC_OS_X_VERSION_MIN_REQUIRED) && \
-    (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_11)
+    {
+	if (dln_incompatible_library_p(handle)) {
+	    if (dln_disable_dlclose()) {
 		/* dlclose() segfaults */
-		rb_fatal("%s - %s", incompatible, file);
-#  else
+		dln_fatalerror("%s - %s", incompatible, file);
+	    }
+	    else {
 		dlclose(handle);
 		error = incompatible;
 		goto failed;
-#  endif
 	    }
 	}
+    }
 # endif
 #endif
 
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]