From unknown Sat Jun 21 03:10:06 2025 X-Loop: help-debbugs@gnu.org Subject: bug#78812: feature/igc: [PATCH] Make lface_id_to_name an exact root Resent-From: Helmut Eller Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 17 Jun 2025 07:57:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 78812 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: 78812@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.17501470055013 (code B ref -1); Tue, 17 Jun 2025 07:57:01 +0000 Received: (at submit) by debbugs.gnu.org; 17 Jun 2025 07:56:45 +0000 Received: from localhost ([127.0.0.1]:52917 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uRRBV-0001Im-55 for submit@debbugs.gnu.org; Tue, 17 Jun 2025 03:56:45 -0400 Received: from lists.gnu.org ([2001:470:142::17]:49782) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uRRBS-0001Hp-An for submit@debbugs.gnu.org; Tue, 17 Jun 2025 03:56:43 -0400 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 ) id 1uRRBL-0007Cb-9q for bug-gnu-emacs@gnu.org; Tue, 17 Jun 2025 03:56:35 -0400 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uRRBF-0004mS-QV for bug-gnu-emacs@gnu.org; Tue, 17 Jun 2025 03:56:32 -0400 Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-adb2bd27c7bso806863666b.2 for ; Tue, 17 Jun 2025 00:56:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750146986; x=1750751786; darn=gnu.org; h=mime-version:user-agent:message-id:date:subject:to:from:from:to:cc :subject:date:message-id:reply-to; bh=ASdlYizbKk2/bT5Mr54xzbmHTag6n4cNLtj/J6YFe9w=; b=C6YZ26j+rJGXAYI09J1fWBdlsQimswIP0+oIyw0tl2KKJTyqN0MNDpD9qMQY+GKwRN fV7yzsduSJcp2e3Kv1KzGAeVI+qfxbZhEhcEoG0JmpNVTFJ559dVL4LQLRUWjSpNupL1 hKBAvDaweEUhwkHLuV7JBREqARa9k/J9nh3sQMn70lZLrcjAWMu6v4mpzuVn7Ko2Q1YW hBsWQKiUZ9negIjqdNoU6bd9tfm7tREtOj2zcV8np4lMAkVZl5MobzVDUQgR4iswPWRu hXqfja2ebtg3gKZkskt18d8APnlIlSrLW0yhap4JlmpnhFcF3Z6x1t0z9NhLS58ZixxE X9FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750146986; x=1750751786; h=mime-version:user-agent:message-id:date:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ASdlYizbKk2/bT5Mr54xzbmHTag6n4cNLtj/J6YFe9w=; b=FpX2Kb0MMFuHbaEuWsxzy4Fb3MoG2GcXvWNDCCzG6U6u7HcxAvdBf9Eprrfbq0nqqP PL2Xq6GT+r1CYHJdl16M+ARisaUVkxU1MpDKkA5XzM9+friDl395Y5rtxi8aojsKkpmd Y8P66oWnIGAFhPOo0Zgir1vA63K4xPWyfenaIP1bIV4w+ZxpYjkUIaKEOYSSm2ddt1w5 xaBOL75gs9tpKKRrZ6ZCreMgRPf34Nv2Y5YPSFl+bLEstN0eC6wNHimtM31LLCqQ8ik+ rMeaY0d7UYnTGjI+XPlkTTQaZk/riR4RkZ6T2bH/EJhKfLKNA6QGklGv/xuJHRsTtdlm iPMQ== X-Gm-Message-State: AOJu0YwgCdjV5sDH+wTYCJpw9R+lS61ZuyQBYh5wL1DPARTWjEV0kQa9 LWAPVXltZm4EDRN0Yt0stvkdi07ZjjLEXPOIUHXDrrzFRSPytULvn0CDe4JJ6Q== X-Gm-Gg: ASbGncs1VMPJm5kz3vWCQJf4KjQmSYdjyd9wXsYp3AqJULb9EyUzhGDknpcEF84ZGz7 V4/vJZav3GbkH0b0Rs5Opdx/PHlBFmaBq0HTPVcW/GaOogSA/tQux/xfkRTx7+Y7QyWd7h8XBkU 8a0V83h4iE/WBfSdF8zb/TM5JFR9k/LnBzPs+9w6dd0ss/yPzk3PzlSAeYHqr6LuLVfekUm+PG3 6jhCClIsZ1CPH7ZGKrmwb3KeyW030R6Ck2k487ENc8GI8ad/730bSOWGgsODEWw7m2DBZZTkfaR BeLbsmyw+fc0q3lQHTdAlvf8M18KCwzhpJ8T0LS5BnMWKvO/FYay9iZRKHuOjNFQPDpLTGfPYr2 MwBf4TOCH0+mhIbChWWE= X-Google-Smtp-Source: AGHT+IFwwvxU6FkSsqiVU1Xyai+4zMz5XymYUqz0oerqiYvtxWaf82sQ3JFYNdLA+VkgLrpTnMvQAg== X-Received: by 2002:a17:907:7e98:b0:ade:79c5:21dc with SMTP id a640c23a62f3a-adfad354e5amr1223256366b.25.1750146985650; Tue, 17 Jun 2025 00:56:25 -0700 (PDT) Received: from caladan (dial-184179.pool.broadband44.net. [212.46.184.179]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-adec8928c15sm811744766b.112.2025.06.17.00.56.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jun 2025 00:56:24 -0700 (PDT) From: Helmut Eller Date: Tue, 17 Jun 2025 09:56:23 +0200 Message-ID: <877c1ag5so.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2a00:1450:4864:20::62e; envelope-from=eller.helmut@gmail.com; helo=mail-ej1-x62e.google.com 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.0 (+) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --=-=-= Content-Type: text/plain This is a proposal to make the variable lface_id_to_name an exact root. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Make-lface_id_to_name-an-exact-root.patch >From c462bc2a21c6e35e903df177a6f1e79d3e60f8ab Mon Sep 17 00:00:00 2001 From: Helmut Eller Date: Tue, 17 Jun 2025 09:29:07 +0200 Subject: [PATCH] Make lface_id_to_name an exact root * src/igc.h (igc_xpalloc_lisp_objs_exact): New. * src/igc.c (igc_xpalloc_lisp_objs_exact): Implementation. * src/xface.c (init_xfaces): igc_xalloc_lisp_objs_exact instead of igc_xzalloc_ambig. (Finternal_make_lisp_face): Use igc_xpalloc_lisp_objs_exact instead of igc_xpalloc_ambig. --- src/igc.c | 18 ++++++++++++++++++ src/igc.h | 6 ++++++ src/xfaces.c | 10 ++++++---- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/igc.c b/src/igc.c index eb845ff7ae0..2b9339d0c99 100644 --- a/src/igc.c +++ b/src/igc.c @@ -3503,6 +3503,24 @@ igc_xnrealloc_ambig (void *old_pa, ptrdiff_t nitems, ptrdiff_t item_size) return new_pa; } +Lisp_Object * +igc_xpalloc_lisp_objs_exact (Lisp_Object *pa, ptrdiff_t *nitems, + ptrdiff_t nitems_incr_min, ptrdiff_t nitems_max, + ptrdiff_t item_size, const char *label) +{ + ptrdiff_t nitems_old = *nitems; + ptrdiff_t nitems_new = nitems_old; + ptrdiff_t nbytes + = xpalloc_nbytes (pa, &nitems_new, nitems_incr_min, nitems_max, item_size); + Lisp_Object *old = pa; + Lisp_Object *new = xzalloc (nbytes); + root_create_exact (global_igc, new, new + nitems_new, scan_exact, label); + memcpy (new, old, nitems_old * sizeof old[0]); + igc_destroy_root_with_start (old); + *nitems = nitems_new; + return new; +} + static void finalize_bignum (struct Lisp_Bignum *n) { diff --git a/src/igc.h b/src/igc.h index 5e24c7c338a..1f1341ca589 100644 --- a/src/igc.h +++ b/src/igc.h @@ -96,6 +96,12 @@ #define EMACS_IGC_H ptrdiff_t nitems_incr_min, ptrdiff_t nitems_max, ptrdiff_t item_size); +Lisp_Object *igc_xpalloc_lisp_objs_exact (Lisp_Object *pa, ptrdiff_t *nitems, + ptrdiff_t nitems_incr_min, + ptrdiff_t nitems_max, + ptrdiff_t item_size, + const char *label); + typedef int igc_scan_result_t; /* zero means success */ struct igc_ss; typedef igc_scan_result_t (*igc_scan_area_t) (struct igc_ss *ss, void *start, diff --git a/src/xfaces.c b/src/xfaces.c index 2ca68193876..7ebbc53709c 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -2990,8 +2990,11 @@ DEFUN ("internal-make-lisp-face", Finternal_make_lisp_face, { #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); + = igc_xpalloc_lisp_objs_exact (lface_id_to_name, + &lface_id_to_name_size, + 1, MAX_FACE_ID, + sizeof *lface_id_to_name, + "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); @@ -7361,8 +7364,7 @@ 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); + lface_id_to_name = igc_xalloc_lisp_objs_exact (next_lface_id); #else lface_id_to_name = xnmalloc (next_lface_id, sizeof *lface_id_to_name); #endif -- 2.39.5 --=-=-=-- From unknown Sat Jun 21 03:10:06 2025 X-Loop: help-debbugs@gnu.org Subject: bug#78812: feature/igc: [PATCH] Make lface_id_to_name an exact root Resent-From: Pip Cet Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 17 Jun 2025 15:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 78812 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Helmut Eller Cc: 78812@debbugs.gnu.org Received: via spool by 78812-submit@debbugs.gnu.org id=B78812.175017393125825 (code B ref 78812); Tue, 17 Jun 2025 15:26:02 +0000 Received: (at 78812) by debbugs.gnu.org; 17 Jun 2025 15:25:31 +0000 Received: from localhost ([127.0.0.1]:60377 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uRYBn-0006iT-10 for submit@debbugs.gnu.org; Tue, 17 Jun 2025 11:25:31 -0400 Received: from mail-4322.protonmail.ch ([185.70.43.22]:15113) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uRYBk-0006hX-90 for 78812@debbugs.gnu.org; Tue, 17 Jun 2025 11:25:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1750173921; x=1750433121; bh=n3Y/RVnwirg+3mNlFTZpQH34ZZD5DT80C4xVHBplDpQ=; 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:List-Unsubscribe:List-Unsubscribe-Post; b=RLNAkYB0/ApEFsQA9tA3qiFTBBfBTVuuShdXZtP8pde5nwMSbVKJE4O/vfxxhop92 +S5nwzwDQ7s3GdKiFXqw+WYbyDFLE8D1NxRttRfPqP8tqtBxh8t4uL9PPWWKYQ/Sj4 xhLmF9erhNilSeStpZQDhBQ0Ltfuc2d+Q2EqwEm/PihvLIxmqKeV13VE2HAIDvDdi7 F0VVo+i1R3NOHStaaUr8my1/mZQfNhbbuw9SItFc+8pwcf62mBD/Zq6Nfvq/QBJ3Q0 MXLnOHCApkfK2zn17C7UP4tf9pxKeLJzu4Bm44gTnRoW8v5TojravBeSnrtS6WHLSQ 14cSAzMN2TUjA== Date: Tue, 17 Jun 2025 15:25:18 +0000 From: Pip Cet Message-ID: <87ikkutmp1.fsf@protonmail.com> In-Reply-To: <877c1ag5so.fsf@gmail.com> References: <877c1ag5so.fsf@gmail.com> Feedback-ID: 112775352:user:proton X-Pm-Message-ID: 36165bfeee2b51b38366eb30381ea354be785d4c MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) "Helmut Eller" writes: > This is a proposal to make the variable lface_id_to_name an exact root. Thank you! I'll apply this as it is, but I'd suggest one change, which I'd like to quickly run by you: Some of the code in igc_xpalloc_lisp_objs_exact handles item_size !=3D word_size, and some doesn't. Would you prefer to remove the parameter or change the code to handle multi-word items, which might be useful for arrays of arrays of Lisp_Object? I think we should add label arguments to all igc*alloc* functions. With your patch, we don't see the lface-id-to-name root until the first time it's been resized, and it would make more sense to see it right away. There's the general problem of memcpy atomicity, but I don't have a solution for that; the complicated code in xpalloc_exact is still insufficient, so we might as well remove it. While the ordinary memcpy function in glibc will always copy large chunks, some debug builds use byte-based replacements, and then we have a potential problem. This is particularly annoying because stress-testing such builds by triggering collections from a background thread might see false positive segfaults. I haven't seen one in practice, but I use such tools very rarely. Thanks again Pip From unknown Sat Jun 21 03:10:06 2025 X-Loop: help-debbugs@gnu.org Subject: bug#78812: feature/igc: [PATCH] Make lface_id_to_name an exact root Resent-From: Helmut Eller Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 18 Jun 2025 08:46:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 78812 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Pip Cet Cc: 78812@debbugs.gnu.org Received: via spool by 78812-submit@debbugs.gnu.org id=B78812.175023635329286 (code B ref 78812); Wed, 18 Jun 2025 08:46:02 +0000 Received: (at 78812) by debbugs.gnu.org; 18 Jun 2025 08:45:53 +0000 Received: from localhost ([127.0.0.1]:45466 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uRoQb-0007cG-51 for submit@debbugs.gnu.org; Wed, 18 Jun 2025 04:45:53 -0400 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]:58567) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1uRoQY-0007bc-7U for 78812@debbugs.gnu.org; Wed, 18 Jun 2025 04:45:52 -0400 Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-ade5b8aab41so1408471766b.0 for <78812@debbugs.gnu.org>; Wed, 18 Jun 2025 01:45:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750236344; x=1750841144; darn=debbugs.gnu.org; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=OCqbcxvQBTCUe7qN/ARO5Xu/o5xVVgX7NmfhVnYeXHI=; b=cauwT/O3yQsQX+UJpKDX7zx9mBEpapkXiem8s7jTP+qTur+zCqSvOfkXHdvrofUyYA z+sESrv3+qEwD6hopkuZGGQqo9OJT4TrQBhocVfF4Q5qpU22L176jkXgo+AK5JJiJAqx gsTJZvravtBsY8xs8KewaaLf3nWIS1Gr4aN6enSvSJGc9ujc1BZEoOTp5TKUC5xqQANv n/HwBlFxY8c6H84MwYad+tlMqZTZZq4ZWU0Y/vII13UkykONW2ivsScfadVWeL9fD9z5 GakAMa3645ElHZMUEOPCKFoO2hpli0gJ2rbPVQgkB0J0A9SyH7fk9m/KhVuyfG9MP+i8 BPqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750236344; x=1750841144; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=OCqbcxvQBTCUe7qN/ARO5Xu/o5xVVgX7NmfhVnYeXHI=; b=jlIWOxvaMD+JHwol2/Jjc6IOvfnK96iGUg1ybpqB4mYhDOLTxTqRZoPs+E8/BI8y6P 1A9rzBFruokdFlEpPUEdlqSu9iSHGLnCqLTykhY0q29Mmoq1x3Nh+GWTwx0EXsANRXJi GysNERoH4+aN2Eb4Oy5qlOL5HeXhu3KeJGgB4ZWnNmem9YHerC9P/Y0z/TP+dYCV/J58 HqQtxO2CLmZOcTSgKcbOCrc8D4cm7htaF89oGsU8e+swwUOmKPPp0WFc2fqJx/CNZ4A4 QqzzvH7Ej976vie4ckK79yEArnGl6gjxj9yoFO2XXvZVOpZzcnELCJDvwzyYZBn5ehPl RGhQ== X-Gm-Message-State: AOJu0YykwpgHPa2RX9v2tAT3OTdlFODHLC9+gOsU8Wrb7eowa8qfoR0x vwsA6b8Z6yOFQzTA4LFug4vxMF87D3kr76YBEuXLpUWHA60O8iBDtDmUH7/sqg== X-Gm-Gg: ASbGncui+9qAHpChBMyREdAHI6ObXak9UDB+zhJU3epBDeaZKGHIDNeZtPWJaN885rI 8FT1BbNjmOMHoM3NnINPCjaE7+K4RNhVCvy6DBmX/cEYm49fwtqx9ZRvNYkRzVHQeyHCg5fYXkN bzQiuAKNvum2HqCQ+9/aa/qsoDfWE/74iU2q6qtWiRTLFeZeaJRFEAA+cVJ4V9ItFx/YWioDtCa 8tnnCARYokDSAgYGLgB9vWG8Vuz/PsCjQEppR0R3UP9ZP8Sty/PbLzrwa3WRZOu33u+BCgTFTZ9 0nI8NNPxEkfNz10m2r8z2DVawPzSlsi5vsGpAi2xBe3JYJe2y9jLg9wDlfuyAMdiAK5Ilcn+iqy lgmTRpPJBQ9210qFGvDc= X-Google-Smtp-Source: AGHT+IGArXog3PV4HxYmMzETpYFmEp6eZ8JCAnTrURwUNn6GNQJ9K6uEItNLjyV7QwQ94coYoGJIbw== X-Received: by 2002:a17:907:3e04:b0:ad1:fa48:da0a with SMTP id a640c23a62f3a-adfad40bd10mr1473996266b.35.1750236343300; Wed, 18 Jun 2025 01:45:43 -0700 (PDT) Received: from caladan (dial-184179.pool.broadband44.net. [212.46.184.179]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-adec8978632sm1012983566b.148.2025.06.18.01.45.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jun 2025 01:45:42 -0700 (PDT) From: Helmut Eller In-Reply-To: <87ikkutmp1.fsf@protonmail.com> References: <877c1ag5so.fsf@gmail.com> <87ikkutmp1.fsf@protonmail.com> Date: Wed, 18 Jun 2025 10:45:41 +0200 Message-ID: <87ldpp30ay.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --=-=-= Content-Type: text/plain On Tue, Jun 17 2025, Pip Cet wrote: > "Helmut Eller" writes: > >> This is a proposal to make the variable lface_id_to_name an exact root. > > Thank you! > > I'll apply this as it is, but I'd suggest one change, which I'd like to > quickly run by you: > > Some of the code in igc_xpalloc_lisp_objs_exact handles item_size != > word_size, and some doesn't. Would you prefer to remove the parameter > or change the code to handle multi-word items, which might be useful for > arrays of arrays of Lisp_Object? Let's remove it. The item_size is redundant here. See the amended patch. I also added the missing xfree :-). > I think we should add label arguments to all igc*alloc* functions. With > your patch, we don't see the lface-id-to-name root until the first time > it's been resized, and it would make more sense to see it right away. I added that as a separate patch. > There's the general problem of memcpy atomicity, but I don't have a > solution for that; the complicated code in xpalloc_exact is still > insufficient, so we might as well remove it. > > While the ordinary memcpy function in glibc will always copy large > chunks, some debug builds use byte-based replacements, and then we have > a potential problem. This is particularly annoying because > stress-testing such builds by triggering collections from a background > thread might see false positive segfaults. I haven't seen one in > practice, but I use such tools very rarely. Fixing all problematic uses of memcpy would be quite tricky. Two obvious cases are larger_vector and copy_hash_table. I suppose that memcpy is also a reason why software write barriers would be a lot of work. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Make-lface_id_to_name-an-exact-root.patch >From e54c26eacf2978243339d7622a74d54430d9367f Mon Sep 17 00:00:00 2001 From: Helmut Eller Date: Tue, 17 Jun 2025 09:29:07 +0200 Subject: [PATCH 1/2] Make lface_id_to_name an exact root * src/igc.h (igc_xpalloc_lisp_objs_exact): New. * src/igc.c (igc_xpalloc_lisp_objs_exact): Implementation. * src/xface.c (init_xfaces): Use igc_xalloc_lisp_objs_exact instead of igc_xzalloc_ambig. (Finternal_make_lisp_face): Use igc_xpalloc_lisp_objs_exact instead of igc_xpalloc_ambig. --- src/igc.c | 20 ++++++++++++++++++++ src/igc.h | 5 +++++ src/xfaces.c | 9 +++++---- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/igc.c b/src/igc.c index eb845ff7ae0..5d9bc9774be 100644 --- a/src/igc.c +++ b/src/igc.c @@ -3503,6 +3503,26 @@ igc_xnrealloc_ambig (void *old_pa, ptrdiff_t nitems, ptrdiff_t item_size) return new_pa; } +Lisp_Object * +igc_xpalloc_lisp_objs_exact (Lisp_Object *pa, ptrdiff_t *nitems, + ptrdiff_t nitems_incr_min, ptrdiff_t nitems_max, + const char *label) +{ + ptrdiff_t nitems_old = *nitems; + ptrdiff_t nitems_new = nitems_old; + ptrdiff_t nbytes + = xpalloc_nbytes (pa, &nitems_new, nitems_incr_min, nitems_max, word_size); + Lisp_Object *old = pa; + Lisp_Object *new = xzalloc (nbytes); + root_create_exact (global_igc, new, new + nitems_new, scan_exact, label); + for (ptrdiff_t i = 0; i < nitems_old; i++) + new[i] = old[i]; + igc_destroy_root_with_start (old); + xfree (old); + *nitems = nitems_new; + return new; +} + static void finalize_bignum (struct Lisp_Bignum *n) { diff --git a/src/igc.h b/src/igc.h index 5e24c7c338a..d9471b0ee62 100644 --- a/src/igc.h +++ b/src/igc.h @@ -96,6 +96,11 @@ #define EMACS_IGC_H ptrdiff_t nitems_incr_min, ptrdiff_t nitems_max, ptrdiff_t item_size); +Lisp_Object *igc_xpalloc_lisp_objs_exact (Lisp_Object *pa, ptrdiff_t *nitems, + ptrdiff_t nitems_incr_min, + ptrdiff_t nitems_max, + const char *label); + typedef int igc_scan_result_t; /* zero means success */ struct igc_ss; typedef igc_scan_result_t (*igc_scan_area_t) (struct igc_ss *ss, void *start, diff --git a/src/xfaces.c b/src/xfaces.c index 2ca68193876..41903a6c3d5 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -2990,8 +2990,10 @@ DEFUN ("internal-make-lisp-face", Finternal_make_lisp_face, { #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); + = igc_xpalloc_lisp_objs_exact (lface_id_to_name, + &lface_id_to_name_size, + 1, MAX_FACE_ID, + "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); @@ -7361,8 +7363,7 @@ 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); + lface_id_to_name = igc_xalloc_lisp_objs_exact (next_lface_id); #else lface_id_to_name = xnmalloc (next_lface_id, sizeof *lface_id_to_name); #endif -- 2.39.5 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0002-Require-an-explicit-label-for-igc_xalloc_lisp_objs_e.patch >From 93f9a7b55c6c73ed5467993538a68013a7c1535e Mon Sep 17 00:00:00 2001 From: Helmut Eller Date: Wed, 18 Jun 2025 10:25:30 +0200 Subject: [PATCH 2/2] Require an explicit label for igc_xalloc_lisp_objs_exact This makes igc-roots-stats a bit more useful. * src/igc.h (igc_xalloc_lisp_objs_exact): Add label argument. * src/igc.c (igc_xalloc_lisp_objs_exact): Pass the label along. * src/xfaces.c (init_xfaces): Specify a label. * src/json.c (json_make_object_workspace_for_slow_path): Specify a label. --- src/igc.c | 5 ++--- src/igc.h | 2 +- src/json.c | 6 ++++-- src/xfaces.c | 3 ++- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/igc.c b/src/igc.c index 5d9bc9774be..26ffa462281 100644 --- a/src/igc.c +++ b/src/igc.c @@ -3334,12 +3334,11 @@ igc_grow_rdstack (struct read_stack *rs) } Lisp_Object * -igc_xalloc_lisp_objs_exact (size_t n) +igc_xalloc_lisp_objs_exact (size_t n, const char *label) { size_t size = n * sizeof (Lisp_Object); void *p = xzalloc (size); - root_create_exact (global_igc, p, (char *) p + size, scan_exact, - "xalloc-exact"); + root_create_exact (global_igc, p, (char *) p + size, scan_exact, label); return p; } diff --git a/src/igc.h b/src/igc.h index d9471b0ee62..178dbf20238 100644 --- a/src/igc.h +++ b/src/igc.h @@ -89,7 +89,7 @@ #define EMACS_IGC_H #ifdef ENABLE_CHECKING void igc_check_freeable (void *p); #endif -Lisp_Object *igc_xalloc_lisp_objs_exact (size_t n); +Lisp_Object *igc_xalloc_lisp_objs_exact (size_t n, const char *label); void * igc_xalloc_raw_exact (size_t n); void *igc_xpalloc_ambig (void *pa, ptrdiff_t *nitems, diff --git a/src/json.c b/src/json.c index 1cb72f26860..d7e7c740126 100644 --- a/src/json.c +++ b/src/json.c @@ -842,7 +842,8 @@ json_make_object_workspace_for_slow_path (struct json_parser *parser, = xnmalloc (new_workspace_size, sizeof (Lisp_Object)); #else new_workspace_ptr - = igc_xalloc_lisp_objs_exact (new_workspace_size); + = igc_xalloc_lisp_objs_exact (new_workspace_size, + "json-parser-object-workspace"); #endif memcpy (new_workspace_ptr, parser->object_workspace, (sizeof (Lisp_Object) @@ -856,7 +857,8 @@ json_make_object_workspace_for_slow_path (struct json_parser *parser, sizeof (Lisp_Object)); #else new_workspace_ptr - = igc_xalloc_lisp_objs_exact (new_workspace_size); + = igc_xalloc_lisp_objs_exact (new_workspace_size, + "json-parser-object-workspace"); memcpy (new_workspace_ptr, parser->object_workspace, (sizeof (Lisp_Object) * parser->object_workspace_current)); diff --git a/src/xfaces.c b/src/xfaces.c index 41903a6c3d5..396d2d9b16c 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -7363,7 +7363,8 @@ 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_xalloc_lisp_objs_exact (next_lface_id); + lface_id_to_name = igc_xalloc_lisp_objs_exact (next_lface_id, + "lface-id-to-name"); #else lface_id_to_name = xnmalloc (next_lface_id, sizeof *lface_id_to_name); #endif -- 2.39.5 --=-=-=-- From unknown Sat Jun 21 03:10:06 2025 X-Loop: help-debbugs@gnu.org Subject: bug#78812: feature/igc: [PATCH] Make lface_id_to_name an exact root Resent-From: Pip Cet Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 18 Jun 2025 12:28:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 78812 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Helmut Eller Cc: 78812@debbugs.gnu.org Received: via spool by 78812-submit@debbugs.gnu.org id=B78812.17502496365747 (code B ref 78812); Wed, 18 Jun 2025 12:28:02 +0000 Received: (at 78812) by debbugs.gnu.org; 18 Jun 2025 12:27:16 +0000 Received: from localhost ([127.0.0.1]:48572 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uRrsp-0001Ub-Gl for submit@debbugs.gnu.org; Wed, 18 Jun 2025 08:27:15 -0400 Received: from mail-24416.protonmail.ch ([109.224.244.16]:15167) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uRrsm-0001Ts-HK for 78812@debbugs.gnu.org; Wed, 18 Jun 2025 08:27:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1750249625; x=1750508825; bh=huoW8SEY4fSkGPD3B3xqjx1JeujWb7cNrpPLZAi3WEc=; 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:List-Unsubscribe:List-Unsubscribe-Post; b=VkqSFofEF37VpTNB/Ne0quSk9i6Llq8OZ2eXMpxe8mXlz83AulR9bOP9EPXpll/Na 4rqYP1jhUhs4D1+6ljltCBpXA2+heSeqXiyoUKYFydNKhFPCbDcZJNs0NDsXOIG3MM gSDQIqDRbXfQB9Zpn79MI4VC6Kg9h5luX1R/tdekOF3uFaTefNHzeykFknQSZ6kbaJ XS7c/WOs0+HrecrAX9pPwHIVEumdBTdEwyy8jeq2S7hW7MiGwjdDTyKH1TYDsWo8Nk 5f/9119aqGtjtm91etEnDcy+hUMY1b6mOWe2rEvg4+2mjB0DaJDKgmzFC5a1FKNij0 woox09I11IKdg== Date: Wed, 18 Jun 2025 12:27:01 +0000 From: Pip Cet Message-ID: <87sejxs0a5.fsf@protonmail.com> In-Reply-To: <87ldpp30ay.fsf@gmail.com> References: <877c1ag5so.fsf@gmail.com> <87ikkutmp1.fsf@protonmail.com> <87ldpp30ay.fsf@gmail.com> Feedback-ID: 112775352:user:proton X-Pm-Message-ID: 45a6b2fd39546694eb67d34bd13127dc1613d452 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) "Helmut Eller" writes: > On Tue, Jun 17 2025, Pip Cet wrote: > >> "Helmut Eller" writes: >> >>> This is a proposal to make the variable lface_id_to_name an exact root. >> >> Thank you! >> >> I'll apply this as it is, but I'd suggest one change, which I'd like to >> quickly run by you: >> >> Some of the code in igc_xpalloc_lisp_objs_exact handles item_size !=3D >> word_size, and some doesn't. Would you prefer to remove the parameter >> or change the code to handle multi-word items, which might be useful for >> arrays of arrays of Lisp_Object? > > Let's remove it. The item_size is redundant here. See the amended > patch. I also added the missing xfree :-). Thanks. I missed that one, and I also missed that memcpy (ptr, NULL, 0) is undefined behavior, see bug#78824. However, the new patch looks good on both counts. >> I think we should add label arguments to all igc*alloc* functions. With >> your patch, we don't see the lface-id-to-name root until the first time >> it's been resized, and it would make more sense to see it right away. > > I added that as a separate patch. Thanks! LGTM (not that that means much, see above). >> There's the general problem of memcpy atomicity, but I don't have a >> solution for that; the complicated code in xpalloc_exact is still >> insufficient, so we might as well remove it. >> >> While the ordinary memcpy function in glibc will always copy large >> chunks, some debug builds use byte-based replacements, and then we have >> a potential problem. This is particularly annoying because >> stress-testing such builds by triggering collections from a background >> thread might see false positive segfaults. I haven't seen one in >> practice, but I use such tools very rarely. > > Fixing all problematic uses of memcpy would be quite tricky. Two > obvious cases are larger_vector and copy_hash_table. I suppose that > memcpy is also a reason why software write barriers would be a lot of > work. So let's use memcpy for now, where there's no obvious way to do it using a loop (and performance isn't important enough to use memcpy, of course). I'll apply the new patch once we've confirmed that bug#78824 was the zero-byte memcpy issue, if that's okay? Pip