From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Newsgroups: gmane.emacs.bugs 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 Message-ID: <87pmsmavj6.fsf@gmail.com> References: <831r54einq.fsf@gnu.org> <871r54xnds.fsf@gmail.com> <87ee933bcj.fsf@gmail.com> <83pmsnbnci.fsf@gnu.org> <83k0ivbjbu.fsf@gnu.org> <83czonbhex.fsf@gnu.org> <83lf3a8eo7.fsf@gnu.org> <87y27at950.fsf@gmail.com> <83bl4685m2.fsf@gnu.org> <837deu84i0.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7645"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.60 (gnu/linux) Cc: 50946@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Oct 03 19:06:49 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mX4wr-0001lG-5I for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 03 Oct 2021 19:06:49 +0200 Original-Received: from localhost ([::1]:46854 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mX4wo-0000AL-PX for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 03 Oct 2021 13:06:46 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48280) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mX4w6-00008t-5D for bug-gnu-emacs@gnu.org; Sun, 03 Oct 2021 13:06:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51516) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mX4w5-0004gu-Td for bug-gnu-emacs@gnu.org; Sun, 03 Oct 2021 13:06:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mX4w5-000597-Mp for bug-gnu-emacs@gnu.org; Sun, 03 Oct 2021 13:06:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 03 Oct 2021 17:06:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50946 X-GNU-PR-Package: emacs Original-Received: via spool by 50946-submit@debbugs.gnu.org id=B50946.163328074319755 (code B ref 50946); Sun, 03 Oct 2021 17:06:01 +0000 Original-Received: (at 50946) by debbugs.gnu.org; 3 Oct 2021 17:05:43 +0000 Original-Received: from localhost ([127.0.0.1]:34829 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mX4vm-00058Y-Us for submit@debbugs.gnu.org; Sun, 03 Oct 2021 13:05:43 -0400 Original-Received: from mail-wr1-f47.google.com ([209.85.221.47]:36546) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mX4vk-00058L-5x for 50946@debbugs.gnu.org; Sun, 03 Oct 2021 13:05:41 -0400 Original-Received: by mail-wr1-f47.google.com with SMTP id o20so7934248wro.3 for <50946@debbugs.gnu.org>; Sun, 03 Oct 2021 10:05:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=LB1wyHK+/g3FbHBEJEkrgK0iEz0yhl5iw7psd+3rKmg=; b=cJW1hGlxFlojEapoaTH6vop5hli9VVXwUGZioBKUXHuCecSr6Cv7RyzeLCo9kWaLox vgQHV3OIyZuUx1z/S6IHojcjOftmpuuYqPLalaA+SyZJ0FEI7Jl/R269eGhEDDTIDD28 77gUSOK3PrEna0AIM6pVEjd6+YjWMJPBOu/sK0XExJKzb4KZObhsQfg0/lbJshfjh3gm kae3IuMRD/TwuTGQIUOtIdxeuCbnQefQDw4dPJQO6M5FFLxKMnNM43nPZMIarA9LK2u4 80K9vwDD1ZPutHKLV+muTlf+r+UKCGQOEvVZMfe2NQCCb6VG6WnzsRQJJ66nU5O/lmGS b7KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=LB1wyHK+/g3FbHBEJEkrgK0iEz0yhl5iw7psd+3rKmg=; b=OMqSi2a174wl3Ef3e8VgAdGMx0qi2CJN1ITbQpj7l8+iLJXpJZFziJYivL7LDvAe8n eArdPzeYaqm/GrVQP7Hh1x07LpxlbZM9A6mwOfmvTFqPfvNu3QrBgfVSXLxm5Xn+29pW 0FDcZPUiHRmSvbFp1KlizvB2BzIrZHxrk72JJuKf0pD4jK6w68nIfW3D/8W76juBg/uQ Rm8smDWa7OggkgDfKb6q/kVaZMQbA99/8zF5kjypOJAhs7cQ9GpGpvtrXa1yUmpOTnFb AqAOm5yZ6wfQ+EAjHLv0bCK6fhKzueg2F5uGIc5kSKmoQMLLgLt7JNKJuR7SEhHPZSKT ZEyA== X-Gm-Message-State: AOAM530aar493fgMICKWcCgjH2B5ah6dmUoVSinogm8he0s3QbiUHHH3 KDpz99+/tym1JyvXkHkQXhpBEjffRl4= X-Google-Smtp-Source: ABdhPJyMvUU/C+NeWFzvOJkKQtuaMPdEZCSSblqkhz2iCMQ3It3O++O7OVJP3pZVQhhFcgBH2aFbZA== X-Received: by 2002:a05:6000:1112:: with SMTP id z18mr6394774wrw.349.1633280733769; Sun, 03 Oct 2021 10:05:33 -0700 (PDT) Original-Received: from krug (87-196-156-235.net.novis.pt. [87.196.156.235]) by smtp.gmail.com with ESMTPSA id v6sm4076932wrd.71.2021.10.03.10.05.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Oct 2021 10:05:33 -0700 (PDT) In-Reply-To: <837deu84i0.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 03 Oct 2021 19:20:07 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:216278 Archived-At: Eli Zaretskii 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=C3=A3o 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") =20 (load "shorthands") -(setq load-source-file-function #'load-with-shorthands-and-code-conversion) =20 (load "emacs-lisp/eldoc") (load "cus-start") ;Late to reduce customize-rogue (needs loaddefs.el anyw= ay) 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. =20 ;;; Code: -(require 'files) (eval-when-compile (require 'cl-lib)) =20 -(defun hack-read-symbol-shorthands (fullname) - "Return value of `read-symbol-shorthands' file-local variable in FULLNAM= E. -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) (>=3D from 0)) - (insert-file-contents fullname nil from to) - (setq to from - from (cond - ((=3D 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-varia= bles))))) - -(defun load-with-shorthands-and-code-conversion (fullname file noerror nom= essage) - "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 cod= e." - (let ((read-symbol-shorthands (hack-read-symbol-shorthands fullname))) - (load-with-code-conversion fullname file noerror nomessage))) - - ;; 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=3D'$(srcdir)/../.git/logs/HEAD' BIN_DESTDIR=3D''/usr= /local/bin/'' \ ELN_DESTDIR=3D'/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/ch= arsets' make[2]: Nothing to be done for 'all'. make[2]: Leaving directory '/home/capitaomorte/Source/Emacs/emacs/admin/cha= rsets' make -C ../admin/unidata charscript.el make[2]: Entering directory '/home/capitaomorte/Source/Emacs/emacs/admin/un= idata' make[2]: Nothing to be done for 'charscript.el'. make[2]: Leaving directory '/home/capitaomorte/Source/Emacs/emacs/admin/uni= data' make -C ../admin/unidata emoji-zwj.el make[2]: Entering directory '/home/capitaomorte/Source/Emacs/emacs/admin/un= idata' make[2]: Nothing to be done for 'emoji-zwj.el'. make[2]: Leaving directory '/home/capitaomorte/Source/Emacs/emacs/admin/uni= data' make -C ../lisp autoloads EMACS=3D"../src/bootstrap-emacs" make[2]: Entering directory '/home/capitaomorte/Source/Emacs/emacs/lisp' make -C ../leim all EMACS=3D"../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=3D"../../src/bootstrap-emacs" make[3]: Entering directory '/home/capitaomorte/Source/Emacs/emacs/admin/gr= ammars' make[3]: Nothing to be done for 'all'. make[3]: Leaving directory '/home/capitaomorte/Source/Emacs/emacs/admin/gra= mmars' 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...=20 INFO Scraping files for loaddefs.el...done make[2]: Leaving directory '/home/capitaomorte/Source/Emacs/emacs/lisp' make -C ../admin/unidata all EMACS=3D"../../src/bootstrap-emacs" make[2]: Entering directory '/home/capitaomorte/Source/Emacs/emacs/admin/un= idata' make[2]: Nothing to be done for 'all'. make[2]: Leaving directory '/home/capitaomorte/Source/Emacs/emacs/admin/uni= data' make -C ../admin/charsets cp51932.el make[2]: Entering directory '/home/capitaomorte/Source/Emacs/emacs/admin/ch= arsets' make[2]: Nothing to be done for 'cp51932.el'. make[2]: Leaving directory '/home/capitaomorte/Source/Emacs/emacs/admin/cha= rsets' make -C ../admin/charsets eucjp-ms.el make[2]: Entering directory '/home/capitaomorte/Source/Emacs/emacs/admin/ch= arsets' make[2]: Nothing to be done for 'eucjp-ms.el'. make[2]: Leaving directory '/home/capitaomorte/Source/Emacs/emacs/admin/cha= rsets' LC_ALL=3DC ./temacs -batch -l loadup --temacs=3Dpdump \ --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/u= ni-special-lowercase.el", "/home/capitaomorte/Source/Emacs/emacs/lisp/inter= national/uni-special-lowercase.el", "/home/capitaomorte/Source/Emacs/emacs/= lisp/international/uni-special-lowercase.el", "/home/capitaomorte/Source/Em= acs/emacs/lisp/international/uni-special-lowercase.el", "/home/capitaomorte= /Source/Emacs/emacs/lisp/international/uni-special-lowercase.el", "/home/ca= pitaomorte/Source/Emacs/emacs/lisp/international/uni-bidi.el", "/home/capit= aomorte/Source/Emacs/emacs/lisp/international/characters.elc", "/home/capit= aomorte/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