unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "João Távora" <joaotavora@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 50946@debbugs.gnu.org
Subject: bug#50946: insert-file-contents can corrupt buffers. [Was: bug#50946: Emacs-28: Inadequate coding in hack-elisp-shorthands]
Date: Sun, 03 Oct 2021 18:05:33 +0100	[thread overview]
Message-ID: <87pmsmavj6.fsf@gmail.com> (raw)
In-Reply-To: <837deu84i0.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 03 Oct 2021 19:20:07 +0300")

Eli Zaretskii <eliz@gnu.org> writes:


>> No, fboundp also works, probably.  Do you prefer that to a hook?
>> A hook is, in theory, more powerful.
> Well, using a hook in our own sources is IMO ... "icky".
> So yes, I prefer the fboundp test.  And then shorthands.el will deal

Hmm, I think we do use them a lot.  Or at least foo-function variables
for the same purpose.

Icky or not, the fboundp one isn't working, the hook one I gave you
earlier does.

With the fboundp, I get some recursive load error (not the first time).
I didn't investigate, maybe you can tell what's going on?  I am missing
sometehing obvious?

After my sig is the patch, followed by the error (search for "make
error".

João

The patch:

diff --git a/lisp/international/mule.el b/lisp/international/mule.el
index 2a855b5673..11d344433f 100644
--- a/lisp/international/mule.el
+++ b/lisp/international/mule.el
@@ -319,7 +319,8 @@ load-with-code-conversion
 	  (let ((load-true-file-name fullname)
                 (load-file-name fullname)
                 (set-auto-coding-for-load t)
-		(inhibit-file-name-operation nil))
+		(inhibit-file-name-operation nil)
+                (shorthands))
 	    (with-current-buffer buffer
               ;; So that we don't get completely screwed if the
               ;; file is encoded in some complicated character set,
@@ -328,6 +329,10 @@ load-with-code-conversion
 	      ;; Don't let deactivate-mark remain set.
 	      (let (deactivate-mark)
 		(insert-file-contents fullname))
+              (setq shorthands
+                    (and (fboundp 'hack-local-variables--find-variables)
+                         (alist-get 'read-symbol-shorthands
+                                    (hack-local-variables--find-variables))))
 	      ;; If the loaded file was inserted with no-conversion or
 	      ;; raw-text coding system, make the buffer unibyte.
 	      ;; Otherwise, eval-buffer might try to interpret random
@@ -338,11 +343,13 @@ load-with-code-conversion
 		  (set-buffer-multibyte nil))
 	      ;; Make `kill-buffer' quiet.
 	      (set-buffer-modified-p nil))
-	    ;; Have the original buffer current while we eval.
-	    (eval-buffer buffer nil
-			 ;; This is compatible with what `load' does.
-                         (if dump-mode file fullname)
-			 nil t))
+	    ;; Have the original buffer current while we eval,
+            ;; but consider shorthands of the eval'ed one.
+	    (let ((read-symbol-shorthands shorthands))
+              (eval-buffer buffer nil
+			   ;; This is compatible with what `load' does.
+                           (if dump-mode file fullname)
+			   nil t)))
 	(let (kill-buffer-hook kill-buffer-query-functions)
 	  (kill-buffer buffer)))
       (do-after-load-evaluation fullname)
diff --git a/lisp/loadup.el b/lisp/loadup.el
index 3fb6b81328..3a55d2c805 100644
--- a/lisp/loadup.el
+++ b/lisp/loadup.el
@@ -355,7 +355,6 @@
 (load "paren")
 
 (load "shorthands")
-(setq load-source-file-function #'load-with-shorthands-and-code-conversion)
 
 (load "emacs-lisp/eldoc")
 (load "cus-start") ;Late to reduce customize-rogue (needs loaddefs.el anyway)
diff --git a/lisp/shorthands.el b/lisp/shorthands.el
index c31ef3d216..adbbf3713b 100644
--- a/lisp/shorthands.el
+++ b/lisp/shorthands.el
@@ -25,40 +25,8 @@
 ;; Basic helpers for loading files with Shorthands.
 
 ;;; Code:
-(require 'files)
 (eval-when-compile (require 'cl-lib))
 
-(defun hack-read-symbol-shorthands (fullname)
-  "Return value of `read-symbol-shorthands' file-local variable in FULLNAME.
-FULLNAME is the absolute file name of an Elisp .el file which
-potentially specifies a file-local value for
-`read-symbol-shorthands'.  The Elisp code in FULLNAME isn't read
-or evaluated in any way, except for extraction of the
-buffer-local value of `read-symbol-shorthands'."
-  (let* ((size (nth 7 (file-attributes fullname)))
-         (from (max 0 (- size 3000)))
-         (to size))
-    (with-temp-buffer
-      (while (and (< (buffer-size) 3000) (>= from 0))
-        (insert-file-contents fullname nil from to)
-        (setq to from
-              from (cond
-                    ((= from 0) -1)
-                    (t (max 0 (- from 100))))))
-      ;; FIXME: relies on the `hack-local-variables--find-variables'
-      ;; detail of files.el.  That function should be exported,
-      ;; possibly be refactored into two parts, since we're only
-      ;; interested in basic "Local Variables" parsing.
-      (alist-get 'read-symbol-shorthands (hack-local-variables--find-variables)))))
-
-(defun load-with-shorthands-and-code-conversion (fullname file noerror nomessage)
-  "Like `load-with-code-conversion', but also consider Elisp shorthands.
-This function uses shorthands defined in the file FULLNAME's local
-value of `read-symbol-shorthands', when it processes that file's Elisp code."
-  (let ((read-symbol-shorthands (hack-read-symbol-shorthands fullname)))
-    (load-with-code-conversion fullname file noerror nomessage)))
-
-\f
 ;; FIXME: move this all to progmodes/elisp-mode.el?  OTOH it'd make
 ;; more sense there, OTOH all the elisp font-lock stuff is actually in
 ;; lisp/emacs-lisp/lisp-mode.el, which isn't right either.  So


The make error I get:

make -C lib all
make[1]: Entering directory '/home/capitaomorte/Source/Emacs/emacs/lib'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/capitaomorte/Source/Emacs/emacs/lib'
make -C lib-src all
make[1]: Entering directory '/home/capitaomorte/Source/Emacs/emacs/lib-src'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/capitaomorte/Source/Emacs/emacs/lib-src'
make -C src VCSWITNESS='$(srcdir)/../.git/logs/HEAD' BIN_DESTDIR=''/usr/local/bin/'' \
	 ELN_DESTDIR='/usr/local/lib/emacs/28.0.60/' all
make[1]: Entering directory '/home/capitaomorte/Source/Emacs/emacs/src'
make -C ../admin/charsets all
make[2]: Entering directory '/home/capitaomorte/Source/Emacs/emacs/admin/charsets'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/home/capitaomorte/Source/Emacs/emacs/admin/charsets'
make -C ../admin/unidata charscript.el
make[2]: Entering directory '/home/capitaomorte/Source/Emacs/emacs/admin/unidata'
make[2]: Nothing to be done for 'charscript.el'.
make[2]: Leaving directory '/home/capitaomorte/Source/Emacs/emacs/admin/unidata'
make -C ../admin/unidata emoji-zwj.el
make[2]: Entering directory '/home/capitaomorte/Source/Emacs/emacs/admin/unidata'
make[2]: Nothing to be done for 'emoji-zwj.el'.
make[2]: Leaving directory '/home/capitaomorte/Source/Emacs/emacs/admin/unidata'
make -C ../lisp autoloads EMACS="../src/bootstrap-emacs"
make[2]: Entering directory '/home/capitaomorte/Source/Emacs/emacs/lisp'
make -C ../leim all EMACS="../src/bootstrap-emacs"
make[3]: Entering directory '/home/capitaomorte/Source/Emacs/emacs/leim'
make[3]: Nothing to be done for 'all'.
make[3]: Leaving directory '/home/capitaomorte/Source/Emacs/emacs/leim'
make -C ../admin/grammars all EMACS="../../src/bootstrap-emacs"
make[3]: Entering directory '/home/capitaomorte/Source/Emacs/emacs/admin/grammars'
make[3]: Nothing to be done for 'all'.
make[3]: Leaving directory '/home/capitaomorte/Source/Emacs/emacs/admin/grammars'
  GEN      loaddefs.el
  SCRAPE   . ./calc ./calendar ./cedet ./cedet/ede ./cedet/semantic ...
  SCRAPE   ./cedet/semantic/analyze ./cedet/semantic/bovine ...
  SCRAPE   ./cedet/semantic/decorate ./cedet/semantic/symref ...
  SCRAPE   ./cedet/semantic/wisent ./cedet/srecode ./emacs-lisp ./emulation ...
  SCRAPE   ./erc ./eshell ./gnus ./image ./international ./language ./leim ...
  SCRAPE   ./leim/ja-dic ./leim/quail ./mail ./mh-e ./net ./nxml ./org ...
  SCRAPE   ./play ./progmodes ./textmodes ./url ./vc
  INFO     Scraping files for loaddefs.el... 
  INFO     Scraping files for loaddefs.el...done
make[2]: Leaving directory '/home/capitaomorte/Source/Emacs/emacs/lisp'
make -C ../admin/unidata all EMACS="../../src/bootstrap-emacs"
make[2]: Entering directory '/home/capitaomorte/Source/Emacs/emacs/admin/unidata'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/home/capitaomorte/Source/Emacs/emacs/admin/unidata'
make -C ../admin/charsets cp51932.el
make[2]: Entering directory '/home/capitaomorte/Source/Emacs/emacs/admin/charsets'
make[2]: Nothing to be done for 'cp51932.el'.
make[2]: Leaving directory '/home/capitaomorte/Source/Emacs/emacs/admin/charsets'
make -C ../admin/charsets eucjp-ms.el
make[2]: Entering directory '/home/capitaomorte/Source/Emacs/emacs/admin/charsets'
make[2]: Nothing to be done for 'eucjp-ms.el'.
make[2]: Leaving directory '/home/capitaomorte/Source/Emacs/emacs/admin/charsets'
LC_ALL=C ./temacs -batch  -l loadup --temacs=pdump \
	--bin-dest /usr/local/bin/ --eln-dest /usr/local/lib/emacs/28.0.60/
Loading loadup.el (source)...
Dump mode: pdump
Using load-path (/home/capitaomorte/Source/Emacs/emacs/lisp)
Loading emacs-lisp/byte-run...
Loading emacs-lisp/backquote...
Loading subr...
Loading version...
Loading widget...
Loading custom...
Loading emacs-lisp/map-ynp...
Loading international/mule...
Loading international/mule-conf...
Loading env...
Loading format...
Loading bindings...
Loading window...
Loading files...
Loading emacs-lisp/macroexp...
Loading cus-face...
Loading faces...
Loading loaddefs.el (source)...
Loading button...
Loading emacs-lisp/nadvice...
Loading emacs-lisp/cl-preloaded...
Loading obarray...
Loading abbrev...
Loading simple...
Loading help...
Loading jka-cmpr-hook...
Loading epa-hook...
Loading international/mule-cmds...
Loading case-table...
Loading international/charprop.el (source)...
Loading international/characters...
Recursive load: "/home/capitaomorte/Source/Emacs/emacs/lisp/international/uni-special-lowercase.el", "/home/capitaomorte/Source/Emacs/emacs/lisp/international/uni-special-lowercase.el", "/home/capitaomorte/Source/Emacs/emacs/lisp/international/uni-special-lowercase.el", "/home/capitaomorte/Source/Emacs/emacs/lisp/international/uni-special-lowercase.el", "/home/capitaomorte/Source/Emacs/emacs/lisp/international/uni-special-lowercase.el", "/home/capitaomorte/Source/Emacs/emacs/lisp/international/uni-bidi.el", "/home/capitaomorte/Source/Emacs/emacs/lisp/international/characters.elc", "/home/capitaomorte/Source/Emacs/emacs/lisp/loadup.el"
make[1]: *** [Makefile:587: emacs.pdmp] Error 255
make[1]: Leaving directory '/home/capitaomorte/Source/Emacs/emacs/src'
make: *** [Makefile:449: src] Error 2





  reply	other threads:[~2021-10-03 17:05 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-01 17:10 bug#50946: Emacs-28: Inadequate coding in hack-elisp-shorthands Alan Mackenzie
2021-10-01 17:53 ` Eli Zaretskii
2021-10-01 21:15   ` João Távora
2021-10-02  6:10     ` Eli Zaretskii
2021-10-02  0:48   ` João Távora
2021-10-02 10:50     ` Alan Mackenzie
2021-10-02 11:13       ` João Távora
2021-10-02 11:38       ` João Távora
2021-10-02 12:38         ` Alan Mackenzie
2021-10-02 12:52           ` Eli Zaretskii
2021-10-02 13:57             ` Alan Mackenzie
2021-10-02 14:19               ` Eli Zaretskii
2021-10-02 14:45                 ` Alan Mackenzie
2021-10-02 15:00                   ` Eli Zaretskii
2021-10-02 20:07                     ` Alan Mackenzie
2021-10-03 11:45                       ` Eli Zaretskii
2021-10-03 12:10                     ` bug#50946: insert-file-contents can corrupt buffers. [Was: bug#50946: Emacs-28: Inadequate coding in hack-elisp-shorthands] Alan Mackenzie
2021-10-03 12:40                       ` Eli Zaretskii
2021-10-03 13:33                         ` Alan Mackenzie
2021-10-03 15:04                         ` bug#50946: insert-file-contents can corrupt buffers Alan Mackenzie
2021-10-03 15:25                           ` Eli Zaretskii
2021-10-03 17:21                             ` Alan Mackenzie
2021-10-03 17:36                               ` Eli Zaretskii
2021-10-03 18:19                                 ` Alan Mackenzie
2021-10-03 15:34                         ` bug#50946: insert-file-contents can corrupt buffers. [Was: bug#50946: Emacs-28: Inadequate coding in hack-elisp-shorthands] João Távora
2021-10-03 15:42                           ` João Távora
2021-10-03 15:56                           ` Eli Zaretskii
2021-10-03 16:02                             ` João Távora
2021-10-03 16:20                               ` Eli Zaretskii
2021-10-03 17:05                                 ` João Távora [this message]
2021-10-03 17:56                                   ` Eli Zaretskii
2021-10-03 18:59                                     ` João Távora
2021-10-03 19:51                                       ` Eli Zaretskii
2021-10-03 19:59                                         ` João Távora
2021-10-02 15:02                 ` bug#50946: Emacs-28: Inadequate coding in hack-elisp-shorthands João Távora
2021-10-04  0:14                   ` Richard Stallman
2021-10-02 14:47           ` João Távora

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87pmsmavj6.fsf@gmail.com \
    --to=joaotavora@gmail.com \
    --cc=50946@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).