File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -1136,6 +1136,18 @@ def test_access_violations(self):
11361136 self .assertEqual (stdout .strip (), b'' )
11371137 self .assertEqual (stderr .strip (), b'' )
11381138
1139+ def test_flush_parameters (self ):
1140+ with open (TESTFN , 'wb+' ) as f :
1141+ f .write (b'x' * PAGESIZE * 3 )
1142+ f .flush ()
1143+
1144+ m = mmap .mmap (f .fileno (), PAGESIZE * 3 )
1145+ self .addCleanup (m .close )
1146+
1147+ m .flush ()
1148+ m .flush (PAGESIZE )
1149+ m .flush (PAGESIZE , PAGESIZE )
1150+
11391151
11401152class LargeMmapTests (unittest .TestCase ):
11411153
Original file line number Diff line number Diff line change @@ -133,7 +133,6 @@ typedef struct {
133133} mmap_object ;
134134
135135#define mmap_object_CAST (op ) ((mmap_object *)(op))
136- #define MMAP_GET_SIZE (self ) (mmap_object_CAST(self)->size)
137136
138137#include "clinic/mmapmodule.c.h"
139138
@@ -937,7 +936,7 @@ mmap_tell_method(PyObject *op, PyObject *Py_UNUSED(ignored))
937936mmap.mmap.flush
938937
939938 offset: Py_ssize_t = 0
940- size: Py_ssize_t(c_default="MMAP_GET_SIZE(self) ") = None
939+ size: Py_ssize_t(c_default="-1 ") = None
941940 /
942941
943942Flushes changes made to the in-memory copy of a file back to disk.
@@ -949,10 +948,15 @@ flushed.
949948
950949static PyObject *
951950mmap_mmap_flush_impl (mmap_object * self , Py_ssize_t offset , Py_ssize_t size )
952- /*[clinic end generated code: output=956ced67466149cf input=23ac67c08804a13a ]*/
951+ /*[clinic end generated code: output=956ced67466149cf input=07c2c6d4e69263a4 ]*/
953952{
954953 CHECK_VALID (NULL );
955954
955+ /* If size is -1 (default), calculate size from offset to end */
956+ if (size == -1 ) {
957+ size = self -> size - offset ;
958+ }
959+
956960 if (size < 0 || offset < 0 || self -> size - offset < size ) {
957961 PyErr_SetString (PyExc_ValueError , "flush values out of range" );
958962 return NULL ;
You can’t perform that action at this time.
0 commit comments