This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ngie
Recipients ngie
Date 2020-05-26.20:44:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1590525883.45.0.922905943745.issue40785@roundup.psfhosted.org>
In-reply-to
Content
The documentation for mmap.mmap() claims that passing a length of 0 will map in an entire file, but unfortunately that doesn't work as shown below:

>>> mmap.mmap(-1, 0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 22] Invalid argument

I've double-checked that this isn't an OS specific bug on the following OS platforms:

* Fedora 31
* FreeBSD 
* OSX Catalina

The errno == EINVAL issue is documented in the OS X Catalina manpage as follows:

```
     [EINVAL]           The len argument was negative or zero. Historically, the system call would not return an error if the argument was zero.  See other potential additional
                        restrictions in the COMPATIBILITY section below.

...

COMPATIBILITY
     mmap() now returns with errno set to EINVAL in places that historically succeeded.  The rules have changed as follows:

     o   The flags parameter must specify either MAP_PRIVATE or MAP_SHARED.

     o   The len parameter must not be 0.

     o   The off parameter must be a multiple of pagesize, as returned by sysconf().
```

POSIX concurs: https://pubs.opengroup.org/onlinepubs/9699919799/ .

So, in short -- python's mmap.mmap(.., 0) implementation relies on behavior which is now not permitted in multiple OSes and is not permitted per the POSIX spec for mmap(2).

1. https://docs.python.org/3/library/mmap.html#mmap.mmap
History
Date User Action Args
2020-05-26 20:44:43ngiesetrecipients: + ngie
2020-05-26 20:44:43ngiesetmessageid: <1590525883.45.0.922905943745.issue40785@roundup.psfhosted.org>
2020-05-26 20:44:43ngielinkissue40785 messages
2020-05-26 20:44:42ngiecreate