[Python-checkins] CVS: python/dist/src/Objects fileobject.c,2.121,2.122

Guido van Rossum gvanrossum@users.sourceforge.net
Mon, 10 Sep 2001 13:43:38 -0700

Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv22862

Modified Files:
Log Message:

Subtlety on Windows: if we change test_largefile.py to use a file
> 4GB, it still fails.  A debug session suggests this is because
fseek(fp, 0, 2) refuses to seek to the end of the file when the file
is > 4GB, because it uses the SetFilePointer() in 32-bit mode.

But it only fails when we seek relative to the end of the file,
because in the other seek modes only calls to fgetpos() and fsetpos()
are made, which use Get/SetFilePointer() in 64-bit mode.  Solution:
#ifdef MS_WInDOWS, replace the call to fseek(fp, ...) with a call to
_lseeki64(fileno(fp), ...).  Make sure to call fflush(fp) first.

(XXX Could also replace the entire branch with a call to _lseeki64().
Would that be more efficient?  Certainly less generated code.)

(XXX This needs more testing.  I can't actually test that it works for
files >4GB on my Win98 machine, because the filesystem here won't let
me create files >=4GB at all.  Tim should test this on his Win2K

Index: fileobject.c
RCS file: /cvsroot/python/python/dist/src/Objects/fileobject.c,v
retrieving revision 2.121
retrieving revision 2.122
diff -C2 -d -r2.121 -r2.122
*** fileobject.c	2001/09/06 00:32:15	2.121
--- fileobject.c	2001/09/10 20:43:35	2.122
*** 240,245 ****
--- 240,251 ----
  	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: