diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-07-26 12:37:57 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-07-26 12:37:57 (GMT) |
commit | 011428e168fcbc75c6e2ee3fbaf511bc64f65501 (patch) | |
tree | 5f5a60bd2b7390d29fdec68e343d3946e9e5c36a /Modules/socketmodule.c | |
parent | af529035abb81f7225c75b3def34fe727ff78f29 (diff) | |
parent | e254e53c833d39e1e479a16d7976a7726c0c1981 (diff) | |
download | cpython-011428e168fcbc75c6e2ee3fbaf511bc64f65501.zip cpython-011428e168fcbc75c6e2ee3fbaf511bc64f65501.tar.gz cpython-011428e168fcbc75c6e2ee3fbaf511bc64f65501.tar.bz2 |
(Merge 3.4) 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.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index f510f0e..bb37dd6 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -3869,8 +3869,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*/ @@ -3880,9 +3885,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); } |