emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: MPS: Crash when switching to buffer


From: Pip Cet
Subject: Re: MPS: Crash when switching to buffer
Date: Tue, 02 Jul 2024 00:22:03 +0000

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);

Attachment: 0002-try-to-fix-face-related-crashes.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]