Skip to content

Commit 5107fd7

Browse files
gh-68048: Remove unneeded lseek() call in mmap.mmap on Windows (GH-7017)
fseek() was necessary for FILE streams on Windows 9x systems for its side effect (flush). lseek() which replaced it in 2003 was never needed. Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent b5c74a6 commit 5107fd7

3 files changed

Lines changed: 3 additions & 3 deletions

File tree

Lib/test/test_mmap.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def test_basic(self):
5959
f.flush()
6060
m = mmap.mmap(f.fileno(), 2 * PAGESIZE)
6161
self.addCleanup(m.close)
62+
self.assertEqual(f.tell(), 2 * PAGESIZE)
6263
finally:
6364
f.close()
6465

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Creating a :class:`mmap.mmap` object on Windows no longer resets the position
2+
of the underlying file to zero, as on other platforms.

Modules/mmapmodule.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,9 +2084,6 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
20842084
fh = _Py_get_osfhandle(fileno);
20852085
if (fh == INVALID_HANDLE_VALUE)
20862086
return NULL;
2087-
2088-
/* Win9x appears to need us seeked to zero */
2089-
lseek(fileno, 0, SEEK_SET);
20902087
}
20912088

20922089
m_obj = (mmap_object *)type->tp_alloc(type, 0);

0 commit comments

Comments
 (0)