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.bugs Subject: bug#38912: 27.0.60; PDumper meets segmentation fault when evil is loaded Date: Tue, 7 Jan 2020 11:32:58 -0800 Organization: UCLA Computer Science Department Message-ID: <4b0e8ed0-87c4-f0b3-f610-080e3be3b3db__26671.9209308334$1578425665$gmane$org@cs.ucla.edu> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------15BD182135ABD8D2D136F3F2" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="259426"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.1 Cc: niwtrx@icloud.com, 38912@debbugs.gnu.org, Pip Cet , emacs-devel@gnu.org To: Stefan Monnier , dancol@dancol.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jan 07 20:34:19 2020 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 1ioucJ-0011nW-Uk for geb-bug-gnu-emacs@m.gmane.org; Tue, 07 Jan 2020 20:34:16 +0100 Original-Received: from localhost ([::1]:55380 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ioucI-0004tT-Fs for geb-bug-gnu-emacs@m.gmane.org; Tue, 07 Jan 2020 14:34:14 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38887) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iouc9-0004qm-3A for bug-gnu-emacs@gnu.org; Tue, 07 Jan 2020 14:34:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iouc6-000715-OD for bug-gnu-emacs@gnu.org; Tue, 07 Jan 2020 14:34:05 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:43416) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iouc6-00070x-Jx for bug-gnu-emacs@gnu.org; Tue, 07 Jan 2020 14:34:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iouc6-0003Ox-Gm for bug-gnu-emacs@gnu.org; Tue, 07 Jan 2020 14:34:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 07 Jan 2020 19:34:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 38912 X-GNU-PR-Package: emacs Original-Received: via spool by 38912-submit@debbugs.gnu.org id=B38912.157842559213014 (code B ref 38912); Tue, 07 Jan 2020 19:34:02 +0000 Original-Received: (at 38912) by debbugs.gnu.org; 7 Jan 2020 19:33:12 +0000 Original-Received: from localhost ([127.0.0.1]:49389 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ioubH-0003Np-SM for submit@debbugs.gnu.org; Tue, 07 Jan 2020 14:33:12 -0500 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:35640) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ioubF-0003Nb-CE for 38912@debbugs.gnu.org; Tue, 07 Jan 2020 14:33:10 -0500 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id C0076160063; Tue, 7 Jan 2020 11:33:03 -0800 (PST) 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 TxD7haS5Wzl6; Tue, 7 Jan 2020 11:33:02 -0800 (PST) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 08AD5160085; Tue, 7 Jan 2020 11:33:02 -0800 (PST) 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 hm4_vfemddkJ; Tue, 7 Jan 2020 11:33:01 -0800 (PST) Original-Received: from Penguin.CS.UCLA.EDU (Penguin.CS.UCLA.EDU [131.179.64.200]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id D77D7160063; Tue, 7 Jan 2020 11:33:01 -0800 (PST) In-Reply-To: Content-Language: en-US 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:174345 Archived-At: This is a multi-part message in MIME format. --------------15BD182135ABD8D2D136F3F2 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 1/7/20 6:16 AM, Stefan Monnier wrote: > I'd be in > favor of introducing this backward incompatibility in Emacs-28, unless > we can find a good use case where the structural-equality is needed > for them. I looked for use cases within Emacs, and found only one: a test case that I changed to use compare-window-configurations instead. I don't think this was a good use case; it's just a hack in a test. I agree with Martin that comparing window configurations is something of a botch. Despite some documentation to the contrary, neither 'equal' nor compare-window-configurations compares all components of window configurations (though the two functions do compare different sets of components). If there's a solid need for comparing different sets of components of window configurations (and I doubt whether the test case establishes a need), it could be implemented by adding an argument to compare-window-configurations to say how to do the comparison. However, there doesn't seem to be a significant need to make all this part of 'equal'. So, after writing some sxhash-equal test cases and then fixing Emacs to handle these test cases properly, I boldly installed the attached patch into master. This should make sxhash-equal compatible with 'equal'. Comments welcome as usual. --------------15BD182135ABD8D2D136F3F2 Content-Type: text/x-patch; charset=UTF-8; name="0001-Fix-sxhash-equal-on-bytecodes-markers-etc.patch" Content-Disposition: attachment; filename="0001-Fix-sxhash-equal-on-bytecodes-markers-etc.patch" Content-Transfer-Encoding: quoted-printable >From 724af7671590cd91df37f64df6be73f6dca0144d Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 7 Jan 2020 11:23:11 -0800 Subject: [PATCH] Fix sxhash-equal on bytecodes, markers, etc. MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit Problem reported by Pip Cet (Bug#38912#14). * doc/lispref/objects.texi (Equality Predicates): Document better when =E2=80=98equal=E2=80=99 looks inside objects. * doc/lispref/windows.texi (Window Configurations): Don=E2=80=99t say that =E2=80=98equal=E2=80=99 looks inside window config= urations. * etc/NEWS: Mention the change. * src/fns.c (internal_equal): Do not look inside window configurations. (sxhash_obj): Hash markers, byte-code function objects, char-tables, and font objects consistently with Fequal. * src/window.c (compare_window_configurations): Now static. Remove last argument. Caller changed. * test/lisp/ffap-tests.el (ffap-other-window--bug-25352): Use compare-window-configurations, not =E2=80=98equal=E2=80=99. * test/src/fns-tests.el (test-sxhash-equal): New test. --- doc/lispref/objects.texi | 8 +++++-- doc/lispref/windows.texi | 4 ---- etc/NEWS | 6 +++++ src/fns.c | 52 ++++++++++++++++++++++++---------------- src/lisp.h | 4 ++-- src/window.c | 21 ++++------------ src/window.h | 1 - test/lisp/ffap-tests.el | 2 +- test/src/fns-tests.el | 16 +++++++++++++ 9 files changed, 67 insertions(+), 47 deletions(-) diff --git a/doc/lispref/objects.texi b/doc/lispref/objects.texi index 4be2eb6918..4242223a48 100644 --- a/doc/lispref/objects.texi +++ b/doc/lispref/objects.texi @@ -2336,8 +2336,12 @@ Equality Predicates @end group @end example =20 -However, two distinct buffers are never considered @code{equal}, even if -their textual contents are the same. +The @code{equal} function recursively compares the contents of objects +if they are integers, strings, markers, vectors, bool-vectors, +byte-code function objects, char-tables, records, or font objects. +Other objects are considered @code{equal} only if they are @code{eq}. +For example, two distinct buffers are never considered @code{equal}, +even if their textual contents are the same. @end defun =20 For @code{equal}, equality is defined recursively; for example, given diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index c9301c9d18..d0791d4019 100644 --- a/doc/lispref/windows.texi +++ b/doc/lispref/windows.texi @@ -5915,10 +5915,6 @@ Window Configurations structure of windows, but ignores the values of point and the saved scrolling positions---it can return @code{t} even if those aspects differ. - -The function @code{equal} can also compare two window configurations; it -regards configurations as unequal if they differ in any respect, even a -saved point. @end defun =20 @defun window-configuration-frame config diff --git a/etc/NEWS b/etc/NEWS index d6cabf8e9e..0784160ce2 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -42,6 +42,12 @@ applies, and please also update docstrings as needed. =0C * Incompatible Lisp Changes in Emacs 28.1 =20 +** 'equal' no longer examines some contents of window configurations. +Instead, it considers window configurations to be equal only if they +are eq. To compare contents, use compare-window-configurations +instead. This change helps fix a bug in sxhash-equal, which returned +incorrect hashes for window configurations and some other objects. + =0C * Lisp Changes in Emacs 28.1 =20 diff --git a/src/fns.c b/src/fns.c index 4a0a8fd96d..4a463a8feb 100644 --- a/src/fns.c +++ b/src/fns.c @@ -2434,6 +2434,9 @@ internal_equal (Lisp_Object o1, Lisp_Object o2, enu= m equal_kind equal_kind, same size. */ if (ASIZE (o2) !=3D size) return false; + + /* Compare bignums, overlays, markers, and boolvectors + specially, by comparing their values. */ if (BIGNUMP (o1)) return mpz_cmp (*xbignum_val (o1), *xbignum_val (o2)) =3D=3D 0; if (OVERLAYP (o1)) @@ -2454,7 +2457,6 @@ internal_equal (Lisp_Object o1, Lisp_Object o2, enu= m equal_kind equal_kind, && (XMARKER (o1)->buffer =3D=3D 0 || XMARKER (o1)->bytepos =3D=3D XMARKER (o2)->bytepos)); } - /* Boolvectors are compared much like strings. */ if (BOOL_VECTOR_P (o1)) { EMACS_INT size =3D bool_vector_size (o1); @@ -2465,11 +2467,6 @@ internal_equal (Lisp_Object o1, Lisp_Object o2, en= um equal_kind equal_kind, return false; return true; } - if (WINDOW_CONFIGURATIONP (o1)) - { - eassert (equal_kind !=3D EQUAL_NO_QUIT); - return compare_window_configurations (o1, o2, false); - } =20 /* Aside from them, only true vectors, char-tables, compiled functions, and fonts (font-spec, font-entity, font-object) @@ -4703,22 +4700,35 @@ sxhash_obj (Lisp_Object obj, int depth) hash =3D sxhash_string (SSDATA (obj), SBYTES (obj)); break; =20 - /* This can be everything from a vector to an overlay. */ case Lisp_Vectorlike: - if (BIGNUMP (obj)) - hash =3D sxhash_bignum (obj); - else if (VECTORP (obj) || RECORDP (obj)) - /* According to the CL HyperSpec, two arrays are equal only if - they are `eq', except for strings and bit-vectors. In - Emacs, this works differently. We have to compare element - by element. Same for records. */ - hash =3D sxhash_vector (obj, depth); - else if (BOOL_VECTOR_P (obj)) - hash =3D sxhash_bool_vector (obj); - else - /* Others are `equal' if they are `eq', so let's take their - address as hash. */ - hash =3D XHASH (obj); + { + enum pvec_type pvec_type =3D PSEUDOVECTOR_TYPE (XVECTOR (obj)); + if (! (PVEC_NORMAL_VECTOR < pvec_type && pvec_type < PVEC_COMPILED)) + { + /* According to the CL HyperSpec, two arrays are equal only if + they are 'eq', except for strings and bit-vectors. In + Emacs, this works differently. We have to compare element + by element. Same for pseudovectors that internal_equal + examines the Lisp contents of. */ + hash =3D sxhash_vector (obj, depth); + break; + } + else if (pvec_type =3D=3D PVEC_BIGNUM) + hash =3D sxhash_bignum (obj); + else if (pvec_type =3D=3D PVEC_MARKER) + { + ptrdiff_t bytepos + =3D XMARKER (obj)->buffer ? XMARKER (obj)->bytepos : 0; + hash =3D sxhash_combine ((intptr_t) XMARKER (obj)->buffer, bytepos)= ; + hash =3D SXHASH_REDUCE (hash); + } + else if (pvec_type =3D=3D PVEC_BOOL_VECTOR) + hash =3D sxhash_bool_vector (obj); + else + /* Others are 'equal' if they are 'eq', so take their + address as hash. */ + hash =3D XHASH (obj); + } break; =20 case Lisp_Cons: diff --git a/src/lisp.h b/src/lisp.h index 1a1ae0399b..3681b7b2a7 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -1069,7 +1069,7 @@ DEFINE_GDB_SYMBOL_END (PSEUDOVECTOR_FLAG) with PVEC_TYPE_MASK to indicate the actual type. */ enum pvec_type { - PVEC_NORMAL_VECTOR, + PVEC_NORMAL_VECTOR, /* Should be first, for sxhash_obj. */ PVEC_FREE, PVEC_BIGNUM, PVEC_MARKER, @@ -1094,7 +1094,7 @@ DEFINE_GDB_SYMBOL_END (PSEUDOVECTOR_FLAG) PVEC_CONDVAR, PVEC_MODULE_FUNCTION, =20 - /* These should be last, check internal_equal to see why. */ + /* These should be last, for internal_equal and sxhash_obj. */ PVEC_COMPILED, PVEC_CHAR_TABLE, PVEC_SUB_CHAR_TABLE, diff --git a/src/window.c b/src/window.c index ff17cd88f3..8cdad27b66 100644 --- a/src/window.c +++ b/src/window.c @@ -7976,19 +7976,17 @@ foreach_window_1 (struct window *w, bool (*fn) (s= truct window *, void *), /* Return true if window configurations CONFIGURATION1 and CONFIGURATION= 2 describe the same state of affairs. This is used by Fequal. =20 - IGNORE_POSITIONS means ignore non-matching scroll positions - and the like. + Ignore non-matching scroll positions and the like. =20 This ignores a couple of things like the dedication status of window, combination_limit and the like. This might have to be fixed. */ =20 -bool +static bool compare_window_configurations (Lisp_Object configuration1, - Lisp_Object configuration2, - bool ignore_positions) + Lisp_Object configuration2) { - register struct save_window_data *d1, *d2; + struct save_window_data *d1, *d2; struct Lisp_Vector *sws1, *sws2; ptrdiff_t i; =20 @@ -8006,9 +8004,6 @@ compare_window_configurations (Lisp_Object configur= ation1, || d1->frame_menu_bar_lines !=3D d2->frame_menu_bar_lines || !EQ (d1->selected_frame, d2->selected_frame) || !EQ (d1->f_current_buffer, d2->f_current_buffer) - || (!ignore_positions - && (!EQ (d1->minibuf_scroll_window, d2->minibuf_scroll_window) - || !EQ (d1->minibuf_selected_window, d2->minibuf_selected_window)= )) || !EQ (d1->focus_frame, d2->focus_frame) /* Verify that the two configurations have the same number of wind= ows. */ || sws1->header.size !=3D sws2->header.size) @@ -8041,12 +8036,6 @@ compare_window_configurations (Lisp_Object configu= ration1, equality. */ || !EQ (sw1->parent, sw2->parent) || !EQ (sw1->prev, sw2->prev) - || (!ignore_positions - && (!EQ (sw1->hscroll, sw2->hscroll) - || !EQ (sw1->min_hscroll, sw2->min_hscroll) - || !EQ (sw1->start_at_line_beg, sw2->start_at_line_beg) - || NILP (Fequal (sw1->start, sw2->start)) - || NILP (Fequal (sw1->pointm, sw2->pointm)))) || !EQ (sw1->left_margin_cols, sw2->left_margin_cols) || !EQ (sw1->right_margin_cols, sw2->right_margin_cols) || !EQ (sw1->left_fringe_width, sw2->left_fringe_width) @@ -8071,7 +8060,7 @@ DEFUN ("compare-window-configurations", Fcompare_wi= ndow_configurations, and scrolling positions. */) (Lisp_Object x, Lisp_Object y) { - if (compare_window_configurations (x, y, true)) + if (compare_window_configurations (x, y)) return Qt; return Qnil; } diff --git a/src/window.h b/src/window.h index aa8d2c8d1d..167d1be7ab 100644 --- a/src/window.h +++ b/src/window.h @@ -1184,7 +1184,6 @@ #define CHECK_LIVE_WINDOW(WINDOW) \ extern Lisp_Object window_parameter (struct window *, Lisp_Object parame= ter); extern struct window *decode_live_window (Lisp_Object); extern struct window *decode_any_window (Lisp_Object); -extern bool compare_window_configurations (Lisp_Object, Lisp_Object, boo= l); extern void mark_window_cursors_off (struct window *); extern bool window_wants_mode_line (struct window *); extern bool window_wants_header_line (struct window *); diff --git a/test/lisp/ffap-tests.el b/test/lisp/ffap-tests.el index eaf39680e4..30c8f79457 100644 --- a/test/lisp/ffap-tests.el +++ b/test/lisp/ffap-tests.el @@ -74,7 +74,7 @@ ffap-other-window--bug-25352 (urls nil) (ffap-url-fetcher (lambda (url) (push url urls) nil))) (should-not (ffap-other-window "https://www.gnu.org")) - (should (equal (current-window-configuration) old)) + (should (compare-window-configurations (current-window-configuration= ) old)) (should (equal urls '("https://www.gnu.org"))))) =20 (provide 'ffap-tests) diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el index 60be2c6c2d..c6ceae4a00 100644 --- a/test/src/fns-tests.el +++ b/test/src/fns-tests.el @@ -858,6 +858,22 @@ test-hash-function-that-mutates-hash-table (puthash k k h))) (should (=3D 100 (hash-table-count h))))) =20 +(ert-deftest test-sxhash-equal () + (should (=3D (sxhash-equal (* most-positive-fixnum most-negative-fixnu= m)) + (sxhash-equal (* most-positive-fixnum most-negative-fixnum)))) + (should (=3D (sxhash-equal (make-string 1000 ?a)) + (sxhash-equal (make-string 1000 ?a)))) + (should (=3D (sxhash-equal (point-marker)) + (sxhash-equal (point-marker)))) + (should (=3D (sxhash-equal (make-vector 1000 (make-string 10 ?a))) + (sxhash-equal (make-vector 1000 (make-string 10 ?a))))) + (should (=3D (sxhash-equal (make-bool-vector 1000 t)) + (sxhash-equal (make-bool-vector 1000 t)))) + (should (=3D (sxhash-equal (make-char-table nil (make-string 10 ?a))) + (sxhash-equal (make-char-table nil (make-string 10 ?a))))) + (should (=3D (sxhash-equal (record 'a (make-string 10 ?a))) + (sxhash-equal (record 'a (make-string 10 ?a)))))) + (ert-deftest test-secure-hash () (should (equal (secure-hash 'md5 "foobar") "3858f62230ac3c915f300c664312c63f")) --=20 2.24.1 --------------15BD182135ABD8D2D136F3F2--