From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Gerd =?UTF-8?Q?M=C3=B6llmann?= Newsgroups: gmane.emacs.bugs Subject: bug#75322: SAFE_ALLOCA assumed to root Lisp_Objects/SSDATA(string) Date: Sun, 05 Jan 2025 07:59:32 +0100 Message-ID: References: <87jzbbke6u.fsf@protonmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35441"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 75322@debbugs.gnu.org To: Pip Cet Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jan 05 08:00:27 2025 Return-path: Envelope-to: geb-bug-gnu-emacs@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 ) id 1tUKcc-000955-Cn for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 05 Jan 2025 08:00:26 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tUKcV-0006PX-DD; Sun, 05 Jan 2025 02:00:19 -0500 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 ) id 1tUKcH-0006Lp-IS for bug-gnu-emacs@gnu.org; Sun, 05 Jan 2025 02:00:10 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tUKcE-0001om-9q for bug-gnu-emacs@gnu.org; Sun, 05 Jan 2025 02:00:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=hT8mqltraMpwkdoOd/pysNbmH/TbTst/Qf31xX/EEJU=; b=s0zbHUBXFM2EK2cZVsK3syno86v1p8gOEmtEtUwcg8yzfmWPIF5XGy4nmHPkTwOaCGXu5Y3W5dOLL1PaCoBkc8JeUmANTisHilxyzrGHTC+qEqKEp4Q4NwXgfFW9bmyKjozQ28pa/0Oxlho9zGEXFTYoNP1xNN4qsAIZrygUlV8QgOZCeyddlDJ3ZkRW2lNS1XUjwT/oeq+f6EhZ8dRglUijQ9cIbRXHlRk31C7jl7tRu9GzgWpWpTVkZ23a6yjsSewThNWX01gvDlouwFVb3H5VOdB0gX7eUvqI+Wcv4NmsCnsR2e+XHzCuYwfK8RXi8KEw7sWz6xGqudZq4BTaQw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tUKcE-0007qJ-3t for bug-gnu-emacs@gnu.org; Sun, 05 Jan 2025 02:00:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Gerd =?UTF-8?Q?M=C3=B6llmann?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 05 Jan 2025 07:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 75322 X-GNU-PR-Package: emacs Original-Received: via spool by 75322-submit@debbugs.gnu.org id=B75322.173606038530090 (code B ref 75322); Sun, 05 Jan 2025 07:00:02 +0000 Original-Received: (at 75322) by debbugs.gnu.org; 5 Jan 2025 06:59:45 +0000 Original-Received: from localhost ([127.0.0.1]:59313 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tUKbw-0007pG-FF for submit@debbugs.gnu.org; Sun, 05 Jan 2025 01:59:45 -0500 Original-Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]:53249) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1tUKbt-0007ox-L5 for 75322@debbugs.gnu.org; Sun, 05 Jan 2025 01:59:42 -0500 Original-Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-43624b2d453so138565055e9.2 for <75322@debbugs.gnu.org>; Sat, 04 Jan 2025 22:59:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736060375; x=1736665175; 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=hT8mqltraMpwkdoOd/pysNbmH/TbTst/Qf31xX/EEJU=; b=M9tRAERN7IRZgC544SB/SppK0o5wwil1r+dZZbkSvNN30WMkn7oUEFtquZ3EOOgArU caADX6LEdA5k9tXuPxtu8VdcdCrSMROJazcp3YC7JVHx0YcIp4vnbWsnzZH7Zmlr/H2Z WC3kY3K4IWIhc3a4jtmzss63wJze6O3cAJz+qcrpK+y06mp3oBTwQmZAYiDt+1aVFf2+ h/SWhp86Vv4SwOd4uGoMfHYh9m2H7y9KqzOH6ADTwqBydInP4QwwrL447mqPvMOGeiid lm3LsvzfEY8FxZO/ufCSv2qpxMRvBjQEfZpDq8m4/ImdOU5flMu3AVp3J7gp6ptyyemU 4J4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736060375; x=1736665175; 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=hT8mqltraMpwkdoOd/pysNbmH/TbTst/Qf31xX/EEJU=; b=dZH7mdLi8hs1PnTbf7XXem2hjAo7Q+XM3RsksE7iLenSXOKzHp2Twtzd2HQ2UMtiNM UV4u22IwYAQ6/+SzqxkJ3L9PdvnkKZYv/iXJ4jAGPvkHjpsF1iECVeIdgEtb6NUhIvtw r9Frh/fvw3wHL6KfQ+wMUTPcIq9+0iovBnDKsfuYTKYSFolw4xFFt2DSwpap9+9lUWdw Gfieyg0tJT6PGzY6alCxzylgBkOM520VBwSGqwSNsnEJEgeXzHvHrYp7+L7CYNSmbQ3l i2zXaVG9vEBJg4BISOVhssAD4Sm3JCpi80r0Hkqm52kjPW9r3C2H1udpg8WEyTVEoN25 Mbzg== X-Gm-Message-State: AOJu0YwrUqKivvYd6Om9NtYdXY5jt6polztcSZu0qQfGWW0MVDOozJXl rSeYrKtSbt2nsrj7YfgUMkgAXnHA9jnra6OZWJGrrQInHPHpHR3bdmemaA== X-Gm-Gg: ASbGncsOdh4hZsNKTJXXNiFUAo4LvrdgQ3s3wH2Cave7vWm8EoiftCXjanOgbsb8LcA wth7j++gb2NB6O4V+JXfJCwZxZR3bCrT+BzKXI5Dbq6OJjOkhZJ8H51+8k9bpDgPiClqhhR+whr NEFauThqL8qLUB/l3eQLBNFazDBmREoOtlWaKGre9OjIJXPG2qVgEVNwJR/+aBIpMaA5+vY7wlQ sKeI9pIWbesQphTo1ct4cuMPGcw7+ZYxqKK3WKmwCjxBZAchN+g/KFTOYyxcmU424OLNGW1j533 uoUa6YUXYE54Zu4IQXTOCphm5w/+rC2/F7UDmfcgSeBYX0GZ3j7DN4w+1fhatzdGTw== X-Google-Smtp-Source: AGHT+IHiyJeQd4JV/anYq4WmIOzNBiwNEt7/TFKhyFkwJpON2lOQrC1xsTQsfce8CZPjqTutxIpArA== X-Received: by 2002:a05:600c:474d:b0:436:18d0:aa6e with SMTP id 5b1f17b1804b1-4366835c14fmr463400005e9.5.1736060374698; Sat, 04 Jan 2025 22:59:34 -0800 (PST) Original-Received: from pro2 (p200300e0b747500078d774d9859911e7.dip0.t-ipconnect.de. [2003:e0:b747:5000:78d7:74d9:8599:11e7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43656af6c4esm565719265e9.4.2025.01.04.22.59.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Jan 2025 22:59:34 -0800 (PST) In-Reply-To: ("Gerd =?UTF-8?Q?M=C3=B6llmann?="'s message of "Sun, 05 Jan 2025 07:32:46 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:298502 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Gerd M=C3=B6llmann writes: > Just want to add that all SAFE_NALLOC uses should be checked in > scratch/igc. For example, set_overlays_multibyte uses it to store > itree_node *, and itree_node is in MPS. > > I think I'll just make it allocate a root in my Emacs. That's the least > work. Please find attached what I'm using now in my Emacs, in addition to your xstrdup commit. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Don-t-use-SAFE_NALLOCA-for-Lisp_Objects.patch >From c364d3199a1b3b1a9ec0f9afe421110d46a77769 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerd=20M=C3=B6llmann?= Date: Sat, 4 Jan 2025 19:42:50 +0100 Subject: [PATCH 1/2] Don't use SAFE_NALLOCA for Lisp_Objects * src/callproc.c (call_process, create_temp_file): Use SAFE_ALLOCA_LISP instead of SAFE_NALLCA. --- src/callproc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/callproc.c b/src/callproc.c index 459ddbeb4f3..6f358f939de 100644 --- a/src/callproc.c +++ b/src/callproc.c @@ -423,7 +423,7 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd, val = Qraw_text; else { - SAFE_NALLOCA (args2, 1, nargs + 1); + SAFE_ALLOCA_LISP (args2, nargs + 1); args2[0] = Qcall_process; for (i = 0; i < nargs; i++) args2[i + 1] = args[i]; coding_systems = Ffind_operation_coding_system (nargs + 1, args2); @@ -741,7 +741,7 @@ call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd, { ptrdiff_t i; - SAFE_NALLOCA (args2, 1, nargs + 1); + SAFE_ALLOCA_LISP (args2, nargs + 1); args2[0] = Qcall_process; for (i = 0; i < nargs; i++) args2[i + 1] = args[i]; coding_systems @@ -1033,7 +1033,7 @@ create_temp_file (ptrdiff_t nargs, Lisp_Object *args, Lisp_Object coding_systems; Lisp_Object *args2; USE_SAFE_ALLOCA; - SAFE_NALLOCA (args2, 1, nargs + 1); + SAFE_ALLOCA_LISP (args2, nargs + 1); args2[0] = Qcall_process_region; memcpy (args2 + 1, args, nargs * sizeof *args); coding_systems = Ffind_operation_coding_system (nargs + 1, args2); -- 2.47.1 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-Make-SAFE_NALLOCA-allocate-an-ambiguous-root.patch >From 5b0a46390dfb5407cb7585bcbb1b7491d81885ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerd=20M=C3=B6llmann?= Date: Sun, 5 Jan 2025 07:45:51 +0100 Subject: [PATCH 2/2] Make SAFE_NALLOCA allocate an ambiguous root * src/igc.c (igc_xnmalloc_ambig): New function. * src/igc.h: Declare it. * src/lisp.h (SAFE_NALLOCA): Use it. --- src/igc.c | 6 ++++++ src/igc.h | 1 + src/lisp.h | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/src/igc.c b/src/igc.c index 54131d5fcf3..10f74c66d8f 100644 --- a/src/igc.c +++ b/src/igc.c @@ -3144,6 +3144,12 @@ igc_xzalloc_ambig (size_t size) return p; } +void * +igc_xnmalloc_ambig (ptrdiff_t nitems, ptrdiff_t item_size) +{ + return igc_xzalloc_ambig (nitems * item_size); +} + void * igc_realloc_ambig (void *block, size_t size) { diff --git a/src/igc.h b/src/igc.h index 2a9bcda58b2..656a384aacf 100644 --- a/src/igc.h +++ b/src/igc.h @@ -86,6 +86,7 @@ #define EMACS_IGC_H struct Lisp_Buffer_Local_Value *igc_alloc_blv (void); void *igc_alloc_handler (void); void *igc_xzalloc_ambig (size_t size); +void *igc_xnmalloc_ambig (ptrdiff_t nitems, ptrdiff_t item_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); diff --git a/src/lisp.h b/src/lisp.h index 67b574a67b7..32e2886561c 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -6109,6 +6109,23 @@ #define SAFE_ALLOCA(size) ((size) <= sa_avail \ NITEMS items, each of the same type as *BUF. MULTIPLIER must positive. The code is tuned for MULTIPLIER being a constant. */ +# ifdef HAVE_MPS +void *igc_xnmalloc_ambig (ptrdiff_t nitems, ptrdiff_t item_size); +void igc_xfree (void *p); + +#define SAFE_NALLOCA(buf, multiplier, nitems) \ + do { \ + if ((nitems) <= sa_avail / sizeof *(buf) / (multiplier)) \ + (buf) = AVAIL_ALLOCA (sizeof *(buf) * (multiplier) * (nitems)); \ + else \ + { \ + (buf) = igc_xnmalloc_ambig (nitems, sizeof *(buf) * (multiplier)); \ + record_unwind_protect_ptr (igc_xfree, buf); \ + } \ + } while (false) + +#else + #define SAFE_NALLOCA(buf, multiplier, nitems) \ do { \ if ((nitems) <= sa_avail / sizeof *(buf) / (multiplier)) \ @@ -6120,6 +6137,8 @@ #define SAFE_NALLOCA(buf, multiplier, nitems) \ } \ } while (false) +#endif + /* SAFE_ALLOCA_STRING allocates a C copy of a Lisp string. */ #define SAFE_ALLOCA_STRING(ptr, string) \ -- 2.47.1 --=-=-=--