From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Helmut Eller Newsgroups: gmane.emacs.devel Subject: Re: MPS: Forwording symbols Date: Mon, 24 Jun 2024 17:13:42 +0200 Message-ID: <87bk3qwezd.fsf@gmail.com> References: <878qyy1f55.fsf@gmail.com> <87o77szwif.fsf@gmail.com> <877cegzu5j.fsf@gmail.com> <87tthjxwet.fsf@gmail.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="9324"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Emacs Devel , Eli Zaretskii To: Gerd =?utf-8?Q?M=C3=B6llmann?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Jun 24 17:14:36 2024 Return-path: 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 ) id 1sLlOu-0002HE-7M for ged-emacs-devel@m.gmane-mx.org; Mon, 24 Jun 2024 17:14:36 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sLlO9-0001lj-8E; Mon, 24 Jun 2024 11:13:49 -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 ) id 1sLlO7-0001lU-QW for emacs-devel@gnu.org; Mon, 24 Jun 2024 11:13:47 -0400 Original-Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLlO5-0005nM-Sg; Mon, 24 Jun 2024 11:13:47 -0400 Original-Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-3658197cdbbso2398643f8f.3; Mon, 24 Jun 2024 08:13:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719242024; x=1719846824; darn=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=yzfASUbkW/RyMuAs426nYbUDCiybJARDcyLc0yT2mVk=; b=B08ymBy6KjxY/128vn+ycoMmDJ999W+6Nu4TDCGS3MWT1AtNmO3pP6Rq/Ogrp/ByQL D2vDYpqLb0zFwxIX8YIffixMUuK/0prcILUeRfT1FjSQafWLdQ4aoaIgiq9lUOW90fny VJbwXMAMi+9GfzlaJeQZv2qTt5HuhpObKz87mzLkBUNjERsUid9/mhtwURKDRffCfs6V 41DfwzgLDJN1j4nbuvZc3qxD9HV2OknMdZ1IBNBEGXz8ZCacKibvJPMaOIFF9RmsVbI+ YMDGKA758d98zLD33pzj7T3Nt0nGnlEVdjmnNUsFNxPLBbn5xWSOv4XCe8Yr3gkCVKl8 +6Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719242024; x=1719846824; 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=yzfASUbkW/RyMuAs426nYbUDCiybJARDcyLc0yT2mVk=; b=UWM72/JfhLAdCoF6J+c2yUGvZLsT04mCg6mbwZM73bBV3JkuXE6d3BHs5JkJwyLn8X BHb5nAikQCMct962r7Zi8bbk9R99MorR7BOo8sGtU0elOGcaL6+WGMvW71kQu9GtG+q7 t/YppRaYlndNV6DpaIad5ewfVpcP0UaLlkBkcslNlH2mkx8xInkC9ZuxkhhsIp6O8WbP vRVFyMYwO7TlGH8dcWe87NjkxUg1VR7p4Veo50yjEkJErC27QwwA/VKIlrXP4e3Fgn/k 0dzNS74NjpGoKXRN4qHOtsF35wa4LOWR/4fQluWvMIhqumXfmuVeS2Ds9kFr8v5o2bhp q+yA== X-Forwarded-Encrypted: i=1; AJvYcCXoDgfnIE1mpOLPNWH+HdTFbCXYU8Cr/YDDQXDOxk5AWUnOK7Sc2iDtBFyDMtf+oc0GF3eSmBVHxhoVv9A= X-Gm-Message-State: AOJu0YxnkMz1T0l9PpyVpHQUmZeLS3zs+hcrWEIHB1wodtZWoBJt2faH Sd1LaeSYsNRAHSK/nN2PgRXwgabhUW0oUx//cQYNhwWV+a3q8B0zNKiPyA== X-Google-Smtp-Source: AGHT+IFW+2tAIo2cviwn2puGtfZhULwtkmx1iUxfDI5Ezb4kN2giVIxur0Al/DOD90Ks4vm9QjOoSg== X-Received: by 2002:adf:f2d1:0:b0:362:2518:fb59 with SMTP id ffacd0b85a97d-366e965d081mr3385368f8f.70.1719242023647; Mon, 24 Jun 2024 08:13:43 -0700 (PDT) Original-Received: from caladan ([31.177.116.19]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3663a8c8451sm10348316f8f.101.2024.06.24.08.13.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jun 2024 08:13:43 -0700 (PDT) In-Reply-To: ("Gerd =?utf-8?Q?M=C3=B6llman?= =?utf-8?Q?n=22's?= message of "Mon, 24 Jun 2024 05:45:06 +0200") Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=eller.helmut@gmail.com; helo=mail-wr1-x430.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-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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:320609 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Mon, Jun 24 2024, Gerd M=C3=B6llmann wrote: >> Here is an attempt to use an enum. I'm not sure that it's easier to >> read and the enum constants have odd names. > > Pushed! I have one more patch: it moves the bufoffset field back to the union. I think that's a bit nicer; and with the predicate enum there is enough room to do it. There other patch, sets some fields in a popped handler to nil to avoid a potential leak. > We even spared a word in the struct :-). Right, I haven't even noticed that. Now the union only needs one word and the type fields could be packed in 3 bits. That would probably be small enough to store it in a symbol. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Move-the-Lisp_Fwd.bufoffset-field-back-to-the-union.patch >From 770aaffe0ae52fb9305f9e2b646803ab2c4c0f84 Mon Sep 17 00:00:00 2001 From: Helmut Eller Date: Mon, 24 Jun 2024 10:06:54 +0200 Subject: [PATCH 1/2] Move the Lisp_Fwd.bufoffset field back to the union * src/lisp.h (struct Lisp_Fwd): With the predicate enum, we can now pack the offset and the predicate into a one-word struct. (XBUFFER_OFFSET): Use the new field name. * src/buffer.c (DEFVAR_PER_BUFFER): Create the one-word struct. * src/data.c (store_symval_forwarding): Use the new field name. --- src/buffer.c | 15 +++++++++------ src/data.c | 2 +- src/lisp.h | 9 ++++++--- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index 39b5e29067a..a69a9a3bbd8 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -5017,14 +5017,17 @@ init_buffer (void) that nil is allowed too). DOC is a dummy where you write the doc string as a comment. */ -#define DEFVAR_PER_BUFFER(lname, vname, predicate, doc) \ +#define DEFVAR_PER_BUFFER(lname, vname, predicate_, doc) \ do { \ - static const struct Lisp_Fwd bo_fwd \ - = { .type = Lisp_Fwd_Buffer_Obj, \ - .bufoffset = offsetof (struct buffer, vname##_), \ - .u.bufpredicate = FWDPRED_##predicate }; \ + static const struct Lisp_Fwd bo_fwd = { \ + .type = Lisp_Fwd_Buffer_Obj, \ + .u.buf = { \ + .offset = offsetof (struct buffer, vname##_), \ + .predicate = FWDPRED_##predicate_ \ + } \ + }; \ static_assert (offsetof (struct buffer, vname##_) \ - < (1 << 8 * sizeof bo_fwd.bufoffset)); \ + < (1 << 8 * sizeof bo_fwd.u.buf.offset)); \ defvar_per_buffer (&bo_fwd, lname); \ } while (0) diff --git a/src/data.c b/src/data.c index 9fd439e07b5..dcf869c1a0e 100644 --- a/src/data.c +++ b/src/data.c @@ -1513,7 +1513,7 @@ store_symval_forwarding (lispfwd valcontents, Lisp_Object newval, { int offset = XBUFFER_OFFSET (valcontents); if (!NILP (newval)) - check_fwd_predicate (valcontents->u.bufpredicate, newval); + check_fwd_predicate (valcontents->u.buf.predicate, newval); if (buf == NULL) buf = current_buffer; set_per_buffer_value (buf, offset, newval); diff --git a/src/lisp.h b/src/lisp.h index e3c2dce7df0..912b208a213 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -3180,13 +3180,16 @@ #define INT_TO_INTEGER(expr) \ struct Lisp_Fwd { enum Lisp_Fwd_Type type : 8; - uint16_t bufoffset; /* used if type == Lisp_Fwd_Buffer_Obj */ union { intmax_t *intvar; bool *boolvar; Lisp_Object *objvar; - enum Lisp_Fwd_Predicate bufpredicate; + struct + { + uint16_t offset; + enum Lisp_Fwd_Predicate predicate : 8; + } buf; int kbdoffset; } u; }; @@ -3207,7 +3210,7 @@ BUFFER_OBJFWDP (lispfwd a) XBUFFER_OFFSET (lispfwd a) { eassert (BUFFER_OBJFWDP (a)); - return a->bufoffset; + return a->u.buf.offset; } INLINE bool -- 2.39.2 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0002-In-pop_handler-clear-references-in-the-dropped-handl.patch >From 5b927463be1ee9055ef18ed654307699f5d17fea Mon Sep 17 00:00:00 2001 From: Helmut Eller Date: Mon, 24 Jun 2024 16:49:09 +0200 Subject: [PATCH 2/2] In pop_handler, clear references in the dropped handler * src/eval.c (pop_handler): Set the val and tag_or_ch fields to nil. Without this, the referenced objects can't be collected until a new handler is pushed. --- src/eval.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/eval.c b/src/eval.c index 6f008804e10..40c3c6394b0 100644 --- a/src/eval.c +++ b/src/eval.c @@ -1281,7 +1281,14 @@ #define clobbered_eassert(E) verify (sizeof (E) != 0) void pop_handler (void) { - handlerlist = handlerlist->next; + struct handler *old = handlerlist; + struct handler *new = old->next; + handlerlist = new; +#ifdef HAVE_MPS + eassert (new->nextfree == old); + old->val = Qnil; + old->tag_or_ch = Qnil; +#endif } /* Set up a catch, then call C function FUNC on argument ARG. -- 2.39.2 --=-=-=--