diff options
author | AN Long <aisk@users.noreply.github.com> | 2024-07-01 14:38:30 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-01 14:38:30 (GMT) |
commit | 8a5176772c932d764daa83c50b99fe0805260b2c (patch) | |
tree | ba7c2a57d6cd546c9f571192649c70c75a21b4f6 /Modules/socketmodule.c | |
parent | c7991cc28788bbb086fd85d8fc55e20742f0de88 (diff) | |
download | cpython-8a5176772c932d764daa83c50b99fe0805260b2c.zip cpython-8a5176772c932d764daa83c50b99fe0805260b2c.tar.gz cpython-8a5176772c932d764daa83c50b99fe0805260b2c.tar.bz2 |
gh-117657: Use critical section to make _socket.socket.close thread safe (GH-120490)
Diffstat (limited to 'Modules/socketmodule.c')
-rw-r--r-- | Modules/socketmodule.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 6d16147..3ffdaa4 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -3331,8 +3331,19 @@ sockets the address is a tuple (ifname, proto [,pkttype [,hatype [,addr]]])"); Set the file descriptor to -1 so operations tried subsequently will surely fail. */ +/*[clinic input] +@critical_section +_socket.socket.close + self as s: self(type="PySocketSockObject *") + +close() + +Close the socket. It cannot be used after this call. +[clinic start generated code]*/ + static PyObject * -sock_close(PySocketSockObject *s, PyObject *Py_UNUSED(ignored)) +_socket_socket_close_impl(PySocketSockObject *s) +/*[clinic end generated code: output=038b2418e07f6f6c input=9839a261e05bcb97]*/ { SOCKET_T fd; int res; @@ -3357,11 +3368,6 @@ sock_close(PySocketSockObject *s, PyObject *Py_UNUSED(ignored)) Py_RETURN_NONE; } -PyDoc_STRVAR(sock_close_doc, -"close()\n\ -\n\ -Close the socket. It cannot be used after this call."); - static PyObject * sock_detach(PySocketSockObject *s, PyObject *Py_UNUSED(ignored)) { @@ -5118,8 +5124,7 @@ static PyMethodDef sock_methods[] = { {"bind", (PyCFunction)sock_bind, METH_O, bind_doc}, #endif - {"close", (PyCFunction)sock_close, METH_NOARGS, - sock_close_doc}, + _SOCKET_SOCKET_CLOSE_METHODDEF #ifdef HAVE_CONNECT {"connect", (PyCFunction)sock_connect, METH_O, connect_doc}, |