From mboxrd@z Thu Jan  1 00:00:00 1970
Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail
From: Pip Cet <pipcet@protonmail.com>
Newsgroups: gmane.emacs.devel
Subject: Re: MPS: Crash when switching to buffer
Date: Tue, 02 Jul 2024 00:22:03 +0000
Message-ID: <cmbRWfutWovlqG2IR9J5QkzlmGkb1ajJ2y4wlZG75Xn8jQS4MPo86luKQNGFbjthaqj-mjXiiAELGcV4ppjGIvQTBoUGW_HFT4oXfse10aA=@protonmail.com>
References: <87v81pbgzi.fsf@localhost> <86a5j1fhd1.fsf@gnu.org>
 <OifzVrpJwTw0NuVdcQss9KlkJ50L2Qb-5cUj-rkoJgaqs_2kYJnLx8AfYVP_Acnv5MnKaJzCBld7ao53dbS7KITa8Pre7LdV7TLMjjMzvJs=@protonmail.com>
 <m28qylcgx1.fsf@pro2.fritz.box>
Mime-Version: 1.0
Content-Type: multipart/mixed;
 boundary="b1_Rdi4mMs41iSQ6g1qfkSuyttLRxRoRhyT8RrFZnltl54"
Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214";
	logging-data="16588"; mail-complaints-to="usenet@ciao.gmane.io"
Cc: Eli Zaretskii <eliz@gnu.org>, Ihor Radchenko <yantar92@posteo.net>,
 emacs-devel@gnu.org, eller.helmut@gmail.com
To: =?utf-8?Q?Gerd_M=C3=B6llmann?= <gerd.moellmann@gmail.com>
Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Jul 02 04:24:13 2024
Return-path: <emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org>
Envelope-to: ged-emacs-devel@m.gmane-mx.org
Original-Received: from lists.gnu.org ([209.51.188.17])
	by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
	(Exim 4.92)
	(envelope-from <emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org>)
	id 1sOTBk-00048T-FH
	for ged-emacs-devel@m.gmane-mx.org; Tue, 02 Jul 2024 04:24:12 +0200
Original-Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <emacs-devel-bounces@gnu.org>)
	id 1sOTB5-0002Os-AY; Mon, 01 Jul 2024 22:23:31 -0400
Original-Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <pipcet@protonmail.com>)
 id 1sORHh-0008W1-16
 for emacs-devel@gnu.org; Mon, 01 Jul 2024 20:22:13 -0400
Original-Received: from mail-40131.protonmail.ch ([185.70.40.131])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <pipcet@protonmail.com>)
 id 1sORHe-0007gY-Vg
 for emacs-devel@gnu.org; Mon, 01 Jul 2024 20:22:12 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com;
 s=protonmail3; t=1719879727; x=1720138927;
 bh=ZYSswCbumLq/PjIzFFvl2Xn2akotDhs3dYFjP5taSbQ=;
 h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References:
 Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID:
 Message-ID:BIMI-Selector;
 b=a1o531bUlEJ2U6QLwtx8c81jpISC/Vzn30200KOAPCAkRYTJX12lxscV6mjNlLhYv
 ABt18Bd2GyrWD8qStg6VOgwVWOZlARpszlqchQgX7ouHt2fJOijiY3yMT9diCGZdj8
 zhRNFCd0LVzvKVuVJxYHE5A2agbAqjbCkxV/H3IwIljzQa4DheTEUq/7rZ9T90grNa
 +Mgd10Qo/d+CMMXOC7V4n/E1Ze9DXW0MtAj0vzf/QtOyCKdEPzy5XmTRt3NdhKyjvR
 ljTv2wXHn0LkpKAg8XOLeJrSZJVzlPpKAaUfQSTjrrJ2CZv1eYmI9o8XlEKfdS6dpD
 YMucTVvBKHaiw==
In-Reply-To: <m28qylcgx1.fsf@pro2.fritz.box>
Feedback-ID: 112775352:user:proton
X-Pm-Message-ID: bacae453a8842fc7b42ee77cca9b20592e779447
Received-SPF: pass client-ip=185.70.40.131; envelope-from=pipcet@protonmail.com;
 helo=mail-40131.protonmail.ch
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001,
 RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001,
 SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Mailman-Approved-At: Mon, 01 Jul 2024 22:23:14 -0400
