From: Helmut Eller <eller.helmut@gmail.com>
To: "Gerd Möllmann" <gerd.moellmann@gmail.com>
Cc: Emacs Devel <emacs-devel@gnu.org>, Eli Zaretskii <eliz@gnu.org>
Subject: Re: MPS: Forwording symbols
Date: Mon, 24 Jun 2024 17:13:42 +0200 [thread overview]
Message-ID: <87bk3qwezd.fsf@gmail.com> (raw)
In-Reply-To: <m21q4n3sxp.fsf@pro2.fritz.box> ("Gerd Möllmann"'s message of "Mon, 24 Jun 2024 05:45:06 +0200")
[-- Attachment #1: Type: text/plain, Size: 671 bytes --]
On Mon, Jun 24 2024, Gerd Möllmann 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.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Move-the-Lisp_Fwd.bufoffset-field-back-to-the-union.patch --]
[-- Type: text/x-diff, Size: 2947 bytes --]
From 770aaffe0ae52fb9305f9e2b646803ab2c4c0f84 Mon Sep 17 00:00:00 2001
From: Helmut Eller <eller.helmut@gmail.com>
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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-In-pop_handler-clear-references-in-the-dropped-handl.patch --]
[-- Type: text/x-diff, Size: 999 bytes --]
From 5b927463be1ee9055ef18ed654307699f5d17fea Mon Sep 17 00:00:00 2001
From: Helmut Eller <eller.helmut@gmail.com>
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
next prev parent reply other threads:[~2024-06-24 15:13 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-16 9:43 MPS: Forwording symbols Gerd Möllmann
2024-06-16 10:15 ` Gerd Möllmann
2024-06-16 19:27 ` Helmut Eller
2024-06-16 19:39 ` Gerd Möllmann
2024-06-17 10:57 ` Eli Zaretskii
2024-06-17 12:15 ` Gerd Möllmann
2024-06-17 12:24 ` Eli Zaretskii
2024-06-17 12:58 ` Gerd Möllmann
2024-06-17 3:43 ` Gerd Möllmann
2024-06-17 11:47 ` Eli Zaretskii
2024-06-17 18:10 ` Helmut Eller
2024-06-17 18:39 ` Gerd Möllmann
2024-06-17 18:50 ` Gerd Möllmann
2024-06-17 19:05 ` Helmut Eller
2024-06-17 19:19 ` Gerd Möllmann
2024-06-17 19:25 ` Helmut Eller
2024-06-17 20:07 ` Gerd Möllmann
2024-06-18 6:32 ` Gerd Möllmann
2024-06-18 9:05 ` Helmut Eller
2024-06-18 9:24 ` Gerd Möllmann
2024-06-18 10:44 ` Gerd Möllmann
2024-06-18 11:55 ` Helmut Eller
2024-06-18 12:21 ` Gerd Möllmann
2024-06-18 19:36 ` Helmut Eller
2024-06-18 19:55 ` Gerd Möllmann
2024-06-20 14:18 ` Helmut Eller
2024-06-20 15:16 ` Gerd Möllmann
2024-06-20 16:17 ` Helmut Eller
2024-06-20 16:27 ` Gerd Möllmann
2024-06-18 12:05 ` Helmut Eller
2024-06-18 12:29 ` Gerd Möllmann
2024-06-18 13:08 ` Eli Zaretskii
2024-06-18 12:36 ` Eli Zaretskii
2024-06-18 16:20 ` Helmut Eller
2024-06-18 16:29 ` Eli Zaretskii
2024-06-18 16:43 ` Gerd Möllmann
2024-06-18 16:37 ` Helmut Eller
2024-06-18 17:33 ` Eli Zaretskii
2024-06-18 17:51 ` Helmut Eller
2024-06-18 18:18 ` Eli Zaretskii
2024-06-18 17:54 ` Eli Zaretskii
2024-06-18 18:11 ` Gerd Möllmann
2024-06-18 18:20 ` Eli Zaretskii
2024-06-18 18:23 ` Gerd Möllmann
2024-06-18 18:12 ` Helmut Eller
2024-06-18 18:22 ` Eli Zaretskii
2024-06-18 19:27 ` Helmut Eller
2024-06-18 19:33 ` Gerd Möllmann
2024-06-19 11:22 ` Eli Zaretskii
2024-06-17 19:06 ` Gerd Möllmann
2024-06-21 15:36 ` Helmut Eller
2024-06-21 15:41 ` Gerd Möllmann
2024-06-21 16:20 ` Gerd Möllmann
2024-06-22 18:02 ` Helmut Eller
2024-06-22 18:27 ` Gerd Möllmann
2024-06-22 18:53 ` Helmut Eller
2024-06-22 19:26 ` Gerd Möllmann
2024-06-23 3:28 ` Gerd Möllmann
2024-06-23 4:10 ` Gerd Möllmann
2024-06-23 19:59 ` Helmut Eller
2024-06-24 3:45 ` Gerd Möllmann
2024-06-24 15:13 ` Helmut Eller [this message]
2024-06-24 16:14 ` Gerd Möllmann
2024-06-24 16:32 ` Eli Zaretskii
2024-06-24 17:00 ` Gerd Möllmann
2024-06-23 15:59 ` Helmut Eller
2024-06-23 16:26 ` Gerd Möllmann
2024-06-21 16:15 ` Ihor Radchenko
2024-06-21 16:25 ` Gerd Möllmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87bk3qwezd.fsf@gmail.com \
--to=eller.helmut@gmail.com \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=gerd.moellmann@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).