https://github.com/python/cpython/commit/4f3be1b5777313fb36ff4bda7e4a4197c932c30e
commit: 4f3be1b5777313fb36ff4bda7e4a4197c932c30e
branch: main
author: Thomas Kowalski <[email protected]>
committer: kumaraditya303 <[email protected]>
date: 2026-07-15T10:39:28Z
summary:
gh-150452: use PyMutex in socket module (#150453)
files:
M Modules/socketmodule.c
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index ada4fda6571049..084c2dbcff066e 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -1170,7 +1170,7 @@ new_sockobject(socket_state *state, SOCKET_T fd, int
family, int type,
/* Lock to allow python interpreter to continue, but only allow one
thread to be in gethostbyname or getaddrinfo */
#if defined(USE_GETHOSTBYNAME_LOCK)
-static PyThread_type_lock netdb_lock;
+static PyMutex netdb_lock = {0};
#endif
@@ -6219,7 +6219,7 @@ socket_gethostbyname_ex(PyObject *self, PyObject *args)
#endif
#else /* not HAVE_GETHOSTBYNAME_R */
#ifdef USE_GETHOSTBYNAME_LOCK
- PyThread_acquire_lock(netdb_lock, 1);
+ PyMutex_Lock(&netdb_lock);
#endif
_Py_COMP_DIAG_PUSH
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
@@ -6235,7 +6235,7 @@ socket_gethostbyname_ex(PyObject *self, PyObject *args)
ret = gethost_common(state, h, SAS2SA(&addr), sizeof(addr),
sa->sa_family);
#ifdef USE_GETHOSTBYNAME_LOCK
- PyThread_release_lock(netdb_lock);
+ PyMutex_Unlock(&netdb_lock);
#endif
finally:
PyMem_Free(name);
@@ -6326,7 +6326,7 @@ socket_gethostbyaddr(PyObject *self, PyObject *args)
#endif
#else /* not HAVE_GETHOSTBYNAME_R */
#ifdef USE_GETHOSTBYNAME_LOCK
- PyThread_acquire_lock(netdb_lock, 1);
+ PyMutex_Lock(&netdb_lock);
#endif
_Py_COMP_DIAG_PUSH
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
@@ -6336,7 +6336,7 @@ socket_gethostbyaddr(PyObject *self, PyObject *args)
Py_END_ALLOW_THREADS
ret = gethost_common(state, h, SAS2SA(&addr), sizeof(addr), af);
#ifdef USE_GETHOSTBYNAME_LOCK
- PyThread_release_lock(netdb_lock);
+ PyMutex_Unlock(&netdb_lock);
#endif
finally:
PyMem_Free(ip_num);
@@ -9292,15 +9292,6 @@ socket_exec(PyObject *m)
#endif
#endif /* _MSTCPIP_ */
- /* Initialize gethostbyname lock */
-#if defined(USE_GETHOSTBYNAME_LOCK)
- netdb_lock = PyThread_allocate_lock();
- if (netdb_lock == NULL) {
- PyErr_NoMemory();
- goto error;
- }
-#endif
-
#ifdef MS_WINDOWS
/* remove some flags on older version Windows during run-time */
if (remove_unusable_flags(m) < 0) {
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]