New submission from Enji Cooper <yaneurab...@gmail.com>:
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 ---------- 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 <rep...@bugs.python.org> <https://bugs.python.org/issue40785> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com