Subject: bug#2790: emacs 22.1.1 cannot open 5GB file on
64GB 64-bit GNU/Linux box

> Okay, tried it (emacs-23.0.91), but no luck. Looks very nice, but
> finding that large file produced the same error. The value of
> 'most-positive-fixnum' prints correctly, though (which is different).

There was an incorrect check that limited the size to INT_MAX/4
(i.e. 512MB for systems where ints are 32bit). I've removed this check
in the CVS code (see patch below). I am now able to open an 800MB file
with this check removed. OTOH with a 2GB file, I got some unjustified
"memory exhausted" error, but I haven't tracked it down yet. Note also
that when you open large files, it's worthwhile to use
find-file-literally to be sure it's opened in unibyte mode; otherwise
it gets decoded which takes ages. Also if the file has many lines (my
800MB file was made up by copying a C file many times, so it had
millions of lines), turning off line-number-mode is is needed to recover
responsiveness when navigating near the end of the buffer.


Index: src/fileio.c
RCS file: /sources/emacs/emacs/src/fileio.c,v
retrieving revision 1.651
retrieving revision 1.652
diff -u -r1.651 -r1.652
--- src/fileio.c 24 Mar 2009 14:14:54 -0000 1.651
+++ src/fileio.c 28 Mar 2009 02:06:08 -0000 1.652
@@ -3300,7 +3300,11 @@
overflow. The calculations below double the file size
twice, so check that it can be multiplied by 4 safely. */
if (XINT (end) != st.st_size
- || st.st_size > INT_MAX / 4)
+ /* Actually, it should test either INT_MAX or LONG_MAX
+ depending on which one is used for EMACS_INT. But in
+ any case, in practice, this test is redundant with the
+ one above.
+ || st.st_size > INT_MAX / 4 */)

ror ("Maximum buffer size exceeded");

/* The file size returned from stat may be zero, but data