@@ -197,43 +197,6 @@ if_indextoname(index) -- return the corresponding interface name\n\
197
197
# define USE_GETHOSTBYNAME_LOCK
198
198
#endif
199
199
200
- /* To use __FreeBSD_version, __OpenBSD__, and __NetBSD_Version__ */
201
- #ifdef HAVE_SYS_PARAM_H
202
- #include <sys/param.h>
203
- #endif
204
- /* On systems on which getaddrinfo() is believed to not be thread-safe,
205
- (this includes the getaddrinfo emulation) protect access with a lock.
206
-
207
- getaddrinfo is thread-safe on Mac OS X 10.5 and later. Originally it was
208
- a mix of code including an unsafe implementation from an old BSD's
209
- libresolv. In 10.5 Apple reimplemented it as a safe IPC call to the
210
- mDNSResponder process. 10.5 is the first be UNIX '03 certified, which
211
- includes the requirement that getaddrinfo be thread-safe. See issue #25924.
212
-
213
- It's thread-safe in OpenBSD starting with 5.4, released Nov 2013:
214
- http://www.openbsd.org/plus54.html
215
-
216
- It's thread-safe in NetBSD starting with 4.0, released Dec 2007:
217
-
218
- http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/net/getaddrinfo.c.diff?r1=1.82&r2=1.83
219
- */
220
- #if ((defined(__APPLE__ ) && \
221
- MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 ) || \
222
- (defined(__FreeBSD__ ) && __FreeBSD_version + 0 < 503000 ) || \
223
- (defined(__OpenBSD__ ) && OpenBSD + 0 < 201311 ) || \
224
- (defined(__NetBSD__ ) && __NetBSD_Version__ + 0 < 400000000 ) || \
225
- !defined(HAVE_GETADDRINFO ))
226
- #define USE_GETADDRINFO_LOCK
227
- #endif
228
-
229
- #ifdef USE_GETADDRINFO_LOCK
230
- #define ACQUIRE_GETADDRINFO_LOCK PyThread_acquire_lock(netdb_lock, 1);
231
- #define RELEASE_GETADDRINFO_LOCK PyThread_release_lock(netdb_lock);
232
- #else
233
- #define ACQUIRE_GETADDRINFO_LOCK
234
- #define RELEASE_GETADDRINFO_LOCK
235
- #endif
236
-
237
200
#if defined(__APPLE__ ) || defined(__CYGWIN__ ) || defined(__NetBSD__ )
238
201
# include <sys/ioctl.h>
239
202
#endif
@@ -1061,7 +1024,7 @@ new_sockobject(SOCKET_T fd, int family, int type, int proto)
1061
1024
1062
1025
/* Lock to allow python interpreter to continue, but only allow one
1063
1026
thread to be in gethostbyname or getaddrinfo */
1064
- #if defined(USE_GETHOSTBYNAME_LOCK ) || defined( USE_GETADDRINFO_LOCK )
1027
+ #if defined(USE_GETHOSTBYNAME_LOCK )
1065
1028
static PyThread_type_lock netdb_lock ;
1066
1029
#endif
1067
1030
@@ -1086,14 +1049,12 @@ setipaddr(const char *name, struct sockaddr *addr_ret, size_t addr_ret_size, int
1086
1049
hints .ai_socktype = SOCK_DGRAM ; /*dummy*/
1087
1050
hints .ai_flags = AI_PASSIVE ;
1088
1051
Py_BEGIN_ALLOW_THREADS
1089
- ACQUIRE_GETADDRINFO_LOCK
1090
1052
error = getaddrinfo (NULL , "0" , & hints , & res );
1091
1053
Py_END_ALLOW_THREADS
1092
1054
/* We assume that those thread-unsafe getaddrinfo() versions
1093
1055
*are* safe regarding their return value, ie. that a
1094
1056
subsequent call to getaddrinfo() does not destroy the
1095
1057
outcome of the first call. */
1096
- RELEASE_GETADDRINFO_LOCK
1097
1058
if (error ) {
1098
1059
set_gaierror (error );
1099
1060
return -1 ;
@@ -1194,7 +1155,6 @@ setipaddr(const char *name, struct sockaddr *addr_ret, size_t addr_ret_size, int
1194
1155
memset (& hints , 0 , sizeof (hints ));
1195
1156
hints .ai_family = af ;
1196
1157
Py_BEGIN_ALLOW_THREADS
1197
- ACQUIRE_GETADDRINFO_LOCK
1198
1158
error = getaddrinfo (name , NULL , & hints , & res );
1199
1159
#if defined(__digital__ ) && defined(__unix__ )
1200
1160
if (error == EAI_NONAME && af == AF_UNSPEC ) {
@@ -1205,7 +1165,6 @@ setipaddr(const char *name, struct sockaddr *addr_ret, size_t addr_ret_size, int
1205
1165
}
1206
1166
#endif
1207
1167
Py_END_ALLOW_THREADS
1208
- RELEASE_GETADDRINFO_LOCK /* see comment in setipaddr() */
1209
1168
if (error ) {
1210
1169
set_gaierror (error );
1211
1170
return -1 ;
@@ -6563,10 +6522,8 @@ socket_getaddrinfo(PyObject *self, PyObject *args, PyObject* kwargs)
6563
6522
hints .ai_protocol = protocol ;
6564
6523
hints .ai_flags = flags ;
6565
6524
Py_BEGIN_ALLOW_THREADS
6566
- ACQUIRE_GETADDRINFO_LOCK
6567
6525
error = getaddrinfo (hptr , pptr , & hints , & res0 );
6568
6526
Py_END_ALLOW_THREADS
6569
- RELEASE_GETADDRINFO_LOCK /* see comment in setipaddr() */
6570
6527
if (error ) {
6571
6528
set_gaierror (error );
6572
6529
goto err ;
@@ -6659,10 +6616,8 @@ socket_getnameinfo(PyObject *self, PyObject *args)
6659
6616
hints .ai_socktype = SOCK_DGRAM ; /* make numeric port happy */
6660
6617
hints .ai_flags = AI_NUMERICHOST ; /* don't do any name resolution */
6661
6618
Py_BEGIN_ALLOW_THREADS
6662
- ACQUIRE_GETADDRINFO_LOCK
6663
6619
error = getaddrinfo (hostp , pbuf , & hints , & res );
6664
6620
Py_END_ALLOW_THREADS
6665
- RELEASE_GETADDRINFO_LOCK /* see comment in setipaddr() */
6666
6621
if (error ) {
6667
6622
set_gaierror (error );
6668
6623
goto fail ;
@@ -8422,7 +8377,7 @@ PyInit__socket(void)
8422
8377
#endif /* _MSTCPIP_ */
8423
8378
8424
8379
/* Initialize gethostbyname lock */
8425
- #if defined(USE_GETHOSTBYNAME_LOCK ) || defined( USE_GETADDRINFO_LOCK )
8380
+ #if defined(USE_GETHOSTBYNAME_LOCK )
8426
8381
netdb_lock = PyThread_allocate_lock ();
8427
8382
#endif
8428
8383
0 commit comments