[Python-checkins] cpython (2.7): Issue #25924: Avoid unnecessary serialization of getaddrinfo(3) calls on OS X

ned.deily python-checkins at python.org
Mon Feb 15 00:58:06 EST 2016


https://hg.python.org/cpython/rev/58ebfa7c1361
changeset:   100244:58ebfa7c1361
branch:      2.7
parent:      100241:1ceb431e1876
user:        Ned Deily <nad at python.org>
date:        Mon Feb 15 16:51:24 2016 +1100
summary:
  Issue #25924: Avoid unnecessary serialization of getaddrinfo(3) calls on OS X
versions 10.5 or higher.  Original patch by A. Jesse Jiryu Davis.

files:
  Misc/NEWS              |   3 +++
  Modules/socketmodule.c |  20 ++++++++++++++++++--
  2 files changed, 21 insertions(+), 2 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -112,6 +112,9 @@
 
 - Issue #23914: Fixed SystemError raised by CPickle unpickler on broken data.
 
+- Issue #25924: Avoid unnecessary serialization of getaddrinfo(3) calls on
+  OS X versions 10.5 or higher.  Original patch by A. Jesse Jiryu Davis..
+
 Tests
 -----
 
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -82,6 +82,11 @@
 */
 
 #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
@@ -183,8 +188,19 @@
 #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(__VMS) || !defined(HAVE_GETADDRINFO))

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list