gh-68048: Remove unneeded lseek() call in mmap.mmap on Windows (GH-7017)

serhiy-storchaka <[email protected]> Sun, 09 Aug 2026 14:10:44 -0400 (EDT)
Newsgroups gmane.comp.python.cvs
Message-ID <[email protected]>
https://github.com/python/cpython/commit/5107fd700d70abf62762d09f766200532866e823
commit: 5107fd700d70abf62762d09f766200532866e823
branch: main
author: Zackery Spytz <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-08-09T18:10:29Z
summary:

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 <[email protected]>

files:
A Misc/NEWS.d/next/Windows/2026-08-09-17-30-00.gh-issue-68048.Mq8Vd4.rst
M Lib/test/test_mmap.py
M Modules/mmapmodule.c

diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py
index 55c6ad04d44d828..053a4ca4db53a57 100644
--- a/Lib/test/test_mmap.py
+++ b/Lib/test/test_mmap.py
@@ -59,6 +59,7 @@ def test_basic(self):
             f.flush()
             m = mmap.mmap(f.fileno(), 2 * PAGESIZE)
             self.addCleanup(m.close)
+            self.assertEqual(f.tell(), 2 * PAGESIZE)
         finally:
             f.close()
 
diff --git a/Misc/NEWS.d/next/Windows/2026-08-09-17-30-00.gh-issue-68048.Mq8Vd4.rst b/Misc/NEWS.d/next/Windows/2026-08-09-17-30-00.gh-issue-68048.Mq8Vd4.rst
new file mode 100644
index 000000000000000..12b5067ba934ec2
--- /dev/null
+++ b/Misc/NEWS.d/next/Windows/2026-08-09-17-30-00.gh-issue-68048.Mq8Vd4.rst
@@ -0,0 +1,2 @@
+Creating a :class:`mmap.mmap` object on Windows no longer resets the position
+of the underlying file to zero, as on other platforms.
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index e521e95d4ded73f..58f1e3b2ddcca70 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -2084,9 +2084,6 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
         fh = _Py_get_osfhandle(fileno);
         if (fh == INVALID_HANDLE_VALUE)
             return NULL;
-
-        /* Win9x appears to need us seeked to zero */
-        lseek(fileno, 0, SEEK_SET);
     }
 
     m_obj = (mmap_object *)type->tp_alloc(type, 0);

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]