Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 47299fd

Browse files
committed
Issue #25924: Avoid unnecessary serialization of getaddrinfo(3) calls on OS X
versions 10.5 or higher. Original patch by A. Jesse Jiryu Davis.
1 parent 203ce92 commit 47299fd

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ Library
212212
- Issue #26050: Add asyncio.StreamReader.readuntil() method.
213213
Patch by Марк Коренберг.
214214

215+
- Issue #25924: Avoid unnecessary serialization of getaddrinfo(3) calls on
216+
OS X versions 10.5 or higher. Original patch by A. Jesse Jiryu Davis.
217+
215218
Documentation
216219
-------------
217220

Modules/socketmodule.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ Local naming conventions:
8484
*/
8585

8686
#ifdef __APPLE__
87+
#include <AvailabilityMacros.h>
88+
/* for getaddrinfo thread safety test on old versions of OS X */
89+
#ifndef MAC_OS_X_VERSION_10_5
90+
#define MAC_OS_X_VERSION_10_5 1050
91+
#endif
8792
/*
8893
* inet_aton is not available on OSX 10.3, yet we want to use a binary
8994
* 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\
184189
#include <sys/param.h>
185190
#endif
186191
/* On systems on which getaddrinfo() is believed to not be thread-safe,
187-
(this includes the getaddrinfo emulation) protect access with a lock. */
188-
#if defined(WITH_THREAD) && (defined(__APPLE__) || \
192+
(this includes the getaddrinfo emulation) protect access with a lock.
193+
194+
getaddrinfo is thread-safe on Mac OS X 10.5 and later. Originally it was
195+
a mix of code including an unsafe implementation from an old BSD's
196+
libresolv. In 10.5 Apple reimplemented it as a safe IPC call to the
197+
mDNSResponder process. 10.5 is the first be UNIX '03 certified, which
198+
includes the requirement that getaddrinfo be thread-safe.
199+
200+
See issue #25924 for details.
201+
*/
202+
#if defined(WITH_THREAD) && ( \
203+
(defined(__APPLE__) && \
204+
MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5) || \
189205
(defined(__FreeBSD__) && __FreeBSD_version+0 < 503000) || \
190206
defined(__OpenBSD__) || defined(__NetBSD__) || \
191207
!defined(HAVE_GETADDRINFO))

0 commit comments

Comments
 (0)