Bug report
Bug description:
The signature of mmap.flush is flush([offset[, size]]), so we should have the ability to call it with offset only, eg: a_mmap_object.flush(4096).
But in current implementation, size's default value is the mmap object's size, so if the offset is non-zero, the total value of size and offset will be larger than the object's size, there is a check for this situation and if it happens, a ValueError will be raised.
So the size argument is required if user want to call it with with a non-zero offset, which is different to the document said.
There is a script to reproduce it:
import mmap import os f = open('test.tmp', 'wb+') f.write(b'x' * mmap.PAGESIZE * 4) f.flush() m = mmap.mmap(f.fileno(), mmap.PAGESIZE * 4) m.flush() m.flush(mmap.PAGESIZE) m.flush(mmap.PAGESIZE, mmap.PAGESIZE) m.close() f.close() os.unlink('test.tmp')
Which will print:
Traceback (most recent call last):
File "/home/xxxxx/Codes/cpython/test_flush_bug.py", line 11, in <module>
m.flush(mmap.PAGESIZE)
~~~~~~~^^^^^^^^^^^^^^^
ValueError: flush values out of range
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux