summaryrefslogtreecommitdiff
path: root/Modules/socketmodule.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-07-26 14:36:55 +0200
committerVictor Stinner <victor.stinner@gmail.com>2014-07-26 14:36:55 +0200
commitdf9e4a7d69467e6a42bd64c5346f7f873870d076 (patch)
tree3c75bb9f415e441d319322208771806eee595535 /Modules/socketmodule.c
parent61f8e489f453542e9e486b72db3c36b066a5009d (diff)
downloadcpython-df9e4a7d69467e6a42bd64c5346f7f873870d076.tar.gz
Fix repr(_socket.socket) on Windows 64-bit: don't fail with OverflowError
on closed socket. repr(socket.socket) already works fine.
Diffstat (limited to 'Modules/socketmodule.c')
-rw-r--r--Modules/socketmodule.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 7c08f8faa3..b37e7935ff 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -3868,8 +3868,13 @@ sock_dealloc(PySocketSockObject *s)
static PyObject *
sock_repr(PySocketSockObject *s)
{
+ long sock_fd;
+ /* On Windows, this test is needed because SOCKET_T is unsigned */
+ if (s->sock_fd == INVALID_SOCKET) {
+ sock_fd = -1;
+ }
#if SIZEOF_SOCKET_T > SIZEOF_LONG
- if (s->sock_fd > LONG_MAX) {
+ else if (s->sock_fd > LONG_MAX) {
/* this can occur on Win64, and actually there is a special
ugly printf formatter for decimal pointer length integer
printing, only bother if necessary*/
@@ -3879,9 +3884,11 @@ sock_repr(PySocketSockObject *s)
return NULL;
}
#endif
+ else
+ sock_fd = (long)s->sock_fd;
return PyUnicode_FromFormat(
"<socket object, fd=%ld, family=%d, type=%d, proto=%d>",
- (long)s->sock_fd, s->sock_family,
+ sock_fd, s->sock_family,
s->sock_type,
s->sock_proto);
}