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
24e561ae
Commit
24e561ae
authored
Sep 03, 2010
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #3805: clean up implementation of the _read method in _ssl.c.
parent
aa44b2b5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
32 deletions
+33
-32
Lib/ssl.py
Lib/ssl.py
+3
-3
Modules/_ssl.c
Modules/_ssl.c
+30
-29
No files found.
Lib/ssl.py
View file @
24e561ae
...
@@ -199,14 +199,14 @@ class SSLSocket(socket):
...
@@ -199,14 +199,14 @@ class SSLSocket(socket):
self
.
_checkClosed
()
self
.
_checkClosed
()
try
:
try
:
if
buffer
:
if
buffer
is
not
None
:
v
=
self
.
_sslobj
.
read
(
buffer
,
len
)
v
=
self
.
_sslobj
.
read
(
len
,
buffer
)
else
:
else
:
v
=
self
.
_sslobj
.
read
(
len
or
1024
)
v
=
self
.
_sslobj
.
read
(
len
or
1024
)
return
v
return
v
except
SSLError
as
x
:
except
SSLError
as
x
:
if
x
.
args
[
0
]
==
SSL_ERROR_EOF
and
self
.
suppress_ragged_eofs
:
if
x
.
args
[
0
]
==
SSL_ERROR_EOF
and
self
.
suppress_ragged_eofs
:
if
buffer
:
if
buffer
is
not
None
:
return
0
return
0
else
:
else
:
return
b''
return
b''
...
...
Modules/_ssl.c
View file @
24e561ae
...
@@ -1156,11 +1156,9 @@ static PyObject *PySSL_SSLread(PySSLSocket *self, PyObject *args)
...
@@ -1156,11 +1156,9 @@ static PyObject *PySSL_SSLread(PySSLSocket *self, PyObject *args)
{
{
PyObject
*
dest
=
NULL
;
PyObject
*
dest
=
NULL
;
Py_buffer
buf
;
Py_buffer
buf
;
int
buf_passed
=
0
;
int
count
=
-
1
;
char
*
mem
;
char
*
mem
;
/* XXX this should use Py_ssize_t */
int
len
,
count
;
int
len
=
1024
;
int
buf_passed
=
0
;
int
sockstate
;
int
sockstate
;
int
err
;
int
err
;
int
nonblocking
;
int
nonblocking
;
...
@@ -1174,26 +1172,28 @@ static PyObject *PySSL_SSLread(PySSLSocket *self, PyObject *args)
...
@@ -1174,26 +1172,28 @@ static PyObject *PySSL_SSLread(PySSLSocket *self, PyObject *args)
}
}
Py_INCREF
(
sock
);
Py_INCREF
(
sock
);
if
(
!
PyArg_ParseTuple
(
args
,
"|Oi:read"
,
&
dest
,
&
count
))
buf
.
obj
=
NULL
;
buf
.
buf
=
NULL
;
if
(
!
PyArg_ParseTuple
(
args
,
"i|w*:read"
,
&
len
,
&
buf
))
goto
error
;
goto
error
;
if
((
dest
==
NULL
)
||
(
dest
==
Py_None
))
{
if
((
buf
.
buf
==
NULL
)
&&
(
buf
.
obj
==
NULL
))
{
if
(
!
(
dest
=
PyByteArray_FromStringAndSize
((
char
*
)
0
,
len
)))
dest
=
PyBytes_FromStringAndSize
(
NULL
,
len
);
goto
error
;
if
(
dest
==
NULL
)
mem
=
PyByteArray_AS_STRING
(
dest
);
}
else
if
(
PyLong_Check
(
dest
))
{
len
=
PyLong_AS_LONG
(
dest
);
if
(
!
(
dest
=
PyByteArray_FromStringAndSize
((
char
*
)
0
,
len
)))
goto
error
;
goto
error
;
mem
=
PyByteArray_AS_STRING
(
dest
);
mem
=
PyBytes_AS_STRING
(
dest
);
}
else
{
}
if
(
PyObject_GetBuffer
(
dest
,
&
buf
,
PyBUF_CONTIG
)
<
0
)
else
{
goto
error
;
mem
=
buf
.
buf
;
len
=
buf
.
len
;
if
((
count
>
0
)
&&
(
count
<=
len
))
len
=
count
;
buf_passed
=
1
;
buf_passed
=
1
;
mem
=
buf
.
buf
;
if
(
len
<=
0
||
len
>
buf
.
len
)
{
len
=
(
int
)
buf
.
len
;
if
(
buf
.
len
!=
len
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"maximum length can't fit in a C 'int'"
);
goto
error
;
}
}
}
}
/* just in case the blocking state of the socket has been changed */
/* just in case the blocking state of the socket has been changed */
...
@@ -1254,23 +1254,24 @@ static PyObject *PySSL_SSLread(PySSLSocket *self, PyObject *args)
...
@@ -1254,23 +1254,24 @@ static PyObject *PySSL_SSLread(PySSLSocket *self, PyObject *args)
PySSL_SetError
(
self
,
count
,
__FILE__
,
__LINE__
);
PySSL_SetError
(
self
,
count
,
__FILE__
,
__LINE__
);
goto
error
;
goto
error
;
}
}
done:
done:
Py_DECREF
(
sock
);
Py_DECREF
(
sock
);
if
(
!
buf_passed
)
{
if
(
!
buf_passed
)
{
PyObject
*
res
=
PyBytes_FromStringAndSize
(
mem
,
count
);
_PyBytes_Resize
(
&
dest
,
count
);
Py_DECREF
(
dest
)
;
return
dest
;
return
res
;
}
}
else
{
else
{
PyBuffer_Release
(
&
buf
);
PyBuffer_Release
(
&
buf
);
return
PyLong_FromLong
(
count
);
return
PyLong_FromLong
(
count
);
}
}
error:
error:
Py_DECREF
(
sock
);
Py_DECREF
(
sock
);
if
(
!
buf_passed
)
{
if
(
!
buf_passed
)
Py_XDECREF
(
dest
);
Py_XDECREF
(
dest
);
}
else
{
else
PyBuffer_Release
(
&
buf
);
PyBuffer_Release
(
&
buf
);
}
return
NULL
;
return
NULL
;
}
}
...
...
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