From: Pip Cet via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: "Gerd Möllmann" <gerd.moellmann@gmail.com>
Cc: 74547@debbugs.gnu.org, "Óscar Fuentes" <oscarfv@telefonica.net>,
geza.herman@gmail.com
Subject: bug#74547: 31.0.50; igc: assertion failed in buffer.c
Date: Sun, 01 Dec 2024 12:57:04 +0000 [thread overview]
Message-ID: <871pyrmui4.fsf@protonmail.com> (raw)
In-Reply-To: <m2ldwzvaqa.fsf@gmail.com>
Gerd Möllmann <gerd.moellmann@gmail.com> writes:
> Pip Cet <pipcet@protonmail.com> writes:
> Yes, exactly, json.c. First thing I saw when searching for xfree
>
> static void
> json_parser_done (void *parser)
> {
> struct json_parser *p = (struct json_parser *) parser;
> if (p->object_workspace != p->internal_object_workspace)
> xfree (p->object_workspace);
>
> That at least needs an explanation. I would have expected it to be
> allocated as root.
Well, the explanation is this comment:
/* Lisp_Objects are collected in this area during object/array
parsing. To avoid allocations, initially
internal_object_workspace is used. If it runs out of space then
we switch to allocated space. Important note: with this design,
GC must not run during JSON parsing, otherwise Lisp_Objects in
the workspace may get incorrectly collected. */
Obviously, we cannot make any such guarantees when MPS is in use. (I
don't think we can make the guarantee when MPS is not in use, but I'm
not totally certain; we certainly allocate strings while parsing JSON,
which is sufficient to trigger GC in the MPS case).
Note that the json_parser object itself is fine (it's allocated on the
stack, thus marked ambiguously), it's only in the case that we create
more than 64 Lisp_Object values when parsing a single JSON document that
we end up with untraced references on the heap.
I don't know whether it's likely that that was what happened to Oscar.
My gut feeling is 64 objects would be easily reached by LSP messages,
but I'd need more time to test.
Anyway, here's a patch which might help:
commit c175744f2172ba3405ae98eb3575b2bf4adadfa4
Author: Pip Cet <pipcet@protonmail.com>
Date: Sun Dec 1 12:46:08 2024 +0000
Ensure JSON parser allocations are traced (bug#74547)
* src/json.c (json_parser_done):
(json_make_object_workspace_for_slow_path): Use IGC-aware allocations.
diff --git a/src/json.c b/src/json.c
index eb446f5c221..900fbcbb41a 100644
--- a/src/json.c
+++ b/src/json.c
@@ -807,7 +807,11 @@ json_parser_done (void *parser)
{
struct json_parser *p = (struct json_parser *) parser;
if (p->object_workspace != p->internal_object_workspace)
+#ifdef HAVE_MPS
+ igc_xfree (p->object_workspace);
+#else
xfree (p->object_workspace);
+#endif
if (p->byte_workspace != p->internal_byte_workspace)
xfree (p->byte_workspace);
}
@@ -833,17 +837,31 @@ json_make_object_workspace_for_slow_path (struct json_parser *parser,
if (parser->object_workspace_size
== JSON_PARSER_INTERNAL_OBJECT_WORKSPACE_SIZE)
{
+#ifndef HAVE_MPS
new_workspace_ptr
= xnmalloc (new_workspace_size, sizeof (Lisp_Object));
+#else
+ new_workspace_ptr
+ = igc_xalloc_lisp_objs_exact (new_workspace_size);
+#endif
memcpy (new_workspace_ptr, parser->object_workspace,
(sizeof (Lisp_Object)
* parser->object_workspace_current));
}
else
{
+#ifndef HAVE_MPS
new_workspace_ptr
= xnrealloc (parser->object_workspace, new_workspace_size,
sizeof (Lisp_Object));
+#else
+ new_workspace_ptr
+ = igc_xalloc_lisp_objs_exact (new_workspace_size);
+ memcpy (new_workspace_ptr, parser->object_workspace,
+ (sizeof (Lisp_Object)
+ * parser->object_workspace_current));
+ igc_xfree (parser->object_workspace);
+#endif
}
parser->object_workspace = new_workspace_ptr;
next prev parent reply other threads:[~2024-12-01 12:57 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-26 18:35 bug#74547: 31.0.50; igc: assertion failed in buffer.c Óscar Fuentes
2024-11-27 6:54 ` Gerd Möllmann
2024-12-01 10:49 ` Pip Cet via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-01 12:05 ` Gerd Möllmann
2024-12-01 12:17 ` Gerd Möllmann
2024-12-01 12:30 ` Pip Cet via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-01 12:39 ` Gerd Möllmann
2024-12-01 12:57 ` Pip Cet via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-12-01 13:30 ` Gerd Möllmann
2024-12-01 14:58 ` Pip Cet via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-01 15:18 ` Gerd Möllmann
2024-12-01 15:48 ` Pip Cet via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-01 16:32 ` Geza Herman
2024-12-01 19:41 ` Gerd Möllmann
2024-12-01 21:15 ` Pip Cet via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-04 19:11 ` Geza Herman
2024-12-01 15:55 ` Eli Zaretskii
2024-12-01 15:23 ` Eli Zaretskii
2024-12-01 15:30 ` Óscar Fuentes
2024-12-01 15:48 ` Gerd Möllmann
2024-12-01 15:58 ` Pip Cet via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-01 16:24 ` Óscar Fuentes
2024-12-01 13:18 ` Óscar Fuentes
2024-12-01 13:44 ` Gerd Möllmann
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=871pyrmui4.fsf@protonmail.com \
--to=bug-gnu-emacs@gnu.org \
--cc=74547@debbugs.gnu.org \
--cc=gerd.moellmann@gmail.com \
--cc=geza.herman@gmail.com \
--cc=oscarfv@telefonica.net \
--cc=pipcet@protonmail.com \
/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).