summaryrefslogtreecommitdiffstats
path: root/Modules/socketmodule.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-07-22 15:43:59 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-07-22 15:43:59 (GMT)
commit524714eeda70de01046e3b4736516f41d7d11010 (patch)
treece1ee1d3cfad2a646f46d1581a677ba4c4ccde4f /Modules/socketmodule.c
parent0cec877230a9232378eb2c7e21348029bbe83fea (diff)
downloadcpython-524714eeda70de01046e3b4736516f41d7d11010.zip
cpython-524714eeda70de01046e3b4736516f41d7d11010.tar.gz
cpython-524714eeda70de01046e3b4736516f41d7d11010.tar.bz2
socket: use INVALID_SOCKET
* Replace "fd = -1" with "fd = INVALID_SOCKET" * Replace "fd < 0" with "fd == INVALID_SOCKET": SOCKET_T is unsigned on Windows Bug found by Pavel Belikov ("Fragment N1"): http://www.viva64.com/en/b/0414/#ID0ECDAE
Diffstat (limited to 'Modules/socketmodule.c')
-rw-r--r--Modules/socketmodule.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 8e804af..b34981c 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -2568,8 +2568,9 @@ sock_close(PySocketSockObject *s)
* and http://linux.derkeiler.com/Mailing-Lists/Kernel/2005-09/3000.html
* for more details.
*/
- if ((fd = s->sock_fd) != -1) {
- s->sock_fd = -1;
+ fd = s->sock_fd;
+ if (fd != INVALID_SOCKET) {
+ s->sock_fd = INVALID_SOCKET;
Py_BEGIN_ALLOW_THREADS
(void) SOCKETCLOSE(fd);
Py_END_ALLOW_THREADS
@@ -2587,7 +2588,7 @@ static PyObject *
sock_detach(PySocketSockObject *s)
{
SOCKET_T fd = s->sock_fd;
- s->sock_fd = -1;
+ s->sock_fd = INVALID_SOCKET;
return PyLong_FromSocket_t(fd);
}
@@ -4165,7 +4166,7 @@ static PyGetSetDef sock_getsetlist[] = {
static void
sock_dealloc(PySocketSockObject *s)
{
- if (s->sock_fd != -1) {
+ if (s->sock_fd != INVALID_SOCKET) {
PyObject *exc, *val, *tb;
Py_ssize_t old_refcount = Py_REFCNT(s);
++Py_REFCNT(s);
@@ -4221,7 +4222,7 @@ sock_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
new = type->tp_alloc(type, 0);
if (new != NULL) {
- ((PySocketSockObject *)new)->sock_fd = -1;
+ ((PySocketSockObject *)new)->sock_fd = INVALID_SOCKET;
((PySocketSockObject *)new)->sock_timeout = _PyTime_FromSeconds(-1);
((PySocketSockObject *)new)->errorhandler = &set_error;
}