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
2f89aa67
Commit
2f89aa67
authored
Aug 02, 2008
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#2538: bytes objects can only provide read-only buffers
parent
07431a30
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
8 deletions
+13
-8
Lib/test/test_bytes.py
Lib/test/test_bytes.py
+5
-0
Lib/test/test_socket.py
Lib/test/test_socket.py
+2
-2
Objects/bytesobject.c
Objects/bytesobject.c
+1
-1
Objects/memoryobject.c
Objects/memoryobject.c
+5
-5
No files found.
Lib/test/test_bytes.py
View file @
2f89aa67
...
...
@@ -453,6 +453,11 @@ class BaseBytesTest(unittest.TestCase):
class
BytesTest
(
BaseBytesTest
):
type2test
=
bytes
def
test_buffer_is_readonly
(
self
):
with
open
(
sys
.
stdin
.
fileno
(),
"rb"
,
buffering
=
0
)
as
f
:
self
.
assertRaises
(
TypeError
,
f
.
readinto
,
b""
)
class
ByteArrayTest
(
BaseBytesTest
):
type2test
=
bytearray
...
...
Lib/test/test_socket.py
View file @
2f89aa67
...
...
@@ -1112,7 +1112,7 @@ class BufferIOTest(SocketConnectedTest):
SocketConnectedTest
.
__init__
(
self
,
methodName
=
methodName
)
def
testRecvInto
(
self
):
buf
=
b
" "
*
1024
buf
=
b
ytearray
(
1024
)
nbytes
=
self
.
cli_conn
.
recv_into
(
buf
)
self
.
assertEqual
(
nbytes
,
len
(
MSG
))
msg
=
buf
[:
len
(
MSG
)]
...
...
@@ -1123,7 +1123,7 @@ class BufferIOTest(SocketConnectedTest):
self
.
serv_conn
.
send
(
buf
)
def
testRecvFromInto
(
self
):
buf
=
b
" "
*
1024
buf
=
b
ytearray
(
1024
)
nbytes
,
addr
=
self
.
cli_conn
.
recvfrom_into
(
buf
)
self
.
assertEqual
(
nbytes
,
len
(
MSG
))
msg
=
buf
[:
len
(
MSG
)]
...
...
Objects/bytesobject.c
View file @
2f89aa67
...
...
@@ -965,7 +965,7 @@ static int
string_buffer_getbuffer
(
PyBytesObject
*
self
,
Py_buffer
*
view
,
int
flags
)
{
return
PyBuffer_FillInfo
(
view
,
(
void
*
)
self
->
ob_sval
,
Py_SIZE
(
self
),
0
,
flags
);
1
,
flags
);
}
static
PySequenceMethods
string_as_sequence
=
{
...
...
Objects/memoryobject.c
View file @
2f89aa67
...
...
@@ -56,7 +56,7 @@ PyMemoryView_FromObject(PyObject *base)
if
(
mview
==
NULL
)
return
NULL
;
mview
->
base
=
NULL
;
if
(
PyObject_GetBuffer
(
base
,
&
(
mview
->
view
),
PyBUF_FULL
)
<
0
)
{
if
(
PyObject_GetBuffer
(
base
,
&
(
mview
->
view
),
PyBUF_FULL
_RO
)
<
0
)
{
Py_DECREF
(
mview
);
return
NULL
;
}
...
...
@@ -204,9 +204,9 @@ _indirect_copy_nd(char *dest, Py_buffer *view, char fort)
a contiguous buffer if it is not. The view will point to
the shadow buffer which can be written to and then
will be copied back into the other buffer when the memory
view is de-allocated. While the shadow buffer is
being used, it will have an exclusive write lock on
the original buffer.
view is de-allocated. While the shadow buffer is
being used, it will have an exclusive write lock on
the original buffer.
*/
PyObject
*
...
...
@@ -528,7 +528,7 @@ memory_subscript(PyMemoryViewObject *self, PyObject *key)
/* Return a new memory-view object */
Py_buffer
newview
;
memset
(
&
newview
,
0
,
sizeof
(
newview
));
/* XXX: This needs to be fixed so it
/* XXX: This needs to be fixed so it
actually returns a sub-view
*/
return
PyMemoryView_FromMemory
(
&
newview
);
...
...
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