Project

General

Profile

Feature #13881

Use getcontext/setcontext on OS X

Added by naruse (Yui NARUSE) 3 months ago. Updated 3 months ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:82715]

Description

getcontext/setcontext is first appeared on OS X 10.5 but deprecated on 10.6.
It seems because POSIX removed them from recent specs.

IEEE Std 1003.1, 2004 Edition says makecontext's use of function declarators with empty parentheses
is an obsolescent feature.
http://pubs.opengroup.org/onlinepubs/009695399/functions/makecontext.html

Then POSIX.1-2008 removed those functions.

But OS X 10.13 still has them maybe because some essential applications uses them for co-routines.
Therefore we can use them for performance.

diff --git a/configure.in b/configure.in
index 08e109317f..3e75eb3cf2 100644
--- a/configure.in
+++ b/configure.in
@@ -1142,8 +1142,6 @@ AS_CASE(["$target_os"],
                    ac_cv_header_syscall_h=no
                ])
                AS_IF([test $macosx_10_5 = yes], [
-                   ac_cv_func_getcontext=no
-                   ac_cv_func_setcontext=no
                ], [
                    AC_DEFINE(BROKEN_SETREUID, 1)
                    AC_DEFINE(BROKEN_SETREGID, 1)
diff --git a/cont.c b/cont.c
index c86095775c..f94883ef02 100644
--- a/cont.c
+++ b/cont.c
@@ -65,7 +65,15 @@
 #ifndef _WIN32
 #include <unistd.h>
 #include <sys/mman.h>
-#include <ucontext.h>
+# ifdef __APPLE__
+/* avoid deprecated maks on ucontext.h */
+int  getcontext(ucontext_t *);
+void makecontext(ucontext_t *, void (*)(), int, ...);
+int  setcontext(const ucontext_t *);
+int  swapcontext(ucontext_t * __restrict, const ucontext_t * __restrict);
+# else
+#  include <ucontext.h>
+# endif
 #endif
 #define RB_PAGE_SIZE (pagesize)
 #define RB_PAGE_MASK (~(RB_PAGE_SIZE - 1))

History

#1 [ruby-core:82716] Updated by hsbt (Hiroshi SHIBATA) 3 months ago

I found getcontext on High Sierra(10.17) beta.

~ > grep getcontext /usr/include/ucontext.h
int  getcontext(ucontext_t *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_2_0, __IPHONE_2_0) __WATCHOS_PROHIBITED __TVOS_PROHIBITED;

Also available in: Atom PDF