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
7fe60c0a
Commit
7fe60c0a
authored
Mar 03, 2005
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Patches #749830, #1144555: allow UNIX mmap size to default to current
file size.
parent
df37c8c1
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
7 deletions
+53
-7
Doc/lib/libmmap.tex
Doc/lib/libmmap.tex
+4
-2
Lib/test/output/test_mmap
Lib/test/output/test_mmap
+2
-0
Lib/test/test_mmap.py
Lib/test/test_mmap.py
+36
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/mmapmodule.c
Modules/mmapmodule.c
+8
-5
No files found.
Doc/lib/libmmap.tex
View file @
7fe60c0a
...
...
@@ -62,8 +62,10 @@ the underlying file.
prot
\optional
{
, access
}}}}
\strong
{
(
\UNIX
{}
version)
}
Maps
\var
{
length
}
bytes from the file
specified by the file descriptor
\var
{
fileno
}
, and returns a mmap
object.
object. If
\var
{
length
}
is
\code
{
0
}
, the maximum length of the map
will be the current size of the file when
\function
{
mmap(
}
is
called.
\var
{
flags
}
specifies the nature of the mapping.
\constant
{
MAP
_
PRIVATE
}
creates a private copy-on-write mapping, so
changes to the contents of the mmap object will be private to this
...
...
Lib/test/output/test_mmap
View file @
7fe60c0a
...
...
@@ -31,4 +31,6 @@ test_mmap
Modifying copy-on-write memory map.
Ensuring copy-on-write maps cannot be resized.
Ensuring invalid access parameter raises exception.
Ensuring that passing 0 as map length sets map size to current file size.
Ensuring that passing 0 as map length sets map size to current file size.
Test passed
Lib/test/test_mmap.py
View file @
7fe60c0a
...
...
@@ -311,7 +311,43 @@ def test_both():
finally
:
os
.
unlink
(
TESTFN
)
# test mapping of entire file by passing 0 for map length
if
hasattr
(
os
,
"stat"
):
print
" Ensuring that passing 0 as map length sets map size to current file size."
f
=
open
(
TESTFN
,
"w+"
)
try
:
f
.
write
(
2
**
16
*
'm'
)
# Arbitrary character
f
.
close
()
f
=
open
(
TESTFN
,
"rb+"
)
mf
=
mmap
.
mmap
(
f
.
fileno
(),
0
)
verify
(
len
(
mf
)
==
2
**
16
,
"Map size should equal file size."
)
vereq
(
mf
.
read
(
2
**
16
),
2
**
16
*
"m"
)
mf
.
close
()
f
.
close
()
finally
:
os
.
unlink
(
TESTFN
)
# test mapping of entire file by passing 0 for map length
if
hasattr
(
os
,
"stat"
):
print
" Ensuring that passing 0 as map length sets map size to current file size."
f
=
open
(
TESTFN
,
"w+"
)
try
:
f
.
write
(
2
**
16
*
'm'
)
# Arbitrary character
f
.
close
()
f
=
open
(
TESTFN
,
"rb+"
)
mf
=
mmap
.
mmap
(
f
.
fileno
(),
0
)
verify
(
len
(
mf
)
==
2
**
16
,
"Map size should equal file size."
)
vereq
(
mf
.
read
(
2
**
16
),
2
**
16
*
"m"
)
mf
.
close
()
f
.
close
()
finally
:
os
.
unlink
(
TESTFN
)
print
' Test passed'
test_both
()
Misc/NEWS
View file @
7fe60c0a
...
...
@@ -36,6 +36,9 @@ Core and builtins
Extension Modules
-----------------
- Patches #749830, #1144555: allow UNIX mmap size to default to current
file size.
- Added functional.partial(). See PEP309.
- Patch #1093585: raise a ValueError for negative history items in readline.
...
...
Modules/mmapmodule.c
View file @
7fe60c0a
...
...
@@ -896,11 +896,14 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
/* on OpenVMS we must ensure that all bytes are written to the file */
fsync
(
fd
);
# endif
if
(
fstat
(
fd
,
&
st
)
==
0
&&
S_ISREG
(
st
.
st_mode
)
&&
(
size_t
)
map_size
>
st
.
st_size
)
{
PyErr_SetString
(
PyExc_ValueError
,
"mmap length is greater than file size"
);
return
NULL
;
if
(
fstat
(
fd
,
&
st
)
==
0
&&
S_ISREG
(
st
.
st_mode
))
{
if
(
map_size
==
0
)
{
map_size
=
(
int
)
st
.
st_size
;
}
else
if
((
size_t
)
map_size
>
st
.
st_size
)
{
PyErr_SetString
(
PyExc_ValueError
,
"mmap length is greater than file size"
);
return
NULL
;
}
}
#endif
m_obj
=
PyObject_New
(
mmap_object
,
&
mmap_object_type
);
...
...
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