X-BeenThere: emacs-devel@gnu.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: "Emacs development discussions." <emacs-devel.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/emacs-devel>,
 <mailto:emacs-devel-request@gnu.org?subject=unsubscribe>
List-Archive: <https://lists.gnu.org/archive/html/emacs-devel>
List-Post: <mailto:emacs-devel@gnu.org>
List-Help: <mailto:emacs-devel-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/emacs-devel>,
 <mailto:emacs-devel-request@gnu.org?subject=subscribe>
Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org
Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org
Xref: news.gmane.io gmane.emacs.devel:321084
Archived-At: <http://permalink.gmane.org/gmane.emacs.devel/321084>

This is a multi-part message in MIME format.

--b1_Rdi4mMs41iSQ6g1qfkSuyttLRxRoRhyT8RrFZnltl54
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

On Monday, July 1st, 2024 at 14:42, Gerd M=C3=B6llmann <gerd.moellmann@gmai=
l.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...
>=20
> That's very possible, and a bug :-). Good catch!
>=20
> If xmalloc/xfree and friends are used to alloc memory that contains
> references, we have replaced them with oen of these
>=20
> 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);
>=20
> 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);
>=20
> void *igc_xnrealloc_ambig (void *pa, ptrdiff_t nitems, ptrdiff_t item_siz=
e);
>=20
> 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 wo=
rk? lface_id_to_name is never freed, it seems...

Ihor, I'm not sure whether the bug is fully reproducible. If it is, could y=
ou 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_lis=
p_face,
 =09 The mapping from Lisp face to Lisp face id is given by the
 =09 property `face' of the Lisp face name.  */
       if (next_lface_id =3D=3D lface_id_to_name_size)
+#ifdef HAVE_MPS
+=09lface_id_to_name =3D
+=09  igc_xpalloc_ambig (lface_id_to_name, &lface_id_to_name_size, 1, MAX_F=
ACE_ID,
+=09=09=09     sizeof *lface_id_to_name);
+#else
 =09lface_id_to_name =3D
 =09  xpalloc (lface_id_to_name, &lface_id_to_name_size, 1, MAX_FACE_ID,
 =09=09   sizeof *lface_id_to_name);
+#endif
=20
       Lisp_Object face_id =3D make_fixnum (next_lface_id);
       lface_id_to_name[next_lface_id] =3D face;
@@ -7326,7 +7332,11 @@ init_xfaces (void)
 =09{
 =09  /* Allocate the lface_id_to_name[] array.  */
 =09  lface_id_to_name_size =3D next_lface_id =3D nfaces;
+#ifdef HAVE_MPS
+=09  lface_id_to_name =3D igc_xzalloc_ambig (next_lface_id * sizeof *lface=
_id_to_name);
+#else
 =09  lface_id_to_name =3D xnmalloc (next_lface_id, sizeof *lface_id_to_nam=
e);
+#endif
=20
 =09  /* Store the faces.  */
 =09  struct Lisp_Hash_Table* table =3D XHASH_TABLE (Vface_new_frame_defaul=
ts);

--b1_Rdi4mMs41iSQ6g1qfkSuyttLRxRoRhyT8RrFZnltl54
Content-Type: text/x-patch; name=0002-try-to-fix-face-related-crashes.patch
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=0002-try-to-fix-face-related-crashes.patch

RnJvbSA3ZGViZDY5YjMzMWYyMDY4YzdkMGQ2OTc1MjYzYjJmOGVhMDg5ZmU0IE1vbiBTZXAgMTcg
MDA6MDA6MDAgMjAwMQpGcm9tOiBQaXAgQ2V0IDxwaXBjZXRAcHJvdG9ubWFpbC5jb20+CkRhdGU6
IFR1ZSwgMiBKdWwgMjAyNCAwMDoxODo1OCArMDAwMApTdWJqZWN0OiBbUEFUQ0ggMi8yXSB0cnkg
dG8gZml4IGZhY2UtcmVsYXRlZCBjcmFzaGVzCgotLS0KIHNyYy94ZmFjZXMuYyB8IDEwICsrKysr
KysrKysKIDEgZmlsZSBjaGFuZ2VkLCAxMCBpbnNlcnRpb25zKCspCgpkaWZmIC0tZ2l0IGEvc3Jj
L3hmYWNlcy5jIGIvc3JjL3hmYWNlcy5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