Subject: Re: bug#25360: File mode specification errors during building

From: [email-masked] (Phillip Lord)
Date: Tue, 17 Jan 2017 22:04:22 +0000

Glenn Morris <[email-masked]> writes:

> [email-masked] wrote:
>
>> Using insert-file-contents instead of file-file-noselect seems to fix it
>> for me:
>
> That sounds like a good change anyway. (I forget, does this respect
> "coding:"? Does this even matter in this case?)

I think, no, it doesn't respect coding, but that it doesn't matter.

>
> (But it still seems like a potential problem to me if functions that used to
> be available early in the build no longer are.)

It shouldn't be, if they are not being called.

Anyway, the cause of the error in this case is this line in files.el.

	 (assoc-default nil magic-fallback-mode-alist
		(lambda (re _dummy)
		  (if (functionp re)
		      (funcall re)
		    (looking-at re)))))))

This is called when loading cangjie-table.b5 with
'image-type-auto-detected-p as the first parameter. Normally, the
condition returns "t", but in this case it will return f, then
the looking-at form fails with the error given. I don't understand which
this process does not happen during the build which generates
ldefs-boot-auto.el.

The bigger problem is that the bootstrap-emacs executable has different
functionality compiled in, even when it does not require it to perform
the task of bootstrapping. This might invalidate my approach, but I am
not sure yet.

The follow patch addresses, the problem at hand, though.

>From bed019eb18fbafffd397eaac7962e30428fe1e04 Mon Sep 17 00:00:00 2001
From: Phillip Lord <[email-masked]>
Date: Mon, 16 Jan 2017 23:09:06 +0000
Subject: [PATCH] Fix file-mode errors in bootstrap.

* lisp/files.el (set-auto-mode): Do not call `looking-at' on a symbol.
* lisp/international/titdic-cnv.el (miscdic-convert): Use
  `insert-file-contents' rather than `find-file-noselect'.
---
 lisp/files.el                    | 28 ++++++++++++++++++++++------
 lisp/international/titdic-cnv.el |  8 ++++----
 2 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/lisp/files.el b/lisp/files.el
index b57e35b..e7b15a8 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -2911,9 +2911,18 @@ set-auto-mode
 						(+ (point-min) magic-mode-regexp-match-limit)))
 			 (assoc-default nil magic-mode-alist
 					(lambda (re _dummy)
-					  (if (functionp re)
-					      (funcall re)
-					    (looking-at re)))))))
+                                          (cond
+                                           ;; Bug#25360 We might have a
+                                           ;; symbol which is not a
+                                           ;; function during bootstrap.
+                                           ((and
+                                              (symbolp re)
+                                              (functionp re))
+                                            (funcall re))
+                                           ((stringp re)
+					    (looking-at re)))
+                                          (t (error "Problem with `magic-mode-alist'."))
+                                           )))))
 	  (set-auto-mode-0 done keep-mode-if-same)))
     ;; Next compare the filename against the entries in auto-mode-alist.
     (unless done
@@ -2966,9 +2975,16 @@ set-auto-mode
 						(+ (point-min) magic-mode-regexp-match-limit)))
 			 (assoc-default nil magic-fallback-mode-alist
 					(lambda (re _dummy)
-					  (if (functionp re)
-					      (funcall re)
-					    (looking-at re)))))))
+                                          ;; Bug#25360 We might have a
+                                          ;; symbol which is not a
+                                          ;; function during bootstrap.
+					  (cond
+                                           ((functionp re)
+                                            (funcall re))
+                                           ((stringp re)
+                                            (looking-at re))
+                                           (t (error "Problem with `magic-fallback-mode-alist'."))
+                                           ))))))
 	  (set-auto-mode-0 done keep-mode-if-same)))
     (unless done
       (set-buffer-major-mode (current-buffer)))))
diff --git a/lisp/international/titdic-cnv.el b/lisp/international/titdic-cnv.el
index 6f65d49..6986b3f 100644
--- a/lisp/international/titdic-cnv.el
+++ b/lisp/international/titdic-cnv.el
@@ -1168,10 +1168,10 @@ miscdic-convert
 		      "Chinese-GB"))
 		  "\" \"" title "\" t\n")
 	  (let* ((coding-system-for-read
-		  (coding-system-change-eol-conversion coding 'unix))
-		 (dicbuf (find-file-noselect filename)))
-	    (funcall converter dicbuf name title)
-	    (kill-buffer dicbuf))
+		  (coding-system-change-eol-conversion coding 'unix)))
+            (with-temp-buffer
+              (insert-file-contents filename)
+              (funcall converter (current-buffer) name title)))
 	  (insert ";; Local Variables:\n"
 		  ";; version-control: never\n"
 		  ";; no-update-autoloads: t\n"
-- 
2.9.3