[Python-Dev] release for 2.1.2, plus 2.2.1...

Martin v. Loewis martin@v.loewis.de
Fri, 4 Jan 2002 11:38:28 +0100


> Do we expect that largefile support should work in Python 2.1.2?  I'm
> okay that autoconf detection fails as long as the instructions in the
> posix module work:
> 
>     http://www.python.org/doc/current/lib/posix-large-files.html

I don't think we can get autoconf detection to work on 2.1. The
instructions are right. Unfortunately, the code is wrong: It prefers
fgetpos in 2.1, but that returns not an integral type on some
systems.

I think the best approach is to copy the body of _portable_fseek and
_portable_ftell from 2.2. With that, I get a setup that atleast looks
right (patch attached)

> I've had some failures on 2.4.7 kernels w/ ext3 filesystems.

Were these compilation failures, or runtime failures? For the
compilation failures, ext3 should be irrelevant, and 2.4.7 should be
irrelevant as well - the glibc version would matter (which defines
fpos_t to be a struct with an mbstate_t inside).

Regards,
Martin

Index: fileobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/fileobject.c,v
retrieving revision 2.110
diff -u -r2.110 fileobject.c
--- fileobject.c	2001/04/14 17:49:40	2.110
+++ fileobject.c	2002/01/04 10:31:39
@@ -225,20 +225,28 @@
 static int
 _portable_fseek(FILE *fp, Py_off_t offset, int whence)
 {
-#if defined(HAVE_FSEEKO)
+#if !defined(HAVE_LARGEFILE_SUPPORT)
+	return fseek(fp, offset, whence);
+#elif defined(HAVE_FSEEKO) && SIZEOF_OFF_T >= 8
 	return fseeko(fp, offset, whence);
 #elif defined(HAVE_FSEEK64)
 	return fseek64(fp, offset, whence);
 #elif defined(__BEOS__)
 	return _fseek(fp, offset, whence);
-#elif defined(HAVE_LARGEFILE_SUPPORT) && SIZEOF_FPOS_T >= 8
+#elif SIZEOF_FPOS_T >= 8
 	/* lacking a 64-bit capable fseek(), use a 64-bit capable fsetpos()
 	   and fgetpos() to implement fseek()*/
 	fpos_t pos;
 	switch (whence) {
 	case SEEK_END:
+#ifdef MS_WINDOWS
+		fflush(fp);
+		if (_lseeki64(fileno(fp), 0, 2) == -1)
+			return -1;
+#else
 		if (fseek(fp, 0, SEEK_END) != 0)
 			return -1;
+#endif
 		/* fall through */
 	case SEEK_CUR:
 		if (fgetpos(fp, &pos) != 0)
@@ -249,7 +257,7 @@
 	}
 	return fsetpos(fp, &offset);
 #else
-	return fseek(fp, offset, whence);
+#error "Large file support, but no way to fseek."
 #endif
 }
 
@@ -260,17 +268,19 @@
 static Py_off_t
 _portable_ftell(FILE* fp)
 {
-#if SIZEOF_FPOS_T >= 8 && defined(HAVE_LARGEFILE_SUPPORT)
+#if !defined(HAVE_LARGEFILE_SUPPORT)
+	return ftell(fp);
+#elif defined(HAVE_FTELLO) && SIZEOF_OFF_T >= 8
+	return ftello(fp);
+#elif defined(HAVE_FTELL64)
+	return ftell64(fp);
+#elif SIZEOF_FPOS_T >= 8
 	fpos_t pos;
 	if (fgetpos(fp, &pos) != 0)
 		return -1;
 	return pos;
-#elif defined(HAVE_FTELLO) && defined(HAVE_LARGEFILE_SUPPORT)
-	return ftello(fp);
-#elif defined(HAVE_FTELL64) && defined(HAVE_LARGEFILE_SUPPORT)
-	return ftell64(fp);
 #else
-	return ftell(fp);
+#error "Large file support, but no way to ftell."
 #endif
 }