Subject: Re: bug#5303: 23.1.91; Cannot load .emacs-history from savehist.el

From: Eli Zaretskii <[email-masked]>
Date: Fri, 22 Jan 2010 10:54:42 +0200

> From: Chong Yidong <[email-masked]>
> Cc: [email-masked], [email-masked],
>         Stefan Monnier <[email-masked]>,
>         Richard Stallman <[email-masked]>
> Date: Thu, 21 Jan 2010 15:41:06 -0500
> 
> Chong Yidong <[email-masked]> writes:
> 
> >>   . Was safe_to_load_p intended to return non-zero value for invalid
> >>     file descriptors such as -2?
> >
> > I think that is a bug.
> 
> Does it fix the bug if safe_to_load_p returns 0 when the call to
> emacs_read on line 895 returns a value <= 0?

It does, but I prefer not to call safe_to_load_p at all in that case.
I've installed a slightly different fix, see below.

(There's another, possibly similar bug: load-file fails for
C:/the-file.el.gz because jka-compr signals a wrong type argument
error.  But that problem existed with the original Fload as well.  I
will file a separate bug and see what I can find there.)

2010-01-22  Eli Zaretskii  <[email-masked]>

	* lread.c (Fload): Don't treat files without .elc extension as
	byte-compiled if they are ``magic'', i.e. `openp' returned -2 for
	them.  (bug#5303)

=== modified file 'src/lread.c'
--- src/lread.c	2010-01-13 08:35:10 +0000
+++ src/lread.c	2010-01-22 08:35:48 +0000
@@ -1155,7 +1155,7 @@ Return t if the file exists and loads su
 
   if (!bcmp (SDATA (found) + SBYTES (found) - 4,
 	     ".elc", 4)
-      || (version = safe_to_load_p (fd)) > 0)
+      || (fd >= 0 && (version = safe_to_load_p (fd)) > 0))
     /* Load .elc files directly, but not when they are
        remote and have no handler!  */
     {