Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
0a649c7b
Commit
0a649c7b
authored
Jul 26, 2014
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix repr(_socket.socket) on Windows 64-bit: don't fail with OverflowError
on closed socket.
parent
465db3c6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
2 deletions
+30
-2
Lib/test/test_socket.py
Lib/test/test_socket.py
+18
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/socketmodule.c
Modules/socketmodule.c
+9
-2
No files found.
Lib/test/test_socket.py
View file @
0a649c7b
...
...
@@ -15,6 +15,11 @@ import contextlib
from
weakref
import
proxy
import
signal
import
math
try
:
import
_socket
except
ImportError
:
_socket
=
None
def
try_address
(
host
,
port
=
0
,
family
=
socket
.
AF_INET
):
"""Try to bind a socket on the given host:port and return True
...
...
@@ -244,6 +249,19 @@ class SocketPairTest(unittest.TestCase, ThreadableTest):
class
GeneralModuleTests
(
unittest
.
TestCase
):
@
unittest
.
skipUnless
(
_socket
is
not
None
,
'need _socket module'
)
def
test_csocket_repr
(
self
):
s
=
_socket
.
socket
(
_socket
.
AF_INET
,
_socket
.
SOCK_STREAM
)
try
:
expected
=
(
'<socket object, fd=%s, family=%s, type=%s, protocol=%s>'
%
(
s
.
fileno
(),
s
.
family
,
s
.
type
,
s
.
proto
))
self
.
assertEqual
(
repr
(
s
),
expected
)
finally
:
s
.
close
()
expected
=
(
'<socket object, fd=-1, family=%s, type=%s, protocol=%s>'
%
(
s
.
family
,
s
.
type
,
s
.
proto
))
self
.
assertEqual
(
repr
(
s
),
expected
)
def
test_weakref
(
self
):
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
p
=
proxy
(
s
)
...
...
Misc/NEWS
View file @
0a649c7b
...
...
@@ -13,6 +13,9 @@ Core and Builtins
Library
-------
- Fix repr(_socket.socket) on Windows 64-bit: don'
t
fail
with
OverflowError
on
closed
socket
.
-
Issue
#
16133
:
The
asynchat
.
async_chat
.
handle_read
()
method
now
ignores
socket
.
error
()
exceptions
with
blocking
I
/
O
errors
:
EAGAIN
,
EALREADY
,
EINPROGRESS
,
or
EWOULDBLOCK
.
...
...
Modules/socketmodule.c
View file @
0a649c7b
...
...
@@ -3123,8 +3123,13 @@ static PyObject *
sock_repr
(
PySocketSockObject
*
s
)
{
char
buf
[
512
];
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*/
...
...
@@ -3134,10 +3139,12 @@ sock_repr(PySocketSockObject *s)
return
NULL
;
}
#endif
else
sock_fd
=
(
long
)
s
->
sock_fd
;
PyOS_snprintf
(
buf
,
sizeof
(
buf
),
"<socket object, fd=%ld, family=%d, type=%d, protocol=%d>"
,
(
long
)
s
->
sock_fd
,
s
->
sock_family
,
sock_fd
,
s
->
sock_family
,
s
->
sock_type
,
s
->
sock_proto
);
return
PyString_FromString
(
buf
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment