From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Akinori MUSHA Newsgroups: gmane.emacs.bugs Subject: bug#37095: [PATCH] Save match data in ucs-normalize-region Date: Tue, 20 Aug 2019 16:18:06 +0900 Message-ID: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="00KXSRts8NEdTXlYtD6hBmhV1jhPWzwFq" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="164820"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 To: 37095@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Aug 20 09:28:05 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hzyYn-000ggk-3Y for geb-bug-gnu-emacs@m.gmane.org; Tue, 20 Aug 2019 09:28:05 +0200 Original-Received: from localhost ([::1]:34114 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hzyYl-0006hw-Of for geb-bug-gnu-emacs@m.gmane.org; Tue, 20 Aug 2019 03:28:03 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46242) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hzyWq-00040F-S5 for bug-gnu-emacs@gnu.org; Tue, 20 Aug 2019 03:26:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hzyWo-0004Lc-Rt for bug-gnu-emacs@gnu.org; Tue, 20 Aug 2019 03:26:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:52014) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hzyWo-0004LO-OB for bug-gnu-emacs@gnu.org; Tue, 20 Aug 2019 03:26:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hzyWo-0004wH-Iv for bug-gnu-emacs@gnu.org; Tue, 20 Aug 2019 03:26:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Akinori MUSHA Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 20 Aug 2019 07:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 37095 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.156628592818916 (code B ref -1); Tue, 20 Aug 2019 07:26:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 20 Aug 2019 07:25:28 +0000 Original-Received: from localhost ([127.0.0.1]:60835 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hzyWF-0004v1-J8 for submit@debbugs.gnu.org; Tue, 20 Aug 2019 03:25:27 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:53188) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hzyWD-0004ur-Dt for submit@debbugs.gnu.org; Tue, 20 Aug 2019 03:25:25 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46182) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hzyWB-0003P4-Il for bug-gnu-emacs@gnu.org; Tue, 20 Aug 2019 03:25:25 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hzyWA-0003OY-7y for bug-gnu-emacs@gnu.org; Tue, 20 Aug 2019 03:25:23 -0400 Original-Received: from v055125.ppp.asahi-net.or.jp ([124.155.55.125]:31566 helo=mail.musha.org) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hzyW9-0003LU-Sz for bug-gnu-emacs@gnu.org; Tue, 20 Aug 2019 03:25:22 -0400 Original-Received: from am-machimachi.local (ae161184.dynamic.ppp.asahi-net.or.jp [14.3.161.184]) (Authenticated sender: akinori) by mail.musha.org (Postfix) with ESMTPSA id 46CMZp6Qc9zsNBf for ; Tue, 20 Aug 2019 16:18:10 +0900 (JST) Openpgp: preference=signencrypt Autocrypt: addr=knu@iDaemons.org; prefer-encrypt=mutual; keydata= mQGiBDjXWqERBACDCxgN9+yMfpm3yvkYp+P4Uw6xxPdcZ9RvnTRkBX9zXaRgSPmMzeZ63LpB 99uVphVZrv/EdlyTf+cRdz6VXXRcTBloA/FsyY86IluBnWCH054WyXzr7az5WB9yDbPnlwcS L919bq0UqTuQUlQswdQAoDQG5LNNZNa0T01ydYtNlwCg3weSI/nEJrGCXGy2wrjg8LiwQ28D /Re2JHQPTYqDEZl6wj5U83wT55ChnTrjPRbGmr/CUdJP6CZQg6+DXYGYulcp3oL4btcdFDRF glJzmQNkUYmqiVC20SMVKUctrOCAI60P7VE40UtXz9EounPSRQQ1lSdMNeRwrZ9o7IcrSj0E Bw8lw3d2WxyM2Rs2crZWfOI2mu8dA/9LbmAw5sLk5Lo5i41nAWP76pyuGxSia6zMRdML6yno C5kmyrI9TwW5LNU/Lsq1Ru2XSA+CwSBpTt0vdwS88dDwPGxRuUHhWVpa1M5t7K7uYODB1cD5 AyNoNnR/lHpxfPZOJNdA3OPgfssN9K+PIuhbBU5xONCoAcdC9TEqSezfUrQhQWtpbm9yaSBN VVNIQSA8YWtpbm9yaUBtdXNoYS5vcmc+iF4EExECAB4FAkEA3xICGwMGCwkIBwMCAxUCAwMW AgECHgECF4AACgkQkgvvx5/Z4e6/swCeOoZdtSIMGoURsJgz0s54M4v9XYsAnjfKKN3F+2/O BM7j0QGWFqkw26/nuQENBDjXWqwQBAC09OxAmKbGn9FETdMA/5abvOY7JgNcFhQutEVnJ90m F/npBucWkCRbOr83t+N X-detected-operating-system: by eggs.gnu.org: FreeBSD [generic] [fuzzy] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:165400 Archived-At: This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --00KXSRts8NEdTXlYtD6hBmhV1jhPWzwFq Content-Type: multipart/mixed; boundary="5sMkWRVSFxXz0oljOufcQ0mjH7itPVZ4p"; protected-headers="v1" From: Akinori MUSHA To: bug-gnu-emacs@gnu.org Message-ID: Subject: [PATCH] Save match data in ucs-normalize-region --5sMkWRVSFxXz0oljOufcQ0mjH7itPVZ4p Content-Type: multipart/mixed; boundary="------------6A994AA2AFB0CBC22F4DF09E" Content-Language: en-US This is a multi-part message in MIME format. --------------6A994AA2AFB0CBC22F4DF09E Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable A patch generated by git format-patch is attached below, which simply wraps `ucs-normalize-region` with `save-match-data`. I'm a user of the Emacs Mac port by mituharu was investigating a bug where dired fails to open a certain local directory on macOS. The error was raised at `replace-match` in the `insert-directory` function: ``` (when (re-search-forward "^ *\\(total\\)" nil t) (let ((available (get-free-disk-space "."))) (when available ;; Replace "total" with "used", to avoid confusion. (replace-match "total used in directory" nil nil nil 1) ``` And it turned out the match data changed after returning from `get-free-disk-space` and that was why `replace-match` failed. Inside of `get-free-disk-space` most platforms uses a generic method to get the free space, and that part is fine because it is surrounded by `save-match-data`. However, the Mac port is one of the few platforms that implements a native 'file-system-info` function, which is called if it exists. Then, the `file-system-info` in `src/mac.c` calls ENCODE_FILE() on a given directory name, which in the end calls `ucs-normalize-region` to normalize the filename, where the match data is clobbered. https://bitbucket.org/mituharu/emacs-mac/src/df827786d7a7fb0a0e2f27577af6= 7e32d9a888a9/src/mac.c#lines-2337 ENCODE_FILE() is transparently called by many C functions, which means `ucs-normalize-region` can be called at unpredictable timings, so I think it should keep match data unchanged. --=20 Akinori MUSHA / https://akinori.org/ --------------6A994AA2AFB0CBC22F4DF09E Content-Type: text/plain; charset=UTF-8; name="0001-Save-match-data-in-ucs-normalize-region.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename*0="0001-Save-match-data-in-ucs-normalize-region.patch" =46rom 11d49adcbadcfcbe844f873e63ba1d596f72e4c5 Mon Sep 17 00:00:00 2001 From: Akinori MUSHA Date: Mon, 19 Aug 2019 23:53:50 +0900 Subject: [PATCH] Save match data in ucs-normalize-region * lisp/international/ucs-normalize.el (ucs-normalize-region): Save match data. This function can be transparently called via ENCODE_FILE() when the underlying filesytem uses normalized Unicode filenames, so it requires much care not to cause any side effects. --- lisp/international/ucs-normalize.el | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lisp/international/ucs-normalize.el b/lisp/international/ucs= -normalize.el index 6f1e770c09..d02d4b8e3e 100644 --- a/lisp/international/ucs-normalize.el +++ b/lisp/international/ucs-normalize.el @@ -514,19 +514,20 @@ ucs-normalize-region (narrow-to-region from to) (goto-char (point-min)) (let (start-pos starter) - (while (re-search-forward quick-check-regexp nil t) - (setq starter (string-to-char (match-string 0))) - (setq start-pos (match-beginning 0)) - (ucs-normalize-block - ;; from - (if (or (=3D start-pos (point-min)) - (and (=3D 0 (ucs-normalize-ccc starter)) - (not (memq starter ucs-normalize-combining-chars= )))) - start-pos (1- start-pos)) - ;; to - (if (looking-at ucs-normalize-combining-chars-regexp) - (match-end 0) (1+ start-pos)) - translation-table composition-predicate)))))) + (save-match-data + (while (re-search-forward quick-check-regexp nil t) + (setq starter (string-to-char (match-string 0))) + (setq start-pos (match-beginning 0)) + (ucs-normalize-block + ;; from + (if (or (=3D start-pos (point-min)) + (and (=3D 0 (ucs-normalize-ccc starter)) + (not (memq starter ucs-normalize-combining-cha= rs)))) + start-pos (1- start-pos)) + ;; to + (if (looking-at ucs-normalize-combining-chars-regexp) + (match-end 0) (1+ start-pos)) + translation-table composition-predicate))))))) =20 ;; ---------------------------------------------------------------------= ----------- =20 --=20 2.22.0 --------------6A994AA2AFB0CBC22F4DF09E-- --5sMkWRVSFxXz0oljOufcQ0mjH7itPVZ4p-- --00KXSRts8NEdTXlYtD6hBmhV1jhPWzwFq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EARECAB0WIQQIHQmcFwWGHUtwsEqSC+/Hn9nh7gUCXVuesgAKCRCSC+/Hn9nh 7tCCAJoCBTbInI2ezz8OZ5zGFncY2bOJrgCg2bzX3M3dH7ge+oCp6TfEE5Eh13I= =HLx7 -----END PGP SIGNATURE----- --00KXSRts8NEdTXlYtD6hBmhV1jhPWzwFq--