summaryrefslogtreecommitdiffstats
path: root/Modules/socketmodule.c
diff options
context:
space:
mode:
authorNed Deily <nad@python.org>2016-02-15 05:54:08 (GMT)
committerNed Deily <nad@python.org>2016-02-15 05:54:08 (GMT)
commit47299fd39cf466adf9e33f26d91bf04ff6f70085 (patch)
treec46626d223cfd70371e0ffabd07755ebfc2e7b54 /Modules/socketmodule.c
parent203ce927f529a2f72e7c4cca574abd8ef1605b52 (diff)
downloadcpython-47299fd39cf466adf9e33f26d91bf04ff6f70085.zip
cpython-47299fd39cf466adf9e33f26d91bf04ff6f70085.tar.gz
cpython-47299fd39cf466adf9e33f26d91bf04ff6f70085.tar.bz2
Issue #25924: Avoid unnecessary serialization of getaddrinfo(3) calls on OS X
versions 10.5 or higher. Original patch by A. Jesse Jiryu Davis.
Diffstat (limited to 'Modules/socketmodule.c')
-rw-r--r--Modules/socketmodule.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 90aa3af..0b679df 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -84,6 +84,11 @@ Local naming conventions:
*/
#ifdef __APPLE__
+#include <AvailabilityMacros.h>
+/* for getaddrinfo thread safety test on old versions of OS X */
+#ifndef MAC_OS_X_VERSION_10_5
+#define MAC_OS_X_VERSION_10_5 1050
+#endif
/*
* inet_aton is not available on OSX 10.3, yet we want to use a binary
* that was build on 10.4 or later to work on that release, weak linking
@@ -184,8 +189,19 @@ if_indextoname(index) -- return the corresponding interface name\n\
#include <sys/param.h>
#endif
/* On systems on which getaddrinfo() is believed to not be thread-safe,
- (this includes the getaddrinfo emulation) protect access with a lock. */
-#if defined(WITH_THREAD) && (defined(__APPLE__) || \
+ (this includes the getaddrinfo emulation) protect access with a lock.
+
+ getaddrinfo is thread-safe on Mac OS X 10.5 and later. Originally it was
+ a mix of code including an unsafe implementation from an old BSD's
+ libresolv. In 10.5 Apple reimplemented it as a safe IPC call to the
+ mDNSResponder process. 10.5 is the first be UNIX '03 certified, which
+ includes the requirement that getaddrinfo be thread-safe.
+
+ See issue #25924 for details.
+ */
+#if defined(WITH_THREAD) && ( \
+ (defined(__APPLE__) && \
+ MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5) || \
(defined(__FreeBSD__) && __FreeBSD_version+0 < 503000) || \
defined(__OpenBSD__) || defined(__NetBSD__) || \
!defined(HAVE_GETADDRINFO))