From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: Changes in GC and in pure space (was: [Emacs-diffs] master 5d4dd55: Fix lifetime error in previous patch) Date: Wed, 21 Aug 2019 17:25:26 -0700 Organization: UCLA Computer Science Department Message-ID: <3097a792-22f7-e1ad-19a8-2620b8c9c88d@cs.ucla.edu> References: <20190721193221.1964.53182@vcs0.savannah.gnu.org> <20190721193222.8C19E20BE2@vcs0.savannah.gnu.org> <83blxmqfkq.fsf@gnu.org> <9568ca7d-854f-1971-bbe8-03ba8c64af42@cs.ucla.edu> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------D3833435B6711DEED0D28C9A" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="208663"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 Cc: Eli Zaretskii , Daniel Colascione , emacs-devel@gnu.org To: Pip Cet Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Aug 22 02:25:51 2019 Return-path: Envelope-to: ged-emacs-devel@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 1i0avG-000sAM-RZ for ged-emacs-devel@m.gmane.org; Thu, 22 Aug 2019 02:25:50 +0200 Original-Received: from localhost ([::1]:37334 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0avE-0008IA-UA for ged-emacs-devel@m.gmane.org; Wed, 21 Aug 2019 20:25:48 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55476) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i0av2-0008DN-9R for emacs-devel@gnu.org; Wed, 21 Aug 2019 20:25:37 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i0av0-0006ab-PE for emacs-devel@gnu.org; Wed, 21 Aug 2019 20:25:36 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:35222) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i0auw-0006YF-3N; Wed, 21 Aug 2019 20:25:30 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id B6277160073; Wed, 21 Aug 2019 17:25:28 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id FQ5nRvqLBNwd; Wed, 21 Aug 2019 17:25:27 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 640151626E2; Wed, 21 Aug 2019 17:25:27 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id CMFVIdf0lZ_y; Wed, 21 Aug 2019 17:25:27 -0700 (PDT) Original-Received: from [192.168.1.9] (cpe-23-242-74-103.socal.res.rr.com [23.242.74.103]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 18B51160073; Wed, 21 Aug 2019 17:25:27 -0700 (PDT) In-Reply-To: Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 131.179.128.68 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:239490 Archived-At: This is a multi-part message in MIME format. --------------D3833435B6711DEED0D28C9A Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Pip Cet wrote: > Try reading #s(hash-table data #0=(#0# . #0#)) Thanks for mentioning that. I installed the attached to fix the bug, along with some similar bugs I noticed. Are there more instances of the problem? --------------D3833435B6711DEED0D28C9A Content-Type: text/x-patch; name="0001-Don-t-hard-loop-on-cycles-in-read-etc.patch" Content-Disposition: attachment; filename="0001-Don-t-hard-loop-on-cycles-in-read-etc.patch" Content-Transfer-Encoding: quoted-printable >From 951ea375d52891f79b89794fbb9dca86ab8cd5a8 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 21 Aug 2019 17:18:33 -0700 Subject: [PATCH] =3D?UTF-8?q?Don=3DE2=3D80=3D99t=3D20hard-loop=3D20on=3D2= 0cycles=3D20in=3D20?=3D =3D?UTF-8?q?=3DE2=3D80=3D98read=3DE2=3D80=3D99=3D20etc.?=3D MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit Problem for =E2=80=98read=E2=80=99 reported by Pip Cet in: https://lists.gnu.org/r/emacs-devel/2019-08/msg00316.html * src/fns.c (Frequire): Protect against circular current-load-list. * src/lread.c (Fget_load_suffixes): Protect against circular load-suffixes or load-file-rep-suffixes. (Fload): Protect against circular loads-in-progress. (openp): Protect against circular PATH and SUFFIXES. (build_load_history): Protect against circular load-history or current-load-list. (readevalloop_eager_expand_eval): Protect against circular SUBFORMS. (read1): Protect against circular data. * test/src/lread-tests.el (lread-circular-hash): New test. --- src/fns.c | 9 ++++-- src/lread.c | 68 ++++++++++++++++++++--------------------- test/src/lread-tests.el | 3 ++ 3 files changed, 43 insertions(+), 37 deletions(-) diff --git a/src/fns.c b/src/fns.c index 6c47b3e5b1..b606d6299c 100644 --- a/src/fns.c +++ b/src/fns.c @@ -2950,9 +2950,12 @@ DEFUN ("require", Frequire, Srequire, 1, 3, 0, But not more than once in any file, and not when we aren't loading or reading from a file. */ if (!from_file) - for (tem =3D Vcurrent_load_list; CONSP (tem); tem =3D XCDR (tem)) - if (NILP (XCDR (tem)) && STRINGP (XCAR (tem))) - from_file =3D 1; + { + Lisp_Object tail =3D Vcurrent_load_list; + FOR_EACH_TAIL_SAFE (tail) + if (NILP (XCDR (tail)) && STRINGP (XCAR (tail))) + from_file =3D true; + } =20 if (from_file) { diff --git a/src/lread.c b/src/lread.c index 1bfbf5aa86..e444830c99 100644 --- a/src/lread.c +++ b/src/lread.c @@ -1064,18 +1064,13 @@ DEFUN ("get-load-suffixes", Fget_load_suffixes, S= get_load_suffixes, 0, 0, 0, This uses the variables `load-suffixes' and `load-file-rep-suffixes'. *= /) (void) { - Lisp_Object lst =3D Qnil, suffixes =3D Vload_suffixes, suffix, ext; - while (CONSP (suffixes)) + Lisp_Object lst =3D Qnil, suffixes =3D Vload_suffixes; + FOR_EACH_TAIL (suffixes) { Lisp_Object exts =3D Vload_file_rep_suffixes; - suffix =3D XCAR (suffixes); - suffixes =3D XCDR (suffixes); - while (CONSP (exts)) - { - ext =3D XCAR (exts); - exts =3D XCDR (exts); - lst =3D Fcons (concat2 (suffix, ext), lst); - } + Lisp_Object suffix =3D XCAR (suffixes); + FOR_EACH_TAIL (exts) + lst =3D Fcons (concat2 (suffix, XCAR (exts)), lst); } return Fnreverse (lst); } @@ -1290,8 +1285,8 @@ DEFUN ("load", Fload, Sload, 1, 5, 0, the general case; the second load may do something different. */ { int load_count =3D 0; - Lisp_Object tem; - for (tem =3D Vloads_in_progress; CONSP (tem); tem =3D XCDR (tem)) + Lisp_Object tem =3D Vloads_in_progress; + FOR_EACH_TAIL_SAFE (tem) if (!NILP (Fequal (found, XCAR (tem))) && (++load_count > 3)) signal_error ("Recursive load", Fcons (found, Vloads_in_progress)); record_unwind_protect (record_load_unwind, Vloads_in_progress); @@ -1611,7 +1606,8 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Obje= ct suffixes, =20 CHECK_STRING (str); =20 - for (tail =3D suffixes; CONSP (tail); tail =3D XCDR (tail)) + tail =3D suffixes; + FOR_EACH_TAIL_SAFE (tail) { CHECK_STRING_CAR (tail); max_suffix_len =3D max (max_suffix_len, @@ -1625,12 +1621,17 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Ob= ject suffixes, =20 absolute =3D complete_filename_p (str); =20 + AUTO_LIST1 (just_use_str, Qnil); + if (NILP (path)) + path =3D just_use_str; + /* Go through all entries in the path and see whether we find the executable. */ - do { + FOR_EACH_TAIL_SAFE (path) + { ptrdiff_t baselen, prefixlen; =20 - if (NILP (path)) + if (EQ (path, just_use_str)) filename =3D str; else filename =3D Fexpand_file_name (str, XCAR (path)); @@ -1663,8 +1664,9 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Obje= ct suffixes, memcpy (fn, SDATA (filename) + prefixlen, baselen); =20 /* Loop over suffixes. */ - for (tail =3D NILP (suffixes) ? list1 (empty_unibyte_string) : suffi= xes; - CONSP (tail); tail =3D XCDR (tail)) + AUTO_LIST1 (empty_string_only, empty_unibyte_string); + tail =3D NILP (suffixes) ? empty_string_only : suffixes; + FOR_EACH_TAIL_SAFE (tail) { Lisp_Object suffix =3D XCAR (tail); ptrdiff_t fnlen, lsuffix =3D SBYTES (suffix); @@ -1808,10 +1810,9 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Obj= ect suffixes, } } } - if (absolute || NILP (path)) + if (absolute) break; - path =3D XCDR (path); - } while (CONSP (path)); + } =20 SAFE_FREE (); errno =3D last_errno; @@ -1838,7 +1839,7 @@ build_load_history (Lisp_Object filename, bool enti= re) tail =3D Vload_history; prev =3D Qnil; =20 - while (CONSP (tail)) + FOR_EACH_TAIL (tail) { tem =3D XCAR (tail); =20 @@ -1861,22 +1862,19 @@ build_load_history (Lisp_Object filename, bool en= tire) { tem2 =3D Vcurrent_load_list; =20 - while (CONSP (tem2)) + FOR_EACH_TAIL (tem2) { newelt =3D XCAR (tem2); =20 if (NILP (Fmember (newelt, tem))) Fsetcar (tail, Fcons (XCAR (tem), Fcons (newelt, XCDR (tem)))); - - tem2 =3D XCDR (tem2); maybe_quit (); } } } else prev =3D tail; - tail =3D XCDR (tail); maybe_quit (); } =20 @@ -1918,10 +1916,9 @@ readevalloop_eager_expand_eval (Lisp_Object val, L= isp_Object macroexpand) if (EQ (CAR_SAFE (val), Qprogn)) { Lisp_Object subforms =3D XCDR (val); - - for (val =3D Qnil; CONSP (subforms); subforms =3D XCDR (subforms)) - val =3D readevalloop_eager_expand_eval (XCAR (subforms), - macroexpand); + val =3D Qnil; + FOR_EACH_TAIL (subforms) + val =3D readevalloop_eager_expand_eval (XCAR (subforms), macroexpand); } else val =3D eval_sub (call2 (macroexpand, val, Qt)); @@ -2861,16 +2858,19 @@ read1 (Lisp_Object readcharfun, int *pch, bool fi= rst_in_list) /* Now use params to make a new hash table and fill it. */ ht =3D Fmake_hash_table (param_count, params); =20 - while (CONSP (data)) - { + Lisp_Object last =3D data; + FOR_EACH_TAIL_SAFE (data) + { key =3D XCAR (data); data =3D XCDR (data); if (!CONSP (data)) - error ("Odd number of elements in hash table data"); + break; val =3D XCAR (data); - data =3D XCDR (data); + last =3D XCDR (data); Fputhash (key, val, ht); - } + } + if (!NILP (last)) + error ("Hash table data is not a list of even length"); =20 return ht; } diff --git a/test/src/lread-tests.el b/test/src/lread-tests.el index 82b75b195c..ba5bfe0145 100644 --- a/test/src/lread-tests.el +++ b/test/src/lread-tests.el @@ -220,4 +220,7 @@ lread-string-to-number-trailing-dot (* most-positive-fixnum most-positive-fixnum))) (should (=3D n (string-to-number (format "%d." n)))))) =20 +(ert-deftest lread-circular-hash () + (should-error (read "#s(hash-table data #0=3D(#0# . #0#))"))) + ;;; lread-tests.el ends here --=20 2.17.1 --------------D3833435B6711DEED0D28C9A--