[issue40785] `mmap.mmap(..., 0)` doesn't work as advertised in docs (fails with EINVAL); relies on compatibility behavior no longer permitted by [some] Unix OSes

2020-05-26 Thread Enji Cooper


Enji Cooper  added the comment:

Sidenote: all versions tested were 3.8.2:

pinklady:freebsd ngie$ /usr/local/opt/python@3.8/bin/python3 -V
Python 3.8.2

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40785] `mmap.mmap(..., 0)` doesn't work as advertised in docs (fails with EINVAL); relies on compatibility behavior no longer permitted by [some] Unix OSes

2020-05-26 Thread Enji Cooper


New submission from Enji Cooper :

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 "", line 1, in 
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

--
components: Interpreter Core
messages: 370029
nosy: ngie
priority: normal
severity: normal
status: open
title: `mmap.mmap(..., 0)` doesn't work as advertised in docs (fails with 
EINVAL); relies on compatibility behavior no longer permitted by [some] Unix 
OSes
versions: Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com