mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Fix repr(_socket.socket) on Windows 64-bit: don't fail with OverflowError
on closed socket. repr(socket.socket) already works fine.
This commit is contained in:
parent
51e44ea66a
commit
e254e53c83
3 changed files with 30 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue