Fix for CONC-521

On macOS, the ucontext functions require _XOPEN_SOURCE to be defined
before including ucontext.h. (Any value is fine, but it's supposed to
be a POSIX-defined number, and 600 seems like the most common choice.)
These functions are required for MYSQL_OPT_NONBLOCK to work on non-x86
platforms, e.g. Apple's M1 chip. This change sets _XOPEN_SOURCE to 600
on Apple platforms during CMake's feature detection and before including
<ucontext.h> in ma_context.h.

Thanks to Evan Miller for reporting this bug and providing the fix.
This commit is contained in:
Georg Richter
2021-01-21 16:56:48 +01:00
parent 4083fd98e5
commit 0b46f1ae42
2 changed files with 6 additions and 0 deletions

View File

@ -49,6 +49,9 @@ CHECK_INCLUDE_FILES (sys/un.h HAVE_SYS_UN_H)
CHECK_INCLUDE_FILES (unistd.h HAVE_UNISTD_H)
CHECK_INCLUDE_FILES (utime.h HAVE_UTIME_H)
IF(APPLE)
SET(CMAKE_REQUIRED_DEFINITIONS -D_XOPEN_SOURCE=600)
ENDIF()
CHECK_INCLUDE_FILES (ucontext.h HAVE_FILE_UCONTEXT_H)
IF(NOT HAVE_FILE_UCONTEXT_H)
CHECK_INCLUDE_FILES (sys/ucontext.h HAVE_FILE_UCONTEXT_H)

View File

@ -52,6 +52,9 @@ struct my_context {
#ifdef MY_CONTEXT_USE_UCONTEXT
#if defined(__APPLE__) && !defined(_XOPEN_SOURCE)
#define _XOPEN_SOURCE 600
#endif
#include <ucontext.h>
struct my_context {