]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-132886: use relaxed atomics for `sock_fd` in gil builds in socket module...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 8 May 2025 17:30:40 +0000 (19:30 +0200)
committerGitHub <noreply@github.com>
Thu, 8 May 2025 17:30:40 +0000 (17:30 +0000)
gh-132886: use relaxed atomics for `sock_fd` in gil builds in socket module (GH-133208)
(cherry picked from commit 2d82ab761ab8051440e486ca68355514f3df42aa)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Modules/socketmodule.c

index 77bc431480823559f7d9f84cf40a7a2581d90cc5..92c9aa8b510dca34095b01063fbc017546a810ea 100644 (file)
@@ -111,7 +111,6 @@ Local naming conventions:
 #include "pycore_moduleobject.h"  // _PyModule_GetState
 #include "pycore_time.h"          // _PyTime_AsMilliseconds()
 #include "pycore_pystate.h"       // _Py_AssertHoldsTstate()
-#include "pycore_pyatomic_ft_wrappers.h"
 
 #ifdef _Py_MEMORY_SANITIZER
 #  include <sanitizer/msan_interface.h>
@@ -565,7 +564,6 @@ static int sock_cloexec_works = -1;
 static inline void
 set_sock_fd(PySocketSockObject *s, SOCKET_T fd)
 {
-#ifdef Py_GIL_DISABLED
 #if SIZEOF_SOCKET_T == SIZEOF_INT
     _Py_atomic_store_int_relaxed((int *)&s->sock_fd, (int)fd);
 #elif SIZEOF_SOCKET_T == SIZEOF_LONG
@@ -575,15 +573,11 @@ set_sock_fd(PySocketSockObject *s, SOCKET_T fd)
 #else
     #error "Unsupported SIZEOF_SOCKET_T"
 #endif
-#else
-    s->sock_fd = fd;
-#endif
 }
 
 static inline SOCKET_T
 get_sock_fd(PySocketSockObject *s)
 {
-#ifdef Py_GIL_DISABLED
 #if SIZEOF_SOCKET_T == SIZEOF_INT
     return (SOCKET_T)_Py_atomic_load_int_relaxed((int *)&s->sock_fd);
 #elif SIZEOF_SOCKET_T == SIZEOF_LONG
@@ -593,9 +587,6 @@ get_sock_fd(PySocketSockObject *s)
 #else
     #error "Unsupported SIZEOF_SOCKET_T"
 #endif
-#else
-    return s->sock_fd;
-#endif
 }
 
 #define _PySocketSockObject_CAST(op)    ((PySocketSockObject *)(op))