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
6282e656
Commit
6282e656
authored
Mar 02, 2016
by
Berker Peksag
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #26335: Make mmap.write() return the number of bytes written like
other write methods. Patch by Jakub Stasiak.
parent
d2dc15b2
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
4 deletions
+21
-4
Doc/library/mmap.rst
Doc/library/mmap.rst
+7
-2
Lib/test/test_mmap.py
Lib/test/test_mmap.py
+8
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/mmapmodule.c
Modules/mmapmodule.c
+3
-2
No files found.
Doc/library/mmap.rst
View file @
6282e656
...
...
@@ -263,13 +263,18 @@ To map anonymous memory, -1 should be passed as the fileno along with the length
.. method:: write(bytes)
Write the bytes in *bytes* into memory at the current position of the
file pointer; the file position is updated to point after the bytes that
file pointer and return the number of bytes written (never less than
``len(bytes)``, since if the write fails, a :exc:`ValueError` will be
raised). The file position is updated to point after the bytes that
were written. If the mmap was created with :const:`ACCESS_READ`, then
writing to it will raise a :exc:`TypeError` exception.
.. versionchanged:: 3.5
Writable :term:`bytes-like object` is now accepted.
.. versionchanged:: 3.6
The number of bytes written is now returned.
.. method:: write_byte(byte)
...
...
Lib/test/test_mmap.py
View file @
6282e656
...
...
@@ -713,6 +713,14 @@ class MmapTests(unittest.TestCase):
gc_collect
()
self
.
assertIs
(
wr
(),
None
)
def
test_write_returning_the_number_of_bytes_written
(
self
):
mm
=
mmap
.
mmap
(
-
1
,
16
)
self
.
assertEqual
(
mm
.
write
(
b""
),
0
)
self
.
assertEqual
(
mm
.
write
(
b"x"
),
1
)
self
.
assertEqual
(
mm
.
write
(
b"yz"
),
2
)
self
.
assertEqual
(
mm
.
write
(
b"python"
),
6
)
class
LargeMmapTests
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
Misc/NEWS
View file @
6282e656
...
...
@@ -198,6 +198,9 @@ Core and Builtins
Library
-------
-
Issue
#
26335
:
Make
mmap
.
write
()
return
the
number
of
bytes
written
like
other
write
methods
.
Patch
by
Jakub
Stasiak
.
-
Issue
#
26457
:
Fixed
the
subnets
()
methods
in
IP
network
classes
for
the
case
when
resulting
prefix
length
is
equal
to
maximal
prefix
length
.
Based
on
patch
by
Xiang
Zhang
.
...
...
Modules/mmapmodule.c
View file @
6282e656
...
...
@@ -389,6 +389,7 @@ mmap_write_method(mmap_object *self,
PyObject
*
args
)
{
Py_buffer
data
;
PyObject
*
result
;
CHECK_VALID
(
NULL
);
if
(
!
PyArg_ParseTuple
(
args
,
"y*:write"
,
&
data
))
...
...
@@ -406,9 +407,9 @@ mmap_write_method(mmap_object *self,
}
memcpy
(
self
->
data
+
self
->
pos
,
data
.
buf
,
data
.
len
);
self
->
pos
=
self
->
pos
+
data
.
len
;
result
=
PyLong_FromSsize_t
(
data
.
len
);
PyBuffer_Release
(
&
data
);
Py_INCREF
(
Py_None
);
return
Py_None
;
return
result
;
}
static
PyObject
*
...
...
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