[ python-Bugs-964876 ] mapping a 0 length file

SourceForge.net noreply at sourceforge.net
Sun Jun 6 12:14:10 EDT 2004


Bugs item #964876, was opened at 2004-06-02 05:28
Message generated for change (Comment added) made by tim_one
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=964876&group_id=5470

Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Manlio Perillo (manlioperillo)
Assigned to: A.M. Kuchling (akuchling)
Summary: mapping a 0 length file

Initial Comment:
>>> sys.version
'2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit
(Intel)]'
>>> sys.platform
'win32'
>>> sys.getwindowsversion()
(5, 1, 2600, 2, '')

Hi.
If I mmap a 0 length file on winnt, I obtain an exception:

>>> import mmap, os

>>> file = os.open(file_name, os.O_RDWR | os.O_BINARY)
>>> buf = mmap.mmap(file, 0, access = map.ACCESS_WRITE)

Traceback (most recent call last):
  File "<pyshell#15>", line 1, in -toplevel-
    buf = mmap.mmap(file, 0, access = mmap.ACCESS_WRITE)
WindowsError: [Errno 1006] Il volume corrispondente al
file è stato alterato dall'esterno. Il file aperto non
è più valido


This is a windows problem, but I think it should be at
least documented.



Thanks and regards   Manlio Perillo

----------------------------------------------------------------------

>Comment By: Tim Peters (tim_one)
Date: 2004-06-06 12:14

Message:
Logged In: YES 
user_id=31435

No, on Windows it's not sane.  While the Python mmap 
module has a .resize() method, Microsoft's file mapping API 
does not -- .resize() on Windows is accomplished by throwing 
away the current mapping and creating a brand new one.  On 
non-Windows systems, it's not guaranteed that Python can 
do a .resize() at all (it depends on whether the platform C 
supports mremap() -- if it doesn't, you get a SystemError

    mmap: resizing not available--no mremap()

exception).

So "in theory" ignores too much of reality to take seriously.

----------------------------------------------------------------------

Comment By: Manlio Perillo (manlioperillo)
Date: 2004-06-06 07:15

Message:
Logged In: YES 
user_id=1054957

tim_one wrote that mapping an empty file as a size-0 file
isn't a sane thing to do anyway.

I think this is not really true.
mmap has a resize method, so, in theory, one can map a
size-0 file  
and let it grow.

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2004-06-05 17:46

Message:
Logged In: YES 
user_id=31435

The patch looks good.  On American Windows, the cryptic 
error msg is:

"WindowsError: [Errno 1006] The volume for a file has been 
externally altered so that the opened file is no longer valid"

Can't find any MS docs on this condition.  Then again, 
mapping an empty file *as* a size-0 file isn't a sane thing to 
do anyway.

----------------------------------------------------------------------

Comment By: Paul Moore (pmoore)
Date: 2004-06-05 14:01

Message:
Logged In: YES 
user_id=113328

Suggested documentation patch:

Index: lib/libmmap.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/lib/libmmap.tex,v
retrieving revision 1.8
diff -u -r1.8 libmmap.tex
--- lib/libmmap.tex	3 Dec 2001 18:27:22 -0000	1.8
+++ lib/libmmap.tex	5 Jun 2004 18:00:08 -0000
@@ -44,7 +44,9 @@
   specified by the file handle \var{fileno}, and returns a mmap
   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.
+  called.  If \var{length} is \code{0} and the file is 0
bytes long,
+  Windows will return an error.  It is not possible to map
a 0-byte
+  file under Windows.
   
   \var{tagname}, if specified and not \code{None}, is a
string giving
   a tag name for the mapping.  Windows allows you to have many


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=964876&group_id=5470



More information about the Python-bugs-list mailing list