From: Ethan Kong <ek.ethan.kong@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 73883@debbugs.gnu.org
Subject: bug#73883: [PATCH] Fix 'equal' freezing on large cyclic objects
Date: Sat, 9 Nov 2024 11:36:56 +0800 [thread overview]
Message-ID: <84de8b8c-eecf-4c56-8c82-5b0236130efb@gmail.com> (raw)
In-Reply-To: <jwviksxr237.fsf-monnier+emacs@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 210 bytes --]
On 24/11/09 02:57, Stefan Monnier wrote:
> While the new title is arguably better for a bug report, the old one was
> better at describing your patch. 🙂
I see. Here is the patch with the old summary line.
[-- Attachment #2: 0001-Fix-internal_equal-so-that-it-uses-at-most-one-hash-.patch --]
[-- Type: text/plain, Size: 2830 bytes --]
From 425270179bb22630b7ad5871fcfcee84737b55fb Mon Sep 17 00:00:00 2001
From: Ethan Kong <ek.ethan.kong@gmail.com>
Date: Sat, 19 Oct 2024 12:43:27 +0800
Subject: [PATCH] Fix internal_equal so that it uses at most one hash table
* src/fns.c (internal_equal): Delegate to internal_equal_1.
(internal_equal_1): New function. Pass the hash table argument by
pointer instead of by value.
---
src/fns.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/src/fns.c b/src/fns.c
index 2de04d06519..ef6922c137b 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -2823,8 +2823,8 @@ equal_no_quit (Lisp_Object o1, Lisp_Object o2)
if EQUAL_KIND == EQUAL_NO_QUIT. */
static bool
-internal_equal (Lisp_Object o1, Lisp_Object o2, enum equal_kind equal_kind,
- int depth, Lisp_Object ht)
+internal_equal_1 (Lisp_Object o1, Lisp_Object o2, enum equal_kind equal_kind,
+ int depth, Lisp_Object *ht)
{
tail_recurse:
if (depth > 10)
@@ -2832,13 +2832,13 @@ internal_equal (Lisp_Object o1, Lisp_Object o2, enum equal_kind equal_kind,
eassert (equal_kind != EQUAL_NO_QUIT);
if (depth > 200)
error ("Stack overflow in equal");
- if (NILP (ht))
- ht = CALLN (Fmake_hash_table, QCtest, Qeq);
+ if (NILP (*ht))
+ *ht = CALLN (Fmake_hash_table, QCtest, Qeq);
switch (XTYPE (o1))
{
case Lisp_Cons: case Lisp_Vectorlike:
{
- struct Lisp_Hash_Table *h = XHASH_TABLE (ht);
+ struct Lisp_Hash_Table *h = XHASH_TABLE (*ht);
hash_hash_t hash = hash_from_key (h, o1);
ptrdiff_t i = hash_lookup_with_hash (h, o1, hash);
if (i >= 0)
@@ -2888,8 +2888,8 @@ internal_equal (Lisp_Object o1, Lisp_Object o2, enum equal_kind equal_kind,
{
if (! CONSP (o2))
return false;
- if (! internal_equal (XCAR (o1), XCAR (o2),
- equal_kind, depth + 1, ht))
+ if (! internal_equal_1 (XCAR (o1), XCAR (o2),
+ equal_kind, depth + 1, ht))
return false;
o2 = XCDR (o2);
if (EQ (XCDR (o1), o2))
@@ -2964,7 +2964,7 @@ internal_equal (Lisp_Object o1, Lisp_Object o2, enum equal_kind equal_kind,
Lisp_Object v1, v2;
v1 = AREF (o1, i);
v2 = AREF (o2, i);
- if (!internal_equal (v1, v2, equal_kind, depth + 1, ht))
+ if (!internal_equal_1 (v1, v2, equal_kind, depth + 1, ht))
return false;
}
return true;
@@ -2985,6 +2985,13 @@ internal_equal (Lisp_Object o1, Lisp_Object o2, enum equal_kind equal_kind,
return false;
}
+static bool
+internal_equal (Lisp_Object o1, Lisp_Object o2, enum equal_kind equal_kind,
+ int depth, Lisp_Object ht)
+{
+ return internal_equal_1 (o1, o2, equal_kind, depth, &ht);
+}
+
/* Return -1/0/1 for the </=/> lexicographic relation between bool-vectors. */
static int
bool_vector_cmp (Lisp_Object a, Lisp_Object b)
--
2.43.0.windows.1
next prev parent reply other threads:[~2024-11-09 3:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-19 10:53 bug#73883: [PATCH] Fix internal_equal so that it uses at most one hash table Ethan Kong
2024-10-20 11:47 ` bug#73883: [PATCH] Fix 'equal' freezing on large cyclic objects Ethan Kong
2024-11-02 11:41 ` Eli Zaretskii
2024-11-08 13:37 ` Ethan Kong
2024-11-08 18:57 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-09 3:36 ` Ethan Kong [this message]
2024-11-09 9:01 ` Eli Zaretskii
2024-10-20 11:55 ` bug#73883: [PATCH] Fix internal_equal so that it uses at most one hash table Stefan Kangas
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=84de8b8c-eecf-4c56-8c82-5b0236130efb@gmail.com \
--to=ek.ethan.kong@gmail.com \
--cc=73883@debbugs.gnu.org \
--cc=monnier@iro.umontreal.ca \
/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).