all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Pip Cet <pipcet@protonmail.com>
To: "Gerd Möllmann" <gerd.moellmann@gmail.com>
Cc: Eli Zaretskii <eliz@gnu.org>,
	Ihor Radchenko <yantar92@posteo.net>,
	emacs-devel@gnu.org, eller.helmut@gmail.com
Subject: Re: MPS: Crash when switching to buffer
Date: Tue, 02 Jul 2024 00:22:03 +0000	[thread overview]
Message-ID: <cmbRWfutWovlqG2IR9J5QkzlmGkb1ajJ2y4wlZG75Xn8jQS4MPo86luKQNGFbjthaqj-mjXiiAELGcV4ppjGIvQTBoUGW_HFT4oXfse10aA=@protonmail.com> (raw)
In-Reply-To: <m28qylcgx1.fsf@pro2.fritz.box>

[-- Attachment #1: Type: text/plain, Size: 2845 bytes --]

On Monday, July 1st, 2024 at 14:42, Gerd Möllmann <gerd.moellmann@gmail.com> wrote:
> > At first glance, the lface_id_to_name "vector" (just a pointer to
> > Lisp_Object, not a Lisp_Vector) isn't allocated using igc methods, so
> > references in it might not be traced. Is that possible, Gerd? I
> > confess I'm not totally sure how xmalloc and friends get translated in
> > the MPS build...
> 
> That's very possible, and a bug :-). Good catch!
> 
> If xmalloc/xfree and friends are used to alloc memory that contains
> references, we have replaced them with oen of these
> 
> void *igc_xzalloc_ambig (size_t size);
> void *igc_realloc_ambig (void *block, size_t size);
> void igc_xfree (void *p);
> Lisp_Object *igc_xalloc_lisp_objs_exact (size_t n);
> 
> void *igc_xpalloc_ambig (void *pa, ptrdiff_t *nitems,
> ptrdiff_t nitems_incr_min, ptrdiff_t nitems_max,
> ptrdiff_t item_size);
> void igc_xpalloc_exact (void **pa_cell, ptrdiff_t *nitems,
> ptrdiff_t nitems_incr_min, ptrdiff_t nitems_max,
> ptrdiff_t item_size, igc_scan_area_t scan);
> 
> void *igc_xnrealloc_ambig (void *pa, ptrdiff_t nitems, ptrdiff_t item_size);
> 
> Hope I got them all. All of them create roots, the ambig variants
> ambiguous roots, the exact variants exact roots. igc_xfree must be used
> instead of xfree so that the roots get destroyed when the memory is freed.

Thanks, that helps clarify things. So would something like the following work? lface_id_to_name is never freed, it seems...

Ihor, I'm not sure whether the bug is fully reproducible. If it is, could you please try this?

diff --git a/src/xfaces.c b/src/xfaces.c
index 2bdd2f660fd..ee26a260ed4 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -2970,9 +2970,15 @@ DEFUN ("internal-make-lisp-face", Finternal_make_lisp_face,
 	 The mapping from Lisp face to Lisp face id is given by the
 	 property `face' of the Lisp face name.  */
       if (next_lface_id == lface_id_to_name_size)
+#ifdef HAVE_MPS
+	lface_id_to_name =
+	  igc_xpalloc_ambig (lface_id_to_name, &lface_id_to_name_size, 1, MAX_FACE_ID,
+			     sizeof *lface_id_to_name);
+#else
 	lface_id_to_name =
 	  xpalloc (lface_id_to_name, &lface_id_to_name_size, 1, MAX_FACE_ID,
 		   sizeof *lface_id_to_name);
+#endif
 
       Lisp_Object face_id = make_fixnum (next_lface_id);
       lface_id_to_name[next_lface_id] = face;
@@ -7326,7 +7332,11 @@ init_xfaces (void)
 	{
 	  /* Allocate the lface_id_to_name[] array.  */
 	  lface_id_to_name_size = next_lface_id = nfaces;
+#ifdef HAVE_MPS
+	  lface_id_to_name = igc_xzalloc_ambig (next_lface_id * sizeof *lface_id_to_name);
+#else
 	  lface_id_to_name = xnmalloc (next_lface_id, sizeof *lface_id_to_name);
+#endif
 
 	  /* Store the faces.  */
 	  struct Lisp_Hash_Table* table = XHASH_TABLE (Vface_new_frame_defaults);

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-try-to-fix-face-related-crashes.patch --]
[-- Type: text/x-patch; name=0002-try-to-fix-face-related-crashes.patch, Size: 1488 bytes --]

From 7debd69b331f2068c7d0d6975263b2f8ea089fe4 Mon Sep 17 00:00:00 2001
From: Pip Cet <pipcet@protonmail.com>
Date: Tue, 2 Jul 2024 00:18:58 +0000
Subject: [PATCH 2/2] try to fix face-related crashes

---
 src/xfaces.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/xfaces.c b/src/xfaces.c
index 2bdd2f660fd..ee26a260ed4 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -2970,9 +2970,15 @@ DEFUN ("internal-make-lisp-face", Finternal_make_lisp_face,
 	 The mapping from Lisp face to Lisp face id is given by the
 	 property `face' of the Lisp face name.  */
       if (next_lface_id == lface_id_to_name_size)
+#ifdef HAVE_MPS
+	lface_id_to_name =
+	  igc_xpalloc_ambig (lface_id_to_name, &lface_id_to_name_size, 1, MAX_FACE_ID,
+			     sizeof *lface_id_to_name);
+#else
 	lface_id_to_name =
 	  xpalloc (lface_id_to_name, &lface_id_to_name_size, 1, MAX_FACE_ID,
 		   sizeof *lface_id_to_name);
+#endif
 
       Lisp_Object face_id = make_fixnum (next_lface_id);
       lface_id_to_name[next_lface_id] = face;
@@ -7326,7 +7332,11 @@ init_xfaces (void)
 	{
 	  /* Allocate the lface_id_to_name[] array.  */
 	  lface_id_to_name_size = next_lface_id = nfaces;
+#ifdef HAVE_MPS
+	  lface_id_to_name = igc_xzalloc_ambig (next_lface_id * sizeof *lface_id_to_name);
+#else
 	  lface_id_to_name = xnmalloc (next_lface_id, sizeof *lface_id_to_name);
+#endif
 
 	  /* Store the faces.  */
 	  struct Lisp_Hash_Table* table = XHASH_TABLE (Vface_new_frame_defaults);
-- 
2.45.2


  reply	other threads:[~2024-07-02  0:22 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-01  9:26 MPS: Crash when switching to buffer Ihor Radchenko
2024-07-01 12:04 ` Eli Zaretskii
2024-07-01 12:13   ` Ihor Radchenko
2024-07-01 12:46     ` Eli Zaretskii
2024-07-01 14:14   ` Pip Cet
2024-07-01 14:42     ` Gerd Möllmann
2024-07-02  0:22       ` Pip Cet [this message]
2024-07-02  4:04         ` Gerd Möllmann
2024-07-02 11:40         ` Ihor Radchenko
2024-07-04 10:31           ` Ihor Radchenko
2024-07-04 11:48             ` Gerd Möllmann
2024-07-04 12:02               ` MPS: User GC customizations (was: MPS: Crash when switching to buffer) Ihor Radchenko
2024-07-04 12:51                 ` MPS: User GC customizations Gerd Möllmann
2024-07-04 13:20                   ` Ihor Radchenko
2024-07-04 14:45                     ` Gerd Möllmann
2024-07-04 15:12                       ` Pip Cet
2024-07-04 16:07                         ` Gerd Möllmann
2024-07-04 16:38                           ` Ihor Radchenko
2024-07-04 17:02                             ` Gerd Möllmann
2024-07-04 17:53                           ` Eli Zaretskii
2024-07-04 18:18                             ` Gerd Möllmann
2024-07-04 18:28                               ` Ihor Radchenko
2024-07-04 18:32                                 ` Pip Cet
2024-07-04 18:43                                   ` Gerd Möllmann
2024-07-04 18:39                               ` Eli Zaretskii
2024-07-04 18:48                                 ` Ihor Radchenko
2024-07-04 13:58                   ` Eli Zaretskii
2024-07-04 14:30                     ` Gerd Möllmann
2024-07-04 15:43                       ` Eli Zaretskii
2024-07-04 15:48                       ` Eli Zaretskii
2024-07-04 15:52                         ` Pip Cet
2024-07-04 16:04                           ` Eli Zaretskii
2024-07-04 17:01                             ` Gerd Möllmann
2024-07-04 18:03                               ` Eli Zaretskii
2024-07-04 18:28                                 ` Gerd Möllmann
2024-07-04 18:43                                   ` Eli Zaretskii
2024-07-04 19:09                                     ` Gerd Möllmann
2024-07-04 19:12                                       ` Eli Zaretskii
2024-07-04 16:38                     ` Pip Cet
2024-07-04 17:06                       ` 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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='cmbRWfutWovlqG2IR9J5QkzlmGkb1ajJ2y4wlZG75Xn8jQS4MPo86luKQNGFbjthaqj-mjXiiAELGcV4ppjGIvQTBoUGW_HFT4oXfse10aA=@protonmail.com' \
    --to=pipcet@protonmail.com \
    --cc=eliz@gnu.org \
    --cc=eller.helmut@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=gerd.moellmann@gmail.com \
    --cc=yantar92@posteo.net \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.